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

Commit c2a03fd6 authored by PETER LIANG's avatar PETER LIANG Committed by Android (Google) Code Review
Browse files

Merge changes from topic "ig"

* changes:
  Fix that accessibility floating menu did not remember tucked state when lock/unlock the phone.
  Refactor the design and improve the animations of Accessibility Floating Menu(9/n).
parents 42051221 8dca8a34
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1341,6 +1341,7 @@
    <dimen name="accessibility_floating_menu_large_width_height">56dp</dimen>
    <dimen name="accessibility_floating_menu_large_single_radius">35dp</dimen>
    <dimen name="accessibility_floating_menu_large_multiple_radius">35dp</dimen>
    <dimen name="accessibility_floating_menu_ime_shifting_space">48dp</dimen>

    <dimen name="accessibility_floating_menu_message_container_horizontal_padding">15dp</dimen>
    <dimen name="accessibility_floating_menu_message_text_vertical_padding">8dp</dimen>
+3 −1
Original line number Diff line number Diff line
@@ -72,7 +72,8 @@ public final class Prefs {
            Key.HAS_SEEN_ACCESSIBILITY_FLOATING_MENU_DOCK_TOOLTIP,
            Key.ACCESSIBILITY_FLOATING_MENU_POSITION,
            Key.HAS_CLICKED_NUDGE_TO_SETUP_DREAM,
            Key.HAS_DISMISSED_NUDGE_TO_SETUP_DREAM
            Key.HAS_DISMISSED_NUDGE_TO_SETUP_DREAM,
            Key.HAS_ACCESSIBILITY_FLOATING_MENU_TUCKED
    })
    // TODO: annotate these with their types so {@link PrefsCommandLine} can know how to set them
    public @interface Key {
@@ -117,6 +118,7 @@ public final class Prefs {
        String ACCESSIBILITY_FLOATING_MENU_POSITION = "AccessibilityFloatingMenuPosition";
        String HAS_CLICKED_NUDGE_TO_SETUP_DREAM = "HasClickedNudgeToSetupDream";
        String HAS_DISMISSED_NUDGE_TO_SETUP_DREAM = "HasDismissedNudgeToSetupDream";
        String HAS_ACCESSIBILITY_FLOATING_MENU_TUCKED = "HasAccessibilityFloatingMenuTucked";
    }

    public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) {
+18 −23
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.systemui.accessibility.floatingmenu;

import static android.util.MathUtils.constrain;

import static java.util.Objects.requireNonNull;

import android.animation.ValueAnimator;
@@ -64,7 +62,6 @@ class MenuAnimationController {
    private final MenuView mMenuView;
    private final ValueAnimator mFadeOutAnimator;
    private final Handler mHandler;
    private boolean mIsMovedToEdge;
    private boolean mIsFadeEffectEnabled;
    private DismissAnimationController.DismissCallback mDismissCallback;

@@ -111,25 +108,25 @@ class MenuAnimationController {
    }

    void moveToTopLeftPosition() {
        mIsMovedToEdge = false;
        mMenuView.updateMenuMoveToTucked(/* isMoveToTucked= */ false);
        final Rect draggableBounds = mMenuView.getMenuDraggableBounds();
        moveAndPersistPosition(new PointF(draggableBounds.left, draggableBounds.top));
    }

    void moveToTopRightPosition() {
        mIsMovedToEdge = false;
        mMenuView.updateMenuMoveToTucked(/* isMoveToTucked= */ false);
        final Rect draggableBounds = mMenuView.getMenuDraggableBounds();
        moveAndPersistPosition(new PointF(draggableBounds.right, draggableBounds.top));
    }

    void moveToBottomLeftPosition() {
        mIsMovedToEdge = false;
        mMenuView.updateMenuMoveToTucked(/* isMoveToTucked= */ false);
        final Rect draggableBounds = mMenuView.getMenuDraggableBounds();
        moveAndPersistPosition(new PointF(draggableBounds.left, draggableBounds.bottom));
    }

    void moveToBottomRightPosition() {
        mIsMovedToEdge = false;
        mMenuView.updateMenuMoveToTucked(/* isMoveToTucked= */ false);
        final Rect draggableBounds = mMenuView.getMenuDraggableBounds();
        moveAndPersistPosition(new PointF(draggableBounds.right, draggableBounds.bottom));
    }
@@ -254,6 +251,8 @@ class MenuAnimationController {
        // If the translation x is zero, it should be at the left of the bound.
        if (currentXTranslation < draggableBounds.left
                || currentXTranslation > draggableBounds.right) {
            constrainPositionAndUpdate(
                    new PointF(mMenuView.getTranslationX(), mMenuView.getTranslationY()));
            moveToEdgeAndHide();
            return true;
        }
@@ -262,37 +261,33 @@ class MenuAnimationController {
        return false;
    }

    private boolean isOnLeftSide() {
    boolean isOnLeftSide() {
        return mMenuView.getTranslationX() < mMenuView.getMenuDraggableBounds().centerX();
    }

    boolean isMovedToEdge() {
        return mIsMovedToEdge;
    boolean isMoveToTucked() {
        return mMenuView.isMoveToTucked();
    }

    void moveToEdgeAndHide() {
        mIsMovedToEdge = true;
        mMenuView.updateMenuMoveToTucked(/* isMoveToTucked= */ true);

        final Rect draggableBounds = mMenuView.getMenuDraggableBounds();
        final float endY = constrain(mMenuView.getTranslationY(), draggableBounds.top,
                draggableBounds.bottom);
        final float menuHalfWidth = mMenuView.getWidth() / 2.0f;
        final PointF position = mMenuView.getMenuPosition();
        final float menuHalfWidth = mMenuView.getMenuWidth() / 2.0f;
        final float endX = isOnLeftSide()
                ? draggableBounds.left - menuHalfWidth
                : draggableBounds.right + menuHalfWidth;
        moveAndPersistPosition(new PointF(endX, endY));
                ? position.x - menuHalfWidth
                : position.x + menuHalfWidth;
        moveToPosition(new PointF(endX, position.y));

        // Keep the touch region let users could click extra space to pop up the menu view
        // from the screen edge
        mMenuView.onBoundsInParentChanged(isOnLeftSide()
                ? draggableBounds.left
                : draggableBounds.right, (int) mMenuView.getTranslationY());
        mMenuView.onBoundsInParentChanged((int) position.x, (int) position.y);

        fadeOutIfEnabled();
    }

    void moveOutEdgeAndShow() {
        mIsMovedToEdge = false;
        mMenuView.updateMenuMoveToTucked(/* isMoveToTucked= */ false);

        mMenuView.onPositionChanged();
        mMenuView.onEdgeChangedIfNeeded();
@@ -345,7 +340,7 @@ class MenuAnimationController {
    }

    private void constrainPositionAndUpdate(PointF position) {
        final Rect draggableBounds = mMenuView.getMenuDraggableBounds();
        final Rect draggableBounds = mMenuView.getMenuDraggableBoundsExcludeIme();
        // Have the space gap margin between the top bound and the menu view, so actually the
        // position y range needs to cut the margin.
        position.offset(-draggableBounds.left, -draggableBounds.top);
+12 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ class MenuInfoRepository {

    @FloatRange(from = 0.0, to = 1.0)
    private static final float DEFAULT_MENU_POSITION_Y_PERCENT = 0.77f;
    private static final boolean DEFAULT_MOVE_TO_TUCKED_VALUE = false;

    private final Context mContext;
    private final Handler mHandler = new Handler(Looper.getMainLooper());
@@ -92,6 +93,12 @@ class MenuInfoRepository {
        mPercentagePosition = getStartPosition();
    }

    void loadMenuMoveToTucked(OnInfoReady<Boolean> callback) {
        callback.onReady(
                Prefs.getBoolean(mContext, Prefs.Key.HAS_ACCESSIBILITY_FLOATING_MENU_TUCKED,
                        DEFAULT_MOVE_TO_TUCKED_VALUE));
    }

    void loadMenuPosition(OnInfoReady<Position> callback) {
        callback.onReady(mPercentagePosition);
    }
@@ -113,6 +120,11 @@ class MenuInfoRepository {
                getMenuOpacityFromSettings(mContext));
    }

    void updateMoveToTucked(boolean isMoveToTucked) {
        Prefs.putBoolean(mContext, Prefs.Key.HAS_ACCESSIBILITY_FLOATING_MENU_TUCKED,
                isMoveToTucked);
    }

    void updateMenuSavingPosition(Position percentagePosition) {
        mPercentagePosition = percentagePosition;
        Prefs.putString(mContext, Prefs.Key.ACCESSIBILITY_FLOATING_MENU_POSITION,
+2 −2
Original line number Diff line number Diff line
@@ -74,10 +74,10 @@ class MenuItemAccessibilityDelegate extends RecyclerViewAccessibilityDelegate.It
                                R.string.accessibility_floating_button_action_move_bottom_right));
        info.addAction(moveBottomRight);

        final int moveEdgeId = mAnimationController.isMovedToEdge()
        final int moveEdgeId = mAnimationController.isMoveToTucked()
                ? R.id.action_move_out_edge_and_show
                : R.id.action_move_to_edge_and_hide;
        final int moveEdgeTextResId = mAnimationController.isMovedToEdge()
        final int moveEdgeTextResId = mAnimationController.isMoveToTucked()
                ? R.string.accessibility_floating_button_action_move_out_edge_and_show
                : R.string.accessibility_floating_button_action_move_to_edge_and_hide_to_half;
        final AccessibilityNodeInfoCompat.AccessibilityActionCompat moveToOrOutEdge =
Loading