Use onQuickStep call from SysUI

Change-Id: I838ef4de2d86abde1848efd757a523c088016756
This commit is contained in:
Winson Chung
2018-03-28 10:19:44 -07:00
parent ef77fd0f40
commit 19adf653bd
4 changed files with 43 additions and 22 deletions
@@ -53,6 +53,8 @@ public class MotionEventQueue {
ACTION_VIRTUAL | (5 << ACTION_POINTER_INDEX_SHIFT);
private static final int ACTION_SHOW_OVERVIEW_FROM_ALT_TAB =
ACTION_VIRTUAL | (6 << ACTION_POINTER_INDEX_SHIFT);
private static final int ACTION_QUICK_STEP =
ACTION_VIRTUAL | (7 << ACTION_POINTER_INDEX_SHIFT);
private final EventArray mEmptyArray = new EventArray();
private final Object mExecutionLock = new Object();
@@ -160,6 +162,9 @@ public class MotionEventQueue {
mConsumer.onShowOverviewFromAltTab();
mConsumer.updateTouchTracking(INTERACTION_QUICK_SCRUB);
break;
case ACTION_QUICK_STEP:
mConsumer.onQuickStep(event.getX(), event.getY(), event.getEventTime());
break;
default:
Log.e(TAG, "Invalid virtual event: " + event.getAction());
}
@@ -204,6 +209,11 @@ public class MotionEventQueue {
queueVirtualAction(ACTION_QUICK_SCRUB_END, 0);
}
public void onQuickStep(MotionEvent event) {
event.setAction(ACTION_QUICK_STEP);
queueNoPreProcess(event);
}
public void reset() {
queueVirtualAction(ACTION_RESET, 0);
}
@@ -79,7 +79,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
private final PointF mDownPos = new PointF();
private final PointF mLastPos = new PointF();
private int mActivePointerId = INVALID_POINTER_ID;
private boolean mTouchThresholdCrossed;
private boolean mGestureStarted;
private int mTouchSlop;
private float mStartDisplacement;
private WindowTransformSwipeHandler mInteractionHandler;
@@ -122,7 +122,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
mDownPos.set(ev.getX(), ev.getY());
mLastPos.set(mDownPos);
mTouchSlop = ViewConfiguration.get(this).getScaledPagingTouchSlop();
mTouchThresholdCrossed = false;
mGestureStarted = false;
// Start the window animation on down to give more time for launcher to draw if the
// user didn't start the gesture over the back button
@@ -155,26 +155,10 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
}
mLastPos.set(ev.getX(pointerIndex), ev.getY(pointerIndex));
float displacement = ev.getY(pointerIndex) - mDownPos.y;
if (isNavBarOnRight()) {
displacement = ev.getX(pointerIndex) - mDownPos.x;
} else if (isNavBarOnLeft()) {
displacement = mDownPos.x - ev.getX(pointerIndex);
}
if (!mTouchThresholdCrossed) {
mTouchThresholdCrossed = Math.abs(displacement) >= mTouchSlop;
if (mTouchThresholdCrossed) {
mStartDisplacement = Math.signum(displacement) * mTouchSlop;
if (mIsDeferredDownTarget) {
// If we deferred starting the window animation on touch down, then
// start tracking now
startTouchTrackingForWindowAnimation(ev.getEventTime());
}
notifyGestureStarted();
}
} else if (mInteractionHandler != null) {
if (mGestureStarted && mInteractionHandler != null) {
// Move
float displacement = getDisplacement(ev.getX(pointerIndex),
ev.getY(pointerIndex));
mInteractionHandler.updateDisplacement(displacement - mStartDisplacement);
}
break;
@@ -195,6 +179,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
return;
}
// Notify the handler that the gesture has actually started
mGestureStarted = true;
mInteractionHandler.onGestureStarted();
}
@@ -276,7 +261,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
* the animation can still be running.
*/
private void finishTouchTracking() {
if (mTouchThresholdCrossed && mInteractionHandler != null) {
if (mGestureStarted && mInteractionHandler != null) {
mVelocityTracker.computeCurrentVelocity(1000,
ViewConfiguration.get(this).getScaledMaximumFlingVelocity());
@@ -336,6 +321,28 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
}
}
@Override
public void onQuickStep(float eventX, float eventY, long eventTime) {
float displacement = getDisplacement(eventX, eventY);
mStartDisplacement = Math.signum(displacement) * mTouchSlop;
if (mIsDeferredDownTarget) {
// If we deferred starting the window animation on touch down, then
// start tracking now
startTouchTrackingForWindowAnimation(eventTime);
}
notifyGestureStarted();
}
private float getDisplacement(float eventX, float eventY) {
float displacement = eventY - mDownPos.y;
if (isNavBarOnRight()) {
displacement = eventX - mDownPos.x;
} else if (isNavBarOnLeft()) {
displacement = mDownPos.x - eventX;
}
return displacement;
}
public void switchToMainChoreographer() {
mEventQueue.setInterimChoreographer(null);
}
@@ -46,6 +46,8 @@ public interface TouchConsumer extends Consumer<MotionEvent> {
default void onQuickScrubProgress(float progress) { }
default void onQuickStep(float eventX, float eventY, long eventTime) { }
/**
* Called on the binder thread to allow the consumer to process the motion event before it is
* posted on a handler thread.
@@ -153,6 +153,8 @@ public class TouchInteractionService extends Service {
@Override
public void onQuickStep(MotionEvent motionEvent) {
mEventQueue.onQuickStep(motionEvent);
TraceHelper.endSection("SysUiBinder", "onQuickStep");
}
};