diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
8 files changed, 149 insertions, 133 deletions
diff --git a/java/src/com/android/inputmethod/latin/ComposingStateManager.java b/java/src/com/android/inputmethod/latin/ComposingStateManager.java index 27f509a29..8811f2023 100644 --- a/java/src/com/android/inputmethod/latin/ComposingStateManager.java +++ b/java/src/com/android/inputmethod/latin/ComposingStateManager.java @@ -53,13 +53,6 @@ public class ComposingStateManager { } } - public synchronized boolean isComposing() { - // TODO: use the composing flag in WordComposer instead of maintaining it - // here separately. Even better, do away with this class and manage the auto - // correction indicator in the same place as the suggestions. - return mIsComposing; - } - public synchronized boolean isAutoCorrectionIndicatorOn() { return mAutoCorrectionIndicatorOn; } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 953d87beb..64b9f3364 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -979,7 +979,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar .setTypedWordValid(false) .setHasMinimalSuggestion(false); // When in fullscreen mode, show completions generated by the application - setSuggestions(builder.build()); + final SuggestedWords words = builder.build(); + final boolean isAutoCorrection = false; + setSuggestions(words, isAutoCorrection); + setAutoCorrectionIndicator(isAutoCorrection); // TODO: is this the right thing to do? What should we auto-correct to in // this case? This says to keep whatever the user typed. mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); @@ -1111,12 +1114,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // and the composingStateManager about it. private void resetEntireInputState() { resetComposingState(true /* alsoResetLastComposedWord */); + mComposingStateManager.onFinishComposingText(); updateSuggestions(); final InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.finishComposingText(); } - mComposingStateManager.onFinishComposingText(); mVoiceProxy.setVoiceInputHighlighted(false); } @@ -1533,8 +1536,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // it entirely and resume suggestions on the previous word, we'd like to still // have touch coordinates for it. resetComposingState(false /* alsoResetLastComposedWord */); - clearSuggestions(); mComposingStateManager.onFinishComposingText(); + clearSuggestions(); } } if (isComposingWord) { @@ -1712,35 +1715,32 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } public void clearSuggestions() { - setSuggestions(SuggestedWords.EMPTY); + setSuggestions(SuggestedWords.EMPTY, false); + setAutoCorrectionIndicator(false); } - public void setSuggestions(SuggestedWords words) { + public void setSuggestions(final SuggestedWords words, final boolean isAutoCorrection) { if (mSuggestionsView != null) { mSuggestionsView.setSuggestions(words); - mKeyboardSwitcher.onAutoCorrectionStateChanged( - words.hasWordAboveAutoCorrectionScoreThreshold()); + mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection); } + } + private void setAutoCorrectionIndicator(final boolean newAutoCorrectionIndicator) { // Put a blue underline to a word in TextView which will be auto-corrected. final InputConnection ic = getCurrentInputConnection(); if (ic != null) { final boolean oldAutoCorrectionIndicator = mComposingStateManager.isAutoCorrectionIndicatorOn(); - final boolean newAutoCorrectionIndicator = Utils.willAutoCorrect(words); if (oldAutoCorrectionIndicator != newAutoCorrectionIndicator) { mComposingStateManager.setAutoCorrectionIndicatorOn(newAutoCorrectionIndicator); if (DEBUG) { Log.d(TAG, "Flip the indicator. " + oldAutoCorrectionIndicator + " -> " + newAutoCorrectionIndicator); - if (mComposingStateManager.isComposing() && newAutoCorrectionIndicator - != mComposingStateManager.isAutoCorrectionIndicatorOn()) { - throw new RuntimeException("Couldn't flip the indicator!"); - } } - final CharSequence textWithUnderline = - getTextWithUnderline(mWordComposer.getTypedWord()); - if (!TextUtils.isEmpty(textWithUnderline)) { + if (mWordComposer.isComposingWord()) { + final CharSequence textWithUnderline = + getTextWithUnderline(mWordComposer.getTypedWord()); ic.setComposingText(textWithUnderline, 1); } } @@ -1827,28 +1827,28 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions); } } + if (Utils.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) { + builder.setShouldBlockAutoCorrectionBySafetyNet(); + } showSuggestions(builder.build(), typedWord); } - public void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) { - final boolean shouldBlockAutoCorrectionBySafetyNet = - Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest); - if (shouldBlockAutoCorrectionBySafetyNet) { - suggestedWords.setShouldBlockAutoCorrection(); - } - setSuggestions(suggestedWords); + public void showSuggestions(final SuggestedWords suggestedWords, final CharSequence typedWord) { + final CharSequence autoCorrection; if (suggestedWords.size() > 0) { - if (shouldBlockAutoCorrectionBySafetyNet) { - mWordComposer.setAutoCorrection(typedWord); - } else if (suggestedWords.hasAutoCorrectionWord()) { - mWordComposer.setAutoCorrection(suggestedWords.getWord(1)); + if (!suggestedWords.mShouldBlockAutoCorrectionBySafetyNet + && suggestedWords.hasAutoCorrectionWord()) { + autoCorrection = suggestedWords.getWord(1); } else { - mWordComposer.setAutoCorrection(typedWord); + autoCorrection = typedWord; } } else { - // TODO: replace with mWordComposer.deleteAutoCorrection()? - mWordComposer.setAutoCorrection(null); + autoCorrection = null; } + mWordComposer.setAutoCorrection(autoCorrection); + final boolean isAutoCorrection = suggestedWords.willAutoCorrect(); + setSuggestions(suggestedWords, isAutoCorrection); + setAutoCorrectionIndicator(isAutoCorrection); setSuggestionStripShown(isSuggestionsStripVisible()); } @@ -1885,7 +1885,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void pickSuggestionManually(final int index, final CharSequence suggestion) { mComposingStateManager.onFinishComposingText(); - final SuggestedWords suggestions = mSuggestionsView.getSuggestions(); + final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion, mSettingsValues.mWordSeparators); @@ -1896,12 +1896,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSuggestionsView.clear(); } mKeyboardSwitcher.updateShiftState(); + resetComposingState(true /* alsoResetLastComposedWord */); final InputConnection ic = getCurrentInputConnection(); if (ic != null) { - ic.beginBatchEdit(); final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index]; ic.commitCompletion(completionInfo); - ic.endBatchEdit(); } return; } @@ -1910,8 +1909,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (suggestion.length() == 1 && isShowingPunctuationList()) { // Word separators are suggested before the user inputs something. // So, LatinImeLogger logs "" as a user's input. - LatinImeLogger.logOnManualSuggestion( - "", suggestion.toString(), index, suggestions.mWords); + LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestedWords); // Rely on onCodeInput to do the complicated swapping/stripping logic consistently. final int primaryCode = suggestion.charAt(0); onCodeInput(primaryCode, new int[] { primaryCode }, @@ -1922,7 +1920,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // We need to log before we commit, because the word composer will store away the user // typed word. LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(), - suggestion.toString(), index, suggestions.mWords); + suggestion.toString(), index, suggestedWords); mExpectingUpdateSelection = true; commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, LastComposedWord.NOT_A_SEPARATOR); @@ -2021,7 +2019,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } public void setPunctuationSuggestions() { - setSuggestions(mSettingsValues.mSuggestPuncList); + setSuggestions(mSettingsValues.mSuggestPuncList, false); + setAutoCorrectionIndicator(false); setSuggestionStripShown(isSuggestionsStripVisible()); } @@ -2414,7 +2413,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar switch (position) { case 0: Intent intent = CompatUtils.getInputLanguageSelectionIntent( - Utils.getInputMethodId(mImm, getPackageName()), + Utils.getInputMethodId(getPackageName()), Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index e3dadf250..5390ee39e 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -44,7 +44,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang } public static void logOnManualSuggestion( - String before, String after, int position, List<CharSequence> suggestions) { + String before, String after, int position, SuggestedWords suggestedWords) { } public static void logOnAutoCorrection(String before, String after, int separatorCode) { diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index dfcb6450e..3029057be 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -329,10 +329,9 @@ public class Settings extends InputMethodSettingsActivity @Override public boolean onPreferenceClick(Preference pref) { if (pref == mInputLanguageSelection) { - startActivity(CompatUtils.getInputLanguageSelectionIntent( - Utils.getInputMethodId( - InputMethodManagerCompatWrapper.getInstance(), - getActivityInternal().getApplicationInfo().packageName), 0)); + final String imeId = Utils.getInputMethodId( + getActivityInternal().getApplicationInfo().packageName); + startActivity(CompatUtils.getInputLanguageSelectionIntent(imeId, 0)); return true; } return false; diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index ed6359cfa..aad975e46 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -20,22 +20,25 @@ import android.text.TextUtils; import android.view.inputmethod.CompletionInfo; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; public class SuggestedWords { - public static final SuggestedWords EMPTY = new SuggestedWords(null, false, false, false, null); + public static final SuggestedWords EMPTY = new SuggestedWords(null, false, false, false, false, + null); - public final List<CharSequence> mWords; + private final List<CharSequence> mWords; public final boolean mTypedWordValid; public final boolean mHasAutoCorrectionCandidate; public final boolean mIsPunctuationSuggestions; + public final boolean mShouldBlockAutoCorrectionBySafetyNet; private final List<SuggestedWordInfo> mSuggestedWordInfoList; - private boolean mShouldBlockAutoCorrection; - private SuggestedWords(List<CharSequence> words, boolean typedWordValid, + SuggestedWords(List<CharSequence> words, boolean typedWordValid, boolean hasAutoCorrectionCandidate, boolean isPunctuationSuggestions, + boolean shouldBlockAutoCorrectionBySafetyNet, List<SuggestedWordInfo> suggestedWordInfoList) { if (words != null) { mWords = words; @@ -45,8 +48,8 @@ public class SuggestedWords { mTypedWordValid = typedWordValid; mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate; mIsPunctuationSuggestions = isPunctuationSuggestions; + mShouldBlockAutoCorrectionBySafetyNet = shouldBlockAutoCorrectionBySafetyNet; mSuggestedWordInfoList = suggestedWordInfoList; - mShouldBlockAutoCorrection = false; } public int size() { @@ -65,20 +68,20 @@ public class SuggestedWords { return mHasAutoCorrectionCandidate && size() > 1 && !mTypedWordValid; } - public boolean hasWordAboveAutoCorrectionScoreThreshold() { - return mHasAutoCorrectionCandidate && ((size() > 1 && !mTypedWordValid) || mTypedWordValid); + public boolean willAutoCorrect() { + return !mTypedWordValid && mHasAutoCorrectionCandidate + && !mShouldBlockAutoCorrectionBySafetyNet; } - public boolean isPunctuationSuggestions() { - return mIsPunctuationSuggestions; - } - - public void setShouldBlockAutoCorrection() { - mShouldBlockAutoCorrection = true; - } - - public boolean shouldBlockAutoCorrection() { - return mShouldBlockAutoCorrection; + @Override + public String toString() { + // Pretty-print method to help debug + return "SuggestedWords:" + + " mTypedWordValid=" + mTypedWordValid + + " mHasAutoCorrectionCandidate=" + mHasAutoCorrectionCandidate + + " mIsPunctuationSuggestions=" + mIsPunctuationSuggestions + + " mShouldBlockAutoCorrectionBySafetyNet=" + mShouldBlockAutoCorrectionBySafetyNet + + " mWords=" + Arrays.toString(mWords.toArray()); } public static class Builder { @@ -86,6 +89,7 @@ public class SuggestedWords { private boolean mTypedWordValid; private boolean mHasMinimalSuggestion; private boolean mIsPunctuationSuggestions; + private boolean mShouldBlockAutoCorrectionBySafetyNet; private List<SuggestedWordInfo> mSuggestedWordInfoList = new ArrayList<SuggestedWordInfo>(); @@ -150,6 +154,11 @@ public class SuggestedWords { return this; } + public Builder setShouldBlockAutoCorrectionBySafetyNet() { + mShouldBlockAutoCorrectionBySafetyNet = true; + return this; + } + // Should get rid of the first one (what the user typed previously) from suggestions // and replace it with what the user currently typed. public Builder addTypedWordAndPreviousSuggestions(CharSequence typedWord, @@ -175,7 +184,8 @@ public class SuggestedWords { public SuggestedWords build() { return new SuggestedWords(mWords, mTypedWordValid, mHasMinimalSuggestion, - mIsPunctuationSuggestions, mSuggestedWordInfoList); + mIsPunctuationSuggestions, mShouldBlockAutoCorrectionBySafetyNet, + mSuggestedWordInfoList); } public int size() { @@ -186,18 +196,20 @@ public class SuggestedWords { return mWords.get(pos); } + public boolean isTypedWordValid() { + return mTypedWordValid; + } + @Override public String toString() { // Pretty-print method to help debug - final StringBuilder sb = new StringBuilder("StringBuilder: mTypedWordValid = " - + mTypedWordValid + " ; mHasMinimalSuggestion = " + mHasMinimalSuggestion - + " ; mIsPunctuationSuggestions = " + mIsPunctuationSuggestions - + " --- "); - for (CharSequence s : mWords) { - sb.append(s); - sb.append(" ; "); - } - return sb.toString(); + return "SuggestedWords.Builder:" + + " mTypedWordValid=" + mTypedWordValid + + " mHasMinimalSuggestion=" + mHasMinimalSuggestion + + " mIsPunctuationSuggestions=" + mIsPunctuationSuggestions + + " mShouldBlockAutoCorrectionBySafetyNet=" + + mShouldBlockAutoCorrectionBySafetyNet + + " mWords=" + Arrays.toString(mWords.toArray()); } } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 6d63e95f6..33d4b877e 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -171,12 +171,16 @@ public class Utils { return keyboardCount > 1; } - public static String getInputMethodId(InputMethodManagerCompatWrapper imm, String packageName) { - return getInputMethodInfo(imm, packageName).getId(); + public static String getInputMethodId(String packageName) { + return getInputMethodInfo(packageName).getId(); } - public static InputMethodInfoCompatWrapper getInputMethodInfo( - InputMethodManagerCompatWrapper imm, String packageName) { + public static InputMethodInfoCompatWrapper getInputMethodInfo(String packageName) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) { + throw new RuntimeException("Input method manager not found"); + } + for (final InputMethodInfoCompatWrapper imi : imm.getEnabledInputMethodList()) { if (imi.getPackageName().equals(packageName)) return imi; @@ -186,19 +190,25 @@ public class Utils { // TODO: Resolve the inconsistencies between the native auto correction algorithms and // this safety net - public static boolean shouldBlockAutoCorrectionBySafetyNet(SuggestedWords suggestions, - Suggest suggest) { + public static boolean shouldBlockAutoCorrectionBySafetyNet( + SuggestedWords.Builder suggestedWordsBuilder, Suggest suggest) { // Safety net for auto correction. // Actually if we hit this safety net, it's actually a bug. - if (suggestions.size() <= 1 || suggestions.mTypedWordValid) return false; + if (suggestedWordsBuilder.size() <= 1 || suggestedWordsBuilder.isTypedWordValid()) { + return false; + } // If user selected aggressive auto correction mode, there is no need to use the safety // net. - if (suggest.isAggressiveAutoCorrectionMode()) return false; - final CharSequence typedWord = suggestions.getWord(0); + if (suggest.isAggressiveAutoCorrectionMode()) { + return false; + } + final CharSequence typedWord = suggestedWordsBuilder.getWord(0); // If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH, // we should not use net because relatively edit distance can be big. - if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false; - final CharSequence suggestionWord = suggestions.getWord(1); + if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) { + return false; + } + final CharSequence suggestionWord = suggestedWordsBuilder.getWord(1); final int typedWordLength = typedWord.length(); final int maxEditDistanceOfNativeDictionary = (typedWordLength < 5 ? 2 : typedWordLength / 2) + 1; @@ -563,8 +573,16 @@ public class Utils { switch (inputType & InputType.TYPE_MASK_CLASS) { case InputType.TYPE_CLASS_NUMBER: - case InputType.TYPE_CLASS_DATETIME: return KeyboardId.MODE_NUMBER; + case InputType.TYPE_CLASS_DATETIME: + switch (variation) { + case InputType.TYPE_DATETIME_VARIATION_DATE: + return KeyboardId.MODE_DATE; + case InputType.TYPE_DATETIME_VARIATION_TIME: + return KeyboardId.MODE_TIME; + default: // InputType.TYPE_DATETIME_VARIATION_NORMAL + return KeyboardId.MODE_DATETIME; + } case InputType.TYPE_CLASS_PHONE: return KeyboardId.MODE_PHONE; case InputType.TYPE_CLASS_TEXT: @@ -766,11 +784,6 @@ public class Utils { return s.toUpperCase(locale).charAt(0) + s.substring(1); } - public static boolean willAutoCorrect(SuggestedWords suggestions) { - return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate - && !suggestions.shouldBlockAutoCorrection(); - } - public static class Stats { public static void onNonSeparator(final char code, final int x, final int y) { diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java index 0bd6abe09..cb1b49c67 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java @@ -34,7 +34,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; public class MoreSuggestions extends Keyboard { public static final int SUGGESTION_CODE_BASE = 1024; - private MoreSuggestions(Builder.MoreSuggestionsParam params) { + MoreSuggestions(Builder.MoreSuggestionsParam params) { super(params); } @@ -63,7 +63,7 @@ public class MoreSuggestions extends Keyboard { paint.setAntiAlias(true); final Resources res = view.getContext().getResources(); mDivider = res.getDrawable(R.drawable.more_suggestions_divider); - // TODO: Drawable itself should has an alpha value. + // TODO: Drawable itself should have an alpha value. mDivider.setAlpha(128); mDividerWidth = mDivider.getIntrinsicWidth(); final int padding = (int) res.getDimension( diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index 40d782640..d3362940f 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -62,7 +62,6 @@ import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; -import com.android.inputmethod.latin.Utils; import java.util.ArrayList; import java.util.List; @@ -95,7 +94,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, private final TextView mPreviewText; private Listener mListener; - private SuggestedWords mSuggestions = SuggestedWords.EMPTY; + private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; private final SuggestionsViewParams mParams; private static final float MIN_TEXT_XSCALE = 0.70f; @@ -259,10 +258,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, return a.getFraction(index, 1000, 1000, 1) / 1000.0f; } - private CharSequence getStyledSuggestionWord(SuggestedWords suggestions, int pos) { - final CharSequence word = suggestions.getWord(pos); - final boolean isAutoCorrect = pos == 1 && Utils.willAutoCorrect(suggestions); - final boolean isTypedWordValid = pos == 0 && suggestions.mTypedWordValid; + private CharSequence getStyledSuggestionWord(SuggestedWords suggestedWords, int pos) { + final CharSequence word = suggestedWords.getWord(pos); + final boolean isAutoCorrect = pos == 1 && suggestedWords.willAutoCorrect(); + final boolean isTypedWordValid = pos == 0 && suggestedWords.mTypedWordValid; if (!isAutoCorrect && !isTypedWordValid) return word; @@ -279,10 +278,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, return spannedWord; } - private int getWordPosition(int index, SuggestedWords suggestions) { + private int getWordPosition(int index, SuggestedWords suggestedWords) { // TODO: This works for 3 suggestions. Revisit this algorithm when there are 5 or more // suggestions. - final int centerPos = Utils.willAutoCorrect(suggestions) ? 1 : 0; + final int centerPos = suggestedWords.willAutoCorrect() ? 1 : 0; if (index == mCenterSuggestionIndex) { return centerPos; } else if (index == centerPos) { @@ -292,14 +291,14 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, } } - private int getSuggestionTextColor(int index, SuggestedWords suggestions, int pos) { + private int getSuggestionTextColor(int index, SuggestedWords suggestedWords, int pos) { // TODO: Need to revisit this logic with bigram suggestions final boolean isSuggested = (pos != 0); final int color; - if (index == mCenterSuggestionIndex && Utils.willAutoCorrect(suggestions)) { + if (index == mCenterSuggestionIndex && suggestedWords.willAutoCorrect()) { color = mColorAutoCorrect; - } else if (index == mCenterSuggestionIndex && suggestions.mTypedWordValid) { + } else if (index == mCenterSuggestionIndex && suggestedWords.mTypedWordValid) { color = mColorValidTypedWord; } else if (isSuggested) { color = mColorSuggested; @@ -307,14 +306,14 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, color = mColorTypedWord; } if (LatinImeLogger.sDBG) { - if (index == mCenterSuggestionIndex && suggestions.mHasAutoCorrectionCandidate - && suggestions.shouldBlockAutoCorrection()) { + if (index == mCenterSuggestionIndex && suggestedWords.mHasAutoCorrectionCandidate + && suggestedWords.mShouldBlockAutoCorrectionBySafetyNet) { return 0xFFFF0000; } } - final SuggestedWordInfo info = (pos < suggestions.size()) - ? suggestions.getInfo(pos) : null; + final SuggestedWordInfo info = (pos < suggestedWords.size()) + ? suggestedWords.getInfo(pos) : null; if (info != null && info.isObsoleteSuggestedWord()) { return applyAlpha(color, mAlphaObsoleted); } else { @@ -334,19 +333,19 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, params.gravity = Gravity.CENTER; } - public void layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup placer, + public void layout(SuggestedWords suggestedWords, ViewGroup stripView, ViewGroup placer, int stripWidth) { - if (suggestions.isPunctuationSuggestions()) { - layoutPunctuationSuggestions(suggestions, stripView); + if (suggestedWords.mIsPunctuationSuggestions) { + layoutPunctuationSuggestions(suggestedWords, stripView); return; } final int countInStrip = mSuggestionsCountInStrip; - setupTexts(suggestions, countInStrip); - mMoreSuggestionsAvailable = (suggestions.size() > countInStrip); + setupTexts(suggestedWords, countInStrip); + mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip); int x = 0; for (int index = 0; index < countInStrip; index++) { - final int pos = getWordPosition(index, suggestions); + final int pos = getWordPosition(index, suggestedWords); if (index != 0) { final View divider = mDividers.get(pos); @@ -369,7 +368,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, // Disable this suggestion if the suggestion is null or empty. word.setEnabled(!TextUtils.isEmpty(styled)); - word.setTextColor(getSuggestionTextColor(index, suggestions, pos)); + word.setTextColor(getSuggestionTextColor(index, suggestedWords, pos)); final int width = getSuggestionWidth(index, stripWidth); final CharSequence text = getEllipsizedText(styled, width, word.getPaint()); final float scaleX = word.getTextScaleX(); @@ -381,7 +380,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, x += word.getMeasuredWidth(); if (DBG) { - final CharSequence debugInfo = getDebugInfo(suggestions, pos); + final CharSequence debugInfo = getDebugInfo(suggestedWords, pos); if (debugInfo != null) { final TextView info = mInfos.get(pos); info.setText(debugInfo); @@ -413,11 +412,11 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, } } - private void setupTexts(SuggestedWords suggestions, int countInStrip) { + private void setupTexts(SuggestedWords suggestedWords, int countInStrip) { mTexts.clear(); - final int count = Math.min(suggestions.size(), countInStrip); + final int count = Math.min(suggestedWords.size(), countInStrip); for (int pos = 0; pos < count; pos++) { - final CharSequence styled = getStyledSuggestionWord(suggestions, pos); + final CharSequence styled = getStyledSuggestionWord(suggestedWords, pos); mTexts.add(styled); } for (int pos = count; pos < countInStrip; pos++) { @@ -426,8 +425,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, } } - private void layoutPunctuationSuggestions(SuggestedWords suggestions, ViewGroup stripView) { - final int countInStrip = Math.min(suggestions.size(), PUNCTUATIONS_IN_STRIP); + private void layoutPunctuationSuggestions(SuggestedWords suggestedWords, + ViewGroup stripView) { + final int countInStrip = Math.min(suggestedWords.size(), PUNCTUATIONS_IN_STRIP); for (int index = 0; index < countInStrip; index++) { if (index != 0) { // Add divider if this isn't the left most suggestion in suggestions strip. @@ -437,7 +437,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, final TextView word = mWords.get(index); word.setEnabled(true); word.setTextColor(mColorAutoCorrect); - final CharSequence text = suggestions.getWord(index); + final CharSequence text = suggestedWords.getWord(index); word.setText(text); word.setTextScaleX(1.0f); word.setCompoundDrawables(null, null, null, null); @@ -636,13 +636,13 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, mKeyboardView = (KeyboardView)inputView.findViewById(R.id.keyboard_view); } - public void setSuggestions(SuggestedWords suggestions) { - if (suggestions == null || suggestions.size() == 0) + public void setSuggestions(SuggestedWords suggestedWords) { + if (suggestedWords == null || suggestedWords.size() == 0) return; clear(); - mSuggestions = suggestions; - mParams.layout(mSuggestions, mSuggestionsStrip, this, getWidth()); + mSuggestedWords = suggestedWords; + mParams.layout(mSuggestedWords, mSuggestionsStrip, this, getWidth()); } @@ -665,7 +665,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, } public SuggestedWords getSuggestions() { - return mSuggestions; + return mSuggestedWords; } public void clear() { @@ -688,7 +688,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, @Override public boolean onCustomRequest(int requestCode) { final int index = requestCode; - final CharSequence word = mSuggestions.getWord(index); + final CharSequence word = mSuggestedWords.getWord(index); mListener.pickSuggestionManually(index, word); dismissMoreSuggestions(); return true; @@ -733,7 +733,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, final int maxWidth = stripWidth - container.getPaddingLeft() - container.getPaddingRight(); final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder; - builder.layout(mSuggestions, params.mSuggestionsCountInStrip, maxWidth, + builder.layout(mSuggestedWords, params.mSuggestionsCountInStrip, maxWidth, (int)(maxWidth * params.mMinMoreSuggestionsWidth), params.mMaxMoreSuggestionsRow); mMoreSuggestionsView.setKeyboard(builder.build()); @@ -835,10 +835,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, if (!(tag instanceof Integer)) return; final int index = (Integer) tag; - if (index >= mSuggestions.size()) + if (index >= mSuggestedWords.size()) return; - final CharSequence word = mSuggestions.getWord(index); + final CharSequence word = mSuggestedWords.getWord(index); mListener.pickSuggestionManually(index, word); } |