diff options
author | 2012-04-02 14:26:36 +0900 | |
---|---|---|
committer | 2012-04-02 15:01:21 +0900 | |
commit | 209dd09e5a534b5819c70fbc5cc1ef056f77d1a3 (patch) | |
tree | 9e0c4f2e51be5daea81f7cfacaf28f67e69e7967 /java/src | |
parent | 96fdc4dd8426a078500ce1d8a104bde7201bf9b5 (diff) | |
download | latinime-209dd09e5a534b5819c70fbc5cc1ef056f77d1a3.tar.gz latinime-209dd09e5a534b5819c70fbc5cc1ef056f77d1a3.tar.xz latinime-209dd09e5a534b5819c70fbc5cc1ef056f77d1a3.zip |
Come back the proximity correction to ExpandableDictionary
Bug: 6242539
Change-Id: Ic0467d54c9d85d0653812d4e127328878ef15b94
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/ProximityInfo.java | 25 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/ExpandableDictionary.java | 13 |
2 files changed, 35 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index 5c1808613..6b59a8dae 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -213,6 +213,31 @@ public class ProximityInfo { touchPositionCorrection); } + public void fillArrayWithNearestKeyCodes(int x, int y, int primaryKeyCode, int[] dest) { + final int destLength = dest.length; + if (destLength < 1) { + return; + } + int index = 0; + if (primaryKeyCode > Keyboard.CODE_SPACE) { + dest[index++] = primaryKeyCode; + } + final Key[] nearestKeys = getNearestKeys(x, y); + for (Key key : nearestKeys) { + if (index >= destLength) { + break; + } + final int code = key.mCode; + if (code <= Keyboard.CODE_SPACE) { + break; + } + dest[index++] = code; + } + if (index < destLength) { + dest[index] = KeyDetector.NOT_A_CODE; + } + } + public Key[] getNearestKeys(int x, int y) { if (mGridNeighbors == null) { return EMPTY_KEY_ARRAY; diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index 098913bef..46d11fa37 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import android.content.Context; +import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.ProximityInfo; @@ -209,13 +210,19 @@ public class ExpandableDictionary extends Dictionary { @SuppressWarnings("unused") final ProximityInfo proximityInfo) { mInputLength = codes.size(); if (mCodes.length < mInputLength) mCodes = new int[mInputLength][]; + final int[] xCoordinates = codes.getXCoordinates(); + final int[] yCoordinates = codes.getYCoordinates(); // Cache the codes so that we don't have to lookup an array list for (int i = 0; i < mInputLength; i++) { // TODO: Calculate proximity info here. if (mCodes[i] == null || mCodes[i].length < 1) { - mCodes[i] = new int[1]; + mCodes[i] = new int[ProximityInfo.MAX_PROXIMITY_CHARS_SIZE]; } - mCodes[i][0] = codes.getCodeAt(i); + final int x = xCoordinates != null && i < xCoordinates.length ? + xCoordinates[i] : WordComposer.NOT_A_COORDINATE; + final int y = xCoordinates != null && i < yCoordinates.length ? + yCoordinates[i] : WordComposer.NOT_A_COORDINATE; + proximityInfo.fillArrayWithNearestKeyCodes(x, y, codes.getCodeAt(i), mCodes[i]); } mMaxDepth = mInputLength * 3; getWordsRec(mRoots, codes, mWordBuilder, 0, false, 1, 0, -1, callback); @@ -328,7 +335,7 @@ public class ExpandableDictionary extends Dictionary { for (int j = 0; j < alternativesSize; j++) { final int addedAttenuation = (j > 0 ? 1 : 2); final int currentChar = currentChars[j]; - if (currentChar == -1) { + if (currentChar == KeyDetector.NOT_A_CODE) { break; } if (currentChar == lowerC || currentChar == c) { |