• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.quickstep.fallback;
17 
18 import android.graphics.PointF;
19 import android.view.MotionEvent;
20 
21 import androidx.annotation.Nullable;
22 
23 import com.android.launcher3.Utilities;
24 import com.android.launcher3.util.DisplayController;
25 import com.android.launcher3.util.NavigationMode;
26 import com.android.launcher3.util.TouchController;
27 import com.android.quickstep.util.NavBarPosition;
28 import com.android.quickstep.util.TriggerSwipeUpTouchTracker;
29 import com.android.quickstep.views.RecentsViewContainer;
30 
31 /**
32  * In 0-button mode, intercepts swipe up from the nav bar on FallbackRecentsView to go home.
33  */
34 public class FallbackNavBarTouchController implements TouchController,
35         TriggerSwipeUpTouchTracker.OnSwipeUpListener {
36 
37     private final RecentsViewContainer mContainer;
38     @Nullable
39     private final TriggerSwipeUpTouchTracker mTriggerSwipeUpTracker;
40 
FallbackNavBarTouchController(RecentsViewContainer container)41     public FallbackNavBarTouchController(RecentsViewContainer container) {
42         mContainer = container;
43         NavigationMode sysUINavigationMode =
44                 DisplayController.getNavigationMode(mContainer.asContext());
45         if (sysUINavigationMode == NavigationMode.NO_BUTTON) {
46             NavBarPosition navBarPosition = new NavBarPosition(sysUINavigationMode,
47                     DisplayController.INSTANCE.get(mContainer.asContext()).getInfo());
48             mTriggerSwipeUpTracker = new TriggerSwipeUpTouchTracker(mContainer.asContext(),
49                     true /* disableHorizontalSwipe */, navBarPosition, this);
50         } else {
51             mTriggerSwipeUpTracker = null;
52         }
53     }
54 
55     @Override
onControllerInterceptTouchEvent(MotionEvent ev)56     public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
57         boolean cameFromNavBar = (ev.getEdgeFlags() & Utilities.EDGE_NAV_BAR) != 0;
58         if (cameFromNavBar && mTriggerSwipeUpTracker != null) {
59             if (ev.getAction() == MotionEvent.ACTION_DOWN) {
60                 mTriggerSwipeUpTracker.init();
61             }
62             onControllerTouchEvent(ev);
63             return mTriggerSwipeUpTracker.interceptedTouch();
64         }
65         return false;
66     }
67 
68     @Override
onControllerTouchEvent(MotionEvent ev)69     public boolean onControllerTouchEvent(MotionEvent ev) {
70         if (mTriggerSwipeUpTracker != null) {
71             mTriggerSwipeUpTracker.onMotionEvent(ev);
72             return true;
73         }
74         return false;
75     }
76 
77     @Override
onSwipeUp(boolean wasFling, PointF finalVelocity)78     public void onSwipeUp(boolean wasFling, PointF finalVelocity) {
79         mContainer.<FallbackRecentsView>getOverviewPanel().startHome();
80     }
81 }
82