Merge "Prevent reflection - ScaleGestureDetector#mMinSpan"

This commit is contained in:
Shep Shapard
2019-02-09 03:28:27 +00:00
committed by Android (Google) Code Review
3 changed files with 35 additions and 6 deletions

View File

@@ -51115,6 +51115,7 @@ package android.view {
method public int getScaledHoverSlop();
method public int getScaledMaximumDrawingCacheSize();
method public int getScaledMaximumFlingVelocity();
method public int getScaledMinScalingSpan();
method public int getScaledMinimumFlingVelocity();
method public int getScaledOverflingDistance();
method public int getScaledOverscrollDistance();

View File

@@ -18,7 +18,6 @@ package android.view;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.os.Handler;
@@ -145,7 +144,7 @@ public class ScaleGestureDetector {
private boolean mInProgress;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768938)
private int mSpanSlop;
@UnsupportedAppUsage
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768938)
private int mMinSpan;
private final Handler mHandler;
@@ -200,10 +199,9 @@ public class ScaleGestureDetector {
Handler handler) {
mContext = context;
mListener = listener;
mSpanSlop = ViewConfiguration.get(context).getScaledTouchSlop() * 2;
final Resources res = context.getResources();
mMinSpan = res.getDimensionPixelSize(com.android.internal.R.dimen.config_minScalingSpan);
final ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
mSpanSlop = viewConfiguration.getScaledTouchSlop() * 2;
mMinSpan = viewConfiguration.getScaledMinScalingSpan();
mHandler = handler;
// Quick scale is enabled by default after JB_MR2
final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;

View File

@@ -293,12 +293,14 @@ public class ViewConfiguration {
*/
private static final float AMBIGUOUS_GESTURE_MULTIPLIER = 2f;
private final boolean mConstructedWithContext;
private final int mEdgeSlop;
private final int mFadingEdgeLength;
private final int mMinimumFlingVelocity;
private final int mMaximumFlingVelocity;
private final int mScrollbarSize;
private final int mTouchSlop;
private final int mMinScalingSpan;
private final int mHoverSlop;
private final int mMinScrollbarTouchTarget;
private final int mDoubleTapTouchSlop;
@@ -329,6 +331,7 @@ public class ViewConfiguration {
*/
@Deprecated
public ViewConfiguration() {
mConstructedWithContext = false;
mEdgeSlop = EDGE_SLOP;
mFadingEdgeLength = FADING_EDGE_LENGTH;
mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;
@@ -350,6 +353,10 @@ public class ViewConfiguration {
mHorizontalScrollFactor = HORIZONTAL_SCROLL_FACTOR;
mVerticalScrollFactor = VERTICAL_SCROLL_FACTOR;
mShowMenuShortcutsWhenKeyboardPresent = false;
// Getter throws if mConstructedWithContext is false so doesn't matter what
// this value is.
mMinScalingSpan = 0;
}
/**
@@ -363,6 +370,7 @@ public class ViewConfiguration {
* @see android.util.DisplayMetrics
*/
private ViewConfiguration(Context context) {
mConstructedWithContext = true;
final Resources res = context.getResources();
final DisplayMetrics metrics = res.getDisplayMetrics();
final Configuration config = res.getConfiguration();
@@ -447,6 +455,8 @@ public class ViewConfiguration {
mShowMenuShortcutsWhenKeyboardPresent = res.getBoolean(
com.android.internal.R.bool.config_showMenuShortcutsWhenKeyboardPresent);
mMinScalingSpan = res.getDimensionPixelSize(
com.android.internal.R.dimen.config_minScalingSpan);
}
/**
@@ -958,6 +968,26 @@ public class ViewConfiguration {
return mShowMenuShortcutsWhenKeyboardPresent;
}
/**
* Retrieves the distance in pixels between touches that must be reached for a gesture to be
* interpreted as scaling.
*
* In general, scaling shouldn't start until this distance has been met or surpassed, and
* scaling should end when the distance in pixels between touches drops below this distance.
*
* @return The distance in pixels
* @throws IllegalStateException if this method is called on a ViewConfiguration that was
* instantiated using a constructor with no Context parameter.
*/
public int getScaledMinScalingSpan() {
if (!mConstructedWithContext) {
throw new IllegalStateException("Min scaling span cannot be determined when this "
+ "method is called on a ViewConfiguration that was instantiated using a "
+ "constructor with no Context parameter");
}
return mMinScalingSpan;
}
/**
* @hide
* @return Whether or not marquee should use fading edges.