diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 82 |
1 files changed, 68 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 2e3cd6b6f..71fd10e83 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -49,11 +49,13 @@ import android.view.ViewGroup.LayoutParams; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.CompletionInfo; +import android.view.inputmethod.CursorAnchorInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.annotations.UsedForTesting; +import com.android.inputmethod.compat.CursorAnchorInfoCompatWrapper; import com.android.inputmethod.compat.InputConnectionCompatUtils; import com.android.inputmethod.compat.InputMethodServiceCompatUtils; import com.android.inputmethod.dictionarypack.DictionaryPackConstants; @@ -136,7 +138,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen new Runnable() { @Override public void run() { - mHandler.postUpdateSuggestionStrip(); + mHandler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_NONE); } }); private final InputLogic mInputLogic = new InputLogic(this /* LatinIME */, @@ -145,6 +147,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // If it turns out we need several, it will get grown seamlessly. final SparseArray<HardwareEventDecoder> mHardwareEventDecoders = new SparseArray<>(1); + // TODO: Move these {@link View}s to {@link KeyboardSwitcher}. + private View mInputView; private View mExtractArea; private View mKeyPreviewBackingView; private SuggestionStripView mSuggestionStripView; @@ -153,6 +157,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @UsedForTesting final KeyboardSwitcher mKeyboardSwitcher; private final SubtypeSwitcher mSubtypeSwitcher; private final SubtypeState mSubtypeState = new SubtypeState(); + private final SpecialKeyDetector mSpecialKeyDetector; // Object for reacting to adding/removing a dictionary pack. private final BroadcastReceiver mDictionaryPackInstallReceiver = @@ -215,7 +220,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen case MSG_UPDATE_SUGGESTION_STRIP: cancelUpdateSuggestionStrip(); latinIme.mInputLogic.performUpdateSuggestionStripSync( - latinIme.mSettings.getCurrent()); + latinIme.mSettings.getCurrent(), msg.arg1 /* inputStyle */); break; case MSG_UPDATE_SHIFT_STATE: switcher.requestUpdatingShiftState(latinIme.getCurrentAutoCapsState(), @@ -265,8 +270,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } - public void postUpdateSuggestionStrip() { - sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTION_STRIP), mDelayUpdateSuggestions); + public void postUpdateSuggestionStrip(final int inputStyle) { + sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTION_STRIP, inputStyle, + 0 /* ignored */), mDelayUpdateSuggestions); } public void postReopenDictionaries() { @@ -419,9 +425,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen latinIme.getCurrentInputConnection(), true /* enableMonitor */); } if (ProductionFlags.ENABLE_CURSOR_ANCHOR_INFO_CALLBACK) { - InputConnectionCompatUtils.requestCursorAnchorInfo( - latinIme.getCurrentInputConnection(), true /* enableMonitor */, - true /* requestImmediateCallback */); + // AcceptTypedWord feature relies on CursorAnchorInfo. + if (latinIme.mSettings.getCurrent().mShouldShowUiToAcceptTypedWord) { + InputConnectionCompatUtils.requestCursorAnchorInfo( + latinIme.getCurrentInputConnection(), true /* enableMonitor */, + true /* requestImmediateCallback */); + } } } } @@ -514,6 +523,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSettings = Settings.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mKeyboardSwitcher = KeyboardSwitcher.getInstance(); + mSpecialKeyDetector = new SpecialKeyDetector(this); mIsHardwareAcceleratedDrawingEnabled = InputMethodServiceCompatUtils.enableHardwareAcceleration(this); Log.i(TAG, "Hardware accelerated drawing: " + mIsHardwareAcceleratedDrawingEnabled); @@ -709,6 +719,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void setInputView(final View view) { super.setInputView(view); + mInputView = view; mExtractArea = getWindow().getWindow().getDecorView() .findViewById(android.R.id.extractArea); mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing); @@ -967,6 +978,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen super.onUpdateCursor(rect); } + // We cannot mark this method as @Override until new SDK becomes publicly available. + // @Override + public void onUpdateCursorAnchorInfo(final CursorAnchorInfo info) { + if (ProductionFlags.ENABLE_CURSOR_ANCHOR_INFO_CALLBACK) { + final CursorAnchorInfoCompatWrapper wrapper = + CursorAnchorInfoCompatWrapper.fromObject(info); + // TODO: Implement here + } + } + /** * This is called when the user has clicked on the extracted text view, * when running in fullscreen mode. The default implementation hides @@ -1040,7 +1061,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen applicationSpecifiedCompletions); final SuggestedWords suggestedWords = new SuggestedWords(applicationSuggestedWords, null /* rawSuggestions */, false /* typedWordValid */, false /* willAutoCorrect */, - false /* isObsoleteSuggestions */, false /* isPrediction */); + false /* isObsoleteSuggestions */, false /* isPrediction */, + SuggestedWords.INPUT_STYLE_APPLICATION_SPECIFIED /* inputStyle */); // When in fullscreen mode, show completions generated by the application forcibly setSuggestedWords(suggestedWords); } @@ -1079,6 +1101,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (visibleKeyboardView == null || !hasSuggestionStripView()) { return; } + final boolean hasHardwareKeyboard = mKeyboardSwitcher.hasHardwareKeyboard(); + if (hasHardwareKeyboard && visibleKeyboardView.getVisibility() == View.GONE) { + // If there is a hardware keyboard and a visible software keyboard view has been hidden, + // no visual element will be shown on the screen. + outInsets.touchableInsets = mInputView.getHeight(); + outInsets.visibleTopInsets = mInputView.getHeight(); + return; + } final int adjustedBackingHeight = getAdjustedBackingViewHeight(); final boolean backingGone = (mKeyPreviewBackingView.getVisibility() == View.GONE); final int backingHeight = backingGone ? 0 : adjustedBackingHeight; @@ -1111,7 +1141,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } @Override + public boolean onEvaluateInputViewShown() { + // Always show {@link InputView}. + return true; + } + + @Override public boolean onEvaluateFullscreenMode() { + if (mKeyboardSwitcher.hasHardwareKeyboard()) { + // If there is a hardware keyboard, disable full screen mode. + return false; + } // Reread resource value here, because this method is called by the framework as needed. final boolean isFullscreenModeAllowed = Settings.readUseFullscreenMode(getResources()); if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) { @@ -1413,7 +1453,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // TODO[IL]: Move this out of LatinIME. - public void getSuggestedWords(final int sessionId, final int sequenceNumber, + public void getSuggestedWords(final int inputStyle, final int sequenceNumber, final OnGetSuggestedWordsCallback callback) { final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); if (keyboard == null) { @@ -1421,7 +1461,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return; } mInputLogic.getSuggestedWords(mSettings.getCurrent(), keyboard.getProximityInfo(), - mKeyboardSwitcher.getKeyboardShiftMode(), sessionId, sequenceNumber, callback); + mKeyboardSwitcher.getKeyboardShiftMode(), inputStyle, sequenceNumber, callback); } @Override @@ -1505,7 +1545,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen default: // SHIFT_NO_UPDATE } if (inputTransaction.requiresUpdateSuggestions()) { - mHandler.postUpdateSuggestionStrip(); + final int inputStyle; + if (inputTransaction.mEvent.isSuggestionStripPress()) { + // Suggestion strip press: no input. + inputStyle = SuggestedWords.INPUT_STYLE_NONE; + } else if (inputTransaction.mEvent.isGesture()) { + inputStyle = SuggestedWords.INPUT_STYLE_TAIL_BATCH; + } else { + inputStyle = SuggestedWords.INPUT_STYLE_TYPING; + } + mHandler.postUpdateSuggestionStrip(inputStyle); } if (inputTransaction.didAffectContents()) { mSubtypeState.setCurrentSubtypeHasBeenUsed(); @@ -1568,6 +1617,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Hooks for hardware keyboard @Override public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) { + mSpecialKeyDetector.onKeyDown(keyEvent); if (!ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED) { return super.onKeyDown(keyCode, keyEvent); } @@ -1587,12 +1637,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } @Override - public boolean onKeyUp(final int keyCode, final KeyEvent event) { - final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode(); + public boolean onKeyUp(final int keyCode, final KeyEvent keyEvent) { + mSpecialKeyDetector.onKeyUp(keyEvent); + if (!ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED) { + return super.onKeyUp(keyCode, keyEvent); + } + final long keyIdentifier = keyEvent.getDeviceId() << 32 + keyEvent.getKeyCode(); if (mInputLogic.mCurrentlyPressedHardwareKeys.remove(keyIdentifier)) { return true; } - return super.onKeyUp(keyCode, event); + return super.onKeyUp(keyCode, keyEvent); } // onKeyDown and onKeyUp are the main events we are interested in. There are two more events |