aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyDetector.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java33
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java15
-rw-r--r--java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java6
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java34
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java9
-rw-r--r--java/src/com/android/inputmethod/latin/DicTraverseSession.java18
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java23
8 files changed, 77 insertions, 64 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
index 97d88af4a..c0e6aa8d7 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
@@ -59,6 +59,9 @@ public class KeyDetector {
}
public Keyboard getKeyboard() {
+ if (mKeyboard == null) {
+ throw new IllegalStateException("keyboard isn't set");
+ }
return mKeyboard;
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 0e6de7032..fcf97b99c 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -108,14 +108,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private int mDelayAfterPreview;
private final PreviewPlacerView mPreviewPlacerView;
- /** True if {@link KeyboardView} should handle gesture events. */
- protected boolean mShouldHandleGesture;
-
// Drawing
/** True if the entire keyboard needs to be dimmed. */
private boolean mNeedsToDimEntireKeyboard;
- /** Whether the keyboard bitmap buffer needs to be redrawn before it's blitted. **/
- private boolean mBufferNeedsUpdate;
/** True if all keys should be drawn */
private boolean mInvalidateAllKeys;
/** The keys that should be drawn */
@@ -438,9 +433,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
return mShowKeyPreviewPopup;
}
- public void setGestureHandlingMode(boolean shouldHandleGesture,
- boolean drawsGesturePreviewTrail, boolean drawsGestureFloatingPreviewText) {
- mShouldHandleGesture = shouldHandleGesture;
+ public void setGesturePreviewMode(boolean drawsGesturePreviewTrail,
+ boolean drawsGestureFloatingPreviewText) {
mPreviewPlacerView.setGesturePreviewMode(
drawsGesturePreviewTrail, drawsGestureFloatingPreviewText);
}
@@ -463,8 +457,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
onDrawKeyboard(canvas);
return;
}
- if (mBufferNeedsUpdate || mOffscreenBuffer == null) {
- mBufferNeedsUpdate = false;
+
+ final boolean bufferNeedsUpdates = mInvalidateAllKeys || !mInvalidatedKeys.isEmpty();
+ if (bufferNeedsUpdates || mOffscreenBuffer == null) {
if (maybeAllocateOffscreenBuffer()) {
mInvalidateAllKeys = true;
// TODO: Stop using the offscreen canvas even when in software rendering
@@ -528,13 +523,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
if (!isHardwareAccelerated) {
canvas.clipRegion(mClipRegion, Region.Op.REPLACE);
- }
-
- // Draw keyboard background.
- canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
- final Drawable background = getBackground();
- if (background != null) {
- background.draw(canvas);
+ // Draw keyboard background.
+ canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
+ final Drawable background = getBackground();
+ if (background != null) {
+ background.draw(canvas);
+ }
}
// TODO: Confirm if it's really required to draw all keys when hardware acceleration is on.
@@ -1052,7 +1046,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
public void invalidateAllKeys() {
mInvalidatedKeys.clear();
mInvalidateAllKeys = true;
- mBufferNeedsUpdate = true;
invalidate();
}
@@ -1070,9 +1063,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mInvalidatedKeys.add(key);
final int x = key.mX + getPaddingLeft();
final int y = key.mY + getPaddingTop();
- mWorkingRect.set(x, y, x + key.mWidth, y + key.mHeight);
- mBufferNeedsUpdate = true;
- invalidate(mWorkingRect);
+ invalidate(x, y, x + key.mWidth, y + key.mHeight);
}
public void closing() {
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index fe9cb9415..4088f3e93 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -482,7 +482,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
super.setKeyboard(keyboard);
mKeyDetector.setKeyboard(
keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection);
- PointerTracker.setKeyDetector(mKeyDetector, mShouldHandleGesture);
+ PointerTracker.setKeyDetector(mKeyDetector);
mTouchScreenRegulator.setKeyboard(keyboard);
mMoreKeysPanelCache.clear();
@@ -500,12 +500,13 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
AccessibleKeyboardViewProxy.getInstance().setKeyboard(keyboard);
}
- @Override
- public void setGestureHandlingMode(final boolean shouldHandleGesture,
- boolean drawsGesturePreviewTrail, boolean drawsGestureFloatingPreviewText) {
- super.setGestureHandlingMode(shouldHandleGesture, drawsGesturePreviewTrail,
- drawsGestureFloatingPreviewText);
- PointerTracker.setKeyDetector(mKeyDetector, shouldHandleGesture);
+ // Note that this method is called from a non-UI thread.
+ public void setMainDictionaryAvailability(boolean mainDictionaryAvailable) {
+ PointerTracker.setMainDictionaryAvailability(mainDictionaryAvailable);
+ }
+
+ public void setGestureHandlingEnabledByUser(boolean gestureHandlingEnabledByUser) {
+ PointerTracker.setGestureHandlingEnabledByUser(gestureHandlingEnabledByUser);
}
/**
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java b/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java
index a183546dd..cd4e3001e 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java
@@ -39,11 +39,7 @@ public class MoreKeysDetector extends KeyDetector {
Key nearestKey = null;
int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare;
- final Keyboard keyboard = getKeyboard();
- if (keyboard == null) {
- throw new NullPointerException("Keyboard isn't set");
- }
- for (final Key key : keyboard.mKeys) {
+ for (final Key key : getKeyboard().mKeys) {
final int dist = key.squaredDistanceToEdge(touchX, touchY);
if (dist < nearestDist) {
nearestKey = key;
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 2b90a3cb9..85360c410 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -29,6 +29,7 @@ import com.android.inputmethod.keyboard.internal.GestureStroke;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LatinImeLogger;
+import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.ResearchLogger;
@@ -43,6 +44,9 @@ public class PointerTracker implements PointerTrackerQueue.Element {
/** 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;
private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec
@@ -198,7 +202,6 @@ public class PointerTracker implements PointerTrackerQueue.Element {
sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack;
setParameters(MainKeyboardView.PointerTrackerParams.DEFAULT);
- updateGestureHandlingMode(null, false /* shouldHandleGesture */);
}
public static void setParameters(MainKeyboardView.PointerTrackerParams params) {
@@ -207,14 +210,22 @@ public class PointerTracker implements PointerTrackerQueue.Element {
params.mTouchNoiseThresholdDistance * params.mTouchNoiseThresholdDistance);
}
- private static void updateGestureHandlingMode(Keyboard keyboard, boolean shouldHandleGesture) {
- if (!shouldHandleGesture
- || AccessibilityUtils.getInstance().isTouchExplorationEnabled()
- || (keyboard != null && keyboard.mId.passwordInput())) {
- sShouldHandleGesture = false;
- } else {
- sShouldHandleGesture = true;
- }
+ 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(boolean mainDictionaryAvailable) {
+ sMainDictionaryAvailable = mainDictionaryAvailable;
+ updateGestureHandlingMode();
+ }
+
+ public static void setGestureHandlingEnabledByUser(boolean gestureHandlingEnabledByUser) {
+ sGestureHandlingEnabledByUser = gestureHandlingEnabledByUser;
+ updateGestureHandlingMode();
}
public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) {
@@ -241,7 +252,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
}
}
- public static void setKeyDetector(KeyDetector keyDetector, boolean shouldHandleGesture) {
+ public static void setKeyDetector(KeyDetector keyDetector) {
final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
@@ -250,7 +261,8 @@ public class PointerTracker implements PointerTrackerQueue.Element {
tracker.mKeyboardLayoutHasBeenChanged = true;
}
final Keyboard keyboard = keyDetector.getKeyboard();
- updateGestureHandlingMode(keyboard, shouldHandleGesture);
+ sGestureHandlingEnabledByInputField = !keyboard.mId.passwordInput();
+ updateGestureHandlingMode();
}
public static void dismissAllKeyPreviews() {
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 7e6c53e2f..e0adc9a71 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -90,9 +90,9 @@ public class BinaryDictionary extends Dictionary {
private native void closeNative(long dict);
private native int getFrequencyNative(long dict, int[] word, int wordLength);
private native boolean isValidBigramNative(long dict, int[] word1, int[] word2);
- private native int getSuggestionsNative(long dict, long proximityInfo, int[] xCoordinates,
- int[] yCoordinates, int[] times, int[] pointerIds, int[] inputCodes, int codesSize,
- int commitPoint, boolean isGesture,
+ private native int getSuggestionsNative(long dict, long proximityInfo, long traverseSession,
+ int[] xCoordinates, int[] yCoordinates, int[] times, int[] pointerIds,
+ int[] inputCodes, int codesSize, int commitPoint, boolean isGesture,
int[] prevWordCodePointArray, boolean useFullEditDistance, char[] outputChars,
int[] outputScores, int[] outputIndices, int[] outputTypes);
private static native float calcNormalizedScoreNative(
@@ -129,7 +129,8 @@ public class BinaryDictionary extends Dictionary {
final int codesSize = isGesture ? ips.getPointerSize() : composerSize;
// proximityInfo and/or prevWordForBigrams may not be null.
final int tmpCount = getSuggestionsNative(mNativeDict,
- proximityInfo.getNativeProximityInfo(), ips.getXCoordinates(),
+ proximityInfo.getNativeProximityInfo(),
+ mDicTraverseSession.getSession(), ips.getXCoordinates(),
ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(),
mInputCodes, codesSize, 0 /* commitPoint */, isGesture, prevWordCodePointArray,
mUseFullEditDistance, mOutputChars, mOutputScores, mSpaceIndices, mOutputTypes);
diff --git a/java/src/com/android/inputmethod/latin/DicTraverseSession.java b/java/src/com/android/inputmethod/latin/DicTraverseSession.java
index d0c70f3ad..437876e05 100644
--- a/java/src/com/android/inputmethod/latin/DicTraverseSession.java
+++ b/java/src/com/android/inputmethod/latin/DicTraverseSession.java
@@ -22,16 +22,30 @@ public class DicTraverseSession {
static {
JniUtils.loadNativeLibrary();
}
+ private native long setDicTraverseSessionNative(String locale);
+ private native void initDicTraverseSessionNative(
+ long nativeDicTraverseSession, int[] previousWord, int previwousWordLength);
+ private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);
private long mNativeDicTraverseSession;
public DicTraverseSession(Locale locale) {
mNativeDicTraverseSession = createNativeDicTraverseSession(
locale != null ? locale.toString() : "");
+ initSession();
}
- private native long setDicTraverseSessionNative(String locale);
- private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);
+ public long getSession() {
+ return mNativeDicTraverseSession;
+ }
+
+ public void initSession() {
+ initSession(null, 0);
+ }
+
+ public void initSession(int[] previousWord, int previousWordLength) {
+ initDicTraverseSessionNative(mNativeDicTraverseSession, previousWord, previousWordLength);
+ }
private final long createNativeDicTraverseSession(String locale) {
return setDicTraverseSessionNative(locale);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 43901bab4..e0dbb8e6e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -433,10 +433,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
}
+ // Note that this method is called from a non-UI thread.
@Override
public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable) {
mIsMainDictionaryAvailable = isMainDictionaryAvailable;
- updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability();
+ final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
+ if (mainKeyboardView != null) {
+ mainKeyboardView.setMainDictionaryAvailability(isMainDictionaryAvailable);
+ }
}
private void initSuggest() {
@@ -701,7 +705,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
switcher.loadKeyboard(editorInfo, mCurrentSettings);
- updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability();
}
setSuggestionStripShownInternal(
isSuggestionsStripVisible(), /* needsInputViewShown */ false);
@@ -719,8 +722,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler.cancelUpdateSuggestionStrip();
mHandler.cancelDoubleSpacesTimer();
+ mainKeyboardView.setMainDictionaryAvailability(mIsMainDictionaryAvailable);
mainKeyboardView.setKeyPreviewPopupEnabled(mCurrentSettings.mKeyPreviewPopupOn,
mCurrentSettings.mKeyPreviewPopupDismissDelay);
+ mainKeyboardView.setGestureHandlingEnabledByUser(mCurrentSettings.mGestureInputEnabled);
+ mainKeyboardView.setGesturePreviewMode(mCurrentSettings.mGesturePreviewTrailEnabled,
+ mCurrentSettings.mGestureFloatingPreviewTextEnabled);
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
}
@@ -2103,7 +2110,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mKeyboardSwitcher.getMainKeyboardView() != null) {
// Reload keyboard because the current language has been changed.
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mCurrentSettings);
- updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability();
}
// Since we just changed languages, we should re-evaluate suggestions with whatever word
// we are currently composing. If we are not composing anything, we may want to display
@@ -2111,17 +2117,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler.postUpdateSuggestionStrip();
}
- private void updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability() {
- final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
- if (mainKeyboardView != null) {
- final boolean shouldHandleGesture = mCurrentSettings.mGestureInputEnabled
- && mIsMainDictionaryAvailable;
- mainKeyboardView.setGestureHandlingMode(shouldHandleGesture,
- mCurrentSettings.mGesturePreviewTrailEnabled,
- mCurrentSettings.mGestureFloatingPreviewTextEnabled);
- }
- }
-
// TODO: Remove this method from {@link LatinIME} and move {@link FeedbackManager} to
// {@link KeyboardSwitcher}. Called from KeyboardSwitcher
public void hapticAndAudioFeedback(final int primaryCode) {