aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2014-08-24 17:41:49 -0700
committerYohei Yukawa <yukawa@google.com>2014-08-24 20:28:24 -0700
commit4a71d2c48021351e10bd61d5ee007533651da627 (patch)
tree6f85396f926b5fa5b8712ff7dadfbb4b435e2ea0 /java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
parentcd6ef9a8b117b82623251510fac72ee108ec1a2a (diff)
downloadlatinime-4a71d2c48021351e10bd61d5ee007533651da627.tar.gz
latinime-4a71d2c48021351e10bd61d5ee007533651da627.tar.xz
latinime-4a71d2c48021351e10bd61d5ee007533651da627.zip
Allow to add/remove background color to/from the committed text
This is a groundwork for subsequent CLs where we need to add/remove background color to/from the commited text. In this CL, we use Spanned#SPAN_COMPOSING so that we can easily remove such a background color by calling InputConnection#finishComposingText. To make this operation easy and realiable, we need to track whether we have specified the background color to the commited text or not at one place. Here we use RichInputConnection for this purpose. Change-Id: I5f9bc4425c5d1b80a719a20e5baf336729ec08d2
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java')
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java24
1 files changed, 22 insertions, 2 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..6fce2497e 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;
@@ -1994,7 +1995,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 +2006,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 +2032,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