Merge "Come back the proximity correction to ExpandableDictionary"

main
satok 2012-04-02 01:20:26 -07:00 committed by Android (Google) Code Review
commit 6747b30a64
2 changed files with 35 additions and 3 deletions

View File

@ -213,6 +213,31 @@ public class ProximityInfo {
touchPositionCorrection); 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) { public Key[] getNearestKeys(int x, int y) {
if (mGridNeighbors == null) { if (mGridNeighbors == null) {
return EMPTY_KEY_ARRAY; return EMPTY_KEY_ARRAY;

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import android.content.Context; import android.content.Context;
import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
@ -209,13 +210,19 @@ public class ExpandableDictionary extends Dictionary {
@SuppressWarnings("unused") final ProximityInfo proximityInfo) { @SuppressWarnings("unused") final ProximityInfo proximityInfo) {
mInputLength = codes.size(); mInputLength = codes.size();
if (mCodes.length < mInputLength) mCodes = new int[mInputLength][]; 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 // Cache the codes so that we don't have to lookup an array list
for (int i = 0; i < mInputLength; i++) { for (int i = 0; i < mInputLength; i++) {
// TODO: Calculate proximity info here. // TODO: Calculate proximity info here.
if (mCodes[i] == null || mCodes[i].length < 1) { 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; mMaxDepth = mInputLength * 3;
getWordsRec(mRoots, codes, mWordBuilder, 0, false, 1, 0, -1, callback); 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++) { for (int j = 0; j < alternativesSize; j++) {
final int addedAttenuation = (j > 0 ? 1 : 2); final int addedAttenuation = (j > 0 ? 1 : 2);
final int currentChar = currentChars[j]; final int currentChar = currentChars[j];
if (currentChar == -1) { if (currentChar == KeyDetector.NOT_A_CODE) {
break; break;
} }
if (currentChar == lowerC || currentChar == c) { if (currentChar == lowerC || currentChar == c) {