android.view.inputmethod.ExtractedTextRequest Java Examples

The following examples show how to use android.view.inputmethod.ExtractedTextRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InputConnectionCommandEditor.java    From AlexaAndroid with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean replace(String str1, String str2) {
    boolean success = false;
    mInputConnection.beginBatchEdit();
    ExtractedText extractedText = mInputConnection.getExtractedText(new ExtractedTextRequest(), 0);
    if (extractedText != null) {
        CharSequence beforeCursor = extractedText.text;
        //CharSequence beforeCursor = mInputConnection.getTextBeforeCursor(MAX_SELECTABLE_CONTEXT, 0);
        Log.i("replace: " + beforeCursor);
        int index = beforeCursor.toString().lastIndexOf(str1);
        Log.i("replace: " + index);
        if (index > 0) {
            mInputConnection.setSelection(index, index);
            mInputConnection.deleteSurroundingText(0, str1.length());
            if (!str2.isEmpty()) {
                mInputConnection.commitText(str2, 0);
            }
            success = true;
        }
        mInputConnection.endBatchEdit();
    }
    return success;
}
 
Example #2
Source File: CtrlInputAction.java    From remotekeyboard with Apache License 2.0 6 votes vote down vote up
/**
 * Try to replace the current word with its substitution.
 */
private void replaceText(InputConnection con) {
	ExtractedText txt = con.getExtractedText(new ExtractedTextRequest(), 0);
	if (txt != null) {
		int end = txt.text.toString().indexOf(" ", txt.selectionEnd);
		if (end == -1) {
			end = txt.text.length();
		}
		int start = txt.text.toString().lastIndexOf(" ", txt.selectionEnd - 1);
		start++;
		String sel = txt.text.subSequence(start, end).toString();
		String rep = myService.replacements.get(sel);
		if (rep != null) {
			con.setComposingRegion(start, end);
			con.setComposingText(rep, 1);
			con.finishComposingText();
		}
		else {
			String err = myService.getResources().getString(
					R.string.err_no_replacement, sel);
			Toast.makeText(myService, err, Toast.LENGTH_SHORT).show();
		}
	}
}
 
Example #3
Source File: KeyboardWidget.java    From FirefoxReality with Mozilla Public License 2.0 6 votes vote down vote up
private void displayComposingText(String aText, ComposingAction aAction) {
    if (mInputConnection == null) {
        return;
    }
    boolean succeeded = mInputConnection.setComposingText(aText, 1);
    if (!succeeded) {
        // Fix for InlineAutocompleteEditText failed setComposingText() calls
        String fullText = mInputConnection.getExtractedText(new ExtractedTextRequest(),0).text.toString();
        String beforeText = mInputConnection.getTextBeforeCursor(fullText.length(),0).toString();
        if (beforeText.endsWith(mComposingDisplayText)) {
            mInternalDeleteHint = true;
            mInputConnection.deleteSurroundingText(mComposingDisplayText.length(), 0);
        }
        mInputConnection.setComposingText(aText, 1);
    }
    mComposingDisplayText = aText;
    if (aAction == ComposingAction.FINISH) {
        mInputConnection.finishComposingText();
        mComposingText = "";
    }
}
 
Example #4
Source File: RichInputConnection.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
private void checkConsistencyForDebug() {
    final ExtractedTextRequest r = new ExtractedTextRequest();
    r.hintMaxChars = 0;
    r.hintMaxLines = 0;
    r.token = 1;
    r.flags = 0;
    final ExtractedText et = mIC.getExtractedText(r, 0);
    final CharSequence beforeCursor = getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE,
            0);
    final StringBuilder internal = new StringBuilder(mCommittedTextBeforeComposingText)
            .append(mComposingText);
    if (null == et || null == beforeCursor) return;
    final int actualLength = Math.min(beforeCursor.length(), internal.length());
    if (internal.length() > actualLength) {
        internal.delete(0, internal.length() - actualLength);
    }
    final String reference = (beforeCursor.length() <= actualLength) ? beforeCursor.toString()
            : beforeCursor.subSequence(beforeCursor.length() - actualLength,
                    beforeCursor.length()).toString();
    if (et.selectionStart != mExpectedSelStart
            || !(reference.equals(internal.toString()))) {
        final String context = "Expected selection start = " + mExpectedSelStart
                + "\nActual selection start = " + et.selectionStart
                + "\nExpected text = " + internal.length() + " " + internal
                + "\nActual text = " + reference.length() + " " + reference;
        ((LatinIME)mParent).debugDumpStateAndCrashWithException(context);
    } else {
        Log.e(TAG, DebugLogUtils.getStackTrace(2));
        Log.e(TAG, "Exp <> Actual : " + mExpectedSelStart + " <> " + et.selectionStart);
    }
}
 
