当前位置: 首页>>代码示例>>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;未经允许,请勿转载。