diff options
| author | 2020-02-14 10:39:58 -0500 | |
|---|---|---|
| committer | 2020-02-14 11:09:31 -0500 | |
| commit | 780d450e709b5d702ef8c4f4810e9a1930e17c0c (patch) | |
| tree | b765e519624af4354186fb3802316d37fe00cd0d | |
| parent | 94dd284a57d7559b9e32f13a69ba6ec1b653455e (diff) | |
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
6 files changed, 129 insertions, 247 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 9282925ecb5e..c6f39624cce2 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2830,13 +2830,13 @@ "logout" = Logout the current user --> <string-array translatable="false" name="config_globalActionsList"> + <item>emergency</item> <item>power</item> <item>restart</item> <item>lockdown</item> <item>logout</item> <item>bugreport</item> <item>screenshot</item> - <item>emergency</item> </string-array> <!-- Number of milliseconds to hold a wake lock to ensure that drawing is fully diff --git a/packages/SystemUI/res/layout/global_actions_grid_v2.xml b/packages/SystemUI/res/layout/global_actions_grid_v2.xml index f90012d790e0..4fe21e5bc0ac 100644 --- a/packages/SystemUI/res/layout/global_actions_grid_v2.xml +++ b/packages/SystemUI/res/layout/global_actions_grid_v2.xml @@ -2,15 +2,17 @@ <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/global_actions_container" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/global_actions_grid_root" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="match_parent" android:clipChildren="false" android:clipToPadding="false" + android:paddingBottom="@dimen/global_actions_grid_container_shadow_offset" android:layout_marginBottom="@dimen/global_actions_grid_container_negative_shadow_offset"> <com.android.systemui.globalactions.GlobalActionsFlatLayout @@ -25,65 +27,20 @@ android:gravity="top | center_horizontal" android:clipChildren="false" android:clipToPadding="false" - android:paddingBottom="@dimen/global_actions_grid_container_shadow_offset" - android:layout_marginTop="@dimen/global_actions_top_margin" - android:layout_marginBottom="@dimen/global_actions_grid_container_negative_shadow_offset"> + android:layout_marginTop="@dimen/global_actions_top_margin"> <LinearLayout - android:layout_height="wrap_content" + android:id="@android:id/list" android:layout_width="wrap_content" - android:layoutDirection="ltr" - android:clipChildren="false" - android:clipToPadding="false" - android:layout_marginBottom="@dimen/global_actions_grid_container_bottom_margin"> - <!-- For separated items--> - <LinearLayout - android:id="@+id/separated_button" - android:layout_width="wrap_content" - android:layout_height="match_parent" - 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="vertical" - android:gravity="center" - android:translationZ="@dimen/global_actions_translate" - /> - <!-- Grid of action items --> - <com.android.systemui.globalactions.ListGridLayout - android:id="@android:id/list" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical" - android:gravity="right" - android:layout_marginRight="@dimen/global_actions_grid_side_margin" - android:translationZ="@dimen/global_actions_translate" - 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" - > - <LinearLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:visibility="gone" - android:layoutDirection="locale" - /> - <LinearLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:visibility="gone" - android:layoutDirection="locale" - /> - <LinearLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:visibility="gone" - android:layoutDirection="locale" - /> - </com.android.systemui.globalactions.ListGridLayout> - </LinearLayout> + 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" /> </com.android.systemui.globalactions.GlobalActionsFlatLayout> <LinearLayout @@ -110,8 +67,7 @@ android:layout_marginLeft="@dimen/global_actions_grid_horizontal_padding" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" - app:layout_constraintTop_toBottomOf="@id/global_actions_panel"> - - </LinearLayout> + app:layout_constraintTop_toBottomOf="@id/global_actions_panel" + app:layout_constraintBottom_toBottomOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> </ScrollView> diff --git a/packages/SystemUI/src/com/android/systemui/MultiListLayout.java b/packages/SystemUI/src/com/android/systemui/MultiListLayout.java index d153fb039802..611da0dbc890 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 d298b992d418..ef0be88bfd4e 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<Action>(); @@ -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 6749f1d663eb..f1025615783b 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()); - } - - @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; + protected boolean shouldReverseListItems() { + int rotation = getCurrentRotation(); + if (rotation == ROTATION_NONE) { + return false; } - 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; + if (getCurrentLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { + return rotation == ROTATION_LANDSCAPE; } + return rotation == ROTATION_SEASCAPE; } @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); - } - } - - @Override - public void removeAllItems() { - ViewGroup separatedList = getSeparatedView(); - ListGridLayout list = getListView(); - if (separatedList != null) { - separatedList.removeAllViews(); - } - if (list != null) { - list.removeAllItems(); + // only add items to the list view if we haven't hit our max yet + if (getListView().getChildCount() < MAX_ITEMS) { + super.addToListView(v, reverse); } } - /** - * 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 f755a93ed275..183ee458acb4 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); } } |