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

Commit d79f49fe authored by Aran Ink's avatar Aran Ink Committed by Automerger Merge Worker
Browse files

Merge "Always use new controls layout for GlobalActions." into rvc-dev am:...

Merge "Always use new controls layout for GlobalActions." into rvc-dev am: 1f20930d am: 897976b5

Change-Id: I3c3ca1518701c172f8beeb5786c35f9f70711c40
parents 1f8b0632 897976b5
Loading
Loading
Loading
Loading
+48 −34
Original line number Original line Diff line number Diff line
@@ -195,9 +195,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
    private final LifecycleRegistry mLifecycle = new LifecycleRegistry(this);
    private final LifecycleRegistry mLifecycle = new LifecycleRegistry(this);


    @VisibleForTesting
    @VisibleForTesting
    protected ArrayList<Action> mItems;
    protected final ArrayList<Action> mItems = new ArrayList<>();
    @VisibleForTesting
    @VisibleForTesting
    protected ArrayList<Action> mOverflowItems;
    protected final ArrayList<Action> mOverflowItems = new ArrayList<>();


    private ActionsDialog mDialog;
    private ActionsDialog mDialog;


@@ -453,12 +453,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        prepareDialog();
        prepareDialog();
        seedFavorites();
        seedFavorites();


        // If we only have 1 item and it's a simple press action, just do this action.
        if (mAdapter.getCount() == 1
                && mAdapter.getItem(0) instanceof SinglePressAction
                && !(mAdapter.getItem(0) instanceof LongPressAction)) {
            ((SinglePressAction) mAdapter.getItem(0)).onPress();
        } else {
        WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
        WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
        attrs.setTitle("ActionsDialog");
        attrs.setTitle("ActionsDialog");
        attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
        attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
@@ -466,7 +460,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        mDialog.show();
        mDialog.show();
        mWindowManagerFuncs.onGlobalActionsShown();
        mWindowManagerFuncs.onGlobalActionsShown();
    }
    }
    }


    @VisibleForTesting
    @VisibleForTesting
    protected boolean shouldShowAction(Action action) {
    protected boolean shouldShowAction(Action action) {
@@ -485,7 +478,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    protected int getMaxShownPowerItems() {
    protected int getMaxShownPowerItems() {
        if (shouldShowControls()) {
        if (shouldUseControlsLayout()) {
            return mResources.getInteger(com.android.systemui.R.integer.power_menu_max_columns);
            return mResources.getInteger(com.android.systemui.R.integer.power_menu_max_columns);
        } else {
        } else {
            return Integer.MAX_VALUE;
            return Integer.MAX_VALUE;
@@ -497,10 +490,10 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
     * whether controls are enabled and whether the max number of shown items has been reached.
     * whether controls are enabled and whether the max number of shown items has been reached.
     */
     */
    private void addActionItem(Action action) {
    private void addActionItem(Action action) {
        if (mItems != null && shouldShowAction(action)) {
        if (shouldShowAction(action)) {
            if (mItems.size() < getMaxShownPowerItems()) {
            if (mItems.size() < getMaxShownPowerItems()) {
                mItems.add(action);
                mItems.add(action);
            } else if (mOverflowItems != null) {
            } else {
                mOverflowItems.add(action);
                mOverflowItems.add(action);
            }
            }
        }
        }
@@ -522,8 +515,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        mAirplaneModeOn = new AirplaneModeAction();
        mAirplaneModeOn = new AirplaneModeAction();
        onAirplaneModeChanged();
        onAirplaneModeChanged();


        mItems = new ArrayList<Action>();
        mItems.clear();
        mOverflowItems = new ArrayList<Action>();
        mOverflowItems.clear();
        String[] defaultActions = getDefaultActions();
        String[] defaultActions = getDefaultActions();


        // make sure emergency affordance action is first, if needed
        // make sure emergency affordance action is first, if needed
@@ -588,6 +581,11 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }
        }
    }
    }


    private void onRotate() {
        // re-allocate actions between main and overflow lists
        this.createActionItems();
    }

    /**
    /**
     * Create the global actions dialog.
     * Create the global actions dialog.
     *
     *
@@ -599,11 +597,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        mAdapter = new MyAdapter();
        mAdapter = new MyAdapter();
        mOverflowAdapter = new MyOverflowAdapter();
        mOverflowAdapter = new MyOverflowAdapter();


        mDepthController.setShowingHomeControls(shouldShowControls());
        mDepthController.setShowingHomeControls(shouldUseControlsLayout());
        ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, mOverflowAdapter,
        ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, mOverflowAdapter,
                getWalletPanelViewController(), mDepthController, mSysuiColorExtractor,
                getWalletPanelViewController(), mDepthController, mSysuiColorExtractor,
                mStatusBarService, mNotificationShadeWindowController,
                mStatusBarService, mNotificationShadeWindowController,
                shouldShowControls() ? mControlsUiController : null, mBlurUtils);
                shouldShowControls() ? mControlsUiController : null, mBlurUtils,
                shouldUseControlsLayout(), this::onRotate);
        dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
        dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
        dialog.setKeyguardShowing(mKeyguardShowing);
        dialog.setKeyguardShowing(mKeyguardShowing);


@@ -704,7 +703,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,


        @Override
        @Override
        public boolean shouldBeSeparated() {
        public boolean shouldBeSeparated() {
            return !shouldShowControls();
            return !shouldUseControlsLayout();
        }
        }


        @Override
        @Override
@@ -712,7 +711,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
                Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
            View v = super.create(context, convertView, parent, inflater);
            View v = super.create(context, convertView, parent, inflater);
            int textColor;
            int textColor;
            if (shouldShowControls()) {
            if (shouldUseControlsLayout()) {
                v.setBackgroundTintList(ColorStateList.valueOf(v.getResources().getColor(
                v.setBackgroundTintList(ColorStateList.valueOf(v.getResources().getColor(
                        com.android.systemui.R.color.global_actions_emergency_background)));
                        com.android.systemui.R.color.global_actions_emergency_background)));
                textColor = v.getResources().getColor(
                textColor = v.getResources().getColor(
@@ -1152,7 +1151,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
    }
    }


    private int getActionLayoutId() {
    private int getActionLayoutId() {
        if (shouldShowControls()) {
        if (shouldUseControlsLayout()) {
            return com.android.systemui.R.layout.global_actions_grid_item_v2;
            return com.android.systemui.R.layout.global_actions_grid_item_v2;
        }
        }
        return com.android.systemui.R.layout.global_actions_grid_item;
        return com.android.systemui.R.layout.global_actions_grid_item;
@@ -1275,12 +1274,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
    public class MyOverflowAdapter extends BaseAdapter {
    public class MyOverflowAdapter extends BaseAdapter {
        @Override
        @Override
        public int getCount() {
        public int getCount() {
            return mOverflowItems != null ? mOverflowItems.size() : 0;
            return mOverflowItems.size();
        }
        }


        @Override
        @Override
        public Action getItem(int position) {
        public Action getItem(int position) {
            return mOverflowItems != null ? mOverflowItems.get(position) : null;
            return mOverflowItems.get(position);
        }
        }


        @Override
        @Override
@@ -1888,7 +1887,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        private final NotificationShadeWindowController mNotificationShadeWindowController;
        private final NotificationShadeWindowController mNotificationShadeWindowController;
        private final NotificationShadeDepthController mDepthController;
        private final NotificationShadeDepthController mDepthController;
        private final BlurUtils mBlurUtils;
        private final BlurUtils mBlurUtils;
        private final boolean mUseControlsLayout;
        private ListPopupWindow mOverflowPopup;
        private ListPopupWindow mOverflowPopup;
        private final Runnable mOnRotateCallback;


        private ControlsUiController mControlsUiController;
        private ControlsUiController mControlsUiController;
        private ViewGroup mControlsView;
        private ViewGroup mControlsView;
@@ -1898,7 +1899,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                NotificationShadeDepthController depthController,
                NotificationShadeDepthController depthController,
                SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
                SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
                NotificationShadeWindowController notificationShadeWindowController,
                NotificationShadeWindowController notificationShadeWindowController,
                ControlsUiController controlsUiController, BlurUtils blurUtils) {
                ControlsUiController controlsUiController, BlurUtils blurUtils,
                boolean useControlsLayout, Runnable onRotateCallback) {
            super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
            super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
            mContext = context;
            mContext = context;
            mAdapter = adapter;
            mAdapter = adapter;
@@ -1909,6 +1911,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            mNotificationShadeWindowController = notificationShadeWindowController;
            mNotificationShadeWindowController = notificationShadeWindowController;
            mControlsUiController = controlsUiController;
            mControlsUiController = controlsUiController;
            mBlurUtils = blurUtils;
            mBlurUtils = blurUtils;
            mUseControlsLayout = useControlsLayout;
            mOnRotateCallback = onRotateCallback;


            // Window initialization
            // Window initialization
            Window window = getWindow();
            Window window = getWindow();
@@ -2068,7 +2072,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            }
            }
            if (mBackgroundDrawable == null) {
            if (mBackgroundDrawable == null) {
                mBackgroundDrawable = new ScrimDrawable();
                mBackgroundDrawable = new ScrimDrawable();
                if (mControlsUiController != null) {
                if (mUseControlsLayout) {
                    mScrimAlpha = 1.0f;
                    mScrimAlpha = 1.0f;
                } else {
                } else {
                    mScrimAlpha = mBlurUtils.supportsBlursOnWindows()
                    mScrimAlpha = mBlurUtils.supportsBlursOnWindows()
@@ -2088,7 +2092,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }
        }


        private int getGlobalActionsLayoutId(Context context) {
        private int getGlobalActionsLayoutId(Context context) {
            if (mControlsUiController != null) {
            if (mUseControlsLayout) {
                return com.android.systemui.R.layout.global_actions_grid_v2;
                return com.android.systemui.R.layout.global_actions_grid_v2;
            }
            }


@@ -2133,9 +2137,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
            if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
                return;
                return;
            }
            }
            boolean hasControls = mControlsUiController != null;
            ((ScrimDrawable) mBackgroundDrawable).setColor(
            ((ScrimDrawable) mBackgroundDrawable).setColor(
                    !hasControls && colors.supportsDarkText() ? Color.WHITE : Color.BLACK, animate);
                    !mUseControlsLayout && colors.supportsDarkText()
                            ? Color.WHITE : Color.BLACK, animate);
            View decorView = getWindow().getDecorView();
            View decorView = getWindow().getDecorView();
            if (colors.supportsDarkText()) {
            if (colors.supportsDarkText()) {
                decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
                decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
@@ -2177,7 +2181,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                    .start();
                    .start();
            ViewGroup root = (ViewGroup) mGlobalActionsLayout.getRootView();
            ViewGroup root = (ViewGroup) mGlobalActionsLayout.getRootView();
            root.setOnApplyWindowInsetsListener((v, windowInsets) -> {
            root.setOnApplyWindowInsetsListener((v, windowInsets) -> {
                if (mControlsUiController != null) {
                if (mUseControlsLayout) {
                    root.setPadding(windowInsets.getStableInsetLeft(),
                    root.setPadding(windowInsets.getStableInsetLeft(),
                            windowInsets.getStableInsetTop(),
                            windowInsets.getStableInsetTop(),
                            windowInsets.getStableInsetRight(),
                            windowInsets.getStableInsetRight(),
@@ -2281,10 +2285,14 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        public void refreshDialog() {
        public void refreshDialog() {
            initializeLayout();
            initializeLayout();
            mGlobalActionsLayout.updateList();
            mGlobalActionsLayout.updateList();
            if (mControlsUiController != null) {
                mControlsUiController.show(mControlsView);
            }
        }
        }


        public void onRotate(int from, int to) {
        public void onRotate(int from, int to) {
            if (mShowing) {
            if (mShowing) {
                mOnRotateCallback.run();
                refreshDialog();
                refreshDialog();
            }
            }
        }
        }
@@ -2317,4 +2325,10 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                && mControlsUiController.getAvailable()
                && mControlsUiController.getAvailable()
                && !mControlsServiceInfos.isEmpty();
                && !mControlsServiceInfos.isEmpty();
    }
    }

    // TODO: Remove legacy layout XML and classes.
    protected boolean shouldUseControlsLayout() {
        // always use new controls layout
        return true;
    }
}
}
 No newline at end of file