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

Commit 267c6b2a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Avoid FloatingToolbar flickers"

parents 516e4d3c 4a7aeb3c
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -1387,7 +1387,7 @@ public class Editor {
        if (mTextActionMode != null) {
        if (mTextActionMode != null) {
            switch (event.getActionMasked()) {
            switch (event.getActionMasked()) {
                case MotionEvent.ACTION_MOVE:
                case MotionEvent.ACTION_MOVE:
                    hideFloatingToolbar();
                    hideFloatingToolbar(ActionMode.DEFAULT_HIDE_DURATION);
                    break;
                    break;
                case MotionEvent.ACTION_UP:  // fall through
                case MotionEvent.ACTION_UP:  // fall through
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_CANCEL:
@@ -1396,10 +1396,10 @@ public class Editor {
        }
        }
    }
    }


    private void hideFloatingToolbar() {
    void hideFloatingToolbar(int duration) {
        if (mTextActionMode != null) {
        if (mTextActionMode != null) {
            mTextView.removeCallbacks(mShowFloatingToolbar);
            mTextView.removeCallbacks(mShowFloatingToolbar);
            mTextActionMode.hide(ActionMode.DEFAULT_HIDE_DURATION);
            mTextActionMode.hide(duration);
        }
        }
    }
    }


+6 −0
Original line number Original line Diff line number Diff line
@@ -374,6 +374,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    private static final int KEY_DOWN_HANDLED_BY_KEY_LISTENER = 1;
    private static final int KEY_DOWN_HANDLED_BY_KEY_LISTENER = 1;
    private static final int KEY_DOWN_HANDLED_BY_MOVEMENT_METHOD = 2;
    private static final int KEY_DOWN_HANDLED_BY_MOVEMENT_METHOD = 2;


    private static final int FLOATING_TOOLBAR_SELECT_ALL_REFRESH_DELAY = 500;

    // System wide time for last cut, copy or text changed action.
    // System wide time for last cut, copy or text changed action.
    static long sLastCutCopyOrTextChangedTime;
    static long sLastCutCopyOrTextChangedTime;


@@ -11138,6 +11140,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    }
    }


    boolean selectAllText() {
    boolean selectAllText() {
        if (mEditor != null) {
            // Hide the toolbar before changing the selection to avoid flickering.
            mEditor.hideFloatingToolbar(FLOATING_TOOLBAR_SELECT_ALL_REFRESH_DELAY);
        }
        final int length = mText.length();
        final int length = mText.length();
        Selection.setSelection((Spannable) mText, 0, length);
        Selection.setSelection((Spannable) mText, 0, length);
        return length > 0;
        return length > 0;
+12 −1
Original line number Original line Diff line number Diff line
@@ -295,6 +295,8 @@ public final class FloatingActionMode extends ActionMode {
     */
     */
    private static final class FloatingToolbarVisibilityHelper {
    private static final class FloatingToolbarVisibilityHelper {


        private static final long MIN_SHOW_DURATION_FOR_MOVE_HIDE = 500;

        private final FloatingToolbar mToolbar;
        private final FloatingToolbar mToolbar;


        private boolean mHideRequested;
        private boolean mHideRequested;
@@ -304,6 +306,8 @@ public final class FloatingActionMode extends ActionMode {


        private boolean mActive;
        private boolean mActive;


        private long mLastShowTime;

        public FloatingToolbarVisibilityHelper(FloatingToolbar toolbar) {
        public FloatingToolbarVisibilityHelper(FloatingToolbar toolbar) {
            mToolbar = Preconditions.checkNotNull(toolbar);
            mToolbar = Preconditions.checkNotNull(toolbar);
        }
        }
@@ -327,8 +331,14 @@ public final class FloatingActionMode extends ActionMode {
        }
        }


        public void setMoving(boolean moving) {
        public void setMoving(boolean moving) {
            // Avoid unintended flickering by allowing the toolbar to show long enough before
            // triggering the 'moving' flag - which signals a hide.
            final boolean showingLongEnough =
                System.currentTimeMillis() - mLastShowTime > MIN_SHOW_DURATION_FOR_MOVE_HIDE;
            if (!moving || showingLongEnough) {
                mMoving = moving;
                mMoving = moving;
            }
            }
        }


        public void setOutOfBounds(boolean outOfBounds) {
        public void setOutOfBounds(boolean outOfBounds) {
            mOutOfBounds = outOfBounds;
            mOutOfBounds = outOfBounds;
@@ -347,6 +357,7 @@ public final class FloatingActionMode extends ActionMode {
                mToolbar.hide();
                mToolbar.hide();
            } else {
            } else {
                mToolbar.show();
                mToolbar.show();
                mLastShowTime = System.currentTimeMillis();
            }
            }
        }
        }
    }
    }