Example usage for android.view.inputmethod InputConnection finishComposingText

List of usage examples for android.view.inputmethod InputConnection finishComposingText

Introduction

In this page you can find the example usage for android.view.inputmethod InputConnection finishComposingText.

Prototype

boolean finishComposingText();

Source Link

Document

Have the text editor finish whatever composing text is currently active.

Usage

From source file:Main.java

/**
 * Append newText to the text field represented by connection.
 * The new text becomes selected./*  ww w  .java2  s  .  co  m*/
 */
public static void appendText(InputConnection connection, String newText) {
    if (connection == null) {
        return;
    }

    // Commit the composing text
    connection.finishComposingText();

    // Add a space if the field already has text.
    CharSequence charBeforeCursor = connection.getTextBeforeCursor(1, 0);
    if (charBeforeCursor != null && !charBeforeCursor.equals(" ") && (charBeforeCursor.length() > 0)) {
        newText = " " + newText;
    }

    connection.setComposingText(newText, 1);
}

From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java

/**
 * Deal with the editor reporting movement of its cursor.
 *///from   www  .  ja  v  a2s  .  c  o  m
@Override
public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd,
        int candidatesStart, int candidatesEnd) {
    super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);

    // If the current selection in the text view changes, we should
    // clear whatever candidate text we have.
    if (mComposing.length() > 0 && (newSelStart != candidatesEnd || newSelEnd != candidatesEnd)) {
        mComposing.setLength(0);
        updateCandidates();
        InputConnection ic = getCurrentInputConnection();
        if (ic != null) {
            ic.finishComposingText();
        }
    }
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

@Override
protected void abortCorrectionAndResetPredictionState(boolean forever) {
    super.abortCorrectionAndResetPredictionState(forever);
    mJustAutoAddedWord = false;//  ww  w . j  a  v  a  2s  .  co m
    mKeyboardHandler.removeMessages(KeyboardUIStateHandler.MSG_UPDATE_SUGGESTIONS);
    mKeyboardHandler.removeMessages(KeyboardUIStateHandler.MSG_RESTART_NEW_WORD_SUGGESTIONS);

    final InputConnection ic = getCurrentInputConnection();
    if (ic != null)
        ic.finishComposingText();

    clearSuggestions();

    mUndoCommitCursorPosition = UNDO_COMMIT_NONE;
    mCommittedWord = "";
    mWord.reset();
    TextEntryState.newSession(mPredictionOn);
    mJustAddedAutoSpace = false;
    mJustAutoAddedWord = false;
    if (forever) {
        Logger.d(TAG, "abortCorrection will abort correct forever");
        mPredictionOn = false;
        setCandidatesViewShown(false);
    }
    TextEntryState.newSession(mPredictionOn && (!forever));
}

From source file:org.pocketworkstation.pckeyboard.LatinIME.java

@Override
public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd,
        int candidatesStart, int candidatesEnd) {
    super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);

    // If the current selection in the text view changes, we should
    // clear whatever candidate text we have.
    if ((((mComposing.length() > 0 && mPredicting))
            && (newSelStart != candidatesEnd || newSelEnd != candidatesEnd)
            && mLastSelectionStart != newSelStart)) {
        mComposing.setLength(0);//w  w  w . j  a v  a  2 s. c om
        mPredicting = false;
        postUpdateSuggestions();
        TextEntryState.reset();
        InputConnection ic = getCurrentInputConnection();
        if (ic != null) {
            ic.finishComposingText();
        }
    } else if (!mPredicting && !mJustAccepted) {
        switch (TextEntryState.getState()) {
        case ACCEPTED_DEFAULT:
            TextEntryState.reset();
            // fall through
        case SPACE_AFTER_PICKED:
            mJustAddedAutoSpace = false; // The user moved the cursor.
            break;
        }
    }
    mJustAccepted = false;
    postUpdateShiftKeyState();

    // Make a note of the cursor position
    mLastSelectionStart = newSelStart;
    mLastSelectionEnd = newSelEnd;

    if (mReCorrectionEnabled) {
        // Don't look for corrections if the keyboard is not visible
        if (mKeyboardSwitcher != null && mKeyboardSwitcher.getInputView() != null
                && mKeyboardSwitcher.getInputView().isShown()) {
            // Check if we should go in or out of correction mode.
            if (isPredictionOn() && mJustRevertedSeparator == null
                    && (candidatesStart == candidatesEnd || newSelStart != oldSelStart
                            || TextEntryState.isCorrecting())
                    && (newSelStart < newSelEnd - 1 || (!mPredicting))) {
                if (isCursorTouchingWord() || mLastSelectionStart < mLastSelectionEnd) {
                    postUpdateOldSuggestions();
                } else {
                    abortCorrection(false);
                    // Show the punctuation suggestions list if the current
                    // one is not
                    // and if not showing "Touch again to save".
                    if (mCandidateView != null && !mSuggestPuncList.equals(mCandidateView.getSuggestions())
                            && !mCandidateView.isShowingAddToDictionaryHint()) {
                        setNextSuggestions();
                    }
                }
            }
        }
    }
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

