Merge "Configure power menu grid"
diff --git a/packages/SystemUI/res/values-land/config.xml b/packages/SystemUI/res/values-land/config.xml
index 8c5006d..062e33c 100644
--- a/packages/SystemUI/res/values-land/config.xml
+++ b/packages/SystemUI/res/values-land/config.xml
@@ -33,4 +33,10 @@
 
     <!-- Max number of columns for power menu -->
     <integer name="power_menu_max_columns">4</integer>
+
+    <!-- Max number of columns for power menu lite -->
+    <integer name="power_menu_lite_max_columns">4</integer>
+    <!-- Max number of rows for power menu lite -->
+    <integer name="power_menu_lite_max_rows">2</integer>
+
 </resources>
diff --git a/packages/SystemUI/res/values-sw600dp-land/config.xml b/packages/SystemUI/res/values-sw600dp-land/config.xml
index fe546f6..588638f 100644
--- a/packages/SystemUI/res/values-sw600dp-land/config.xml
+++ b/packages/SystemUI/res/values-sw600dp-land/config.xml
@@ -33,4 +33,7 @@
     <!-- Notifications are sized to match the width of two (of 4) qs tiles in landscape. -->
     <bool name="config_skinnyNotifsInLandscape">false</bool>
 
+    <integer name="power_menu_lite_max_columns">3</integer>
+    <integer name="power_menu_lite_max_rows">2</integer>
+
 </resources>
diff --git a/packages/SystemUI/res/values-sw600dp-port/config.xml b/packages/SystemUI/res/values-sw600dp-port/config.xml
index 3c6a81e..857e162 100644
--- a/packages/SystemUI/res/values-sw600dp-port/config.xml
+++ b/packages/SystemUI/res/values-sw600dp-port/config.xml
@@ -23,4 +23,8 @@
 
     <!-- The number of columns in the QuickSettings -->
     <integer name="quick_settings_num_columns">3</integer>
+
+    <integer name="power_menu_lite_max_columns">2</integer>
+    <integer name="power_menu_lite_max_rows">3</integer>
+
 </resources>
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsLayoutLite.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsLayoutLite.java
index f1e5b08..42230ae 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsLayoutLite.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsLayoutLite.java
@@ -16,8 +16,6 @@
 
 package com.android.systemui.globalactions;
 
-import static com.android.systemui.util.leak.RotationUtils.ROTATION_NONE;
-
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.View;
@@ -33,15 +31,9 @@
  * ConstraintLayout implementation of the button layout created by the global actions dialog.
  */
 public class GlobalActionsLayoutLite extends GlobalActionsLayout {
-    private final int mMaxColumns;
-    private final int mMaxRows;
 
     public GlobalActionsLayoutLite(Context context, AttributeSet attrs) {
         super(context, attrs);
-        mMaxColumns = getResources().getInteger(
-                com.android.systemui.R.integer.power_menu_lite_max_columns);
-        mMaxRows = getResources().getInteger(
-                com.android.systemui.R.integer.power_menu_lite_max_rows);
         setOnClickListener(v -> { }); // Prevent parent onClickListener from triggering
     }
 
@@ -60,10 +52,13 @@
     @Override
     public void onUpdateList() {
         super.onUpdateList();
-        int nElementsWrap = (getCurrentRotation() == ROTATION_NONE) ? mMaxColumns : mMaxRows;
+        int nElementsWrap = getResources().getInteger(
+                com.android.systemui.R.integer.power_menu_lite_max_columns);
         int nChildren = getListView().getChildCount() - 1; // don't count flow element
-        if (getCurrentRotation() != ROTATION_NONE && nChildren > mMaxRows) {
-            // up to 4 elements can fit in a row in landscape, otherwise limit for balance
+
+        // Avoid having just one action on the last row if there are more than 2 columns because
+        // it looks unbalanced. Instead, bring the column size down to balance better.
+        if (nChildren == nElementsWrap + 1 && nElementsWrap > 2) {
             nElementsWrap -= 1;
         }
         Flow flow = findViewById(R.id.list_flow);