diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java index 9bb253b3d890f..2c1bd2186dea1 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java @@ -195,9 +195,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, private final LifecycleRegistry mLifecycle = new LifecycleRegistry(this); @VisibleForTesting - protected ArrayList mItems; + protected final ArrayList mItems = new ArrayList<>(); @VisibleForTesting - protected ArrayList mOverflowItems; + protected final ArrayList mOverflowItems = new ArrayList<>(); private ActionsDialog mDialog; @@ -453,19 +453,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, prepareDialog(); 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(); - attrs.setTitle("ActionsDialog"); - attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; - mDialog.getWindow().setAttributes(attrs); - mDialog.show(); - mWindowManagerFuncs.onGlobalActionsShown(); - } + WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes(); + attrs.setTitle("ActionsDialog"); + attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; + mDialog.getWindow().setAttributes(attrs); + mDialog.show(); + mWindowManagerFuncs.onGlobalActionsShown(); } @VisibleForTesting @@ -485,7 +478,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, */ @VisibleForTesting protected int getMaxShownPowerItems() { - if (shouldShowControls()) { + if (shouldUseControlsLayout()) { return mResources.getInteger(com.android.systemui.R.integer.power_menu_max_columns); } else { 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. */ private void addActionItem(Action action) { - if (mItems != null && shouldShowAction(action)) { + if (shouldShowAction(action)) { if (mItems.size() < getMaxShownPowerItems()) { mItems.add(action); - } else if (mOverflowItems != null) { + } else { mOverflowItems.add(action); } } @@ -522,8 +515,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, mAirplaneModeOn = new AirplaneModeAction(); onAirplaneModeChanged(); - mItems = new ArrayList(); - mOverflowItems = new ArrayList(); + mItems.clear(); + mOverflowItems.clear(); String[] defaultActions = getDefaultActions(); // 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. * @@ -599,11 +597,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, mAdapter = new MyAdapter(); mOverflowAdapter = new MyOverflowAdapter(); - mDepthController.setShowingHomeControls(shouldShowControls()); + mDepthController.setShowingHomeControls(shouldUseControlsLayout()); ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, mOverflowAdapter, getWalletPanelViewController(), mDepthController, mSysuiColorExtractor, mStatusBarService, mNotificationShadeWindowController, - shouldShowControls() ? mControlsUiController : null, mBlurUtils); + shouldShowControls() ? mControlsUiController : null, mBlurUtils, + shouldUseControlsLayout(), this::onRotate); dialog.setCanceledOnTouchOutside(false); // Handled by the custom class. dialog.setKeyguardShowing(mKeyguardShowing); @@ -704,7 +703,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, @Override public boolean shouldBeSeparated() { - return !shouldShowControls(); + return !shouldUseControlsLayout(); } @Override @@ -712,7 +711,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { View v = super.create(context, convertView, parent, inflater); int textColor; - if (shouldShowControls()) { + if (shouldUseControlsLayout()) { v.setBackgroundTintList(ColorStateList.valueOf(v.getResources().getColor( com.android.systemui.R.color.global_actions_emergency_background))); textColor = v.getResources().getColor( @@ -1152,7 +1151,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, } 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; @@ -1275,12 +1274,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, public class MyOverflowAdapter extends BaseAdapter { @Override public int getCount() { - return mOverflowItems != null ? mOverflowItems.size() : 0; + return mOverflowItems.size(); } @Override public Action getItem(int position) { - return mOverflowItems != null ? mOverflowItems.get(position) : null; + return mOverflowItems.get(position); } @Override @@ -1888,7 +1887,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, private final NotificationShadeWindowController mNotificationShadeWindowController; private final NotificationShadeDepthController mDepthController; private final BlurUtils mBlurUtils; + private final boolean mUseControlsLayout; private ListPopupWindow mOverflowPopup; + private final Runnable mOnRotateCallback; private ControlsUiController mControlsUiController; private ViewGroup mControlsView; @@ -1898,7 +1899,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, NotificationShadeDepthController depthController, SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService, 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); mContext = context; mAdapter = adapter; @@ -1909,6 +1911,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, mNotificationShadeWindowController = notificationShadeWindowController; mControlsUiController = controlsUiController; mBlurUtils = blurUtils; + mUseControlsLayout = useControlsLayout; + mOnRotateCallback = onRotateCallback; // Window initialization Window window = getWindow(); @@ -2068,7 +2072,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, } if (mBackgroundDrawable == null) { mBackgroundDrawable = new ScrimDrawable(); - if (mControlsUiController != null) { + if (mUseControlsLayout) { mScrimAlpha = 1.0f; } else { mScrimAlpha = mBlurUtils.supportsBlursOnWindows() @@ -2088,7 +2092,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, } private int getGlobalActionsLayoutId(Context context) { - if (mControlsUiController != null) { + if (mUseControlsLayout) { return com.android.systemui.R.layout.global_actions_grid_v2; } @@ -2133,9 +2137,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, if (!(mBackgroundDrawable instanceof ScrimDrawable)) { return; } - boolean hasControls = mControlsUiController != null; ((ScrimDrawable) mBackgroundDrawable).setColor( - !hasControls && colors.supportsDarkText() ? Color.WHITE : Color.BLACK, animate); + !mUseControlsLayout && colors.supportsDarkText() + ? Color.WHITE : Color.BLACK, animate); View decorView = getWindow().getDecorView(); if (colors.supportsDarkText()) { decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | @@ -2177,7 +2181,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, .start(); ViewGroup root = (ViewGroup) mGlobalActionsLayout.getRootView(); root.setOnApplyWindowInsetsListener((v, windowInsets) -> { - if (mControlsUiController != null) { + if (mUseControlsLayout) { root.setPadding(windowInsets.getStableInsetLeft(), windowInsets.getStableInsetTop(), windowInsets.getStableInsetRight(), @@ -2281,10 +2285,14 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, public void refreshDialog() { initializeLayout(); mGlobalActionsLayout.updateList(); + if (mControlsUiController != null) { + mControlsUiController.show(mControlsView); + } } public void onRotate(int from, int to) { if (mShowing) { + mOnRotateCallback.run(); refreshDialog(); } } @@ -2317,4 +2325,10 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, && mControlsUiController.getAvailable() && !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