Search in sources :

Example 36 with Editable

use of android.text.Editable in project android_frameworks_base by ResurrectionRemix.

the class BaseInputConnection method setComposingRegion.

public boolean setComposingRegion(int start, int end) {
    final Editable content = getEditable();
    if (content != null) {
        beginBatchEdit();
        removeComposingSpans(content);
        int a = start;
        int b = end;
        if (a > b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        // Clip the end points to be within the content bounds.
        final int length = content.length();
        if (a < 0)
            a = 0;
        if (b < 0)
            b = 0;
        if (a > length)
            a = length;
        if (b > length)
            b = length;
        ensureDefaultComposingSpans();
        if (mDefaultComposingSpans != null) {
            for (int i = 0; i < mDefaultComposingSpans.length; ++i) {
                content.setSpan(mDefaultComposingSpans[i], a, b, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
            }
        }
        content.setSpan(COMPOSING, a, b, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
        // Note: sendCurrentText does nothing unless mDummyMode is set
        sendCurrentText();
        endBatchEdit();
    }
    return true;
}
Also used : Editable(android.text.Editable)

Example 37 with Editable

use of android.text.Editable in project android_frameworks_base by ResurrectionRemix.

the class BaseInputConnection method deleteSurroundingTextInCodePoints.

/**
     * The default implementation performs the deletion around the current selection position of the
     * editable text.
     * @param beforeLength The number of characters before the cursor to be deleted, in code points.
     *        If this is greater than the number of existing characters between the beginning of the
     *        text and the cursor, then this method does not fail but deletes all the characters in
     *        that range.
     * @param afterLength The number of characters after the cursor to be deleted, in code points.
     *        If this is greater than the number of existing characters between the cursor and
     *        the end of the text, then this method does not fail but deletes all the characters in
     *        that range.
     */
public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) {
    if (DEBUG)
        Log.v(TAG, "deleteSurroundingText " + beforeLength + " / " + afterLength);
    final Editable content = getEditable();
    if (content == null)
        return false;
    beginBatchEdit();
    int a = Selection.getSelectionStart(content);
    int b = Selection.getSelectionEnd(content);
    if (a > b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    // Ignore the composing text.
    int ca = getComposingSpanStart(content);
    int cb = getComposingSpanEnd(content);
    if (cb < ca) {
        int tmp = ca;
        ca = cb;
        cb = tmp;
    }
    if (ca != -1 && cb != -1) {
        if (ca < a)
            a = ca;
        if (cb > b)
            b = cb;
    }
    if (a >= 0 && b >= 0) {
        final int start = findIndexBackward(content, a, Math.max(beforeLength, 0));
        if (start != INVALID_INDEX) {
            final int end = findIndexForward(content, b, Math.max(afterLength, 0));
            if (end != INVALID_INDEX) {
                final int numDeleteBefore = a - start;
                if (numDeleteBefore > 0) {
                    content.delete(start, a);
                }
                final int numDeleteAfter = end - b;
                if (numDeleteAfter > 0) {
                    content.delete(b - numDeleteBefore, end - numDeleteBefore);
                }
            }
        }
    // NOTE: You may think we should return false here if start and/or end is INVALID_INDEX,
    // but the truth is that IInputConnectionWrapper running in the middle of IPC calls
    // always returns true to the IME without waiting for the completion of this method as
    // IInputConnectionWrapper#isAtive() returns true.  This is actually why some methods
    // including this method look like asynchronous calls from the IME.
    }
    endBatchEdit();
    return true;
}
Also used : Editable(android.text.Editable)

Example 38 with Editable

use of android.text.Editable in project android_frameworks_base by ResurrectionRemix.

the class BaseInputConnection method getCursorCapsMode.

/**
     * The default implementation uses TextUtils.getCapsMode to get the
     * cursor caps mode for the current selection position in the editable
     * text, unless in dummy mode in which case 0 is always returned.
     */
public int getCursorCapsMode(int reqModes) {
    if (mDummyMode)
        return 0;
    final Editable content = getEditable();
    if (content == null)
        return 0;
    int a = Selection.getSelectionStart(content);
    int b = Selection.getSelectionEnd(content);
    if (a > b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    return TextUtils.getCapsMode(content, a, reqModes);
}
Also used : Editable(android.text.Editable)

Example 39 with Editable

use of android.text.Editable in project android_frameworks_base by ResurrectionRemix.

the class BaseInputConnection method setSelection.

/**
     * The default implementation changes the selection position in the
     * current editable text.
     */
public boolean setSelection(int start, int end) {
    if (DEBUG)
        Log.v(TAG, "setSelection " + start + ", " + end);
    final Editable content = getEditable();
    if (content == null)
        return false;
    int len = content.length();
    if (start > len || end > len || start < 0 || end < 0) {
        // anyway.
        return true;
    }
    if (start == end && MetaKeyKeyListener.getMetaState(content, MetaKeyKeyListener.META_SELECTING) != 0) {
        // If we are in selection mode, then we want to extend the
        // selection instead of replacing it.
        Selection.extendSelection(content, start);
    } else {
        Selection.setSelection(content, start, end);
    }
    return true;
}
Also used : Editable(android.text.Editable)

Example 40 with Editable

use of android.text.Editable in project android_frameworks_base by ResurrectionRemix.

the class BaseInputConnection method getTextBeforeCursor.

/**
     * The default implementation returns the given amount of text from the
     * current cursor position in the buffer.
     */
public CharSequence getTextBeforeCursor(int length, int flags) {
    final Editable content = getEditable();
    if (content == null)
        return null;
    int a = Selection.getSelectionStart(content);
    int b = Selection.getSelectionEnd(content);
    if (a > b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    if (a <= 0) {
        return "";
    }
    if (length > a) {
        length = a;
    }
    if ((flags & GET_TEXT_WITH_STYLES) != 0) {
        return content.subSequence(a - length, a);
    }
    return TextUtils.substring(content, a - length, a);
}
Also used : Editable(android.text.Editable)

Aggregations

Editable (android.text.Editable)881 TextWatcher (android.text.TextWatcher)414 View (android.view.View)293 TextView (android.widget.TextView)217 EditText (android.widget.EditText)144 Paint (android.graphics.Paint)102 ImageView (android.widget.ImageView)94 Intent (android.content.Intent)81 AdapterView (android.widget.AdapterView)81 KeyEvent (android.view.KeyEvent)74 TextPaint (android.text.TextPaint)69 InputMethodManager (android.view.inputmethod.InputMethodManager)64 ListView (android.widget.ListView)64 DialogInterface (android.content.DialogInterface)57 SuppressLint (android.annotation.SuppressLint)56 Spannable (android.text.Spannable)51 AlertDialog (android.app.AlertDialog)46 RecyclerView (android.support.v7.widget.RecyclerView)45 ArrayList (java.util.ArrayList)43 Button (android.widget.Button)41