Skip to content

Commit adb9388

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Delay starting scale gesture events until a touch slop threshold" into jb-mr1-dev
2 parents f1ffb4f + 47ec2fb commit adb9388

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

core/java/android/view/ScaleGestureDetector.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public interface OnScaleGestureListener {
8686
* pointers going up.
8787
*
8888
* Once a scale has ended, {@link ScaleGestureDetector#getFocusX()}
89-
* and {@link ScaleGestureDetector#getFocusY()} will return the location
90-
* of the pointer remaining on the screen.
89+
* and {@link ScaleGestureDetector#getFocusY()} will return focal point
90+
* of the pointers remaining on the screen.
9191
*
9292
* @param detector The detector reporting the event - use this to
9393
* retrieve extended info about event state.
@@ -128,13 +128,15 @@ public void onScaleEnd(ScaleGestureDetector detector) {
128128

129129
private float mCurrSpan;
130130
private float mPrevSpan;
131+
private float mInitialSpan;
131132
private float mCurrSpanX;
132133
private float mCurrSpanY;
133134
private float mPrevSpanX;
134135
private float mPrevSpanY;
135136
private long mCurrTime;
136137
private long mPrevTime;
137138
private boolean mInProgress;
139+
private int mSpanSlop;
138140

139141
/**
140142
* Consistency verifier for debugging purposes.
@@ -146,6 +148,7 @@ public void onScaleEnd(ScaleGestureDetector detector) {
146148
public ScaleGestureDetector(Context context, OnScaleGestureListener listener) {
147149
mContext = context;
148150
mListener = listener;
151+
mSpanSlop = ViewConfiguration.get(context).getScaledTouchSlop() * 2;
149152
}
150153

151154
/**
@@ -176,6 +179,7 @@ public boolean onTouchEvent(MotionEvent event) {
176179
if (mInProgress) {
177180
mListener.onScaleEnd(this);
178181
mInProgress = false;
182+
mInitialSpan = 0;
179183
}
180184

181185
if (streamComplete) {
@@ -221,18 +225,24 @@ public boolean onTouchEvent(MotionEvent event) {
221225
// Dispatch begin/end events as needed.
222226
// If the configuration changes, notify the app to reset its current state by beginning
223227
// a fresh scale event stream.
228+
final boolean wasInProgress = mInProgress;
229+
mFocusX = focusX;
230+
mFocusY = focusY;
224231
if (mInProgress && (span == 0 || configChanged)) {
225232
mListener.onScaleEnd(this);
226233
mInProgress = false;
234+
mInitialSpan = span;
227235
}
228236
if (configChanged) {
229237
mPrevSpanX = mCurrSpanX = spanX;
230238
mPrevSpanY = mCurrSpanY = spanY;
231-
mPrevSpan = mCurrSpan = span;
239+
mInitialSpan = mPrevSpan = mCurrSpan = span;
232240
}
233-
if (!mInProgress && span != 0) {
234-
mFocusX = focusX;
235-
mFocusY = focusY;
241+
if (!mInProgress && span != 0 &&
242+
(wasInProgress || Math.abs(span - mInitialSpan) > mSpanSlop)) {
243+
mPrevSpanX = mCurrSpanX = spanX;
244+
mPrevSpanY = mCurrSpanY = spanY;
245+
mPrevSpan = mCurrSpan = span;
236246
mInProgress = mListener.onScaleBegin(this);
237247
}
238248

@@ -241,8 +251,6 @@ public boolean onTouchEvent(MotionEvent event) {
241251
mCurrSpanX = spanX;
242252
mCurrSpanY = spanY;
243253
mCurrSpan = span;
244-
mFocusX = focusX;
245-
mFocusY = focusY;
246254

247255
boolean updatePrev = true;
248256
if (mInProgress) {

0 commit comments

Comments
 (0)