aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/WordComposer.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2011-11-22 11:35:40 +0900
committerJean Chalard <jchalard@google.com>2011-11-29 17:50:36 +0900
commit6b1f500da451de56932a8b2a99c63857994ece85 (patch)
tree7a86d364087fbb4aefa265f3be9826b0db99c021 /java/src/com/android/inputmethod/latin/WordComposer.java
parentc1f7d39b4aabe71ecf7934272a848d8c0fe5a7f0 (diff)
downloadlatinime-6b1f500da451de56932a8b2a99c63857994ece85.tar.gz
latinime-6b1f500da451de56932a8b2a99c63857994ece85.tar.xz
latinime-6b1f500da451de56932a8b2a99c63857994ece85.zip
Resume suggestion when backspacing to the end of a word
Bug: 5515381 Change-Id: I26fea896feaf2e9716c7ae3d4f2630360f23ac50
Diffstat (limited to 'java/src/com/android/inputmethod/latin/WordComposer.java')
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 612b16071..ef2e4d378 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -17,7 +17,9 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.KeyDetector;
+import com.android.inputmethod.keyboard.LatinKeyboard;
import java.util.ArrayList;
import java.util.Arrays;
@@ -137,6 +139,50 @@ public class WordComposer {
}
/**
+ * Internal method to retrieve reasonable proximity info for a character.
+ */
+ private void addKeyInfo(final int codePoint, final LatinKeyboard keyboard,
+ final KeyDetector keyDetector) {
+ for (final Key key : keyboard.mKeys) {
+ if (key.mCode == codePoint) {
+ final int x = key.mX + key.mWidth / 2;
+ final int y = key.mY + key.mHeight / 2;
+ final int[] codes = keyDetector.newCodeArray();
+ keyDetector.getKeyIndexAndNearbyCodes(x, y, codes);
+ add(codePoint, codes, x, y);
+ return;
+ }
+ }
+ add(codePoint, new int[] { codePoint },
+ WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
+ }
+
+ /**
+ * Set the currently composing word to the one passed as an argument.
+ * This will register NOT_A_COORDINATE for X and Ys, and use the passed keyboard for proximity.
+ */
+ public void setComposingWord(final CharSequence word, final LatinKeyboard keyboard,
+ final KeyDetector keyDetector) {
+ reset();
+ final int length = word.length();
+ for (int i = 0; i < length; ++i) {
+ int codePoint = word.charAt(i);
+ addKeyInfo(codePoint, keyboard, keyDetector);
+ }
+ }
+
+ /**
+ * Shortcut for the above method, this will create a new KeyDetector for the passed keyboard.
+ */
+ public void setComposingWord(final CharSequence word, final LatinKeyboard keyboard) {
+ final KeyDetector keyDetector = new KeyDetector(0);
+ keyDetector.setKeyboard(keyboard, 0, 0);
+ keyDetector.setProximityCorrectionEnabled(true);
+ keyDetector.setProximityThreshold(keyboard.mMostCommonKeyWidth);
+ setComposingWord(word, keyboard, keyDetector);
+ }
+
+ /**
* Swaps the first and second values in the codes array if the primary code is not the first
* value in the array but the second. This happens when the preferred key is not the key that
* the user released the finger on.