diff options
6 files changed, 54 insertions, 36 deletions
diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml index c59dbdc32158..bb0c6f6acb06 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 74acfa2a6e36..eb5c180aa754 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 55f23dd9cac3..ac7e6b815666 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 eaca9d718fd2..2c6645480abf 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 eed1df0ffbee..22c1c38b4505 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 6dbe1199c967..1c50f797e1a7 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 @@ public class QuickQSPanel extends QSPanel { 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 @@ public class QuickQSPanel extends QSPanel { * 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 @@ public class QuickQSPanel extends QSPanel { @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 @@ public class QuickQSPanel extends QSPanel { @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 @@ public class QuickQSPanel extends QSPanel { 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; + } } } |