From 8c736aa4f96eed7c49ca5d10666de01223064c56 Mon Sep 17 00:00:00 2001 From: Beverly Date: Wed, 10 Jun 2020 17:42:32 -0400 Subject: [PATCH] Set PageIndicator pages in QSPanel#onMeasure Pre-emptively update PageIndicator's numPages before measuring in QSPanel so that views will be appropriately measured. Previously, new PageIndicator child views would be added in the middle of a QSPanel layout pass after already being measured, so the new PageIndicator child wouldn't be measured. Test: manually add and remove new QS tiles. rotate between landscape + portrait modes. observe the PageIndicator is correct. Fixes: 157542221 Change-Id: Ic1bb29039dd12993a50758bf48a4ad792d8cdfc3 --- .../android/systemui/qs/PagedTileLayout.java | 26 ++++++++++++------- .../src/com/android/systemui/qs/QSPanel.java | 7 ++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java index 28369925367ae..3eed8ad89075f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java +++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java @@ -291,15 +291,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { } private void emptyAndInflateOrRemovePages() { - final int nTiles = mTiles.size(); - // We should always have at least one page, even if it's empty. - int numPages = Math.max(nTiles / mPages.get(0).maxTiles(), 1); - - // Add one more not full page if needed - if (nTiles > numPages * mPages.get(0).maxTiles()) { - numPages++; - } - + final int numPages = getNumPages(); final int NP = mPages.size(); for (int i = 0; i < NP; i++) { mPages.get(i).removeAllViews(); @@ -431,6 +423,22 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { return mPages.get(0).mColumns; } + /** + * Gets the number of pages in this paged tile layout + */ + public int getNumPages() { + final int nTiles = mTiles.size(); + // We should always have at least one page, even if it's empty. + int numPages = Math.max(nTiles / mPages.get(0).maxTiles(), 1); + + // Add one more not full page if needed + if (nTiles > numPages * mPages.get(0).maxTiles()) { + numPages++; + } + + return numPages; + } + public int getNumVisibleTiles() { if (mPages.size() == 0) return 0; TilePage currentPage = mPages.get(getCurrentPageNumber()); diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java index ecdb2c91ca48d..0fc3829fab66d 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java @@ -240,8 +240,13 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - if (mTileLayout instanceof PagedTileLayout) { + // Since PageIndicator gets measured before PagedTileLayout, we preemptively set the + // # of pages before the measurement pass so PageIndicator is measured appropriately + if (mFooterPageIndicator != null) { + mFooterPageIndicator.setNumPages(((PagedTileLayout) mTileLayout).getNumPages()); + } + // Allow the UI to be as big as it want's to, we're in a scroll view int newHeight = 10000; int availableHeight = MeasureSpec.getSize(heightMeasureSpec);