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

Commit c7926618 authored by Aaron Heuckroth's avatar Aaron Heuckroth
Browse files

Fix Global Actions animations, and use old power menu when panel is disabled.

Also tweak feature flags setup to use old flag as a force option for debugging.

Test: Automated tests pass. Long-press power menu without plugin installed from different device orientations -- menu should animate in from the closest screen edge in all orientations and rotate correctly when device is rotated. Repeat after enabling the settings_global_actions_force_grid_enabled option in Feature Flags to ensure the correct behavior persists when using the new grid layout.

Fixes: 126444760
Fixes: 129698948

Change-Id: I9ac387244a5904f832c5d8b6c40362c00c6a22a2
parent 4ef3a544
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -38,7 +38,8 @@ public class FeatureFlagUtils {
    public static final String HEARING_AID_SETTINGS = "settings_bluetooth_hearing_aid";
    public static final String SAFETY_HUB = "settings_safety_hub";
    public static final String SCREENRECORD_LONG_PRESS = "settings_screenrecord_long_press";
    public static final String GLOBAL_ACTIONS_GRID_ENABLED = "settings_global_actions_grid_enabled";
    public static final String FORCE_GLOBAL_ACTIONS_GRID_ENABLED =
            "settings_global_actions_force_grid_enabled";
    public static final String GLOBAL_ACTIONS_PANEL_ENABLED =
            "settings_global_actions_panel_enabled";

@@ -57,7 +58,7 @@ public class FeatureFlagUtils {
        DEFAULT_FLAGS.put(HEARING_AID_SETTINGS, "false");
        DEFAULT_FLAGS.put(SAFETY_HUB, "false");
        DEFAULT_FLAGS.put(SCREENRECORD_LONG_PRESS, "false");
        DEFAULT_FLAGS.put(GLOBAL_ACTIONS_GRID_ENABLED, "true");
        DEFAULT_FLAGS.put(FORCE_GLOBAL_ACTIONS_GRID_ENABLED, "false");
        DEFAULT_FLAGS.put(GLOBAL_ACTIONS_PANEL_ENABLED, "true");
        DEFAULT_FLAGS.put("settings_wifi_details_saved_screen", "true");
        DEFAULT_FLAGS.put("settings_wifi_details_datausage_header", "false");
+25 −0
Original line number Diff line number Diff line
@@ -561,4 +561,29 @@ public class HardwareUiLayout extends MultiListLayout implements Tunable {
        inoutInfo.contentInsets.set(mList.getLeft(), mList.getTop(),
                0, getBottom() - mList.getBottom());
    };

    private float getAnimationDistance() {
        return getContext().getResources().getDimension(
                com.android.systemui.R.dimen.global_actions_panel_width) / 2;
    }

    @Override
    public float getAnimationOffsetX() {
        if (RotationUtils.getRotation(mContext) == ROTATION_NONE) {
            return getAnimationDistance();
        }
        return 0;
    }

    @Override
    public float getAnimationOffsetY() {
        switch (RotationUtils.getRotation(getContext())) {
            case RotationUtils.ROTATION_LANDSCAPE:
                return -getAnimationDistance();
            case RotationUtils.ROTATION_SEASCAPE:
                return getAnimationDistance();
            default: // Portrait
                return 0;
        }
    }
}
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
@@ -147,6 +147,16 @@ public abstract class MultiListLayout extends LinearLayout {
        void onRotate(int from, int to);
    }

    /**
     * Get the X offset in pixels for use when animating the view onto or off of the screen.
     */
    public abstract float getAnimationOffsetX();

    /**
     * Get the Y offset in pixels for use when animating the view onto or off of the screen.
     */
    public abstract float getAnimationOffsetY();

    /**
     * Adapter class for converting items into child views for MultiListLayout and handling
     * callbacks for input events.
+23 −24
Original line number Diff line number Diff line
@@ -1127,11 +1127,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }

        protected int getActionLayoutId(Context context) {
            if (isGridEnabled(context)) {
            return com.android.systemui.R.layout.global_actions_grid_item;
        }
            return com.android.systemui.R.layout.global_actions_item;
        }

        public View create(
                Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
@@ -1540,26 +1537,28 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            initializeLayout();
        }

        private boolean initializePanel() {
        private boolean shouldUsePanel() {
            if (!isPanelEnabled(mContext) || mPanelController == null) {
                return false;
            }
            View panelView = mPanelController.getPanelContent();
            if (panelView == null) {
            if (mPanelController.getPanelContent() == null) {
                return false;
            }
            return true;
        }

        private void initializePanel() {
            FrameLayout panelContainer = new FrameLayout(mContext);
            FrameLayout.LayoutParams panelParams =
                    new FrameLayout.LayoutParams(
                            FrameLayout.LayoutParams.MATCH_PARENT,
                            FrameLayout.LayoutParams.WRAP_CONTENT);
            panelContainer.addView(panelView, panelParams);
            panelContainer.addView(mPanelController.getPanelContent(), panelParams);
            addContentView(
                    panelContainer,
                    new ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT,
                            ViewGroup.LayoutParams.MATCH_PARENT));
            return true;
        }

        private void initializeLayout() {
@@ -1578,8 +1577,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            mGlobalActionsLayout.setRotationListener(this::onRotate);
            mGlobalActionsLayout.setAdapter(mAdapter);

            boolean panelEnabled = initializePanel();
            if (!panelEnabled) {
            if (!shouldUsePanel()) {
                if (mBackgroundDrawable == null) {
                    mBackgroundDrawable = new GradientDrawable(mContext);
                }
@@ -1589,12 +1587,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                        com.android.systemui.R.drawable.global_action_panel_scrim);
                mScrimAlpha = 1f;
            }
            mGlobalActionsLayout.setSnapToEdge(panelEnabled);
            mGlobalActionsLayout.setSnapToEdge(true);
            getWindow().setBackgroundDrawable(mBackgroundDrawable);
        }

        private int getGlobalActionsLayoutId(Context context) {
            if (isGridEnabled(context)) {
            if (isForceGridEnabled(context) || shouldUsePanel()) {
                if (RotationUtils.getRotation(context) == RotationUtils.ROTATION_SEASCAPE) {
                    return com.android.systemui.R.layout.global_actions_grid_seascape;
                }
@@ -1653,11 +1651,13 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            super.show();
            mShowing = true;
            mBackgroundDrawable.setAlpha(0);
            mGlobalActionsLayout.setTranslationX(getAnimTranslation());
            mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
            mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
            mGlobalActionsLayout.setAlpha(0);
            mGlobalActionsLayout.animate()
                    .alpha(1)
                    .translationX(0)
                    .translationY(0)
                    .setDuration(300)
                    .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
                    .setUpdateListener(animation -> {
@@ -1675,10 +1675,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            }
            mShowing = false;
            mGlobalActionsLayout.setTranslationX(0);
            mGlobalActionsLayout.setTranslationY(0);
            mGlobalActionsLayout.setAlpha(1);
            mGlobalActionsLayout.animate()
                    .alpha(0)
                    .translationX(getAnimTranslation())
                    .translationX(mGlobalActionsLayout.getAnimationOffsetX())
                    .translationY(mGlobalActionsLayout.getAnimationOffsetY())
                    .setDuration(300)
                    .withEndAction(super::dismiss)
                    .setInterpolator(new LogAccelerateInterpolator())
@@ -1701,11 +1703,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            }
        }

        private float getAnimTranslation() {
            return getContext().getResources().getDimension(
                    com.android.systemui.R.dimen.global_actions_panel_width) / 2;
        }

        @Override
        public void onColorsChanged(ColorExtractor extractor, int which) {
            if (mKeyguardShowing) {
@@ -1731,17 +1728,19 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }

        public void onRotate(int from, int to) {
            if (mShowing && isGridEnabled(mContext)) {
            if (mShowing && (shouldUsePanel() || isForceGridEnabled(mContext))) {
                refreshDialog();
            }
        }
    }

    /**
     * Determines whether or not the Global Actions menu should use the newer grid-style layout.
     * Determines whether or not the Global Actions menu should be forced to
     * use the newer grid-style layout.
     */
    private static boolean isGridEnabled(Context context) {
        return FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.GLOBAL_ACTIONS_GRID_ENABLED);
    private static boolean isForceGridEnabled(Context context) {
        return FeatureFlagUtils.isEnabled(context,
                FeatureFlagUtils.FORCE_GLOBAL_ACTIONS_GRID_ENABLED);
    }

    /**
+37 −6
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package com.android.systemui.globalactions;

import static com.android.systemui.util.leak.RotationUtils.ROTATION_LANDSCAPE;
import static com.android.systemui.util.leak.RotationUtils.ROTATION_NONE;
import static com.android.systemui.util.leak.RotationUtils.ROTATION_SEASCAPE;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
@@ -85,8 +89,8 @@ public class GlobalActionsGridLayout extends MultiListLayout {
        int rotation = RotationUtils.getRotation(mContext);

        boolean reverse = false; // should we add items to parents in the reverse order?
        if (rotation == RotationUtils.ROTATION_NONE
                || rotation == RotationUtils.ROTATION_SEASCAPE) {
        if (rotation == ROTATION_NONE
                || rotation == ROTATION_SEASCAPE) {
            reverse = !reverse; // if we're in portrait or seascape, reverse items
        }
        if (TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
@@ -125,9 +129,9 @@ public class GlobalActionsGridLayout extends MultiListLayout {
    private void updateSnapPosition() {
        if (mSnapToEdge) {
            setPadding(0, 0, 0, 0);
            if (mRotation == RotationUtils.ROTATION_LANDSCAPE) {
            if (mRotation == ROTATION_LANDSCAPE) {
                setGravity(Gravity.RIGHT);
            } else if (mRotation == RotationUtils.ROTATION_SEASCAPE) {
            } else if (mRotation == ROTATION_SEASCAPE) {
                setGravity(Gravity.LEFT);
            } else {
                setGravity(Gravity.BOTTOM);
@@ -157,9 +161,9 @@ public class GlobalActionsGridLayout extends MultiListLayout {
            return getSeparatedView();
        } else {
            switch (rotation) {
                case RotationUtils.ROTATION_LANDSCAPE:
                case ROTATION_LANDSCAPE:
                    return getListView().getParentView(index, false, true);
                case RotationUtils.ROTATION_SEASCAPE:
                case ROTATION_SEASCAPE:
                    return getListView().getParentView(index, true, true);
                default:
                    return getListView().getParentView(index, false, false);
@@ -174,4 +178,31 @@ public class GlobalActionsGridLayout extends MultiListLayout {
    public void setDivisionView(View v) {
        // do nothing
    }

    private float getAnimationDistance() {
        int rows = getListView().getRowCount();
        float gridItemSize = getContext().getResources().getDimension(
                com.android.systemui.R.dimen.global_actions_grid_item_height);
        return rows * gridItemSize / 2;
    }

    @Override
    public float getAnimationOffsetX() {
        switch (RotationUtils.getRotation(getContext())) {
            case ROTATION_LANDSCAPE:
                return getAnimationDistance();
            case ROTATION_SEASCAPE:
                return -getAnimationDistance();
            default: // Portrait
                return 0;
        }
    }

    @Override
    public float getAnimationOffsetY() {
        if (RotationUtils.getRotation(mContext) == ROTATION_NONE) {
            return getAnimationDistance();
        }
        return 0;
    }
}
Loading