| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.back; |
| 18 |
|
| 19 |
import android.os.SystemProperties; |
| 20 |
import android.view.RemoteAnimationTarget; |
| 21 |
import android.window.BackEvent; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
class TouchTracker { |
| 27 |
private static final String PREDICTIVE_BACK_PROGRESS_THRESHOLD_PROP = |
| 28 |
"persist.wm.debug.predictive_back_progress_threshold"; |
| 29 |
private static final int PROGRESS_THRESHOLD = SystemProperties |
| 30 |
.getInt(PREDICTIVE_BACK_PROGRESS_THRESHOLD_PROP, -1); |
| 31 |
private float mProgressThreshold; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
private float mLatestTouchX; |
| 36 |
private float mLatestTouchY; |
| 37 |
private boolean mTriggerBack; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
private float mInitTouchX; |
| 43 |
private float mInitTouchY; |
| 44 |
private float mStartThresholdX; |
| 45 |
private int mSwipeEdge; |
| 46 |
private boolean mCancelled; |
| 47 |
|
| 48 |
void update(float touchX, float touchY) { |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
if (mCancelled && ((touchX > mLatestTouchX && mSwipeEdge == BackEvent.EDGE_LEFT) |
| 54 |
|| touchX < mLatestTouchX && mSwipeEdge == BackEvent.EDGE_RIGHT)) { |
| 55 |
mCancelled = false; |
| 56 |
mStartThresholdX = touchX; |
| 57 |
} |
| 58 |
mLatestTouchX = touchX; |
| 59 |
mLatestTouchY = touchY; |
| 60 |
} |
| 61 |
|
| 62 |
void setTriggerBack(boolean triggerBack) { |
| 63 |
if (mTriggerBack != triggerBack && !triggerBack) { |
| 64 |
mCancelled = true; |
| 65 |
} |
| 66 |
mTriggerBack = triggerBack; |
| 67 |
} |
| 68 |
|
| 69 |
void setGestureStartLocation(float touchX, float touchY, int swipeEdge) { |
| 70 |
mInitTouchX = touchX; |
| 71 |
mInitTouchY = touchY; |
| 72 |
mSwipeEdge = swipeEdge; |
| 73 |
mStartThresholdX = mInitTouchX; |
| 74 |
} |
| 75 |
|
| 76 |
void reset() { |
| 77 |
mInitTouchX = 0; |
| 78 |
mInitTouchY = 0; |
| 79 |
mStartThresholdX = 0; |
| 80 |
mCancelled = false; |
| 81 |
mTriggerBack = false; |
| 82 |
mSwipeEdge = BackEvent.EDGE_LEFT; |
| 83 |
} |
| 84 |
|
| 85 |
BackEvent createStartEvent(RemoteAnimationTarget target) { |
| 86 |
return new BackEvent(mInitTouchX, mInitTouchY, 0, mSwipeEdge, target); |
| 87 |
} |
| 88 |
|
| 89 |
BackEvent createProgressEvent() { |
| 90 |
float progressThreshold = PROGRESS_THRESHOLD >= 0 |
| 91 |
? PROGRESS_THRESHOLD : mProgressThreshold; |
| 92 |
progressThreshold = progressThreshold == 0 ? 1 : progressThreshold; |
| 93 |
float progress = 0; |
| 94 |
|
| 95 |
if (!mCancelled) { |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
float startX = mTriggerBack ? mInitTouchX : mStartThresholdX; |
| 102 |
float deltaX = Math.max( |
| 103 |
mSwipeEdge == BackEvent.EDGE_LEFT |
| 104 |
? mLatestTouchX - startX |
| 105 |
: startX - mLatestTouchX, |
| 106 |
0); |
| 107 |
progress = Math.min(Math.max(deltaX / progressThreshold, 0), 1); |
| 108 |
} |
| 109 |
return createProgressEvent(progress); |
| 110 |
} |
| 111 |
|
| 112 |
BackEvent createProgressEvent(float progress) { |
| 113 |
return new BackEvent(mLatestTouchX, mLatestTouchY, progress, mSwipeEdge, null); |
| 114 |
} |
| 115 |
|
| 116 |
public void setProgressThreshold(float progressThreshold) { |
| 117 |
mProgressThreshold = progressThreshold; |
| 118 |
} |
| 119 |
} |