Example #5
Source File: InputConnectionHacker.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
@Override
    public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
//        return ic.getExtractedText(request, flags);
        String text = editAreaView.getSelectedText();
        if (text == null) text = "";
        ExtractedText et = new ExtractedText();
        et.text = text;
        et.partialEndOffset = text.length();
        et.selectionStart = 0;
        et.selectionEnd = text.length();
        et.flags = 0;
        return et;
    }
 
Example #6
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
private void checkReCorrectionOnStart() {
    if (mReCorrectionEnabled && isPredictionOn()) {
        // First get the cursor position. This is required by
        // setOldSuggestions(), so that
        // it can pass the correct range to setComposingRegion(). At this
        // point, we don't
        // have valid values for mLastSelectionStart/Stop because
        // onUpdateSelection() has
        // not been called yet.
        InputConnection ic = getCurrentInputConnection();
        if (ic == null)
            return;
        ExtractedTextRequest etr = new ExtractedTextRequest();
        etr.token = 0; // anything is fine here
        ExtractedText et = ic.getExtractedText(etr, 0);
        if (et == null)
            return;

        mLastSelectionStart = et.startOffset + et.selectionStart;
        mLastSelectionEnd = et.startOffset + et.selectionEnd;

        // Then look for possible corrections in a delayed fashion
        if (!TextUtils.isEmpty(et.text) && isCursorTouchingWord()) {
            postUpdateOldSuggestions();
        }
    }
}
 
Example #7
Source File: EditingUtil.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
private static int getCursorPosition(InputConnection connection) {
    ExtractedText extracted = connection.getExtractedText(
        new ExtractedTextRequest(), 0);
    if (extracted == null) {
      return -1;
    }
    return extracted.startOffset + extracted.selectionStart;
}
 
Example #8
Source File: ThreadedInputConnection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @see InputConnection#getExtractedText(android.view.inputmethod.ExtractedTextRequest, int)
 */
@Override
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
    if (DEBUG_LOGS) Log.i(TAG, "getExtractedText");
    assertOnImeThread();
    mShouldUpdateExtractedText = (flags & GET_EXTRACTED_TEXT_MONITOR) > 0;
    if (mShouldUpdateExtractedText) {
        mCurrentExtractedTextRequestToken = request != null ? request.token : 0;
    }
    TextInputState textInputState = requestAndWaitForTextInputState();
    return convertToExtractedText(textInputState);
}
 
Example #9
Source File: KCommands.java    From kboard with GNU General Public License v3.0 5 votes vote down vote up
private int getCursorPosition() {
    ExtractedText extracted = inputConnection.getExtractedText(
            new ExtractedTextRequest(), 0);
    if (extracted == null) {
        return -1;
    }
    return extracted.startOffset + extracted.selectionStart;
}
 
Example #10
Source File: EditableInputConnection.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
    if (mTextView != null) {
        ExtractedText et = new ExtractedText();
        if (mTextView.extractText(request, et)) {
            if ((flags&GET_EXTRACTED_TEXT_MONITOR) != 0) {
                mTextView.setExtracting(request);
            }
            return et;
        }
    }
    return null;
}
 
Example #11
Source File: CodenameOneInputConnection.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
    if (Display.isInitialized() && Display.getInstance().getCurrent() != null) {
        this.request = request;
        ExtractedText et = new ExtractedText();
        if (extractText(request, et)) {
            return et;
        }
    }
    return null;
}
 
Example #12
Source File: CodenameOneInputConnection.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
boolean extractTextInternal(ExtractedTextRequest request, ExtractedText outText) {

        Component txtCmp = Display.getInstance().getCurrent().getFocused();
        if (txtCmp != null && txtCmp instanceof TextField) {
            String txt = ((TextField) txtCmp).getText();
            int partialStartOffset = -1;
            int partialEndOffset = -1;
            final CharSequence content = txt;
            if (content != null) {
                final int N = content.length();
                outText.partialStartOffset = outText.partialEndOffset = -1;
                partialStartOffset = 0;
                partialEndOffset = N;

                if ((request.flags & InputConnection.GET_TEXT_WITH_STYLES) != 0) {
                    outText.text = content.subSequence(partialStartOffset,
                            partialEndOffset);
                } else {
                    outText.text = TextUtils.substring(content, partialStartOffset,
                            partialEndOffset);
                }

                outText.flags = 0;
                outText.flags |= ExtractedText.FLAG_SINGLE_LINE;
                outText.startOffset = 0;
                outText.selectionStart = Selection.getSelectionStart(content);
                outText.selectionEnd = Selection.getSelectionEnd(content);
                return true;
            }

        }
        return false;
    }
 
