Ensure QQS does not clip tile views.
- Remove qs_quick_tile_space_width resource in favor of specifying the
max size for QQS when the notification panel's size is large enough.
Change-Id: I6a3ee05fa20d6e8f8f4bd688d310de6a242d26f9
Fixes: 110276500
Test: manually changing window density/size and viewing QQS
diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml
index c59dbdc..bb0c6f6 100644
--- a/packages/SystemUI/res/values-land/dimens.xml
+++ b/packages/SystemUI/res/values-land/dimens.xml
@@ -24,8 +24,6 @@
<dimen name="brightness_mirror_height">40dp</dimen>
- <!-- Width for the spacer, used between QS tiles. -->
- <dimen name="qs_quick_tile_space_width">38dp</dimen>
<dimen name="qs_tile_margin_top">2dp</dimen>
<dimen name="qs_header_tooltip_height">24dp</dimen>
diff --git a/packages/SystemUI/res/values-sw600dp/dimens.xml b/packages/SystemUI/res/values-sw600dp/dimens.xml
index 74acfa2..eb5c180 100644
--- a/packages/SystemUI/res/values-sw600dp/dimens.xml
+++ b/packages/SystemUI/res/values-sw600dp/dimens.xml
@@ -19,9 +19,6 @@
<!-- Standard notification width + gravity -->
<dimen name="notification_panel_width">416dp</dimen>
- <!-- Width for the spacer, used between QS tiles depend on notification_panel_width -->
- <dimen name="qs_quick_tile_space_width">0dp</dimen>
-
<!-- Diameter of outer shape drawable shown in navbar search-->
<dimen name="navbar_search_outerring_diameter">430dip</dimen>
diff --git a/packages/SystemUI/res/values-sw900dp-land/dimen.xml b/packages/SystemUI/res/values-sw900dp-land/dimen.xml
index 55f23dd..ac7e6b8 100644
--- a/packages/SystemUI/res/values-sw900dp-land/dimen.xml
+++ b/packages/SystemUI/res/values-sw900dp-land/dimen.xml
@@ -18,4 +18,9 @@
<resources>
<!-- Standard notification width + gravity for tablet large screen device -->
<dimen name="notification_panel_width">544dp</dimen>
-</resources>
\ No newline at end of file
+
+ <!-- Maximum width of quick quick settings panel. -->
+ <dimen name="qs_quick_layout_width">478dp</dimen>
+
+</resources>
+
diff --git a/packages/SystemUI/res/values-w550dp-land/dimens.xml b/packages/SystemUI/res/values-w550dp-land/dimens.xml
index eaca9d7..2c66454 100644
--- a/packages/SystemUI/res/values-w550dp-land/dimens.xml
+++ b/packages/SystemUI/res/values-w550dp-land/dimens.xml
@@ -18,4 +18,7 @@
<resources>
<!-- Standard notification width + gravity -->
<dimen name="notification_panel_width">544dp</dimen>
+
+ <!-- Maximum width of quick quick settings panel. -->
+ <dimen name="qs_quick_layout_width">478dp</dimen>
</resources>
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index eed1df0..22c1c38 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -348,8 +348,8 @@
<dimen name="qs_tile_margin_top_bottom">12dp</dimen>
<dimen name="qs_tile_margin_top">18dp</dimen>
<dimen name="qs_quick_tile_size">48dp</dimen>
- <!-- Width for the spacer, used between QS tiles. -->
- <dimen name="qs_quick_tile_space_width">0dp</dimen>
+ <!-- Maximum width of quick quick settings panel. Defaults to MATCH_PARENT-->
+ <dimen name="qs_quick_layout_width">-1px</dimen>
<dimen name="qs_quick_tile_padding">12dp</dimen>
<dimen name="qs_header_gear_translation">16dp</dimen>
<dimen name="qs_header_tile_margin_horizontal">0dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
index 6dbe119..1c50f79 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
@@ -192,29 +192,21 @@
mTileDimensionSize = mContext.getResources().getDimensionPixelSize(
R.dimen.qs_quick_tile_size);
-
- setGravity(Gravity.CENTER);
- setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
+ updateLayoutParams();
}
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
+ updateLayoutParams();
+ }
+ private void updateLayoutParams() {
setGravity(Gravity.CENTER);
- LayoutParams staticSpaceLayoutParams = generateSpaceLayoutParams(
- mContext.getResources().getDimensionPixelSize(
- R.dimen.qs_quick_tile_space_width));
-
- // Update space params since they fill any open space in portrait orientation and have
- // a static width in landscape orientation.
- final int childViewCount = getChildCount();
- for (int i = 0; i < childViewCount; i++) {
- View childView = getChildAt(i);
- if (childView instanceof Space) {
- childView.setLayoutParams(staticSpaceLayoutParams);
- }
- }
+ int width = getResources().getDimensionPixelSize(R.dimen.qs_quick_layout_width);
+ LayoutParams lp = new LayoutParams(width, LayoutParams.MATCH_PARENT);
+ lp.gravity = Gravity.CENTER_HORIZONTAL;
+ setLayoutParams(lp);
}
/**
@@ -222,11 +214,9 @@
* then we're going to have the space expand to take up as much space as possible. If the
* width is non-zero, we want the inter-tile spacers to be fixed.
*/
- private LayoutParams generateSpaceLayoutParams(int spaceWidth) {
- LayoutParams lp = new LayoutParams(spaceWidth, mTileDimensionSize);
- if (spaceWidth == 0) {
- lp.weight = 1;
- }
+ private LayoutParams generateSpaceLayoutParams() {
+ LayoutParams lp = new LayoutParams(0, mTileDimensionSize);
+ lp.weight = 1;
lp.gravity = Gravity.CENTER;
return lp;
}
@@ -243,13 +233,7 @@
@Override
public void addTile(TileRecord tile) {
if (getChildCount() != 0) {
- // Add a spacer between tiles. We want static-width spaces if we're in landscape to
- // keep the tiles close. For portrait, we stick with spaces that fill up any
- // available space.
- LayoutParams spaceLayoutParams = generateSpaceLayoutParams(
- mContext.getResources().getDimensionPixelSize(
- R.dimen.qs_quick_tile_space_width));
- addView(new Space(mContext), getChildCount(), spaceLayoutParams);
+ addView(new Space(mContext), getChildCount(), generateSpaceLayoutParams());
}
addView(tile.tileView, getChildCount(), generateTileLayoutParams());
@@ -305,6 +289,10 @@
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ if (hideOverflowingChildren(widthMeasureSpec)) {
+ return; // Rely on visibility change to trigger remeasure.
+ }
+
if (mRecords != null && mRecords.size() > 0) {
View previousView = this;
for (TileRecord record : mRecords) {
@@ -317,5 +305,32 @@
R.id.expand_indicator);
}
}
+
+ /**
+ * Hide child views that would otherwise be clipped.
+ * @return {@code true} if any child visibilities have changed.
+ */
+ private boolean hideOverflowingChildren(int widthMeasureSpec) {
+ if (getChildCount() == 0) {
+ return false;
+ }
+ boolean childVisibilityChanged = false;
+ int widthRemaining = MeasureSpec.getSize(widthMeasureSpec)
+ - getChildAt(0).getMeasuredWidth() - getPaddingStart() - getPaddingEnd();
+ for (int i = 2; i < getChildCount(); i += 2) {
+ View tileChild = getChildAt(i);
+ LayoutParams lp = (LayoutParams) tileChild.getLayoutParams();
+ // All Space views have 0 width; only tiles contribute to the total width.
+ widthRemaining = widthRemaining
+ - tileChild.getMeasuredWidth() - lp.getMarginEnd() - lp.getMarginStart();
+ int newVisibility = widthRemaining < 0 ? View.GONE : View.VISIBLE;
+ if (tileChild.getVisibility() != newVisibility) {
+ tileChild.setVisibility(newVisibility);
+ getChildAt(i - 1).setVisibility(newVisibility); // Hide spacer as well.
+ childVisibilityChanged = true;
+ }
+ }
+ return childVisibilityChanged;
+ }
}
}