Skip to content

Commit 4020953

Browse files
committed
Adjust mBiggerTouchSlopSquare to the suitable value
If the scaling factor is larger than 1.0 (i.e. 1.5), then mTouchSlopSquare(576) is bigger than mBiggerTouchSlopSquare(400). The double tap condition should be bigger than a single tap's one. This causes the fail of the following CTS test cases in the device has over 240 density. - android.view.cts.GestureDetectorTest * testOnTouchEvent - android.view.cts.GestureDetector_SimpleOnGestureListenerTest * testSimpleOnGestureListener To fix this issue, I'll add a new public method ViewConfiguration#getScaledLargeTouchSlop() then the value returned from that method is used as a slop area of mLargeTouchSlop. Change-Id: I0e61c13670e1300be1ccf45a89ef89410496fb48
1 parent a220a29 commit 4020953

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

api/current.xml

100644100755
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190704,6 +190704,17 @@
190704190704
visibility="public"
190705190705
>
190706190706
</method>
190707+
<method name="getScaledLargeTouchSlop"
190708+
return="int"
190709+
abstract="false"
190710+
native="false"
190711+
synchronized="false"
190712+
static="false"
190713+
final="false"
190714+
deprecated="not deprecated"
190715+
visibility="public"
190716+
>
190717+
</method>
190707190718
<method name="getScaledMaximumDrawingCacheSize"
190708190719
return="int"
190709190720
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)