From b0611351e3cb70a9868226fc54bc23534311ae2e Mon Sep 17 00:00:00 2001 From: Jason Chang Date: Tue, 30 Jun 2020 15:44:14 +0800 Subject: [PATCH] Refactoring to use more precise statements when calculating gesture distance and others 1) Use more precise statements when calculating gesture distance and refine ACTION_CANCEL motion events and others. 2) Check system property "ro.support_one_handed_mode" to enable or disable one-handed quicksteps gesture feature. Bug: 160315874 Test: make and install Test: manual enable one handed mode and swipe down to trigger Test: manual start one handed and rotate device Change-Id: Ib27f9b6f92edda3cbff1ecb554b1a70f2e56e552 --- .../OneHandedModeInputConsumer.java | 15 ++++++++------- .../quickstep/RecentsAnimationDeviceState.java | 12 ++++++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OneHandedModeInputConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OneHandedModeInputConsumer.java index 0bb8fff2a1..22bd334517 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OneHandedModeInputConsumer.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OneHandedModeInputConsumer.java @@ -52,7 +52,6 @@ public class OneHandedModeInputConsumer extends DelegateInputConsumer { private final PointF mDownPos = new PointF(); private final PointF mLastPos = new PointF(); - private final PointF mStartDragPos = new PointF(); private boolean mPassedSlop; @@ -92,7 +91,6 @@ public class OneHandedModeInputConsumer extends DelegateInputConsumer { if (!mPassedSlop) { if (squaredHypot(mLastPos.x - mDownPos.x, mLastPos.y - mDownPos.y) > mSquaredSlop) { - mStartDragPos.set(mLastPos.x, mLastPos.y); if ((!mDeviceState.isOneHandedModeActive() && isValidStartAngle( mDownPos.x - mLastPos.x, mDownPos.y - mLastPos.y)) || (mDeviceState.isOneHandedModeActive() && isValidExitAngle( @@ -104,17 +102,16 @@ public class OneHandedModeInputConsumer extends DelegateInputConsumer { } } } else { - float distance = (float) Math.hypot(mLastPos.x - mStartDragPos.x, - mLastPos.y - mStartDragPos.y); + float distance = (float) Math.hypot(mLastPos.x - mDownPos.x, + mLastPos.y - mDownPos.y); if (distance > mDragDistThreshold && mPassedSlop) { onStopGestureDetected(); } } break; } - case ACTION_UP: - case ACTION_CANCEL: { - if (mLastPos.y >= mStartDragPos.y && mPassedSlop) { + case ACTION_UP: { + if (mLastPos.y >= mDownPos.y && mPassedSlop) { onStartGestureDetected(); } @@ -122,6 +119,10 @@ public class OneHandedModeInputConsumer extends DelegateInputConsumer { mState = STATE_INACTIVE; break; } + case ACTION_CANCEL: + mPassedSlop = false; + mState = STATE_INACTIVE; + break; } if (mState != STATE_ACTIVE) { diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java index 2868b1b37c..716887509d 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java @@ -79,6 +79,8 @@ public class RecentsAnimationDeviceState implements DefaultDisplay.DisplayInfoChangeListener, OneHandedModeChangeListener { + static final String SUPPORT_ONE_HANDED_MODE = "ro.support_one_handed_mode"; + private final Context mContext; private final SysUINavigationMode mSysUiNavMode; private final DefaultDisplay mDefaultDisplay; @@ -165,13 +167,15 @@ public class RecentsAnimationDeviceState implements } } - if (SystemProperties.getBoolean("ro.support_one_handed_mode", false)) { + if (SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false)) { SecureSettingsObserver oneHandedEnabledObserver = SecureSettingsObserver.newOneHandedSettingsObserver( mContext, enabled -> mIsOneHandedModeEnabled = enabled); oneHandedEnabledObserver.register(); oneHandedEnabledObserver.dispatchOnChange(); runOnDestroy(oneHandedEnabledObserver::unregister); + } else { + mIsOneHandedModeEnabled = false; } SecureSettingsObserver swipeBottomEnabledObserver = @@ -443,7 +447,7 @@ public class RecentsAnimationDeviceState implements } /** - * @return whether screen pinning is enabled and active + * @return whether one-handed mode is enabled and active */ public boolean isOneHandedModeActive() { return (mSystemUiStateFlags & SYSUI_STATE_ONE_HANDED_ACTIVE) != 0; @@ -518,6 +522,10 @@ public class RecentsAnimationDeviceState implements * @return whether the given motion event can trigger the one handed mode. */ public boolean canTriggerOneHandedAction(MotionEvent ev) { + if (!SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false)) { + return false; + } + if (!mIsOneHandedModeEnabled && !mIsSwipeToNotificationEnabled) { return false; }