diff options
Diffstat (limited to 'java/src')
12 files changed, 161 insertions, 180 deletions
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index f476d83b4..e82d91411 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -93,7 +93,6 @@ public class SuggestionSpanUtils { CharSequence pickedWord, SuggestedWords suggestedWords) { if (TextUtils.isEmpty(pickedWord) || CONSTRUCTOR_SuggestionSpan == null || suggestedWords == null || suggestedWords.size() == 0 - || suggestedWords.getInfo(0).isObsoleteSuggestedWord() || OBJ_SUGGESTIONS_MAX_SIZE == null) { return pickedWord; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java index 3638eae8d..ea3f6236a 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java @@ -97,21 +97,21 @@ public class KeyDetector { /** * Computes maximum size of the array that can contain all nearby key codes returned by - * {@link #getKeyAndNearbyCodes}. + * {@link #getNearbyCodes}. * * @return Returns maximum size of the array that can contain all nearby key codes returned - * by {@link #getKeyAndNearbyCodes}. + * by {@link #getNearbyCodes}. */ protected int getMaxNearbyKeys() { return MAX_NEARBY_KEYS; } /** - * Allocates array that can hold all key codes returned by {@link #getKeyAndNearbyCodes} + * Allocates array that can hold all key codes returned by {@link #getNearbyCodes} * method. The maximum size of the array should be computed by {@link #getMaxNearbyKeys}. * * @return Allocates and returns an array that can hold all key codes returned by - * {@link #getKeyAndNearbyCodes} method. All elements in the returned array are + * {@link #getNearbyCodes} method. All elements in the returned array are * initialized by {@link #NOT_A_CODE} value. */ public int[] newCodeArray() { @@ -222,15 +222,15 @@ public class KeyDetector { * @param x The x-coordinate of a touch point * @param y The y-coordinate of a touch point * @param allCodes All nearby key codes except functional key are returned in this array - * @return The nearest key */ - public Key getKeyAndNearbyCodes(int x, int y, final int[] allCodes) { + // TODO: Move this method to native code. + public void getNearbyCodes(int x, int y, final int[] allCodes) { final int touchX = getTouchX(x); final int touchY = getTouchY(y); initializeNearbyKeys(); Key primaryKey = null; - for (final Key key: mKeyboard.getNearestKeys(touchX, touchY)) { + for (final Key key : mKeyboard.getNearestKeys(touchX, touchY)) { final boolean isOnKey = key.isOnKey(touchX, touchY); final int distance = key.squaredDistanceToEdge(touchX, touchY); if (isOnKey || (mProximityCorrectOn && distance < mProximityThresholdSquare)) { @@ -241,16 +241,31 @@ public class KeyDetector { } } - if (allCodes != null && allCodes.length > 0) { - getNearbyKeyCodes(primaryKey != null ? primaryKey.mCode : NOT_A_CODE, allCodes); - if (DEBUG) { - Log.d(TAG, "x=" + x + " y=" + y - + " primary=" + printableCode(primaryKey) - + " codes=" + printableCodes(allCodes)); - } + getNearbyKeyCodes(primaryKey != null ? primaryKey.mCode : NOT_A_CODE, allCodes); + if (DEBUG) { + Log.d(TAG, "x=" + x + " y=" + y + + " primary=" + printableCode(primaryKey) + + " codes=" + printableCodes(allCodes)); } + } + + /** + * Detect the key whose hitbox the touch point is in. + * + * @param x The x-coordinate of a touch point + * @param y The y-coordinate of a touch point + * @return the key that the touch point hits. + */ + public Key detectHitKey(int x, int y) { + final int touchX = getTouchX(x); + final int touchY = getTouchY(y); - return primaryKey; + for (final Key key : mKeyboard.getNearestKeys(touchX, touchY)) { + if (key.isOnKey(touchX, touchY)) { + return key; + } + } + return null; } public static String printableCode(Key key) { diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java b/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java index 742ee98d7..6c8d02016 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java @@ -39,7 +39,7 @@ public class MoreKeysDetector extends KeyDetector { } @Override - public Key getKeyAndNearbyCodes(int x, int y, final int[] allCodes) { + public void getNearbyCodes(int x, int y, final int[] allCodes) { final int touchX = getTouchX(x); final int touchY = getTouchY(y); @@ -53,8 +53,26 @@ public class MoreKeysDetector extends KeyDetector { } } - if (allCodes != null && nearestKey != null) { + if (nearestKey != null) { allCodes[0] = nearestKey.mCode; + } else { + allCodes[0] = NOT_A_CODE; + } + } + + @Override + public Key detectHitKey(int x, int y) { + final int touchX = getTouchX(x); + final int touchY = getTouchY(y); + + Key nearestKey = null; + int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare; + for (final Key key : getKeyboard().mKeys) { + final int dist = key.squaredDistanceToEdge(touchX, touchY); + if (dist < nearestDist) { + nearestKey = key; + nearestDist = dist; + } } return nearestKey; } diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index ed889712a..ec9081681 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -318,7 +318,7 @@ public class PointerTracker { } public Key getKeyOn(int x, int y) { - return mKeyDetector.getKeyAndNearbyCodes(x, y, null); + return mKeyDetector.detectHitKey(x, y); } private void setReleasedKeyGraphics(Key key) { @@ -421,7 +421,7 @@ public class PointerTracker { private Key onMoveKeyInternal(int x, int y) { mLastX = x; mLastY = y; - return mKeyDetector.getKeyAndNearbyCodes(x, y, null); + return mKeyDetector.detectHitKey(x, y); } private Key onMoveKey(int x, int y) { @@ -748,7 +748,7 @@ public class PointerTracker { private long mPreviousEventTime; private void printTouchEvent(String title, int x, int y, long eventTime) { - final Key key = mKeyDetector.getKeyAndNearbyCodes(x, y, null); + final Key key = mKeyDetector.detectHitKey(x, y); final String code = KeyDetector.printableCode(key); final long delta = eventTime - mPreviousEventTime; Log.d(TAG, String.format("%s%s[%d] %4d %4d %5d %s", title, diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 9f5931de9..fa5a46fca 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -459,6 +459,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // TODO: remove the following when it's not needed by updateCorrectionMode() any more mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */); + updateCorrectionMode(); + Utils.GCUtils.getInstance().reset(); boolean tryGC = true; for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { @@ -534,8 +536,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar = new UserBigramDictionary(this, this, localeStr, Suggest.DIC_USER_BIGRAM); mSuggest.setUserBigramDictionary(mUserBigramDictionary); - updateCorrectionMode(); - LocaleUtils.setSystemLocale(res, savedLocale); } @@ -931,7 +931,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + false /* isObsoleteSuggestions */); // When in fullscreen mode, show completions generated by the application final boolean isAutoCorrection = false; setSuggestions(suggestedWords, isAutoCorrection); @@ -1715,7 +1716,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar setAutoCorrectionIndicator(false); } - public void setSuggestions(final SuggestedWords words, final boolean isAutoCorrection) { + private void setSuggestions(final SuggestedWords words, final boolean isAutoCorrection) { if (mSuggestionsView != null) { mSuggestionsView.setSuggestions(words); mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection); @@ -1725,15 +1726,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar 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) { - if (mIsAutoCorrectionIndicatorOn != newAutoCorrectionIndicator) { - if (mWordComposer.isComposingWord()) { - mIsAutoCorrectionIndicatorOn = newAutoCorrectionIndicator; - final CharSequence textWithUnderline = - getTextWithUnderline(mWordComposer.getTypedWord()); - ic.setComposingText(textWithUnderline, 1); - } - } + if (ic == null) return; + if (mIsAutoCorrectionIndicatorOn != newAutoCorrectionIndicator + && mWordComposer.isComposingWord()) { + mIsAutoCorrectionIndicatorOn = newAutoCorrectionIndicator; + final CharSequence textWithUnderline = + getTextWithUnderline(mWordComposer.getTypedWord()); + ic.setComposingText(textWithUnderline, 1); } } @@ -1766,7 +1765,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } final CharSequence typedWord = mWordComposer.getTypedWord(); - // getSuggestedWordBuilder handles gracefully a null value of prevWord + // getSuggestedWords handles gracefully a null value of prevWord final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode); @@ -1793,7 +1792,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + true /* isObsoleteSuggestions */); showSuggestions(obsoleteSuggestedWords, typedWord); } } @@ -2059,10 +2059,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (ic == null) return false; CharSequence before = ic.getTextBeforeCursor(1, 0); CharSequence after = ic.getTextAfterCursor(1, 0); - if (!TextUtils.isEmpty(before) && !mSettingsValues.isWordSeparator(before.charAt(0))) { + if (!TextUtils.isEmpty(before) && !mSettingsValues.isWordSeparator(before.charAt(0)) + && !mSettingsValues.isSymbolExcludedFromWordSeparators(before.charAt(0))) { return true; } - if (!TextUtils.isEmpty(after) && !mSettingsValues.isWordSeparator(after.charAt(0))) { + if (!TextUtils.isEmpty(after) && !mSettingsValues.isWordSeparator(after.charAt(0)) + && !mSettingsValues.isSymbolExcludedFromWordSeparators(after.charAt(0))) { return true; } return false; @@ -2233,6 +2235,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettingsValues); } initSuggest(); + updateCorrectionMode(); loadSettings(); // Since we just changed languages, we should re-evaluate suggestions with whatever word // we are currently composing. If we are not composing anything, we may want to display diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index d12b9c428..4346a3671 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -42,9 +42,7 @@ public class SettingsValues { public final String mWeakSpaceStrippers; public final String mWeakSpaceSwappers; private final String mPhantomSpacePromotingSymbols; - private final String mSuggestPuncs; public final SuggestedWords mSuggestPuncList; - public final SuggestedWords mSuggestPuncOutputTextList; private final String mSymbolsExcludedFromWordSeparators; public final String mWordSeparators; public final CharSequence mHintToSaveText; @@ -110,9 +108,7 @@ public class SettingsValues { } final String[] suggestPuncsSpec = KeySpecParser.parseCsvString( res.getString(R.string.suggested_punctuations), res, R.string.english_ime_name); - mSuggestPuncs = createSuggestPuncs(suggestPuncsSpec); mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec); - mSuggestPuncOutputTextList = createSuggestPuncOutputTextList(suggestPuncsSpec); mSymbolsExcludedFromWordSeparators = res.getString(R.string.symbols_excluded_from_word_separators); mWordSeparators = createWordSeparators(mWeakSpaceStrippers, mWeakSpaceSwappers, @@ -164,16 +160,6 @@ public class SettingsValues { } // Helper functions to create member values. - private static String createSuggestPuncs(final String[] puncs) { - final StringBuilder sb = new StringBuilder(); - if (puncs != null) { - for (final String puncSpec : puncs) { - sb.append(KeySpecParser.getLabel(puncSpec)); - } - } - return sb.toString(); - } - private static SuggestedWords createSuggestPuncList(final String[] puncs) { final ArrayList<SuggestedWords.SuggestedWordInfo> puncList = new ArrayList<SuggestedWords.SuggestedWordInfo>(); @@ -187,28 +173,8 @@ public class SettingsValues { false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - true /* isPunctuationSuggestions */); - } - - private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { - final ArrayList<SuggestedWords.SuggestedWordInfo> puncOutputTextList = - new ArrayList<SuggestedWords.SuggestedWordInfo>(); - if (puncs != null) { - for (final String puncSpec : puncs) { - final String outputText = KeySpecParser.getOutputText(puncSpec); - if (outputText != null) { - puncOutputTextList.add(new SuggestedWords.SuggestedWordInfo(outputText)); - } else { - puncOutputTextList.add(new SuggestedWords.SuggestedWordInfo( - KeySpecParser.getLabel(puncSpec))); - } - } - } - return new SuggestedWords(puncOutputTextList, - false /* typedWordValid */, - false /* hasAutoCorrectionCandidate */, - false /* allowsToBeAutoCorrected */, - true /* isPunctuationSuggestions */); + true /* isPunctuationSuggestions */, + false /* isObsoleteSuggestions */); } private static String createWordSeparators(final String weakSpaceStrippers, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 3089625e7..69754d769 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -22,6 +22,7 @@ import android.util.Log; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.ProximityInfo; +import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.io.File; import java.util.ArrayList; @@ -273,7 +274,8 @@ public class Suggest implements Dictionary.WordCallback { false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + false /* isObsoleteSuggestions */); } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder @@ -292,18 +294,9 @@ public class Suggest implements Dictionary.WordCallback { ? typedWord.substring(0, typedWord.length() - mTrailingSingleQuotesCount) : typedWord; // Treating USER_TYPED as UNIGRAM suggestion for logging now. - LatinImeLogger.onAddSuggestedWord(typedWord, Suggest.DIC_USER_TYPED, - Dictionary.UNIGRAM); + LatinImeLogger.onAddSuggestedWord(typedWord, Suggest.DIC_USER_TYPED, Dictionary.UNIGRAM); mConsideredWord = consideredWord; - // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid" - // but still autocorrected from - in the case the whitelist only capitalizes the word. - // The whitelist should be case-insensitive, so it's not possible to be consistent with - // a boolean flag. Right now this is handled with a slight hack in - // WhitelistDictionary#shouldForciblyAutoCorrectFrom. - final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected( - getUnigramDictionaries(), consideredWord, wordComposer.isFirstCharCapitalized()); - if (wordComposer.size() <= 1 && (correctionMode == CORRECTION_FULL_BIGRAM)) { // At first character typed, search only the bigrams Arrays.fill(mBigramScores, 0); @@ -362,12 +355,11 @@ public class Suggest implements Dictionary.WordCallback { } } - CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase, mIsFirstCharCapitalized, - mWhiteListDictionary.getWhitelistedWord(consideredWord)); + final CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase, + mIsFirstCharCapitalized, mWhiteListDictionary.getWhitelistedWord(consideredWord)); final boolean hasAutoCorrection; - if (CORRECTION_FULL == correctionMode - || CORRECTION_FULL_BIGRAM == correctionMode) { + if (CORRECTION_FULL == correctionMode || CORRECTION_FULL_BIGRAM == correctionMode) { final CharSequence autoCorrection = AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer, mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold, @@ -392,59 +384,68 @@ public class Suggest implements Dictionary.WordCallback { mSuggestions.add(0, typedWord); StringUtils.removeDupes(mSuggestions); - final ArrayList<SuggestedWords.SuggestedWordInfo> suggestionsList; + final ArrayList<SuggestedWordInfo> suggestionsList; if (DBG) { - // TODO: this doesn't take into account the fact that removing dupes from mSuggestions - // may have made mScores[] and mSuggestions out of sync. - final CharSequence autoCorrectionSuggestion = mSuggestions.get(0); - double normalizedScore = BinaryDictionary.calcNormalizedScore( - typedWord, autoCorrectionSuggestion.toString(), mScores[0]); - suggestionsList = new ArrayList<SuggestedWords.SuggestedWordInfo>(); - suggestionsList.add(new SuggestedWords.SuggestedWordInfo(autoCorrectionSuggestion, "+", - false)); - final int suggestionsSize = mSuggestions.size(); - // Note: i here is the index in mScores[], but the index in mSuggestions is one more - // than i because we added the typed word to mSuggestions without touching mScores. - for (int i = 0; i < mScores.length && i < suggestionsSize - 1; ++i) { - final String scoreInfoString; - if (normalizedScore > 0) { - scoreInfoString = String.format("%d (%4.2f)", mScores[i], normalizedScore); - normalizedScore = 0.0; - } else { - scoreInfoString = Integer.toString(mScores[i]); - } - suggestionsList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i + 1), - scoreInfoString, false)); - } - for (int i = mScores.length; i < suggestionsSize; ++i) { - suggestionsList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i), - "--", false)); - } + suggestionsList = getSuggestionsInfoListWithDebugInfo(typedWord, mSuggestions, mScores); } else { suggestionsList = SuggestedWords.getFromCharSequenceList(mSuggestions); } + // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid" + // but still autocorrected from - in the case the whitelist only capitalizes the word. + // The whitelist should be case-insensitive, so it's not possible to be consistent with + // a boolean flag. Right now this is handled with a slight hack in + // WhitelistDictionary#shouldForciblyAutoCorrectFrom. + final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected( + getUnigramDictionaries(), consideredWord, wordComposer.isFirstCharCapitalized()); + boolean autoCorrectionAvailable = hasAutoCorrection; - if (correctionMode == Suggest.CORRECTION_FULL - || correctionMode == Suggest.CORRECTION_FULL_BIGRAM) { + if (correctionMode == CORRECTION_FULL || correctionMode == CORRECTION_FULL_BIGRAM) { autoCorrectionAvailable |= !allowsToBeAutoCorrected; } // Don't auto-correct words with multiple capital letter autoCorrectionAvailable &= !wordComposer.isMostlyCaps(); - final boolean shouldBlockAutoCorrectionBySatefyNet; if (allowsToBeAutoCorrected && suggestionsList.size() > 1 && mAutoCorrectionThreshold > 0 && Suggest.shouldBlockAutoCorrectionBySafetyNet(typedWord, suggestionsList.get(1).mWord)) { - shouldBlockAutoCorrectionBySatefyNet = true; - } else { - shouldBlockAutoCorrectionBySatefyNet = false; + autoCorrectionAvailable = false; } return new SuggestedWords(suggestionsList, !allowsToBeAutoCorrected /* typedWordValid */, - autoCorrectionAvailable & !shouldBlockAutoCorrectionBySatefyNet - /* hasAutoCorrectionCandidate */, + autoCorrectionAvailable /* hasAutoCorrectionCandidate */, allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + false /* isObsoleteSuggestions */); + } + + // This assumes the scores[] array is at least as long as suggestions.size() - 1. + private static ArrayList<SuggestedWordInfo> getSuggestionsInfoListWithDebugInfo( + final String typedWord, final ArrayList<CharSequence> suggestions, final int[] scores) { + // TODO: this doesn't take into account the fact that removing dupes from mSuggestions + // may have made mScores[] and mSuggestions out of sync. + final CharSequence autoCorrectionSuggestion = suggestions.get(0); + double normalizedScore = BinaryDictionary.calcNormalizedScore( + typedWord, autoCorrectionSuggestion.toString(), scores[0]); + final int suggestionsSize = suggestions.size(); + final ArrayList<SuggestedWordInfo> suggestionsList = + new ArrayList<SuggestedWordInfo>(suggestionsSize); + suggestionsList.add(new SuggestedWordInfo(autoCorrectionSuggestion, "+")); + // Note: i here is the index in mScores[], but the index in mSuggestions is one more + // than i because we added the typed word to mSuggestions without touching mScores. + for (int i = 0; i < scores.length && i < suggestionsSize - 1; ++i) { + final String scoreInfoString; + if (normalizedScore > 0) { + scoreInfoString = String.format("%d (%4.2f)", scores[i], normalizedScore); + normalizedScore = 0.0; + } else { + scoreInfoString = Integer.toString(scores[i]); + } + suggestionsList.add(new SuggestedWordInfo(suggestions.get(i + 1), scoreInfoString)); + } + for (int i = scores.length; i < suggestionsSize; ++i) { + suggestionsList.add(new SuggestedWordInfo(suggestions.get(i), "--")); + } + return suggestionsList; } @Override diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 6b231f81c..b63bc6c29 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -27,24 +27,27 @@ import java.util.List; public class SuggestedWords { public static final SuggestedWords EMPTY = new SuggestedWords( - Collections.<SuggestedWordInfo>emptyList(), false, false, false, false); + Collections.<SuggestedWordInfo>emptyList(), false, false, false, false, false); public final boolean mTypedWordValid; public final boolean mHasAutoCorrectionCandidate; public final boolean mIsPunctuationSuggestions; public final boolean mAllowsToBeAutoCorrected; + public final boolean mIsObsoleteSuggestions; private final List<SuggestedWordInfo> mSuggestedWordInfoList; public SuggestedWords(final List<SuggestedWordInfo> suggestedWordInfoList, final boolean typedWordValid, final boolean hasAutoCorrectionCandidate, final boolean allowsToBeAutoCorrected, - final boolean isPunctuationSuggestions) { + final boolean isPunctuationSuggestions, + final boolean isObsoleteSuggestions) { mSuggestedWordInfoList = suggestedWordInfoList; mTypedWordValid = typedWordValid; mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate; mAllowsToBeAutoCorrected = allowsToBeAutoCorrected; mIsPunctuationSuggestions = isPunctuationSuggestions; + mIsObsoleteSuggestions = isObsoleteSuggestions; } public int size() { @@ -56,7 +59,7 @@ public class SuggestedWords { } public SuggestedWordInfo getInfo(int pos) { - return mSuggestedWordInfoList != null ? mSuggestedWordInfoList.get(pos) : null; + return mSuggestedWordInfoList.get(pos); } public boolean hasAutoCorrectionWord() { @@ -82,7 +85,7 @@ public class SuggestedWords { final List<CharSequence> wordList) { final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>(); for (CharSequence word : wordList) { - if (null != word) result.add(new SuggestedWordInfo(word, null, false)); + if (null != word) result.add(new SuggestedWordInfo(word)); } return result; } @@ -91,7 +94,7 @@ public class SuggestedWords { final CompletionInfo[] infos) { final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>(); for (CompletionInfo info : infos) { - if (null != info) result.add(new SuggestedWordInfo(info.getText(), null, false)); + if (null != info) result.add(new SuggestedWordInfo(info.getText())); } return result; } @@ -102,14 +105,14 @@ public class SuggestedWords { final CharSequence typedWord, final SuggestedWords previousSuggestions) { final ArrayList<SuggestedWordInfo> suggestionsList = new ArrayList<SuggestedWordInfo>(); final HashSet<String> alreadySeen = new HashSet<String>(); - suggestionsList.add(new SuggestedWordInfo(typedWord, null, false)); + suggestionsList.add(new SuggestedWordInfo(typedWord)); alreadySeen.add(typedWord.toString()); final int previousSize = previousSuggestions.size(); for (int pos = 1; pos < previousSize; pos++) { final String prevWord = previousSuggestions.getWord(pos).toString(); // Filter out duplicate suggestion. if (!alreadySeen.contains(prevWord)) { - suggestionsList.add(new SuggestedWordInfo(prevWord, null, true)); + suggestionsList.add(new SuggestedWordInfo(prevWord)); alreadySeen.add(prevWord); } } @@ -118,32 +121,21 @@ public class SuggestedWords { public static class SuggestedWordInfo { public final CharSequence mWord; - private final CharSequence mDebugString; - private final boolean mPreviousSuggestedWord; + private final String mDebugString; public SuggestedWordInfo(final CharSequence word) { mWord = word; mDebugString = ""; - mPreviousSuggestedWord = false; } - public SuggestedWordInfo(final CharSequence word, final CharSequence debugString, - final boolean previousSuggestedWord) { + public SuggestedWordInfo(final CharSequence word, final String debugString) { mWord = word; + if (null == debugString) throw new NullPointerException(""); mDebugString = debugString; - mPreviousSuggestedWord = previousSuggestedWord; } public String getDebugString() { - if (mDebugString == null) { - return ""; - } else { - return mDebugString.toString(); - } - } - - public boolean isObsoleteSuggestedWord () { - return mPreviousSuggestedWord; + return mDebugString; } @Override diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index f8dd5ae42..a7de47c58 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -30,6 +30,8 @@ import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; +import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -454,4 +456,13 @@ public class Utils { LatinImeLogger.logOnAutoCorrectionCancelled(); } } + + public static String getDebugInfo(final SuggestedWords suggestions, final int pos) { + if (!LatinImeLogger.sDBG) return null; + final SuggestedWordInfo wordInfo = suggestions.getInfo(pos); + if (wordInfo == null) return null; + final String info = wordInfo.getDebugString(); + if (TextUtils.isEmpty(info)) return null; + return info; + } } diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 3324a3793..126ac47e7 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -141,9 +141,9 @@ public class WordComposer { keyY = y; } else { codes = keyDetector.newCodeArray(); - keyDetector.getKeyAndNearbyCodes(x, y, codes); + keyDetector.getNearbyCodes(x, y, codes); keyX = keyDetector.getTouchX(x); - keyY = keyDetector.getTouchX(y); + keyY = keyDetector.getTouchY(y); } add(primaryCode, codes, keyX, keyY); } @@ -204,7 +204,7 @@ public class WordComposer { final int x = key.mX + key.mWidth / 2; final int y = key.mY + key.mHeight / 2; final int[] codes = keyDetector.newCodeArray(); - keyDetector.getKeyAndNearbyCodes(x, y, codes); + keyDetector.getNearbyCodes(x, y, codes); add(codePoint, codes, x, y); return; } diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java index cb1b49c67..c9c88fd23 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin.suggestions; import android.content.res.Resources; import android.graphics.Paint; import android.graphics.drawable.Drawable; -import android.text.TextUtils; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; @@ -29,7 +28,7 @@ import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SuggestedWords; -import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import com.android.inputmethod.latin.Utils; public class MoreSuggestions extends Keyboard { public static final int SUGGESTION_CODE_BASE = 1024; @@ -191,15 +190,6 @@ public class MoreSuggestions extends Keyboard { return this; } - private static String getDebugInfo(SuggestedWords suggestions, int pos) { - if (!DBG) return null; - final SuggestedWordInfo wordInfo = suggestions.getInfo(pos); - if (wordInfo == null) return null; - final String info = wordInfo.getDebugString(); - if (TextUtils.isEmpty(info)) return null; - return info; - } - private static class Divider extends Key.Spacer { private final Drawable mIcon; @@ -223,7 +213,7 @@ public class MoreSuggestions extends Keyboard { final int y = params.getY(pos); final int width = params.getWidth(pos); final String word = mSuggestions.getWord(pos).toString(); - final String info = getDebugInfo(mSuggestions, pos); + final String info = Utils.getDebugInfo(mSuggestions, pos); final int index = pos + SUGGESTION_CODE_BASE; final Key key = new Key( params, word, info, KeyboardIconsSet.ICON_UNDEFINED, index, null, x, y, diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index 812376de0..d3c3afb73 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -63,6 +63,7 @@ import com.android.inputmethod.latin.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.Suggest; 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; @@ -339,9 +340,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, } } - final SuggestedWordInfo info = (pos < suggestedWords.size()) - ? suggestedWords.getInfo(pos) : null; - if (info != null && info.isObsoleteSuggestedWord()) { + if (suggestedWords.mIsObsoleteSuggestions && isSuggested) { return applyAlpha(color, mAlphaObsoleted); } else { return color; @@ -406,8 +405,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, word, getSuggestionWeight(index), ViewGroup.LayoutParams.MATCH_PARENT); x += word.getMeasuredWidth(); - if (DBG) { - final CharSequence debugInfo = getDebugInfo(suggestedWords, pos); + if (DBG && pos < suggestedWords.size()) { + final CharSequence debugInfo = Utils.getDebugInfo(suggestedWords, pos); if (debugInfo != null) { final TextView info = mInfos.get(pos); info.setText(debugInfo); @@ -502,19 +501,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, hintView, 1.0f - mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT); } - private static CharSequence getDebugInfo(SuggestedWords suggestions, int pos) { - if (DBG && pos < suggestions.size()) { - final SuggestedWordInfo wordInfo = suggestions.getInfo(pos); - if (wordInfo != null) { - final CharSequence debugInfo = wordInfo.getDebugString(); - if (!TextUtils.isEmpty(debugInfo)) { - return debugInfo; - } - } - } - return null; - } - private static void setLayoutWeight(View v, float weight, int height) { final ViewGroup.LayoutParams lp = v.getLayoutParams(); if (lp instanceof LinearLayout.LayoutParams) { |