Predictive back: widget to all apps
This CL adds a layer of OnBackPressedHanlderRouter to Launcher:
1. 4 OnBackPressedHandler(s) are added in such order: auto cancel action mode handler, drag handler, view handler and state handler
2. first handler who can handle back will handle the entire back gesture
3. Let WidgetsFullSheet to handle widget to all apps transition
Bug: b/260956481
Test: manual
Change-Id: Idbce3dcec746226dd68aaabaddc8fe01334e9673
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index de5419e..96dd569 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -560,6 +560,61 @@
setTitle(R.string.home_screen);
}
+ /**
+ * Provide {@link OnBackPressedHandler} in below order:
+ * <ol>
+ * <li> auto cancel action mode handler
+ * <li> drag handler
+ * <li> view handler
+ * <li> state handler
+ * </ol>
+ *
+ * A back gesture (a single click on back button, or a swipe back gesture that contains a series
+ * of swipe events) should be handled by the same handler from above list. For a new back
+ * gesture, a new handler should be regenerated.
+ *
+ * Note that state handler will always be handling the back press event if the previous 3 don't.
+ */
+ @NonNull
+ protected OnBackPressedHandler getOnBackPressedHandler() {
+ // #1 auto cancel action mode handler
+ if (isInAutoCancelActionMode()) {
+ return this::finishAutoCancelActionMode;
+ }
+
+ // #2 drag handler
+ if (mDragController.isDragging()) {
+ return mDragController::cancelDrag;
+ }
+
+ // #3 view handler
+ AbstractFloatingView topView =
+ AbstractFloatingView.getTopOpenView(Launcher.this);
+ if (topView != null && topView.canHandleBack()) {
+ return topView;
+ }
+
+ // #4 state handler
+ return new OnBackPressedHandler() {
+ @Override
+ public void onBackInvoked() {
+ onStateBack();
+ }
+
+ @Override
+ public void onBackProgressed(
+ @FloatRange(from = 0.0, to = 1.0) float backProgress) {
+ mStateManager.getState().onBackProgressed(
+ Launcher.this, backProgress);
+ }
+
+ @Override
+ public void onBackCancelled() {
+ mStateManager.getState().onBackCancelled(Launcher.this);
+ }
+ };
+ }
+
protected LauncherOverlayManager getDefaultOverlay() {
return new LauncherOverlayManager() { };
}
@@ -2047,36 +2102,13 @@
@Override
public void onBackPressed() {
- if (finishAutoCancelActionMode()) {
- return;
- }
-
- if (mDragController.isDragging()) {
- mDragController.cancelDrag();
- return;
- }
-
- // Note: There should be at most one log per method call. This is enforced implicitly
- // by using if-else statements.
- AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
- if (topView == null || !topView.onBackPressed()) {
- // Not handled by the floating view.
- onStateBack();
- }
+ getOnBackPressedHandler().onBackInvoked();
}
protected void onStateBack() {
mStateManager.getState().onBackPressed(this);
}
- protected void onBackProgressed(@FloatRange(from = 0.0, to = 1.0) float backProgress) {
- mStateManager.getState().onBackProgressed(this, backProgress);
- }
-
- protected void onBackCancelled() {
- mStateManager.getState().onBackCancelled(this);
- }
-
protected void onScreenOnChanged(boolean isOn) {
// Reset AllApps to its initial state only if we are not in the middle of
// processing a multi-step drop