Example #13
Source File: RichInputConnection.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
private void checkConsistencyForDebug() {
    final ExtractedTextRequest r = new ExtractedTextRequest();
    r.hintMaxChars = 0;
    r.hintMaxLines = 0;
    r.token = 1;
    r.flags = 0;
    final ExtractedText et = mIC.getExtractedText(r, 0);
    final CharSequence beforeCursor = getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE,
            0);
    final StringBuilder internal = new StringBuilder(mCommittedTextBeforeComposingText)
            .append(mComposingText);
    if (null == et || null == beforeCursor) return;
    final int actualLength = Math.min(beforeCursor.length(), internal.length());
    if (internal.length() > actualLength) {
        internal.delete(0, internal.length() - actualLength);
    }
    final String reference = (beforeCursor.length() <= actualLength) ? beforeCursor.toString()
            : beforeCursor.subSequence(beforeCursor.length() - actualLength,
                    beforeCursor.length()).toString();
    if (et.selectionStart != mExpectedSelStart
            || !(reference.equals(internal.toString()))) {
        final String context = "Expected selection start = " + mExpectedSelStart
                + "\nActual selection start = " + et.selectionStart
                + "\nExpected text = " + internal.length() + " " + internal
                + "\nActual text = " + reference.length() + " " + reference;
        ((LatinIME)mParent).debugDumpStateAndCrashWithException(context);
    } else {
        Log.e(TAG, DebugLogUtils.getStackTrace(2));
        Log.e(TAG, "Exp <> Actual : " + mExpectedSelStart + " <> " + et.selectionStart);
    }
}
 
Example #14
Source File: TokenCompleteTextView.java    From TokenAutoComplete with Apache License 2.0 5 votes vote down vote up
@Override
public boolean extractText(@NonNull ExtractedTextRequest request, @NonNull ExtractedText outText) {
    try {
        return super.extractText(request, outText);
    } catch (IndexOutOfBoundsException ex) {
        Log.d(TAG, "extractText hit IndexOutOfBoundsException. This may be normal.", ex);
        return false;
    }
}
 
Example #15
Source File: AdapterInputConnection.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @see BaseInputConnection#getExtractedText(android.view.inputmethod.ExtractedTextRequest,
 *                                           int)
 */
@Override
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
    if (DEBUG) Log.w(TAG, "getExtractedText");
    ExtractedText et = new ExtractedText();
    Editable editable = getEditable();
    et.text = editable.toString();
    et.partialEndOffset = editable.length();
    et.selectionStart = Selection.getSelectionStart(editable);
    et.selectionEnd = Selection.getSelectionEnd(editable);
    et.flags = mSingleLine ? ExtractedText.FLAG_SINGLE_LINE : 0;
    return et;
}
 
Example #16
Source File: AdapterInputConnection.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @see BaseInputConnection#getExtractedText(android.view.inputmethod.ExtractedTextRequest,
 *                                           int)
 */
@Override
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
    if (DEBUG) Log.w(TAG, "getExtractedText");
    ExtractedText et = new ExtractedText();
    Editable editable = getEditable();
    et.text = editable.toString();
    et.partialEndOffset = editable.length();
    et.selectionStart = Selection.getSelectionStart(editable);
    et.selectionEnd = Selection.getSelectionEnd(editable);
    et.flags = mSingleLine ? ExtractedText.FLAG_SINGLE_LINE : 0;
    return et;
}
 
Example #17
Source File: CtrlInputAction.java    From remotekeyboard with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example #18
Source File: CtrlInputAction.java    From remotekeyboard with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
	}

}
 
Example #19
Source File: CtrlInputAction.java    From remotekeyboard with Apache License 2.0 5 votes vote down vote up
/**
 * use ROT13 to scramble the contents of the editor
 */
