Replace useless CharSequence to String
Change-Id: Idc478f901185ee1b4912acc82d0cbc54fee4e991main
parent
243c1fecc6
commit
bc464e2952
|
@ -83,14 +83,13 @@ public final class SuggestionSpanUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CharSequence getTextWithAutoCorrectionIndicatorUnderline(
|
public static CharSequence getTextWithAutoCorrectionIndicatorUnderline(
|
||||||
Context context, CharSequence text) {
|
final Context context, final String text) {
|
||||||
if (TextUtils.isEmpty(text) || CONSTRUCTOR_SuggestionSpan == null
|
if (TextUtils.isEmpty(text) || CONSTRUCTOR_SuggestionSpan == null
|
||||||
|| OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null
|
|| OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null
|
||||||
|| OBJ_FLAG_MISSPELLED == null || OBJ_FLAG_EASY_CORRECT == null) {
|
|| OBJ_FLAG_MISSPELLED == null || OBJ_FLAG_EASY_CORRECT == null) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
final Spannable spannable = text instanceof Spannable
|
final Spannable spannable = new SpannableString(text);
|
||||||
? (Spannable) text : new SpannableString(text);
|
|
||||||
final Object[] args =
|
final Object[] args =
|
||||||
{ context, null, new String[] {}, (int)OBJ_FLAG_AUTO_CORRECTION,
|
{ context, null, new String[] {}, (int)OBJ_FLAG_AUTO_CORRECTION,
|
||||||
(Class<?>) SuggestionSpanPickedNotificationReceiver.class };
|
(Class<?>) SuggestionSpanPickedNotificationReceiver.class };
|
||||||
|
@ -104,8 +103,9 @@ public final class SuggestionSpanUtils {
|
||||||
return spannable;
|
return spannable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CharSequence getTextWithSuggestionSpan(Context context,
|
public static CharSequence getTextWithSuggestionSpan(final Context context,
|
||||||
CharSequence pickedWord, SuggestedWords suggestedWords, boolean dictionaryAvailable) {
|
final String pickedWord, final SuggestedWords suggestedWords,
|
||||||
|
final boolean dictionaryAvailable) {
|
||||||
if (!dictionaryAvailable || TextUtils.isEmpty(pickedWord)
|
if (!dictionaryAvailable || TextUtils.isEmpty(pickedWord)
|
||||||
|| CONSTRUCTOR_SuggestionSpan == null
|
|| CONSTRUCTOR_SuggestionSpan == null
|
||||||
|| suggestedWords.isEmpty() || suggestedWords.mIsPrediction
|
|| suggestedWords.isEmpty() || suggestedWords.mIsPrediction
|
||||||
|
@ -114,18 +114,13 @@ public final class SuggestionSpanUtils {
|
||||||
return pickedWord;
|
return pickedWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Spannable spannable;
|
final Spannable spannable = new SpannableString(pickedWord);
|
||||||
if (pickedWord instanceof Spannable) {
|
|
||||||
spannable = (Spannable) pickedWord;
|
|
||||||
} else {
|
|
||||||
spannable = new SpannableString(pickedWord);
|
|
||||||
}
|
|
||||||
final ArrayList<String> suggestionsList = CollectionUtils.newArrayList();
|
final ArrayList<String> suggestionsList = CollectionUtils.newArrayList();
|
||||||
for (int i = 0; i < suggestedWords.size(); ++i) {
|
for (int i = 0; i < suggestedWords.size(); ++i) {
|
||||||
if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) {
|
if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
final CharSequence word = suggestedWords.getWord(i);
|
final String word = suggestedWords.getWord(i);
|
||||||
if (!TextUtils.equals(pickedWord, word)) {
|
if (!TextUtils.equals(pickedWord, word)) {
|
||||||
suggestionsList.add(word.toString());
|
suggestionsList.add(word.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,11 +56,11 @@ public interface KeyboardActionListener {
|
||||||
public void onCodeInput(int primaryCode, int x, int y);
|
public void onCodeInput(int primaryCode, int x, int y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a sequence of characters to the listener.
|
* Sends a string of characters to the listener.
|
||||||
*
|
*
|
||||||
* @param text the sequence of characters to be displayed.
|
* @param text the string of characters to be registered.
|
||||||
*/
|
*/
|
||||||
public void onTextInput(CharSequence text);
|
public void onTextInput(String text);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when user started batch input.
|
* Called when user started batch input.
|
||||||
|
@ -99,7 +99,7 @@ public interface KeyboardActionListener {
|
||||||
@Override
|
@Override
|
||||||
public void onCodeInput(int primaryCode, int x, int y) {}
|
public void onCodeInput(int primaryCode, int x, int y) {}
|
||||||
@Override
|
@Override
|
||||||
public void onTextInput(CharSequence text) {}
|
public void onTextInput(String text) {}
|
||||||
@Override
|
@Override
|
||||||
public void onStartBatchInput() {}
|
public void onStartBatchInput() {}
|
||||||
@Override
|
@Override
|
||||||
|
@ -114,7 +114,7 @@ public interface KeyboardActionListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method when the vertical correction is removed.
|
// TODO: Remove this method when the vertical correction is removed.
|
||||||
public static boolean isInvalidCoordinate(int coordinate) {
|
public static boolean isInvalidCoordinate(final int coordinate) {
|
||||||
// Detect {@link Constants#NOT_A_COORDINATE},
|
// Detect {@link Constants#NOT_A_COORDINATE},
|
||||||
// {@link Constants#SUGGESTION_STRIP_COORDINATE}, and
|
// {@link Constants#SUGGESTION_STRIP_COORDINATE}, and
|
||||||
// {@link Constants#SPELL_CHECKER_COORDINATE}.
|
// {@link Constants#SPELL_CHECKER_COORDINATE}.
|
||||||
|
|
|
@ -48,7 +48,7 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
|
||||||
private final KeyboardActionListener mMoreKeysKeyboardListener =
|
private final KeyboardActionListener mMoreKeysKeyboardListener =
|
||||||
new KeyboardActionListener.Adapter() {
|
new KeyboardActionListener.Adapter() {
|
||||||
@Override
|
@Override
|
||||||
public void onCodeInput(int primaryCode, int x, int y) {
|
public void onCodeInput(final int primaryCode, final int x, final int y) {
|
||||||
// Because a more keys keyboard doesn't need proximity characters correction, we don't
|
// Because a more keys keyboard doesn't need proximity characters correction, we don't
|
||||||
// send touch event coordinates.
|
// send touch event coordinates.
|
||||||
mListener.onCodeInput(
|
mListener.onCodeInput(
|
||||||
|
@ -56,7 +56,7 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextInput(CharSequence text) {
|
public void onTextInput(final String text) {
|
||||||
mListener.onTextInput(text);
|
mListener.onTextInput(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,12 +66,12 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateBatchInput(InputPointers batchPointers) {
|
public void onUpdateBatchInput(final InputPointers batchPointers) {
|
||||||
mListener.onUpdateBatchInput(batchPointers);
|
mListener.onUpdateBatchInput(batchPointers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEndBatchInput(InputPointers batchPointers) {
|
public void onEndBatchInput(final InputPointers batchPointers) {
|
||||||
mListener.onEndBatchInput(batchPointers);
|
mListener.onEndBatchInput(batchPointers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,21 +81,22 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPressKey(int primaryCode) {
|
public void onPressKey(final int primaryCode) {
|
||||||
mListener.onPressKey(primaryCode);
|
mListener.onPressKey(primaryCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReleaseKey(int primaryCode, boolean withSliding) {
|
public void onReleaseKey(final int primaryCode, final boolean withSliding) {
|
||||||
mListener.onReleaseKey(primaryCode, withSliding);
|
mListener.onReleaseKey(primaryCode, withSliding);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public MoreKeysKeyboardView(Context context, AttributeSet attrs) {
|
public MoreKeysKeyboardView(final Context context, final AttributeSet attrs) {
|
||||||
this(context, attrs, R.attr.moreKeysKeyboardViewStyle);
|
this(context, attrs, R.attr.moreKeysKeyboardViewStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MoreKeysKeyboardView(Context context, AttributeSet attrs, int defStyle) {
|
public MoreKeysKeyboardView(final Context context, final AttributeSet attrs,
|
||||||
|
final int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
|
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
|
@ -105,7 +106,7 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
|
||||||
final Keyboard keyboard = getKeyboard();
|
final Keyboard keyboard = getKeyboard();
|
||||||
if (keyboard != null) {
|
if (keyboard != null) {
|
||||||
final int width = keyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight();
|
final int width = keyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight();
|
||||||
|
@ -117,7 +118,7 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setKeyboard(Keyboard keyboard) {
|
public void setKeyboard(final Keyboard keyboard) {
|
||||||
super.setKeyboard(keyboard);
|
super.setKeyboard(keyboard);
|
||||||
mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(),
|
mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(),
|
||||||
-getPaddingTop() + mVerticalCorrection);
|
-getPaddingTop() + mVerticalCorrection);
|
||||||
|
@ -144,15 +145,16 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) {
|
public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
|
||||||
// More keys keyboard needs no pop-up key preview displayed, so we pass always false with a
|
// More keys keyboard needs no pop-up key preview displayed, so we pass always false with a
|
||||||
// delay of 0. The delay does not matter actually since the popup is not shown anyway.
|
// delay of 0. The delay does not matter actually since the popup is not shown anyway.
|
||||||
super.setKeyPreviewPopupEnabled(false, 0);
|
super.setKeyPreviewPopupEnabled(false, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY,
|
public void showMoreKeysPanel(final View parentView, final Controller controller,
|
||||||
PopupWindow window, KeyboardActionListener listener) {
|
final int pointX, final int pointY, final PopupWindow window,
|
||||||
|
final KeyboardActionListener listener) {
|
||||||
mController = controller;
|
mController = controller;
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
final View container = (View)getParent();
|
final View container = (View)getParent();
|
||||||
|
@ -185,12 +187,12 @@ public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int translateX(int x) {
|
public int translateX(final int x) {
|
||||||
return x - mOriginX;
|
return x - mOriginX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int translateY(int y) {
|
public int translateY(final int y) {
|
||||||
return y - mOriginY;
|
return y - mOriginY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,11 +33,11 @@ public final class AutoCorrection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidWord(final ConcurrentHashMap<String, Dictionary> dictionaries,
|
public static boolean isValidWord(final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
CharSequence word, boolean ignoreCase) {
|
final String word, final boolean ignoreCase) {
|
||||||
if (TextUtils.isEmpty(word)) {
|
if (TextUtils.isEmpty(word)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final CharSequence lowerCasedWord = word.toString().toLowerCase();
|
final String lowerCasedWord = word.toLowerCase();
|
||||||
for (final String key : dictionaries.keySet()) {
|
for (final String key : dictionaries.keySet()) {
|
||||||
final Dictionary dictionary = dictionaries.get(key);
|
final Dictionary dictionary = dictionaries.get(key);
|
||||||
// It's unclear how realistically 'dictionary' can be null, but the monkey is somehow
|
// It's unclear how realistically 'dictionary' can be null, but the monkey is somehow
|
||||||
|
@ -57,7 +57,7 @@ public final class AutoCorrection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxFrequency(final ConcurrentHashMap<String, Dictionary> dictionaries,
|
public static int getMaxFrequency(final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
CharSequence word) {
|
final String word) {
|
||||||
if (TextUtils.isEmpty(word)) {
|
if (TextUtils.isEmpty(word)) {
|
||||||
return Dictionary.NOT_A_PROBABILITY;
|
return Dictionary.NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
@ -76,12 +76,13 @@ public final class AutoCorrection {
|
||||||
// Returns true if this is in any of the dictionaries.
|
// Returns true if this is in any of the dictionaries.
|
||||||
public static boolean isInTheDictionary(
|
public static boolean isInTheDictionary(
|
||||||
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
final CharSequence word, final boolean ignoreCase) {
|
final String word, final boolean ignoreCase) {
|
||||||
return isValidWord(dictionaries, word, ignoreCase);
|
return isValidWord(dictionaries, word, ignoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean suggestionExceedsAutoCorrectionThreshold(SuggestedWordInfo suggestion,
|
public static boolean suggestionExceedsAutoCorrectionThreshold(
|
||||||
CharSequence consideredWord, float autoCorrectionThreshold) {
|
final SuggestedWordInfo suggestion, final String consideredWord,
|
||||||
|
final float autoCorrectionThreshold) {
|
||||||
if (null != suggestion) {
|
if (null != suggestion) {
|
||||||
// Shortlist a whitelisted word
|
// Shortlist a whitelisted word
|
||||||
if (suggestion.mKind == SuggestedWordInfo.KIND_WHITELIST) return true;
|
if (suggestion.mKind == SuggestedWordInfo.KIND_WHITELIST) return true;
|
||||||
|
@ -89,8 +90,7 @@ public final class AutoCorrection {
|
||||||
// TODO: when the normalized score of the first suggestion is nearly equals to
|
// TODO: when the normalized score of the first suggestion is nearly equals to
|
||||||
// the normalized score of the second suggestion, behave less aggressive.
|
// the normalized score of the second suggestion, behave less aggressive.
|
||||||
final float normalizedScore = BinaryDictionary.calcNormalizedScore(
|
final float normalizedScore = BinaryDictionary.calcNormalizedScore(
|
||||||
consideredWord.toString(), suggestion.mWord.toString(),
|
consideredWord, suggestion.mWord, autoCorrectionSuggestionScore);
|
||||||
autoCorrectionSuggestionScore);
|
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "Normalized " + consideredWord + "," + suggestion + ","
|
Log.d(TAG, "Normalized " + consideredWord + "," + suggestion + ","
|
||||||
+ autoCorrectionSuggestionScore + ", " + normalizedScore
|
+ autoCorrectionSuggestionScore + ", " + normalizedScore
|
||||||
|
@ -100,8 +100,7 @@ public final class AutoCorrection {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "Auto corrected by S-threshold.");
|
Log.d(TAG, "Auto corrected by S-threshold.");
|
||||||
}
|
}
|
||||||
return !shouldBlockAutoCorrectionBySafetyNet(consideredWord.toString(),
|
return !shouldBlockAutoCorrectionBySafetyNet(consideredWord, suggestion.mWord);
|
||||||
suggestion.mWord);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -110,7 +109,7 @@ public final class AutoCorrection {
|
||||||
// TODO: Resolve the inconsistencies between the native auto correction algorithms and
|
// TODO: Resolve the inconsistencies between the native auto correction algorithms and
|
||||||
// this safety net
|
// this safety net
|
||||||
public static boolean shouldBlockAutoCorrectionBySafetyNet(final String typedWord,
|
public static boolean shouldBlockAutoCorrectionBySafetyNet(final String typedWord,
|
||||||
final CharSequence suggestion) {
|
final String suggestion) {
|
||||||
// Safety net for auto correction.
|
// Safety net for auto correction.
|
||||||
// Actually if we hit this safety net, it's a bug.
|
// Actually if we hit this safety net, it's a bug.
|
||||||
// If user selected aggressive auto correction mode, there is no need to use the safety
|
// If user selected aggressive auto correction mode, there is no need to use the safety
|
||||||
|
@ -123,7 +122,7 @@ public final class AutoCorrection {
|
||||||
}
|
}
|
||||||
final int maxEditDistanceOfNativeDictionary =
|
final int maxEditDistanceOfNativeDictionary =
|
||||||
(typedWordLength < 5 ? 2 : typedWordLength / 2) + 1;
|
(typedWordLength < 5 ? 2 : typedWordLength / 2) + 1;
|
||||||
final int distance = BinaryDictionary.editDistance(typedWord, suggestion.toString());
|
final int distance = BinaryDictionary.editDistance(typedWord, suggestion);
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "Autocorrected edit distance = " + distance
|
Log.d(TAG, "Autocorrected edit distance = " + distance
|
||||||
+ ", " + maxEditDistanceOfNativeDictionary);
|
+ ", " + maxEditDistanceOfNativeDictionary);
|
||||||
|
|
|
@ -64,7 +64,7 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
|
|
||||||
// TODO: There should be a way to remove used DicTraverseSession objects from
|
// TODO: There should be a way to remove used DicTraverseSession objects from
|
||||||
// {@code mDicTraverseSessions}.
|
// {@code mDicTraverseSessions}.
|
||||||
private DicTraverseSession getTraverseSession(int traverseSessionId) {
|
private DicTraverseSession getTraverseSession(final int traverseSessionId) {
|
||||||
synchronized(mDicTraverseSessions) {
|
synchronized(mDicTraverseSessions) {
|
||||||
DicTraverseSession traverseSession = mDicTraverseSessions.get(traverseSessionId);
|
DicTraverseSession traverseSession = mDicTraverseSessions.get(traverseSessionId);
|
||||||
if (traverseSession == null) {
|
if (traverseSession == null) {
|
||||||
|
@ -116,26 +116,27 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
private static native int editDistanceNative(char[] before, char[] after);
|
private static native int editDistanceNative(char[] before, char[] after);
|
||||||
|
|
||||||
// TODO: Move native dict into session
|
// TODO: Move native dict into session
|
||||||
private final void loadDictionary(String path, long startOffset, long length) {
|
private final void loadDictionary(final String path, final long startOffset,
|
||||||
|
final long length) {
|
||||||
mNativeDict = openNative(path, startOffset, length, FULL_WORD_SCORE_MULTIPLIER,
|
mNativeDict = openNative(path, startOffset, length, FULL_WORD_SCORE_MULTIPLIER,
|
||||||
MAX_WORD_LENGTH, MAX_WORDS, MAX_PREDICTIONS);
|
MAX_WORD_LENGTH, MAX_WORDS, MAX_PREDICTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
final String prevWord, final ProximityInfo proximityInfo) {
|
||||||
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, 0);
|
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo, int sessionId) {
|
final String prevWord, final ProximityInfo proximityInfo, int sessionId) {
|
||||||
if (!isValidDictionary()) return null;
|
if (!isValidDictionary()) return null;
|
||||||
|
|
||||||
Arrays.fill(mInputCodePoints, Constants.NOT_A_CODE);
|
Arrays.fill(mInputCodePoints, Constants.NOT_A_CODE);
|
||||||
// TODO: toLowerCase in the native code
|
// TODO: toLowerCase in the native code
|
||||||
final int[] prevWordCodePointArray = (null == prevWord)
|
final int[] prevWordCodePointArray = (null == prevWord)
|
||||||
? null : StringUtils.toCodePointArray(prevWord.toString());
|
? null : StringUtils.toCodePointArray(prevWord);
|
||||||
final int composerSize = composer.size();
|
final int composerSize = composer.size();
|
||||||
|
|
||||||
final boolean isGesture = composer.isBatchMode();
|
final boolean isGesture = composer.isBatchMode();
|
||||||
|
@ -178,11 +179,12 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
return mNativeDict != 0;
|
return mNativeDict != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float calcNormalizedScore(String before, String after, int score) {
|
public static float calcNormalizedScore(final String before, final String after,
|
||||||
|
final int score) {
|
||||||
return calcNormalizedScoreNative(before.toCharArray(), after.toCharArray(), score);
|
return calcNormalizedScoreNative(before.toCharArray(), after.toCharArray(), score);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int editDistance(String before, String after) {
|
public static int editDistance(final String before, final String after) {
|
||||||
if (before == null || after == null) {
|
if (before == null || after == null) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
@ -190,23 +192,23 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(CharSequence word) {
|
public boolean isValidWord(final String word) {
|
||||||
return getFrequency(word) >= 0;
|
return getFrequency(word) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFrequency(CharSequence word) {
|
public int getFrequency(final String word) {
|
||||||
if (word == null) return -1;
|
if (word == null) return -1;
|
||||||
int[] codePoints = StringUtils.toCodePointArray(word.toString());
|
int[] codePoints = StringUtils.toCodePointArray(word);
|
||||||
return getFrequencyNative(mNativeDict, codePoints);
|
return getFrequencyNative(mNativeDict, codePoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add a batch process version (isValidBigramMultiple?) to avoid excessive numbers of jni
|
// TODO: Add a batch process version (isValidBigramMultiple?) to avoid excessive numbers of jni
|
||||||
// calls when checking for changes in an entire dictionary.
|
// calls when checking for changes in an entire dictionary.
|
||||||
public boolean isValidBigram(CharSequence word1, CharSequence word2) {
|
public boolean isValidBigram(final String word1, final String word2) {
|
||||||
if (TextUtils.isEmpty(word1) || TextUtils.isEmpty(word2)) return false;
|
if (TextUtils.isEmpty(word1) || TextUtils.isEmpty(word2)) return false;
|
||||||
int[] chars1 = StringUtils.toCodePointArray(word1.toString());
|
final int[] chars1 = StringUtils.toCodePointArray(word1);
|
||||||
int[] chars2 = StringUtils.toCodePointArray(word2.toString());
|
final int[] chars2 = StringUtils.toCodePointArray(word2);
|
||||||
return isValidBigramNative(mNativeDict, chars1, chars2);
|
return isValidBigramNative(mNativeDict, chars1, chars2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
*/
|
*/
|
||||||
private final boolean mUseFirstLastBigrams;
|
private final boolean mUseFirstLastBigrams;
|
||||||
|
|
||||||
public ContactsBinaryDictionary(final Context context, Locale locale) {
|
public ContactsBinaryDictionary(final Context context, final Locale locale) {
|
||||||
super(context, getFilenameWithLocale(NAME, locale.toString()), Dictionary.TYPE_CONTACTS);
|
super(context, getFilenameWithLocale(NAME, locale.toString()), Dictionary.TYPE_CONTACTS);
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
mUseFirstLastBigrams = useFirstLastBigramsForLocale(locale);
|
mUseFirstLastBigrams = useFirstLastBigramsForLocale(locale);
|
||||||
|
@ -120,7 +120,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean useFirstLastBigramsForLocale(Locale locale) {
|
private boolean useFirstLastBigramsForLocale(final Locale locale) {
|
||||||
// TODO: Add firstname/lastname bigram rules for other languages.
|
// TODO: Add firstname/lastname bigram rules for other languages.
|
||||||
if (locale != null && locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) {
|
if (locale != null && locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -128,7 +128,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWords(Cursor cursor) {
|
private void addWords(final Cursor cursor) {
|
||||||
clearFusionDictionary();
|
clearFusionDictionary();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (!cursor.isAfterLast() && count < MAX_CONTACT_COUNT) {
|
while (!cursor.isAfterLast() && count < MAX_CONTACT_COUNT) {
|
||||||
|
@ -160,7 +160,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
* Adds the words in a name (e.g., firstname/lastname) to the binary dictionary along with their
|
* Adds the words in a name (e.g., firstname/lastname) to the binary dictionary along with their
|
||||||
* bigrams depending on locale.
|
* bigrams depending on locale.
|
||||||
*/
|
*/
|
||||||
private void addName(String name) {
|
private void addName(final String name) {
|
||||||
int len = StringUtils.codePointCount(name);
|
int len = StringUtils.codePointCount(name);
|
||||||
String prevWord = null;
|
String prevWord = null;
|
||||||
// TODO: Better tokenization for non-Latin writing systems
|
// TODO: Better tokenization for non-Latin writing systems
|
||||||
|
@ -188,7 +188,8 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
/**
|
/**
|
||||||
* Returns the index of the last letter in the word, starting from position startIndex.
|
* Returns the index of the last letter in the word, starting from position startIndex.
|
||||||
*/
|
*/
|
||||||
private static int getWordEndPosition(String string, int len, int startIndex) {
|
private static int getWordEndPosition(final String string, final int len,
|
||||||
|
final int startIndex) {
|
||||||
int end;
|
int end;
|
||||||
int cp = 0;
|
int cp = 0;
|
||||||
for (end = startIndex + 1; end < len; end += Character.charCount(cp)) {
|
for (end = startIndex + 1; end < len; end += Character.charCount(cp)) {
|
||||||
|
@ -249,7 +250,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isValidName(String name) {
|
private static boolean isValidName(final String name) {
|
||||||
if (name != null && -1 == name.indexOf('@')) {
|
if (name != null && -1 == name.indexOf('@')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -259,7 +260,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
/**
|
/**
|
||||||
* Checks if the words in a name are in the current binary dictionary.
|
* Checks if the words in a name are in the current binary dictionary.
|
||||||
*/
|
*/
|
||||||
private boolean isNameInDictionary(String name) {
|
private boolean isNameInDictionary(final String name) {
|
||||||
int len = StringUtils.codePointCount(name);
|
int len = StringUtils.codePointCount(name);
|
||||||
String prevWord = null;
|
String prevWord = null;
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
|
|
|
@ -59,12 +59,12 @@ public abstract class Dictionary {
|
||||||
// TODO: pass more context than just the previous word, to enable better suggestions (n-gram
|
// TODO: pass more context than just the previous word, to enable better suggestions (n-gram
|
||||||
// and more)
|
// and more)
|
||||||
abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo);
|
final String prevWord, final ProximityInfo proximityInfo);
|
||||||
|
|
||||||
// The default implementation of this method ignores sessionId.
|
// The default implementation of this method ignores sessionId.
|
||||||
// Subclasses that want to use sessionId need to override this method.
|
// Subclasses that want to use sessionId need to override this method.
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo, int sessionId) {
|
final String prevWord, final ProximityInfo proximityInfo, final int sessionId) {
|
||||||
return getSuggestions(composer, prevWord, proximityInfo);
|
return getSuggestions(composer, prevWord, proximityInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,9 +73,9 @@ public abstract class Dictionary {
|
||||||
* @param word the word to search for. The search should be case-insensitive.
|
* @param word the word to search for. The search should be case-insensitive.
|
||||||
* @return true if the word exists, false otherwise
|
* @return true if the word exists, false otherwise
|
||||||
*/
|
*/
|
||||||
abstract public boolean isValidWord(CharSequence word);
|
abstract public boolean isValidWord(final String word);
|
||||||
|
|
||||||
public int getFrequency(CharSequence word) {
|
public int getFrequency(final String word) {
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public abstract class Dictionary {
|
||||||
* @param typedWord the word to compare with
|
* @param typedWord the word to compare with
|
||||||
* @return true if they are the same, false otherwise.
|
* @return true if they are the same, false otherwise.
|
||||||
*/
|
*/
|
||||||
protected boolean same(final char[] word, final int length, final CharSequence typedWord) {
|
protected boolean same(final char[] word, final int length, final String typedWord) {
|
||||||
if (typedWord.length() != length) {
|
if (typedWord.length() != length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public final class DictionaryCollection extends Dictionary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
final String prevWord, final ProximityInfo proximityInfo) {
|
||||||
final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries;
|
final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries;
|
||||||
if (dictionaries.isEmpty()) return null;
|
if (dictionaries.isEmpty()) return null;
|
||||||
// To avoid creating unnecessary objects, we get the list out of the first
|
// To avoid creating unnecessary objects, we get the list out of the first
|
||||||
|
@ -74,14 +74,14 @@ public final class DictionaryCollection extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(CharSequence word) {
|
public boolean isValidWord(final String word) {
|
||||||
for (int i = mDictionaries.size() - 1; i >= 0; --i)
|
for (int i = mDictionaries.size() - 1; i >= 0; --i)
|
||||||
if (mDictionaries.get(i).isValidWord(word)) return true;
|
if (mDictionaries.get(i).isValidWord(word)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFrequency(CharSequence word) {
|
public int getFrequency(final String word) {
|
||||||
int maxFreq = -1;
|
int maxFreq = -1;
|
||||||
for (int i = mDictionaries.size() - 1; i >= 0; --i) {
|
for (int i = mDictionaries.size() - 1; i >= 0; --i) {
|
||||||
final int tempFreq = mDictionaries.get(i).getFrequency(word);
|
final int tempFreq = mDictionaries.get(i).getFrequency(word);
|
||||||
|
|
|
@ -198,7 +198,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
final String prevWord, final ProximityInfo proximityInfo) {
|
||||||
asyncReloadDictionaryIfRequired();
|
asyncReloadDictionaryIfRequired();
|
||||||
if (mLocalDictionaryController.tryLock()) {
|
if (mLocalDictionaryController.tryLock()) {
|
||||||
try {
|
try {
|
||||||
|
@ -213,12 +213,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final CharSequence word) {
|
public boolean isValidWord(final String word) {
|
||||||
asyncReloadDictionaryIfRequired();
|
asyncReloadDictionaryIfRequired();
|
||||||
return isValidWordInner(word);
|
return isValidWordInner(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isValidWordInner(final CharSequence word) {
|
protected boolean isValidWordInner(final String word) {
|
||||||
if (mLocalDictionaryController.tryLock()) {
|
if (mLocalDictionaryController.tryLock()) {
|
||||||
try {
|
try {
|
||||||
return isValidWordLocked(word);
|
return isValidWordLocked(word);
|
||||||
|
@ -229,17 +229,17 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isValidWordLocked(final CharSequence word) {
|
protected boolean isValidWordLocked(final String word) {
|
||||||
if (mBinaryDictionary == null) return false;
|
if (mBinaryDictionary == null) return false;
|
||||||
return mBinaryDictionary.isValidWord(word);
|
return mBinaryDictionary.isValidWord(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isValidBigram(final CharSequence word1, final CharSequence word2) {
|
protected boolean isValidBigram(final String word1, final String word2) {
|
||||||
if (mBinaryDictionary == null) return false;
|
if (mBinaryDictionary == null) return false;
|
||||||
return mBinaryDictionary.isValidBigram(word1, word2);
|
return mBinaryDictionary.isValidBigram(word1, word2);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isValidBigramInner(final CharSequence word1, final CharSequence word2) {
|
protected boolean isValidBigramInner(final String word1, final String word2) {
|
||||||
if (mLocalDictionaryController.tryLock()) {
|
if (mLocalDictionaryController.tryLock()) {
|
||||||
try {
|
try {
|
||||||
return isValidBigramLocked(word1, word2);
|
return isValidBigramLocked(word1, word2);
|
||||||
|
@ -250,7 +250,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isValidBigramLocked(final CharSequence word1, final CharSequence word2) {
|
protected boolean isValidBigramLocked(final String word1, final String word2) {
|
||||||
if (mBinaryDictionary == null) return false;
|
if (mBinaryDictionary == null) return false;
|
||||||
return mBinaryDictionary.isValidBigram(word1, word2);
|
return mBinaryDictionary.isValidBigram(word1, word2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
mData = new Node[INCREMENT];
|
mData = new Node[INCREMENT];
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(Node n) {
|
void add(final Node n) {
|
||||||
if (mLength + 1 > mData.length) {
|
if (mLength + 1 > mData.length) {
|
||||||
Node[] tempData = new Node[mLength + INCREMENT];
|
Node[] tempData = new Node[mLength + INCREMENT];
|
||||||
if (mLength > 0) {
|
if (mLength > 0) {
|
||||||
|
@ -172,7 +172,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRequiresReload(boolean reload) {
|
public void setRequiresReload(final boolean reload) {
|
||||||
synchronized (mUpdatingLock) {
|
synchronized (mUpdatingLock) {
|
||||||
mRequiresReload = reload;
|
mRequiresReload = reload;
|
||||||
}
|
}
|
||||||
|
@ -202,8 +202,8 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
addWordRec(mRoots, word, 0, shortcutTarget, frequency, null);
|
addWordRec(mRoots, word, 0, shortcutTarget, frequency, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWordRec(NodeArray children, final String word, final int depth,
|
private void addWordRec(final NodeArray children, final String word, final int depth,
|
||||||
final String shortcutTarget, final int frequency, Node parentNode) {
|
final String shortcutTarget, final int frequency, final Node parentNode) {
|
||||||
final int wordLength = word.length();
|
final int wordLength = word.length();
|
||||||
if (wordLength <= depth) return;
|
if (wordLength <= depth) return;
|
||||||
final char c = word.charAt(depth);
|
final char c = word.charAt(depth);
|
||||||
|
@ -248,7 +248,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
final String prevWord, final ProximityInfo proximityInfo) {
|
||||||
if (reloadDictionaryIfRequired()) return null;
|
if (reloadDictionaryIfRequired()) return null;
|
||||||
if (composer.size() > 1) {
|
if (composer.size() > 1) {
|
||||||
if (composer.size() >= BinaryDictionary.MAX_WORD_LENGTH) {
|
if (composer.size() >= BinaryDictionary.MAX_WORD_LENGTH) {
|
||||||
|
@ -277,7 +277,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes,
|
protected ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes,
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
final String prevWordForBigrams, final ProximityInfo proximityInfo) {
|
||||||
final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
|
final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
|
||||||
mInputLength = codes.size();
|
mInputLength = codes.size();
|
||||||
if (mCodes.length < mInputLength) mCodes = new int[mInputLength][];
|
if (mCodes.length < mInputLength) mCodes = new int[mInputLength][];
|
||||||
|
@ -305,7 +305,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean isValidWord(CharSequence word) {
|
public synchronized boolean isValidWord(final String word) {
|
||||||
synchronized (mUpdatingLock) {
|
synchronized (mUpdatingLock) {
|
||||||
// If we need to update, start off a background task
|
// If we need to update, start off a background task
|
||||||
if (mRequiresReload) startDictionaryLoadingTaskLocked();
|
if (mRequiresReload) startDictionaryLoadingTaskLocked();
|
||||||
|
@ -320,7 +320,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
return (node == null) ? false : !node.mShortcutOnly;
|
return (node == null) ? false : !node.mShortcutOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean removeBigram(String word1, String word2) {
|
protected boolean removeBigram(final String word1, final String word2) {
|
||||||
// Refer to addOrSetBigram() about word1.toLowerCase()
|
// Refer to addOrSetBigram() about word1.toLowerCase()
|
||||||
final Node firstWord = searchWord(mRoots, word1.toLowerCase(), 0, null);
|
final Node firstWord = searchWord(mRoots, word1.toLowerCase(), 0, null);
|
||||||
final Node secondWord = searchWord(mRoots, word2, 0, null);
|
final Node secondWord = searchWord(mRoots, word2, 0, null);
|
||||||
|
@ -345,13 +345,13 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
/**
|
/**
|
||||||
* Returns the word's frequency or -1 if not found
|
* Returns the word's frequency or -1 if not found
|
||||||
*/
|
*/
|
||||||
protected int getWordFrequency(CharSequence word) {
|
protected int getWordFrequency(final String word) {
|
||||||
// Case-sensitive search
|
// Case-sensitive search
|
||||||
final Node node = searchNode(mRoots, word, 0, word.length());
|
final Node node = searchNode(mRoots, word, 0, word.length());
|
||||||
return (node == null) ? -1 : node.mFrequency;
|
return (node == null) ? -1 : node.mFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NextWord getBigramWord(String word1, String word2) {
|
protected NextWord getBigramWord(final String word1, final String word2) {
|
||||||
// Refer to addOrSetBigram() about word1.toLowerCase()
|
// Refer to addOrSetBigram() about word1.toLowerCase()
|
||||||
final Node firstWord = searchWord(mRoots, word1.toLowerCase(), 0, null);
|
final Node firstWord = searchWord(mRoots, word1.toLowerCase(), 0, null);
|
||||||
final Node secondWord = searchWord(mRoots, word2, 0, null);
|
final Node secondWord = searchWord(mRoots, word2, 0, null);
|
||||||
|
@ -368,7 +368,8 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int computeSkippedWordFinalFreq(int freq, int snr, int inputLength) {
|
private static int computeSkippedWordFinalFreq(final int freq, final int snr,
|
||||||
|
final int inputLength) {
|
||||||
// The computation itself makes sense for >= 2, but the == 2 case returns 0
|
// The computation itself makes sense for >= 2, but the == 2 case returns 0
|
||||||
// anyway so we may as well test against 3 instead and return the constant
|
// anyway so we may as well test against 3 instead and return the constant
|
||||||
if (inputLength >= 3) {
|
if (inputLength >= 3) {
|
||||||
|
@ -431,9 +432,9 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
* @param suggestions the list in which to add suggestions
|
* @param suggestions the list in which to add suggestions
|
||||||
*/
|
*/
|
||||||
// TODO: Share this routine with the native code for BinaryDictionary
|
// TODO: Share this routine with the native code for BinaryDictionary
|
||||||
protected void getWordsRec(NodeArray roots, final WordComposer codes, final char[] word,
|
protected void getWordsRec(final NodeArray roots, final WordComposer codes, final char[] word,
|
||||||
final int depth, final boolean completion, int snr, int inputIndex, int skipPos,
|
final int depth, final boolean completion, final int snr, final int inputIndex,
|
||||||
final ArrayList<SuggestedWordInfo> suggestions) {
|
final int skipPos, final ArrayList<SuggestedWordInfo> suggestions) {
|
||||||
final int count = roots.mLength;
|
final int count = roots.mLength;
|
||||||
final int codeSize = mInputLength;
|
final int codeSize = mInputLength;
|
||||||
// Optimization: Prune out words that are too long compared to how much was typed.
|
// Optimization: Prune out words that are too long compared to how much was typed.
|
||||||
|
@ -524,11 +525,13 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int setBigramAndGetFrequency(String word1, String word2, int frequency) {
|
public int setBigramAndGetFrequency(final String word1, final String word2,
|
||||||
|
final int frequency) {
|
||||||
return setBigramAndGetFrequency(word1, word2, frequency, null /* unused */);
|
return setBigramAndGetFrequency(word1, word2, frequency, null /* unused */);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int setBigramAndGetFrequency(String word1, String word2, ForgettingCurveParams fcp) {
|
public int setBigramAndGetFrequency(final String word1, final String word2,
|
||||||
|
final ForgettingCurveParams fcp) {
|
||||||
return setBigramAndGetFrequency(word1, word2, 0 /* unused */, fcp);
|
return setBigramAndGetFrequency(word1, word2, 0 /* unused */, fcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,8 +543,8 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
* @param fcp an instance of ForgettingCurveParams to use for decay policy
|
* @param fcp an instance of ForgettingCurveParams to use for decay policy
|
||||||
* @return returns the final bigram frequency
|
* @return returns the final bigram frequency
|
||||||
*/
|
*/
|
||||||
private int setBigramAndGetFrequency(
|
private int setBigramAndGetFrequency(final String word1, final String word2,
|
||||||
String word1, String word2, int frequency, ForgettingCurveParams fcp) {
|
final int frequency, final ForgettingCurveParams fcp) {
|
||||||
// We don't want results to be different according to case of the looked up left hand side
|
// We don't want results to be different according to case of the looked up left hand side
|
||||||
// word. We do want however to return the correct case for the right hand side.
|
// word. We do want however to return the correct case for the right hand side.
|
||||||
// So we want to squash the case of the left hand side, and preserve that of the right
|
// So we want to squash the case of the left hand side, and preserve that of the right
|
||||||
|
@ -572,7 +575,8 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
* Searches for the word and add the word if it does not exist.
|
* Searches for the word and add the word if it does not exist.
|
||||||
* @return Returns the terminal node of the word we are searching for.
|
* @return Returns the terminal node of the word we are searching for.
|
||||||
*/
|
*/
|
||||||
private Node searchWord(NodeArray children, String word, int depth, Node parentNode) {
|
private Node searchWord(final NodeArray children, final String word, final int depth,
|
||||||
|
final Node parentNode) {
|
||||||
final int wordLength = word.length();
|
final int wordLength = word.length();
|
||||||
final char c = word.charAt(depth);
|
final char c = word.charAt(depth);
|
||||||
// Does children have the current character?
|
// Does children have the current character?
|
||||||
|
@ -602,11 +606,11 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
return searchWord(childNode.mChildren, word, depth + 1, childNode);
|
return searchWord(childNode.mChildren, word, depth + 1, childNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runBigramReverseLookUp(final CharSequence previousWord,
|
private void runBigramReverseLookUp(final String previousWord,
|
||||||
final ArrayList<SuggestedWordInfo> suggestions) {
|
final ArrayList<SuggestedWordInfo> suggestions) {
|
||||||
// Search for the lowercase version of the word only, because that's where bigrams
|
// Search for the lowercase version of the word only, because that's where bigrams
|
||||||
// store their sons.
|
// store their sons.
|
||||||
Node prevWord = searchNode(mRoots, previousWord.toString().toLowerCase(), 0,
|
final Node prevWord = searchNode(mRoots, previousWord.toLowerCase(), 0,
|
||||||
previousWord.length());
|
previousWord.length());
|
||||||
if (prevWord != null && prevWord.mNGrams != null) {
|
if (prevWord != null && prevWord.mNGrams != null) {
|
||||||
reverseLookUp(prevWord.mNGrams, suggestions);
|
reverseLookUp(prevWord.mNGrams, suggestions);
|
||||||
|
@ -641,7 +645,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
* @param terminalNodes list of terminal nodes we want to add
|
* @param terminalNodes list of terminal nodes we want to add
|
||||||
* @param suggestions the suggestion collection to add the word to
|
* @param suggestions the suggestion collection to add the word to
|
||||||
*/
|
*/
|
||||||
private void reverseLookUp(LinkedList<NextWord> terminalNodes,
|
private void reverseLookUp(final LinkedList<NextWord> terminalNodes,
|
||||||
final ArrayList<SuggestedWordInfo> suggestions) {
|
final ArrayList<SuggestedWordInfo> suggestions) {
|
||||||
Node node;
|
Node node;
|
||||||
int freq;
|
int freq;
|
||||||
|
@ -714,7 +718,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static char toLowerCase(char c) {
|
private static char toLowerCase(final char c) {
|
||||||
char baseChar = c;
|
char baseChar = c;
|
||||||
if (c < BASE_CHARS.length) {
|
if (c < BASE_CHARS.length) {
|
||||||
baseChar = BASE_CHARS[c];
|
baseChar = BASE_CHARS[c];
|
||||||
|
|
|
@ -44,7 +44,7 @@ public final class LastComposedWord {
|
||||||
public final String mTypedWord;
|
public final String mTypedWord;
|
||||||
public final String mCommittedWord;
|
public final String mCommittedWord;
|
||||||
public final String mSeparatorString;
|
public final String mSeparatorString;
|
||||||
public final CharSequence mPrevWord;
|
public final String mPrevWord;
|
||||||
public final InputPointers mInputPointers = new InputPointers(BinaryDictionary.MAX_WORD_LENGTH);
|
public final InputPointers mInputPointers = new InputPointers(BinaryDictionary.MAX_WORD_LENGTH);
|
||||||
|
|
||||||
private boolean mActive;
|
private boolean mActive;
|
||||||
|
@ -56,7 +56,7 @@ public final class LastComposedWord {
|
||||||
// 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 InputPointers inputPointers,
|
public LastComposedWord(final int[] primaryKeyCodes, final InputPointers inputPointers,
|
||||||
final String typedWord, final String committedWord,
|
final String typedWord, final String committedWord,
|
||||||
final String separatorString, final CharSequence prevWord) {
|
final String separatorString, final String prevWord) {
|
||||||
mPrimaryKeyCodes = primaryKeyCodes;
|
mPrimaryKeyCodes = primaryKeyCodes;
|
||||||
if (inputPointers != null) {
|
if (inputPointers != null) {
|
||||||
mInputPointers.copy(inputPointers);
|
mInputPointers.copy(inputPointers);
|
||||||
|
|
|
@ -171,7 +171,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
new DictionaryPackInstallBroadcastReceiver(this);
|
new DictionaryPackInstallBroadcastReceiver(this);
|
||||||
|
|
||||||
// Keeps track of most recently inserted text (multi-character key) for reverting
|
// Keeps track of most recently inserted text (multi-character key) for reverting
|
||||||
private CharSequence mEnteredText;
|
private String mEnteredText;
|
||||||
|
|
||||||
private boolean mIsAutoCorrectionIndicatorOn;
|
private boolean mIsAutoCorrectionIndicatorOn;
|
||||||
|
|
||||||
|
@ -1093,7 +1093,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
|
|
||||||
private void commitTyped(final String separatorString) {
|
private void commitTyped(final String separatorString) {
|
||||||
if (!mWordComposer.isComposingWord()) return;
|
if (!mWordComposer.isComposingWord()) return;
|
||||||
final CharSequence typedWord = mWordComposer.getTypedWord();
|
final String typedWord = mWordComposer.getTypedWord();
|
||||||
if (typedWord.length() > 0) {
|
if (typedWord.length() > 0) {
|
||||||
commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD,
|
commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD,
|
||||||
separatorString);
|
separatorString);
|
||||||
|
@ -1379,7 +1379,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
|
|
||||||
// Called from PointerTracker through the KeyboardActionListener interface
|
// Called from PointerTracker through the KeyboardActionListener interface
|
||||||
@Override
|
@Override
|
||||||
public void onTextInput(final CharSequence rawText) {
|
public void onTextInput(final String rawText) {
|
||||||
mConnection.beginBatchEdit();
|
mConnection.beginBatchEdit();
|
||||||
if (mWordComposer.isComposingWord()) {
|
if (mWordComposer.isComposingWord()) {
|
||||||
commitCurrentAutoCorrection(rawText.toString());
|
commitCurrentAutoCorrection(rawText.toString());
|
||||||
|
@ -1387,7 +1387,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
resetComposingState(true /* alsoResetLastComposedWord */);
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
||||||
}
|
}
|
||||||
mHandler.postUpdateSuggestionStrip();
|
mHandler.postUpdateSuggestionStrip();
|
||||||
final CharSequence text = specificTldProcessingOnTextInput(rawText);
|
final String text = specificTldProcessingOnTextInput(rawText);
|
||||||
if (SPACE_STATE_PHANTOM == mSpaceState) {
|
if (SPACE_STATE_PHANTOM == mSpaceState) {
|
||||||
sendKeyCodePoint(Keyboard.CODE_SPACE);
|
sendKeyCodePoint(Keyboard.CODE_SPACE);
|
||||||
}
|
}
|
||||||
|
@ -1558,7 +1558,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
mKeyboardSwitcher.updateShiftState();
|
mKeyboardSwitcher.updateShiftState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence specificTldProcessingOnTextInput(final CharSequence text) {
|
private String specificTldProcessingOnTextInput(final String text) {
|
||||||
if (text.length() <= 1 || text.charAt(0) != Keyboard.CODE_PERIOD
|
if (text.length() <= 1 || text.charAt(0) != Keyboard.CODE_PERIOD
|
||||||
|| !Character.isLetter(text.charAt(1))) {
|
|| !Character.isLetter(text.charAt(1))) {
|
||||||
// Not a tld: do nothing.
|
// Not a tld: do nothing.
|
||||||
|
@ -1571,7 +1571,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
final CharSequence lastOne = mConnection.getTextBeforeCursor(1, 0);
|
final CharSequence lastOne = mConnection.getTextBeforeCursor(1, 0);
|
||||||
if (lastOne != null && lastOne.length() == 1
|
if (lastOne != null && lastOne.length() == 1
|
||||||
&& lastOne.charAt(0) == Keyboard.CODE_PERIOD) {
|
&& lastOne.charAt(0) == Keyboard.CODE_PERIOD) {
|
||||||
return text.subSequence(1, text.length());
|
return text.substring(1);
|
||||||
} else {
|
} else {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
@ -1831,7 +1831,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
return didAutoCorrect;
|
return didAutoCorrect;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence getTextWithUnderline(final CharSequence text) {
|
private CharSequence getTextWithUnderline(final String text) {
|
||||||
return mIsAutoCorrectionIndicatorOn
|
return mIsAutoCorrectionIndicatorOn
|
||||||
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(this, text)
|
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(this, text)
|
||||||
: text;
|
: text;
|
||||||
|
@ -1926,7 +1926,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
// whatever is *before* the half-committed word in the buffer, hence 2; if we aren't, we
|
// whatever is *before* the half-committed word in the buffer, hence 2; if we aren't, we
|
||||||
// should just skip whitespace if any, so 1.
|
// should just skip whitespace if any, so 1.
|
||||||
// TODO: this is slow (2-way IPC) - we should probably cache this instead.
|
// TODO: this is slow (2-way IPC) - we should probably cache this instead.
|
||||||
final CharSequence prevWord =
|
final String prevWord =
|
||||||
mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators,
|
mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators,
|
||||||
mWordComposer.isComposingWord() ? 2 : 1);
|
mWordComposer.isComposingWord() ? 2 : 1);
|
||||||
final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer,
|
final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer,
|
||||||
|
@ -1935,7 +1935,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
return maybeRetrieveOlderSuggestions(typedWord, suggestedWords);
|
return maybeRetrieveOlderSuggestions(typedWord, suggestedWords);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SuggestedWords maybeRetrieveOlderSuggestions(final CharSequence typedWord,
|
private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
|
||||||
final SuggestedWords suggestedWords) {
|
final SuggestedWords suggestedWords) {
|
||||||
// TODO: consolidate this into getSuggestedWords
|
// TODO: consolidate this into getSuggestedWords
|
||||||
// We update the suggestion strip only when we have some suggestions to show, i.e. when
|
// We update the suggestion strip only when we have some suggestions to show, i.e. when
|
||||||
|
@ -1965,13 +1965,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSuggestionStrip(final SuggestedWords suggestedWords,
|
private void showSuggestionStrip(final SuggestedWords suggestedWords, final String typedWord) {
|
||||||
final CharSequence typedWord) {
|
|
||||||
if (suggestedWords.isEmpty()) {
|
if (suggestedWords.isEmpty()) {
|
||||||
clearSuggestionStrip();
|
clearSuggestionStrip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final CharSequence autoCorrection;
|
final String autoCorrection;
|
||||||
if (suggestedWords.mWillAutoCorrect) {
|
if (suggestedWords.mWillAutoCorrect) {
|
||||||
autoCorrection = suggestedWords.getWord(1);
|
autoCorrection = suggestedWords.getWord(1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1989,9 +1988,9 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
if (mHandler.hasPendingUpdateSuggestions()) {
|
if (mHandler.hasPendingUpdateSuggestions()) {
|
||||||
updateSuggestionStrip();
|
updateSuggestionStrip();
|
||||||
}
|
}
|
||||||
final CharSequence typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
|
final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
|
||||||
final String typedWord = mWordComposer.getTypedWord();
|
final String typedWord = mWordComposer.getTypedWord();
|
||||||
final CharSequence autoCorrection = (typedAutoCorrection != null)
|
final String autoCorrection = (typedAutoCorrection != null)
|
||||||
? typedAutoCorrection : typedWord;
|
? typedAutoCorrection : typedWord;
|
||||||
if (autoCorrection != null) {
|
if (autoCorrection != null) {
|
||||||
if (TextUtils.isEmpty(typedWord)) {
|
if (TextUtils.isEmpty(typedWord)) {
|
||||||
|
@ -2022,7 +2021,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
|
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
|
||||||
// interface
|
// interface
|
||||||
@Override
|
@Override
|
||||||
public void pickSuggestionManually(final int index, final CharSequence suggestion) {
|
public void pickSuggestionManually(final int index, final String suggestion) {
|
||||||
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
|
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
|
||||||
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
|
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
|
||||||
if (suggestion.length() == 1 && isShowingPunctuationList()) {
|
if (suggestion.length() == 1 && isShowingPunctuationList()) {
|
||||||
|
@ -2107,13 +2106,13 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
/**
|
/**
|
||||||
* Commits the chosen word to the text field and saves it for later retrieval.
|
* Commits the chosen word to the text field and saves it for later retrieval.
|
||||||
*/
|
*/
|
||||||
private void commitChosenWord(final CharSequence chosenWord, final int commitType,
|
private void commitChosenWord(final String chosenWord, final int commitType,
|
||||||
final String separatorString) {
|
final String separatorString) {
|
||||||
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
|
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
|
||||||
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
|
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
|
||||||
this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1);
|
this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1);
|
||||||
// Add the word to the user history dictionary
|
// Add the word to the user history dictionary
|
||||||
final CharSequence prevWord = addToUserHistoryDictionary(chosenWord);
|
final String prevWord = addToUserHistoryDictionary(chosenWord);
|
||||||
// TODO: figure out here if this is an auto-correct or if the best word is actually
|
// TODO: figure out here if this is an auto-correct or if the best word is actually
|
||||||
// what user typed. Note: currently this is done much later in
|
// what user typed. Note: currently this is done much later in
|
||||||
// LastComposedWord#didCommitTypedWord by string equality of the remembered
|
// LastComposedWord#didCommitTypedWord by string equality of the remembered
|
||||||
|
@ -2132,7 +2131,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
setSuggestionStripShown(isSuggestionsStripVisible());
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence addToUserHistoryDictionary(final CharSequence suggestion) {
|
private String addToUserHistoryDictionary(final String suggestion) {
|
||||||
if (TextUtils.isEmpty(suggestion)) return null;
|
if (TextUtils.isEmpty(suggestion)) return null;
|
||||||
if (mSuggest == null) return null;
|
if (mSuggest == null) return null;
|
||||||
|
|
||||||
|
@ -2147,19 +2146,18 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
= mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators, 2);
|
= mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators, 2);
|
||||||
final String secondWord;
|
final String secondWord;
|
||||||
if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
|
if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
|
||||||
secondWord = suggestion.toString().toLowerCase(
|
secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
|
||||||
mSubtypeSwitcher.getCurrentSubtypeLocale());
|
|
||||||
} else {
|
} else {
|
||||||
secondWord = suggestion.toString();
|
secondWord = suggestion;
|
||||||
}
|
}
|
||||||
// We demote unrecognized words (frequency < 0, below) by specifying them as "invalid".
|
// We demote unrecognized words (frequency < 0, below) by specifying them as "invalid".
|
||||||
// We don't add words with 0-frequency (assuming they would be profanity etc.).
|
// We don't add words with 0-frequency (assuming they would be profanity etc.).
|
||||||
final int maxFreq = AutoCorrection.getMaxFrequency(
|
final int maxFreq = AutoCorrection.getMaxFrequency(
|
||||||
mSuggest.getUnigramDictionaries(), suggestion);
|
mSuggest.getUnigramDictionaries(), suggestion);
|
||||||
if (maxFreq == 0) return null;
|
if (maxFreq == 0) return null;
|
||||||
userHistoryDictionary.addToUserHistory(null == prevWord ? null : prevWord.toString(),
|
final String prevWordString = (null == prevWord) ? null : prevWord.toString();
|
||||||
secondWord, maxFreq > 0);
|
userHistoryDictionary.addToUserHistory(prevWordString, secondWord, maxFreq > 0);
|
||||||
return prevWord;
|
return prevWordString;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -2184,9 +2182,9 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
}
|
}
|
||||||
|
|
||||||
private void revertCommit() {
|
private void revertCommit() {
|
||||||
final CharSequence previousWord = mLastComposedWord.mPrevWord;
|
final String previousWord = mLastComposedWord.mPrevWord;
|
||||||
final String originallyTypedWord = mLastComposedWord.mTypedWord;
|
final String originallyTypedWord = mLastComposedWord.mTypedWord;
|
||||||
final CharSequence committedWord = mLastComposedWord.mCommittedWord;
|
final String committedWord = mLastComposedWord.mCommittedWord;
|
||||||
final int cancelLength = committedWord.length();
|
final int cancelLength = committedWord.length();
|
||||||
final int separatorLength = LastComposedWord.getSeparatorLength(
|
final int separatorLength = LastComposedWord.getSeparatorLength(
|
||||||
mLastComposedWord.mSeparatorString);
|
mLastComposedWord.mSeparatorString);
|
||||||
|
@ -2196,9 +2194,9 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
if (mWordComposer.isComposingWord()) {
|
if (mWordComposer.isComposingWord()) {
|
||||||
throw new RuntimeException("revertCommit, but we are composing a word");
|
throw new RuntimeException("revertCommit, but we are composing a word");
|
||||||
}
|
}
|
||||||
final String wordBeforeCursor =
|
final CharSequence wordBeforeCursor =
|
||||||
mConnection.getTextBeforeCursor(deleteLength, 0)
|
mConnection.getTextBeforeCursor(deleteLength, 0)
|
||||||
.subSequence(0, cancelLength).toString();
|
.subSequence(0, cancelLength);
|
||||||
if (!TextUtils.equals(committedWord, wordBeforeCursor)) {
|
if (!TextUtils.equals(committedWord, wordBeforeCursor)) {
|
||||||
throw new RuntimeException("revertCommit check failed: we thought we were "
|
throw new RuntimeException("revertCommit check failed: we thought we were "
|
||||||
+ "reverting \"" + committedWord
|
+ "reverting \"" + committedWord
|
||||||
|
|
|
@ -398,7 +398,7 @@ public final class RichInputConnection {
|
||||||
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
|
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence getNthPreviousWord(final String sentenceSeperators, final int n) {
|
public String getNthPreviousWord(final String sentenceSeperators, final int n) {
|
||||||
mIC = mParent.getCurrentInputConnection();
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (null == mIC) return null;
|
if (null == mIC) return null;
|
||||||
final CharSequence prev = mIC.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
|
final CharSequence prev = mIC.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
|
||||||
|
@ -466,19 +466,22 @@ public final class RichInputConnection {
|
||||||
// (n = 2) "abc|" -> null
|
// (n = 2) "abc|" -> null
|
||||||
// (n = 2) "abc |" -> null
|
// (n = 2) "abc |" -> null
|
||||||
// (n = 2) "abc. def|" -> null
|
// (n = 2) "abc. def|" -> null
|
||||||
public static CharSequence getNthPreviousWord(final CharSequence prev,
|
public static String getNthPreviousWord(final CharSequence prev,
|
||||||
final String sentenceSeperators, final int n) {
|
final String sentenceSeperators, final int n) {
|
||||||
if (prev == null) return null;
|
if (prev == null) return null;
|
||||||
String[] w = spaceRegex.split(prev);
|
final String[] w = spaceRegex.split(prev);
|
||||||
|
|
||||||
// If we can't find n words, or we found an empty word, return null.
|
// If we can't find n words, or we found an empty word, return null.
|
||||||
if (w.length < n || w[w.length - n].length() <= 0) return null;
|
if (w.length < n) return null;
|
||||||
|
final String nthPrevWord = w[w.length - n];
|
||||||
|
final int length = nthPrevWord.length();
|
||||||
|
if (length <= 0) return null;
|
||||||
|
|
||||||
// If ends in a separator, return null
|
// If ends in a separator, return null
|
||||||
char lastChar = w[w.length - n].charAt(w[w.length - n].length() - 1);
|
final char lastChar = nthPrevWord.charAt(length - 1);
|
||||||
if (sentenceSeperators.contains(String.valueOf(lastChar))) return null;
|
if (sentenceSeperators.contains(String.valueOf(lastChar))) return null;
|
||||||
|
|
||||||
return w[w.length - n];
|
return nthPrevWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -511,19 +514,20 @@ public final class RichInputConnection {
|
||||||
* be included in the returned range
|
* be included in the returned range
|
||||||
* @return a range containing the text surrounding the cursor
|
* @return a range containing the text surrounding the cursor
|
||||||
*/
|
*/
|
||||||
public Range getWordRangeAtCursor(String sep, int additionalPrecedingWordsCount) {
|
public Range getWordRangeAtCursor(final String sep, final int additionalPrecedingWordsCount) {
|
||||||
mIC = mParent.getCurrentInputConnection();
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (mIC == null || sep == null) {
|
if (mIC == null || sep == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CharSequence before = mIC.getTextBeforeCursor(1000, 0);
|
final CharSequence before = mIC.getTextBeforeCursor(1000, 0);
|
||||||
CharSequence after = mIC.getTextAfterCursor(1000, 0);
|
final CharSequence after = mIC.getTextAfterCursor(1000, 0);
|
||||||
if (before == null || after == null) {
|
if (before == null || after == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Going backward, alternate skipping non-separators and separators until enough words
|
// Going backward, alternate skipping non-separators and separators until enough words
|
||||||
// have been read.
|
// have been read.
|
||||||
|
int count = additionalPrecedingWordsCount;
|
||||||
int start = before.length();
|
int start = before.length();
|
||||||
boolean isStoppingAtWhitespace = true; // toggles to indicate what to stop at
|
boolean isStoppingAtWhitespace = true; // toggles to indicate what to stop at
|
||||||
while (true) { // see comments below for why this is guaranteed to halt
|
while (true) { // see comments below for why this is guaranteed to halt
|
||||||
|
@ -540,7 +544,7 @@ public final class RichInputConnection {
|
||||||
// isStoppingAtWhitespace is true every other time through the loop,
|
// isStoppingAtWhitespace is true every other time through the loop,
|
||||||
// so additionalPrecedingWordsCount is guaranteed to become < 0, which
|
// so additionalPrecedingWordsCount is guaranteed to become < 0, which
|
||||||
// guarantees outer loop termination
|
// guarantees outer loop termination
|
||||||
if (isStoppingAtWhitespace && (--additionalPrecedingWordsCount < 0)) {
|
if (isStoppingAtWhitespace && (--count < 0)) {
|
||||||
break; // outer loop
|
break; // outer loop
|
||||||
}
|
}
|
||||||
isStoppingAtWhitespace = !isStoppingAtWhitespace;
|
isStoppingAtWhitespace = !isStoppingAtWhitespace;
|
||||||
|
@ -558,7 +562,7 @@ public final class RichInputConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cursor = getCursorPosition();
|
final int cursor = getCursorPosition();
|
||||||
if (start >= 0 && cursor + end <= after.length() + before.length()) {
|
if (start >= 0 && cursor + end <= after.length() + before.length()) {
|
||||||
String word = before.toString().substring(start, before.length())
|
String word = before.toString().substring(start, before.length())
|
||||||
+ after.toString().substring(0, end);
|
+ after.toString().substring(0, end);
|
||||||
|
@ -569,8 +573,8 @@ public final class RichInputConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCursorTouchingWord(final SettingsValues settingsValues) {
|
public boolean isCursorTouchingWord(final SettingsValues settingsValues) {
|
||||||
CharSequence before = getTextBeforeCursor(1, 0);
|
final CharSequence before = getTextBeforeCursor(1, 0);
|
||||||
CharSequence after = getTextAfterCursor(1, 0);
|
final CharSequence after = getTextAfterCursor(1, 0);
|
||||||
if (!TextUtils.isEmpty(before) && !settingsValues.isWordSeparator(before.charAt(0))
|
if (!TextUtils.isEmpty(before) && !settingsValues.isWordSeparator(before.charAt(0))
|
||||||
&& !settingsValues.isSymbolExcludedFromWordSeparators(before.charAt(0))) {
|
&& !settingsValues.isSymbolExcludedFromWordSeparators(before.charAt(0))) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -16,9 +16,11 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import android.text.InputType;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.Keyboard; // For character constants
|
//For character constants
|
||||||
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -28,30 +30,30 @@ public final class StringUtils {
|
||||||
// This utility class is not publicly instantiable.
|
// This utility class is not publicly instantiable.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int codePointCount(String text) {
|
public static int codePointCount(final String text) {
|
||||||
if (TextUtils.isEmpty(text)) return 0;
|
if (TextUtils.isEmpty(text)) return 0;
|
||||||
return text.codePointCount(0, text.length());
|
return text.codePointCount(0, text.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsInArray(String key, String[] array) {
|
public static boolean containsInArray(final String key, final String[] array) {
|
||||||
for (final String element : array) {
|
for (final String element : array) {
|
||||||
if (key.equals(element)) return true;
|
if (key.equals(element)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsInCsv(String key, String csv) {
|
public static boolean containsInCsv(final String key, final String csv) {
|
||||||
if (TextUtils.isEmpty(csv)) return false;
|
if (TextUtils.isEmpty(csv)) return false;
|
||||||
return containsInArray(key, csv.split(","));
|
return containsInArray(key, csv.split(","));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String appendToCsvIfNotExists(String key, String csv) {
|
public static String appendToCsvIfNotExists(final String key, final String csv) {
|
||||||
if (TextUtils.isEmpty(csv)) return key;
|
if (TextUtils.isEmpty(csv)) return key;
|
||||||
if (containsInCsv(key, csv)) return csv;
|
if (containsInCsv(key, csv)) return csv;
|
||||||
return csv + "," + key;
|
return csv + "," + key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String removeFromCsvIfExists(String key, String csv) {
|
public static String removeFromCsvIfExists(final String key, final String csv) {
|
||||||
if (TextUtils.isEmpty(csv)) return "";
|
if (TextUtils.isEmpty(csv)) return "";
|
||||||
final String[] elements = csv.split(",");
|
final String[] elements = csv.split(",");
|
||||||
if (!containsInArray(key, elements)) return csv;
|
if (!containsInArray(key, elements)) return csv;
|
||||||
|
@ -62,83 +64,21 @@ public final class StringUtils {
|
||||||
return TextUtils.join(",", result);
|
return TextUtils.join(",", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if a and b are equal ignoring the case of the character.
|
|
||||||
* @param a first character to check
|
|
||||||
* @param b second character to check
|
|
||||||
* @return {@code true} if a and b are equal, {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
public static boolean equalsIgnoreCase(char a, char b) {
|
|
||||||
// Some language, such as Turkish, need testing both cases.
|
|
||||||
return a == b
|
|
||||||
|| Character.toLowerCase(a) == Character.toLowerCase(b)
|
|
||||||
|| Character.toUpperCase(a) == Character.toUpperCase(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if a and b are equal ignoring the case of the characters, including if they are
|
|
||||||
* both null.
|
|
||||||
* @param a first CharSequence to check
|
|
||||||
* @param b second CharSequence to check
|
|
||||||
* @return {@code true} if a and b are equal, {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
public static boolean equalsIgnoreCase(CharSequence a, CharSequence b) {
|
|
||||||
if (a == b)
|
|
||||||
return true; // including both a and b are null.
|
|
||||||
if (a == null || b == null)
|
|
||||||
return false;
|
|
||||||
final int length = a.length();
|
|
||||||
if (length != b.length())
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
if (!equalsIgnoreCase(a.charAt(i), b.charAt(i)))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if a and b are equal ignoring the case of the characters, including if a is null
|
|
||||||
* and b is zero length.
|
|
||||||
* @param a CharSequence to check
|
|
||||||
* @param b character array to check
|
|
||||||
* @param offset start offset of array b
|
|
||||||
* @param length length of characters in array b
|
|
||||||
* @return {@code true} if a and b are equal, {@code false} otherwise.
|
|
||||||
* @throws IndexOutOfBoundsException
|
|
||||||
* if {@code offset < 0 || length < 0 || offset + length > data.length}.
|
|
||||||
* @throws NullPointerException if {@code b == null}.
|
|
||||||
*/
|
|
||||||
public static boolean equalsIgnoreCase(CharSequence a, char[] b, int offset, int length) {
|
|
||||||
if (offset < 0 || length < 0 || length > b.length - offset)
|
|
||||||
throw new IndexOutOfBoundsException("array.length=" + b.length + " offset=" + offset
|
|
||||||
+ " length=" + length);
|
|
||||||
if (a == null)
|
|
||||||
return length == 0; // including a is null and b is zero length.
|
|
||||||
if (a.length() != length)
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
if (!equalsIgnoreCase(a.charAt(i), b[offset + i]))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove duplicates from an array of strings.
|
* Remove duplicates from an array of strings.
|
||||||
*
|
*
|
||||||
* This method will always keep the first occurrence of all strings at their position
|
* This method will always keep the first occurrence of all strings at their position
|
||||||
* in the array, removing the subsequent ones.
|
* in the array, removing the subsequent ones.
|
||||||
*/
|
*/
|
||||||
public static void removeDupes(final ArrayList<CharSequence> suggestions) {
|
public static void removeDupes(final ArrayList<String> suggestions) {
|
||||||
if (suggestions.size() < 2) return;
|
if (suggestions.size() < 2) return;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
// Don't cache suggestions.size(), since we may be removing items
|
// Don't cache suggestions.size(), since we may be removing items
|
||||||
while (i < suggestions.size()) {
|
while (i < suggestions.size()) {
|
||||||
final CharSequence cur = suggestions.get(i);
|
final String cur = suggestions.get(i);
|
||||||
// Compare each suggestion with each previous suggestion
|
// Compare each suggestion with each previous suggestion
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
CharSequence previous = suggestions.get(j);
|
final String previous = suggestions.get(j);
|
||||||
if (TextUtils.equals(cur, previous)) {
|
if (TextUtils.equals(cur, previous)) {
|
||||||
suggestions.remove(i);
|
suggestions.remove(i);
|
||||||
i--;
|
i--;
|
||||||
|
@ -149,7 +89,7 @@ public final class StringUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toTitleCase(String s, Locale locale) {
|
public static String toTitleCase(final String s, final Locale locale) {
|
||||||
if (s.length() <= 1) {
|
if (s.length() <= 1) {
|
||||||
// TODO: is this really correct? Shouldn't this be s.toUpperCase()?
|
// TODO: is this really correct? Shouldn't this be s.toUpperCase()?
|
||||||
return s;
|
return s;
|
||||||
|
@ -165,21 +105,19 @@ public final class StringUtils {
|
||||||
return s.toUpperCase(locale).charAt(0) + s.substring(1);
|
return s.toUpperCase(locale).charAt(0) + s.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int[] EMPTY_CODEPOINTS = {};
|
||||||
|
|
||||||
public static int[] toCodePointArray(final String string) {
|
public static int[] toCodePointArray(final String string) {
|
||||||
final char[] characters = string.toCharArray();
|
final int length = string.length();
|
||||||
final int length = characters.length;
|
|
||||||
final int[] codePoints = new int[Character.codePointCount(characters, 0, length)];
|
|
||||||
if (length <= 0) {
|
if (length <= 0) {
|
||||||
return new int[0];
|
return EMPTY_CODEPOINTS;
|
||||||
}
|
}
|
||||||
int codePoint = Character.codePointAt(characters, 0);
|
final int[] codePoints = new int[string.codePointCount(0, length)];
|
||||||
int dsti = 0;
|
int destIndex = 0;
|
||||||
for (int srci = Character.charCount(codePoint);
|
for (int index = 0; index < length; index = string.offsetByCodePoints(index, 1)) {
|
||||||
srci < length; srci += Character.charCount(codePoint), ++dsti) {
|
codePoints[destIndex] = string.codePointAt(index);
|
||||||
codePoints[dsti] = codePoint;
|
destIndex++;
|
||||||
codePoint = Character.codePointAt(characters, srci);
|
|
||||||
}
|
}
|
||||||
codePoints[dsti] = codePoint;
|
|
||||||
return codePoints;
|
return codePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ public final class Suggest {
|
||||||
public static final String TAG = Suggest.class.getSimpleName();
|
public static final String TAG = Suggest.class.getSimpleName();
|
||||||
|
|
||||||
// Session id for
|
// Session id for
|
||||||
// {@link #getSuggestedWords(WordComposer,CharSequence,ProximityInfo,boolean,int)}.
|
// {@link #getSuggestedWords(WordComposer,String,ProximityInfo,boolean,int)}.
|
||||||
public static final int SESSION_TYPING = 0;
|
public static final int SESSION_TYPING = 0;
|
||||||
public static final int SESSION_GESTURE = 1;
|
public static final int SESSION_GESTURE = 1;
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public final class Suggest {
|
||||||
* Sets an optional user dictionary resource to be loaded. The user dictionary is consulted
|
* Sets an optional user dictionary resource to be loaded. The user dictionary is consulted
|
||||||
* before the main dictionary, if set. This refers to the system-managed user dictionary.
|
* before the main dictionary, if set. This refers to the system-managed user dictionary.
|
||||||
*/
|
*/
|
||||||
public void setUserDictionary(UserBinaryDictionary userDictionary) {
|
public void setUserDictionary(final UserBinaryDictionary userDictionary) {
|
||||||
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_USER, userDictionary);
|
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_USER, userDictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,12 +147,12 @@ public final class Suggest {
|
||||||
* the contacts dictionary by passing null to this method. In this case no contacts dictionary
|
* the contacts dictionary by passing null to this method. In this case no contacts dictionary
|
||||||
* won't be used.
|
* won't be used.
|
||||||
*/
|
*/
|
||||||
public void setContactsDictionary(ContactsBinaryDictionary contactsDictionary) {
|
public void setContactsDictionary(final ContactsBinaryDictionary contactsDictionary) {
|
||||||
mContactsDict = contactsDictionary;
|
mContactsDict = contactsDictionary;
|
||||||
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_CONTACTS, contactsDictionary);
|
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_CONTACTS, contactsDictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserHistoryDictionary(UserHistoryDictionary userHistoryDictionary) {
|
public void setUserHistoryDictionary(final UserHistoryDictionary userHistoryDictionary) {
|
||||||
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_USER_HISTORY, userHistoryDictionary);
|
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_USER_HISTORY, userHistoryDictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,9 +160,9 @@ public final class Suggest {
|
||||||
mAutoCorrectionThreshold = threshold;
|
mAutoCorrectionThreshold = threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuggestedWords getSuggestedWords(
|
public SuggestedWords getSuggestedWords(final WordComposer wordComposer,
|
||||||
final WordComposer wordComposer, CharSequence prevWordForBigram,
|
final String prevWordForBigram, final ProximityInfo proximityInfo,
|
||||||
final ProximityInfo proximityInfo, final boolean isCorrectionEnabled, int sessionId) {
|
final boolean isCorrectionEnabled, final int sessionId) {
|
||||||
LatinImeLogger.onStartSuggestion(prevWordForBigram);
|
LatinImeLogger.onStartSuggestion(prevWordForBigram);
|
||||||
if (wordComposer.isBatchMode()) {
|
if (wordComposer.isBatchMode()) {
|
||||||
return getSuggestedWordsForBatchInput(
|
return getSuggestedWordsForBatchInput(
|
||||||
|
@ -174,9 +174,9 @@ public final class Suggest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves suggestions for the typing input.
|
// Retrieves suggestions for the typing input.
|
||||||
private SuggestedWords getSuggestedWordsForTypingInput(
|
private SuggestedWords getSuggestedWordsForTypingInput(final WordComposer wordComposer,
|
||||||
final WordComposer wordComposer, CharSequence prevWordForBigram,
|
final String prevWordForBigram, final ProximityInfo proximityInfo,
|
||||||
final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) {
|
final boolean isCorrectionEnabled) {
|
||||||
final int trailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount();
|
final int trailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount();
|
||||||
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
|
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
|
||||||
MAX_SUGGESTIONS);
|
MAX_SUGGESTIONS);
|
||||||
|
@ -203,7 +203,7 @@ public final class Suggest {
|
||||||
wordComposerForLookup, prevWordForBigram, proximityInfo));
|
wordComposerForLookup, prevWordForBigram, proximityInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
final CharSequence whitelistedWord;
|
final String whitelistedWord;
|
||||||
if (suggestionsSet.isEmpty()) {
|
if (suggestionsSet.isEmpty()) {
|
||||||
whitelistedWord = null;
|
whitelistedWord = null;
|
||||||
} else if (SuggestedWordInfo.KIND_WHITELIST != suggestionsSet.first().mKind) {
|
} else if (SuggestedWordInfo.KIND_WHITELIST != suggestionsSet.first().mKind) {
|
||||||
|
@ -287,9 +287,9 @@ public final class Suggest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves suggestions for the batch input.
|
// Retrieves suggestions for the batch input.
|
||||||
private SuggestedWords getSuggestedWordsForBatchInput(
|
private SuggestedWords getSuggestedWordsForBatchInput(final WordComposer wordComposer,
|
||||||
final WordComposer wordComposer, CharSequence prevWordForBigram,
|
final String prevWordForBigram, final ProximityInfo proximityInfo,
|
||||||
final ProximityInfo proximityInfo, int sessionId) {
|
final int sessionId) {
|
||||||
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
|
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
|
||||||
MAX_SUGGESTIONS);
|
MAX_SUGGESTIONS);
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ public final class Suggest {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SuggestedWordInfo wordInfo : suggestionsSet) {
|
for (SuggestedWordInfo wordInfo : suggestionsSet) {
|
||||||
LatinImeLogger.onAddSuggestedWord(wordInfo.mWord.toString(), wordInfo.mSourceDict);
|
LatinImeLogger.onAddSuggestedWord(wordInfo.mWord, wordInfo.mSourceDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
||||||
|
@ -372,7 +372,7 @@ public final class Suggest {
|
||||||
if (o1.mScore < o2.mScore) return 1;
|
if (o1.mScore < o2.mScore) return 1;
|
||||||
if (o1.mCodePointCount < o2.mCodePointCount) return -1;
|
if (o1.mCodePointCount < o2.mCodePointCount) return -1;
|
||||||
if (o1.mCodePointCount > o2.mCodePointCount) return 1;
|
if (o1.mCodePointCount > o2.mCodePointCount) return 1;
|
||||||
return o1.mWord.toString().compareTo(o2.mWord.toString());
|
return o1.mWord.compareTo(o2.mWord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static final SuggestedWordInfoComparator sSuggestedWordInfoComparator =
|
private static final SuggestedWordInfoComparator sSuggestedWordInfoComparator =
|
||||||
|
@ -383,16 +383,17 @@ public final class Suggest {
|
||||||
final boolean isFirstCharCapitalized, final int trailingSingleQuotesCount) {
|
final boolean isFirstCharCapitalized, final int trailingSingleQuotesCount) {
|
||||||
final StringBuilder sb = new StringBuilder(wordInfo.mWord.length());
|
final StringBuilder sb = new StringBuilder(wordInfo.mWord.length());
|
||||||
if (isAllUpperCase) {
|
if (isAllUpperCase) {
|
||||||
sb.append(wordInfo.mWord.toString().toUpperCase(locale));
|
sb.append(wordInfo.mWord.toUpperCase(locale));
|
||||||
} else if (isFirstCharCapitalized) {
|
} else if (isFirstCharCapitalized) {
|
||||||
sb.append(StringUtils.toTitleCase(wordInfo.mWord.toString(), locale));
|
sb.append(StringUtils.toTitleCase(wordInfo.mWord, locale));
|
||||||
} else {
|
} else {
|
||||||
sb.append(wordInfo.mWord);
|
sb.append(wordInfo.mWord);
|
||||||
}
|
}
|
||||||
for (int i = trailingSingleQuotesCount - 1; i >= 0; --i) {
|
for (int i = trailingSingleQuotesCount - 1; i >= 0; --i) {
|
||||||
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
|
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
|
||||||
}
|
}
|
||||||
return new SuggestedWordInfo(sb, wordInfo.mScore, wordInfo.mKind, wordInfo.mSourceDict);
|
return new SuggestedWordInfo(sb.toString(), wordInfo.mScore, wordInfo.mKind,
|
||||||
|
wordInfo.mSourceDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
|
|
@ -90,11 +90,14 @@ public final class SuggestedWords {
|
||||||
public static ArrayList<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
|
public static ArrayList<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
|
||||||
final CompletionInfo[] infos) {
|
final CompletionInfo[] infos) {
|
||||||
final ArrayList<SuggestedWordInfo> result = CollectionUtils.newArrayList();
|
final ArrayList<SuggestedWordInfo> result = CollectionUtils.newArrayList();
|
||||||
for (CompletionInfo info : infos) {
|
for (final CompletionInfo info : infos) {
|
||||||
if (null != info && info.getText() != null) {
|
if (info == null) continue;
|
||||||
result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE,
|
final CharSequence text = info.getText();
|
||||||
SuggestedWordInfo.KIND_APP_DEFINED, Dictionary.TYPE_APPLICATION_DEFINED));
|
if (null == text) continue;
|
||||||
}
|
final SuggestedWordInfo suggestedWordInfo = new SuggestedWordInfo(text.toString(),
|
||||||
|
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_APP_DEFINED,
|
||||||
|
Dictionary.TYPE_APPLICATION_DEFINED);
|
||||||
|
result.add(suggestedWordInfo);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +105,7 @@ public final class SuggestedWords {
|
||||||
// Should get rid of the first one (what the user typed previously) from suggestions
|
// Should get rid of the first one (what the user typed previously) from suggestions
|
||||||
// and replace it with what the user currently typed.
|
// and replace it with what the user currently typed.
|
||||||
public static ArrayList<SuggestedWordInfo> getTypedWordAndPreviousSuggestions(
|
public static ArrayList<SuggestedWordInfo> getTypedWordAndPreviousSuggestions(
|
||||||
final CharSequence typedWord, final SuggestedWords previousSuggestions) {
|
final String typedWord, final SuggestedWords previousSuggestions) {
|
||||||
final ArrayList<SuggestedWordInfo> suggestionsList = CollectionUtils.newArrayList();
|
final ArrayList<SuggestedWordInfo> suggestionsList = CollectionUtils.newArrayList();
|
||||||
final HashSet<String> alreadySeen = CollectionUtils.newHashSet();
|
final HashSet<String> alreadySeen = CollectionUtils.newHashSet();
|
||||||
suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE,
|
suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE,
|
||||||
|
@ -111,7 +114,7 @@ public final class SuggestedWords {
|
||||||
final int previousSize = previousSuggestions.size();
|
final int previousSize = previousSuggestions.size();
|
||||||
for (int pos = 1; pos < previousSize; pos++) {
|
for (int pos = 1; pos < previousSize; pos++) {
|
||||||
final SuggestedWordInfo prevWordInfo = previousSuggestions.getWordInfo(pos);
|
final SuggestedWordInfo prevWordInfo = previousSuggestions.getWordInfo(pos);
|
||||||
final String prevWord = prevWordInfo.mWord.toString();
|
final String prevWord = prevWordInfo.mWord;
|
||||||
// Filter out duplicate suggestion.
|
// Filter out duplicate suggestion.
|
||||||
if (!alreadySeen.contains(prevWord)) {
|
if (!alreadySeen.contains(prevWord)) {
|
||||||
suggestionsList.add(prevWordInfo);
|
suggestionsList.add(prevWordInfo);
|
||||||
|
@ -139,9 +142,9 @@ public final class SuggestedWords {
|
||||||
public final String mSourceDict;
|
public final String mSourceDict;
|
||||||
private String mDebugString = "";
|
private String mDebugString = "";
|
||||||
|
|
||||||
public SuggestedWordInfo(final CharSequence word, final int score, final int kind,
|
public SuggestedWordInfo(final String word, final int score, final int kind,
|
||||||
final String sourceDict) {
|
final String sourceDict) {
|
||||||
mWord = word.toString();
|
mWord = word;
|
||||||
mScore = score;
|
mScore = score;
|
||||||
mKind = kind;
|
mKind = kind;
|
||||||
mSourceDict = sourceDict;
|
mSourceDict = sourceDict;
|
||||||
|
@ -149,7 +152,7 @@ public final class SuggestedWords {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setDebugString(String str) {
|
public void setDebugString(final String str) {
|
||||||
if (null == str) throw new NullPointerException("Debug info is null");
|
if (null == str) throw new NullPointerException("Debug info is null");
|
||||||
mDebugString = str;
|
mDebugString = str;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +174,7 @@ public final class SuggestedWords {
|
||||||
if (TextUtils.isEmpty(mDebugString)) {
|
if (TextUtils.isEmpty(mDebugString)) {
|
||||||
return mWord;
|
return mWord;
|
||||||
} else {
|
} else {
|
||||||
return mWord + " (" + mDebugString.toString() + ")";
|
return mWord + " (" + mDebugString + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,13 +33,13 @@ public final class SynchronouslyLoadedContactsBinaryDictionary extends ContactsB
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
public synchronized ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
final String prevWordForBigrams, final ProximityInfo proximityInfo) {
|
||||||
syncReloadDictionaryIfRequired();
|
syncReloadDictionaryIfRequired();
|
||||||
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo);
|
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean isValidWord(CharSequence word) {
|
public synchronized boolean isValidWord(final String word) {
|
||||||
syncReloadDictionaryIfRequired();
|
syncReloadDictionaryIfRequired();
|
||||||
return isValidWordInner(word);
|
return isValidWordInner(word);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,13 +36,13 @@ public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDic
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
public synchronized ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
final String prevWordForBigrams, final ProximityInfo proximityInfo) {
|
||||||
syncReloadDictionaryIfRequired();
|
syncReloadDictionaryIfRequired();
|
||||||
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo);
|
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean isValidWord(CharSequence word) {
|
public synchronized boolean isValidWord(final String word) {
|
||||||
syncReloadDictionaryIfRequired();
|
syncReloadDictionaryIfRequired();
|
||||||
return isValidWordInner(word);
|
return isValidWordInner(word);
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,7 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWords(Cursor cursor) {
|
private void addWords(final Cursor cursor) {
|
||||||
// 16 is JellyBean, but we want this to compile against ICS.
|
// 16 is JellyBean, but we want this to compile against ICS.
|
||||||
final boolean hasShortcutColumn = android.os.Build.VERSION.SDK_INT >= 16;
|
final boolean hasShortcutColumn = android.os.Build.VERSION.SDK_INT >= 16;
|
||||||
clearFusionDictionary();
|
clearFusionDictionary();
|
||||||
|
|
|
@ -122,7 +122,7 @@ public final class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer composer,
|
protected ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
final String prevWord, final ProximityInfo proximityInfo) {
|
||||||
// Inhibit suggestions (not predictions) for user history for now. Removing this method
|
// Inhibit suggestions (not predictions) for user history for now. Removing this method
|
||||||
// is enough to use it through the standard ExpandableDictionary way.
|
// is enough to use it through the standard ExpandableDictionary way.
|
||||||
return null;
|
return null;
|
||||||
|
@ -132,7 +132,7 @@ public final class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
* Return whether the passed charsequence is in the dictionary.
|
* Return whether the passed charsequence is in the dictionary.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean isValidWord(final CharSequence word) {
|
public synchronized boolean isValidWord(final String word) {
|
||||||
// TODO: figure out what is the correct thing to do here.
|
// TODO: figure out what is the correct thing to do here.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ public final class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
* context, as in beginning of a sentence for example.
|
* context, as in beginning of a sentence for example.
|
||||||
* The second word may not be null (a NullPointerException would be thrown).
|
* The second word may not be null (a NullPointerException would be thrown).
|
||||||
*/
|
*/
|
||||||
public int addToUserHistory(final String word1, String word2, boolean isValid) {
|
public int addToUserHistory(final String word1, final String word2, final boolean isValid) {
|
||||||
if (word2.length() >= BinaryDictionary.MAX_WORD_LENGTH ||
|
if (word2.length() >= BinaryDictionary.MAX_WORD_LENGTH ||
|
||||||
(word1 != null && word1.length() >= BinaryDictionary.MAX_WORD_LENGTH)) {
|
(word1 != null && word1.length() >= BinaryDictionary.MAX_WORD_LENGTH)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -175,7 +175,7 @@ public final class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cancelAddingUserHistory(String word1, String word2) {
|
public boolean cancelAddingUserHistory(final String word1, final String word2) {
|
||||||
if (mBigramListLock.tryLock()) {
|
if (mBigramListLock.tryLock()) {
|
||||||
try {
|
try {
|
||||||
if (mBigramList.removeBigram(word1, word2)) {
|
if (mBigramList.removeBigram(word1, word2)) {
|
||||||
|
@ -226,7 +226,8 @@ public final class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
final ExpandableDictionary dictionary = this;
|
final ExpandableDictionary dictionary = this;
|
||||||
final OnAddWordListener listener = new OnAddWordListener() {
|
final OnAddWordListener listener = new OnAddWordListener() {
|
||||||
@Override
|
@Override
|
||||||
public void setUnigram(String word, String shortcutTarget, int frequency) {
|
public void setUnigram(final String word, final String shortcutTarget,
|
||||||
|
final int frequency) {
|
||||||
profTotal++;
|
profTotal++;
|
||||||
if (DBG_SAVE_RESTORE) {
|
if (DBG_SAVE_RESTORE) {
|
||||||
Log.d(TAG, "load unigram: " + word + "," + frequency);
|
Log.d(TAG, "load unigram: " + word + "," + frequency);
|
||||||
|
@ -236,7 +237,7 @@ public final class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBigram(String word1, String word2, int frequency) {
|
public void setBigram(final String word1, final String word2, final int frequency) {
|
||||||
if (word1.length() < BinaryDictionary.MAX_WORD_LENGTH
|
if (word1.length() < BinaryDictionary.MAX_WORD_LENGTH
|
||||||
&& word2.length() < BinaryDictionary.MAX_WORD_LENGTH) {
|
&& word2.length() < BinaryDictionary.MAX_WORD_LENGTH) {
|
||||||
profTotal++;
|
profTotal++;
|
||||||
|
@ -292,8 +293,9 @@ public final class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
private final SharedPreferences mPrefs;
|
private final SharedPreferences mPrefs;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
public UpdateBinaryTask(UserHistoryDictionaryBigramList pendingWrites, String locale,
|
public UpdateBinaryTask(final UserHistoryDictionaryBigramList pendingWrites,
|
||||||
UserHistoryDictionary dict, SharedPreferences prefs, Context context) {
|
final String locale, final UserHistoryDictionary dict,
|
||||||
|
final SharedPreferences prefs, final Context context) {
|
||||||
mBigramList = pendingWrites;
|
mBigramList = pendingWrites;
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
mUserHistoryDictionary = dict;
|
mUserHistoryDictionary = dict;
|
||||||
|
@ -303,7 +305,7 @@ public final class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... v) {
|
protected Void doInBackground(final Void... v) {
|
||||||
if (mUserHistoryDictionary.isTest) {
|
if (mUserHistoryDictionary.isTest) {
|
||||||
// If isTest == true, wait until the lock is released.
|
// If isTest == true, wait until the lock is released.
|
||||||
mUserHistoryDictionary.mBigramListLock.lock();
|
mUserHistoryDictionary.mBigramListLock.lock();
|
||||||
|
@ -360,7 +362,7 @@ public final class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFrequency(String word1, String word2) {
|
public int getFrequency(final String word1, final String word2) {
|
||||||
final int freq;
|
final int freq;
|
||||||
if (word1 == null) { // unigram
|
if (word1 == null) { // unigram
|
||||||
freq = FREQUENCY_FOR_TYPED;
|
freq = FREQUENCY_FOR_TYPED;
|
||||||
|
|
|
@ -38,7 +38,7 @@ public final class WordComposer {
|
||||||
private int[] mPrimaryKeyCodes;
|
private int[] mPrimaryKeyCodes;
|
||||||
private final InputPointers mInputPointers = new InputPointers(N);
|
private final InputPointers mInputPointers = new InputPointers(N);
|
||||||
private final StringBuilder mTypedWord;
|
private final StringBuilder mTypedWord;
|
||||||
private CharSequence mAutoCorrection;
|
private String mAutoCorrection;
|
||||||
private boolean mIsResumed;
|
private boolean mIsResumed;
|
||||||
private boolean mIsBatchMode;
|
private boolean mIsBatchMode;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public final class WordComposer {
|
||||||
refreshSize();
|
refreshSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public WordComposer(WordComposer source) {
|
public WordComposer(final 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);
|
||||||
mInputPointers.copy(source.mInputPointers);
|
mInputPointers.copy(source.mInputPointers);
|
||||||
|
@ -121,7 +121,8 @@ public final class WordComposer {
|
||||||
return mInputPointers;
|
return mInputPointers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isFirstCharCapitalized(int index, int codePoint, boolean previous) {
|
private static boolean isFirstCharCapitalized(final int index, final int codePoint,
|
||||||
|
final boolean previous) {
|
||||||
if (index == 0) return Character.isUpperCase(codePoint);
|
if (index == 0) return Character.isUpperCase(codePoint);
|
||||||
return previous && !Character.isUpperCase(codePoint);
|
return previous && !Character.isUpperCase(codePoint);
|
||||||
}
|
}
|
||||||
|
@ -129,7 +130,7 @@ public final class WordComposer {
|
||||||
/**
|
/**
|
||||||
* Add a new keystroke, with the pressed key's code point with the touch point coordinates.
|
* Add a new keystroke, with the pressed key's code point with the touch point coordinates.
|
||||||
*/
|
*/
|
||||||
public void add(int primaryCode, int keyX, int keyY) {
|
public void add(final int primaryCode, final int keyX, final int keyY) {
|
||||||
final int newIndex = size();
|
final int newIndex = size();
|
||||||
mTypedWord.appendCodePoint(primaryCode);
|
mTypedWord.appendCodePoint(primaryCode);
|
||||||
refreshSize();
|
refreshSize();
|
||||||
|
@ -156,12 +157,12 @@ public final class WordComposer {
|
||||||
mAutoCorrection = null;
|
mAutoCorrection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBatchInputPointers(InputPointers batchPointers) {
|
public void setBatchInputPointers(final InputPointers batchPointers) {
|
||||||
mInputPointers.set(batchPointers);
|
mInputPointers.set(batchPointers);
|
||||||
mIsBatchMode = true;
|
mIsBatchMode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBatchInputWord(CharSequence word) {
|
public void setBatchInputWord(final String word) {
|
||||||
reset();
|
reset();
|
||||||
mIsBatchMode = true;
|
mIsBatchMode = true;
|
||||||
final int length = word.length();
|
final int length = word.length();
|
||||||
|
@ -321,14 +322,14 @@ public final class WordComposer {
|
||||||
/**
|
/**
|
||||||
* Sets the auto-correction for this word.
|
* Sets the auto-correction for this word.
|
||||||
*/
|
*/
|
||||||
public void setAutoCorrection(final CharSequence correction) {
|
public void setAutoCorrection(final String correction) {
|
||||||
mAutoCorrection = correction;
|
mAutoCorrection = correction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the auto-correction for this word, or null if none.
|
* @return the auto-correction for this word, or null if none.
|
||||||
*/
|
*/
|
||||||
public CharSequence getAutoCorrectionOrNull() {
|
public String getAutoCorrectionOrNull() {
|
||||||
return mAutoCorrection;
|
return mAutoCorrection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +342,7 @@ public final class WordComposer {
|
||||||
|
|
||||||
// `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above.
|
// `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above.
|
||||||
public LastComposedWord commitWord(final int type, final String committedWord,
|
public LastComposedWord commitWord(final int type, final String committedWord,
|
||||||
final String separatorString, final CharSequence prevWord) {
|
final String separatorString, final String prevWord) {
|
||||||
// Note: currently, we come here whenever we commit a word. If it's a MANUAL_PICK
|
// Note: currently, we come here whenever we commit a word. If it's a MANUAL_PICK
|
||||||
// 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.
|
||||||
|
|
|
@ -212,7 +212,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ArrayList<CharSequence> mSuggestions;
|
private final ArrayList<String> mSuggestions;
|
||||||
private final int[] mScores;
|
private final int[] mScores;
|
||||||
private final String mOriginalText;
|
private final String mOriginalText;
|
||||||
private final float mSuggestionThreshold;
|
private final float mSuggestionThreshold;
|
||||||
|
@ -335,7 +335,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
gatheredSuggestions = mSuggestions.toArray(EMPTY_STRING_ARRAY);
|
gatheredSuggestions = mSuggestions.toArray(EMPTY_STRING_ARRAY);
|
||||||
|
|
||||||
final int bestScore = mScores[mLength - 1];
|
final int bestScore = mScores[mLength - 1];
|
||||||
final CharSequence bestSuggestion = mSuggestions.get(0);
|
final String bestSuggestion = mSuggestions.get(0);
|
||||||
final float normalizedScore =
|
final float normalizedScore =
|
||||||
BinaryDictionary.calcNormalizedScore(
|
BinaryDictionary.calcNormalizedScore(
|
||||||
mOriginalText, bestSuggestion.toString(), bestScore);
|
mOriginalText, bestSuggestion.toString(), bestScore);
|
||||||
|
|
|
@ -268,7 +268,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
|
||||||
dictInfo.mDictionary.getSuggestions(composer, prevWord,
|
dictInfo.mDictionary.getSuggestions(composer, prevWord,
|
||||||
dictInfo.mProximityInfo);
|
dictInfo.mProximityInfo);
|
||||||
for (final SuggestedWordInfo suggestion : suggestions) {
|
for (final SuggestedWordInfo suggestion : suggestions) {
|
||||||
final String suggestionStr = suggestion.mWord.toString();
|
final String suggestionStr = suggestion.mWord;
|
||||||
suggestionsGatherer.addWord(suggestionStr.toCharArray(), null, 0,
|
suggestionsGatherer.addWord(suggestionStr.toCharArray(), null, 0,
|
||||||
suggestionStr.length(), suggestion.mScore);
|
suggestionStr.length(), suggestion.mScore);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,11 @@ public final class DictionaryPool extends LinkedBlockingQueue<DictAndProximity>
|
||||||
new Dictionary(Dictionary.TYPE_MAIN) {
|
new Dictionary(Dictionary.TYPE_MAIN) {
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
final String prevWord, final ProximityInfo proximityInfo) {
|
||||||
return noSuggestions;
|
return noSuggestions;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(CharSequence word) {
|
public boolean isValidWord(final String word) {
|
||||||
// This is never called. However if for some strange reason it ever gets
|
// This is never called. However if for some strange reason it ever gets
|
||||||
// called, returning true is less destructive (it will not underline the
|
// called, returning true is less destructive (it will not underline the
|
||||||
// word in red).
|
// word in red).
|
||||||
|
|
|
@ -65,7 +65,7 @@ public final class MoreSuggestions extends Keyboard {
|
||||||
int pos = fromPos, rowStartPos = fromPos;
|
int pos = fromPos, rowStartPos = fromPos;
|
||||||
final int size = Math.min(suggestions.size(), SuggestionStripView.MAX_SUGGESTIONS);
|
final int size = Math.min(suggestions.size(), SuggestionStripView.MAX_SUGGESTIONS);
|
||||||
while (pos < size) {
|
while (pos < size) {
|
||||||
final String word = suggestions.getWord(pos).toString();
|
final String word = suggestions.getWord(pos);
|
||||||
// TODO: Should take care of text x-scaling.
|
// TODO: Should take care of text x-scaling.
|
||||||
mWidths[pos] = (int)view.getLabelWidth(word, paint) + padding;
|
mWidths[pos] = (int)view.getLabelWidth(word, paint) + padding;
|
||||||
final int numColumn = pos - rowStartPos + 1;
|
final int numColumn = pos - rowStartPos + 1;
|
||||||
|
|
|
@ -77,7 +77,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
OnLongClickListener {
|
OnLongClickListener {
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
public boolean addWordToUserDictionary(String word);
|
public boolean addWordToUserDictionary(String word);
|
||||||
public void pickSuggestionManually(int index, CharSequence word);
|
public void pickSuggestionManually(int index, String word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The maximum number of suggestions available. See {@link Suggest#mPrefMaxSuggestions}.
|
// The maximum number of suggestions available. See {@link Suggest#mPrefMaxSuggestions}.
|
||||||
|
@ -286,7 +286,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
|
|
||||||
private CharSequence getStyledSuggestionWord(final SuggestedWords suggestedWords,
|
private CharSequence getStyledSuggestionWord(final SuggestedWords suggestedWords,
|
||||||
final int pos) {
|
final int pos) {
|
||||||
final CharSequence word = suggestedWords.getWord(pos);
|
final String word = suggestedWords.getWord(pos);
|
||||||
final boolean isAutoCorrect = pos == 1 && suggestedWords.willAutoCorrect();
|
final boolean isAutoCorrect = pos == 1 && suggestedWords.willAutoCorrect();
|
||||||
final boolean isTypedWordValid = pos == 0 && suggestedWords.mTypedWordValid;
|
final boolean isTypedWordValid = pos == 0 && suggestedWords.mTypedWordValid;
|
||||||
if (!isAutoCorrect && !isTypedWordValid)
|
if (!isAutoCorrect && !isTypedWordValid)
|
||||||
|
@ -338,7 +338,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
// is in slot 1.
|
// is in slot 1.
|
||||||
if (index == mCenterSuggestionIndex
|
if (index == mCenterSuggestionIndex
|
||||||
&& AutoCorrection.shouldBlockAutoCorrectionBySafetyNet(
|
&& AutoCorrection.shouldBlockAutoCorrectionBySafetyNet(
|
||||||
suggestedWords.getWord(1).toString(), suggestedWords.getWord(0))) {
|
suggestedWords.getWord(1), suggestedWords.getWord(0))) {
|
||||||
return 0xFFFF0000;
|
return 0xFFFF0000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
x += word.getMeasuredWidth();
|
x += word.getMeasuredWidth();
|
||||||
|
|
||||||
if (DBG && pos < suggestedWords.size()) {
|
if (DBG && pos < suggestedWords.size()) {
|
||||||
final CharSequence debugInfo = Utils.getDebugInfo(suggestedWords, pos);
|
final String debugInfo = Utils.getDebugInfo(suggestedWords, pos);
|
||||||
if (debugInfo != null) {
|
if (debugInfo != null) {
|
||||||
final TextView info = mInfos.get(pos);
|
final TextView info = mInfos.get(pos);
|
||||||
info.setText(debugInfo);
|
info.setText(debugInfo);
|
||||||
|
@ -466,7 +466,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
final TextView word = mWords.get(index);
|
final TextView word = mWords.get(index);
|
||||||
word.setEnabled(true);
|
word.setEnabled(true);
|
||||||
word.setTextColor(mColorAutoCorrect);
|
word.setTextColor(mColorAutoCorrect);
|
||||||
final CharSequence text = suggestedWords.getWord(index);
|
final String text = suggestedWords.getWord(index);
|
||||||
word.setText(text);
|
word.setText(text);
|
||||||
word.setTextScaleX(1.0f);
|
word.setTextScaleX(1.0f);
|
||||||
word.setCompoundDrawables(null, null, null, null);
|
word.setCompoundDrawables(null, null, null, null);
|
||||||
|
@ -476,7 +476,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
mMoreSuggestionsAvailable = false;
|
mMoreSuggestionsAvailable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void layoutAddToDictionaryHint(final CharSequence word, final ViewGroup stripView,
|
public void layoutAddToDictionaryHint(final String word, final ViewGroup stripView,
|
||||||
final int stripWidth, final CharSequence hintText, final OnClickListener listener) {
|
final int stripWidth, final CharSequence hintText, final OnClickListener listener) {
|
||||||
final int width = stripWidth - mDividerWidth - mPadding * 2;
|
final int width = stripWidth - mDividerWidth - mPadding * 2;
|
||||||
|
|
||||||
|
@ -690,7 +690,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
&& mParams.isAddToDictionaryShowing(mSuggestionsStrip.getChildAt(0));
|
&& mParams.isAddToDictionaryShowing(mSuggestionsStrip.getChildAt(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showAddToDictionaryHint(final CharSequence word, final CharSequence hintText) {
|
public void showAddToDictionaryHint(final String word, final CharSequence hintText) {
|
||||||
clear();
|
clear();
|
||||||
mParams.layoutAddToDictionaryHint(word, mSuggestionsStrip, getWidth(), hintText, this);
|
mParams.layoutAddToDictionaryHint(word, mSuggestionsStrip, getWidth(), hintText, this);
|
||||||
}
|
}
|
||||||
|
@ -723,7 +723,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
@Override
|
@Override
|
||||||
public boolean onCustomRequest(final int requestCode) {
|
public boolean onCustomRequest(final int requestCode) {
|
||||||
final int index = requestCode;
|
final int index = requestCode;
|
||||||
final CharSequence word = mSuggestedWords.getWord(index);
|
final String word = mSuggestedWords.getWord(index);
|
||||||
mListener.pickSuggestionManually(index, word);
|
mListener.pickSuggestionManually(index, word);
|
||||||
dismissMoreSuggestions();
|
dismissMoreSuggestions();
|
||||||
return true;
|
return true;
|
||||||
|
@ -871,7 +871,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
if (index >= mSuggestedWords.size())
|
if (index >= mSuggestedWords.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final CharSequence word = mSuggestedWords.getWord(index);
|
final String word = mSuggestedWords.getWord(index);
|
||||||
mListener.pickSuggestionManually(index, word);
|
mListener.pickSuggestionManually(index, word);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -281,7 +281,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
||||||
waitForDictionaryToBeLoaded();
|
waitForDictionaryToBeLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void pickSuggestionManually(final int index, final CharSequence suggestion) {
|
protected void pickSuggestionManually(final int index, final String suggestion) {
|
||||||
mLatinIME.pickSuggestionManually(index, suggestion);
|
mLatinIME.pickSuggestionManually(index, suggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue