Refinements to magnification for improved wearable support.

This change refactors ScreenMagnifier to use resources for its triple-tap
adjustment and scale threshold values.  New values more appropriate for
wearable form factors are supplied.  This also fixes a bug in the triple-
tap detection logic where the incorrect ViewConfiguration value for the
tap threshold was used, prematurely disqualifying some touch events as
potential taps.

Change-Id: If47e556aadb5beb1bad24644122560c6fbe33bad
diff --git a/core/res/res/values-watch/config.xml b/core/res/res/values-watch/config.xml
index 307a1ea..745aa73 100644
--- a/core/res/res/values-watch/config.xml
+++ b/core/res/res/values-watch/config.xml
@@ -43,4 +43,12 @@
     <!-- Flags enabling default window features. See Window.java -->
     <bool name="config_defaultWindowFeatureOptionsPanel">false</bool>
     <bool name="config_defaultWindowFeatureContextMenu">false</bool>
+
+    <!-- Time adjustment, in milliseconds, applied to the default double tap threshold
+         used for gesture detection by the screen magnifier. -->
+    <integer name="config_screen_magnification_multi_tap_adjustment">25</integer>
+
+    <!-- Scale factor threshold used by the screen magnifier to determine when to switch from
+         panning to scaling the magnification viewport. -->
+    <item name="config_screen_magnification_scaling_threshold" format="float" type="dimen">0.1</item>
 </resources>
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index b0869ea..0d8d725 100755
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2052,4 +2052,12 @@
 
     <!-- Whether to start in touch mode -->
     <bool name="config_defaultInTouchMode">true</bool>
+
+    <!-- Time adjustment, in milliseconds, applied to the default double tap threshold
+         used for gesture detection by the screen magnifier. -->
+    <integer name="config_screen_magnification_multi_tap_adjustment">-50</integer>
+
+    <!-- Scale factor threshold used by the screen magnifier to determine when to switch from
+         panning to scaling the magnification viewport. -->
+    <item name="config_screen_magnification_scaling_threshold" format="float" type="dimen">0.3</item>
 </resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index b676dfa..35802c9 100755
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2164,4 +2164,7 @@
   <java-symbol type="bool" name="config_use_sim_language_file" />
   <java-symbol type="bool" name="config_LTE_eri_for_network_name" />
   <java-symbol type="bool" name="config_defaultInTouchMode" />
+
+  <java-symbol type="integer" name="config_screen_magnification_multi_tap_adjustment" />
+  <java-symbol type="dimen" name="config_screen_magnification_scaling_threshold" />
 </resources>
diff --git a/services/accessibility/java/com/android/server/accessibility/ScreenMagnifier.java b/services/accessibility/java/com/android/server/accessibility/ScreenMagnifier.java
index c8b080e..b4613d6 100644
--- a/services/accessibility/java/com/android/server/accessibility/ScreenMagnifier.java
+++ b/services/accessibility/java/com/android/server/accessibility/ScreenMagnifier.java
@@ -34,6 +34,7 @@
 import android.text.TextUtils;
 import android.util.Property;
 import android.util.Slog;
+import android.util.TypedValue;
 import android.view.GestureDetector;
 import android.view.GestureDetector.SimpleOnGestureListener;
 import android.view.MagnificationSpec;
@@ -110,7 +111,6 @@
     private static final int STATE_MAGNIFIED_INTERACTION = 4;
 
     private static final float DEFAULT_MAGNIFICATION_SCALE = 2.0f;
-    private static final int MULTI_TAP_TIME_SLOP_ADJUSTMENT = 50;
 
     private static final int MESSAGE_ON_MAGNIFIED_BOUNDS_CHANGED = 1;
     private static final int MESSAGE_ON_RECTANGLE_ON_SCREEN_REQUESTED = 2;
@@ -135,9 +135,8 @@
 
     private final AccessibilityManagerService mAms;
 
-    private final int mTapTimeSlop = ViewConfiguration.getTapTimeout();
-    private final int mMultiTapTimeSlop =
-            ViewConfiguration.getDoubleTapTimeout() - MULTI_TAP_TIME_SLOP_ADJUSTMENT;
+    private final int mTapTimeSlop = ViewConfiguration.getJumpTapTimeout();
+    private final int mMultiTapTimeSlop;
     private final int mTapDistanceSlop;
     private final int mMultiTapDistanceSlop;
 
@@ -192,6 +191,9 @@
         mWindowManager = LocalServices.getService(WindowManagerInternal.class);
         mAms = service;
 
+        mMultiTapTimeSlop = ViewConfiguration.getDoubleTapTimeout()
+                + mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_screen_magnification_multi_tap_adjustment);
         mLongAnimationDuration = context.getResources().getInteger(
                 com.android.internal.R.integer.config_longAnimTime);
         mTapDistanceSlop = ViewConfiguration.get(context).getScaledTouchSlop();
@@ -481,15 +483,20 @@
         private static final float MIN_SCALE = 1.3f;
         private static final float MAX_SCALE = 5.0f;
 
-        private static final float SCALING_THRESHOLD = 0.3f;
-
         private final ScaleGestureDetector mScaleGestureDetector;
         private final GestureDetector mGestureDetector;
 
+        private final float mScalingThreshold;
+
         private float mInitialScaleFactor = -1;
         private boolean mScaling;
 
         public MagnifiedContentInteractonStateHandler(Context context) {
+            final TypedValue scaleValue = new TypedValue();
+            context.getResources().getValue(
+                    com.android.internal.R.dimen.config_screen_magnification_scaling_threshold,
+                    scaleValue, false);
+            mScalingThreshold = scaleValue.getFloat();
             mScaleGestureDetector = new ScaleGestureDetector(context, this);
             mScaleGestureDetector.setQuickScaleEnabled(false);
             mGestureDetector = new GestureDetector(context, this);
@@ -537,7 +544,7 @@
                     mInitialScaleFactor = detector.getScaleFactor();
                 } else {
                     final float deltaScale = detector.getScaleFactor() - mInitialScaleFactor;
-                    if (Math.abs(deltaScale) > SCALING_THRESHOLD) {
+                    if (Math.abs(deltaScale) > mScalingThreshold) {
                         mScaling = true;
                         return true;
                     }