Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblesNavBarGestureTracker.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 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
17 package com.android.wm.shell.bubbles;
18
19 import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_BUBBLES;
20 import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME;
21
22 import android.content.Context;
23 import android.hardware.input.InputManager;
24 import android.util.Log;
25 import android.view.Choreographer;
26 import android.view.InputChannel;
27 import android.view.InputEventReceiver;
28 import android.view.InputMonitor;
29
30 import androidx.annotation.Nullable;
31
32 import com.android.wm.shell.bubbles.BubblesNavBarMotionEventHandler.MotionEventListener;
33
34 /**
35 * Set up tracking bubbles gestures that begin in navigation bar
36 */
37 class BubblesNavBarGestureTracker {
38
39 private static final String TAG = TAG_WITH_CLASS_NAME ? "BubblesGestureTracker" : TAG_BUBBLES;
40
41 private static final String GESTURE_MONITOR = "bubbles-gesture";
42 private final Context mContext;
43 private final BubblePositioner mPositioner;
44
45 @Nullable
46 private InputMonitor mInputMonitor;
47 @Nullable
48 private InputEventReceiver mInputEventReceiver;
49
50 BubblesNavBarGestureTracker(Context context, BubblePositioner positioner) {
51 mContext = context;
52 mPositioner = positioner;
53 }
54
55 /**
56 * Start tracking gestures
57 *
58 * @param listener listener that is notified of touch events
59 */
60 void start(MotionEventListener listener) {
61 if (BubbleDebugConfig.DEBUG_BUBBLE_GESTURE) {
62 Log.d(TAG, "start monitoring bubbles swipe up gesture");
63 }
64
65 stopInternal();
66
67 mInputMonitor = InputManager.getInstance().monitorGestureInput(GESTURE_MONITOR,
68 mContext.getDisplayId());
69 InputChannel inputChannel = mInputMonitor.getInputChannel();
70
71 BubblesNavBarMotionEventHandler motionEventHandler =
72 new BubblesNavBarMotionEventHandler(mContext, mPositioner,
73 this::onInterceptTouch, listener);
74 mInputEventReceiver = new BubblesNavBarInputEventReceiver(inputChannel,
75 Choreographer.getInstance(), motionEventHandler);
76 }
77
78 void stop() {
79 if (BubbleDebugConfig.DEBUG_BUBBLE_GESTURE) {
80 Log.d(TAG, "stop monitoring bubbles swipe up gesture");
81 }
82 stopInternal();
83 }
84
85 private void stopInternal() {
86 if (mInputEventReceiver != null) {
87 mInputEventReceiver.dispose();
88 mInputEventReceiver = null;
89 }
90 if (mInputMonitor != null) {
91 mInputMonitor.dispose();
92 mInputMonitor = null;
93 }
94 }
95
96 private void onInterceptTouch() {
97 if (BubbleDebugConfig.DEBUG_BUBBLE_GESTURE) {
98 Log.d(TAG, "intercept touch event");
99 }
100 if (mInputMonitor != null) {
101 mInputMonitor.pilferPointers();
102 }
103 }
104 }