android.view.inputmethod.InputConnection#setSelection ( )源码实例Demo

下面列出了android.view.inputmethod.InputConnection#setSelection ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: InputMethodService.java
/**
 * This is called when the user has moved the cursor in the extracted
 * text view, when running in fullsreen mode.  The default implementation
 * performs the corresponding selection change on the underlying text
 * editor.
 */
public void onExtractedSelectionChanged(int start, int end) {
    InputConnection conn = getCurrentInputConnection();
    if (conn != null) {
        conn.setSelection(start, end);
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: InputMethodService.java
/**
 * @hide
 */
public void onExtractedDeleteText(int start, int end) {
    InputConnection conn = getCurrentInputConnection();
    if (conn != null) {
        conn.finishComposingText();
        conn.setSelection(start, start);
        conn.deleteSurroundingText(0, end - start);
    }
}
 
源代码3 项目: android_9.0.0_r45   文件: InputMethodService.java
/**
 * @hide
 */
public void onExtractedSetSpan(Object span, int start, int end, int flags) {
    InputConnection conn = getCurrentInputConnection();
    if (conn != null) {
        if (!conn.setSelection(start, end)) return;
        CharSequence text = conn.getSelectedText(InputConnection.GET_TEXT_WITH_STYLES);
        if (text instanceof Spannable) {
            ((Spannable) text).setSpan(span, 0, text.length(), flags);
            conn.setComposingRegion(start, end);
            conn.commitText(text, 1);
        }
    }
}
 
源代码4 项目: mongol-library   文件: ImeContainer.java
@Override
public void moveCursorEnd() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;
    ExtractedText extractedText = ic.getExtractedText(new ExtractedTextRequest(), 0);
    if (extractedText == null || extractedText.text == null) return;
    int length = extractedText.text.length();
    ic.setSelection(length, length);
}
 
源代码5 项目: mongol-library   文件: ImeContainer.java
@Override
public void selectWordBack() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;
    ExtractedText extractedText = ic.getExtractedText(new ExtractedTextRequest(), 0);
    int previousWordBoundary = getPreviousWordBoundary(extractedText.text, extractedText.selectionStart);
    int start = extractedText.startOffset + previousWordBoundary;
    int end = extractedText.startOffset + extractedText.selectionEnd;
    ic.setSelection(start, end);
}
 
源代码6 项目: mongol-library   文件: ImeContainer.java
@Override
public void selectWordForward() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;
    ExtractedText extractedText = ic.getExtractedText(new ExtractedTextRequest(), 0);
    int nextWordBoundary = getNextWordBoundary(extractedText.text, extractedText.selectionEnd);
    int start = extractedText.startOffset + extractedText.selectionStart;
    int end = extractedText.startOffset + nextWordBoundary;
    ic.setSelection(start, end);
}
 
源代码7 项目: brailleback   文件: BrailleIME.java
private boolean setCursor(InputConnection ic, int pos) {
    if (mCurrentText == null) {
        return false;
    }
    int textLen = mCurrentText.length();
    pos = (pos < 0) ? 0 : ((pos <= textLen) ? pos : textLen);
    int off = mExtractedText != null ? mExtractedText.startOffset : 0;
    int cursor = off + pos;
    return ic.setSelection(cursor, cursor);
}
 
源代码8 项目: hackerskeyboard   文件: EditingUtil.java
/**
 * Removes the word surrounding the cursor. Parameters are identical to
 * getWordAtCursor.
 */
public static void deleteWordAtCursor(
    InputConnection connection, String separators) {

    Range range = getWordRangeAtCursor(connection, separators, null);
    if (range == null) return;

    connection.finishComposingText();
    // Move cursor to beginning of word, to avoid crash when cursor is outside
    // of valid range after deleting text.
    int newCursor = getCursorPosition(connection) - range.charsBefore;
    connection.setSelection(newCursor, newCursor);
    connection.deleteSurroundingText(0, range.charsBefore + range.charsAfter);
}
 
源代码9 项目: remotekeyboard   文件: CtrlInputAction.java
/**
 * Place the cursor on the next occurance of a symbol
 * 
 * @param con
 *          driver
 * @param symbol
 *          the symbol to jump to
 */
private void jumpForward(InputConnection con, int symbol) {
	ExtractedText txt = con.getExtractedText(new ExtractedTextRequest(), 0);
	if (txt != null) {
		int pos = txt.text.toString().indexOf(symbol, txt.selectionEnd + 1);
		if (pos == -1) {
			pos = txt.text.length();
		}
		con.setSelection(pos, pos);
	}
}
 
源代码10 项目: remotekeyboard   文件: CtrlInputAction.java
/**
 * Place the cursor on the last occusrance of a symbol
 * 
 * @param con
 *          driver
 * @param symbol
 *          the symbol to jump to
 */
private void jumpBackward(InputConnection con, int symbol) {
	ExtractedText txt = con.getExtractedText(new ExtractedTextRequest(), 0);
	if (txt != null) {
		int pos = txt.text.toString().lastIndexOf(symbol, txt.selectionEnd - 2);
		pos++;

		con.setSelection(pos, pos);
	}

}
 
源代码11 项目: mongol-library   文件: ImeContainer.java
@Override
public void moveCursorStart() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;
    ic.setSelection(0, 0);
}