From 1696ace37c58d93319f871e0e4e97b1ef5a75ed6 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Mon, 26 Oct 2020 09:17:45 -0400 Subject: [PATCH] Use proper size for indexing We are indexing over mRecords, so use its size to determine index limit in the layouts used in QuickQSPanel The issue is introduced in the refactor of QS as the tiles are now set in QSPanelControllerBase#switchTileLayout, after the switch is completed. Test: manual, dismiss media while in landscape Fixes: 171628022 Change-Id: I5f0caf73f7637ea8308d8795b0a60825025d6c5b --- .../src/com/android/systemui/qs/DoubleLineTileLayout.kt | 2 +- .../SystemUI/src/com/android/systemui/qs/QSPanel.java | 9 ++++++++- .../com/android/systemui/qs/QSPanelControllerBase.java | 1 + .../src/com/android/systemui/qs/QuickQSPanel.java | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/DoubleLineTileLayout.kt b/packages/SystemUI/src/com/android/systemui/qs/DoubleLineTileLayout.kt index 81076475c5ce1..6ac1e7079531a 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/DoubleLineTileLayout.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/DoubleLineTileLayout.kt @@ -99,7 +99,7 @@ class DoubleLineTileLayout( } } - override fun getNumVisibleTiles() = tilesToShow + override fun getNumVisibleTiles() = Math.min(mRecords.size, tilesToShow) override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java index 1b17a2a277f2f..76f244652cd9c 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java @@ -480,7 +480,6 @@ public class QSPanel extends LinearLayout implements Tunable, BrightnessMirrorLi } } mTileLayout = newLayout; - newLayout.setListening(mListening); if (needsDynamicRowsAndColumns()) { newLayout.setMinRows(horizontal ? 2 : 1); // Let's use 3 columns to match the current layout @@ -498,6 +497,14 @@ public class QSPanel extends LinearLayout implements Tunable, BrightnessMirrorLi return false; } + /** + * Sets the listening state of the current layout to the state of the view. Used after + * switching layouts. + */ + public void reSetLayoutListening() { + mTileLayout.setListening(mListening); + } + private void updateHorizontalLinearLayoutMargins() { if (mHorizontalLinearLayout != null && !displayMediaMarginsOnMedia()) { LayoutParams lp = (LayoutParams) mHorizontalLinearLayout.getLayoutParams(); diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java index fe92827806c6e..68a6cdcbd2899 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java @@ -214,6 +214,7 @@ public abstract class QSPanelControllerBase extends ViewContr boolean switchTileLayout(boolean force) { if (mView.switchTileLayout(force, mRecords)) { setTiles(); + mView.reSetLayoutListening(); return true; } return false; diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java index 84a5b6f0538d9..ed0900d07b561 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java @@ -336,7 +336,7 @@ public class QuickQSPanel extends QSPanel { @Override public int getNumVisibleTiles() { - return mColumns; + return Math.min(mRecords.size(), mColumns); } @Override @@ -353,6 +353,7 @@ public class QuickQSPanel extends QSPanel { boolean startedListening = !mListening && listening; super.setListening(listening); if (startedListening) { + // getNumVisibleTiles() <= mRecords.size() for (int i = 0; i < getNumVisibleTiles(); i++) { QSTile tile = mRecords.get(i).tile; mUiEventLogger.logWithInstanceId(QSEvent.QQS_TILE_VISIBLE, 0,