Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58e1e06c authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

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
parent 0ddacc17
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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;
    }

+9 −0
Original line number Diff line number Diff line
@@ -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);
+10 −1
Original line number Diff line number Diff line
@@ -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();