Search in sources :

Example 1 with InputTransaction

use of com.android.inputmethod.event.InputTransaction in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class InputLogic method onTextInput.

/**
     * React to a string input.
     *
     * This is triggered by keys that input many characters at once, like the ".com" key or
     * some additional keys for example.
     *
     * @param settingsValues the current values of the settings.
     * @param event the input event containing the data.
     * @return the complete transaction object
     */
public InputTransaction onTextInput(final SettingsValues settingsValues, final Event event, final int keyboardShiftMode, final LatinIME.UIHandler handler) {
    final String rawText = event.getTextToCommit().toString();
    final InputTransaction inputTransaction = new InputTransaction(settingsValues, event, SystemClock.uptimeMillis(), mSpaceState, getActualCapsMode(settingsValues, keyboardShiftMode));
    mConnection.beginBatchEdit();
    if (mWordComposer.isComposingWord()) {
        commitCurrentAutoCorrection(settingsValues, rawText, handler);
    } else {
        resetComposingState(true);
    }
    handler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_TYPING);
    final String text = performSpecificTldProcessingOnTextInput(rawText);
    if (SpaceState.PHANTOM == mSpaceState) {
        insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
    }
    mConnection.commitText(text, 1);
    StatsUtils.onWordCommitUserTyped(mEnteredText, mWordComposer.isBatchMode());
    mConnection.endBatchEdit();
    // Space state must be updated before calling updateShiftState
    mSpaceState = SpaceState.NONE;
    mEnteredText = text;
    mWordBeingCorrectedByCursor = null;
    inputTransaction.setDidAffectContents();
    inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
    return inputTransaction;
}
Also used : InputTransaction(com.android.inputmethod.event.InputTransaction) SpannableString(android.text.SpannableString)

Example 2 with InputTransaction

use of com.android.inputmethod.event.InputTransaction in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class LatinIME method onEvent.