@Override
public void onConfigurationChanged(Configuration conf) {
    Log.i("PCKeyboard", "onConfigurationChanged()");
    // If the system locale changes and is different from the saved
    // locale (mSystemLocale), then reload the input locale list from the
    // latin ime settings (shared prefs) and reset the input locale
    // to the first one.
    final String systemLocale = conf.locale.toString();
    if (!TextUtils.equals(systemLocale, mSystemLocale)) {
        mSystemLocale = systemLocale;/*from   w  ww.  j a  v  a 2  s .  c o  m*/
        if (mLanguageSwitcher != null) {
            mLanguageSwitcher.loadLocales(PreferenceManager.getDefaultSharedPreferences(this));
            mLanguageSwitcher.setSystemLocale(conf.locale);
            toggleLanguage(true, true);
        } else {
            reloadKeyboards();
        }
    }
    // If orientation changed while predicting, commit the change
    if (conf.orientation != mOrientation) {
        InputConnection ic = getCurrentInputConnection();
        commitTyped(ic, true);
        if (ic != null)
            ic.finishComposingText(); // For voice input
        mOrientation = conf.orientation;
        reloadKeyboards();
        removeCandidateViewContainer();
    }
    mConfigurationChanging = true;
    super.onConfigurationChanged(conf);
    mConfigurationChanging = false;
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

@Override
public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd,
        int candidatesStart, int candidatesEnd) {
    super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);

    if (DEBUG) {/*from   w ww.ja va 2  s . c o  m*/
        Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart + ", ose=" + oldSelEnd + ", nss=" + newSelStart
                + ", nse=" + newSelEnd + ", cs=" + candidatesStart + ", ce=" + candidatesEnd);
    }

    // If the current selection in the text view changes, we should
    // clear whatever candidate text we have.
    if ((((mComposing.length() > 0 && mPredicting))
            && (newSelStart != candidatesEnd || newSelEnd != candidatesEnd)
            && mLastSelectionStart != newSelStart)) {
        mComposing.setLength(0);
        mPredicting = false;
        postUpdateSuggestions();
        TextEntryState.reset();
        InputConnection ic = getCurrentInputConnection();
        if (ic != null) {
            ic.finishComposingText();
        }
    } else if (!mPredicting && !mJustAccepted) {
        switch (TextEntryState.getState()) {
        case ACCEPTED_DEFAULT:
            TextEntryState.reset();
            // fall through
        case SPACE_AFTER_PICKED:
            mJustAddedAutoSpace = false; // The user moved the cursor.
            break;
        }
    }
    mJustAccepted = false;
    postUpdateShiftKeyState();

    // Make a note of the cursor position
    mLastSelectionStart = newSelStart;
    mLastSelectionEnd = newSelEnd;

    if (mReCorrectionEnabled) {
        // Don't look for corrections if the keyboard is not visible
        if (mKeyboardSwitcher != null && mKeyboardSwitcher.getInputView() != null
                && mKeyboardSwitcher.getInputView().isShown()) {
            // Check if we should go in or out of correction mode.
            if (isPredictionOn() && mJustRevertedSeparator == null
                    && (candidatesStart == candidatesEnd || newSelStart != oldSelStart
                            || TextEntryState.isCorrecting())
                    && (newSelStart < newSelEnd - 1 || (!mPredicting))) {
                if (isCursorTouchingWord() || mLastSelectionStart < mLastSelectionEnd) {
                    postUpdateOldSuggestions();
                } else {
                    abortCorrection(false);
                    // Show the punctuation suggestions list if the current
                    // one is not
                    // and if not showing "Touch again to save".
                    if (mCandidateView != null && !mSuggestPuncList.equals(mCandidateView.getSuggestions())
                            && !mCandidateView.isShowingAddToDictionaryHint()) {
                        setNextSuggestions();
                    }
                }
            }
        }
    }
}