am 0c8ea69c: Merge "Separate logic of enabling gesture typing"

* commit '0c8ea69cadb9d9a157a09e3a93dab29e1813f381':
  Separate logic of enabling gesture typing
main
Tadashi G. Takaoka 2013-12-20 00:07:19 -08:00 committed by Android Git Automerger
commit e3e1e303d8
3 changed files with 65 additions and 25 deletions

View File

@ -22,8 +22,8 @@ import android.os.SystemClock;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.keyboard.internal.BogusMoveEventDetector; import com.android.inputmethod.keyboard.internal.BogusMoveEventDetector;
import com.android.inputmethod.keyboard.internal.GestureEnabler;
import com.android.inputmethod.keyboard.internal.GestureStroke; import com.android.inputmethod.keyboard.internal.GestureStroke;
import com.android.inputmethod.keyboard.internal.GestureStroke.GestureStrokeParams; import com.android.inputmethod.keyboard.internal.GestureStroke.GestureStrokeParams;
import com.android.inputmethod.keyboard.internal.GestureStrokeWithPreviewPoints; import com.android.inputmethod.keyboard.internal.GestureStrokeWithPreviewPoints;
@ -50,12 +50,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private static final boolean DEBUG_LISTENER = false; private static final boolean DEBUG_LISTENER = false;
private static boolean DEBUG_MODE = LatinImeLogger.sDBG || DEBUG_EVENT; private static boolean DEBUG_MODE = LatinImeLogger.sDBG || DEBUG_EVENT;
/** True if {@link PointerTracker}s should handle gesture events. */
private static boolean sShouldHandleGesture = false;
private static boolean sMainDictionaryAvailable = false;
private static boolean sGestureHandlingEnabledByInputField = false;
private static boolean sGestureHandlingEnabledByUser = false;
public interface DrawingProxy { public interface DrawingProxy {
public void invalidateKey(Key key); public void invalidateKey(Key key);
public void showKeyPreview(Key key); public void showKeyPreview(Key key);
@ -137,6 +131,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
private static GestureEnabler sGestureEnabler = new GestureEnabler();
// Parameters for pointer handling. // Parameters for pointer handling.
private static PointerTrackerParams sParams; private static PointerTrackerParams sParams;
private static GestureStrokeParams sGestureStrokeParams; private static GestureStrokeParams sGestureStrokeParams;
@ -229,22 +225,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
sDrawingProxy = drawingProxy; sDrawingProxy = drawingProxy;
} }
private static void updateGestureHandlingMode() {
sShouldHandleGesture = sMainDictionaryAvailable
&& sGestureHandlingEnabledByInputField
&& sGestureHandlingEnabledByUser
&& !AccessibilityUtils.getInstance().isTouchExplorationEnabled();
}
// Note that this method is called from a non-UI thread. // Note that this method is called from a non-UI thread.
public static void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) { public static void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
sMainDictionaryAvailable = mainDictionaryAvailable; sGestureEnabler.setMainDictionaryAvailability(mainDictionaryAvailable);
updateGestureHandlingMode();
} }
public static void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) { public static void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) {
sGestureHandlingEnabledByUser = gestureHandlingEnabledByUser; sGestureEnabler.setGestureHandlingEnabledByUser(gestureHandlingEnabledByUser);
updateGestureHandlingMode();
} }
public static PointerTracker getPointerTracker(final int id) { public static PointerTracker getPointerTracker(final int id) {
@ -278,8 +265,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
tracker.setKeyDetectorInner(keyDetector); tracker.setKeyDetectorInner(keyDetector);
} }
final Keyboard keyboard = keyDetector.getKeyboard(); final Keyboard keyboard = keyDetector.getKeyboard();
sGestureHandlingEnabledByInputField = !keyboard.mId.passwordInput(); sGestureEnabler.setPasswordMode(keyboard.mId.passwordInput());
updateGestureHandlingMode();
} }
public static void setReleasedKeyGraphicsToAllKeys() { public static void setReleasedKeyGraphicsToAllKeys() {
@ -484,7 +470,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
private static boolean needsToSuppressKeyPreviewPopup(final long eventTime) { private static boolean needsToSuppressKeyPreviewPopup(final long eventTime) {
if (!sShouldHandleGesture) return false; if (!sGestureEnabler.shouldHandleGesture()) return false;
return sTypingTimeRecorder.needsToSuppressKeyPreviewPopup(eventTime); return sTypingTimeRecorder.needsToSuppressKeyPreviewPopup(eventTime);
} }
@ -761,7 +747,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
sPointerTrackerQueue.add(this); sPointerTrackerQueue.add(this);
onDownEventInternal(x, y, eventTime); onDownEventInternal(x, y, eventTime);
if (!sShouldHandleGesture) { if (!sGestureEnabler.shouldHandleGesture()) {
return; return;
} }
// A gesture should start only from a non-modifier key. Note that the gesture detection is // A gesture should start only from a non-modifier key. Note that the gesture detection is
@ -862,7 +848,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return; return;
} }
if (sShouldHandleGesture && me != null) { if (sGestureEnabler.shouldHandleGesture() && me != null) {
// Add historical points to gesture path. // Add historical points to gesture path.
final int pointerIndex = me.findPointerIndex(mPointerId); final int pointerIndex = me.findPointerIndex(mPointerId);
final int historicalSize = me.getHistorySize(); final int historicalSize = me.getHistorySize();
@ -1014,7 +1000,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final Key oldKey = mCurrentKey; final Key oldKey = mCurrentKey;
final Key newKey = onMoveKey(x, y); final Key newKey = onMoveKey(x, y);
if (sShouldHandleGesture) { if (sGestureEnabler.shouldHandleGesture()) {
// Register move event on gesture tracker. // Register move event on gesture tracker.
onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, newKey); onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, newKey);
if (sInGesture) { if (sInGesture) {

View File

@ -87,7 +87,7 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
return true; return true;
} }
// {@link GestureDetector#OnGestureListener} methods. // {@link GestureEnabler#OnGestureListener} methods.
private Key mCurrentKey; private Key mCurrentKey;
private Key getKey(final MotionEvent e) { private Key getKey(final MotionEvent e) {

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2013 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.
*/
package com.android.inputmethod.keyboard.internal;
import com.android.inputmethod.accessibility.AccessibilityUtils;
public final class GestureEnabler {
/** True if we should handle gesture events. */
private boolean mShouldHandleGesture;
private boolean mMainDictionaryAvailable;
private boolean mGestureHandlingEnabledByInputField;
private boolean mGestureHandlingEnabledByUser;
private void updateGestureHandlingMode() {
mShouldHandleGesture = mMainDictionaryAvailable
&& mGestureHandlingEnabledByInputField
&& mGestureHandlingEnabledByUser
&& !AccessibilityUtils.getInstance().isTouchExplorationEnabled();
}
// Note that this method is called from a non-UI thread.
public void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
mMainDictionaryAvailable = mainDictionaryAvailable;
updateGestureHandlingMode();
}
public void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) {
mGestureHandlingEnabledByUser = gestureHandlingEnabledByUser;
updateGestureHandlingMode();
}
public void setPasswordMode(final boolean passwordMode) {
mGestureHandlingEnabledByInputField = !passwordMode;
updateGestureHandlingMode();
}
public boolean shouldHandleGesture() {
return mShouldHandleGesture;
}
}