// This method is public for testability of LatinIME, but also in the future it should
// completely replace #onCodeInput.
public void onEvent(@Nonnull final Event event) {
    if (Constants.CODE_SHORTCUT == event.mKeyCode) {
        mRichImm.switchToShortcutIme(this);
    }
    final InputTransaction completeInputTransaction = mInputLogic.onCodeInput(mSettings.getCurrent(), event, mKeyboardSwitcher.getKeyboardShiftMode(), mKeyboardSwitcher.getCurrentKeyboardScriptId(), mHandler);
    updateStateAfterInputTransaction(completeInputTransaction);
    mKeyboardSwitcher.onEvent(event, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
}
Also used : InputTransaction(com.android.inputmethod.event.InputTransaction)

Example 3 with InputTransaction

use of com.android.inputmethod.event.InputTransaction in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class LatinIME method pickSuggestionManually.

// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
// interface
@Override
public void pickSuggestionManually(final SuggestedWordInfo suggestionInfo) {
    final InputTransaction completeInputTransaction = mInputLogic.onPickSuggestionManually(mSettings.getCurrent(), suggestionInfo, mKeyboardSwitcher.getKeyboardShiftMode(), mKeyboardSwitcher.getCurrentKeyboardScriptId(), mHandler);
    updateStateAfterInputTransaction(completeInputTransaction);
}
Also used : InputTransaction(com.android.inputmethod.event.InputTransaction)

Example 4 with InputTransaction

use of com.android.inputmethod.event.InputTransaction in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class LatinIME method onTextInput.

// Called from PointerTracker through the KeyboardActionListener interface
@Override
public void onTextInput(final String rawText) {
    // TODO: have the keyboard pass the correct key code when we need it.
    final Event event = Event.createSoftwareTextEvent(rawText, Constants.CODE_OUTPUT_TEXT);
    final InputTransaction completeInputTransaction = mInputLogic.onTextInput(mSettings.getCurrent(), event, mKeyboardSwitcher.getKeyboardShiftMode(), mHandler);
    updateStateAfterInputTransaction(completeInputTransaction);
    mKeyboardSwitcher.onEvent(event, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
}
Also used : InputTransaction(com.android.inputmethod.event.InputTransaction) Event(com.android.inputmethod.event.Event) KeyEvent(android.view.KeyEvent)

Example 5 with InputTransaction

use of com.android.inputmethod.event.InputTransaction in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class InputLogic method onPickSuggestionManually.

/**
     * A suggestion was picked from the suggestion strip.
     * @param settingsValues the current values of the settings.
     * @param suggestionInfo the suggestion info.
     * @param keyboardShiftState the shift state of the keyboard, as returned by
     *     {@link com.android.inputmethod.keyboard.KeyboardSwitcher#getKeyboardShiftMode()}
     * @return the complete transaction object
     */
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
// interface
public InputTransaction onPickSuggestionManually(final SettingsValues settingsValues, final SuggestedWordInfo suggestionInfo, final int keyboardShiftState, final int currentKeyboardScriptId, final LatinIME.UIHandler handler) {
    final SuggestedWords suggestedWords = mSuggestedWords;
    final String suggestion = suggestionInfo.mWord;
    // If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
    if (suggestion.length() == 1 && suggestedWords.isPunctuationSuggestions()) {
        // We still want to log a suggestion click.
        StatsUtils.onPickSuggestionManually(mSuggestedWords, suggestionInfo, mDictionaryFacilitator);
        // Word separators are suggested before the user inputs something.
        // Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
        final Event event = Event.createPunctuationSuggestionPickedEvent(suggestionInfo);
        return onCodeInput(settingsValues, event, keyboardShiftState, currentKeyboardScriptId, handler);
    }
    final Event event = Event.createSuggestionPickedEvent(suggestionInfo);
    final InputTransaction inputTransaction = new InputTransaction(settingsValues, event, SystemClock.uptimeMillis(), mSpaceState, keyboardShiftState);
    // Manual pick affects the contents of the editor, so we take note of this. It's important
    // for the sequence of language switching.
    inputTransaction.setDidAffectContents();
    mConnection.beginBatchEdit();
    if (SpaceState.PHANTOM == mSpaceState && suggestion.length() > 0 && // the current batch input text and there is no need for a phantom space.
    !mWordComposer.isBatchMode()) {
        final int firstChar = Character.codePointAt(suggestion, 0);
        if (!settingsValues.isWordSeparator(firstChar) || settingsValues.isUsuallyPrecededBySpace(firstChar)) {
            insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
        }
    }
    // the risk of calling commitCompletion twice because we don't know how the app will react.
    if (suggestionInfo.isKindOf(SuggestedWordInfo.KIND_APP_DEFINED)) {
        mSuggestedWords = SuggestedWords.getEmptyInstance();
        mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
        inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
        resetComposingState(true);
        mConnection.commitCompletion(suggestionInfo.mApplicationSpecifiedCompletionInfo);
        mConnection.endBatchEdit();
        return inputTransaction;
    }
    commitChosenWord(settingsValues, suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, LastComposedWord.NOT_A_SEPARATOR);
    mConnection.endBatchEdit();
    // Don't allow cancellation of manual pick
    mLastComposedWord.deactivate();
    // Space state must be updated before calling updateShiftState
    mSpaceState = SpaceState.PHANTOM;
    inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
    // If we're not showing the "Touch again to save", then update the suggestion strip.
    // That's going to be predictions (or punctuation suggestions), so INPUT_STYLE_NONE.
    handler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_NONE);
    StatsUtils.onPickSuggestionManually(mSuggestedWords, suggestionInfo, mDictionaryFacilitator);
    StatsUtils.onWordCommitSuggestionPickedManually(suggestionInfo.mWord, mWordComposer.isBatchMode());
    return inputTransaction;
}
Also used : InputTransaction(com.android.inputmethod.event.InputTransaction) SuggestedWords(com.android.inputmethod.latin.SuggestedWords) KeyEvent(android.view.KeyEvent) Event(com.android.inputmethod.event.Event) SpannableString(android.text.SpannableString)

Aggregations

InputTransaction (com.android.inputmethod.event.InputTransaction)6 KeyEvent (android.view.KeyEvent)3 Event (com.android.inputmethod.event.Event)3 SpannableString (android.text.SpannableString)2 SuggestedWords (com.android.inputmethod.latin.SuggestedWords)1