Skip to content

Commit eb8171b

Browse files
cco3Android Code Review
authored andcommitted
Merge "Adjust mBiggerTouchSlopSquare to the suitable value"
2 parents 76616b1 + 4020953 commit eb8171b

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

api/current.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192791,6 +192791,17 @@
192791192791
visibility="public"
192792192792
>
192793192793
</method>
192794+
<method name="getScaledLargeTouchSlop"
192795+
return="int"
192796+
abstract="false"
192797+
native="false"
192798+
synchronized="false"
192799+
static="false"
192800+
final="false"
192801+
deprecated="not deprecated"
192802+
visibility="public"
192803+
>
192804+
</method>
192794192805
<method name="getScaledMaximumDrawingCacheSize"
192795192806
return="int"
192796192807
abstract="false"

core/java/android/view/GestureDetector.java

100644100755
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,8 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
193193
}
194194
}
195195

196-
// TODO: ViewConfiguration
197-
private int mBiggerTouchSlopSquare = 20 * 20;
198-
199196
private int mTouchSlopSquare;
197+
private int mLargeTouchSlopSquare;
200198
private int mDoubleTapSlopSquare;
201199
private int mMinimumFlingVelocity;
202200
private int mMaximumFlingVelocity;
@@ -384,22 +382,25 @@ private void init(Context context, boolean ignoreMultitouch) {
384382
mIgnoreMultitouch = ignoreMultitouch;
385383

386384
// Fallback to support pre-donuts releases
387-
int touchSlop, doubleTapSlop;
385+
int touchSlop, largeTouchSlop, doubleTapSlop;
388386
if (context == null) {
389387
//noinspection deprecation
390388
touchSlop = ViewConfiguration.getTouchSlop();
389+
largeTouchSlop = touchSlop + 2;
391390
doubleTapSlop = ViewConfiguration.getDoubleTapSlop();
392391
//noinspection deprecation
393392
mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
394393
mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity();
395394
} else {
396395
final ViewConfiguration configuration = ViewConfiguration.get(context);
397396
touchSlop = configuration.getScaledTouchSlop();
397+
largeTouchSlop = configuration.getScaledLargeTouchSlop();
398398
doubleTapSlop = configuration.getScaledDoubleTapSlop();
399399
mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
400400
mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity();
401401
}
402402
mTouchSlopSquare = touchSlop * touchSlop;
403+
mLargeTouchSlopSquare = largeTouchSlop * largeTouchSlop;
403404
mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop;
404405
}
405406

@@ -534,7 +535,7 @@ public boolean onTouchEvent(MotionEvent ev) {
534535
mHandler.removeMessages(SHOW_PRESS);
535536
mHandler.removeMessages(LONG_PRESS);
536537
}
537-
if (distance > mBiggerTouchSlopSquare) {
538+
if (distance > mLargeTouchSlopSquare) {
538539
mAlwaysInBiggerTapRegion = false;
539540
}
540541
} else if ((Math.abs(scrollX) >= 1) || (Math.abs(scrollY) >= 1)) {

core/java/android/view/ViewConfiguration.java

100644100755
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ public class ViewConfiguration {
101101
*/
102102
private static final int TOUCH_SLOP = 16;
103103

104+
/**
105+
* Distance a touch can wander before we think the user is the first touch
106+
* in a sequence of double tap
107+
*/
108+
private static final int LARGE_TOUCH_SLOP = 18;
109+
104110
/**
105111
* Distance a touch can wander before we think the user is attempting a paged scroll
106112
* (in dips)
@@ -156,6 +162,7 @@ public class ViewConfiguration {
156162
private final int mMaximumFlingVelocity;
157163
private final int mScrollbarSize;
158164
private final int mTouchSlop;
165+
private final int mLargeTouchSlop;
159166
private final int mPagingTouchSlop;
160167
private final int mDoubleTapSlop;
161168
private final int mWindowTouchSlop;
@@ -177,6 +184,7 @@ public ViewConfiguration() {
177184
mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
178185
mScrollbarSize = SCROLL_BAR_SIZE;
179186
mTouchSlop = TOUCH_SLOP;
187+
mLargeTouchSlop = LARGE_TOUCH_SLOP;
180188
mPagingTouchSlop = PAGING_TOUCH_SLOP;
181189
mDoubleTapSlop = DOUBLE_TAP_SLOP;
182190
mWindowTouchSlop = WINDOW_TOUCH_SLOP;
@@ -206,6 +214,7 @@ private ViewConfiguration(Context context) {
206214
mMaximumFlingVelocity = (int) (density * MAXIMUM_FLING_VELOCITY + 0.5f);
207215
mScrollbarSize = (int) (density * SCROLL_BAR_SIZE + 0.5f);
208216
mTouchSlop = (int) (density * TOUCH_SLOP + 0.5f);
217+
mLargeTouchSlop = (int) (density * LARGE_TOUCH_SLOP + 0.5f);
209218
mPagingTouchSlop = (int) (density * PAGING_TOUCH_SLOP + 0.5f);
210219
mDoubleTapSlop = (int) (density * DOUBLE_TAP_SLOP + 0.5f);
211220
mWindowTouchSlop = (int) (density * WINDOW_TOUCH_SLOP + 0.5f);
@@ -366,6 +375,14 @@ public int getScaledTouchSlop() {
366375
return mTouchSlop;
367376
}
368377

378+
/**
379+
* @return Distance a touch can wander before we think the user is the first touch
380+
* in a sequence of double tap
381+
*/
382+
public int getScaledLargeTouchSlop() {
383+
return mLargeTouchSlop;
384+
}
385+
369386
/**
370387
* @return Distance a touch can wander before we think the user is scrolling a full page
371388
* in dips

0 commit comments

Comments
 (0)