aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2014-09-18 07:38:20 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-09-18 07:38:20 +0000
commit233a2f21c38a27049fa3b03af699593f629d1681 (patch)
treecc79f1178e773ed12b4e6ae9b639b47589994ddc /java/src/com/android/inputmethod/latin
parent902cefb6635053b682a917259eb5a964a17506fd (diff)
parent8c9948f436bd764c6483d9af8c730e1b91e3b7ab (diff)
downloadlatinime-233a2f21c38a27049fa3b03af699593f629d1681.tar.gz
latinime-233a2f21c38a27049fa3b03af699593f629d1681.tar.xz
latinime-233a2f21c38a27049fa3b03af699593f629d1681.zip
am 8c9948f4: am fa63d910: Merge "Use Add-To-Dictionary indicator only" into lmp-dev
* commit '8c9948f436bd764c6483d9af8c730e1b91e3b7ab': Use Add-To-Dictionary indicator only
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java27
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java9
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java192
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java15
-rw-r--r--java/src/com/android/inputmethod/latin/utils/StringUtils.java34
5 files changed, 121 insertions, 156 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 84b2d279c..81953221e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -188,9 +188,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private static final int MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED = 6;
private static final int MSG_RESET_CACHES = 7;
private static final int MSG_WAIT_FOR_DICTIONARY_LOAD = 8;
- private static final int MSG_SHOW_COMMIT_INDICATOR = 9;
// Update this when adding new messages
- private static final int MSG_LAST = MSG_SHOW_COMMIT_INDICATOR;
+ private static final int MSG_LAST = MSG_WAIT_FOR_DICTIONARY_LOAD;
private static final int ARG1_NOT_GESTURE_INPUT = 0;
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
@@ -201,7 +200,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private int mDelayInMillisecondsToUpdateSuggestions;
private int mDelayInMillisecondsToUpdateShiftState;
- private int mDelayInMillisecondsToShowCommitIndicator;
public UIHandler(final LatinIME ownerInstance) {
super(ownerInstance);
@@ -217,8 +215,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
R.integer.config_delay_in_milliseconds_to_update_suggestions);
mDelayInMillisecondsToUpdateShiftState = res.getInteger(
R.integer.config_delay_in_milliseconds_to_update_shift_state);
- mDelayInMillisecondsToShowCommitIndicator = res.getInteger(
- R.integer.text_decorator_delay_in_milliseconds_to_show_commit_indicator);
}
@Override
@@ -276,14 +272,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
latinIme.getCurrentRecapitalizeState());
}
break;
- case MSG_SHOW_COMMIT_INDICATOR:
- // Protocol of MSG_SET_COMMIT_INDICATOR_ENABLED:
- // - what: MSG_SHOW_COMMIT_INDICATOR
- // - arg1: not used.
- // - arg2: not used.
- // - obj: the Runnable object to be called back.
- ((Runnable) msg.obj).run();
- break;
case MSG_WAIT_FOR_DICTIONARY_LOAD:
Log.i(TAG, "Timeout waiting for dictionary load");
break;
@@ -384,19 +372,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
obtainMessage(MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED, suggestedWords).sendToTarget();
}
- /**
- * Posts a delayed task to show the commit indicator.
- *
- * <p>Only one task can exist in the queue. When this method is called, any prior task that
- * has not yet fired will be canceled.</p>
- * @param task the runnable object that will be fired when the delayed task is dispatched.
- */
- public void postShowCommitIndicatorTask(final Runnable task) {
- removeMessages(MSG_SHOW_COMMIT_INDICATOR);
- sendMessageDelayed(obtainMessage(MSG_SHOW_COMMIT_INDICATOR, task),
- mDelayInMillisecondsToShowCommitIndicator);
- }
-
// Working variables for the following methods.
private boolean mIsOrientationChanging;
private boolean mPendingSuccessiveImsCallback;
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index b5d42dd04..744b0321a 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -252,7 +252,7 @@ public final class RichInputConnection {
* See {@link InputConnection#commitText(CharSequence, int)}.
*/
public void commitText(final CharSequence text, final int newCursorPosition) {
- commitTextWithBackgroundColor(text, newCursorPosition, Color.TRANSPARENT);
+ commitTextWithBackgroundColor(text, newCursorPosition, Color.TRANSPARENT, text.length());
}
/**
@@ -265,9 +265,11 @@ public final class RichInputConnection {
* the background color. Note that this method specifies {@link BackgroundColorSpan} with
* {@link Spanned#SPAN_COMPOSING} flag, meaning that the background color persists until
* {@link #finishComposingText()} is called.
+ * @param coloredTextLength the length of text, in Java chars, which should be rendered with
+ * the given background color.
*/
public void commitTextWithBackgroundColor(final CharSequence text, final int newCursorPosition,
- final int color) {
+ final int color, final int coloredTextLength) {
if (DEBUG_BATCH_NESTING) checkBatchEdit();
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
mCommittedTextBeforeComposingText.append(text);
@@ -285,7 +287,8 @@ public final class RichInputConnection {
mTempObjectForCommitText.clear();
mTempObjectForCommitText.append(text);
final BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(color);
- mTempObjectForCommitText.setSpan(backgroundColorSpan, 0, text.length(),
+ final int spanLength = Math.min(coloredTextLength, text.length());
+ mTempObjectForCommitText.setSpan(backgroundColorSpan, 0, spanLength,
Spanned.SPAN_COMPOSING | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mIC.commitText(mTempObjectForCommitText, newCursorPosition);
mLastCommittedTextHasBackgroundColor = true;
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 5ab3571e6..21e2a1c10 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -28,6 +28,7 @@ import android.util.Log;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.inputmethod.CorrectionInfo;
+import android.view.inputmethod.CursorAnchorInfo;
import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.CursorAnchorInfoCompatWrapper;
@@ -90,12 +91,8 @@ public final class InputLogic {
private final TextDecorator mTextDecorator = new TextDecorator(new TextDecorator.Listener() {
@Override
- public void onClickComposingTextToCommit(SuggestedWordInfo wordInfo) {
- mLatinIME.pickSuggestionManually(wordInfo);
- }
- @Override
- public void onClickComposingTextToAddToDictionary(SuggestedWordInfo wordInfo) {
- mLatinIME.addWordToUserDictionary(wordInfo.mWord);
+ public void onClickComposingTextToAddToDictionary(final String word) {
+ mLatinIME.addWordToUserDictionary(word);
mLatinIME.dismissAddToDictionaryHint();
}
});
@@ -170,6 +167,7 @@ public final class InputLogic {
mConnection.requestCursorUpdates(true /* enableMonitor */,
true /* requestImmediateCallback */);
}
+ mTextDecorator.reset();
}
}
@@ -333,17 +331,8 @@ public final class InputLogic {
}
final boolean shouldShowAddToDictionaryHint = shouldShowAddToDictionaryHint(suggestionInfo);
- final boolean shouldShowAddToDictionaryIndicator =
- shouldShowAddToDictionaryHint && settingsValues.mShouldShowUiToAcceptTypedWord;
- final int backgroundColor;
- if (shouldShowAddToDictionaryIndicator) {
- backgroundColor = settingsValues.mTextHighlightColorForAddToDictionaryIndicator;
- } else {
- backgroundColor = Color.TRANSPARENT;
- }
- commitChosenWordWithBackgroundColor(settingsValues, suggestion,
- LastComposedWord.COMMIT_TYPE_MANUAL_PICK, LastComposedWord.NOT_A_SEPARATOR,
- backgroundColor);
+ commitChosenWord(settingsValues, suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
+ LastComposedWord.NOT_A_SEPARATOR);
mConnection.endBatchEdit();
// Don't allow cancellation of manual pick
mLastComposedWord.deactivate();
@@ -358,9 +347,6 @@ public final class InputLogic {
// That's going to be predictions (or punctuation suggestions), so INPUT_STYLE_NONE.
handler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_NONE);
}
- if (shouldShowAddToDictionaryIndicator) {
- mTextDecorator.showAddToDictionaryIndicator(suggestionInfo);
- }
return inputTransaction;
}
@@ -430,6 +416,9 @@ public final class InputLogic {
mRecapitalizeStatus.enable();
// We moved the cursor and need to invalidate the indicator right now.
mTextDecorator.reset();
+ // Remaining background color that was used for the add-to-dictionary indicator should be
+ // removed.
+ mConnection.removeBackgroundColorFromHighlightedTextIfNecessary();
// We moved the cursor. If we are touching a word, we need to resume suggestion.
mLatinIME.mHandler.postResumeSuggestions(false /* shouldIncludeResumedWordInSuggestions */,
true /* shouldDelay */);
@@ -508,7 +497,9 @@ public final class InputLogic {
handler.cancelUpdateSuggestionStrip();
++mAutoCommitSequenceNumber;
mConnection.beginBatchEdit();
- if (mWordComposer.isComposingWord()) {
+ if (!mWordComposer.isComposingWord()) {
+ mConnection.removeBackgroundColorFromHighlightedTextIfNecessary();
+ } else {
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
// If we are in the middle of a recorrection, we need to commit the recorrection
// first so that we can insert the batch input at the current cursor position.
@@ -620,42 +611,6 @@ public final class InputLogic {
}
mSuggestedWords = suggestedWords;
final boolean newAutoCorrectionIndicator = suggestedWords.mWillAutoCorrect;
- if (shouldShowCommitIndicator(suggestedWords, settingsValues)) {
- // typedWordInfo is never null here.
- final int textBackgroundColor = settingsValues.mTextHighlightColorForCommitIndicator;
- final SuggestedWordInfo typedWordInfo = suggestedWords.getTypedWordInfoOrNull();
- handler.postShowCommitIndicatorTask(new Runnable() {
- @Override
- public void run() {
- // TODO: This needs to be refactored to ensure that mWordComposer is accessed
- // only from the UI thread.
- if (!mWordComposer.isComposingWord()) {
- mTextDecorator.reset();
- return;
- }
- final SuggestedWordInfo currentTypedWordInfo =
- mSuggestedWords.getTypedWordInfoOrNull();
- if (currentTypedWordInfo == null) {
- mTextDecorator.reset();
- return;
- }
- if (!currentTypedWordInfo.equals(typedWordInfo)) {
- // Suggested word has been changed. This task is obsolete.
- mTextDecorator.reset();
- return;
- }
- // TODO: As with the above TODO comment, this operation must be performed only
- // on the UI thread too. Needs to be refactored.
- setComposingTextInternalWithBackgroundColor(typedWordInfo.mWord,
- 1 /* newCursorPosition */, textBackgroundColor);
- mTextDecorator.showCommitIndicator(typedWordInfo);
- }
- });
- } else {
- // Note: It is OK to not cancel previous postShowCommitIndicatorTask() here. Having a
- // cancellation mechanism could improve performance a bit though.
- mTextDecorator.reset();
- }
// Put a blue underline to a word in TextView which will be auto-corrected.
if (mIsAutoCorrectionIndicatorOn != newAutoCorrectionIndicator
@@ -833,13 +788,14 @@ public final class InputLogic {
final InputTransaction inputTransaction,
// TODO: remove this argument
final LatinIME.UIHandler handler) {
- // In case the "add to dictionary" hint was still displayed.
- // TODO: Do we really need to check if we have composing text here?
- if (!mWordComposer.isComposingWord() &&
- mSuggestionStripViewAccessor.isShowingAddToDictionaryHint()) {
- mSuggestionStripViewAccessor.dismissAddToDictionaryHint();
+ if (!mWordComposer.isComposingWord()) {
mConnection.removeBackgroundColorFromHighlightedTextIfNecessary();
- mTextDecorator.reset();
+ // In case the "add to dictionary" hint was still displayed.
+ // TODO: Do we really need to check if we have composing text here?
+ if (mSuggestionStripViewAccessor.isShowingAddToDictionaryHint()) {
+ mSuggestionStripViewAccessor.dismissAddToDictionaryHint();
+ mTextDecorator.reset();
+ }
}
final int codePoint = event.mCodePoint;
@@ -1096,7 +1052,7 @@ public final class InputLogic {
inputTransaction.setRequiresUpdateSuggestions();
} else {
if (mLastComposedWord.canRevertCommit()) {
- revertCommit(inputTransaction);
+ revertCommit(inputTransaction, inputTransaction.mSettingsValues);
return;
}
if (mEnteredText != null && mConnection.sameAsTextBeforeCursor(mEnteredText)) {
@@ -1582,14 +1538,19 @@ public final class InputLogic {
* This is triggered upon pressing backspace just after a commit with auto-correction.
*
* @param inputTransaction The transaction in progress.
+ * @param settingsValues the current values of the settings.
*/
- private void revertCommit(final InputTransaction inputTransaction) {
+ private void revertCommit(final InputTransaction inputTransaction,
+ final SettingsValues settingsValues) {
final CharSequence originallyTypedWord = mLastComposedWord.mTypedWord;
+ final String originallyTypedWordString =
+ originallyTypedWord != null ? originallyTypedWord.toString() : "";
final CharSequence committedWord = mLastComposedWord.mCommittedWord;
final String committedWordString = committedWord.toString();
final int cancelLength = committedWord.length();
+ final String separatorString = mLastComposedWord.mSeparatorString;
// We want java chars, not codepoints for the following.
- final int separatorLength = mLastComposedWord.mSeparatorString.length();
+ final int separatorLength = separatorString.length();
// TODO: should we check our saved separator against the actual contents of the text view?
final int deleteLength = cancelLength + separatorLength;
if (DebugFlags.DEBUG_ENABLED) {
@@ -1608,7 +1569,7 @@ public final class InputLogic {
if (!TextUtils.isEmpty(committedWord)) {
mDictionaryFacilitator.removeWordFromPersonalizedDicts(committedWordString);
}
- final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString;
+ final String stringToCommit = originallyTypedWord + separatorString;
final SpannableString textToCommit = new SpannableString(stringToCommit);
if (committedWord instanceof SpannableString) {
final SpannableString committedWordWithSuggestionSpans = (SpannableString)committedWord;
@@ -1645,23 +1606,53 @@ public final class InputLogic {
suggestions.toArray(new String[suggestions.size()]), 0 /* flags */),
0 /* start */, lastCharIndex /* end */, 0 /* flags */);
}
+
+ final boolean shouldShowAddToDictionaryForTypedWord =
+ shouldShowAddToDictionaryForTypedWord(mLastComposedWord, settingsValues);
+
if (inputTransaction.mSettingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
// For languages with spaces, we revert to the typed string, but the cursor is still
// after the separator so we don't resume suggestions. If the user wants to correct
// the word, they have to press backspace again.
- mConnection.commitText(textToCommit, 1);
+ if (shouldShowAddToDictionaryForTypedWord) {
+ mConnection.commitTextWithBackgroundColor(textToCommit, 1,
+ settingsValues.mTextHighlightColorForAddToDictionaryIndicator,
+ originallyTypedWordString.length());
+ } else {
+ mConnection.commitText(textToCommit, 1);
+ }
} else {
// For languages without spaces, we revert the typed string but the cursor is flush
// with the typed word, so we need to resume suggestions right away.
final int[] codePoints = StringUtils.toCodePointArray(stringToCommit);
mWordComposer.setComposingWord(codePoints,
mLatinIME.getCoordinatesForCurrentKeyboard(codePoints));
- setComposingTextInternal(textToCommit, 1);
+ if (shouldShowAddToDictionaryForTypedWord) {
+ setComposingTextInternalWithBackgroundColor(textToCommit, 1,
+ settingsValues.mTextHighlightColorForAddToDictionaryIndicator,
+ originallyTypedWordString.length());
+ } else {
+ setComposingTextInternal(textToCommit, 1);
+ }
}
// Don't restart suggestion yet. We'll restart if the user deletes the separator.
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
- // We have a separator between the word and the cursor: we should show predictions.
- inputTransaction.setRequiresUpdateSuggestions();
+
+ if (shouldShowAddToDictionaryForTypedWord) {
+ // Due to the API limitation as of L, we cannot reliably retrieve the reverted text
+ // when the separator causes line breaking. Until this API limitation is addressed in
+ // the framework, show the indicator only when the separator doesn't contain
+ // line-breaking characters.
+ if (!StringUtils.hasLineBreakCharacter(separatorString)) {
+ mTextDecorator.showAddToDictionaryIndicator(originallyTypedWordString,
+ mConnection.getExpectedSelectionStart(),
+ mConnection.getExpectedSelectionEnd());
+ }
+ mSuggestionStripViewAccessor.showAddToDictionaryHint(originallyTypedWordString);
+ } else {
+ // We have a separator between the word and the cursor: we should show predictions.
+ inputTransaction.setRequiresUpdateSuggestions();
+ }
}
/**
@@ -2085,9 +2076,7 @@ public final class InputLogic {
}
/**
- * Commits the chosen word to the text field and saves it for later retrieval. This is a
- * synonym of {@code commitChosenWordWithBackgroundColor(settingsValues, chosenWord,
- * commitType, separatorString, Color.TRANSPARENT}.
+ * Commits the chosen word to the text field and saves it for later retrieval.
*
* @param settingsValues the current values of the settings.
* @param chosenWord the word we want to commit.
@@ -2096,23 +2085,6 @@ public final class InputLogic {
*/
private void commitChosenWord(final SettingsValues settingsValues, final String chosenWord,
final int commitType, final String separatorString) {
- commitChosenWordWithBackgroundColor(settingsValues, chosenWord, commitType, separatorString,
- Color.TRANSPARENT);
- }
-
- /**
- * Commits the chosen word to the text field and saves it for later retrieval.
- *
- * @param settingsValues the current values of the settings.
- * @param chosenWord the word we want to commit.
- * @param commitType the type of the commit, as one of LastComposedWord.COMMIT_TYPE_*
- * @param separatorString the separator that's causing the commit, or NOT_A_SEPARATOR if none.
- * @param backgroundColor the background color to be specified with the committed text. Pass
- * {@link Color#TRANSPARENT} to not specify the background color.
- */
- private void commitChosenWordWithBackgroundColor(final SettingsValues settingsValues,
- final String chosenWord, final int commitType, final String separatorString,
- final int backgroundColor) {
final SuggestedWords suggestedWords = mSuggestedWords;
final CharSequence chosenWordWithSuggestions =
SuggestionSpanUtils.getTextWithSuggestionSpan(mLatinIME, chosenWord,
@@ -2122,7 +2094,7 @@ public final class InputLogic {
// information from the 1st previous word.
final PrevWordsInfo prevWordsInfo = mConnection.getPrevWordsInfoFromNthPreviousWord(
settingsValues.mSpacingAndPunctuations, mWordComposer.isComposingWord() ? 2 : 1);
- mConnection.commitTextWithBackgroundColor(chosenWordWithSuggestions, 1, backgroundColor);
+ mConnection.commitText(chosenWordWithSuggestions, 1);
// Add the word to the user history dictionary
performAdditionToUserHistoryDictionary(settingsValues, chosenWord, prevWordsInfo);
// TODO: figure out here if this is an auto-correct or if the best word is actually
@@ -2206,7 +2178,7 @@ public final class InputLogic {
private void setComposingTextInternal(final CharSequence newComposingText,
final int newCursorPosition) {
setComposingTextInternalWithBackgroundColor(newComposingText, newCursorPosition,
- Color.TRANSPARENT);
+ Color.TRANSPARENT, newComposingText.length());
}
/**
@@ -2222,9 +2194,11 @@ public final class InputLogic {
* @param newCursorPosition the new cursor position
* @param backgroundColor the background color to be set to the composing text. Set
* {@link Color#TRANSPARENT} to disable the background color.
+ * @param coloredTextLength the length of text, in Java chars, which should be rendered with
+ * the given background color.
*/
private void setComposingTextInternalWithBackgroundColor(final CharSequence newComposingText,
- final int newCursorPosition, final int backgroundColor) {
+ final int newCursorPosition, final int backgroundColor, final int coloredTextLength) {
final CharSequence composingTextToBeSet;
if (backgroundColor == Color.TRANSPARENT) {
composingTextToBeSet = newComposingText;
@@ -2232,7 +2206,8 @@ public final class InputLogic {
final SpannableString spannable = new SpannableString(newComposingText);
final BackgroundColorSpan backgroundColorSpan =
new BackgroundColorSpan(backgroundColor);
- spannable.setSpan(backgroundColorSpan, 0, spannable.length(),
+ final int spanLength = Math.min(coloredTextLength, spannable.length());
+ spannable.setSpan(backgroundColorSpan, 0, spanLength,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
composingTextToBeSet = spannable;
}
@@ -2254,7 +2229,8 @@ public final class InputLogic {
}
/**
- * Must be called from {@link InputMethodService#onUpdateCursorAnchorInfo} is called.
+ * Must be called from {@link InputMethodService#onUpdateCursorAnchorInfo(CursorAnchorInfo)} is
+ * called.
* @param info The wrapper object with which we can access cursor/anchor info.
*/
public void onUpdateCursorAnchorInfo(final CursorAnchorInfoCompatWrapper info) {
@@ -2278,12 +2254,12 @@ public final class InputLogic {
}
/**
- * Returns whether the commit indicator should be shown or not.
- * @param suggestedWords the suggested word that is being displayed.
+ * Returns whether the add to dictionary indicator should be shown or not.
+ * @param lastComposedWord the last composed word information.
* @param settingsValues the current settings value.
* @return {@code true} if the commit indicator should be shown.
*/
- private boolean shouldShowCommitIndicator(final SuggestedWords suggestedWords,
+ private boolean shouldShowAddToDictionaryForTypedWord(final LastComposedWord lastComposedWord,
final SettingsValues settingsValues) {
if (!mConnection.isCursorAnchorInfoMonitorEnabled()) {
// We cannot help in this case because we are heavily relying on this new API.
@@ -2292,24 +2268,16 @@ public final class InputLogic {
if (!settingsValues.mShouldShowUiToAcceptTypedWord) {
return false;
}
- final SuggestedWordInfo typedWordInfo = suggestedWords.getTypedWordInfoOrNull();
- if (typedWordInfo == null) {
+ if (TextUtils.isEmpty(lastComposedWord.mTypedWord)) {
return false;
}
- if (suggestedWords.mInputStyle != SuggestedWords.INPUT_STYLE_TYPING){
+ if (TextUtils.equals(lastComposedWord.mTypedWord, lastComposedWord.mCommittedWord)) {
return false;
}
- if (settingsValues.mShowCommitIndicatorOnlyForAutoCorrection
- && !suggestedWords.mWillAutoCorrect) {
+ if (!mDictionaryFacilitator.isUserDictionaryEnabled()) {
return false;
}
- // TODO: Calling shouldShowAddToDictionaryHint(typedWordInfo) multiple times should be fine
- // in terms of performance, but we can do better. One idea is to make SuggestedWords include
- // a boolean that tells whether the word is a dictionary word or not.
- if (settingsValues.mShowCommitIndicatorOnlyForOutOfVocabulary
- && !shouldShowAddToDictionaryHint(typedWordInfo)) {
- return false;
- }
- return true;
+ return !mDictionaryFacilitator.isValidWord(lastComposedWord.mTypedWord,
+ true /* ignoreCase */);
}
}
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 5c742a8b1..d8c548d8b 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -97,10 +97,7 @@ public final class SettingsValues {
new int[AdditionalFeaturesSettingUtils.ADDITIONAL_FEATURES_SETTINGS_SIZE];
// TextDecorator
- public final int mTextHighlightColorForCommitIndicator;
public final int mTextHighlightColorForAddToDictionaryIndicator;
- public final boolean mShowCommitIndicatorOnlyForAutoCorrection;
- public final boolean mShowCommitIndicatorOnlyForOutOfVocabulary;
// Debug settings
public final boolean mIsInternal;
@@ -175,12 +172,6 @@ public final class SettingsValues {
mSuggestionsEnabledPerUserSettings = readSuggestionsEnabled(prefs);
AdditionalFeaturesSettingUtils.readAdditionalFeaturesPreferencesIntoArray(
prefs, mAdditionalFeaturesSettingValues);
- mShowCommitIndicatorOnlyForAutoCorrection = res.getBoolean(
- R.bool.text_decorator_only_for_auto_correction);
- mShowCommitIndicatorOnlyForOutOfVocabulary = res.getBoolean(
- R.bool.text_decorator_only_for_out_of_vocabulary);
- mTextHighlightColorForCommitIndicator = res.getColor(
- R.color.text_decorator_commit_indicator_text_highlight_color);
mTextHighlightColorForAddToDictionaryIndicator = res.getColor(
R.color.text_decorator_add_to_dictionary_indicator_text_highlight_color);
mIsInternal = Settings.isInternal(prefs);
@@ -426,12 +417,6 @@ public final class SettingsValues {
sb.append("" + (null == awu ? "null" : awu.toString()));
sb.append("\n mAdditionalFeaturesSettingValues = ");
sb.append("" + Arrays.toString(mAdditionalFeaturesSettingValues));
- sb.append("\n mShowCommitIndicatorOnlyForAutoCorrection = ");
- sb.append("" + mShowCommitIndicatorOnlyForAutoCorrection);
- sb.append("\n mShowCommitIndicatorOnlyForOutOfVocabulary = ");
- sb.append("" + mShowCommitIndicatorOnlyForOutOfVocabulary);
- sb.append("\n mTextHighlightColorForCommitIndicator = ");
- sb.append("" + mTextHighlightColorForCommitIndicator);
sb.append("\n mTextHighlightColorForAddToDictionaryIndicator = ");
sb.append("" + mTextHighlightColorForAddToDictionaryIndicator);
sb.append("\n mIsInternal = ");
diff --git a/java/src/com/android/inputmethod/latin/utils/StringUtils.java b/java/src/com/android/inputmethod/latin/utils/StringUtils.java
index 38f0b3fee..1781924ac 100644
--- a/java/src/com/android/inputmethod/latin/utils/StringUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/StringUtils.java
@@ -37,6 +37,14 @@ public final class StringUtils {
private static final String EMPTY_STRING = "";
+ private static final char CHAR_LINE_FEED = 0X000A;
+ private static final char CHAR_VERTICAL_TAB = 0X000B;
+ private static final char CHAR_FORM_FEED = 0X000C;
+ private static final char CHAR_CARRIAGE_RETURN = 0X000D;
+ private static final char CHAR_NEXT_LINE = 0X0085;
+ private static final char CHAR_LINE_SEPARATOR = 0X2028;
+ private static final char CHAR_PARAGRAPH_SEPARATOR = 0X2029;
+
private StringUtils() {
// This utility class is not publicly instantiable.
}
@@ -594,4 +602,30 @@ public final class StringUtils {
return sb + "]";
}
}
+
+ /**
+ * Returns whether the last composed word contains line-breaking character (e.g. CR or LF).
+ * @param text the text to be examined.
+ * @return {@code true} if the last composed word contains line-breaking separator.
+ */
+ @UsedForTesting
+ public static boolean hasLineBreakCharacter(final String text) {
+ if (TextUtils.isEmpty(text)) {
+ return false;
+ }
+ for (int i = text.length() - 1; i >= 0; --i) {
+ final char c = text.charAt(i);
+ switch (c) {
+ case CHAR_LINE_FEED:
+ case CHAR_VERTICAL_TAB:
+ case CHAR_FORM_FEED:
+ case CHAR_CARRIAGE_RETURN:
+ case CHAR_NEXT_LINE:
+ case CHAR_LINE_SEPARATOR:
+ case CHAR_PARAGRAPH_SEPARATOR:
+ return true;
+ }
+ }
+ return false;
+ }
}