當前位置: 首頁>>代碼示例>>Java>>正文


Java InputConnection.setComposingText方法代碼示例

本文整理匯總了Java中android.view.inputmethod.InputConnection.setComposingText方法的典型用法代碼示例。如果您正苦於以下問題:Java InputConnection.setComposingText方法的具體用法?Java InputConnection.setComposingText怎麽用?Java InputConnection.setComposingText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.inputmethod.InputConnection的用法示例。


在下文中一共展示了InputConnection.setComposingText方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: revertLastWord

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
public void revertLastWord(boolean deleteChar) {
    final int length = mComposing.length();
    if (!mPredicting && length > 0) {
        final InputConnection ic = getCurrentInputConnection();
        mPredicting = true;
        mJustRevertedSeparator = ic.getTextBeforeCursor(1, 0);
        if (deleteChar) ic.deleteSurroundingText(1, 0);
        int toDelete = mCommittedLength;
        CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
        if (toTheLeft != null && toTheLeft.length() > 0
                && isWordSeparator(toTheLeft.charAt(0))) {
            toDelete--;
        }
        ic.deleteSurroundingText(toDelete, 0);
        ic.setComposingText(mComposing, 1);
        TextEntryState.backspace();
        postUpdateSuggestions();
    } else {
        sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
        mJustRevertedSeparator = null;
    }
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:23,代碼來源:KP2AKeyboard.java

示例2: appendText

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
/**
 * Append newText to the text field represented by connection.
 * The new text becomes selected.
 */
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);
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:23,代碼來源:EditingUtil.java

示例3: handleBackspace

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private void handleBackspace() {
    boolean deleteChar = false;
    InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;

    ic.beginBatchEdit();
   
    if (mPredicting) {
        final int length = mComposing.length();
        if (length > 0) {
            mComposing.delete(length - 1, length);
            mWord.deleteLast();
            ic.setComposingText(mComposing, 1);
            if (mComposing.length() == 0) {
                mPredicting = false;
            }
            postUpdateSuggestions();
        } else {
            ic.deleteSurroundingText(1, 0);
        }
    } else {
        deleteChar = true;
    }
    postUpdateShiftKeyState();
    TextEntryState.backspace();
    if (TextEntryState.getState() == TextEntryState.State.UNDO_COMMIT) {
        revertLastWord(deleteChar);
        ic.endBatchEdit();
        return;
    } else if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
        ic.deleteSurroundingText(mEnteredText.length(), 0);
    } else if (deleteChar) {
        if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
            // Go back to the suggestion mode if the user canceled the
            // "Touch again to save".
            // NOTE: In gerenal, we don't revert the word when backspacing
            // from a manual suggestion pick.  We deliberately chose a
            // different behavior only in the case of picking the first
            // suggestion (typed word).  It's intentional to have made this
            // inconsistent with backspacing after selecting other suggestions.
            revertLastWord(deleteChar);
        } else {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
            if (mDeleteCount > DELETE_ACCELERATE_AT) {
                sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
            }
        }
    }
    mJustRevertedSeparator = null;
    ic.endBatchEdit();
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:52,代碼來源:KP2AKeyboard.java

示例4: handleCharacter

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private void handleCharacter(int primaryCode, int[] keyCodes) {
   
    if (mLastSelectionStart == mLastSelectionEnd && TextEntryState.isCorrecting()) {
        abortCorrection(false);
    }

    if (isAlphabet(primaryCode) && isPredictionOn() && !isCursorTouchingWord()) {
        if (!mPredicting) {
            mPredicting = true;
            mComposing.setLength(0);
            saveWordInHistory(mBestWord);
            mWord.reset();
        }
    }
    if (mKeyboardSwitcher.getInputView().isShifted()) {
        if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT
                || keyCodes[0] > Character.MAX_CODE_POINT) {
            return;
        }
        primaryCode = keyCodes[0];
        if (mKeyboardSwitcher.isAlphabetMode() && Character.isLowerCase(primaryCode)) {
            // In some locales, such as Turkish, Character.toUpperCase() may return a wrong
            // character because it doesn't take care of locale.
            final String upperCaseString = new String(new int[] {primaryCode}, 0, 1)
                    .toUpperCase(mLanguageSwitcher.getInputLocale());
            if (upperCaseString.codePointCount(0, upperCaseString.length()) == 1) {
                primaryCode = upperCaseString.codePointAt(0);
            } else {
                // Some keys, such as [eszett], have upper case as multi-characters.
                onText(upperCaseString);
                return;
            }
        }
    }
    if (mPredicting) {
        if (mKeyboardSwitcher.getInputView().isShifted()
                && mKeyboardSwitcher.isAlphabetMode()
                && mComposing.length() == 0) {
            mWord.setFirstCharCapitalized(true);
        }
        mComposing.append((char) primaryCode);
        mWord.add(primaryCode, keyCodes);
        InputConnection ic = getCurrentInputConnection();
        if (ic != null) {
            // If it's the first letter, make note of auto-caps state
            if (mWord.size() == 1) {
                mWord.setAutoCapitalized(
                        getCursorCapsMode(ic, getCurrentInputEditorInfo()) != 0);
            }
            ic.setComposingText(mComposing, 1);
        }
        postUpdateSuggestions();
    } else {
        sendKeyChar((char) primaryCode);
    }
    updateShiftKeyState(getCurrentInputEditorInfo());
    if (KP2AKeyboard.PERF_DEBUG) measureCps();
    TextEntryState.typedCharacter((char) primaryCode, isWordSeparator(primaryCode));
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:60,代碼來源:KP2AKeyboard.java


注:本文中的android.view.inputmethod.InputConnection.setComposingText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。