From 79cfa8925b294f1c6433c0e7761c567606532736 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Mon, 17 May 2021 16:23:15 -0400 Subject: [PATCH] Fix margins between headers and tiles. Also: * Remove old classes. * Change height of tiles. * Add back clipping on PagedTileLayout, as the views don't need to go outside its bounds. * Fix a scrolling issue Fixes: 187460996 Fixes: 187966021 Fixes: 187334034 Fixes: 188459321 Test: manual Change-Id: Ide520f26982a3f2c8918424cb4c14d3d14da3724 --- .../SystemUI/res/layout/qs_paged_page.xml | 4 +- .../res/layout/qs_paged_tile_layout.xml | 5 +- .../quick_status_bar_expanded_header.xml | 2 +- packages/SystemUI/res/values-land/dimens.xml | 10 +- packages/SystemUI/res/values/dimens.xml | 14 +- .../systemui/qs/DoubleLineTileLayout.kt | 164 ------------------ .../android/systemui/qs/PagedTileLayout.java | 3 - .../android/systemui/qs/QSContainerImpl.java | 11 +- .../src/com/android/systemui/qs/QSPanel.java | 16 ++ .../com/android/systemui/qs/QuickQSPanel.java | 159 ----------------- .../systemui/qs/QuickStatusBarHeader.java | 6 + .../com/android/systemui/qs/TileLayout.java | 15 +- 12 files changed, 48 insertions(+), 361 deletions(-) delete mode 100644 packages/SystemUI/src/com/android/systemui/qs/DoubleLineTileLayout.kt diff --git a/packages/SystemUI/res/layout/qs_paged_page.xml b/packages/SystemUI/res/layout/qs_paged_page.xml index c83077371bb06..a4f0a0c85d411 100644 --- a/packages/SystemUI/res/layout/qs_paged_page.xml +++ b/packages/SystemUI/res/layout/qs_paged_page.xml @@ -18,6 +18,4 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tile_page" android:layout_width="match_parent" - android:layout_height="match_parent" - android:clipChildren="false" - android:clipToPadding="false" /> + android:layout_height="match_parent"/> diff --git a/packages/SystemUI/res/layout/qs_paged_tile_layout.xml b/packages/SystemUI/res/layout/qs_paged_tile_layout.xml index 666ec2705e5d4..6b054a91d46b9 100644 --- a/packages/SystemUI/res/layout/qs_paged_tile_layout.xml +++ b/packages/SystemUI/res/layout/qs_paged_tile_layout.xml @@ -20,7 +20,4 @@ android:id="@+id/qs_pager" android:layout_width="match_parent" android:layout_height="0dp" - android:layout_weight="1" - android:clipChildren="false" - android:clipToPadding="false" - android:paddingBottom="@dimen/qs_paged_tile_layout_padding_bottom" /> + android:layout_weight="1"/> diff --git a/packages/SystemUI/res/layout/quick_status_bar_expanded_header.xml b/packages/SystemUI/res/layout/quick_status_bar_expanded_header.xml index d8f0742e18781..f9dcd390cd510 100644 --- a/packages/SystemUI/res/layout/quick_status_bar_expanded_header.xml +++ b/packages/SystemUI/res/layout/quick_status_bar_expanded_header.xml @@ -50,7 +50,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/quick_qs_status_icons" - android:layout_marginTop="8dp" + android:layout_marginTop="@dimen/qqs_layout_margin_top" android:accessibilityTraversalAfter="@id/quick_qs_status_icons" android:clipChildren="false" android:clipToPadding="false" diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml index 96809dc2ff55b..c6931e82ba70c 100644 --- a/packages/SystemUI/res/values-land/dimens.xml +++ b/packages/SystemUI/res/values-land/dimens.xml @@ -22,13 +22,15 @@ 2dp 16dp - 8dp - + 84dp + 0dp + 12dp + 8dp - 44dp + 48dp @*android:dimen/quick_qs_offset_height 14dp diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index e7d714e60076e..32da8f534692c 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -536,21 +536,22 @@ 25dp 28dp - 88dp + 84dp 18dp 8dp - 2dp @dimen/qs_tile_margin_horizontal 4dp -4dp + 8dp + 24dp + 16dp - 54dp + 68dp 8dp - 18dp -1dp 56dp 20dp @@ -610,7 +611,6 @@ 32dp 4dp 20dp - 0dp 15dp 14dp @@ -1251,8 +1251,6 @@ 10sp - 8dp - 16dp 72dp diff --git a/packages/SystemUI/src/com/android/systemui/qs/DoubleLineTileLayout.kt b/packages/SystemUI/src/com/android/systemui/qs/DoubleLineTileLayout.kt deleted file mode 100644 index 4f577f312a9c1..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/qs/DoubleLineTileLayout.kt +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2019 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.qs - -import android.content.Context -import android.content.res.Configuration -import android.view.View -import android.view.ViewGroup -import com.android.internal.logging.UiEventLogger -import com.android.systemui.R -import com.android.systemui.qs.TileLayout.exactly - -class DoubleLineTileLayout( - context: Context -) : ViewGroup(context), QSPanel.QSTileLayout { - - companion object { - private const val NUM_LINES = 2 - } - - protected val mRecords = ArrayList() - private var _listening = false - private var smallTileSize = 0 - private val twoLineHeight - get() = smallTileSize * NUM_LINES + cellMarginVertical * (NUM_LINES - 1) - private var cellMarginHorizontal = 0 - private var cellMarginVertical = 0 - private var tilesToShow = 0 - - init { - isFocusableInTouchMode = true - clipChildren = false - clipToPadding = false - - updateResources() - } - - override fun addTile(tile: QSPanelControllerBase.TileRecord) { - mRecords.add(tile) - tile.tile.setListening(this, _listening) - addTileView(tile) - } - - protected fun addTileView(tile: QSPanelControllerBase.TileRecord) { - addView(tile.tileView) - } - - override fun removeTile(tile: QSPanelControllerBase.TileRecord) { - mRecords.remove(tile) - tile.tile.setListening(this, false) - removeView(tile.tileView) - } - - override fun removeAllViews() { - mRecords.forEach { it.tile.setListening(this, false) } - mRecords.clear() - super.removeAllViews() - } - - override fun getOffsetTop(tile: QSPanelControllerBase.TileRecord?) = top - - override fun updateResources(): Boolean { - with(mContext.resources) { - smallTileSize = getDimensionPixelSize(R.dimen.qs_quick_tile_size) - cellMarginHorizontal = getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal_two_line) - cellMarginVertical = getDimensionPixelSize(R.dimen.new_qs_vertical_margin) - } - requestLayout() - return false - } - - override fun setListening(listening: Boolean, uiEventLogger: UiEventLogger) { - if (_listening == listening) return - _listening = listening - for (record in mRecords) { - record.tile.setListening(this, listening) - } - if (listening) { - for (i in 0 until numVisibleTiles) { - val tile = mRecords[i].tile - uiEventLogger.logWithInstanceId( - QSEvent.QQS_TILE_VISIBLE, 0, tile.metricsSpec, tile.instanceId) - } - } - } - - override fun getNumVisibleTiles() = Math.min(mRecords.size, tilesToShow) - - override fun onConfigurationChanged(newConfig: Configuration) { - super.onConfigurationChanged(newConfig) - updateResources() - postInvalidate() - } - - override fun onFinishInflate() { - updateResources() - } - - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - - mRecords.forEach { - it.tileView.measure(exactly(smallTileSize), exactly(smallTileSize)) - } - - val height = twoLineHeight + paddingBottom + paddingTop - setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), height) - } - - private fun calculateMaxColumns(availableWidth: Int): Int { - if (smallTileSize + cellMarginHorizontal == 0) { - return 0 - } else { - return (availableWidth - smallTileSize) / (smallTileSize + cellMarginHorizontal) + 1 - } - } - - override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { - val availableWidth = r - l - paddingLeft - paddingRight - val maxColumns = calculateMaxColumns(availableWidth) - val actualColumns = Math.min(maxColumns, mRecords.size / NUM_LINES) - if (actualColumns == 0) { - // No tileSize or horizontal margin - return - } - tilesToShow = actualColumns * NUM_LINES - - val spacePerTile = availableWidth / actualColumns - - for (index in 0 until mRecords.size) { - val tileView = mRecords[index].tileView - if (index >= tilesToShow) { - tileView.visibility = View.GONE - } else { - tileView.visibility = View.VISIBLE - if (index > 0) tileView.updateAccessibilityOrder(mRecords[index - 1].tileView) - val column = index % actualColumns - val left = getLeftForColumn(column, spacePerTile) - val top = if (index < actualColumns) 0 else getTopBottomRow() - tileView.layout(left, top, left + smallTileSize, top + smallTileSize) - } - } - } - - private fun getLeftForColumn(column: Int, spacePerTile: Int): Int { - // Distribute the space evenly among all tiles. - return (column * spacePerTile + spacePerTile / 2.0f - smallTileSize / 2.0f).toInt() - } - - private fun getTopBottomRow() = smallTileSize + cellMarginVertical -} \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java index aa4fb712090b4..e0c8af6b89776 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java +++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java @@ -332,9 +332,6 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { @Override public boolean updateResources() { - setPadding(0, 0, 0, - getContext().getResources().getDimensionPixelSize( - R.dimen.qs_paged_tile_layout_padding_bottom)); boolean changed = false; for (int i = 0; i < mPages.size(); i++) { changed |= mPages.get(i).updateResources(); diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java b/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java index 3a3f3f1ca7ea2..cd97f976540d5 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java @@ -199,10 +199,13 @@ public class QSContainerImpl extends FrameLayout { void updateResources(QSPanelController qsPanelController, QuickStatusBarHeaderController quickStatusBarHeaderController) { - LayoutParams layoutParams = (LayoutParams) mQSPanelContainer.getLayoutParams(); - layoutParams.topMargin = mContext.getResources().getDimensionPixelSize( - com.android.internal.R.dimen.quick_qs_offset_height); - mQSPanelContainer.setLayoutParams(layoutParams); + mQSPanelContainer.setPaddingRelative( + getPaddingStart(), + mContext.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.quick_qs_offset_height), + getPaddingEnd(), + getPaddingBottom() + ); int sideMargins = getResources().getDimensionPixelSize(R.dimen.notification_side_paddings); int padding = getResources().getDimensionPixelSize( diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java index 7062e8cea207c..01a668487af39 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java @@ -165,9 +165,23 @@ public class QSPanel extends LinearLayout implements Tunable { } addView(view, 0); mBrightnessView = view; + + setBrightnessViewMargin(); + mMovableContentStartIndex++; } + private void setBrightnessViewMargin() { + if (mBrightnessView != null) { + MarginLayoutParams lp = (MarginLayoutParams) mBrightnessView.getLayoutParams(); + lp.topMargin = mContext.getResources() + .getDimensionPixelSize(R.dimen.qs_brightness_margin_top); + lp.bottomMargin = mContext.getResources() + .getDimensionPixelSize(R.dimen.qs_brightness_margin_bottom); + mBrightnessView.setLayoutParams(lp); + } + } + /** */ public QSTileLayout createRegularTileLayout() { if (mRegularTileLayout == null) { @@ -291,6 +305,8 @@ public class QSPanel extends LinearLayout implements Tunable { updatePageIndicator(); + setBrightnessViewMargin(); + if (mTileLayout != null) { mTileLayout.updateResources(); } diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java index c3458feb5dfef..9a697b1fe2ce5 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java @@ -18,9 +18,7 @@ package com.android.systemui.qs; import android.content.Context; import android.content.res.Configuration; -import android.graphics.Rect; import android.util.AttributeSet; -import android.view.Gravity; import android.view.View; import android.widget.LinearLayout; @@ -49,19 +47,6 @@ public class QuickQSPanel extends QSPanel { getResources().getInteger(R.integer.quick_qs_panel_max_columns)); } - @Override - void initialize() { - super.initialize(); - applyBottomMargin((View) mRegularTileLayout); - } - - private void applyBottomMargin(View view) { - int margin = getResources().getDimensionPixelSize(R.dimen.qs_header_tile_margin_bottom); - MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams(); - layoutParams.bottomMargin = margin; - view.setLayoutParams(layoutParams); - } - @Override public void setBrightnessView(View view) { // Don't add brightness view @@ -188,150 +173,6 @@ public class QuickQSPanel extends QSPanel { return QSEvent.QQS_TILE_VISIBLE; } - private static class HeaderTileLayout extends TileLayout { - - private Rect mClippingBounds = new Rect(); - - HeaderTileLayout(Context context) { - super(context); - setClipChildren(false); - setClipToPadding(false); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, - LayoutParams.WRAP_CONTENT); - lp.gravity = Gravity.CENTER_HORIZONTAL; - setLayoutParams(lp); - } - - @Override - protected void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - updateResources(); - } - - @Override - public void onFinishInflate(){ - super.onFinishInflate(); - updateResources(); - } - - private LayoutParams generateTileLayoutParams() { - LayoutParams lp = new LayoutParams(mCellWidth, mCellHeight); - return lp; - } - - @Override - protected void addTileView(QSPanelControllerBase.TileRecord tile) { - addView(tile.tileView, getChildCount(), generateTileLayoutParams()); - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - // We only care about clipping on the right side - mClippingBounds.set(0, 0, r - l, 10000); - setClipBounds(mClippingBounds); - - calculateColumns(); - - for (int i = 0; i < mRecords.size(); i++) { - mRecords.get(i).tileView.setVisibility( i < mColumns ? View.VISIBLE : View.GONE); - } - - setAccessibilityOrder(); - layoutTileRecords(mColumns); - } - - @Override - public boolean updateResources() { - mCellWidth = mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size); - mCellHeight = mCellWidth; - - return false; - } - - private boolean calculateColumns() { - int prevNumColumns = mColumns; - int maxTiles = mRecords.size(); - - if (maxTiles == 0){ // Early return during setup - mColumns = 0; - return true; - } - - final int availableWidth = getMeasuredWidth() - getPaddingStart() - getPaddingEnd(); - final int leftoverWhitespace = availableWidth - maxTiles * mCellWidth; - - if (leftoverWhitespace > 0) { - mCellMarginHorizontal = leftoverWhitespace / Math.max(1, maxTiles); - mColumns = maxTiles; - } else{ - mColumns = mCellWidth == 0 ? 1 : - Math.min(maxTiles, availableWidth / mCellWidth ); - // If we can only fit one column, use mCellMarginHorizontal to center it. - if (mColumns == 1) { - mCellMarginHorizontal = (availableWidth - mCellWidth) / 2; - } else { - mCellMarginHorizontal = - (availableWidth - mColumns * mCellWidth) / mColumns; - } - - } - return mColumns != prevNumColumns; - } - - private void setAccessibilityOrder() { - if (mRecords != null && mRecords.size() > 0) { - View previousView = this; - for (QSPanelControllerBase.TileRecord record : mRecords) { - if (record.tileView.getVisibility() == GONE) continue; - previousView = record.tileView.updateAccessibilityOrder(previousView); - } - } - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - // Measure each QS tile. - for (QSPanelControllerBase.TileRecord record : mRecords) { - if (record.tileView.getVisibility() == GONE) continue; - record.tileView.measure(exactly(mCellWidth), exactly(mCellHeight)); - } - - int height = mCellHeight; - if (height < 0) height = 0; - - setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), height); - } - - @Override - public int getNumVisibleTiles() { - return Math.min(mRecords.size(), mColumns); - } - - @Override - protected int getColumnStart(int column) { - if (mColumns == 1) { - // Only one column/tile. Use the margin to center the tile. - return getPaddingStart() + mCellMarginHorizontal; - } - return getPaddingStart() + mCellMarginHorizontal / 2 - + column * (mCellWidth + mCellMarginHorizontal); - } - - @Override - public void setListening(boolean listening, UiEventLogger uiEventLogger) { - boolean startedListening = !mListening && listening; - super.setListening(listening, uiEventLogger); - if (startedListening) { - // getNumVisibleTiles() <= mRecords.size() - for (int i = 0; i < getNumVisibleTiles(); i++) { - QSTile tile = mRecords.get(i).tile; - uiEventLogger.logWithInstanceId(QSEvent.QQS_TILE_VISIBLE, 0, - tile.getMetricsSpec(), tile.getInstanceId()); - } - } - } - } - static class QQSSideLabelTileLayout extends SideLabelTileLayout { QQSSideLabelTileLayout(Context context) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java index 81b5318d80895..f66872286f90a 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java @@ -225,6 +225,12 @@ public class QuickStatusBarHeader extends FrameLayout { mBatteryRemainingIcon.updateColors(mTextColorPrimary, textColorSecondary, mTextColorPrimary); } + + MarginLayoutParams qqsLP = (MarginLayoutParams) mHeaderQsPanel.getLayoutParams(); + qqsLP.topMargin = mContext.getResources() + .getDimensionPixelSize(R.dimen.qqs_layout_margin_top); + mHeaderQsPanel.setLayoutParams(qqsLP); + updateHeadersPadding(); updateAnimators(); } diff --git a/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java index 96712bd9297c1..3e558a962427f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java +++ b/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java @@ -19,7 +19,6 @@ import java.util.ArrayList; public class TileLayout extends ViewGroup implements QSTileLayout { public static final int NO_MAX_COLUMNS = 100; - private static final float TILE_ASPECT = 1.2f; private static final String TAG = "TileLayout"; @@ -34,7 +33,6 @@ public class TileLayout extends ViewGroup implements QSTileLayout { protected int mRows = 1; protected final ArrayList mRecords = new ArrayList<>(); - private int mCellMarginTop; protected boolean mListening; protected int mMaxAllowedRows = 3; @@ -123,7 +121,6 @@ public class TileLayout extends ViewGroup implements QSTileLayout { mCellMarginHorizontal = res.getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal); mSidePadding = useSidePadding() ? mCellMarginHorizontal / 2 : 0; mCellMarginVertical= res.getDimensionPixelSize(R.dimen.qs_tile_margin_vertical); - mCellMarginTop = res.getDimensionPixelSize(R.dimen.qs_tile_margin_top); mMaxAllowedRows = Math.max(1, getResources().getInteger(R.integer.quick_settings_max_rows)); if (mLessRows) mMaxAllowedRows = Math.max(mMinRows, mMaxAllowedRows - 1); if (updateColumns()) { @@ -169,10 +166,7 @@ public class TileLayout extends ViewGroup implements QSTileLayout { mCellHeight = record.tileView.getMeasuredHeight(); } - // Only include the top margin in our measurement if we have more than 1 row to show. - // Otherwise, don't add the extra margin buffer at top. - int height = (mCellHeight + mCellMarginVertical) * mRows + - (mRows != 0 ? (mCellMarginTop - mCellMarginVertical) : 0); + int height = (mCellHeight + mCellMarginVertical) * mRows; if (height < 0) height = 0; setMeasuredDimension(width, height); @@ -186,9 +180,8 @@ public class TileLayout extends ViewGroup implements QSTileLayout { * @param tilesCount Upper limit on the number of tiles to show. to prevent empty rows. */ public boolean updateMaxRows(int allowedHeight, int tilesCount) { - final int availableHeight = allowedHeight - mCellMarginTop - // Add the cell margin in order to divide easily by the height + the margin below - + mCellMarginVertical; + // Add the cell margin in order to divide easily by the height + the margin below + final int availableHeight = allowedHeight + mCellMarginVertical; final int previousRows = mRows; mRows = availableHeight / (getCellHeight() + mCellMarginVertical); if (mRows < mMinRows) { @@ -243,7 +236,7 @@ public class TileLayout extends ViewGroup implements QSTileLayout { } protected int getRowTop(int row) { - return row * (mCellHeight + mCellMarginVertical) + mCellMarginTop; + return row * (mCellHeight + mCellMarginVertical); } protected int getColumnStart(int column) {