From 780d450e709b5d702ef8c4f4810e9a1930e17c0c Mon Sep 17 00:00:00 2001 From: Aran Ink Date: Fri, 14 Feb 2020 10:39:58 -0500 Subject: [PATCH] Simplify GlobalActionsFlatLayout and fix dismiss Add a touch handler to the ScrollView container to catch touches outside of the power, wallet, and controls UIs. Adjust MultiListLayout and GloblActionsLayout to allow a very simple row-based layout for the new power menu design, instead of having to use ListGridLayout. Extract the AirplaneMode action into its own class, instead of defining it inline. Bump emergency to the top of the list of global actions to ensure it's top-priority and positioned correctly for global actions layouts without a separated view. Fixes: 149299063 Test: Manual. Enable quick controls -- tapping beneath the controls area should dismiss the GlobalActionsDialog. Dismissing should still work in either the grid (no Controls) or column (no wallet or controls) layouts. Tapping actions, swiping cards in Quick Access Wallet, and interacting with control items should still work as expected. Change-Id: Iad32045837edb0be6c9f36ec5d663483bda6f5de --- core/res/res/values/config.xml | 2 +- .../res/layout/global_actions_grid_v2.xml | 78 ++------- .../com/android/systemui/MultiListLayout.java | 5 +- .../globalactions/GlobalActionsDialog.java | 101 ++++++------ .../GlobalActionsFlatLayout.java | 150 +++--------------- .../globalactions/GlobalActionsLayout.java | 44 +++-- 6 files changed, 131 insertions(+), 249 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 9282925ecb5e8..c6f39624cce22 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2830,13 +2830,13 @@ "logout" = Logout the current user --> + emergency power restart lockdown logout bugreport screenshot - emergency - - - - - - - - + android:layout_height="wrap_content" + android:layout_marginLeft="@dimen/global_actions_grid_side_margin" + android:layout_marginRight="@dimen/global_actions_grid_side_margin" + android:paddingLeft="@dimen/global_actions_grid_horizontal_padding" + android:paddingRight="@dimen/global_actions_grid_horizontal_padding" + android:paddingTop="@dimen/global_actions_grid_vertical_padding" + android:paddingBottom="@dimen/global_actions_grid_vertical_padding" + android:orientation="horizontal" + android:gravity="left" + android:translationZ="@dimen/global_actions_translate" /> - - + app:layout_constraintTop_toBottomOf="@id/global_actions_panel" + app:layout_constraintBottom_toBottomOf="parent" /> diff --git a/packages/SystemUI/src/com/android/systemui/MultiListLayout.java b/packages/SystemUI/src/com/android/systemui/MultiListLayout.java index d153fb0398020..611da0dbc890f 100644 --- a/packages/SystemUI/src/com/android/systemui/MultiListLayout.java +++ b/packages/SystemUI/src/com/android/systemui/MultiListLayout.java @@ -57,7 +57,10 @@ public abstract class MultiListLayout extends LinearLayout { } protected void setSeparatedViewVisibility(boolean visible) { - getSeparatedView().setVisibility(visible ? View.VISIBLE : View.GONE); + ViewGroup separatedView = getSeparatedView(); + if (separatedView != null) { + separatedView.setVisibility(visible ? View.VISIBLE : View.GONE); + } } /** diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java index d298b992d4180..ef0be88bfd4ef 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java @@ -335,45 +335,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, } else { mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler); } - mAirplaneModeOn = new ToggleAction( - R.drawable.ic_lock_airplane_mode, - R.drawable.ic_lock_airplane_mode_off, - R.string.global_actions_toggle_airplane_mode, - R.string.global_actions_airplane_mode_on_status, - R.string.global_actions_airplane_mode_off_status) { - - void onToggle(boolean on) { - if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) { - mIsWaitingForEcmExit = true; - // Launch ECM exit dialog - Intent ecmDialogIntent = - new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null); - ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mContext.startActivity(ecmDialogIntent); - } else { - changeAirplaneModeSystemSetting(on); - } - } - - @Override - protected void changeStateFromPress(boolean buttonOn) { - if (!mHasTelephony) return; - - // In ECM mode airplane state cannot be changed - if (!TelephonyProperties.in_ecm_mode().orElse(false)) { - mState = buttonOn ? State.TurningOn : State.TurningOff; - mAirplaneState = mState; - } - } - - public boolean showDuringKeyguard() { - return true; - } - - public boolean showBeforeProvisioning() { - return false; - } - }; + mAirplaneModeOn = new AirplaneModeAction(); onAirplaneModeChanged(); mItems = new ArrayList(); @@ -537,7 +499,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, @Override public boolean shouldBeSeparated() { - return !shouldShowControls(); + return true; } @Override @@ -1333,6 +1295,48 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, } } + private class AirplaneModeAction extends ToggleAction { + AirplaneModeAction() { + super( + R.drawable.ic_lock_airplane_mode, + R.drawable.ic_lock_airplane_mode_off, + R.string.global_actions_toggle_airplane_mode, + R.string.global_actions_airplane_mode_on_status, + R.string.global_actions_airplane_mode_off_status); + } + void onToggle(boolean on) { + if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) { + mIsWaitingForEcmExit = true; + // Launch ECM exit dialog + Intent ecmDialogIntent = + new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null); + ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(ecmDialogIntent); + } else { + changeAirplaneModeSystemSetting(on); + } + } + + @Override + protected void changeStateFromPress(boolean buttonOn) { + if (!mHasTelephony) return; + + // In ECM mode airplane state cannot be changed + if (!TelephonyProperties.in_ecm_mode().orElse(false)) { + mState = buttonOn ? State.TurningOn : State.TurningOff; + mAirplaneState = mState; + } + } + + public boolean showDuringKeyguard() { + return true; + } + + public boolean showBeforeProvisioning() { + return false; + } + } + private class SilentModeToggleAction extends ToggleAction { public SilentModeToggleAction() { super(R.drawable.ic_audio_vol_mute, @@ -1555,6 +1559,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, private ControlsUiController mControlsUiController; private ViewGroup mControlsView; + private ViewGroup mContainerView; ActionsDialog(Context context, MyAdapter adapter, GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils, @@ -1672,6 +1677,14 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, mScrimAlpha = ScrimController.BUSY_SCRIM_ALPHA; } getWindow().setBackgroundDrawable(mBackgroundDrawable); + + if (mControlsView != null) { + mContainerView = findViewById(com.android.systemui.R.id.global_actions_container); + mContainerView.setOnTouchListener((v, e) -> { + dismiss(); + return true; + }); + } } private void fixNavBarClipping() { @@ -1894,14 +1907,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, return isPanelDebugModeEnabled(context); } - - /** - * Determines whether the Global Actions menu should use a separated view for emergency actions. - */ - private static boolean shouldUseSeparatedView() { - return true; - } - private boolean shouldShowControls() { return !mKeyguardManager.isDeviceLocked() && mControlsUiController.getAvailable(); diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsFlatLayout.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsFlatLayout.java index 6749f1d663ebf..f1025615783b5 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsFlatLayout.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsFlatLayout.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,164 +23,62 @@ import static com.android.systemui.util.leak.RotationUtils.ROTATION_SEASCAPE; import android.content.Context; import android.util.AttributeSet; import android.view.View; -import android.view.ViewGroup; import com.android.internal.annotations.VisibleForTesting; +import com.android.systemui.HardwareBgDrawable; +import com.android.systemui.R; /** - * Single row implementation of the button layout created by the global actions dialog. + * Flat, single-row implementation of the button layout created by the global actions dialog. */ public class GlobalActionsFlatLayout extends GlobalActionsLayout { + private static final int MAX_ITEMS = 4; public GlobalActionsFlatLayout(Context context, AttributeSet attrs) { super(context, attrs); } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - mBackgroundsSet = true; - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - - // backgrounds set only once, the first time onMeasure is called after inflation - // if (getListView() != null && !mBackgroundsSet) { - // setBackgrounds(); - // mBackgroundsSet = true; - // } - } - @VisibleForTesting - protected void setupListView() { - ListGridLayout listView = getListView(); - listView.setExpectedCount(Math.min(2, mAdapter.countListItems())); - listView.setReverseSublists(shouldReverseSublists()); - listView.setReverseItems(shouldReverseListItems()); - listView.setSwapRowsAndColumns(shouldSwapRowsAndColumns()); + protected boolean shouldReverseListItems() { + int rotation = getCurrentRotation(); + if (rotation == ROTATION_NONE) { + return false; + } + if (getCurrentLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { + return rotation == ROTATION_LANDSCAPE; + } + return rotation == ROTATION_SEASCAPE; } @Override - public void onUpdateList() { - setupListView(); - super.onUpdateList(); - updateSeparatedItemSize(); - } - - /** - * If the separated view contains only one item, expand the bounds of that item to take up the - * entire view, so that the whole thing is touch-able. - */ - @VisibleForTesting - protected void updateSeparatedItemSize() { - ViewGroup separated = getSeparatedView(); - if (separated.getChildCount() == 0) { - return; - } - View firstChild = separated.getChildAt(0); - ViewGroup.LayoutParams childParams = firstChild.getLayoutParams(); - - if (separated.getChildCount() == 1) { - childParams.width = ViewGroup.LayoutParams.MATCH_PARENT; - childParams.height = ViewGroup.LayoutParams.MATCH_PARENT; - } else { - childParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; - childParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - } - } - - @Override - protected ListGridLayout getListView() { - return (ListGridLayout) super.getListView(); - } - - @Override - protected void removeAllListViews() { - ListGridLayout list = getListView(); - if (list != null) { - list.removeAllItems(); - } + protected HardwareBgDrawable getBackgroundDrawable(int backgroundColor) { + return null; } @Override protected void addToListView(View v, boolean reverse) { - ListGridLayout list = getListView(); - if (list != null) { - list.addItem(v); + // only add items to the list view if we haven't hit our max yet + if (getListView().getChildCount() < MAX_ITEMS) { + super.addToListView(v, reverse); } } - @Override - public void removeAllItems() { - ViewGroup separatedList = getSeparatedView(); - ListGridLayout list = getListView(); - if (separatedList != null) { - separatedList.removeAllViews(); - } - if (list != null) { - list.removeAllItems(); - } - } - - /** - * Determines whether the ListGridLayout should fill sublists in the reverse order. - * Used to account for sublist ordering changing between landscape and seascape views. - */ @VisibleForTesting - protected boolean shouldReverseSublists() { - if (getCurrentRotation() == ROTATION_SEASCAPE) { - return true; - } - return false; - } - - /** - * Determines whether the ListGridLayout should fill rows first instead of columns. - * Used to account for vertical/horizontal changes due to landscape or seascape rotations. - */ - @VisibleForTesting - protected boolean shouldSwapRowsAndColumns() { - if (getCurrentRotation() == ROTATION_NONE) { - return false; - } - return true; - } - - @Override - protected boolean shouldReverseListItems() { - int rotation = getCurrentRotation(); - boolean reverse = false; // should we add items to parents in the reverse order? - if (rotation == ROTATION_NONE - || rotation == ROTATION_SEASCAPE) { - reverse = !reverse; // if we're in portrait or seascape, reverse items - } - if (getCurrentLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { - reverse = !reverse; // if we're in an RTL language, reverse items (again) - } - return reverse; + protected float getGridItemSize() { + return getContext().getResources().getDimension(R.dimen.global_actions_grid_item_height); } @VisibleForTesting protected 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; + return getGridItemSize() / 2; } @Override public float getAnimationOffsetX() { - switch (getCurrentRotation()) { - case ROTATION_LANDSCAPE: - return getAnimationDistance(); - case ROTATION_SEASCAPE: - return -getAnimationDistance(); - default: // Portrait - return 0; - } + return 0; } @Override public float getAnimationOffsetY() { - if (getCurrentRotation() == ROTATION_NONE) { - return getAnimationDistance(); - } - return 0; + return -getAnimationDistance(); } } diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsLayout.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsLayout.java index f755a93ed2753..183ee458acb4d 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsLayout.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsLayout.java @@ -42,16 +42,30 @@ public abstract class GlobalActionsLayout extends MultiListLayout { } private void setBackgrounds() { - int gridBackgroundColor = getResources().getColor( + ViewGroup listView = getListView(); + int listBgColor = getResources().getColor( R.color.global_actions_grid_background, null); - int separatedBackgroundColor = getResources().getColor( - R.color.global_actions_separated_background, null); - HardwareBgDrawable listBackground = new HardwareBgDrawable(true, true, getContext()); - HardwareBgDrawable separatedBackground = new HardwareBgDrawable(true, true, getContext()); - listBackground.setTint(gridBackgroundColor); - separatedBackground.setTint(separatedBackgroundColor); - getListView().setBackground(listBackground); - getSeparatedView().setBackground(separatedBackground); + HardwareBgDrawable listBackground = getBackgroundDrawable(listBgColor); + if (listBackground != null) { + listView.setBackground(listBackground); + } + + ViewGroup separatedView = getSeparatedView(); + + if (separatedView != null) { + int separatedBgColor = getResources().getColor( + R.color.global_actions_separated_background, null); + HardwareBgDrawable separatedBackground = getBackgroundDrawable(separatedBgColor); + if (separatedBackground != null) { + getSeparatedView().setBackground(separatedBackground); + } + } + } + + protected HardwareBgDrawable getBackgroundDrawable(int backgroundColor) { + HardwareBgDrawable background = new HardwareBgDrawable(true, true, getContext()); + background.setTint(backgroundColor); + return background; } @Override @@ -74,10 +88,16 @@ public abstract class GlobalActionsLayout extends MultiListLayout { } protected void addToSeparatedView(View v, boolean reverse) { - if (reverse) { - getSeparatedView().addView(v, 0); + ViewGroup separated = getSeparatedView(); + if (separated != null) { + if (reverse) { + separated.addView(v, 0); + } else { + separated.addView(v); + } } else { - getSeparatedView().addView(v); + // if no separated view exists, just use the list view + addToListView(v, reverse); } }