Skip to content

Instantly share code, notes, and snippets.

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.Priority;
import com.bumptech.glide.Registry;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.model.ModelLoader;
import com.bumptech.glide.load.model.ModelLoaderFactory;
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter
import java.util.ArrayList
class ViewPagerAdapter2(
fragmentManager: FragmentManager,
lifecycle: Lifecycle,
): FragmentStateAdapter(fragmentManager, lifecycle) {
@Anrimian
Anrimian / AndroidUtils.kt
Created November 28, 2021 11:22
Dialog that shows system colors table on api 31+
import android.app.AlertDialog
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
@Anrimian
Anrimian / BitmapLruCache.java
Created October 25, 2019 07:55
Lightweight android image loader(with rx dependency)
public class BitmapLruCache<K> extends LruCache<K, Bitmap> {
/**
* @param maxSize for caches that do not override {@link #sizeOf}, this is
* the maximum number of entries in the cache. For all other caches,
* this is the maximum sum of the sizes of the entries in this cache.
*/
public BitmapLruCache(int maxSize) {
super(maxSize);
}
@Anrimian
Anrimian / DialogFragmentRunner.java
Last active December 26, 2019 12:39
Utilite class that makes restore fragment dialog state little easier
public class DialogFragmentRunner<T extends DialogFragment> {
private final FragmentManager fragmentManager;
private final String tag;
private final Callback<T> fragmentInitializer;
public DialogFragmentRunner(FragmentManager fragmentManager,
String tag,
Callback<T> fragmentInitializer) {
this.fragmentManager = fragmentManager;

Improved solution from so answer, with copy-paste support

Credit card input filter example:

yourEditText.setFilters(new InputFilter[]{
            new InputFilter.LengthFilter(23),
            new SpacesInputFilter(23, new int[]{4, 9, 14, 19}, ' '),
});
import android.os.Bundle;
import com.arellomobile.mvp.MvpDelegate;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import androidx.fragment.app.Fragment;
public class MvpBottomSheetDialogFragment extends BottomSheetDialogFragment {
import android.support.constraint.motion.MotionLayout;
import android.support.v4.view.ViewCompat;
public class MotionLayoutUtils {
public static void setProgress(MotionLayout motionLayout, float progress) {
if (ViewCompat.isLaidOut(motionLayout)) {
motionLayout.setProgress(progress);
} else {
motionLayout.post(() -> motionLayout.setProgress(progress));
@Anrimian
Anrimian / MultiTypeAdapter.java
Created June 29, 2018 08:38
MultiTypeAdapter for RecyclerView
public class MultiTypeAdapter extends RecyclerView.Adapter {
private final List<ViewHolderBuilder> builders;
private final List<Item> items;
MultiTypeAdapter(List<Item> items, List<ViewHolderBuilder> builders) {
this.items = items;
this.builders = builders;
}
public class StickyHeaderViewManager<T> {
@Nonnull
private View headerView;
@Nonnull
private RecyclerView recyclerView;
@Nonnull