Merge "Fix qs rows count on foldables" into tm-qpr-dev

This commit is contained in:
Anton Potapov
2022-11-14 18:07:29 +00:00
committed by Android (Google) Code Review
3 changed files with 40 additions and 10 deletions

View File

@@ -364,13 +364,18 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
private void distributeTiles() { private void distributeTiles() {
emptyAndInflateOrRemovePages(); emptyAndInflateOrRemovePages();
final int tileCount = mPages.get(0).maxTiles(); final int tilesPerPageCount = mPages.get(0).maxTiles();
if (DEBUG) Log.d(TAG, "Distributing tiles");
int index = 0; int index = 0;
final int NT = mTiles.size(); final int totalTilesCount = mTiles.size();
for (int i = 0; i < NT; i++) { if (DEBUG) {
Log.d(TAG, "Distributing tiles: "
+ "[tilesPerPageCount=" + tilesPerPageCount + "]"
+ "[totalTilesCount=" + totalTilesCount + "]"
);
}
for (int i = 0; i < totalTilesCount; i++) {
TileRecord tile = mTiles.get(i); TileRecord tile = mTiles.get(i);
if (mPages.get(index).mRecords.size() == tileCount) index++; if (mPages.get(index).mRecords.size() == tilesPerPageCount) index++;
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Adding " + tile.tile.getClass().getSimpleName() + " to " Log.d(TAG, "Adding " + tile.tile.getClass().getSimpleName() + " to "
+ index); + index);
@@ -577,8 +582,8 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
}); });
setOffscreenPageLimit(lastPageNumber); // Ensure the page to reveal has been inflated. setOffscreenPageLimit(lastPageNumber); // Ensure the page to reveal has been inflated.
int dx = getWidth() * lastPageNumber; int dx = getWidth() * lastPageNumber;
mScroller.startScroll(getScrollX(), getScrollY(), isLayoutRtl() ? -dx : dx, 0, mScroller.startScroll(getScrollX(), getScrollY(), isLayoutRtl() ? -dx : dx, 0,
REVEAL_SCROLL_DURATION_MILLIS); REVEAL_SCROLL_DURATION_MILLIS);
postInvalidateOnAnimation(); postInvalidateOnAnimation();
} }
@@ -738,6 +743,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
public interface PageListener { public interface PageListener {
int INVALID_PAGE = -1; int INVALID_PAGE = -1;
void onPageChanged(boolean isFirst, int pageNumber); void onPageChanged(boolean isFirst, int pageNumber);
} }
} }

View File

@@ -123,7 +123,6 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
public boolean updateResources() { public boolean updateResources() {
final Resources res = mContext.getResources(); final Resources res = mContext.getResources();
mResourceColumns = Math.max(1, res.getInteger(R.integer.quick_settings_num_columns)); mResourceColumns = Math.max(1, res.getInteger(R.integer.quick_settings_num_columns));
updateColumns();
mMaxCellHeight = mContext.getResources().getDimensionPixelSize(mCellHeightResId); mMaxCellHeight = mContext.getResources().getDimensionPixelSize(mCellHeightResId);
mCellMarginHorizontal = res.getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal); mCellMarginHorizontal = res.getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal);
mSidePadding = useSidePadding() ? mCellMarginHorizontal / 2 : 0; mSidePadding = useSidePadding() ? mCellMarginHorizontal / 2 : 0;

View File

@@ -27,6 +27,8 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.res.Resources;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeInfo;
@@ -42,16 +44,22 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@SmallTest @SmallTest
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class TileLayoutTest extends SysuiTestCase { public class TileLayoutTest extends SysuiTestCase {
private TileLayout mTileLayout; private Resources mResources;
private int mLayoutSizeForOneTile; private int mLayoutSizeForOneTile;
private TileLayout mTileLayout; // under test
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mTileLayout = new TileLayout(mContext); Context context = Mockito.spy(mContext);
mResources = Mockito.spy(context.getResources());
Mockito.when(mContext.getResources()).thenReturn(mResources);
mTileLayout = new TileLayout(context);
// Layout needs to leave space for the tile margins. Three times the margin size is // Layout needs to leave space for the tile margins. Three times the margin size is
// sufficient for any number of columns. // sufficient for any number of columns.
mLayoutSizeForOneTile = mLayoutSizeForOneTile =
@@ -203,4 +211,21 @@ public class TileLayoutTest extends SysuiTestCase {
verify(tileRecord1.tileView).setPosition(0); verify(tileRecord1.tileView).setPosition(0);
verify(tileRecord2.tileView).setPosition(1); verify(tileRecord2.tileView).setPosition(1);
} }
@Test
public void resourcesChanged_updateResources_returnsTrue() {
Mockito.when(mResources.getInteger(R.integer.quick_settings_num_columns)).thenReturn(1);
mTileLayout.updateResources(); // setup with 1
Mockito.when(mResources.getInteger(R.integer.quick_settings_num_columns)).thenReturn(2);
assertEquals(true, mTileLayout.updateResources());
}
@Test
public void resourcesSame_updateResources_returnsFalse() {
Mockito.when(mResources.getInteger(R.integer.quick_settings_num_columns)).thenReturn(1);
mTileLayout.updateResources(); // setup with 1
assertEquals(false, mTileLayout.updateResources());
}
} }