Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3f321e6 authored by Clara Bayarri's avatar Clara Bayarri Committed by Android Git Automerger
Browse files

am c1f28bc9: Merge "Separate the SelectionActionMode into Insertion and Selection." into mnc-dev

* commit 'c1f28bc9':
  Separate the SelectionActionMode into Insertion and Selection.
parents b7ba71bb c1f28bc9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -41542,6 +41542,7 @@ package android.widget {
    method public int getCompoundPaddingTop();
    method public final int getCurrentHintTextColor();
    method public final int getCurrentTextColor();
    method public android.view.ActionMode.Callback getCustomInsertionActionModeCallback();
    method public android.view.ActionMode.Callback getCustomSelectionActionModeCallback();
    method protected boolean getDefaultEditable();
    method protected android.text.method.MovementMethod getDefaultMovementMethod();
@@ -41644,6 +41645,7 @@ package android.widget {
    method public void setCompoundDrawablesWithIntrinsicBounds(int, int, int, int);
    method public void setCompoundDrawablesWithIntrinsicBounds(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable);
    method public void setCursorVisible(boolean);
    method public void setCustomInsertionActionModeCallback(android.view.ActionMode.Callback);
    method public void setCustomSelectionActionModeCallback(android.view.ActionMode.Callback);
    method public final void setEditableFactory(android.text.Editable.Factory);
    method public void setElegantTextHeight(boolean);
+2 −0
Original line number Diff line number Diff line
@@ -44121,6 +44121,7 @@ package android.widget {
    method public int getCompoundPaddingTop();
    method public final int getCurrentHintTextColor();
    method public final int getCurrentTextColor();
    method public android.view.ActionMode.Callback getCustomInsertionActionModeCallback();
    method public android.view.ActionMode.Callback getCustomSelectionActionModeCallback();
    method protected boolean getDefaultEditable();
    method protected android.text.method.MovementMethod getDefaultMovementMethod();
@@ -44223,6 +44224,7 @@ package android.widget {
    method public void setCompoundDrawablesWithIntrinsicBounds(int, int, int, int);
    method public void setCompoundDrawablesWithIntrinsicBounds(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable);
    method public void setCursorVisible(boolean);
    method public void setCustomInsertionActionModeCallback(android.view.ActionMode.Callback);
    method public void setCustomSelectionActionModeCallback(android.view.ActionMode.Callback);
    method public final void setEditableFactory(android.text.Editable.Factory);
    method public void setElegantTextHeight(boolean);
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public class ExtractEditText extends EditText {
        if (mIME != null && mIME.onExtractTextContextMenuItem(id)) {
            // Mode was started on Extracted, needs to be stopped here.
            // Cut and paste will change the text, which stops selection mode.
            if (id == android.R.id.copy) stopSelectionActionMode();
            if (id == android.R.id.copy) stopTextActionMode();
            return true;
        }
        return super.onTextContextMenuItem(id);
+124 −113

File changed.

Preview size limit exceeded, changes collapsed.

+56 −19
Original line number Diff line number Diff line
@@ -1481,7 +1481,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                }
            }
            if (mEditor.hasSelectionController()) {
                mEditor.startSelectionActionModeWithSelection();
                mEditor.startSelectionActionMode();
            }
        }
    }
@@ -5282,7 +5282,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        // - onFocusChanged cannot start it when focus is given to a view with selected text (after
        //   a screen rotation) since layout is not yet initialized at that point.
        if (mEditor != null && mEditor.mCreatedWithASelection) {
            mEditor.startSelectionActionModeWithSelection();
            mEditor.startSelectionActionMode();
            mEditor.mCreatedWithASelection = false;
        }

@@ -5290,7 +5290,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        // ExtractEditText does not call onFocus when it is displayed, and mHasSelectionOnFocus can
        // not be set. Do the test here instead.
        if (this instanceof ExtractEditText && hasSelection() && mEditor != null) {
            mEditor.startSelectionActionModeWithSelection();
            mEditor.startSelectionActionMode();
        }

        unregisterForPreDraw();
@@ -5908,7 +5908,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    @Override
    public boolean onKeyPreIme(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            boolean isInSelectionMode = mEditor != null && mEditor.mSelectionActionMode != null;
            boolean isInSelectionMode = mEditor != null && mEditor.mTextActionMode != null;

            if (isInSelectionMode) {
                if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
@@ -5923,7 +5923,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                        state.handleUpEvent(event);
                    }
                    if (event.isTracking() && !event.isCanceled()) {
                        stopSelectionActionMode();
                        stopTextActionMode();
                        return true;
                    }
                }
@@ -6092,8 +6092,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

                // Has to be done on key down (and not on key up) to correctly be intercepted.
            case KeyEvent.KEYCODE_BACK:
                if (mEditor != null && mEditor.mSelectionActionMode != null) {
                    stopSelectionActionMode();
                if (mEditor != null && mEditor.mTextActionMode != null) {
                    stopTextActionMode();
                    return -1;
                }
                break;
@@ -6423,7 +6423,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        // extracted mode will start. Some text is selected though, and will trigger an action mode
        // in the extracted view.
        mEditor.hideControllers();
        stopSelectionActionMode();
        stopTextActionMode();
    }

    /**
@@ -8258,7 +8258,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        super.onVisibilityChanged(changedView, visibility);
        if (mEditor != null && visibility != VISIBLE) {
            mEditor.hideControllers();
            stopSelectionActionMode();
            stopTextActionMode();
        }
    }

@@ -8976,7 +8976,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                            Selection.setSelection((Spannable) text, start, end);
                            // Make sure selection mode is engaged.
                            if (mEditor != null) {
                                mEditor.startSelectionActionModeWithSelection();
                                mEditor.startSelectionActionMode();
                            }
                            return true;
                        }
@@ -9100,12 +9100,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            case ID_CUT:
                setPrimaryClip(ClipData.newPlainText(null, getTransformedText(min, max)));
                deleteText_internal(min, max);
                stopSelectionActionMode();
                stopTextActionMode();
                return true;

            case ID_COPY:
                setPrimaryClip(ClipData.newPlainText(null, getTransformedText(min, max)));
                stopSelectionActionMode();
                stopTextActionMode();
                return true;

            case ID_REPLACE:
@@ -9195,14 +9195,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     * selection is initiated in this View.
     *
     * The standard implementation populates the menu with a subset of Select All, Cut, Copy,
     * Paste and Share actions, depending on what this View supports.
     * Paste, Replace and Share actions, depending on what this View supports.
     *
     * A custom implementation can add new entries in the default menu in its
     * {@link android.view.ActionMode.Callback#onPrepareActionMode(ActionMode, Menu)} method. The
     * default actions can also be removed from the menu using
     * {@link android.view.Menu#removeItem(int)} and passing {@link android.R.id#selectAll},
     * {@link android.R.id#cut}, {@link android.R.id#copy}, {@link android.R.id#paste} or
     * {@link android.R.id#shareText} ids as parameters.
     * {@link android.R.id#cut}, {@link android.R.id#copy}, {@link android.R.id#paste},
     * {@link android.R.id#replaceText} or {@link android.R.id#shareText} ids as parameters.
     *
     * Returning false from
     * {@link android.view.ActionMode.Callback#onCreateActionMode(ActionMode, Menu)} will prevent
@@ -9229,12 +9229,49 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        return mEditor == null ? null : mEditor.mCustomSelectionActionModeCallback;
    }

    /**
     * If provided, this ActionMode.Callback will be used to create the ActionMode when text
     * insertion is initiated in this View.
     *
     * The standard implementation populates the menu with a subset of Select All,
     * Paste and Replace actions, depending on what this View supports.
     *
     * A custom implementation can add new entries in the default menu in its
     * {@link android.view.ActionMode.Callback#onPrepareActionMode(ActionMode, Menu)} method. The
     * default actions can also be removed from the menu using
     * {@link android.view.Menu#removeItem(int)} and passing {@link android.R.id#selectAll},
     * {@link android.R.id#paste} or {@link android.R.id#replaceText} ids as parameters.
     *
     * Returning false from
     * {@link android.view.ActionMode.Callback#onCreateActionMode(ActionMode, Menu)} will prevent
     * the action mode from being started.
     *
     * Action click events should be handled by the custom implementation of
     * {@link android.view.ActionMode.Callback#onActionItemClicked(ActionMode, MenuItem)}.
     *
     * Note that text insertion mode is not started when a TextView receives focus and the
     * {@link android.R.attr#selectAllOnFocus} flag has been set.
     */
    public void setCustomInsertionActionModeCallback(ActionMode.Callback actionModeCallback) {
        createEditorIfNeeded();
        mEditor.mCustomInsertionActionModeCallback = actionModeCallback;
    }

    /**
     * Retrieves the value set in {@link #setCustomInsertionActionModeCallback}. Default is null.
     *
     * @return The current custom insertion callback.
     */
    public ActionMode.Callback getCustomInsertionActionModeCallback() {
        return mEditor == null ? null : mEditor.mCustomInsertionActionModeCallback;
    }

    /**
     * @hide
     */
    protected void stopSelectionActionMode() {
    protected void stopTextActionMode() {
        if (mEditor != null) {
            mEditor.stopSelectionActionMode();
            mEditor.stopTextActionMode();
        }
    }

@@ -9346,7 +9383,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    }
                }
            }
            stopSelectionActionMode();
            stopTextActionMode();
            sLastCutCopyOrTextChangedTime = 0;
        }
    }
@@ -9359,7 +9396,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            sharingIntent.removeExtra(android.content.Intent.EXTRA_TEXT);
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, selectedText);
            getContext().startActivity(Intent.createChooser(sharingIntent, null));
            stopSelectionActionMode();
            stopTextActionMode();
        }
    }