• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.launcher3.uioverrides;
17 
18 import static com.android.launcher3.LauncherState.ALL_APPS;
19 import static com.android.launcher3.LauncherState.NORMAL;
20 import static com.android.launcher3.LauncherState.OVERVIEW;
21 
22 import android.view.MotionEvent;
23 
24 import com.android.launcher3.AbstractFloatingView;
25 import com.android.launcher3.Launcher;
26 import com.android.launcher3.LauncherState;
27 import com.android.launcher3.userevent.nano.LauncherLogProto;
28 import com.android.quickstep.TouchInteractionService;
29 import com.android.quickstep.views.RecentsView;
30 
31 /**
32  * Touch controller from going from OVERVIEW to ALL_APPS.
33  *
34  * This is used in landscape mode. It is also used in portrait mode for the fallback recents.
35  */
36 public class OverviewToAllAppsTouchController extends PortraitStatesTouchController {
37 
OverviewToAllAppsTouchController(Launcher l)38     public OverviewToAllAppsTouchController(Launcher l) {
39         super(l);
40     }
41 
42     @Override
canInterceptTouch(MotionEvent ev)43     protected boolean canInterceptTouch(MotionEvent ev) {
44         if (mCurrentAnimation != null) {
45             // If we are already animating from a previous state, we can intercept.
46             return true;
47         }
48         if (AbstractFloatingView.getTopOpenView(mLauncher) != null) {
49             return false;
50         }
51         if (mLauncher.isInState(ALL_APPS)) {
52             // In all-apps only listen if the container cannot scroll itself
53             return mLauncher.getAppsView().shouldContainerScroll(ev);
54         } else if (mLauncher.isInState(NORMAL)) {
55             return true;
56         } else if (mLauncher.isInState(OVERVIEW)) {
57             RecentsView rv = mLauncher.getOverviewPanel();
58             return ev.getY() > (rv.getBottom() - rv.getPaddingBottom());
59         } else {
60             return false;
61         }
62     }
63 
64     @Override
getTargetState(LauncherState fromState, boolean isDragTowardPositive)65     protected LauncherState getTargetState(LauncherState fromState, boolean isDragTowardPositive) {
66         if (fromState == ALL_APPS && !isDragTowardPositive) {
67             // Should swipe down go to OVERVIEW instead?
68             return TouchInteractionService.isConnected() ?
69                     mLauncher.getStateManager().getLastState() : NORMAL;
70         } else if (isDragTowardPositive) {
71             return ALL_APPS;
72         }
73         return fromState;
74     }
75 
76     @Override
getLogContainerTypeForNormalState()77     protected int getLogContainerTypeForNormalState() {
78         return LauncherLogProto.ContainerType.WORKSPACE;
79     }
80 }
81