parent
737c87a5f1
commit
71538b08e4
|
@ -199,10 +199,12 @@ public class BinaryDictionary extends Dictionary {
|
||||||
//final int commitPoint = codes.getCommitPoint();
|
//final int commitPoint = codes.getCommitPoint();
|
||||||
//codes.clearCommitPoint();
|
//codes.clearCommitPoint();
|
||||||
|
|
||||||
|
final InputPointers ips = codes.getInputPointers();
|
||||||
|
|
||||||
return getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(),
|
return getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(),
|
||||||
codes.getXCoordinates(), codes.getYCoordinates(), emptyArray, emptyArray, mInputCodes,
|
ips.getXCoordinates(), ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(),
|
||||||
codesSize, 0 /* unused */, false, prevWordCodePointArray, mUseFullEditDistance,
|
mInputCodes, codesSize, 0 /* unused */, false, prevWordCodePointArray,
|
||||||
outputChars, scores, spaceIndices);
|
mUseFullEditDistance, outputChars, scores, spaceIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float calcNormalizedScore(String before, String after, int score) {
|
public static float calcNormalizedScore(String before, String after, int score) {
|
||||||
|
|
|
@ -268,8 +268,9 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
|
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
|
||||||
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 InputPointers ips = codes.getInputPointers();
|
||||||
final int[] yCoordinates = codes.getYCoordinates();
|
final int[] xCoordinates = ips.getXCoordinates();
|
||||||
|
final int[] yCoordinates = ips.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.
|
||||||
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class InputPointers {
|
||||||
|
private final ScalableIntArray mXCoordinates = new ScalableIntArray();
|
||||||
|
private final ScalableIntArray mYCoordinates = new ScalableIntArray();
|
||||||
|
private final ScalableIntArray mPointerIds = new ScalableIntArray();
|
||||||
|
private final ScalableIntArray mTimes = new ScalableIntArray();
|
||||||
|
|
||||||
|
public void addPointer(int index, int x, int y, int pointerId, int time) {
|
||||||
|
mXCoordinates.add(index, x);
|
||||||
|
mYCoordinates.add(index, y);
|
||||||
|
mPointerIds.add(index, pointerId);
|
||||||
|
mTimes.add(index, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPointer(int x, int y, int pointerId, int time) {
|
||||||
|
mXCoordinates.add(x);
|
||||||
|
mYCoordinates.add(y);
|
||||||
|
mPointerIds.add(pointerId);
|
||||||
|
mTimes.add(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(InputPointers ip) {
|
||||||
|
mXCoordinates.set(ip.mXCoordinates);
|
||||||
|
mYCoordinates.set(ip.mYCoordinates);
|
||||||
|
mPointerIds.set(ip.mPointerIds);
|
||||||
|
mTimes.set(ip.mTimes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copy(InputPointers ip) {
|
||||||
|
mXCoordinates.copy(ip.mXCoordinates);
|
||||||
|
mYCoordinates.copy(ip.mYCoordinates);
|
||||||
|
mPointerIds.copy(ip.mPointerIds);
|
||||||
|
mTimes.copy(ip.mTimes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
mXCoordinates.reset();
|
||||||
|
mYCoordinates.reset();
|
||||||
|
mPointerIds.reset();
|
||||||
|
mTimes.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPointerSize() {
|
||||||
|
return mXCoordinates.getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getXCoordinates() {
|
||||||
|
return mXCoordinates.mArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getYCoordinates() {
|
||||||
|
return mYCoordinates.mArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getPointerIds() {
|
||||||
|
return mPointerIds.mArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getTimes() {
|
||||||
|
return mTimes.mArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ScalableIntArray {
|
||||||
|
private static final int DEFAULT_SIZE = BinaryDictionary.MAX_WORD_LENGTH;
|
||||||
|
private int[] mArray;
|
||||||
|
private int mLength;
|
||||||
|
|
||||||
|
public ScalableIntArray() {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int index, int val) {
|
||||||
|
if (mLength < index + 1) {
|
||||||
|
mLength = index;
|
||||||
|
add(val);
|
||||||
|
} else {
|
||||||
|
mArray[index] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int val) {
|
||||||
|
if (mLength >= mArray.length) {
|
||||||
|
final int[] newArray = new int[mLength * 2];
|
||||||
|
System.arraycopy(mArray, 0, newArray, 0, mLength);
|
||||||
|
}
|
||||||
|
mArray[mLength] = val;
|
||||||
|
++mLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return mLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
mArray = new int[DEFAULT_SIZE];
|
||||||
|
mLength = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getPrimitiveArray() {
|
||||||
|
return mArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copy(ScalableIntArray ip) {
|
||||||
|
mArray = Arrays.copyOf(ip.mArray, ip.mArray.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(ScalableIntArray ip) {
|
||||||
|
mArray = ip.mArray;
|
||||||
|
mLength = ip.mLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,26 +41,26 @@ public class LastComposedWord {
|
||||||
public static final int NOT_A_SEPARATOR = -1;
|
public static final int NOT_A_SEPARATOR = -1;
|
||||||
|
|
||||||
public final int[] mPrimaryKeyCodes;
|
public final int[] mPrimaryKeyCodes;
|
||||||
public final int[] mXCoordinates;
|
|
||||||
public final int[] mYCoordinates;
|
|
||||||
public final String mTypedWord;
|
public final String mTypedWord;
|
||||||
public final String mCommittedWord;
|
public final String mCommittedWord;
|
||||||
public final int mSeparatorCode;
|
public final int mSeparatorCode;
|
||||||
public final CharSequence mPrevWord;
|
public final CharSequence mPrevWord;
|
||||||
|
public final InputPointers mInputPointers = new InputPointers();
|
||||||
|
|
||||||
private boolean mActive;
|
private boolean mActive;
|
||||||
|
|
||||||
public static final LastComposedWord NOT_A_COMPOSED_WORD =
|
public static final LastComposedWord NOT_A_COMPOSED_WORD =
|
||||||
new LastComposedWord(null, null, null, "", "", NOT_A_SEPARATOR, null);
|
new LastComposedWord(null, null, "", "", NOT_A_SEPARATOR, null);
|
||||||
|
|
||||||
// Warning: this is using the passed objects as is and fully expects them to be
|
// Warning: this is using the passed objects as is and fully expects them to be
|
||||||
// immutable. Do not fiddle with their contents after you passed them to this constructor.
|
// immutable. Do not fiddle with their contents after you passed them to this constructor.
|
||||||
public LastComposedWord(final int[] primaryKeyCodes, final int[] xCoordinates,
|
public LastComposedWord(final int[] primaryKeyCodes, final InputPointers inputPointers,
|
||||||
final int[] yCoordinates, final String typedWord, final String committedWord,
|
final String typedWord, final String committedWord,
|
||||||
final int separatorCode, final CharSequence prevWord) {
|
final int separatorCode, final CharSequence prevWord) {
|
||||||
mPrimaryKeyCodes = primaryKeyCodes;
|
mPrimaryKeyCodes = primaryKeyCodes;
|
||||||
mXCoordinates = xCoordinates;
|
if (inputPointers != null) {
|
||||||
mYCoordinates = yCoordinates;
|
mInputPointers.copy(inputPointers);
|
||||||
|
}
|
||||||
mTypedWord = typedWord;
|
mTypedWord = typedWord;
|
||||||
mCommittedWord = committedWord;
|
mCommittedWord = committedWord;
|
||||||
mSeparatorCode = separatorCode;
|
mSeparatorCode = separatorCode;
|
||||||
|
|
|
@ -34,8 +34,7 @@ public class WordComposer {
|
||||||
private static final int N = BinaryDictionary.MAX_WORD_LENGTH;
|
private static final int N = BinaryDictionary.MAX_WORD_LENGTH;
|
||||||
|
|
||||||
private int[] mPrimaryKeyCodes;
|
private int[] mPrimaryKeyCodes;
|
||||||
private int[] mXCoordinates;
|
private final InputPointers mInputPointers = new InputPointers();
|
||||||
private int[] mYCoordinates;
|
|
||||||
private StringBuilder mTypedWord;
|
private StringBuilder mTypedWord;
|
||||||
private CharSequence mAutoCorrection;
|
private CharSequence mAutoCorrection;
|
||||||
private boolean mIsResumed;
|
private boolean mIsResumed;
|
||||||
|
@ -54,8 +53,6 @@ public class WordComposer {
|
||||||
public WordComposer() {
|
public WordComposer() {
|
||||||
mPrimaryKeyCodes = new int[N];
|
mPrimaryKeyCodes = new int[N];
|
||||||
mTypedWord = new StringBuilder(N);
|
mTypedWord = new StringBuilder(N);
|
||||||
mXCoordinates = new int[N];
|
|
||||||
mYCoordinates = new int[N];
|
|
||||||
mAutoCorrection = null;
|
mAutoCorrection = null;
|
||||||
mTrailingSingleQuotesCount = 0;
|
mTrailingSingleQuotesCount = 0;
|
||||||
mIsResumed = false;
|
mIsResumed = false;
|
||||||
|
@ -69,8 +66,7 @@ public class WordComposer {
|
||||||
public void init(WordComposer source) {
|
public void init(WordComposer source) {
|
||||||
mPrimaryKeyCodes = Arrays.copyOf(source.mPrimaryKeyCodes, source.mPrimaryKeyCodes.length);
|
mPrimaryKeyCodes = Arrays.copyOf(source.mPrimaryKeyCodes, source.mPrimaryKeyCodes.length);
|
||||||
mTypedWord = new StringBuilder(source.mTypedWord);
|
mTypedWord = new StringBuilder(source.mTypedWord);
|
||||||
mXCoordinates = Arrays.copyOf(source.mXCoordinates, source.mXCoordinates.length);
|
mInputPointers.copy(source.mInputPointers);
|
||||||
mYCoordinates = Arrays.copyOf(source.mYCoordinates, source.mYCoordinates.length);
|
|
||||||
mCapsCount = source.mCapsCount;
|
mCapsCount = source.mCapsCount;
|
||||||
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
|
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
|
||||||
mAutoCapitalized = source.mAutoCapitalized;
|
mAutoCapitalized = source.mAutoCapitalized;
|
||||||
|
@ -116,12 +112,8 @@ public class WordComposer {
|
||||||
return mPrimaryKeyCodes[index];
|
return mPrimaryKeyCodes[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getXCoordinates() {
|
public InputPointers getInputPointers() {
|
||||||
return mXCoordinates;
|
return mInputPointers;
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getYCoordinates() {
|
|
||||||
return mYCoordinates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isFirstCharCapitalized(int index, int codePoint, boolean previous) {
|
private static boolean isFirstCharCapitalized(int index, int codePoint, boolean previous) {
|
||||||
|
@ -157,8 +149,8 @@ public class WordComposer {
|
||||||
if (newIndex < BinaryDictionary.MAX_WORD_LENGTH) {
|
if (newIndex < BinaryDictionary.MAX_WORD_LENGTH) {
|
||||||
mPrimaryKeyCodes[newIndex] = primaryCode >= Keyboard.CODE_SPACE
|
mPrimaryKeyCodes[newIndex] = primaryCode >= Keyboard.CODE_SPACE
|
||||||
? Character.toLowerCase(primaryCode) : primaryCode;
|
? Character.toLowerCase(primaryCode) : primaryCode;
|
||||||
mXCoordinates[newIndex] = keyX;
|
// TODO: Set correct pointer id and time
|
||||||
mYCoordinates[newIndex] = keyY;
|
mInputPointers.addPointer(newIndex, keyX, keyY, 0, 0);
|
||||||
}
|
}
|
||||||
mIsFirstCharCapitalized = isFirstCharCapitalized(
|
mIsFirstCharCapitalized = isFirstCharCapitalized(
|
||||||
newIndex, primaryCode, mIsFirstCharCapitalized);
|
newIndex, primaryCode, mIsFirstCharCapitalized);
|
||||||
|
@ -318,14 +310,11 @@ public class WordComposer {
|
||||||
// or a DECIDED_WORD we may cancel the commit later; otherwise, we should deactivate
|
// or a DECIDED_WORD we may cancel the commit later; otherwise, we should deactivate
|
||||||
// the last composed word to ensure this does not happen.
|
// the last composed word to ensure this does not happen.
|
||||||
final int[] primaryKeyCodes = mPrimaryKeyCodes;
|
final int[] primaryKeyCodes = mPrimaryKeyCodes;
|
||||||
final int[] xCoordinates = mXCoordinates;
|
|
||||||
final int[] yCoordinates = mYCoordinates;
|
|
||||||
mPrimaryKeyCodes = new int[N];
|
mPrimaryKeyCodes = new int[N];
|
||||||
mXCoordinates = new int[N];
|
|
||||||
mYCoordinates = new int[N];
|
|
||||||
final LastComposedWord lastComposedWord = new LastComposedWord(primaryKeyCodes,
|
final LastComposedWord lastComposedWord = new LastComposedWord(primaryKeyCodes,
|
||||||
xCoordinates, yCoordinates, mTypedWord.toString(), committedWord, separatorCode,
|
mInputPointers, mTypedWord.toString(), committedWord, separatorCode,
|
||||||
prevWord);
|
prevWord);
|
||||||
|
mInputPointers.reset();
|
||||||
if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD
|
if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD
|
||||||
&& type != LastComposedWord.COMMIT_TYPE_MANUAL_PICK) {
|
&& type != LastComposedWord.COMMIT_TYPE_MANUAL_PICK) {
|
||||||
lastComposedWord.deactivate();
|
lastComposedWord.deactivate();
|
||||||
|
@ -339,8 +328,7 @@ public class WordComposer {
|
||||||
|
|
||||||
public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord) {
|
public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord) {
|
||||||
mPrimaryKeyCodes = lastComposedWord.mPrimaryKeyCodes;
|
mPrimaryKeyCodes = lastComposedWord.mPrimaryKeyCodes;
|
||||||
mXCoordinates = lastComposedWord.mXCoordinates;
|
mInputPointers.set(lastComposedWord.mInputPointers);
|
||||||
mYCoordinates = lastComposedWord.mYCoordinates;
|
|
||||||
mTypedWord.setLength(0);
|
mTypedWord.setLength(0);
|
||||||
mTypedWord.append(lastComposedWord.mTypedWord);
|
mTypedWord.append(lastComposedWord.mTypedWord);
|
||||||
refreshSize();
|
refreshSize();
|
||||||
|
|
Loading…
Reference in New Issue