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

Commit fd3a3a11 authored by Abodunrinwa Toki's avatar Abodunrinwa Toki
Browse files

Hide floating toolbar when user interacts with screen.

- Adds an ActionMode.snooze(int) API.
- Clients call this to hide the floating toolbar on DOWN touch event.
- This is called repeatedly as a snooze timeout will re-show the
  toolbar.
- ActionMode.snooze(0) will "wake" the toolbar, reshowing it.
- Clients call this to re-show the toolbar on UP touch event.
- This CL also adds code to hide the toolbar when the "content rect"
  is changing.

Bug: 20148125
Change-Id: If5a9a15f72c73cad8ca01a4328a58570b3e29f66
parent 59c15e30
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -34438,6 +34438,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
  }
@@ -36501,6 +36503,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
@@ -36700,6 +36700,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
  }
@@ -38763,6 +38765,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