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

Commit 1f21d2a8 authored by Abodunrinwa Toki's avatar Abodunrinwa Toki Committed by Android (Google) Code Review
Browse files

Merge "Hide floating toolbar when user interacts with screen." into mnc-dev

parents 7597dc7c fd3a3a11
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -34443,6 +34443,8 @@ package android.view {
    method public abstract void setTitle(int);
    method public void setTitleOptionalHint(boolean);
    method public void setType(int);
    method public void snooze(int);
    field public static final int SNOOZE_TIME_DEFAULT;
    field public static final int TYPE_FLOATING = 1; // 0x1
    field public static final int TYPE_PRIMARY = 0; // 0x0
  }
@@ -36507,6 +36509,7 @@ package android.view {
  public class ViewConfiguration {
    ctor public deprecated ViewConfiguration();
    method public static android.view.ViewConfiguration get(android.content.Context);
    method public static int getDefaultActionModeSnoozeTime();
    method public static int getDoubleTapTimeout();
    method public static deprecated int getEdgeSlop();
    method public static deprecated int getFadingEdgeLength();
+3 −0
Original line number Diff line number Diff line
@@ -36706,6 +36706,8 @@ package android.view {
    method public abstract void setTitle(int);
    method public void setTitleOptionalHint(boolean);
    method public void setType(int);
    method public void snooze(int);
    field public static final int SNOOZE_TIME_DEFAULT;
    field public static final int TYPE_FLOATING = 1; // 0x1
    field public static final int TYPE_PRIMARY = 0; // 0x0
  }
@@ -38770,6 +38772,7 @@ package android.view {
  public class ViewConfiguration {
    ctor public deprecated ViewConfiguration();
    method public static android.view.ViewConfiguration get(android.content.Context);
    method public static int getDefaultActionModeSnoozeTime();
    method public static int getDoubleTapTimeout();
    method public static deprecated int getEdgeSlop();
    method public static deprecated int getFadingEdgeLength();
+19 −0
Original line number Diff line number Diff line
@@ -44,6 +44,12 @@ public abstract class ActionMode {
     */
    public static final int TYPE_FLOATING = 1;

    /**
     * Default snooze time.
     */
    public static final int SNOOZE_TIME_DEFAULT =
            ViewConfiguration.getDefaultActionModeSnoozeTime();

    private Object mTag;
    private boolean mTitleOptionalHint;
    private int mType = TYPE_PRIMARY;
@@ -206,6 +212,19 @@ public abstract class ActionMode {
     */
    public void invalidateContentRect() {}

    /**
     * Hide the action mode view from obstructing the content below for a short period.
     * This only makes sense for action modes that support dynamic positioning on the screen.
     * If this method is called again before the snooze time expires, the later snooze will
     * cancel the former and then take effect.
     * NOTE that there is an internal limit to how long the mode can be snoozed for. It's typically
     * about a few seconds.
     *
     * @param snoozeTime The number of milliseconds to snooze for.
     * @see #SNOOZE_TIME_DEFAULT
     */
    public void snooze(int snoozeTime) {}

    /**
     * Finish and close this action mode. The action mode's {@link ActionMode.Callback} will
     * have its {@link Callback#onDestroyActionMode(ActionMode)} method called.
+12 −0
Original line number Diff line number Diff line
@@ -212,6 +212,11 @@ public class ViewConfiguration {
     */
    private static final int OVERFLING_DISTANCE = 6;

    /**
     * Default time to snooze an action mode for.
     */
    private static final int ACTION_MODE_SNOOZE_TIME_DEFAULT = 2000;

    /**
     * Configuration values for overriding {@link #hasPermanentMenuKey()} behavior.
     * These constants must match the definition in res/values/config.xml.
@@ -731,6 +736,13 @@ public class ViewConfiguration {
        return SCROLL_FRICTION;
    }

    /**
     * @return the default duration in milliseconds for {@link ActionMode#snooze(int)}.
     */
    public static int getDefaultActionModeSnoozeTime() {
        return ACTION_MODE_SNOOZE_TIME_DEFAULT;
    }

    /**
     * Report if the device has a permanent menu key available to the user.
     *
+56 −0
Original line number Diff line number Diff line
@@ -233,6 +233,24 @@ public class Editor {

    final CursorAnchorInfoNotifier mCursorAnchorInfoNotifier = new CursorAnchorInfoNotifier();

    private final Runnable mHideFloatingToolbar = new Runnable() {
        @Override
        public void run() {
            if (mSelectionActionMode != null) {
                mSelectionActionMode.snooze(ActionMode.SNOOZE_TIME_DEFAULT);
            }
        }
    };

    private final Runnable mShowFloatingToolbar = new Runnable() {
        @Override
        public void run() {
            if (mSelectionActionMode != null) {
                mSelectionActionMode.snooze(0);  // snooze off.
            }
        }
    };

    Editor(TextView textView) {
        mTextView = textView;
        // Synchronize the filter list, which places the undo input filter at the end.
@@ -358,6 +376,9 @@ public class Editor {
            mTextView.removeCallbacks(mSelectionModeWithoutSelectionRunnable);
        }

        mTextView.removeCallbacks(mHideFloatingToolbar);
        mTextView.removeCallbacks(mShowFloatingToolbar);

        destroyDisplayListsData();

        if (mSpellChecker != null) {
@@ -1169,6 +1190,8 @@ public class Editor {
    }

    void onTouchEvent(MotionEvent event) {
        updateFloatingToolbarVisibility(event);

        if (hasSelectionController()) {
            getSelectionController().onTouchEvent(event);
        }
@@ -1189,6 +1212,37 @@ public class Editor {
        }
    }

    private void updateFloatingToolbarVisibility(MotionEvent event) {
        if (mSelectionActionMode != null) {
            switch (event.getActionMasked()) {
                case MotionEvent.ACTION_MOVE:
                    hideFloatingToolbar();
                    break;
                case MotionEvent.ACTION_UP:  // fall through
                case MotionEvent.ACTION_CANCEL:
                    showFloatingToolbar();
            }
        }
    }

    private void hideFloatingToolbar() {
        if (mSelectionActionMode != null) {
            mTextView.removeCallbacks(mShowFloatingToolbar);
            // Delay the "hide" a little bit just in case a "show" will happen almost immediately.
            mTextView.postDelayed(mHideFloatingToolbar, 100);
        }
    }

    private void showFloatingToolbar() {
        if (mSelectionActionMode != null) {
            mTextView.removeCallbacks(mHideFloatingToolbar);
            // Delay "show" so it doesn't interfere with click confirmations
            // or double-clicks that could "dismiss" the floating toolbar.
            int delay = ViewConfiguration.getDoubleTapTimeout();
            mTextView.postDelayed(mShowFloatingToolbar, delay);
        }
    }

    public void beginBatchEdit() {
        mInBatchEditControllers = true;
        final InputMethodState ims = mInputMethodState;
@@ -3661,6 +3715,8 @@ public class Editor {

        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            updateFloatingToolbarVisibility(ev);

            switch (ev.getActionMasked()) {
                case MotionEvent.ACTION_DOWN: {
                    startTouchUpFilter(getCurrentCursorOffset());
Loading