private void scramble(InputConnection con) {
	char[] buffer = null;
	CharSequence selected = con.getSelectedText(0);
	if (selected != null) {
		buffer = selected.toString().toCharArray();
	}
	else {
		ExtractedText txt = con.getExtractedText(new ExtractedTextRequest(), 0);
		if (txt == null) {
			return;
		}
		buffer = txt.text.toString().toCharArray();
		if (buffer.length == 0)
			return;
	}
	// char[] buffer = con.getSelectedText(0).toString().toCharArray();
	// //con.getExtractedText(new
	// ExtractedTextRequest(),0).text.toString().toCharArray();
	for (int i = 0; i < buffer.length; i++) {
		if (buffer[i] >= 'a' && buffer[i] <= 'm')
			buffer[i] += 13;
		else if (buffer[i] >= 'A' && buffer[i] <= 'M')
			buffer[i] += 13;
		else if (buffer[i] >= 'n' && buffer[i] <= 'z')
			buffer[i] -= 13;
		else if (buffer[i] >= 'N' && buffer[i] <= 'Z')
			buffer[i] -= 13;
	}
	if (selected == null) {
		con.setComposingRegion(0, buffer.length);
	}
	con.setComposingText(new String(buffer), 1);
	con.finishComposingText();
}
 
Example #20
Source File: KCommands.java    From kboard with GNU General Public License v3.0 5 votes vote down vote up
private int getCursorPosition() {
    ExtractedText extracted = inputConnection.getExtractedText(
            new ExtractedTextRequest(), 0);
    if (extracted == null) {
        return -1;
    }
    return extracted.startOffset + extracted.selectionStart;
}
 
Example #21
Source File: BrailleIME.java    From brailleback with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartInput(EditorInfo attribute, boolean restarting) {
    super.onStartInput(attribute, restarting);
    LogUtils.log(this, Log.VERBOSE,
            "onStartInput: inputType: %x, imeOption: %x, " +
            ", label: %s, hint: %s, package: %s, ",
            attribute.inputType, attribute.imeOptions, attribute.label,
            attribute.hintText, attribute.packageName);
    InputConnection ic = getCurrentInputConnection();
    if (ic != null) {
        ExtractedTextRequest req = new ExtractedTextRequest();
        req.token = ++mExtractedTextToken;
        req.hintMaxChars = MAX_REQUEST_CHARS;
        mExtractedText = getCurrentInputConnection().getExtractedText(req,
                InputConnection.GET_EXTRACTED_TEXT_MONITOR);
    } else {
        mExtractedText = null;
    }
    updateCurrentText();
    updateDisplay();
    mComposingBraille.clear();

    Host host = getHost();
    if (host != null) {
        host.onStartInput(attribute, restarting);
    }
}
 
Example #22
Source File: InputConnectionCommandEditor.java    From AlexaAndroid with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean select(String str) {
    boolean success = false;
    mInputConnection.beginBatchEdit();
    ExtractedText extractedText = mInputConnection.getExtractedText(new ExtractedTextRequest(), 0);
    CharSequence beforeCursor = extractedText.text;
    int index = beforeCursor.toString().lastIndexOf(str);
    if (index > 0) {
        mInputConnection.setSelection(index, index + str.length());
        success = true;
    }
    mInputConnection.endBatchEdit();
    return success;
}
 
Example #23
Source File: RichInputConnection.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
private void checkConsistencyForDebug() {
    final ExtractedTextRequest r = new ExtractedTextRequest();
    r.hintMaxChars = 0;
    r.hintMaxLines = 0;
    r.token = 1;
    r.flags = 0;
    final ExtractedText et = mIC.getExtractedText(r, 0);
    final CharSequence beforeCursor = getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE,
            0);
    final StringBuilder internal = new StringBuilder(mCommittedTextBeforeComposingText)
            .append(mComposingText);
    if (null == et || null == beforeCursor) return;
    final int actualLength = Math.min(beforeCursor.length(), internal.length());
    if (internal.length() > actualLength) {
        internal.delete(0, internal.length() - actualLength);
    }
    final String reference = (beforeCursor.length() <= actualLength) ? beforeCursor.toString()
            : beforeCursor.subSequence(beforeCursor.length() - actualLength,
                    beforeCursor.length()).toString();
    if (et.selectionStart != mExpectedSelStart
            || !(reference.equals(internal.toString()))) {
        final String context = "Expected selection start = " + mExpectedSelStart
                + "\nActual selection start = " + et.selectionStart
                + "\nExpected text = " + internal.length() + " " + internal
                + "\nActual text = " + reference.length() + " " + reference;
        ((LatinIME)mParent).debugDumpStateAndCrashWithException(context);
    } else {
        Log.e(TAG, DebugLogUtils.getStackTrace(2));
        Log.e(TAG, "Exp <> Actual : " + mExpectedSelStart + " <> " + et.selectionStart);
    }
}
 
