Search in sources :

Example 1 with ExtractEditText

use of android.inputmethodservice.ExtractEditText in project XobotOS by xamarin.

the class TextView method startSelectionActionMode.

/**
     *
     * @return true if the selection mode was actually started.
     */
private boolean startSelectionActionMode() {
    if (mSelectionActionMode != null) {
        // Selection action mode is already started
        return false;
    }
    if (!canSelectText() || !requestFocus()) {
        Log.w(LOG_TAG, "TextView does not support text selection. Action mode cancelled.");
        return false;
    }
    if (!hasSelection()) {
        // There may already be a selection on device rotation
        if (!selectCurrentWord()) {
            // No word found under cursor or text selection not permitted.
            return false;
        }
    }
    final InputMethodManager imm = InputMethodManager.peekInstance();
    boolean extractedTextModeWillBeStartedFullScreen = !(this instanceof ExtractEditText) && imm != null && imm.isFullscreenMode();
    // immediately hiding the newly created action bar, which would be visually distracting.
    if (!extractedTextModeWillBeStartedFullScreen) {
        ActionMode.Callback actionModeCallback = new SelectionActionModeCallback();
        mSelectionActionMode = startActionMode(actionModeCallback);
    }
    final boolean selectionStarted = mSelectionActionMode != null || extractedTextModeWillBeStartedFullScreen;
    if (selectionStarted && !mTextIsSelectable && imm != null) {
        // Show the IME to be able to replace text, except when selecting non editable text.
        imm.showSoftInput(this, 0, null);
    }
    return selectionStarted;
}
Also used : Callback(android.view.ActionMode.Callback) ExtractEditText(android.inputmethodservice.ExtractEditText) ActionMode(android.view.ActionMode) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 2 with ExtractEditText

use of android.inputmethodservice.ExtractEditText in project XobotOS by xamarin.

the class TextView method onFocusChanged.

@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    if (mTemporaryDetach) {
        // If we are temporarily in the detach state, then do nothing.
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        return;
    }
    mShowCursor = SystemClock.uptimeMillis();
    ensureEndedBatchEdit();
    if (focused) {
        int selStart = getSelectionStart();
        int selEnd = getSelectionEnd();
        // SelectAllOnFocus fields are highlighted and not selected. Do not start text selection
        // mode for these, unless there was a specific selection already started.
        final boolean isFocusHighlighted = mSelectAllOnFocus && selStart == 0 && selEnd == mText.length();
        mCreatedWithASelection = mFrozenWithFocus && hasSelection() && !isFocusHighlighted;
        if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) {
            // If a tap was used to give focus to that view, move cursor at tap position.
            // Has to be done before onTakeFocus, which can be overloaded.
            final int lastTapPosition = getLastTapPosition();
            if (lastTapPosition >= 0) {
                Selection.setSelection((Spannable) mText, lastTapPosition);
            }
            if (mMovement != null) {
                mMovement.onTakeFocus(this, (Spannable) mText, direction);
            }
            // It would be better to know why the DecorView does not have focus at that time.
            if (((this instanceof ExtractEditText) || mSelectionMoved) && selStart >= 0 && selEnd >= 0) {
                /*
                     * Someone intentionally set the selection, so let them
                     * do whatever it is that they wanted to do instead of
                     * the default on-focus behavior.  We reset the selection
                     * here instead of just skipping the onTakeFocus() call
                     * because some movement methods do something other than
                     * just setting the selection in theirs and we still
                     * need to go through that path.
                     */
                Selection.setSelection((Spannable) mText, selStart, selEnd);
            }
            if (mSelectAllOnFocus) {
                selectAll();
            }
            mTouchFocusSelected = true;
        }
        mFrozenWithFocus = false;
        mSelectionMoved = false;
        if (mText instanceof Spannable) {
            Spannable sp = (Spannable) mText;
            MetaKeyKeyListener.resetMetaState(sp);
        }
        makeBlink();
        if (mError != null) {
            showError();
        }
    } else {
        if (mError != null) {
            hideError();
        }
        // Don't leave us in the middle of a batch edit.
        onEndBatchEdit();
        if (this instanceof ExtractEditText) {
            // terminateTextSelectionMode removes selection, which we want to keep when
            // ExtractEditText goes out of focus.
            final int selStart = getSelectionStart();
            final int selEnd = getSelectionEnd();
            hideControllers();
            Selection.setSelection((Spannable) mText, selStart, selEnd);
        } else {
            hideControllers();
            downgradeEasyCorrectionSpans();
        }
        // No need to create the controller
        if (mSelectionModifierCursorController != null) {
            mSelectionModifierCursorController.resetTouchOffsets();
        }
    }
    startStopMarquee(focused);
    if (mTransformation != null) {
        mTransformation.onFocusChanged(this, mText, focused, direction, previouslyFocusedRect);
    }
    super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
