aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/inputlogic
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic')
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java56
1 files changed, 44 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 348bae63a..616828efe 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.latin.inputlogic;
+import android.graphics.Color;
import android.os.SystemClock;
import android.text.SpannableString;
import android.text.TextUtils;
@@ -232,6 +233,20 @@ public final class InputLogic {
}
/**
+ * Determines whether "Touch again to save" should be shown or not.
+ * @param suggestionInfo the suggested word chosen by the user.
+ * @return {@code true} if we should show the "Touch again to save" hint.
+ */
+ private boolean shouldShowAddToDictionaryHint(final SuggestedWordInfo suggestionInfo) {
+ // We should show the "Touch again to save" hint if the user pressed the first entry
+ // AND it's in none of our current dictionaries (main, user or otherwise).
+ return (suggestionInfo.isKindOf(SuggestedWordInfo.KIND_TYPED)
+ || suggestionInfo.isKindOf(SuggestedWordInfo.KIND_OOV_CORRECTION))
+ && !mDictionaryFacilitator.isValidWord(suggestionInfo.mWord, true /* ignoreCase */)
+ && mDictionaryFacilitator.isUserDictionaryEnabled();
+ }
+
+ /**
* A suggestion was picked from the suggestion strip.
* @param settingsValues the current values of the settings.
* @param suggestionInfo the suggestion info.
@@ -297,14 +312,7 @@ public final class InputLogic {
mSpaceState = SpaceState.PHANTOM;
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
- // We should show the "Touch again to save" hint if the user pressed the first entry
- // AND it's in none of our current dictionaries (main, user or otherwise).
- final boolean showingAddToDictionaryHint =
- (suggestionInfo.isKindOf(SuggestedWordInfo.KIND_TYPED)
- || suggestionInfo.isKindOf(SuggestedWordInfo.KIND_OOV_CORRECTION))
- && !mDictionaryFacilitator.isValidWord(suggestion, true /* ignoreCase */);
-
- if (showingAddToDictionaryHint && mDictionaryFacilitator.isUserDictionaryEnabled()) {
+ if (shouldShowAddToDictionaryHint(suggestionInfo)) {
mSuggestionStripViewAccessor.showAddToDictionaryHint(suggestion);
} else {
// If we're not showing the "Touch again to save", then update the suggestion strip.
@@ -743,6 +751,13 @@ 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();
+ }
+
final int codePoint = event.mCodePoint;
mSpaceState = SpaceState.NONE;
if (inputTransaction.mSettingsValues.isWordSeparator(codePoint)
@@ -838,8 +853,6 @@ public final class InputLogic {
} else {
sendKeyCodePoint(settingsValues, codePoint);
}
- // In case the "add to dictionary" hint was still displayed.
- mSuggestionStripViewAccessor.dismissAddToDictionaryHint();
}
inputTransaction.setRequiresUpdateSuggestions();
}
@@ -1994,7 +2007,9 @@ public final class InputLogic {
}
/**
- * 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. This is a
+ * synonym of {@code commitChosenWordWithBackgroundColor(settingsValues, chosenWord,
+ * commitType, separatorString, Color.TRANSPARENT}.
*
* @param settingsValues the current values of the settings.
* @param chosenWord the word we want to commit.
@@ -2003,6 +2018,23 @@ 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,
@@ -2012,7 +2044,7 @@ public final class InputLogic {
// information from the 1st previous word.
final PrevWordsInfo prevWordsInfo = mConnection.getPrevWordsInfoFromNthPreviousWord(
settingsValues.mSpacingAndPunctuations, mWordComposer.isComposingWord() ? 2 : 1);
- mConnection.commitText(chosenWordWithSuggestions, 1);
+ mConnection.commitTextWithBackgroundColor(chosenWordWithSuggestions, 1, backgroundColor);
// 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