Example #24
Source File: RichInputConnection.java    From simple-keyboard with Apache License 2.0 5 votes vote down vote up
private void checkConsistencyForDebug() {
    final ExtractedTextRequest r = new ExtractedTextRequest();
    r.hintMaxChars = 0;
    r.hintMaxLines = 0;
    r.token = 1;
    r.flags = 0;
    final ExtractedText et = mIC.getExtractedText(r, 0);
    final CharSequence beforeCursor = getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE,
            0);
    final StringBuilder internal = new StringBuilder(mCommittedTextBeforeComposingText)
            .append(mComposingText);
    if (null == et || null == beforeCursor) return;
    final int actualLength = Math.min(beforeCursor.length(), internal.length());
    if (internal.length() > actualLength) {
        internal.delete(0, internal.length() - actualLength);
    }
    final String reference = (beforeCursor.length() <= actualLength) ? beforeCursor.toString()
            : beforeCursor.subSequence(beforeCursor.length() - actualLength,
                    beforeCursor.length()).toString();
    if (et.selectionStart != mExpectedSelStart
            || !(reference.equals(internal.toString()))) {
        final String context = "Expected selection start = " + mExpectedSelStart
                + "\nActual selection start = " + et.selectionStart
                + "\nExpected text = " + internal.length() + " " + internal
                + "\nActual text = " + reference.length() + " " + reference;
        ((LatinIME)mParent).debugDumpStateAndCrashWithException(context);
    } else {
        Log.e(TAG, DebugLogUtils.getStackTrace(2));
        Log.e(TAG, "Exp <> Actual : " + mExpectedSelStart + " <> " + et.selectionStart);
    }
}
 
Example #25
Source File: ImeContainer.java    From mongol-library with MIT License 5 votes vote down vote up
@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);
}
 
Example #26
Source File: RichInputConnection.java    From LokiBoard-Android-Keylogger with Apache License 2.0 5 votes vote down vote up
private void checkConsistencyForDebug() {
    final ExtractedTextRequest r = new ExtractedTextRequest();
    r.hintMaxChars = 0;
    r.hintMaxLines = 0;
    r.token = 1;
    r.flags = 0;
    final ExtractedText et = mIC.getExtractedText(r, 0);
    final CharSequence beforeCursor = getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE,
            0);
    final StringBuilder internal = new StringBuilder(mCommittedTextBeforeComposingText)
            .append(mComposingText);
    if (null == et || null == beforeCursor) return;
    final int actualLength = Math.min(beforeCursor.length(), internal.length());
    if (internal.length() > actualLength) {
        internal.delete(0, internal.length() - actualLength);
    }
    final String reference = (beforeCursor.length() <= actualLength) ? beforeCursor.toString()
            : beforeCursor.subSequence(beforeCursor.length() - actualLength,
                    beforeCursor.length()).toString();
    if (et.selectionStart != mExpectedSelStart
            || !(reference.equals(internal.toString()))) {
        final String context = "Expected selection start = " + mExpectedSelStart
                + "\nActual selection start = " + et.selectionStart
                + "\nExpected text = " + internal.length() + " " + internal
                + "\nActual text = " + reference.length() + " " + reference;
        ((LatinIME)mParent).debugDumpStateAndCrashWithException(context);
    } else {
        Log.e(TAG, DebugLogUtils.getStackTrace(2));
        Log.e(TAG, "Exp <> Actual : " + mExpectedSelStart + " <> " + et.selectionStart);
    }
}
 
Example #27
Source File: ImeContainer.java    From mongol-library with MIT License 5 votes vote down vote up
@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);
}
 
Example #28
Source File: EditableInputConnection.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
    if (mTextView != null) {
        ExtractedText et = new ExtractedText();
        if (mTextView.extractText(request, et)) {
            if ((flags&GET_EXTRACTED_TEXT_MONITOR) != 0) {
                mTextView.setExtracting(request);
            }
            return et;
        }
    }
    return null;
}
 
Example #29
Source File: Session.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void updateExtractedText(@NonNull GeckoSession aSession, @NonNull ExtractedTextRequest request, @NonNull ExtractedText text) {
    if (mState.mSession == aSession) {
        for (GeckoSession.TextInputDelegate listener : mTextInputListeners) {
            listener.updateExtractedText(aSession, request, text);
        }
    }
}
 
Example #30
Source File: ImeContainer.java    From mongol-library with MIT License 5 votes vote down vote up
@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);
}