From 0ce1d70dffb2f19a8e2997f03556b46b44c57156 Mon Sep 17 00:00:00 2001 From: Linus Lee Date: Thu, 2 Apr 2015 15:53:26 -0700 Subject: 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 --- res/layout/app_drawer_item.xml | 11 +- .../android/launcher3/AppDrawerListAdapter.java | 122 ++++++++++++++++----- src/com/android/launcher3/AppDrawerScrubber.java | 39 ++++++- 3 files changed, 143 insertions(+), 29 deletions(-) diff --git a/res/layout/app_drawer_item.xml b/res/layout/app_drawer_item.xml index cc2ed8f9b..5d3b94655 100644 --- a/res/layout/app_drawer_item.xml +++ b/res/layout/app_drawer_item.xml @@ -19,6 +19,15 @@ android:splitMotionEvents="false" android:layout_width="match_parent" android:layout_height="wrap_content"> + + mHeaderList; private LayoutInflater mLayoutInflater; private Launcher mLauncher; private DeviceProfile mDeviceProfile; - private LinkedHashMap mSectionHeaders; + private LinkedHashMap mSectionHeaders; private LinearLayout.LayoutParams mIconParams; private Rect mIconRect; private LocaleSetManager mLocaleSetManager; @@ -93,12 +110,14 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter mViewHolderSet; @@ -125,11 +145,16 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter(); mInterpolator = new DecelerateInterpolator(); YDPI = ctx.getResources().getDisplayMetrics().ydpi; @@ -161,6 +186,12 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter= ANIMATION_DURATION) { + if (animation != null) { + animation.cancel(); + } + + if (mPendingShrink) { + mPendingShrink = false; + mLastScrollSpeed = 0; + checkAnimationState(); + } + + } + } + + public void animate(ViewHolder holder, Animator animation, float percentage) { percentage = mInterpolator.getInterpolation(percentage); if (!mExpanding) { @@ -233,17 +292,24 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter= ANIMATION_DURATION) { - animation.cancel(); - - if (mPendingShrink) { - mPendingShrink = false; - mLastScrollSpeed = 0; - checkAnimationState(); - } + if (getSectionForPosition(holder.getPosition()) == mSectionTarget) { + holder.mFadingBackgroundFront.setVisibility(View.INVISIBLE); + holder.mFadingBackgroundBack.setAlpha(percentage); + holder.mFadingBackgroundBack.setVisibility(View.VISIBLE); + } else { + holder.mFadingBackgroundFront.setAlpha(percentage); + holder.mFadingBackgroundFront.setVisibility(View.VISIBLE); + holder.mFadingBackgroundBack.setVisibility(View.INVISIBLE); + } + } + /** + * Sets the section index to highlight different from the rest when scrubbing + */ + public void setSectionTarget(int sectionIndex) { + mSectionTarget = sectionIndex; + for (ViewHolder holder : mViewHolderSet) { + animate(holder, null); } } } @@ -289,6 +355,13 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter(); + mSectionHeaders = new LinkedHashMap<>(); } - int count = 0; + + int sectionIndex = 0; for (int i = 0; i < mHeaderList.size(); i++) { - AppItemIndexedInfo info = mHeaderList.get(i); if (!mHeaderList.get(i).isChild) { - mSectionHeaders.put(String.valueOf(mHeaderList.get(i).mStartString), count); - } - if (info.mInfo.size() < mDeviceProfile.numColumnsBase) { - count++; - } else { - count += info.mInfo.size() / mDeviceProfile.numColumnsBase; + mSectionHeaders.put(String.valueOf(mHeaderList.get(i).mStartString), + new SectionIndices(sectionIndex, i)); + sectionIndex++; } } } @@ -741,12 +811,12 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter list) { 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; } -- cgit v1.2.3