From 9978c55a34f5329671de936d71877de18641d682 Mon Sep 17 00:00:00 2001 From: Amin Shaikh Date: Thu, 22 Mar 2018 07:24:41 -0400 Subject: [PATCH] Listen to all attached QS pages. Instead of only listening to the tiles on the current QS page, listen to its neighbors as well. Remove all custom page tracking logic and rely on the PagerAdapter lifecycle to update the listening status of each page. Change-Id: Idb8452d532147467704bf6654c662342da78eddd Fixes: 34804413 Test: visual --- .../android/systemui/qs/PagedTileLayout.java | 64 ++++--------------- 1 file changed, 12 insertions(+), 52 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java index ea3a60b932466..892395222d1fb 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java +++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java @@ -42,16 +42,14 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { }; - private final ArrayList mTiles = new ArrayList(); - private final ArrayList mPages = new ArrayList(); + private final ArrayList mTiles = new ArrayList<>(); + private final ArrayList mPages = new ArrayList<>(); private PageIndicator mPageIndicator; private int mNumPages; private PageListener mPageListener; - private int mPosition; - private boolean mOffPage; private boolean mListening; private Scroller mScroller; @@ -85,16 +83,12 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { public void setListening(boolean listening) { if (mListening == listening) return; mListening = listening; - if (mListening) { - setPageListening(mPosition, true); - if (mOffPage) { - setPageListening(mPosition + 1, true); - } - } else { - // Make sure no pages are listening. - for (int i = 0; i < mPages.size(); i++) { - mPages.get(i).setListening(false); - } + updateListening(); + } + + private void updateListening() { + for (TilePage tilePage : mPages) { + tilePage.setListening(tilePage.getParent() == null ? false : mListening); } } @@ -137,43 +131,6 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { super.computeScroll(); } - /** - * Sets individual pages to listening or not. If offPage it will set - * the next page after position to listening as well since we are in between - * pages. - */ - private void setCurrentPage(int position, boolean offPage) { - if (mPosition == position && mOffPage == offPage) return; - if (mListening) { - if (mPosition != position) { - // Clear out the last pages from listening. - setPageListening(mPosition, false); - if (mOffPage) { - setPageListening(mPosition + 1, false); - } - // Set the new pages to listening - setPageListening(position, true); - if (offPage) { - setPageListening(position + 1, true); - } - } else if (mOffPage != offPage) { - // Whether we are showing position + 1 has changed. - setPageListening(mPosition + 1, offPage); - } - } - // Save the current state. - mPosition = position; - mOffPage = offPage; - } - - private void setPageListening(int position, boolean listening) { - if (position >= mPages.size()) return; - if (isLayoutRtl()) { - position = mPages.size() - 1 - position; - } - mPages.get(position).setListening(listening); - } - @Override public boolean hasOverlappingRendering() { return false; @@ -362,7 +319,6 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (mPageIndicator == null) return; - setCurrentPage(position, positionOffset != 0); mPageIndicator.setLocation(position + positionOffset); if (mPageListener != null) { mPageListener.onPageChanged(positionOffsetPixels == 0 && @@ -407,11 +363,14 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { } private final PagerAdapter mAdapter = new PagerAdapter() { + @Override public void destroyItem(ViewGroup container, int position, Object object) { if (DEBUG) Log.d(TAG, "Destantiating " + position); container.removeView((View) object); + updateListening(); } + @Override public Object instantiateItem(ViewGroup container, int position) { if (DEBUG) Log.d(TAG, "Instantiating " + position); if (isLayoutRtl()) { @@ -419,6 +378,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { } ViewGroup view = mPages.get(position); container.addView(view); + updateListening(); return view; }