diff options
Diffstat (limited to 'java')
24 files changed, 212 insertions, 218 deletions
diff --git a/java/res/xml-sw600dp/key_comma.xml b/java/res/xml-sw600dp/key_comma.xml index 67199e237..e616a8d70 100644 --- a/java/res/xml-sw600dp/key_comma.xml +++ b/java/res/xml-sw600dp/key_comma.xml @@ -2,7 +2,7 @@ <!-- /* ** -** Copyright 2014, The Android Open Source Project +** Copyright 2012, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. @@ -21,27 +21,36 @@ <merge xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" > - <!-- The table comma key which may have settings as popup key. --> - <!-- Kept as a separate file for cleaner overriding by an overlay. --> - <key-style - latin:styleName="baseTabletCommaKeyStyle" - latin:keySpec="!text/keyspec_tablet_comma" - latin:keyHintLabel="!text/keyhintlabel_tablet_comma" - latin:keyLabelFlags="hasPopupHint" - latin:parentStyle="hasShiftedLetterHintStyle" /> <switch> <case - latin:clobberSettingsKey="true" + latin:mode="url" > <Key - latin:moreKeys="!text/morekeys_tablet_comma" - latin:keyStyle="baseTabletCommaKeyStyle" /> + latin:keySpec="/" + latin:keyStyle="settingsMoreKeysStyle" /> + </case> + <case + latin:mode="email" + > + <Key + latin:keySpec="\@" + latin:keyStyle="settingsMoreKeysStyle" /> + </case> + <case + latin:keyboardLayoutSet="dvorak" + > + <Key + latin:keySpec="!" + latin:moreKeys="!text/morekeys_exclamation,%" + latin:keyStyle="settingsMoreKeysStyle" /> </case> - <!-- clobberSettingsKey="false" --> <default> <Key - latin:moreKeys="!text/morekeys_tablet_comma,!text/keyspec_settings" - latin:keyStyle="baseTabletCommaKeyStyle" /> + latin:keySpec="!text/keyspec_tablet_comma" + latin:moreKeys="!text/morekeys_tablet_comma,%" + latin:keyHintLabel="!text/keyhintlabel_tablet_comma" + latin:keyLabelFlags="hasPopupHint" + latin:keyStyle="settingsMoreKeysStyle" /> </default> </switch> </merge> diff --git a/java/res/xml-sw600dp/key_f1.xml b/java/res/xml-sw600dp/key_f1.xml deleted file mode 100644 index ba78a6430..000000000 --- a/java/res/xml-sw600dp/key_f1.xml +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -/* -** -** Copyright 2012, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ ---> - -<merge - xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" -> - <switch> - <case - latin:mode="email" - > - <Key - latin:keySpec="\@" /> - </case> - <default> - <Key - latin:keySpec="/" /> - </default> - </switch> -</merge> diff --git a/java/res/xml-sw600dp/key_period.xml b/java/res/xml-sw600dp/key_period.xml index d2909d82d..df1daf792 100644 --- a/java/res/xml-sw600dp/key_period.xml +++ b/java/res/xml-sw600dp/key_period.xml @@ -35,6 +35,13 @@ latin:moreKeys="!autoColumnOrder!8,\\,,.,',#,),(,/,;,@,:,-,",+,\\%,&" latin:backgroundType="functional" /> </case> + <case + latin:keyboardLayoutSet="dvorak" + > + <Key + latin:keySpec="\?" + latin:moreKeys="!text/morekeys_tablet_period,!text/morekeys_question" /> + </case> <default> <Key latin:keySpec="!text/keyspec_tablet_period" diff --git a/java/res/xml-sw600dp/key_question_exclamation.xml b/java/res/xml-sw600dp/key_question_exclamation.xml deleted file mode 100644 index edee5c5dd..000000000 --- a/java/res/xml-sw600dp/key_question_exclamation.xml +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -/* -** -** Copyright 2012, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ ---> - -<merge - xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" -> - <switch> - <case - latin:mode="email|url" - > - <Key - latin:keySpec="-" /> - </case> - <default> - <Key - latin:keySpec="\?" - latin:keyHintLabel="!" - latin:moreKeys="!" - latin:keyStyle="hasShiftedLetterHintStyle" /> - </default> - </switch> -</merge> diff --git a/java/res/xml-sw600dp/key_space_5kw.xml b/java/res/xml-sw600dp/key_space_7kw.xml index 8302184c7..3311f812a 100644 --- a/java/res/xml-sw600dp/key_space_5kw.xml +++ b/java/res/xml-sw600dp/key_space_7kw.xml @@ -34,7 +34,7 @@ latin:keyStyle="languageSwitchKeyStyle" /> <Key latin:keyStyle="spaceKeyStyle" - latin:keyWidth="27.0%p" /> + latin:keyWidth="45.0%p" /> <Key latin:keyStyle="zwnjKeyStyle" /> </case> @@ -44,7 +44,7 @@ > <Key latin:keyStyle="spaceKeyStyle" - latin:keyWidth="36.0%p" /> + latin:keyWidth="54.0%p" /> <Key latin:keyStyle="zwnjKeyStyle" /> </case> @@ -55,13 +55,13 @@ latin:keyStyle="languageSwitchKeyStyle" /> <Key latin:keyStyle="spaceKeyStyle" - latin:keyWidth="36.0%p" /> + latin:keyWidth="54.0%p" /> </case> <!-- languageSwitchKeyEnabled="false" --> <default> <Key latin:keyStyle="spaceKeyStyle" - latin:keyWidth="45.0%p" /> + latin:keyWidth="63.0%p" /> </default> </switch> </merge> diff --git a/java/res/xml-sw600dp/key_styles_common.xml b/java/res/xml-sw600dp/key_styles_common.xml index 1b52b1efd..c750a9319 100644 --- a/java/res/xml-sw600dp/key_styles_common.xml +++ b/java/res/xml-sw600dp/key_styles_common.xml @@ -36,6 +36,9 @@ </default> </switch> <!-- Base key style for the key which may have settings key as more keys. --> + <key-style + latin:styleName="baseSettingsMoreKeysStyle" + latin:parentStyle="hasShiftedLetterHintStyle" /> <include latin:keyboardLayout="@xml/key_styles_settings" /> <!-- Functional key styles --> diff --git a/java/res/xml-sw600dp/row_dvorak4.xml b/java/res/xml-sw600dp/row_dvorak4.xml deleted file mode 100644 index ab2b5603d..000000000 --- a/java/res/xml-sw600dp/row_dvorak4.xml +++ /dev/null @@ -1,49 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -/* -** -** Copyright 2012, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ ---> - -<merge - xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" -> - <Row - latin:keyWidth="9.0%p" - latin:backgroundType="functional" - > - <Key - latin:keyStyle="toSymbolKeyStyle" - latin:keyWidth="10.0%p" /> - <include - latin:keyboardLayout="@xml/key_settings" /> - <Key - latin:keySpec="_" - latin:keyHintLabel="-" - latin:moreKeys="-" - latin:keyStyle="hasShiftedLetterHintStyle" /> - <include - latin:keyXPos="28.0%p" - latin:keyboardLayout="@xml/key_space_5kw" - latin:backgroundType="normal" /> - <include - latin:keyboardLayout="@xml/key_f1" /> - <include - latin:keyboardLayout="@xml/key_question_exclamation" /> - <include - latin:keyboardLayout="@xml/key_f2" /> - </Row> -</merge> diff --git a/java/res/xml-sw600dp/row_pcqwerty5.xml b/java/res/xml-sw600dp/row_pcqwerty5.xml index ac07f11c2..4dcae1455 100644 --- a/java/res/xml-sw600dp/row_pcqwerty5.xml +++ b/java/res/xml-sw600dp/row_pcqwerty5.xml @@ -50,6 +50,6 @@ latin:keyXPos="-9.0%p" latin:keyWidth="9.0%p" latin:backgroundType="functional" - latin:keyboardLayout="@xml/key_f2" /> + latin:keyboardLayout="@xml/key_emoji" /> </Row> </merge> diff --git a/java/res/xml-sw600dp/row_qwerty4.xml b/java/res/xml-sw600dp/row_qwerty4.xml index 0eb86f2d4..ed7150de4 100644 --- a/java/res/xml-sw600dp/row_qwerty4.xml +++ b/java/res/xml-sw600dp/row_qwerty4.xml @@ -30,18 +30,14 @@ latin:keyWidth="10.0%p" /> <include latin:keyboardLayout="@xml/key_comma" /> - <Key - latin:keySpec="_" /> <!-- Space key. --> <include - latin:keyXPos="28.0%p" - latin:keyboardLayout="@xml/key_space_5kw" + latin:keyXPos="19.0%p" + latin:keyboardLayout="@xml/key_space_7kw" latin:backgroundType="normal" /> <include - latin:keyboardLayout="@xml/key_f1" /> - <include latin:keyboardLayout="@xml/key_period" /> <include - latin:keyboardLayout="@xml/key_f2" /> + latin:keyboardLayout="@xml/key_emoji" /> </Row> </merge> diff --git a/java/res/xml-sw600dp/rows_dvorak.xml b/java/res/xml-sw600dp/rows_dvorak.xml index 88592676d..c8f5e3aa2 100644 --- a/java/res/xml-sw600dp/rows_dvorak.xml +++ b/java/res/xml-sw600dp/rows_dvorak.xml @@ -53,6 +53,8 @@ latin:keyStyle="shiftKeyStyle" latin:keyWidth="fillRight" /> </Row> + <!-- Dvorak layout shares almost the same row with Qwerty layout. + The difference is defined in xml-sw600dp/row_qwerty4.xml. --> <include - latin:keyboardLayout="@xml/row_dvorak4" /> + latin:keyboardLayout="@xml/row_qwerty4" /> </merge> diff --git a/java/res/xml-sw600dp/rows_symbols.xml b/java/res/xml-sw600dp/rows_symbols.xml index a915c3351..05e7c685e 100644 --- a/java/res/xml-sw600dp/rows_symbols.xml +++ b/java/res/xml-sw600dp/rows_symbols.xml @@ -70,6 +70,6 @@ <include latin:keyboardLayout="@xml/row_symbols4" /> <include - latin:keyboardLayout="@xml/key_f2" /> + latin:keyboardLayout="@xml/key_emoji" /> </Row> </merge> diff --git a/java/res/xml-sw600dp/rows_symbols_shift.xml b/java/res/xml-sw600dp/rows_symbols_shift.xml index 7ead4d5b1..70ac42eb9 100644 --- a/java/res/xml-sw600dp/rows_symbols_shift.xml +++ b/java/res/xml-sw600dp/rows_symbols_shift.xml @@ -72,6 +72,6 @@ <include latin:keyboardLayout="@xml/row_symbols_shift4" /> <include - latin:keyboardLayout="@xml/key_f2" /> + latin:keyboardLayout="@xml/key_emoji" /> </Row> </merge> diff --git a/java/res/xml/key_f1.xml b/java/res/xml/key_comma.xml index 7bd7385a1..cf919a85d 100644 --- a/java/res/xml/key_f1.xml +++ b/java/res/xml/key_comma.xml @@ -23,6 +23,15 @@ > <switch> <case + latin:keyboardLayoutSet="dvorak" + > + <Key + latin:keySpec="q" + latin:moreKeys="!text/morekeys_q,%" + latin:backgroundType="normal" + latin:keyStyle="settingsMoreKeysStyle" /> + </case> + <case latin:mode="url" > <Key diff --git a/java/res/xml/key_f2.xml b/java/res/xml/key_emoji.xml index 473dd210a..473dd210a 100644 --- a/java/res/xml/key_f2.xml +++ b/java/res/xml/key_emoji.xml diff --git a/java/res/xml/key_period.xml b/java/res/xml/key_period.xml index e1d4bbdf7..fc27c0235 100644 --- a/java/res/xml/key_period.xml +++ b/java/res/xml/key_period.xml @@ -48,6 +48,14 @@ latin:moreKeys="!text/morekeys_punctuation" latin:backgroundType="functional" /> </case> + <case + latin:keyboardLayoutSet="dvorak" + > + <Key + latin:keySpec="z" + latin:keyLabelFlags="hasPopupHint" + latin:moreKeys="!text/morekeys_punctuation,!text/morekeys_z" /> + </case> <default> <Key latin:keySpec="!text/keyspec_period" diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml index 2d006c992..167e6f88d 100644 --- a/java/res/xml/key_styles_common.xml +++ b/java/res/xml/key_styles_common.xml @@ -36,6 +36,8 @@ </default> </switch> <!-- Base key style for the key which may have settings key as more keys. --> + <key-style + latin:styleName="baseSettingsMoreKeysStyle" /> <include latin:keyboardLayout="@xml/key_styles_settings" /> <!-- Functional key styles --> diff --git a/java/res/xml/key_styles_settings.xml b/java/res/xml/key_styles_settings.xml index 956b40235..a504bed78 100644 --- a/java/res/xml/key_styles_settings.xml +++ b/java/res/xml/key_styles_settings.xml @@ -29,15 +29,17 @@ > <key-style latin:styleName="settingsMoreKeysStyle" - latin:backgroundType="functional" /> + latin:backgroundType="functional" + latin:parentStyle="baseSettingsMoreKeysStyle" /> </case> <!-- clobberSettingsKey="false" --> <default> <key-style latin:styleName="settingsMoreKeysStyle" latin:keyLabelFlags="hasPopupHint" - latin:moreKeys="!text/keyspec_settings" - latin:backgroundType="functional" /> + latin:additionalMoreKeys="!text/keyspec_settings" + latin:backgroundType="functional" + latin:parentStyle="baseSettingsMoreKeysStyle" /> </default> </switch> </merge> diff --git a/java/res/xml/row_dvorak4.xml b/java/res/xml/row_dvorak4.xml deleted file mode 100644 index e7a3ee736..000000000 --- a/java/res/xml/row_dvorak4.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -/* -** -** Copyright 2012, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ ---> - -<merge - xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" -> - <Row - latin:keyWidth="10%p" - > - <Key - latin:keyStyle="toSymbolKeyStyle" - latin:keyWidth="15%p" /> - <Key - latin:keySpec="q" - latin:backgroundType="normal" - latin:keyStyle="settingsMoreKeysStyle" /> - <include - latin:keyXPos="25%p" - latin:keyboardLayout="@xml/key_space_5kw" /> - <Key - latin:keySpec="z" - latin:keyLabelFlags="hasPopupHint" - latin:moreKeys="!text/morekeys_punctuation,!text/morekeys_z" /> - <Key - latin:keyStyle="enterKeyStyle" - latin:keyWidth="fillRight" /> - </Row> -</merge> diff --git a/java/res/xml/row_qwerty4.xml b/java/res/xml/row_qwerty4.xml index 509092d96..5bc104f69 100644 --- a/java/res/xml/row_qwerty4.xml +++ b/java/res/xml/row_qwerty4.xml @@ -28,7 +28,7 @@ latin:keyStyle="toSymbolKeyStyle" latin:keyWidth="15%p" /> <include - latin:keyboardLayout="@xml/key_f1" /> + latin:keyboardLayout="@xml/key_comma" /> <include latin:keyXPos="25%p" latin:keyboardLayout="@xml/key_space_5kw" /> diff --git a/java/res/xml/rows_dvorak.xml b/java/res/xml/rows_dvorak.xml index 13d70210d..f656613ec 100644 --- a/java/res/xml/rows_dvorak.xml +++ b/java/res/xml/rows_dvorak.xml @@ -49,6 +49,8 @@ latin:keyWidth="fillRight" latin:visualInsetsLeft="1%p" /> </Row> + <!-- Dvorak layout shares almost the same row with Qwerty layout. + The difference is defined in xml/row_qwerty4.xml. --> <include - latin:keyboardLayout="@xml/row_dvorak4" /> + latin:keyboardLayout="@xml/row_qwerty4" /> </merge> diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 140e76879..77cdf49fb 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -261,6 +261,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { } public void onToggleEmojiKeyboard() { + if (mKeyboardLayoutSet == null) { + return; + } if (isShowingEmojiPalettes()) { setAlphabetKeyboard(); } else { diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java index ea63cef02..035557610 100644 --- a/java/src/com/android/inputmethod/latin/RichInputConnection.java +++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java @@ -16,9 +16,13 @@ package com.android.inputmethod.latin; +import android.graphics.Color; import android.inputmethodservice.InputMethodService; import android.os.Build; +import android.text.SpannableStringBuilder; +import android.text.Spanned; import android.text.TextUtils; +import android.text.style.BackgroundColorSpan; import android.util.Log; import android.view.KeyEvent; import android.view.inputmethod.CompletionInfo; @@ -81,6 +85,18 @@ public final class RichInputConnection { */ private final StringBuilder mComposingText = new StringBuilder(); + /** + * This variable is a temporary object used in + * {@link #commitTextWithBackgroundColor(CharSequence, int, int)} to avoid object creation. + */ + private SpannableStringBuilder mTempObjectForCommitText = new SpannableStringBuilder(); + /** + * This variable is used to track whether the last committed text had the background color or + * not. + * TODO: Omit this flag if possible. + */ + private boolean mLastCommittedTextHasBackgroundColor = false; + private final InputMethodService mParent; InputConnection mIC; int mNestLevel; @@ -219,12 +235,37 @@ public final class RichInputConnection { // it works, but it's wrong and should be fixed. mCommittedTextBeforeComposingText.append(mComposingText); mComposingText.setLength(0); + // TODO: Clear this flag in setComposingRegion() and setComposingText() as well if needed. + mLastCommittedTextHasBackgroundColor = false; if (null != mIC) { mIC.finishComposingText(); } } - public void commitText(final CharSequence text, final int i) { + /** + * Synonym of {@code commitTextWithBackgroundColor(text, newCursorPosition, Color.TRANSPARENT}. + * @param text The text to commit. This may include styles. + * See {@link InputConnection#commitText(CharSequence, int)}. + * @param newCursorPosition The new cursor position around the text. + * See {@link InputConnection#commitText(CharSequence, int)}. + */ + public void commitText(final CharSequence text, final int newCursorPosition) { + commitTextWithBackgroundColor(text, newCursorPosition, Color.TRANSPARENT); + } + + /** + * Calls {@link InputConnection#commitText(CharSequence, int)} with the given background color. + * @param text The text to commit. This may include styles. + * See {@link InputConnection#commitText(CharSequence, int)}. + * @param newCursorPosition The new cursor position around the text. + * See {@link InputConnection#commitText(CharSequence, int)}. + * @param color The background color to be attached. Set {@link Color#TRANSPARENT} to disable + * 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. + */ + public void commitTextWithBackgroundColor(final CharSequence text, final int newCursorPosition, + final int color) { if (DEBUG_BATCH_NESTING) checkBatchEdit(); if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug(); mCommittedTextBeforeComposingText.append(text); @@ -234,11 +275,43 @@ public final class RichInputConnection { mExpectedSelStart += text.length() - mComposingText.length(); mExpectedSelEnd = mExpectedSelStart; mComposingText.setLength(0); + mLastCommittedTextHasBackgroundColor = false; if (null != mIC) { - mIC.commitText(text, i); + if (color == Color.TRANSPARENT) { + mIC.commitText(text, newCursorPosition); + } else { + mTempObjectForCommitText.clear(); + mTempObjectForCommitText.append(text); + final BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(color); + mTempObjectForCommitText.setSpan(backgroundColorSpan, 0, text.length(), + Spanned.SPAN_COMPOSING | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + mIC.commitText(mTempObjectForCommitText, newCursorPosition); + mLastCommittedTextHasBackgroundColor = true; + } } } + /** + * Removes the background color from the highlighted text if necessary. Should be called while + * there is no on-going composing text. + * + * <p>CAVEAT: This method internally calls {@link InputConnection#finishComposingText()}. + * Be careful of any unexpected side effects.</p> + */ + public void removeBackgroundColorFromHighlightedTextIfNecessary() { + // TODO: We haven't yet full tested if we really need to check this flag or not. Omit this + // flag if everything works fine without this condition. + if (!mLastCommittedTextHasBackgroundColor) { + return; + } + if (mComposingText.length() > 0) { + Log.e(TAG, "clearSpansWithComposingFlags should be called when composing text is " + + "empty. mComposingText=" + mComposingText); + return; + } + finishComposingText(); + } + public CharSequence getSelectedText(final int flags) { return (null == mIC) ? null : mIC.getSelectedText(flags); } diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index d7693af41..38fcb683d 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -19,6 +19,7 @@ package com.android.inputmethod.latin; import android.text.TextUtils; import android.view.inputmethod.CompletionInfo; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.define.DebugFlags; import com.android.inputmethod.latin.utils.StringUtils; @@ -420,4 +421,18 @@ public class SuggestedWords { mWillAutoCorrect, mIsObsoleteSuggestions, mIsPrediction, INPUT_STYLE_TAIL_BATCH); } + + /** + * @return the {@link SuggestedWordInfo} which corresponds to the word that is originally + * typed by the user. Otherwise returns {@code null}. Note that gesture input is not + * considered to be a typed word. + */ + @UsedForTesting + public SuggestedWordInfo getTypedWordInfoOrNull() { + if (this == EMPTY) { + return null; + } + final SuggestedWordInfo info = getInfo(SuggestedWords.INDEX_OF_TYPED_WORD); + return (info.getKind() == SuggestedWordInfo.KIND_TYPED) ? info : null; + } } 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 |