Also used : ExtractEditText(android.inputmethodservice.ExtractEditText) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Spannable(android.text.Spannable)

Example 3 with ExtractEditText

use of android.inputmethodservice.ExtractEditText in project XobotOS by xamarin.

the class TextView method onPreDraw.

/**
     * {@inheritDoc}
     */
public boolean onPreDraw() {
    if (mPreDrawState != PREDRAW_PENDING) {
        return true;
    }
    if (mLayout == null) {
        assumeLayout();
    }
    boolean changed = false;
    if (mMovement != null) {
        /* This code also provides auto-scrolling when a cursor is moved using a
             * CursorController (insertion point or selection limits).
             * For selection, ensure start or end is visible depending on controller's state.
             */
        int curs = getSelectionEnd();
        // Do not create the controller if it is not already created.
        if (mSelectionModifierCursorController != null && mSelectionModifierCursorController.isSelectionStartDragged()) {
            curs = getSelectionStart();
        }
        /*
             * TODO: This should really only keep the end in view if
             * it already was before the text changed.  I'm not sure
             * of a good way to tell from here if it was.
             */
        if (curs < 0 && (mGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
            curs = mText.length();
        }
        if (curs >= 0) {
            changed = bringPointIntoView(curs);
        }
    } else {
        changed = bringTextIntoView();
    }
    //   a screen rotation) since layout is not yet initialized at that point.
    if (mCreatedWithASelection) {
        startSelectionActionMode();
        mCreatedWithASelection = false;
    }
    // not be set. Do the test here instead.
    if (this instanceof ExtractEditText && hasSelection()) {
        startSelectionActionMode();
    }
    mPreDrawState = PREDRAW_DONE;
    return !changed;
}
Also used : ExtractEditText(android.inputmethodservice.ExtractEditText) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 4 with ExtractEditText

use of android.inputmethodservice.ExtractEditText in project android_frameworks_base by ParanoidAndroid.

the class Editor method onFocusChanged.

void onFocusChanged(boolean focused, int direction) {
    mShowCursor = SystemClock.uptimeMillis();
    ensureEndedBatchEdit();
    if (focused) {
        int selStart = mTextView.getSelectionStart();
        int selEnd = mTextView.getSelectionEnd();
        // SelectAllOnFocus fields are highlighted and not selected. Do not start text selection
        // mode for these, unless there was a specific selection already started.
        final boolean isFocusHighlighted = mSelectAllOnFocus && selStart == 0 && selEnd == mTextView.getText().length();
        mCreatedWithASelection = mFrozenWithFocus && mTextView.hasSelection() && !isFocusHighlighted;
        if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) {
            // If a tap was used to give focus to that view, move cursor at tap position.
            // Has to be done before onTakeFocus, which can be overloaded.
            final int lastTapPosition = getLastTapPosition();
            if (lastTapPosition >= 0) {
                Selection.setSelection((Spannable) mTextView.getText(), lastTapPosition);
            }
            // Note this may have to be moved out of the Editor class
            MovementMethod mMovement = mTextView.getMovementMethod();
            if (mMovement != null) {
                mMovement.onTakeFocus(mTextView, (Spannable) mTextView.getText(), direction);
            }
            // It would be better to know why the DecorView does not have focus at that time.
            if (((mTextView instanceof ExtractEditText) || mSelectionMoved) && selStart >= 0 && selEnd >= 0) {
                /*
                     * Someone intentionally set the selection, so let them
                     * do whatever it is that they wanted to do instead of
                     * the default on-focus behavior.  We reset the selection
                     * here instead of just skipping the onTakeFocus() call
                     * because some movement methods do something other than
                     * just setting the selection in theirs and we still
                     * need to go through that path.
                     */
                Selection.setSelection((Spannable) mTextView.getText(), selStart, selEnd);
            }
            if (mSelectAllOnFocus) {
                mTextView.selectAllText();
            }
            mTouchFocusSelected = true;
        }
        mFrozenWithFocus = false;
        mSelectionMoved = false;
        if (mError != null) {
            showError();
        }
        makeBlink();
    } else {
        if (mError != null) {
            hideError();
        }
        // Don't leave us in the middle of a batch edit.
        mTextView.onEndBatchEdit();
        if (mTextView instanceof ExtractEditText) {
            // terminateTextSelectionMode removes selection, which we want to keep when
            // ExtractEditText goes out of focus.
            final int selStart = mTextView.getSelectionStart();
            final int selEnd = mTextView.getSelectionEnd();
            hideControllers();
            Selection.setSelection((Spannable) mTextView.getText(), selStart, selEnd);
        } else {
            if (mTemporaryDetach)
                mPreserveDetachedSelection = true;
            hideControllers();
            if (mTemporaryDetach)
                mPreserveDetachedSelection = false;
            downgradeEasyCorrectionSpans();
        }
        // No need to create the controller
        if (mSelectionModifierCursorController != null) {
            mSelectionModifierCursorController.resetTouchOffsets();
        }
    }
}
Also used : ExtractEditText(android.inputmethodservice.ExtractEditText) MovementMethod(android.text.method.MovementMethod) Paint(android.graphics.Paint)

