diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 84 |
1 files changed, 54 insertions, 30 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index e1d809907..87b34a99c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -51,6 +51,7 @@ import android.view.WindowManager; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CursorAnchorInfo; import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethod; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.accessibility.AccessibilityUtils; @@ -192,8 +193,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private static final int ARG1_FALSE = 0; private static final int ARG1_TRUE = 1; - private int mDelayUpdateSuggestions; - private int mDelayUpdateShiftState; + private int mDelayInMillisecondsToUpdateSuggestions; + private int mDelayInMillisecondsToUpdateShiftState; public UIHandler(final LatinIME ownerInstance) { super(ownerInstance); @@ -205,8 +206,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return; } final Resources res = latinIme.getResources(); - mDelayUpdateSuggestions = res.getInteger(R.integer.config_delay_update_suggestions); - mDelayUpdateShiftState = res.getInteger(R.integer.config_delay_update_shift_state); + mDelayInMillisecondsToUpdateSuggestions = + res.getInteger(R.integer.config_delay_in_milliseconds_to_update_suggestions); + mDelayInMillisecondsToUpdateShiftState = + res.getInteger(R.integer.config_delay_in_milliseconds_to_update_shift_state); } @Override @@ -272,7 +275,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void postUpdateSuggestionStrip(final int inputStyle) { sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTION_STRIP, inputStyle, - 0 /* ignored */), mDelayUpdateSuggestions); + 0 /* ignored */), mDelayInMillisecondsToUpdateSuggestions); } public void postReopenDictionaries() { @@ -285,16 +288,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (latinIme == null) { return; } - if (!latinIme.mSettings.getCurrent() - .isSuggestionsEnabledPerUserSettings()) { + if (!latinIme.mSettings.getCurrent().isSuggestionsEnabledPerUserSettings()) { return; } removeMessages(MSG_RESUME_SUGGESTIONS); if (shouldDelay) { sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS, - shouldIncludeResumedWordInSuggestions ? ARG1_TRUE : ARG1_FALSE, - 0 /* ignored */), - mDelayUpdateSuggestions); + shouldIncludeResumedWordInSuggestions ? ARG1_TRUE : ARG1_FALSE, + 0 /* ignored */), mDelayInMillisecondsToUpdateSuggestions); } else { sendMessage(obtainMessage(MSG_RESUME_SUGGESTIONS, shouldIncludeResumedWordInSuggestions ? ARG1_TRUE : ARG1_FALSE, @@ -335,7 +336,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void postUpdateShiftState() { removeMessages(MSG_UPDATE_SHIFT_STATE); - sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), mDelayUpdateShiftState); + sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), + mDelayInMillisecondsToUpdateShiftState); } @UsedForTesting @@ -747,7 +749,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void onCurrentInputMethodSubtypeChanged(final InputMethodSubtype subtype) { // Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged() // is not guaranteed. It may even be called at the same time on a different thread. - mSubtypeSwitcher.onSubtypeChanged(subtype); + final RichInputMethodSubtype richSubtype = new RichInputMethodSubtype(subtype); + mSubtypeSwitcher.onSubtypeChanged(richSubtype); mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype)); loadKeyboard(); } @@ -1138,6 +1141,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } @Override + public boolean onShowInputRequested(final int flags, final boolean configChange) { + if ((flags & InputMethod.SHOW_EXPLICIT) == 0 && mKeyboardSwitcher.hasHardwareKeyboard()) { + // Even when IME is implicitly shown and physical keyboard is connected, we should + // show {@link InputView}. + // See {@link InputMethodService#onShowInputRequested(int,boolean)}. + return true; + } + return super.onShowInputRequested(flags, configChange); + } + + @Override public boolean onEvaluateFullscreenMode() { if (mKeyboardSwitcher.hasHardwareKeyboard()) { // If there is a hardware keyboard, disable full screen mode. @@ -1258,10 +1272,26 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSubtypeState.switchSubtype(token, mRichImm); } + // TODO: Instead of checking for alphabetic keyboard here, separate keycodes for + // alphabetic shift and shift while in symbol layout and get rid of this method. + private int getCodePointForKeyboard(final int codePoint) { + if (Constants.CODE_SHIFT == codePoint) { + final Keyboard currentKeyboard = mKeyboardSwitcher.getKeyboard(); + if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) { + return codePoint; + } else { + return Constants.CODE_SYMBOL_SHIFT; + } + } else { + return codePoint; + } + } + // Implementation of {@link KeyboardActionListener}. @Override public void onCodeInput(final int codePoint, final int x, final int y, final boolean isKeyRepeat) { + // TODO: this processing does not belong inside LatinIME, the caller should be doing this. final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); // x and y include some padding, but everything down the line (especially native // code) needs the coordinates in the keyboard frame. @@ -1270,36 +1300,30 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // this transformation, it should be done already before calling onCodeInput. final int keyX = mainKeyboardView.getKeyX(x); final int keyY = mainKeyboardView.getKeyY(y); - final int codeToSend; - if (Constants.CODE_SHIFT == codePoint) { - // TODO: Instead of checking for alphabetic keyboard here, separate keycodes for - // alphabetic shift and shift while in symbol layout. - final Keyboard currentKeyboard = mKeyboardSwitcher.getKeyboard(); - if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) { - codeToSend = codePoint; - } else { - codeToSend = Constants.CODE_SYMBOL_SHIFT; - } - } else { - codeToSend = codePoint; - } - if (Constants.CODE_SHORTCUT == codePoint) { + final Event event = createSoftwareKeypressEvent(getCodePointForKeyboard(codePoint), + keyX, keyY, isKeyRepeat); + onEvent(event); + } + + // This method is public for testability of LatinIME, but also in the future it should + // completely replace #onCodeInput. + public void onEvent(final Event event) { + if (Constants.CODE_SHORTCUT == event.mCodePoint) { mSubtypeSwitcher.switchToShortcutIME(this); - // Still call the *#onCodeInput methods for readability. } - final Event event = createSoftwareKeypressEvent(codeToSend, keyX, keyY, isKeyRepeat); final InputTransaction completeInputTransaction = mInputLogic.onCodeInput(mSettings.getCurrent(), event, mKeyboardSwitcher.getKeyboardShiftMode(), mKeyboardSwitcher.getCurrentKeyboardScriptId(), mHandler); updateStateAfterInputTransaction(completeInputTransaction); - mKeyboardSwitcher.onCodeInput(codePoint, getCurrentAutoCapsState(), + mKeyboardSwitcher.onCodeInput(event.mCodePoint, getCurrentAutoCapsState(), getCurrentRecapitalizeState()); } // A helper method to split the code point and the key code. Ultimately, they should not be // squashed into the same variable, and this method should be removed. - private static Event createSoftwareKeypressEvent(final int keyCodeOrCodePoint, final int keyX, + // public for testing, as we don't want to copy the same logic into test code + public static Event createSoftwareKeypressEvent(final int keyCodeOrCodePoint, final int keyX, final int keyY, final boolean isKeyRepeat) { final int keyCode; final int codePoint; |