Skip to content

Instantly share code, notes, and snippets.

public class HideFabScrollListener extends RecyclerView.OnScrollListener {
private static final int TRANSLATE_HIDE_DURATION_MILLIS = 200;
private static final int TRANSLATE_SHOW_DURATION_MILLIS = 170;
private View fab;
private Animator hideAnimator;
private Animator showAnimator;
public class DefaultInsertionPredicate<S, T> implements InsertionPredicate<S, T> {
@Override
public boolean canInsert(@Nonnull Section<S, T> section, @Nonnull T item) {
return true;
}
}
public class StickyHeaderViewManager<T> {
@Nonnull
private View headerView;
@Nonnull
private RecyclerView recyclerView;
@Nonnull
@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;
}
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));
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 {

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}, ' '),
});
@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;
@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 / 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