Example 5 with ExtractEditText

use of android.inputmethodservice.ExtractEditText in project android_frameworks_base by ParanoidAndroid.

the class TextView method onPreDraw.

/**
     * {@inheritDoc}
     */
public boolean onPreDraw() {
    if (mLayout == null) {
        assumeLayout();
    }
    boolean changed = false;
    if (mMovement != null) {
        /* This code also provides auto-scrolling when a cursor is moved using a
             * CursorController (insertion point or selection limits).
             * For selection, ensure start or end is visible depending on controller's state.
             */
        int curs = getSelectionEnd();
        // Do not create the controller if it is not already created.
        if (mEditor != null && mEditor.mSelectionModifierCursorController != null && mEditor.mSelectionModifierCursorController.isSelectionStartDragged()) {
            curs = getSelectionStart();
        }
        /*
             * TODO: This should really only keep the end in view if
             * it already was before the text changed.  I'm not sure
             * of a good way to tell from here if it was.
             */
        if (curs < 0 && (mGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
            curs = mText.length();
        }
        if (curs >= 0) {
            changed = bringPointIntoView(curs);
        }
    } else {
        changed = bringTextIntoView();
    }
    //   a screen rotation) since layout is not yet initialized at that point.
    if (mEditor != null && mEditor.mCreatedWithASelection) {
        mEditor.startSelectionActionMode();
        mEditor.mCreatedWithASelection = false;
    }
    // not be set. Do the test here instead.
    if (this instanceof ExtractEditText && hasSelection() && mEditor != null) {
        mEditor.startSelectionActionMode();
    }
    getViewTreeObserver().removeOnPreDrawListener(this);
    mPreDrawRegistered = false;
    return !changed;
}
Also used : ExtractEditText(android.inputmethodservice.ExtractEditText) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Aggregations

ExtractEditText (android.inputmethodservice.ExtractEditText)5 Paint (android.graphics.Paint)4 TextPaint (android.text.TextPaint)3 Spannable (android.text.Spannable)1 MovementMethod (android.text.method.MovementMethod)1 ActionMode (android.view.ActionMode)1 Callback (android.view.ActionMode.Callback)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1