Search in sources :

Example 1 with KeyboardSwitcher

use of com.android.inputmethod.keyboard.KeyboardSwitcher in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class LatinIME method onStartInputViewInternal.

@SuppressWarnings("deprecation")
void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restarting) {
    super.onStartInputView(editorInfo, restarting);
    mDictionaryFacilitator.onStartInput();
    // Switch to the null consumer to handle cases leading to early exit below, for which we
    // also wouldn't be consuming gesture data.
    mGestureConsumer = GestureConsumer.NULL_GESTURE_CONSUMER;
    mRichImm.refreshSubtypeCaches();
    final KeyboardSwitcher switcher = mKeyboardSwitcher;
    switcher.updateKeyboardTheme();
    final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView();
    // If we are starting input in a different text field from before, we'll have to reload
    // settings, so currentSettingsValues can't be final.
    SettingsValues currentSettingsValues = mSettings.getCurrent();
    if (editorInfo == null) {
        Log.e(TAG, "Null EditorInfo in onStartInputView()");
        if (DebugFlags.DEBUG_ENABLED) {
            throw new NullPointerException("Null EditorInfo in onStartInputView()");
        }
        return;
    }
    if (DebugFlags.DEBUG_ENABLED) {
        Log.d(TAG, "onStartInputView: editorInfo:" + String.format("inputType=0x%08x imeOptions=0x%08x", editorInfo.inputType, editorInfo.imeOptions));
        Log.d(TAG, "All caps = " + ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) + ", sentence caps = " + ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) != 0) + ", word caps = " + ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_WORDS) != 0));
    }
    Log.i(TAG, "Starting input. Cursor position = " + editorInfo.initialSelStart + "," + editorInfo.initialSelEnd);
    // TODO: Consolidate these checks with {@link InputAttributes}.
    if (InputAttributes.inPrivateImeOptions(null, NO_MICROPHONE_COMPAT, editorInfo)) {
        Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions);
        Log.w(TAG, "Use " + getPackageName() + "." + NO_MICROPHONE + " instead");
    }
    if (InputAttributes.inPrivateImeOptions(getPackageName(), FORCE_ASCII, editorInfo)) {
        Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions);
        Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead");
    }
    // In landscape mode, this method gets called without the input view being created.
    if (mainKeyboardView == null) {
        return;
    }
    // Update to a gesture consumer with the current editor and IME state.
    mGestureConsumer = GestureConsumer.newInstance(editorInfo, mInputLogic.getPrivateCommandPerformer(), mRichImm.getCurrentSubtypeLocale(), switcher.getKeyboard());
    // Forward this event to the accessibility utilities, if enabled.
    final AccessibilityUtils accessUtils = AccessibilityUtils.getInstance();
    if (accessUtils.isTouchExplorationEnabled()) {
        accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting);
    }
    final boolean inputTypeChanged = !currentSettingsValues.isSameInputType(editorInfo);
    final boolean isDifferentTextField = !restarting || inputTypeChanged;
    StatsUtils.onStartInputView(editorInfo.inputType, Settings.getInstance().getCurrent().mDisplayOrientation, !isDifferentTextField);
    // The EditorInfo might have a flag that affects fullscreen mode.
    // Note: This call should be done by InputMethodService?
    updateFullscreenMode();
    // ALERT: settings have not been reloaded and there is a chance they may be stale.
    // In the practice, if it is, we should have gotten onConfigurationChanged so it should
    // be fine, but this is horribly confusing and must be fixed AS SOON AS POSSIBLE.
    // In some cases the input connection has not been reset yet and we can't access it. In
    // this case we will need to call loadKeyboard() later, when it's accessible, so that we
    // can go into the correct mode, so we need to do some housekeeping here.
    final boolean needToCallLoadKeyboardLater;
    final Suggest suggest = mInputLogic.mSuggest;
    if (!isImeSuppressedByHardwareKeyboard()) {
        // The app calling setText() has the effect of clearing the composing
        // span, so we should reset our state unconditionally, even if restarting is true.
        // We also tell the input logic about the combining rules for the current subtype, so
        // it can adjust its combiners if needed.
        mInputLogic.startInput(mRichImm.getCombiningRulesExtraValueOfCurrentSubtype(), currentSettingsValues);
        resetDictionaryFacilitatorIfNecessary();
        // TODO[IL]: Can the following be moved to InputLogic#startInput?
        if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(editorInfo.initialSelStart, editorInfo.initialSelEnd, false)) {
            // Sometimes, while rotating, for some reason the framework tells the app we are not
            // connected to it and that means we can't refresh the cache. In this case, schedule
            // a refresh later.
            // We try resetting the caches up to 5 times before giving up.
            mHandler.postResetCaches(isDifferentTextField, 5);
            // mLastSelection{Start,End} are reset later in this method, no need to do it here
            needToCallLoadKeyboardLater = true;
        } else {
            // When rotating, and when input is starting again in a field from where the focus
            // didn't move (the keyboard having been closed with the back key),
            // initialSelStart and initialSelEnd sometimes are lying. Make a best effort to
            // work around this bug.
            mInputLogic.mConnection.tryFixLyingCursorPosition();
            mHandler.postResumeSuggestionsForStartInput(true);
            needToCallLoadKeyboardLater = false;
        }
    } else {
        // If we have a hardware keyboard we don't need to call loadKeyboard later anyway.
        needToCallLoadKeyboardLater = false;
    }
    if (isDifferentTextField || !currentSettingsValues.hasSameOrientation(getResources().getConfiguration())) {
        loadSettings();
    }
    if (isDifferentTextField) {
        mainKeyboardView.closing();
        currentSettingsValues = mSettings.getCurrent();
        if (currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) {
            suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold);
        }
        suggest.setPlausibilityThreshold(currentSettingsValues.mPlausibilityThreshold);
        switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
        if (needToCallLoadKeyboardLater) {
            // If we need to call loadKeyboard again later, we need to save its state now. The
            // later call will be done in #retryResetCaches.
            switcher.saveKeyboardState();
        }
    } else if (restarting) {
        // TODO: Come up with a more comprehensive way to reset the keyboard layout when
        // a keyboard layout set doesn't get reloaded in this method.
        switcher.resetKeyboardStateToAlphabet(getCurrentAutoCapsState(), getCurrentRecapitalizeState());
        // In apps like Talk, we come here when the text is sent and the field gets emptied and
        // we need to re-evaluate the shift state, but not the whole layout which would be
        // disruptive.
        // Space state must be updated before calling updateShiftState
        switcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState());
    }
    // This will set the punctuation suggestions if next word suggestion is off;
    // otherwise it will clear the suggestion strip.
    setNeutralSuggestionStrip();
    mHandler.cancelUpdateSuggestionStrip();
    mainKeyboardView.setMainDictionaryAvailability(mDictionaryFacilitator.hasAtLeastOneInitializedMainDictionary());
    mainKeyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn, currentSettingsValues.mKeyPreviewPopupDismissDelay);
    mainKeyboardView.setSlidingKeyInputPreviewEnabled(currentSettingsValues.mSlidingKeyInputPreviewEnabled);
    mainKeyboardView.setGestureHandlingEnabledByUser(currentSettingsValues.mGestureInputEnabled, currentSettingsValues.mGestureTrailEnabled, currentSettingsValues.mGestureFloatingPreviewTextEnabled);
    if (TRACE)
        Debug.startMethodTracing("/data/trace/latinime");
}
Also used : MainKeyboardView(com.android.inputmethod.keyboard.MainKeyboardView) SettingsValues(com.android.inputmethod.latin.settings.SettingsValues) KeyboardSwitcher(com.android.inputmethod.keyboard.KeyboardSwitcher) AccessibilityUtils(com.android.inputmethod.accessibility.AccessibilityUtils)

Aggregations

AccessibilityUtils (com.android.inputmethod.accessibility.AccessibilityUtils)1 KeyboardSwitcher (com.android.inputmethod.keyboard.KeyboardSwitcher)1 MainKeyboardView (com.android.inputmethod.keyboard.MainKeyboardView)1 SettingsValues (com.android.inputmethod.latin.settings.SettingsValues)1