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 / ClickAreaHelper.java
Last active September 28, 2018 06:55
Class intended to support multiple click areas for a View.
/**
* Class intended to support multiple click areas for a {@link View}.
*/
public abstract class ClickAreaHelper implements View.OnTouchListener, View.OnClickListener, View.OnLongClickListener {
private OnClickAreaListener mOnClickAreaListener;
private OnLongClickAreaListener mOnLongClickAreaListener;
private View mView;
@samuel22gj
samuel22gj / SpacingDividerItemDecoration.java
Last active April 26, 2018 07:06
A RecyclerView.ItemDecoration that can add spacing divider between items.
/**
* SpacingDividerItemDecoration is a {@link RecyclerView.ItemDecoration} that can add space divider
* between items of a {@link android.support.v7.widget.LinearLayoutManager}. It supports both {@link #HORIZONTAL}
* and {@link #VERTICAL} orientations.
*/
public class SpacingDividerItemDecoration extends RecyclerView.ItemDecoration {
@IntDef({HORIZONTAL, VERTICAL})
@Retention(RetentionPolicy.SOURCE)
public @interface OrientationMode {}
@samuel22gj
samuel22gj / ParallaxRecyclerView.java
Last active January 30, 2018 08:23
A RecyclerView that make the first ViewHolder has parallax effect.
/**
* Make the first {@link RecyclerView.ViewHolder} has parallax effect.
*/
public class ParallaxRecyclerView extends ECRecyclerView {
private static final String TAG = ParallaxRecyclerView.class.getSimpleName();
private static final float DEFAULT_PARALLAX_MULTIPLIER = 0.5f;
private float mParallaxMultiplier = DEFAULT_PARALLAX_MULTIPLIER;
private OnParallaxScrollListener mParallaxScrollListener;
@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) {
@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 / 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 / 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 / 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 / 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 / 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);
}