summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Aran Ink <nesciosquid@google.com> 2020-06-18 19:18:04 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-06-18 19:18:04 +0000
commitee441db39f3fd34dedf9a90fb7cbec307546c965 (patch)
treecb2b1f82f27f1fdd3106b19711c79c40981277f3
parentcaa0c3758d16d9ace3abc79062c4b64f7bce41c4 (diff)
parent143eea4f7e117ac39e4ac01cdb5847d74e3ff5ed (diff)
Merge "Convert PowerOptions menu into a dialog and update styling." into rvc-dev
-rw-r--r--packages/SystemUI/res/layout/global_actions_power_dialog.xml24
-rw-r--r--packages/SystemUI/res/layout/global_actions_power_item.xml45
-rw-r--r--packages/SystemUI/res/values/dimens.xml4
-rw-r--r--packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java83
-rw-r--r--packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPowerDialog.java60
5 files changed, 183 insertions, 33 deletions
diff --git a/packages/SystemUI/res/layout/global_actions_power_dialog.xml b/packages/SystemUI/res/layout/global_actions_power_dialog.xml
new file mode 100644
index 000000000000..ff3f0fb74cd5
--- /dev/null
+++ b/packages/SystemUI/res/layout/global_actions_power_dialog.xml
@@ -0,0 +1,24 @@
+<!--
+ ~ 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.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:divider="@drawable/controls_list_divider"
+ android:showDividers="middle"
+/>
+
diff --git a/packages/SystemUI/res/layout/global_actions_power_item.xml b/packages/SystemUI/res/layout/global_actions_power_item.xml
new file mode 100644
index 000000000000..0d060b63486f
--- /dev/null
+++ b/packages/SystemUI/res/layout/global_actions_power_item.xml
@@ -0,0 +1,45 @@
+<!--
+ ~ 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.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<com.android.systemui.globalactions.GlobalActionsItem
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="@dimen/global_actions_power_dialog_item_width"
+ android:layout_height="@dimen/global_actions_power_dialog_item_height"
+ android:gravity="bottom|center_horizontal"
+ android:orientation="vertical"
+ android:paddingTop="12dp"
+ android:paddingBottom="12dp"
+ android:stateListAnimator="@anim/control_state_list_animator">
+ <ImageView
+ android:id="@*android:id/icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_marginBottom="45dp"
+ android:scaleType="centerInside"
+ android:tint="@color/control_primary_text" />
+ <TextView
+ android:id="@*android:id/message"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:marqueeRepeatLimit="marquee_forever"
+ android:ellipsize="marquee"
+ android:layout_marginBottom="16dp"
+ android:maxLines="1"
+ android:textSize="16sp"
+ android:gravity="center"
+ android:textColor="@color/control_primary_text"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+</com.android.systemui.globalactions.GlobalActionsItem>
+
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 9bcfdc43fbbf..c06b9161ad1f 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -1058,6 +1058,10 @@
<!-- Shift quick access wallet down in Global Actions when Controls are unavailable -->
<dimen name="global_actions_wallet_top_margin">40dp</dimen>
+ <!-- Shutdown and restart actions are larger in power options dialog -->
+ <dimen name="global_actions_power_dialog_item_height">190dp</dimen>
+ <dimen name="global_actions_power_dialog_item_width">255dp</dimen>
+
<!-- The maximum offset in either direction that elements are moved horizontally to prevent
burn-in on AOD. -->
<dimen name="burn_in_prevention_offset_x">8dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
index b520717ee27f..c891bf6cb53c 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
@@ -1425,16 +1425,26 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
Log.w(TAG, "No power options action found at position: " + position);
return null;
}
- int viewLayoutResource = com.android.systemui.R.layout.controls_more_item;
+ int viewLayoutResource = com.android.systemui.R.layout.global_actions_power_item;
View view = convertView != null ? convertView
: LayoutInflater.from(mContext).inflate(viewLayoutResource, parent, false);
- TextView textView = (TextView) view;
- if (action.getMessageResId() != 0) {
- textView.setText(action.getMessageResId());
+ view.setOnClickListener(v -> onClickItem(position));
+ if (action instanceof LongPressAction) {
+ view.setOnLongClickListener(v -> onLongClickItem(position));
+ }
+ ImageView icon = view.findViewById(R.id.icon);
+ TextView messageView = view.findViewById(R.id.message);
+ messageView.setSelected(true); // necessary for marquee to work
+
+ icon.setImageDrawable(action.getIcon(mContext));
+ icon.setScaleType(ScaleType.CENTER_CROP);
+
+ if (action.getMessage() != null) {
+ messageView.setText(action.getMessage());
} else {
- textView.setText(action.getMessage());
+ messageView.setText(action.getMessageResId());
}
- return textView;
+ return view;
}
private boolean onLongClickItem(int position) {
@@ -1570,6 +1580,11 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
int getMessageResId();
/**
+ * Return the icon drawable for this action.
+ */
+ Drawable getIcon(Context context);
+
+ /**
* Return the message associated with this action, or null if it doesn't have one.
* @return
*/
@@ -1633,6 +1648,15 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
return mMessage;
}
+ @Override
+ public Drawable getIcon(Context context) {
+ if (mIcon != null) {
+ return mIcon;
+ } else {
+ return context.getDrawable(mIconResId);
+ }
+ }
+
public View create(
Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
View v = inflater.inflate(com.android.systemui.R.layout.global_actions_grid_item_v2,
@@ -1642,12 +1666,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
TextView messageView = v.findViewById(R.id.message);
messageView.setSelected(true); // necessary for marquee to work
- if (mIcon != null) {
- icon.setImageDrawable(mIcon);
- icon.setScaleType(ScaleType.CENTER_CROP);
- } else if (mIconResId != 0) {
- icon.setImageDrawable(context.getDrawable(mIconResId));
- }
+ icon.setImageDrawable(getIcon(context));
+ icon.setScaleType(ScaleType.CENTER_CROP);
+
if (mMessage != null) {
messageView.setText(mMessage);
} else {
@@ -1738,6 +1759,11 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
return isOn() ? mEnabledIconResId : mDisabledIconResid;
}
+ @Override
+ public Drawable getIcon(Context context) {
+ return context.getDrawable(getIconResId());
+ }
+
public View create(Context context, View convertView, ViewGroup parent,
LayoutInflater inflater) {
willCreate();
@@ -1904,6 +1930,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
return null;
}
+ @Override
+ public Drawable getIcon(Context context) {
+ return null;
+ }
+
+
public View create(Context context, View convertView, ViewGroup parent,
LayoutInflater inflater) {
View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
@@ -2075,7 +2107,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
private final NotificationShadeDepthController mDepthController;
private final SysUiState mSysUiState;
private ListPopupWindow mOverflowPopup;
- private ListPopupWindow mPowerOptionsPopup;
+ private Dialog mPowerOptionsDialog;
private final Runnable mOnRotateCallback;
private final boolean mControlsAvailable;
@@ -2211,21 +2243,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
}
}
- private ListPopupWindow createPowerOptionsPopup() {
- GlobalActionsPopupMenu popup = new GlobalActionsPopupMenu(
- new ContextThemeWrapper(
- mContext,
- com.android.systemui.R.style.Control_ListPopupWindow
- ), false /* isDropDownMode */);
- popup.setOnItemClickListener(
- (parent, view, position, id) -> mPowerOptionsAdapter.onClickItem(position));
- popup.setOnItemLongClickListener(
- (parent, view, position, id) -> mPowerOptionsAdapter.onLongClickItem(position));
- popup.setAnchorView(mGlobalActionsLayout);
- popup.setAdapter(mPowerOptionsAdapter);
- return popup;
- }
-
private ListPopupWindow createPowerOverflowPopup() {
GlobalActionsPopupMenu popup = new GlobalActionsPopupMenu(
new ContextThemeWrapper(
@@ -2244,8 +2261,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
}
public void showPowerOptionsMenu() {
- mPowerOptionsPopup = createPowerOptionsPopup();
- mPowerOptionsPopup.show();
+ mPowerOptionsDialog = GlobalActionsPowerDialog.create(mContext, mPowerOptionsAdapter);
+ mPowerOptionsDialog.show();
}
private void showPowerOverflowMenu() {
@@ -2479,11 +2496,11 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
}
private void dismissPowerOptions(boolean immediate) {
- if (mPowerOptionsPopup != null) {
+ if (mPowerOptionsDialog != null) {
if (immediate) {
- mPowerOptionsPopup.dismissImmediate();
+ mPowerOptionsDialog.dismiss();
} else {
- mPowerOptionsPopup.dismiss();
+ mPowerOptionsDialog.dismiss();
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPowerDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPowerDialog.java
new file mode 100644
index 000000000000..9dec3ab859b1
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPowerDialog.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.systemui.globalactions;
+
+import android.annotation.NonNull;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.res.Resources;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.ListAdapter;
+
+/**
+ * Creates a customized Dialog for displaying the Shut Down and Restart actions.
+ */
+public class GlobalActionsPowerDialog {
+
+ /**
+ * Create a dialog for displaying Shut Down and Restart actions.
+ */
+ public static Dialog create(@NonNull Context context, ListAdapter adapter) {
+ ViewGroup listView = (ViewGroup) LayoutInflater.from(context).inflate(
+ com.android.systemui.R.layout.global_actions_power_dialog, null);
+
+ for (int i = 0; i < adapter.getCount(); i++) {
+ View action = adapter.getView(i, null, listView);
+ listView.addView(action);
+ }
+
+ Resources res = context.getResources();
+
+ Dialog dialog = new Dialog(context);
+ dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ dialog.setContentView(listView);
+
+ Window window = dialog.getWindow();
+ window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
+ window.setTitle(""); // prevent Talkback from speaking first item name twice
+ window.setBackgroundDrawable(res.getDrawable(
+ com.android.systemui.R.drawable.control_background, context.getTheme()));
+
+ return dialog;
+ }
+}