From 918e420d1becc1389b9895538eceff85fe882c99 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 19 Jul 2012 12:33:51 +0900 Subject: [PATCH] Gesture input should be turned off depending on the configuration The gesture input will be disabled when * It is AOSP build. * Accessibility mode is on. * The input field is password mode. Bug: 6844755 Bug: 6844763 Bug: 6845011 Change-Id: I74972cc765d15c08059e0c9014f863ffb2a57c6c --- java/res/values/gesture-input.xml | 22 ++++++++++++++++ .../keyboard/LatinKeyboardView.java | 8 ++++-- .../inputmethod/keyboard/PointerTracker.java | 26 ++++++++++++++++--- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 java/res/values/gesture-input.xml diff --git a/java/res/values/gesture-input.xml b/java/res/values/gesture-input.xml new file mode 100644 index 000000000..235616fbe --- /dev/null +++ b/java/res/values/gesture-input.xml @@ -0,0 +1,22 @@ + + + + false + diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 7714ba892..1eae2c1d4 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -341,10 +341,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke mHasDistinctMultitouch = context.getPackageManager() .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT); + final Resources res = getResources(); final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean( - Utils.getDeviceOverrideValue(context.getResources(), + Utils.getDeviceOverrideValue(res, R.array.phantom_sudden_move_event_device_list, "false")); - PointerTracker.init(mHasDistinctMultitouch, needsPhantomSuddenMoveEventHack); + final boolean gestureInputEnabledByBuildConfig = res.getBoolean( + R.bool.config_gesture_input_enabled_by_build_config); + PointerTracker.init(mHasDistinctMultitouch, needsPhantomSuddenMoveEventHack, + gestureInputEnabledByBuildConfig); final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.LatinKeyboardView, defStyle, R.style.LatinKeyboardView); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index cc6789d13..c925227b9 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -22,6 +22,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.TextView; +import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.keyboard.internal.GestureStroke; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.InputPointers; @@ -39,7 +40,8 @@ public class PointerTracker { private static boolean DEBUG_MODE = LatinImeLogger.sDBG; // TODO: There should be an option to turn on/off the gesture input. - private static final boolean GESTURE_ON = true; + private static boolean sIsGestureEnabled = true; + private static final int MIN_RECOGNITION_TIME = 100; // msec public interface KeyEventHandler { @@ -116,6 +118,7 @@ public class PointerTracker { private static LatinKeyboardView.PointerTrackerParams sParams; private static int sTouchNoiseThresholdDistanceSquared; private static boolean sNeedsPhantomSuddenMoveEventHack; + private static boolean sConfigGestureInputEnabledByBuildConfig; private static final ArrayList sTrackers = new ArrayList(); private static PointerTrackerQueue sPointerTrackerQueue; @@ -177,15 +180,18 @@ public class PointerTracker { private final GestureStroke mGestureStroke; public static void init(boolean hasDistinctMultitouch, - boolean needsPhantomSuddenMoveEventHack) { + boolean needsPhantomSuddenMoveEventHack, + boolean gestureInputEnabledByBuildConfig) { if (hasDistinctMultitouch) { sPointerTrackerQueue = new PointerTrackerQueue(); } else { sPointerTrackerQueue = null; } sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack; + sConfigGestureInputEnabledByBuildConfig = gestureInputEnabledByBuildConfig; setParameters(LatinKeyboardView.PointerTrackerParams.DEFAULT); + updateGestureInputEnabledState(null); } public static void setParameters(LatinKeyboardView.PointerTrackerParams params) { @@ -194,6 +200,16 @@ public class PointerTracker { params.mTouchNoiseThresholdDistance * params.mTouchNoiseThresholdDistance); } + private static void updateGestureInputEnabledState(Keyboard keyboard) { + if (!sConfigGestureInputEnabledByBuildConfig + || AccessibilityUtils.getInstance().isTouchExplorationEnabled() + || (keyboard != null && keyboard.mId.passwordInput())) { + sIsGestureEnabled = false; + } else { + sIsGestureEnabled = true; + } + } + public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) { final ArrayList trackers = sTrackers; @@ -222,6 +238,8 @@ public class PointerTracker { // Mark that keyboard layout has been changed. tracker.mKeyboardLayoutHasBeenChanged = true; } + final Keyboard keyboard = keyDetector.getKeyboard(); + updateGestureInputEnabledState(keyboard); } public static void dismissAllKeyPreviews() { @@ -611,7 +629,7 @@ public class PointerTracker { if (queue != null && queue.size() == 1) { mIsPossibleGesture = false; // A gesture should start only from the letter key. - if (GESTURE_ON && mIsAlphabetKeyboard && key != null + if (sIsGestureEnabled && mIsAlphabetKeyboard && key != null && Keyboard.isLetterCode(key.mCode)) { mIsPossibleGesture = true; mGestureStroke.addPoint(x, y, 0, false); @@ -654,7 +672,7 @@ public class PointerTracker { private void onGestureMoveEvent(PointerTracker tracker, int x, int y, long eventTime, boolean isHistorical, Key key) { final int gestureTime = (int)(eventTime - tracker.getDownTime()); - if (GESTURE_ON && mIsPossibleGesture) { + if (sIsGestureEnabled && mIsPossibleGesture) { final GestureStroke stroke = mGestureStroke; stroke.addPoint(x, y, gestureTime, isHistorical); if (!mInGesture && stroke.isStartOfAGesture(gestureTime)) {