This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RecyclerHeaderViewHolder extends RecyclerView.ViewHolder { | |
| public RecyclerHeaderViewHolder(View itemView) { | |
| super(itemView); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class HidingScrollListener extends RecyclerView.OnScrollListener { | |
| private static final int HIDE_THRESHOLD = 20; | |
| private int scrolledDistance = 0; | |
| private boolean controlsVisible = true; | |
| @Override | |
| public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
| super.onScrolled(recyclerView, dx, dy); | |
| if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if((controlsVisible && dy>0) || (!controlsVisible && dy<0)) { | |
| scrolledDistance += dy; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) { | |
| onHide(); | |
| controlsVisible = false; | |
| scrolledDistance = 0; | |
| } else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) { | |
| onShow(); | |
| controlsVisible = true; | |
| scrolledDistance = 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void initRecyclerView() { | |
| RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); | |
| recyclerView.setLayoutManager(new LinearLayoutManager(this)); | |
| RecyclerAdapter recyclerAdapter = new RecyclerAdapter(createItemList()); | |
| recyclerView.setAdapter(recyclerAdapter); | |
| //setting up our OnScrollListener | |
| recyclerView.setOnScrollListener(new HidingScrollListener() { | |
| @Override | |
| public void onHide() { | |
| hideViews(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void hideViews() { | |
| mToolbar.animate().translationY(-mToolbar.getHeight()).setInterpolator(new AccelerateInterpolator(2)); | |
| FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFabButton.getLayoutParams(); | |
| int fabBottomMargin = lp.bottomMargin; | |
| mFabButton.animate().translationY(mFabButton.getHeight()+fabBottomMargin).setInterpolator(new AccelerateInterpolator(2)).start(); | |
| } | |
| private void showViews() { | |
| mToolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
| super.onScrolled(recyclerView, dx, dy); | |
| int firstVisibleItem = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition(); | |
| //show views if first item is first visible position and views are hidden | |
| if (firstVisibleItem == 0) { | |
| if(!controlsVisible) { | |
| onShow(); | |
| controlsVisible = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent"> | |
| <android.support.v7.widget.RecyclerView | |
| android:id="@+id/recyclerView" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:paddingTop="?attr/actionBarSize" | |
| android:clipToPadding="false"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class PartTwoActivity extends ActionBarActivity { | |
| private Toolbar mToolbar; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| setTheme(R.style.AppThemeGreen); | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_part_two); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class HidingScrollListener extends RecyclerView.OnScrollListener { | |
| private int mToolbarOffset = 0; | |
| private int mToolbarHeight; | |
| public HidingScrollListener(Context context) { | |
| mToolbarHeight = Utils.getToolbarHeight(context); | |
| } | |
| @Override |