• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.launcher3.uioverrides;
2 
3 import static com.android.launcher3.LauncherState.ALL_APPS;
4 import static com.android.launcher3.LauncherState.NORMAL;
5 
6 import android.view.MotionEvent;
7 
8 import com.android.launcher3.AbstractFloatingView;
9 import com.android.launcher3.Launcher;
10 import com.android.launcher3.LauncherState;
11 import com.android.launcher3.LauncherStateManager.AnimationComponents;
12 import com.android.launcher3.touch.AbstractStateChangeTouchController;
13 import com.android.launcher3.touch.SwipeDetector;
14 import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
15 
16 /**
17  * TouchController to switch between NORMAL and ALL_APPS state.
18  */
19 public class AllAppsSwipeController extends AbstractStateChangeTouchController {
20 
21     private MotionEvent mTouchDownEvent;
22 
AllAppsSwipeController(Launcher l)23     public AllAppsSwipeController(Launcher l) {
24         super(l, SwipeDetector.VERTICAL);
25     }
26 
27     @Override
canInterceptTouch(MotionEvent ev)28     protected boolean canInterceptTouch(MotionEvent ev) {
29         if (ev.getAction() == MotionEvent.ACTION_DOWN) {
30             mTouchDownEvent = ev;
31         }
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         if (!mLauncher.isInState(NORMAL) && !mLauncher.isInState(ALL_APPS)) {
40             // Don't listen for the swipe gesture if we are already in some other state.
41             return false;
42         }
43         if (mLauncher.isInState(ALL_APPS) && !mLauncher.getAppsView().shouldContainerScroll(ev)) {
44             return false;
45         }
46         return true;
47     }
48 
49     @Override
getTargetState(LauncherState fromState, boolean isDragTowardPositive)50     protected LauncherState getTargetState(LauncherState fromState, boolean isDragTowardPositive) {
51         if (fromState == NORMAL && isDragTowardPositive) {
52             return ALL_APPS;
53         } else if (fromState == ALL_APPS && !isDragTowardPositive) {
54             return NORMAL;
55         }
56         return fromState;
57     }
58 
59     @Override
getLogContainerTypeForNormalState()60     protected int getLogContainerTypeForNormalState() {
61         return mLauncher.getDragLayer().isEventOverView(mLauncher.getHotseat(), mTouchDownEvent) ?
62                 ContainerType.HOTSEAT : ContainerType.WORKSPACE;
63     }
64 
65     @Override
initCurrentAnimation(@nimationComponents int animComponents)66     protected float initCurrentAnimation(@AnimationComponents int animComponents) {
67         float range = getShiftRange();
68         long maxAccuracy = (long) (2 * range);
69         mCurrentAnimation = mLauncher.getStateManager()
70                 .createAnimationToNewWorkspace(mToState, maxAccuracy, animComponents);
71         float startVerticalShift = mFromState.getVerticalProgress(mLauncher) * range;
72         float endVerticalShift = mToState.getVerticalProgress(mLauncher) * range;
73         float totalShift = endVerticalShift - startVerticalShift;
74         return 1 / totalShift;
75     }
76 }
77