Skip to content

Instantly share code, notes, and snippets.

View samuel22gj's full-sized avatar
👨‍💻
Coding

Samuel Huang samuel22gj

👨‍💻
Coding
View GitHub Profile
@samuel22gj
samuel22gj / MultiTypeRecyclerAdapter.java
Last active January 25, 2018 18:05
Multiple Type RecyclerView Adapter
public class MultiTypeRecyclerAdapter extends RecyclerView.Adapter<MultiTypeRecyclerAdapter.ViewHolder> {
private static final String TAG = MultiTypeRecyclerAdapter.class.getSimpleName();
@Retention(SOURCE)
@IntDef({VIEW_TYPE_SUBTITLE, VIEW_TYPE_PROMOTION})
public @interface VIEW_TYPE {}
private static final int VIEW_TYPE_SUBTITLE = 0;
private static final int VIEW_TYPE_PROMOTION = 1;
private List<Item> mList;
public class RippleDrawableCompat {
public static class Builder {
int normalColor = Color.TRANSPARENT;
int pressColor = Color.TRANSPARENT;
int strokeColor = Color.TRANSPARENT;
int strokeWidth = 0;
float radius = 0.0f;
public Builder() {
public class ColorUtils {
private static final float DEFAULT_LIGHTNESS_ADJUST_PERCENTAGE = 0.2f;
public static boolean isFlagshipLight(@ColorInt int color) {
return getBrightness(color) >= 204.0f;
// return getLightness(color) > 0.5f;
// return getContrast(color, Color.BLACK) > 4.5;
}
@samuel22gj
samuel22gj / MyCollapsingToolbarLayout.java
Last active May 16, 2017 05:36
with OnScrimVisibilityChangedListener
public class ECCollapsingToolbarLayout extends CollapsingToolbarLayout {
private boolean mIsScrimShow;
private OnScrimVisibilityChangedListener mOnScrimVisibilityChangedListener;
private AppBarLayout.OnOffsetChangedListener mOnOffsetChangedListener;
public ECCollapsingToolbarLayout(Context context) {
super(context);
}
@samuel22gj
samuel22gj / FitsSystemWindowsFrameLayout.java
Last active March 27, 2019 12:50
Fix windowSoftInputMode=“adjustResize” not working when activity is full screen
/**
* A kind of FrameLayout which enable {@code fitsSystemWindows} and can only consume specific directions.
*/
public class FitsSystemWindowsFrameLayout extends FrameLayout {
private static final String TAG = FitsSystemWindowsFrameLayout.class.getSimpleName();
private static final int FLAG_CONSUME_SYSTEM_WINDOWS_LEFT = 0x0001;
private static final int FLAG_CONSUME_SYSTEM_WINDOWS_TOP = 0x0002;
private static final int FLAG_CONSUME_SYSTEM_WINDOWS_RIGHT = 0x0004;
private static final int FLAG_CONSUME_SYSTEM_WINDOWS_BOTTOM = 0x0008;
@samuel22gj
samuel22gj / TabViewPagerFragment.java
Last active May 16, 2017 05:35
A wrap Fragment with TabLayout and ViewPager
public abstract class TabViewPagerFragment extends ECFragment implements TabLayout.OnTabSelectedListener, ViewPager.OnPageChangeListener {
private static final String TAG = ECTabViewPagerFragment.class.getSimpleName();
private TabLayout mTabLayout;
@TabLayout.Mode
private int mTabLayoutMode = TabLayout.MODE_FIXED;
private ViewPager mViewPager;
private TabPageAdapter mPagerAdapter;
/*
@samuel22gj
samuel22gj / GridlinesItemDecoration.java
Created June 2, 2017 02:48
A kind of ItemDecoration to draw gridlines with specific color and size.
/**
* A kind of {@link android.support.v7.widget.RecyclerView.ItemDecoration} to draw gridlines with
* specific color and size. It assumes every item at same column has the same width and don't draw border.
*/
public class GridlinesItemDecoration extends RecyclerView.ItemDecoration {
private static final String TAG = GridlinesItemDecoration.class.getSimpleName();
private int mDividerSize;
private Paint mPaint;
@samuel22gj
samuel22gj / WrapContentViewPager.java
Last active July 24, 2017 05:30
A ViewPager support height is WRAP_CONTENT
/**
* A ViewPager support height is {@code WRAP_CONTENT}.
*/
public class WrapContentViewPager extends ViewPager {
public WrapContentViewPager(Context context) {
super(context, null);
}
public WrapContentViewPager(Context context, AttributeSet attrs) {
@samuel22gj
samuel22gj / GifDrawableImageViewTarget.java
Last active May 27, 2020 06:47
Glide v4 target for GifDrawable or Drawable
/**
* A target for display {@link GifDrawable} or {@link Drawable} objects in {@link ImageView}s.
*/
public class GifDrawableImageViewTarget extends ImageViewTarget<Drawable> {
private int mLoopCount = GifDrawable.LOOP_FOREVER;
public GifDrawableImageViewTarget(ImageView view, int loopCount) {
super(view);
mLoopCount = loopCount;
@samuel22gj
samuel22gj / OnItemVisibleChangeListener.java
Last active July 14, 2023 09:09
A callback listener to notify when item visibility change.
public abstract class OnItemVisibleChangeListener extends RecyclerView.OnScrollListener {
private static final String TAG = OnItemVisibleChangeListener.class.getSimpleName();
private int mFirstVisibleItemPosition = RecyclerView.NO_POSITION;
private int mFirstCompletelyVisibleItemPosition = RecyclerView.NO_POSITION;
private int mLastVisibleItemPosition = RecyclerView.NO_POSITION;
private int mLastCompletelyVisibleItemPosition = RecyclerView.NO_POSITION;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {