Allow customization of touch handler.
Add #setTouchHandler to PipManager so that other devices (e.g. TV,
Chrome OS) may set its own touch handler to overwrite the default one.
Bug: 148407130
Test: Set a custom touch handler, note it being used instead of the
default one
Change-Id: Ice3a57a700926b474b29dec1e0b3a8503501477b
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
index f39d1ec..e48a23f 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
@@ -297,6 +297,13 @@
}
/**
+ * Sets a customized touch gesture that replaces the default one.
+ */
+ public void setTouchGesture(PipTouchGesture gesture) {
+ mTouchHandler.setTouchGesture(gesture);
+ }
+
+ /**
* Sets both shelf visibility and its height.
*/
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchGesture.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchGesture.java
index e8e8a4d..72335db 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchGesture.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchGesture.java
@@ -24,19 +24,19 @@
/**
* Handle the touch down.
*/
- void onDown(PipTouchState touchState) {}
+ public void onDown(PipTouchState touchState) {}
/**
* Handle the touch move, and return whether the event was consumed.
*/
- boolean onMove(PipTouchState touchState) {
+ public boolean onMove(PipTouchState touchState) {
return false;
}
/**
* Handle the touch up, and return whether the gesture was consumed.
*/
- boolean onUp(PipTouchState touchState) {
+ public boolean onUp(PipTouchState touchState) {
return false;
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
index 09f1638..65cc666 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
@@ -126,8 +126,8 @@
// Touch state
private final PipTouchState mTouchState;
private final FlingAnimationUtils mFlingAnimationUtils;
- private final PipTouchGesture[] mGestures;
private final PipMotionHelper mMotionHelper;
+ private PipTouchGesture mGesture;
// Temp vars
private final Rect mTmpBounds = new Rect();
@@ -185,9 +185,7 @@
mSnapAlgorithm = new PipSnapAlgorithm(mContext);
mFlingAnimationUtils = new FlingAnimationUtils(context.getResources().getDisplayMetrics(),
2.5f);
- mGestures = new PipTouchGesture[] {
- mDefaultMovementGesture
- };
+ mGesture = new DefaultPipTouchGesture();
mMotionHelper = new PipMotionHelper(mContext, mActivityManager, mActivityTaskManager,
mMenuController, mSnapAlgorithm, mFlingAnimationUtils);
mTouchState = new PipTouchState(mViewConfig, mHandler,
@@ -210,6 +208,10 @@
this::onAccessibilityShowMenu, mHandler);
}
+ public void setTouchGesture(PipTouchGesture gesture) {
+ mGesture = gesture;
+ }
+
public void setTouchEnabled(boolean enabled) {
mTouchState.setAllowTouches(enabled);
}
@@ -363,17 +365,12 @@
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
mMotionHelper.synchronizePinnedStackBounds();
-
- for (PipTouchGesture gesture : mGestures) {
- gesture.onDown(mTouchState);
- }
+ mGesture.onDown(mTouchState);
break;
}
case MotionEvent.ACTION_MOVE: {
- for (PipTouchGesture gesture : mGestures) {
- if (gesture.onMove(mTouchState)) {
- break;
- }
+ if (mGesture.onMove(mTouchState)) {
+ break;
}
shouldDeliverToMenu = !mTouchState.isDragging();
@@ -384,10 +381,8 @@
// dragging (ie. when the IME shows)
updateMovementBounds(mMenuState);
- for (PipTouchGesture gesture : mGestures) {
- if (gesture.onUp(mTouchState)) {
- break;
- }
+ if (mGesture.onUp(mTouchState)) {
+ break;
}
// Fall through to clean up
@@ -591,7 +586,7 @@
/**
* Gesture controlling normal movement of the PIP.
*/
- private PipTouchGesture mDefaultMovementGesture = new PipTouchGesture() {
+ private class DefaultPipTouchGesture extends PipTouchGesture {
// Whether the PiP was on the left side of the screen at the start of the gesture
private boolean mStartedOnLeft;
private final Point mStartPosition = new Point();
@@ -623,7 +618,7 @@
}
@Override
- boolean onMove(PipTouchState touchState) {
+ public boolean onMove(PipTouchState touchState) {
if (!touchState.isUserInteracting()) {
return false;
}