• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.launcher3.uioverrides.touchcontrollers;
2 
3 import static com.android.launcher3.LauncherState.NORMAL;
4 import static com.android.launcher3.LauncherState.OVERVIEW;
5 import static com.android.launcher3.Utilities.EDGE_NAV_BAR;
6 
7 import android.view.MotionEvent;
8 
9 import com.android.launcher3.AbstractFloatingView;
10 import com.android.launcher3.Launcher;
11 import com.android.launcher3.LauncherState;
12 import com.android.launcher3.LauncherStateManager.AnimationComponents;
13 import com.android.launcher3.touch.AbstractStateChangeTouchController;
14 import com.android.launcher3.touch.SwipeDetector;
15 import com.android.launcher3.userevent.nano.LauncherLogProto;
16 import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
17 import com.android.quickstep.RecentsModel;
18 
19 /**
20  * Touch controller for handling edge swipes in landscape/seascape UI
21  */
22 public class LandscapeEdgeSwipeController extends AbstractStateChangeTouchController {
23 
24     private static final String TAG = "LandscapeEdgeSwipeCtrl";
25 
LandscapeEdgeSwipeController(Launcher l)26     public LandscapeEdgeSwipeController(Launcher l) {
27         super(l, SwipeDetector.HORIZONTAL);
28     }
29 
30     @Override
canInterceptTouch(MotionEvent ev)31     protected boolean canInterceptTouch(MotionEvent ev) {
32         if (mCurrentAnimation != null) {
33             // If we are already animating from a previous state, we can intercept.
34             return true;
35         }
36         if (AbstractFloatingView.getTopOpenView(mLauncher) != null) {
37             return false;
38         }
39         return mLauncher.isInState(NORMAL) && (ev.getEdgeFlags() & EDGE_NAV_BAR) != 0;
40     }
41 
42     @Override
getTargetState(LauncherState fromState, boolean isDragTowardPositive)43     protected LauncherState getTargetState(LauncherState fromState, boolean isDragTowardPositive) {
44         boolean draggingFromNav = mLauncher.getDeviceProfile().isSeascape() == isDragTowardPositive;
45         return draggingFromNav ? OVERVIEW : NORMAL;
46     }
47 
48     @Override
getLogContainerTypeForNormalState()49     protected int getLogContainerTypeForNormalState() {
50         return LauncherLogProto.ContainerType.NAVBAR;
51     }
52 
53     @Override
getShiftRange()54     protected float getShiftRange() {
55         return mLauncher.getDragLayer().getWidth();
56     }
57 
58     @Override
initCurrentAnimation(@nimationComponents int animComponent)59     protected float initCurrentAnimation(@AnimationComponents int animComponent) {
60         float range = getShiftRange();
61         long maxAccuracy = (long) (2 * range);
62         mCurrentAnimation = mLauncher.getStateManager().createAnimationToNewWorkspace(mToState,
63                 maxAccuracy, animComponent);
64         return (mLauncher.getDeviceProfile().isSeascape() ? 2 : -2) / range;
65     }
66 
67     @Override
getDirectionForLog()68     protected int getDirectionForLog() {
69         return mLauncher.getDeviceProfile().isSeascape() ? Direction.RIGHT : Direction.LEFT;
70     }
71 
72     @Override
onSwipeInteractionCompleted(LauncherState targetState, int logAction)73     protected void onSwipeInteractionCompleted(LauncherState targetState, int logAction) {
74         super.onSwipeInteractionCompleted(targetState, logAction);
75         if (mStartState == NORMAL && targetState == OVERVIEW) {
76             RecentsModel.INSTANCE.get(mLauncher).onOverviewShown(true, TAG);
77         }
78     }
79 }
80