Separate logic of enabling gesture typing

Change-Id: I91fc566f24a38a55d2352201d5d581d3fa02a428
main
Tadashi G. Takaoka 2013-12-20 15:47:38 +09:00
parent db6d9b0ab4
commit a00838b6e8
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.view.MotionEvent;
import com.android.inputmethod.accessibility.AccessibilityUtils;
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.GestureStrokeParams;
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 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 void invalidateKey(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.
private static PointerTrackerParams sParams;
private static GestureStrokeParams sGestureStrokeParams;
@ -229,22 +225,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
sDrawingProxy = drawingProxy;
}
private static void updateGestureHandlingMode() {
sShouldHandleGesture = sMainDictionaryAvailable
&& sGestureHandlingEnabledByInputField
&& sGestureHandlingEnabledByUser
&& !AccessibilityUtils.getInstance().isTouchExplorationEnabled();
}
// Note that this method is called from a non-UI thread.
public static void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
sMainDictionaryAvailable = mainDictionaryAvailable;
updateGestureHandlingMode();
sGestureEnabler.setMainDictionaryAvailability(mainDictionaryAvailable);
}
public static void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) {
sGestureHandlingEnabledByUser = gestureHandlingEnabledByUser;
updateGestureHandlingMode();
sGestureEnabler.setGestureHandlingEnabledByUser(gestureHandlingEnabledByUser);
}
public static PointerTracker getPointerTracker(final int id) {
@ -278,8 +265,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
tracker.setKeyDetectorInner(keyDetector);
}
final Keyboard keyboard = keyDetector.getKeyboard();
sGestureHandlingEnabledByInputField = !keyboard.mId.passwordInput();
updateGestureHandlingMode();
sGestureEnabler.setPasswordMode(keyboard.mId.passwordInput());
}
public static void setReleasedKeyGraphicsToAllKeys() {
@ -484,7 +470,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
private static boolean needsToSuppressKeyPreviewPopup(final long eventTime) {
if (!sShouldHandleGesture) return false;
if (!sGestureEnabler.shouldHandleGesture()) return false;
return sTypingTimeRecorder.needsToSuppressKeyPreviewPopup(eventTime);
}
@ -761,7 +747,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
sPointerTrackerQueue.add(this);
onDownEventInternal(x, y, eventTime);
if (!sShouldHandleGesture) {
if (!sGestureEnabler.shouldHandleGesture()) {
return;
}
// 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;
}
if (sShouldHandleGesture && me != null) {
if (sGestureEnabler.shouldHandleGesture() && me != null) {
// Add historical points to gesture path.
final int pointerIndex = me.findPointerIndex(mPointerId);
final int historicalSize = me.getHistorySize();
@ -1014,7 +1000,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final Key oldKey = mCurrentKey;
final Key newKey = onMoveKey(x, y);
if (sShouldHandleGesture) {
if (sGestureEnabler.shouldHandleGesture()) {
// Register move event on gesture tracker.
onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, newKey);
if (sInGesture) {

View File

@ -87,7 +87,7 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
return true;
}
// {@link GestureDetector#OnGestureListener} methods.
// {@link GestureEnabler#OnGestureListener} methods.
private Key mCurrentKey;
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;
}
}