Fix qs rows count on foldables
Fixes: 255102159 Test: Manual on foldable device + autotest Change-Id: I54243e2373fa6fac26886618173ef4c4b5a71a3a
This commit is contained in:
@@ -364,13 +364,18 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
private void distributeTiles() {
|
||||
emptyAndInflateOrRemovePages();
|
||||
|
||||
final int tileCount = mPages.get(0).maxTiles();
|
||||
if (DEBUG) Log.d(TAG, "Distributing tiles");
|
||||
final int tilesPerPageCount = mPages.get(0).maxTiles();
|
||||
int index = 0;
|
||||
final int NT = mTiles.size();
|
||||
for (int i = 0; i < NT; i++) {
|
||||
final int totalTilesCount = mTiles.size();
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Distributing tiles: "
|
||||
+ "[tilesPerPageCount=" + tilesPerPageCount + "]"
|
||||
+ "[totalTilesCount=" + totalTilesCount + "]"
|
||||
);
|
||||
}
|
||||
for (int i = 0; i < totalTilesCount; i++) {
|
||||
TileRecord tile = mTiles.get(i);
|
||||
if (mPages.get(index).mRecords.size() == tileCount) index++;
|
||||
if (mPages.get(index).mRecords.size() == tilesPerPageCount) index++;
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Adding " + tile.tile.getClass().getSimpleName() + " to "
|
||||
+ index);
|
||||
@@ -577,8 +582,8 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
});
|
||||
setOffscreenPageLimit(lastPageNumber); // Ensure the page to reveal has been inflated.
|
||||
int dx = getWidth() * lastPageNumber;
|
||||
mScroller.startScroll(getScrollX(), getScrollY(), isLayoutRtl() ? -dx : dx, 0,
|
||||
REVEAL_SCROLL_DURATION_MILLIS);
|
||||
mScroller.startScroll(getScrollX(), getScrollY(), isLayoutRtl() ? -dx : dx, 0,
|
||||
REVEAL_SCROLL_DURATION_MILLIS);
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
|
||||
@@ -738,6 +743,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
|
||||
public interface PageListener {
|
||||
int INVALID_PAGE = -1;
|
||||
|
||||
void onPageChanged(boolean isFirst, int pageNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,6 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
public boolean updateResources() {
|
||||
final Resources res = mContext.getResources();
|
||||
mResourceColumns = Math.max(1, res.getInteger(R.integer.quick_settings_num_columns));
|
||||
updateColumns();
|
||||
mMaxCellHeight = mContext.getResources().getDimensionPixelSize(mCellHeightResId);
|
||||
mCellMarginHorizontal = res.getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal);
|
||||
mSidePadding = useSidePadding() ? mCellMarginHorizontal / 2 : 0;
|
||||
|
||||
@@ -27,6 +27,8 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
@@ -42,16 +44,22 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TileLayoutTest extends SysuiTestCase {
|
||||
private TileLayout mTileLayout;
|
||||
private Resources mResources;
|
||||
private int mLayoutSizeForOneTile;
|
||||
private TileLayout mTileLayout; // under test
|
||||
|
||||
@Before
|
||||
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
|
||||
// sufficient for any number of columns.
|
||||
mLayoutSizeForOneTile =
|
||||
@@ -203,4 +211,21 @@ public class TileLayoutTest extends SysuiTestCase {
|
||||
verify(tileRecord1.tileView).setPosition(0);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user