Merge "Pull up some more common code (A95)"

main
Jean Chalard 2012-07-10 22:48:38 -07:00 committed by Android (Google) Code Review
commit 0b329fd0d1
1 changed files with 13 additions and 15 deletions

View File

@ -111,24 +111,26 @@ public class BinaryDictionary extends Dictionary {
Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE); Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE);
Arrays.fill(mOutputChars, (char) 0); Arrays.fill(mOutputChars, (char) 0);
Arrays.fill(mOutputScores, 0); Arrays.fill(mOutputScores, 0);
// TODO: toLowerCase in the native code
final int[] prevWordCodePointArray = (null == prevWord)
? null : StringUtils.toCodePointArray(prevWord.toString());
if (composer.size() <= 1) { if (composer.size() <= 1) {
return TextUtils.isEmpty(prevWord) ? null : getBigramsInternal(composer, prevWord); return TextUtils.isEmpty(prevWord) ? null : getBigramsInternal(composer,
prevWordCodePointArray);
} else { } else {
return getWordsInternal(composer, prevWord, proximityInfo); return getWordsInternal(composer, prevWordCodePointArray, proximityInfo);
} }
} }
// TODO: move to native code // TODO: move to native code
private ArrayList<SuggestedWordInfo> getBigramsInternal(final WordComposer codes, private ArrayList<SuggestedWordInfo> getBigramsInternal(final WordComposer codes,
final CharSequence previousWord) { final int[] previousWord) {
int[] codePoints = StringUtils.toCodePointArray(previousWord.toString());
int codesSize = codes.size(); int codesSize = codes.size();
if (codesSize > 0) { if (codesSize > 0) {
mInputCodes[0] = codes.getCodeAt(0); mInputCodes[0] = codes.getCodeAt(0);
} }
int count = getBigramsNative(mNativeDict, codePoints, codePoints.length, mInputCodes, int count = getBigramsNative(mNativeDict, previousWord, previousWord.length, mInputCodes,
codesSize, mOutputChars, mOutputScores, MAX_WORD_LENGTH, MAX_BIGRAMS); codesSize, mOutputChars, mOutputScores, MAX_WORD_LENGTH, MAX_BIGRAMS);
if (count > MAX_BIGRAMS) { if (count > MAX_BIGRAMS) {
count = MAX_BIGRAMS; count = MAX_BIGRAMS;
@ -154,9 +156,9 @@ public class BinaryDictionary extends Dictionary {
// TODO: move to native code // TODO: move to native code
// proximityInfo and/or prevWordForBigrams may not be null. // proximityInfo and/or prevWordForBigrams may not be null.
private ArrayList<SuggestedWordInfo> getWordsInternal(final WordComposer codes, private ArrayList<SuggestedWordInfo> getWordsInternal(final WordComposer codes,
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) { final int[] prevWord, final ProximityInfo proximityInfo) {
final int count = getWordsInternalInternal(codes, prevWordForBigrams, proximityInfo, final int count = getWordsInternalInternal(codes, prevWord, proximityInfo, mOutputChars,
mOutputChars, mOutputScores, mSpaceIndices); mOutputScores, mSpaceIndices);
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>(); final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
for (int j = 0; j < count; ++j) { for (int j = 0; j < count; ++j) {
@ -183,7 +185,7 @@ public class BinaryDictionary extends Dictionary {
// proximityInfo may not be null. // proximityInfo may not be null.
// TODO: remove this method by inlining it into getWordsInternal // TODO: remove this method by inlining it into getWordsInternal
private int getWordsInternalInternal(final WordComposer codes, private int getWordsInternalInternal(final WordComposer codes,
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo, final int[] prevWord, final ProximityInfo proximityInfo,
char[] outputChars, int[] scores, int[] spaceIndices) { char[] outputChars, int[] scores, int[] spaceIndices) {
final InputPointers ips = codes.getInputPointers(); final InputPointers ips = codes.getInputPointers();
final boolean isGesture = codes.isBatchMode(); final boolean isGesture = codes.isBatchMode();
@ -199,13 +201,9 @@ public class BinaryDictionary extends Dictionary {
} }
} }
// TODO: toLowerCase in the native code
final int[] prevWordCodePointArray = (null == prevWordForBigrams)
? null : StringUtils.toCodePointArray(prevWordForBigrams.toString());
return getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(), return getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(),
ips.getXCoordinates(), ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(), ips.getXCoordinates(), ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(),
mInputCodes, codesSize, 0 /* unused */, isGesture, prevWordCodePointArray, mInputCodes, codesSize, 0 /* unused */, isGesture, prevWord,
mUseFullEditDistance, outputChars, scores, spaceIndices); mUseFullEditDistance, outputChars, scores, spaceIndices);
} }