From 1f0b93cf59d48990cfb800d4f3dc3ae8a3eeabc1 Mon Sep 17 00:00:00 2001 From: SagarMakhar <sagarmakhar@gmail.com> Date: Thu, 21 Oct 2021 11:10:09 +0000 Subject: [PATCH] Use flow layout for advanced power menu as well Change-Id: I62e46729278d57b8b21aa0c307f25d9ec053b216 Signed-off-by: SamarV-121 <samarvispute121@pm.me> --- .../global_actions_power_dialog_flow.xml | 38 +++++++++++++++++++ .../GlobalActionsDialogLite.java | 2 +- .../GlobalActionsPowerDialog.java | 11 +++++- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 packages/SystemUI/res/layout/global_actions_power_dialog_flow.xml diff --git a/packages/SystemUI/res/layout/global_actions_power_dialog_flow.xml b/packages/SystemUI/res/layout/global_actions_power_dialog_flow.xml new file mode 100644 index 000000000000..1b4c8f36a5be --- /dev/null +++ b/packages/SystemUI/res/layout/global_actions_power_dialog_flow.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2021 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. +--> +<androidx.constraintlayout.widget.ConstraintLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/power_actions_container" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:background="@drawable/global_actions_lite_background" + android:padding="@dimen/global_actions_lite_padding"> + + <androidx.constraintlayout.helper.widget.Flow + android:id="@+id/power_flow" + android:layout_width="match_parent" + android:layout_height="wrap_content" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:flow_wrapMode="chain" + app:flow_maxElementsWrap="2" + app:flow_horizontalGap="@dimen/global_actions_lite_padding" + app:flow_verticalGap="@dimen/global_actions_lite_padding" + app:flow_horizontalStyle="packed"/> +</androidx.constraintlayout.widget.ConstraintLayout> diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java index 5a3d339ebd1a..62326c581364 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java @@ -1600,7 +1600,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene Log.w(TAG, "No power options action found at position: " + position); return null; } - int viewLayoutResource = com.android.systemui.R.layout.global_actions_power_item; + int viewLayoutResource = com.android.systemui.R.layout.global_actions_grid_item_lite; View view = convertView != null ? convertView : LayoutInflater.from(mContext).inflate(viewLayoutResource, parent, false); view.setOnClickListener(v -> onClickItem(position)); diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPowerDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPowerDialog.java index caa88a372036..ec627a148036 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPowerDialog.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPowerDialog.java @@ -26,6 +26,8 @@ import android.view.Window; import android.view.WindowManager; import android.widget.ListAdapter; +import androidx.constraintlayout.helper.widget.Flow; + /** * Creates a customized Dialog for displaying the Shut Down and Restart actions. */ @@ -36,11 +38,15 @@ public class GlobalActionsPowerDialog { */ 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); + com.android.systemui.R.layout.global_actions_power_dialog_flow, null); + + Flow flow = listView.findViewById(com.android.systemui.R.id.power_flow); for (int i = 0; i < adapter.getCount(); i++) { View action = adapter.getView(i, null, listView); + action.setId(View.generateViewId()); listView.addView(action); + flow.addView(action); } Resources res = context.getResources(); @@ -53,7 +59,8 @@ public class GlobalActionsPowerDialog { 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())); + com.android.systemui.R.drawable.global_actions_lite_background, + context.getTheme())); window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); return dialog; -- GitLab