diff options
author | Tony Mak <tonymak@google.com> | 2018-02-27 17:19:34 +0000 |
---|---|---|
committer | Tony Mak <tonymak@google.com> | 2018-02-27 17:29:12 +0000 |
commit | 2e564400ba6282a8fd12d20f4f8749c7c4e98853 (patch) | |
tree | 6eb3881b2ecdb6cea28719aa1bbda4ce2fb725ad /src | |
parent | 7eadfc4f150ed6fd3877249847740624ab671031 (diff) | |
download | android_packages_apps_Trebuchet-2e564400ba6282a8fd12d20f4f8749c7c4e98853.tar.gz android_packages_apps_Trebuchet-2e564400ba6282a8fd12d20f4f8749c7c4e98853.tar.bz2 android_packages_apps_Trebuchet-2e564400ba6282a8fd12d20f4f8749c7c4e98853.zip |
Fix all apps tab fling detection
It is a regression when we changed from ViewPager to PagedView.
Unlike ViewPager, PagedView does not take "yDiff" into account
when determining should it intercept its child MotionEvent.
Override determineScrollingStart, just like what we did in Workspace
Change-Id: I25f7415c45c370629558d944f59bf95c741b9319
FIX: 73878167
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/PagedView.java | 8 | ||||
-rw-r--r-- | src/com/android/launcher3/allapps/AllAppsPagedView.java | 33 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index ccb0a955d..4be32b207 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -1892,6 +1892,14 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou getNextPage() + 1, getChildCount()); } + protected float getDownMotionX() { + return mDownMotionX; + } + + protected float getDownMotionY() { + return mDownMotionY; + } + @Override public boolean onHoverEvent(android.view.MotionEvent event) { return true; diff --git a/src/com/android/launcher3/allapps/AllAppsPagedView.java b/src/com/android/launcher3/allapps/AllAppsPagedView.java index 86186fdb5..3b4450bf8 100644 --- a/src/com/android/launcher3/allapps/AllAppsPagedView.java +++ b/src/com/android/launcher3/allapps/AllAppsPagedView.java @@ -18,12 +18,17 @@ package com.android.launcher3.allapps; import android.content.Context; import android.util.AttributeSet; +import android.view.MotionEvent; import com.android.launcher3.PagedView; import com.android.launcher3.R; public class AllAppsPagedView extends PagedView<PersonalWorkSlidingTabStrip> { - public AllAppsPagedView(Context context) { + final static float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6; + final static float MAX_SWIPE_ANGLE = (float) Math.PI / 3; + final static float TOUCH_SLOP_DAMPING_FACTOR = 4; + + public AllAppsPagedView(Context context) { this(context, null); } @@ -46,4 +51,30 @@ public class AllAppsPagedView extends PagedView<PersonalWorkSlidingTabStrip> { super.onScrollChanged(l, t, oldl, oldt); mPageIndicator.setScroll(l, mMaxScrollX); } + + @Override + protected void determineScrollingStart(MotionEvent ev) { + float absDeltaX = Math.abs(ev.getX() - getDownMotionX()); + float absDeltaY = Math.abs(ev.getY() - getDownMotionY()); + + if (Float.compare(absDeltaX, 0f) == 0) return; + + float slope = absDeltaY / absDeltaX; + float theta = (float) Math.atan(slope); + + if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) { + cancelCurrentPageLongPress(); + } + + if (theta > MAX_SWIPE_ANGLE) { + return; + } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) { + theta -= START_DAMPING_TOUCH_SLOP_ANGLE; + float extraRatio = (float) + Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE))); + super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio); + } else { + super.determineScrollingStart(ev); + } + } } |