Cleaning and new constant in ViewConfiguration
Fixed the documentation and comments for dips versus pixels.
Added a new DOUBLE_TAP_TOUCH_SLOP to replace the hard-coded and
*unscaled* value used in GestureDetector. Assuming this value was
ok for hdpi devices, set it to 20 / 1.5 ~= 16 in dips.
New method kept hidden to keep API unchanged.
Change-Id: I6d237faa2fdb7714e0e3558978af130df9a061a5
diff --git a/core/java/android/view/GestureDetector.java b/core/java/android/view/GestureDetector.java
index a496a9e..25d08ac 100644
--- a/core/java/android/view/GestureDetector.java
+++ b/core/java/android/view/GestureDetector.java
@@ -193,10 +193,8 @@
}
}
- // TODO: ViewConfiguration
- private int mBiggerTouchSlopSquare = 20 * 20;
-
private int mTouchSlopSquare;
+ private int mDoubleTapTouchSlopSquare;
private int mDoubleTapSlopSquare;
private int mMinimumFlingVelocity;
private int mMaximumFlingVelocity;
@@ -391,10 +389,11 @@
mIgnoreMultitouch = ignoreMultitouch;
// Fallback to support pre-donuts releases
- int touchSlop, doubleTapSlop;
+ int touchSlop, doubleTapSlop, doubleTapTouchSlop;
if (context == null) {
//noinspection deprecation
touchSlop = ViewConfiguration.getTouchSlop();
+ doubleTapTouchSlop = touchSlop; // Hack rather than adding a hiden method for this
doubleTapSlop = ViewConfiguration.getDoubleTapSlop();
//noinspection deprecation
mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
@@ -402,11 +401,13 @@
} else {
final ViewConfiguration configuration = ViewConfiguration.get(context);
touchSlop = configuration.getScaledTouchSlop();
+ doubleTapTouchSlop = configuration.getScaledDoubleTapTouchSlop();
doubleTapSlop = configuration.getScaledDoubleTapSlop();
mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity();
}
mTouchSlopSquare = touchSlop * touchSlop;
+ mDoubleTapTouchSlopSquare = doubleTapTouchSlop * doubleTapTouchSlop;
mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop;
}
@@ -545,7 +546,7 @@
mHandler.removeMessages(SHOW_PRESS);
mHandler.removeMessages(LONG_PRESS);
}
- if (distance > mBiggerTouchSlopSquare) {
+ if (distance > mDoubleTapTouchSlopSquare) {
mAlwaysInBiggerTapRegion = false;
}
} else if ((Math.abs(scrollX) >= 1) || (Math.abs(scrollY) >= 1)) {
diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java
index 3441f7e..d824e36 100644
--- a/core/java/android/view/ViewConfiguration.java
+++ b/core/java/android/view/ViewConfiguration.java
@@ -49,7 +49,7 @@
/**
* Defines the width of the horizontal scrollbar and the height of the vertical scrollbar in
- * pixels
+ * dips
*/
private static final int SCROLL_BAR_SIZE = 10;
@@ -64,7 +64,7 @@
private static final int SCROLL_BAR_DEFAULT_DELAY = 300;
/**
- * Defines the length of the fading edges in pixels
+ * Defines the length of the fading edges in dips
*/
private static final int FADING_EDGE_LENGTH = 12;
@@ -134,44 +134,50 @@
private static final int ZOOM_CONTROLS_TIMEOUT = 3000;
/**
- * Inset in pixels to look for touchable content when the user touches the edge of the screen
+ * Inset in dips to look for touchable content when the user touches the edge of the screen
*/
private static final int EDGE_SLOP = 12;
/**
- * Distance a touch can wander before we think the user is scrolling in pixels
+ * Distance a touch can wander before we think the user is scrolling in dips
*/
private static final int TOUCH_SLOP = 16;
/**
+ * Distance the first touch can wander before we stop considering this event a double tap
+ * (in dips)
+ */
+ private static final int DOUBLE_TAP_TOUCH_SLOP = TOUCH_SLOP;
+
+ /**
* Distance a touch can wander before we think the user is attempting a paged scroll
* (in dips)
*/
private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;
/**
- * Distance between the first touch and second touch to still be considered a double tap
+ * Distance in dips between the first touch and second touch to still be considered a double tap
*/
private static final int DOUBLE_TAP_SLOP = 100;
/**
- * Distance a touch needs to be outside of a window's bounds for it to
+ * Distance in dips a touch needs to be outside of a window's bounds for it to
* count as outside for purposes of dismissing the window.
*/
private static final int WINDOW_TOUCH_SLOP = 16;
/**
- * Minimum velocity to initiate a fling, as measured in pixels per second
+ * Minimum velocity to initiate a fling, as measured in dips per second
*/
private static final int MINIMUM_FLING_VELOCITY = 50;
/**
- * Maximum velocity to initiate a fling, as measured in pixels per second
+ * Maximum velocity to initiate a fling, as measured in dips per second
*/
private static final int MAXIMUM_FLING_VELOCITY = 8000;
/**
- * Distance between a touch up event denoting the end of a touch exploration
+ * Distance in dips between a touch up event denoting the end of a touch exploration
* gesture and the touch up event of a subsequent tap for the latter tap to be
* considered as a tap i.e. to perform a click.
*/
@@ -198,12 +204,12 @@
private static final float SCROLL_FRICTION = 0.015f;
/**
- * Max distance to overscroll for edge effects
+ * Max distance in dips to overscroll for edge effects
*/
private static final int OVERSCROLL_DISTANCE = 0;
/**
- * Max distance to overfling for edge effects
+ * Max distance in dips to overfling for edge effects
*/
private static final int OVERFLING_DISTANCE = 6;
@@ -213,6 +219,7 @@
private final int mMaximumFlingVelocity;
private final int mScrollbarSize;
private final int mTouchSlop;
+ private final int mDoubleTapTouchSlop;
private final int mPagingTouchSlop;
private final int mDoubleTapSlop;
private final int mScaledTouchExplorationTapSlop;
@@ -239,6 +246,7 @@
mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
mScrollbarSize = SCROLL_BAR_SIZE;
mTouchSlop = TOUCH_SLOP;
+ mDoubleTapTouchSlop = DOUBLE_TAP_TOUCH_SLOP;
mPagingTouchSlop = PAGING_TOUCH_SLOP;
mDoubleTapSlop = DOUBLE_TAP_SLOP;
mScaledTouchExplorationTapSlop = TOUCH_EXPLORATION_TAP_SLOP;
@@ -278,6 +286,7 @@
mMaximumFlingVelocity = (int) (density * MAXIMUM_FLING_VELOCITY + 0.5f);
mScrollbarSize = (int) (density * SCROLL_BAR_SIZE + 0.5f);
mTouchSlop = (int) (sizeAndDensity * TOUCH_SLOP + 0.5f);
+ mDoubleTapTouchSlop = (int) (sizeAndDensity * DOUBLE_TAP_TOUCH_SLOP + 0.5f);
mPagingTouchSlop = (int) (sizeAndDensity * PAGING_TOUCH_SLOP + 0.5f);
mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f);
mScaledTouchExplorationTapSlop = (int) (density * TOUCH_EXPLORATION_TAP_SLOP + 0.5f);
@@ -325,7 +334,7 @@
/**
* @return The width of the horizontal scrollbar and the height of the vertical
- * scrollbar in pixels
+ * scrollbar in dips
*
* @deprecated Use {@link #getScaledScrollBarSize()} instead.
*/
@@ -357,7 +366,7 @@
}
/**
- * @return the length of the fading edges in pixels
+ * @return the length of the fading edges in dips
*
* @deprecated Use {@link #getScaledFadingEdgeLength()} instead.
*/
@@ -452,7 +461,7 @@
}
/**
- * @return Inset in pixels to look for touchable content when the user touches the edge of the
+ * @return Inset in dips to look for touchable content when the user touches the edge of the
* screen
*
* @deprecated Use {@link #getScaledEdgeSlop()} instead.
@@ -471,7 +480,7 @@
}
/**
- * @return Distance a touch can wander before we think the user is scrolling in pixels
+ * @return Distance in dips a touch can wander before we think the user is scrolling
*
* @deprecated Use {@link #getScaledTouchSlop()} instead.
*/
@@ -481,22 +490,31 @@
}
/**
- * @return Distance a touch can wander before we think the user is scrolling in pixels
+ * @return Distance in pixels a touch can wander before we think the user is scrolling
*/
public int getScaledTouchSlop() {
return mTouchSlop;
}
/**
- * @return Distance a touch can wander before we think the user is scrolling a full page
- * in dips
+ * @return Distance in pixels the first touch can wander before we do not consider this a
+ * potential double tap event
+ * @hide
+ */
+ public int getScaledDoubleTapTouchSlop() {
+ return mDoubleTapTouchSlop;
+ }
+
+ /**
+ * @return Distance in pixels a touch can wander before we think the user is scrolling a full
+ * page
*/
public int getScaledPagingTouchSlop() {
return mPagingTouchSlop;
}
/**
- * @return Distance between the first touch and second touch to still be
+ * @return Distance in dips between the first touch and second touch to still be
* considered a double tap
* @deprecated Use {@link #getScaledDoubleTapSlop()} instead.
* @hide The only client of this should be GestureDetector, which needs this
@@ -508,7 +526,7 @@
}
/**
- * @return Distance between the first touch and second touch to still be
+ * @return Distance in pixels between the first touch and second touch to still be
* considered a double tap
*/
public int getScaledDoubleTapSlop() {
@@ -516,7 +534,7 @@
}
/**
- * @return Distance between a touch up event denoting the end of a touch exploration
+ * @return Distance in pixels between a touch up event denoting the end of a touch exploration
* gesture and the touch up event of a subsequent tap for the latter tap to be
* considered as a tap i.e. to perform a click.
*
@@ -540,7 +558,7 @@
}
/**
- * @return Distance a touch must be outside the bounds of a window for it
+ * @return Distance in dips a touch must be outside the bounds of a window for it
* to be counted as outside the window for purposes of dismissing that
* window.
*
@@ -552,16 +570,15 @@
}
/**
- * @return Distance a touch must be outside the bounds of a window for it
- * to be counted as outside the window for purposes of dismissing that
- * window.
+ * @return Distance in pixels a touch must be outside the bounds of a window for it
+ * to be counted as outside the window for purposes of dismissing that window.
*/
public int getScaledWindowTouchSlop() {
return mWindowTouchSlop;
}
/**
- * @return Minimum velocity to initiate a fling, as measured in pixels per second.
+ * @return Minimum velocity to initiate a fling, as measured in dips per second.
*
* @deprecated Use {@link #getScaledMinimumFlingVelocity()} instead.
*/
@@ -578,7 +595,7 @@
}
/**
- * @return Maximum velocity to initiate a fling, as measured in pixels per second.
+ * @return Maximum velocity to initiate a fling, as measured in dips per second.
*
* @deprecated Use {@link #getScaledMaximumFlingVelocity()} instead.
*/
@@ -617,14 +634,16 @@
}
/**
- * @return The maximum distance a View should overscroll by when showing edge effects.
+ * @return The maximum distance a View should overscroll by when showing edge effects (in
+ * pixels).
*/
public int getScaledOverscrollDistance() {
return mOverscrollDistance;
}
/**
- * @return The maximum distance a View should overfling by when showing edge effects.
+ * @return The maximum distance a View should overfling by when showing edge effects (in
+ * pixels).
*/
public int getScaledOverflingDistance() {
return mOverflingDistance;