diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java index eb62110065..283743dc64 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java @@ -51,7 +51,7 @@ import com.android.quickstep.views.RecentsView; * first home screen instead of to Overview. */ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouchController { - + private static final float ONE_HANDED_ACTIVATED_SLOP_MULTIPLIER = 2.5f; // How much of the movement to use for translating overview after swipe and hold. private static final float OVERVIEW_MOVEMENT_FACTOR = 0.25f; @@ -260,4 +260,14 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch private float dpiFromPx(float pixels) { return Utilities.dpiFromPx(pixels, mLauncher.getResources().getDisplayMetrics().densityDpi); } + + @Override + public void onOneHandedModeStateChanged(boolean activated) { + if (activated) { + mDetector.setTouchSlopMultiplier(ONE_HANDED_ACTIVATED_SLOP_MULTIPLIER); + } else { + // Reset touch slop multiplier to default 1.0f + mDetector.setTouchSlopMultiplier(1f /* default */); + } + } } diff --git a/quickstep/src/com/android/quickstep/BaseActivityInterface.java b/quickstep/src/com/android/quickstep/BaseActivityInterface.java index 4ae6fa8541..7ab371b4d9 100644 --- a/quickstep/src/com/android/quickstep/BaseActivityInterface.java +++ b/quickstep/src/com/android/quickstep/BaseActivityInterface.java @@ -114,6 +114,9 @@ public abstract class BaseActivityInterface callback); diff --git a/quickstep/src/com/android/quickstep/FallbackActivityInterface.java b/quickstep/src/com/android/quickstep/FallbackActivityInterface.java index 4ee4398d81..906599f560 100644 --- a/quickstep/src/com/android/quickstep/FallbackActivityInterface.java +++ b/quickstep/src/com/android/quickstep/FallbackActivityInterface.java @@ -73,6 +73,11 @@ public final class FallbackActivityInterface extends // set to zero prior to this class becoming active. } + @Override + public void onOneHandedModeStateChanged(boolean activated) { + // Do nothing for FallbackActivityInterface + } + /** 6 */ @Override public AnimationFactory prepareRecentsUI(RecentsAnimationDeviceState deviceState, diff --git a/quickstep/src/com/android/quickstep/LauncherActivityInterface.java b/quickstep/src/com/android/quickstep/LauncherActivityInterface.java index 9014774ae7..30abfbb922 100644 --- a/quickstep/src/com/android/quickstep/LauncherActivityInterface.java +++ b/quickstep/src/com/android/quickstep/LauncherActivityInterface.java @@ -104,6 +104,15 @@ public final class LauncherActivityInterface extends launcher.onAssistantVisibilityChanged(visibility); } + @Override + public void onOneHandedModeStateChanged(boolean activated) { + Launcher launcher = getCreatedActivity(); + if (launcher == null) { + return; + } + launcher.onOneHandedStateChanged(activated); + } + @Override public AnimationFactory prepareRecentsUI(RecentsAnimationDeviceState deviceState, boolean activityVisible, Consumer callback) { diff --git a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java index fb8f9fe31d..0efe6666a8 100644 --- a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java +++ b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java @@ -111,6 +111,11 @@ public final class OverviewComponentObserver { if (mDeviceState.isHomeDisabled() != mIsHomeDisabled) { updateOverviewTargets(); } + + // Notify ALL_APPS touch controller when one handed mode state activated or deactivated + if (mDeviceState.isOneHandedModeEnabled()) { + mActivityInterface.onOneHandedModeStateChanged(mDeviceState.isOneHandedModeActive()); + } } private void updateOverviewTargets(Intent unused) { diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 8889e60688..299c68fdb5 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -576,6 +576,14 @@ public class Launcher extends StatefulActivity implements Launche mHotseat.getQsb().setAlpha(1f - visibility); } + /** + * Called when one handed mode activated and deactivated. + * @param activated true if one handed mode activated, false otherwise. + */ + public void onOneHandedStateChanged(boolean activated) { + mDragLayer.onOneHandedModeStateChanged(activated); + } + private void initDeviceProfile(InvariantDeviceProfile idp) { // Load configuration-specific DeviceProfile mDeviceProfile = idp.getDeviceProfile(this); diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java index c2f609c6a7..011325d6cf 100644 --- a/src/com/android/launcher3/dragndrop/DragLayer.java +++ b/src/com/android/launcher3/dragndrop/DragLayer.java @@ -48,6 +48,7 @@ import com.android.launcher3.folder.Folder; import com.android.launcher3.graphics.Scrim; import com.android.launcher3.keyboard.ViewGroupFocusHelper; import com.android.launcher3.util.Thunk; +import com.android.launcher3.util.TouchController; import com.android.launcher3.views.BaseDragLayer; import java.util.ArrayList; @@ -519,4 +520,14 @@ public class DragLayer extends BaseDragLayer { public Scrim getWorkspaceDragScrim() { return mWorkspaceDragScrim; } + + /** + * Called when one handed mode state changed. + * @param activated true if one handed mode activated, false otherwise. + */ + public void onOneHandedModeStateChanged(boolean activated) { + for (TouchController controller : mControllers) { + controller.onOneHandedModeStateChanged(activated); + } + } } diff --git a/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java b/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java index 8c3c115334..f751b7d505 100644 --- a/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java +++ b/src/com/android/launcher3/touch/SingleAxisSwipeDetector.java @@ -102,6 +102,8 @@ public class SingleAxisSwipeDetector extends BaseSwipeDetector { private int mScrollDirections; + private float mTouchSlopMultiplier = 1f; + public SingleAxisSwipeDetector(@NonNull Context context, @NonNull Listener l, @NonNull Direction dir) { this(ViewConfiguration.get(context), l, dir, Utilities.isRtl(context.getResources())); @@ -115,6 +117,19 @@ public class SingleAxisSwipeDetector extends BaseSwipeDetector { mDir = dir; } + /** + * Provides feasibility to adjust touch slop when visible window size changed. When visible + * bounds translate become smaller, multiply a larger multiplier could ensure the UX + * more consistent. + * + * @see #shouldScrollStart(PointF) + * + * @param touchSlopMultiplier the value to multiply original touch slop. + */ + public void setTouchSlopMultiplier(float touchSlopMultiplier) { + mTouchSlopMultiplier = touchSlopMultiplier; + } + public void setDetectableScrollConditions(int scrollDirectionFlags, boolean ignoreSlop) { mScrollDirections = scrollDirectionFlags; mIgnoreSlopWhenSettling = ignoreSlop; @@ -133,7 +148,7 @@ public class SingleAxisSwipeDetector extends BaseSwipeDetector { @Override protected boolean shouldScrollStart(PointF displacement) { // Reject cases where the angle or slop condition is not met. - float minDisplacement = Math.max(mTouchSlop, + float minDisplacement = Math.max(mTouchSlop * mTouchSlopMultiplier, Math.abs(mDir.extractOrthogonalDirection(displacement))); if (Math.abs(mDir.extractDirection(displacement)) < minDisplacement) { return false; diff --git a/src/com/android/launcher3/util/TouchController.java b/src/com/android/launcher3/util/TouchController.java index fc1d819f78..9c397c0f74 100644 --- a/src/com/android/launcher3/util/TouchController.java +++ b/src/com/android/launcher3/util/TouchController.java @@ -32,5 +32,10 @@ public interface TouchController { */ boolean onControllerInterceptTouchEvent(MotionEvent ev); + /** + * Called when one handed mode state changed + */ + default void onOneHandedModeStateChanged(boolean activated) { } + default void dump(String prefix, PrintWriter writer) { } }