aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2014-08-27 09:18:50 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-08-27 09:18:50 +0000
commitc925ca43a6e0b3175feb002ce6b5577ef7d66507 (patch)
treee3d4ea06bcda2665dbe4f276306cdc8e12f7a594 /java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
parent8159336ba1d247134cd600465c474842b32a7b91 (diff)
parent97681ebdf16dd94b7ed0607342cc2750fb96a641 (diff)
downloadlatinime-c925ca43a6e0b3175feb002ce6b5577ef7d66507.tar.gz
latinime-c925ca43a6e0b3175feb002ce6b5577ef7d66507.tar.xz
latinime-c925ca43a6e0b3175feb002ce6b5577ef7d66507.zip
am 97681ebd: Set highlight color along with the commit indicator
* commit '97681ebdf16dd94b7ed0607342cc2750fb96a641': Set highlight color along with the commit indicator
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java')
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java41
1 files changed, 39 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 de62f9786..e35fed9c8 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -20,7 +20,9 @@ import android.graphics.Color;
import android.inputmethodservice.InputMethodService;
import android.os.SystemClock;
import android.text.SpannableString;
+import android.text.Spanned;
import android.text.TextUtils;
+import android.text.style.BackgroundColorSpan;
import android.text.style.SuggestionSpan;
import android.util.Log;
import android.view.KeyCharacterMap;
@@ -620,6 +622,7 @@ public final class InputLogic {
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
@@ -641,6 +644,10 @@ public final class InputLogic {
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);
}
});
@@ -2199,8 +2206,38 @@ public final class InputLogic {
*/
private void setComposingTextInternal(final CharSequence newComposingText,
final int newCursorPosition) {
- mConnection.setComposingText(newComposingText, newCursorPosition);
- mTextDecorator.hideIndicatorIfNecessary(newComposingText);
+ setComposingTextInternalWithBackgroundColor(newComposingText, newCursorPosition,
+ Color.TRANSPARENT);
+ }
+
+ /**
+ * Equivalent to {@link #setComposingTextInternal(CharSequence, int)} except that this method
+ * allows to set {@link BackgroundColorSpan} to the composing text with the given color.
+ *
+ * <p>TODO: Currently the background color is exclusive with the black underline, which is
+ * automatically added by the framework. We need to change the framework if we need to have both
+ * of them at the same time.</p>
+ * <p>TODO: Should we move this method to {@link RichInputConnection}?</p>
+ *
+ * @param newComposingText the composing text to be set
+ * @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.
+ */
+ private void setComposingTextInternalWithBackgroundColor(final CharSequence newComposingText,
+ final int newCursorPosition, final int backgroundColor) {
+ final CharSequence composingTextToBeSet;
+ if (backgroundColor == Color.TRANSPARENT) {
+ composingTextToBeSet = newComposingText;
+ } else {
+ final SpannableString spannable = new SpannableString(newComposingText);
+ final BackgroundColorSpan backgroundColorSpan =
+ new BackgroundColorSpan(backgroundColor);
+ spannable.setSpan(backgroundColorSpan, 0, spannable.length(),
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
+ composingTextToBeSet = spannable;
+ }
+ mConnection.setComposingText(composingTextToBeSet, newCursorPosition);
}
//////////////////////////////////////////////////////////////////////////////////////////////