summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMario Bertschler <bmario@google.com>2016-12-27 15:41:24 -0800
committerMario Bertschler <bmario@google.com>2017-01-03 14:22:26 -0800
commitee4ee424b42f76ce41dfd659a92f249af8ccd0e1 (patch)
tree1ae810dae444ebf49ba67942a79f12dc36120636 /src
parentc9c57631a985a8e1a4eac17ef0952bd344e281a2 (diff)
downloadandroid_packages_apps_Trebuchet-ee4ee424b42f76ce41dfd659a92f249af8ccd0e1.tar.gz
android_packages_apps_Trebuchet-ee4ee424b42f76ce41dfd659a92f249af8ccd0e1.tar.bz2
android_packages_apps_Trebuchet-ee4ee424b42f76ce41dfd659a92f249af8ccd0e1.zip
Enables direct scrolling on the fastscroll bar.
This enables to touch anywhere in the scrollbar to directly scroll to that particular point without the need of exactly touching the thumb to start fastscrolling. This feature is currently behind a feature flag LAUNCHER3_DIRECT_SCROLL and enabled by default. Change-Id: I5b86c6acb71ff0c88476343657da221c7bdc59c3
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java65
1 files changed, 44 insertions, 21 deletions
diff --git a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java
index 40c5ed65d..4fecc3da5 100644
--- a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java
+++ b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java
@@ -28,6 +28,8 @@ import android.view.View;
import android.view.ViewConfiguration;
import android.widget.TextView;
+import com.android.launcher3.config.FeatureFlags;
+
/**
* The track and scrollbar that shows when you scroll the list.
*/
@@ -198,6 +200,11 @@ public class BaseRecyclerViewFastScrollBar {
case MotionEvent.ACTION_DOWN:
if (isNearThumb(downX, downY)) {
mTouchOffsetY = downY - mThumbOffsetY;
+ } else if (FeatureFlags.LAUNCHER3_DIRECT_SCROLL
+ && mRv.supportsFastScrolling()
+ && isNearScrollBar(downX)) {
+ calcTouchOffsetAndPrepToFastScroll(downY, lastY);
+ updateFastScrollSectionNameAndThumbOffset(lastY, y);
}
break;
case MotionEvent.ACTION_MOVE:
@@ -207,28 +214,10 @@ public class BaseRecyclerViewFastScrollBar {
if (!mIsDragging && !mIgnoreDragGesture && mRv.supportsFastScrolling() &&
isNearThumb(downX, lastY) &&
Math.abs(y - downY) > config.getScaledTouchSlop()) {
- mRv.getParent().requestDisallowInterceptTouchEvent(true);
- mIsDragging = true;
- if (mCanThumbDetach) {
- mIsThumbDetached = true;
- }
- mTouchOffsetY += (lastY - downY);
- animatePopupVisibility(true);
- showActiveScrollbar(true);
+ calcTouchOffsetAndPrepToFastScroll(downY, lastY);
}
if (mIsDragging) {
- // Update the fastscroller section name at this touch position
- int bottom = mRv.getScrollbarTrackHeight() - mThumbHeight;
- float boundedY = (float) Math.max(0, Math.min(bottom, y - mTouchOffsetY));
- String sectionName = mRv.scrollToPositionAtProgress(boundedY / bottom);
- if (!sectionName.equals(mPopupSectionName)) {
- mPopupSectionName = sectionName;
- mPopupView.setText(sectionName);
- }
- animatePopupVisibility(!sectionName.isEmpty());
- updatePopupY(lastY);
- mLastTouchY = boundedY;
- setThumbOffsetY((int) mLastTouchY);
+ updateFastScrollSectionNameAndThumbOffset(lastY, y);
}
break;
case MotionEvent.ACTION_UP:
@@ -245,6 +234,32 @@ public class BaseRecyclerViewFastScrollBar {
}
}
+ private void calcTouchOffsetAndPrepToFastScroll(int downY, int lastY) {
+ mRv.getParent().requestDisallowInterceptTouchEvent(true);
+ mIsDragging = true;
+ if (mCanThumbDetach) {
+ mIsThumbDetached = true;
+ }
+ mTouchOffsetY += (lastY - downY);
+ animatePopupVisibility(true);
+ showActiveScrollbar(true);
+ }
+
+ private void updateFastScrollSectionNameAndThumbOffset(int lastY, int y) {
+ // Update the fastscroller section name at this touch position
+ int bottom = mRv.getScrollbarTrackHeight() - mThumbHeight;
+ float boundedY = (float) Math.max(0, Math.min(bottom, y - mTouchOffsetY));
+ String sectionName = mRv.scrollToPositionAtProgress(boundedY / bottom);
+ if (!sectionName.equals(mPopupSectionName)) {
+ mPopupSectionName = sectionName;
+ mPopupView.setText(sectionName);
+ }
+ animatePopupVisibility(!sectionName.isEmpty());
+ updatePopupY(lastY);
+ mLastTouchY = boundedY;
+ setThumbOffsetY((int) mLastTouchY);
+ }
+
public void draw(Canvas canvas) {
if (mThumbOffsetY < 0) {
return;
@@ -277,7 +292,7 @@ public class BaseRecyclerViewFastScrollBar {
}
/**
- * Returns whether the specified points are near the scroll bar bounds.
+ * Returns whether the specified point is inside the thumb bounds.
*/
public boolean isNearThumb(int x, int y) {
int left = getDrawLeft();
@@ -286,6 +301,14 @@ public class BaseRecyclerViewFastScrollBar {
return mTmpRect.contains(x, y);
}
+ /**
+ * Returns whether the specified x position is near the scroll bar.
+ */
+ public boolean isNearScrollBar(int x) {
+ int left = getDrawLeft();
+ return x >= left && x <= left + mMaxWidth;
+ }
+
private void animatePopupVisibility(boolean visible) {
if (mPopupVisible != visible) {
mPopupVisible = visible;