Merge "Refactoring to use more precise statements when calculating gesture distance and others" into ub-launcher3-master

This commit is contained in:
Jason Chang authored and Android (Google) Code Review committed 2020-07-31 02:19:17 +00:00
commit c22726e067
2 files changed
+18 -9

No files matched your search

@@ -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) {
@@ -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;
}