From 58e1e06c87a2679b55d90acd48057aa664e4e770 Mon Sep 17 00:00:00 2001 From: Olivier St-Onge Date: Thu, 14 Mar 2024 14:57:18 -0400 Subject: Reset squishiness fraction of reused tile views when added to new layout Otherwise the tile view's squishiness might differ from the layout squishiness fraction, leading to a bug where a tile's height would sometimes not be updated on configuration changes. Bug: 310377121 Flag: none Test: TileLayoutTest Change-Id: Idfe83541e21ea069036104b8bd7cc42f8d7d5dc4 --- .../SystemUI/src/com/android/systemui/qs/PagedTileLayout.java | 6 ++++++ packages/SystemUI/src/com/android/systemui/qs/TileLayout.java | 9 +++++++++ .../tests/src/com/android/systemui/qs/TileLayoutTest.java | 11 ++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java index 43f3a2242da4..5d2aeef5eb16 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java +++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java @@ -305,6 +305,12 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { page.setMinRows(mMinRows); page.setMaxColumns(mMaxColumns); page.setSelected(false); + + // All pages should have the same squishiness, so grabbing the value from the first page + // and giving it to new pages. + float squishiness = mPages.isEmpty() ? 1f : mPages.get(0).getSquishinessFraction(); + page.setSquishinessFraction(squishiness); + return page; } diff --git a/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java index 9d4eba5aafc2..dcb9288f74be 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java +++ b/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java @@ -110,6 +110,11 @@ public class TileLayout extends ViewGroup implements QSTileLayout { } protected void addTileView(TileRecord tile) { + // Re-using tile views might lead to having out-of-date squishiness. This is fixed by + // making sure we set the correct squishiness value when added to the layout. + if (tile.tileView instanceof HeightOverrideable) { + ((HeightOverrideable) tile.tileView).setSquishinessFraction(mSquishinessFraction); + } addView(tile.tileView); } @@ -349,6 +354,10 @@ public class TileLayout extends ViewGroup implements QSTileLayout { } } + public float getSquishinessFraction() { + return mSquishinessFraction; + } + @Override public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { super.onInitializeAccessibilityNodeInfoInternal(info); diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/TileLayoutTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/TileLayoutTest.java index f809259eedc1..0eae5aae3600 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/TileLayoutTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/TileLayoutTest.java @@ -39,10 +39,11 @@ import android.view.accessibility.AccessibilityNodeInfo; import androidx.test.runner.AndroidJUnit4; -import com.android.systemui.res.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.qs.QSTile; +import com.android.systemui.qs.tileimpl.HeightOverrideable; import com.android.systemui.qs.tileimpl.QSTileViewImpl; +import com.android.systemui.res.R; import org.junit.Before; import org.junit.Test; @@ -87,6 +88,14 @@ public class TileLayoutTest extends SysuiTestCase { verify(tileRecord.tile, times(1)).setListening(mTileLayout, false); } + @Test + public void testAddTile_SetsRightSquishiness() { + QSPanelControllerBase.TileRecord tileRecord = createTileRecord(); + ((HeightOverrideable) tileRecord.tileView).setSquishinessFraction(.5f); + mTileLayout.addTile(tileRecord); + assertEquals(1f, ((HeightOverrideable) tileRecord.tileView).getSquishinessFraction()); + } + @Test public void testSetListening_CallsSetListeningOnTile() { QSPanelControllerBase.TileRecord tileRecord = createTileRecord(); -- cgit v1.2.3-59-g8ed1b