Java Code Examples for android.view.inputmethod.ExtractedText#FLAG_SINGLE_LINE

The following examples show how to use android.view.inputmethod.ExtractedText#FLAG_SINGLE_LINE . 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: ThreadedInputConnection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private ExtractedText convertToExtractedText(TextInputState textInputState) {
    if (textInputState == null) return null;
    ExtractedText extractedText = new ExtractedText();
    extractedText.text = textInputState.text();
    extractedText.partialEndOffset = textInputState.text().length();
    // Set the partial start offset to -1 because the content is the full text.
    // See: Android documentation for ExtractedText#partialStartOffset
    extractedText.partialStartOffset = -1;
    extractedText.selectionStart = textInputState.selection().start();
    extractedText.selectionEnd = textInputState.selection().end();
    extractedText.flags = textInputState.singleLine() ? ExtractedText.FLAG_SINGLE_LINE : 0;
    return extractedText;
}
 
Example 2
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 3
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 4
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;
}