| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 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 |
|
| 57 |
|
| 58 |
|
| 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 |
} |