diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 28c7a37bde..3b077912a6 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -176,6 +176,8 @@ public class DeviceProfile { public int cellYPaddingPx = -1; // Folder + public final int numFolderRows; + public final int numFolderColumns; public float folderLabelTextScale; public int folderLabelTextSizePx; public int folderFooterHeightPx; @@ -431,6 +433,8 @@ public class DeviceProfile { } folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale); + numFolderRows = inv.numFolderRows; + numFolderColumns = inv.numFolderColumns; if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) { TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle, @@ -622,11 +626,11 @@ public class DeviceProfile { isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId), ResponsiveSpecType.Folder); mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio, - DimensionType.WIDTH, inv.numFolderColumns, + DimensionType.WIDTH, numFolderColumns, mResponsiveWorkspaceWidthSpec.getAvailableSpace(), mResponsiveWorkspaceWidthSpec); mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio, - DimensionType.HEIGHT, inv.numFolderRows, + DimensionType.HEIGHT, numFolderRows, mResponsiveWorkspaceHeightSpec.getAvailableSpace(), mResponsiveWorkspaceHeightSpec); } @@ -1365,16 +1369,16 @@ public class DeviceProfile { Point totalWorkspacePadding = getTotalWorkspacePadding(); // Check if the folder fit within the available height. - float contentUsedHeight = folderCellHeightPx * inv.numFolderRows - + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y) + float contentUsedHeight = folderCellHeightPx * numFolderRows + + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y) + folderFooterHeightPx + folderContentPaddingTop; int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y; float scaleY = contentMaxHeight / contentUsedHeight; // Check if the folder fit within the available width. - float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns - + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x) + float contentUsedWidth = folderCellWidthPx * numFolderColumns + + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x) + folderContentPaddingLeftRight * 2; int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x; float scaleX = contentMaxWidth / contentUsedWidth; @@ -1991,8 +1995,8 @@ public class DeviceProfile { writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx)); writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx)); - writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows); - writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns); + writer.println(prefix + "\tnumFolderRows: " + numFolderRows); + writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns); writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx)); writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx)); writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx)); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index a351947230..0eebdc6dea 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -792,7 +792,7 @@ public class Launcher extends StatefulActivity if (info.container >= 0) { View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container); if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) { - if (new FolderGridOrganizer(getDeviceProfile().inv) + if (new FolderGridOrganizer(getDeviceProfile()) .setFolderInfo((FolderInfo) folderIcon.getTag()) .isItemInPreview(info.rank)) { folderIcon.invalidate(); @@ -2646,7 +2646,7 @@ public class Launcher extends StatefulActivity // Cache one page worth of icons getViewCache().setCacheSize(R.layout.folder_application, - mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows); + mDeviceProfile.numFolderColumns * mDeviceProfile.numFolderRows); getViewCache().setCacheSize(R.layout.folder_page, 2); TraceHelper.INSTANCE.endSection(); diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index 8bf7ec234e..e7a559ea09 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -1082,7 +1082,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo private void updateItemLocationsInDatabaseBatch(boolean isBind) { FolderGridOrganizer verifier = new FolderGridOrganizer( - mActivityContext.getDeviceProfile().inv).setFolderInfo(mInfo); + mActivityContext.getDeviceProfile()).setFolderInfo(mInfo); ArrayList items = new ArrayList<>(); int total = mInfo.contents.size(); @@ -1381,7 +1381,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo @Override public void onAdd(WorkspaceItemInfo item, int rank) { FolderGridOrganizer verifier = new FolderGridOrganizer( - mActivityContext.getDeviceProfile().inv).setFolderInfo(mInfo); + mActivityContext.getDeviceProfile()).setFolderInfo(mInfo); verifier.updateRankAndPos(item, rank); mLauncherDelegate.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0, item.cellX, item.cellY); diff --git a/src/com/android/launcher3/folder/FolderAnimationManager.java b/src/com/android/launcher3/folder/FolderAnimationManager.java index 9e2e2bf5fc..a91373ba49 100644 --- a/src/com/android/launcher3/folder/FolderAnimationManager.java +++ b/src/com/android/launcher3/folder/FolderAnimationManager.java @@ -96,7 +96,7 @@ public class FolderAnimationManager { mContext = folder.getContext(); mDeviceProfile = folder.mActivityContext.getDeviceProfile(); - mPreviewVerifier = new FolderGridOrganizer(mDeviceProfile.inv); + mPreviewVerifier = new FolderGridOrganizer(mDeviceProfile); mIsOpening = isOpening; diff --git a/src/com/android/launcher3/folder/FolderGridOrganizer.java b/src/com/android/launcher3/folder/FolderGridOrganizer.java index 4be82ed8d3..04360115b6 100644 --- a/src/com/android/launcher3/folder/FolderGridOrganizer.java +++ b/src/com/android/launcher3/folder/FolderGridOrganizer.java @@ -20,7 +20,7 @@ import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_I import android.graphics.Point; -import com.android.launcher3.InvariantDeviceProfile; +import com.android.launcher3.DeviceProfile; import com.android.launcher3.model.data.FolderInfo; import com.android.launcher3.model.data.ItemInfo; @@ -41,16 +41,33 @@ public class FolderGridOrganizer { private int mCountX; private int mCountY; private boolean mDisplayingUpperLeftQuadrant = false; + private static final int PREVIEW_MAX_ROWS = 2; + private static final int PREVIEW_MAX_COLUMNS = 2; /** * Note: must call {@link #setFolderInfo(FolderInfo)} manually for verifier to work. */ - public FolderGridOrganizer(InvariantDeviceProfile profile) { + public FolderGridOrganizer(DeviceProfile profile) { mMaxCountX = profile.numFolderColumns; mMaxCountY = profile.numFolderRows; mMaxItemsPerPage = mMaxCountX * mMaxCountY; } + private FolderGridOrganizer(int maxCountX, int maxCountY) { + mMaxCountX = maxCountX; + mMaxCountY = maxCountY; + mMaxItemsPerPage = mMaxCountX * mMaxCountY; + } + + /** + * Returns a FolderGridOrganizer that should only be used to verify if the folder icon is + * showing in the preview. Max number of rows is {@link #PREVIEW_MAX_ROWS} and columns is + * {@link #PREVIEW_MAX_COLUMNS}. + */ + public static FolderGridOrganizer getPreviewIconVerifier() { + return new FolderGridOrganizer(PREVIEW_MAX_ROWS, PREVIEW_MAX_COLUMNS); + } + /** * Updates the organizer with the provided folder info */ @@ -127,6 +144,7 @@ public class FolderGridOrganizer { /** * Updates the item's cellX, cellY and rank corresponding to the provided rank. + * * @return true if there was any change */ public boolean updateRankAndPos(ItemInfo item, int rank) { @@ -189,7 +207,7 @@ public class FolderGridOrganizer { if (page > 0 || mDisplayingUpperLeftQuadrant) { int col = rank % mCountX; int row = rank / mCountX; - return col < 2 && row < 2; + return col < PREVIEW_MAX_COLUMNS && row < PREVIEW_MAX_ROWS; } return rank < MAX_NUM_ITEMS_IN_PREVIEW; } diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index cb1dc4fb2a..c80fb8cb98 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -221,7 +221,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel icon.setAccessibilityDelegate(activity.getAccessibilityDelegate()); - icon.mPreviewVerifier = new FolderGridOrganizer(activity.getDeviceProfile().inv); + icon.mPreviewVerifier = new FolderGridOrganizer(activity.getDeviceProfile()); icon.mPreviewVerifier.setFolderInfo(folderInfo); icon.updatePreviewItems(false); diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java index 36e5e1b106..f2bed925c1 100644 --- a/src/com/android/launcher3/folder/FolderPagedView.java +++ b/src/com/android/launcher3/folder/FolderPagedView.java @@ -37,8 +37,6 @@ import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.BubbleTextView; import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; -import com.android.launcher3.InvariantDeviceProfile; -import com.android.launcher3.LauncherAppState; import com.android.launcher3.PagedView; import com.android.launcher3.R; import com.android.launcher3.ShortcutAndWidgetContainer; @@ -101,14 +99,15 @@ public class FolderPagedView extends PagedView implements Cli public FolderPagedView(Context context, AttributeSet attrs) { super(context, attrs); - InvariantDeviceProfile profile = LauncherAppState.getIDP(context); + ActivityContext activityContext = ActivityContext.lookupContext(context); + DeviceProfile profile = activityContext.getDeviceProfile(); mOrganizer = new FolderGridOrganizer(profile); mIsRtl = Utilities.isRtl(getResources()); setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); mFocusIndicatorHelper = new ViewGroupFocusHelper(this); - mViewCache = ActivityContext.lookupContext(context).getViewCache(); + mViewCache = activityContext.getViewCache(); } public void setFolder(Folder folder) { diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index f4ce3607f7..d9f43ef6a3 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -481,8 +481,7 @@ public class LoaderTask implements Runnable { mItemsDeleted = c.commitDeleted(); // Sort the folder items, update ranks, and make sure all preview items are high res. - FolderGridOrganizer verifier = - new FolderGridOrganizer(mApp.getInvariantDeviceProfile()); + FolderGridOrganizer verifier = FolderGridOrganizer.getPreviewIconVerifier(); for (FolderInfo folder : mBgDataModel.folders) { Collections.sort(folder.contents, Folder.ITEM_POS_COMPARATOR); verifier.setFolderInfo(folder); diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait.txt index 6c3fa5e69c..8473b68d81 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 147.0px (56.0dp) iconTextSizePx: 38.0px (14.476191dp) iconDrawablePaddingPx: 12.0px (4.571429dp) - inv.numFolderRows: 4 - inv.numFolderColumns: 4 + numFolderRows: 4 + numFolderColumns: 4 folderCellWidthPx: 195.0px (74.28571dp) folderCellHeightPx: 230.0px (87.61905dp) folderChildIconSizePx: 147.0px (56.0dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait3Button.txt index cd06ed93d9..c23fcc0d2a 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait3Button.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait3Button.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 147.0px (56.0dp) iconTextSizePx: 38.0px (14.476191dp) iconDrawablePaddingPx: 12.0px (4.571429dp) - inv.numFolderRows: 4 - inv.numFolderColumns: 4 + numFolderRows: 4 + numFolderColumns: 4 folderCellWidthPx: 195.0px (74.28571dp) folderCellHeightPx: 230.0px (87.61905dp) folderChildIconSizePx: 147.0px (56.0dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt index cd199079fd..5cd7dc83c6 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 147.0px (56.0dp) iconTextSizePx: 0.0px (0.0dp) iconDrawablePaddingPx: 0.0px (0.0dp) - inv.numFolderRows: 4 - inv.numFolderColumns: 4 + numFolderRows: 4 + numFolderColumns: 4 folderCellWidthPx: 163.0px (62.095238dp) folderCellHeightPx: 192.0px (73.14286dp) folderChildIconSizePx: 123.0px (46.857143dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt index 8850583dae..f8afa37f42 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 147.0px (56.0dp) iconTextSizePx: 0.0px (0.0dp) iconDrawablePaddingPx: 0.0px (0.0dp) - inv.numFolderRows: 4 - inv.numFolderColumns: 4 + numFolderRows: 4 + numFolderColumns: 4 folderCellWidthPx: 173.0px (65.90476dp) folderCellHeightPx: 205.0px (78.09524dp) folderChildIconSizePx: 131.0px (49.904762dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt index 26b86dcf04..32e1f1b427 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 120.0px (60.0dp) iconTextSizePx: 28.0px (14.0dp) iconDrawablePaddingPx: 9.0px (4.5dp) - inv.numFolderRows: 3 - inv.numFolderColumns: 3 + numFolderRows: 3 + numFolderColumns: 3 folderCellWidthPx: 240.0px (120.0dp) folderCellHeightPx: 208.0px (104.0dp) folderChildIconSizePx: 120.0px (60.0dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt index 577830623c..7c52c904de 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 120.0px (60.0dp) iconTextSizePx: 28.0px (14.0dp) iconDrawablePaddingPx: 9.0px (4.5dp) - inv.numFolderRows: 3 - inv.numFolderColumns: 3 + numFolderRows: 3 + numFolderColumns: 3 folderCellWidthPx: 240.0px (120.0dp) folderCellHeightPx: 208.0px (104.0dp) folderChildIconSizePx: 120.0px (60.0dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt index 9e943ae2d2..b284ce08bc 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 120.0px (60.0dp) iconTextSizePx: 28.0px (14.0dp) iconDrawablePaddingPx: 9.0px (4.5dp) - inv.numFolderRows: 3 - inv.numFolderColumns: 3 + numFolderRows: 3 + numFolderColumns: 3 folderCellWidthPx: 204.0px (102.0dp) folderCellHeightPx: 240.0px (120.0dp) folderChildIconSizePx: 120.0px (60.0dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt index f159b85350..7001967624 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 120.0px (60.0dp) iconTextSizePx: 28.0px (14.0dp) iconDrawablePaddingPx: 9.0px (4.5dp) - inv.numFolderRows: 3 - inv.numFolderColumns: 3 + numFolderRows: 3 + numFolderColumns: 3 folderCellWidthPx: 204.0px (102.0dp) folderCellHeightPx: 240.0px (120.0dp) folderChildIconSizePx: 120.0px (60.0dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape.txt index 55e98808d1..ba83533a8d 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 141.0px (53.714287dp) iconTextSizePx: 34.0px (12.952381dp) iconDrawablePaddingPx: 13.0px (4.952381dp) - inv.numFolderRows: 3 - inv.numFolderColumns: 4 + numFolderRows: 3 + numFolderColumns: 4 folderCellWidthPx: 189.0px (72.0dp) folderCellHeightPx: 219.0px (83.42857dp) folderChildIconSizePx: 141.0px (53.714287dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape3Button.txt index a2f0aa2383..1b1240b60e 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape3Button.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape3Button.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 141.0px (53.714287dp) iconTextSizePx: 34.0px (12.952381dp) iconDrawablePaddingPx: 13.0px (4.952381dp) - inv.numFolderRows: 3 - inv.numFolderColumns: 4 + numFolderRows: 3 + numFolderColumns: 4 folderCellWidthPx: 189.0px (72.0dp) folderCellHeightPx: 219.0px (83.42857dp) folderChildIconSizePx: 141.0px (53.714287dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait.txt index ca42cdab40..11e70776c5 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 141.0px (53.714287dp) iconTextSizePx: 34.0px (12.952381dp) iconDrawablePaddingPx: 13.0px (4.952381dp) - inv.numFolderRows: 3 - inv.numFolderColumns: 4 + numFolderRows: 3 + numFolderColumns: 4 folderCellWidthPx: 189.0px (72.0dp) folderCellHeightPx: 219.0px (83.42857dp) folderChildIconSizePx: 141.0px (53.714287dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait3Button.txt index d53badca19..1a8b3ac217 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait3Button.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait3Button.txt @@ -37,8 +37,8 @@ DeviceProfile: iconSizePx: 141.0px (53.714287dp) iconTextSizePx: 34.0px (12.952381dp) iconDrawablePaddingPx: 13.0px (4.952381dp) - inv.numFolderRows: 3 - inv.numFolderColumns: 4 + numFolderRows: 3 + numFolderColumns: 4 folderCellWidthPx: 189.0px (72.0dp) folderCellHeightPx: 219.0px (83.42857dp) folderChildIconSizePx: 141.0px (53.714287dp)