diff options
author | Linus Lee <llee@cyngn.com> | 2015-04-02 15:53:26 -0700 |
---|---|---|
committer | Linus Lee <llee@cyngn.com> | 2015-04-16 19:15:31 +0000 |
commit | 0ce1d70dffb2f19a8e2997f03556b46b44c57156 (patch) | |
tree | 7c3107c84f24ea2e03e851a73a96705d2f9ceee2 /src/com/android/launcher3/AppDrawerScrubber.java | |
parent | d06291251703ce19968625742438c03351203d37 (diff) | |
download | android_packages_apps_Trebuchet-0ce1d70dffb2f19a8e2997f03556b46b44c57156.tar.gz android_packages_apps_Trebuchet-0ce1d70dffb2f19a8e2997f03556b46b44c57156.tar.bz2 android_packages_apps_Trebuchet-0ce1d70dffb2f19a8e2997f03556b46b44c57156.zip |
AppDrawer: Add highlighting scrubbing and offset
When you drag the scrubber it now highlights that section differently
Also when you drag on the scrubber, instead of bringing the section
into view at any point, it will try to make it the 3 row from the bottom
Change-Id: I7cefaa24fb3c757f6e031247bb4a247473dde828
Diffstat (limited to 'src/com/android/launcher3/AppDrawerScrubber.java')
-rw-r--r-- | src/com/android/launcher3/AppDrawerScrubber.java | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/com/android/launcher3/AppDrawerScrubber.java b/src/com/android/launcher3/AppDrawerScrubber.java index 706ddfe96..c65fd373d 100644 --- a/src/com/android/launcher3/AppDrawerScrubber.java +++ b/src/com/android/launcher3/AppDrawerScrubber.java @@ -20,9 +20,11 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.content.Context; import android.graphics.Color; +import android.graphics.PointF; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.LinearSmoothScroller; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -261,8 +263,41 @@ public class AppDrawerScrubber extends LinearLayout { // get the index of the underlying list int adapterIndex = mSectionContainer.getAdapterIndex(mLastIndex, index); - mLayoutManager.smoothScrollToPosition(mListView, null, - mAdapter.getPositionForSection(adapterIndex)); + int itemIndex = mAdapter.getPositionForSection(adapterIndex); + + // get any child's height since all children are the same height + int itemHeight = 0; + View child = mLayoutManager.getChildAt(0); + if (child != null) { + itemHeight = child.getMeasuredHeight(); + } + + if (itemHeight != 0) { + // scroll to the item such that there are 2 rows beneath it from the bottom + final int itemDiff = 2 * itemHeight; + LinearSmoothScroller scroller = new LinearSmoothScroller(mListView.getContext()) { + @Override + protected int getVerticalSnapPreference() { + // position the item against the end of the list view + return SNAP_TO_END; + } + + @Override + public PointF computeScrollVectorForPosition(int targetPosition) { + return mLayoutManager.computeScrollVectorForPosition(targetPosition); + } + + @Override + public int calculateDyToMakeVisible(View view, int snapPreference) { + int dy = super.calculateDyToMakeVisible(view, snapPreference); + return dy - itemDiff; + } + }; + scroller.setTargetPosition(itemIndex); + mLayoutManager.startSmoothScroll(scroller); + } + + mAdapter.setSectionTarget(adapterIndex); mLastIndex = index; } |