Merge "Convert PowerOptions menu into a dialog and update styling." into rvc-dev

This commit is contained in:
Aran Ink
2020-06-18 19:18:04 +00:00
committed by Android (Google) Code Review
5 changed files with 184 additions and 34 deletions

View File

@@ -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"
/>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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());
} else {
textView.setText(action.getMessage());
view.setOnClickListener(v -> onClickItem(position));
if (action instanceof LongPressAction) {
view.setOnLongClickListener(v -> onLongClickItem(position));
}
return textView;
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 {
messageView.setText(action.getMessageResId());
}
return view;
}
private boolean onLongClickItem(int position) {
@@ -1569,6 +1579,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();
}
}
}

View File

@@ -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;
}
}