diff --git a/java/res/values/gesture-input.xml b/java/res/values/gesture-input.xml new file mode 100644 index 0000000000000000000000000000000000000000..235616fbe06f95bd068299c1fadd4a6048f9139f --- /dev/null +++ b/java/res/values/gesture-input.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2012, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> +<resources> + <bool name="config_gesture_input_enabled_by_build_config">false</bool> +</resources> diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 7714ba892d243106a8f6cfe9964c90203643fd87..1eae2c1d43ad6a9c45f27492e8fbb6ba23d5b558 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 cc6789d13a4bbaaa0933f6782cafbb227dbd7f6b..c925227b9d374826c8bdb8bc1c066b3703403544 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<PointerTracker> sTrackers = new ArrayList<PointerTracker>(); 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<PointerTracker> 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)) {