Merge "Refactoring FolderPagedView to make it more testable" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
45bad7252e
@@ -70,6 +70,7 @@ import static com.android.launcher3.LauncherState.SPRING_LOADED;
|
||||
import static com.android.launcher3.Utilities.postAsyncCallback;
|
||||
import static com.android.launcher3.config.FeatureFlags.FOLDABLE_SINGLE_PAGE;
|
||||
import static com.android.launcher3.config.FeatureFlags.MULTI_SELECT_EDIT_MODE;
|
||||
import static com.android.launcher3.folder.FolderGridOrganizer.createFolderGridOrganizer;
|
||||
import static com.android.launcher3.logging.KeyboardStateManager.KeyboardState.HIDE;
|
||||
import static com.android.launcher3.logging.KeyboardStateManager.KeyboardState.SHOW;
|
||||
import static com.android.launcher3.logging.StatsLogManager.EventEnum;
|
||||
@@ -188,7 +189,6 @@ import com.android.launcher3.dragndrop.DragLayer;
|
||||
import com.android.launcher3.dragndrop.DragView;
|
||||
import com.android.launcher3.dragndrop.LauncherDragController;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.folder.FolderGridOrganizer;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
|
||||
@@ -816,7 +816,7 @@ public class Launcher extends StatefulActivity<LauncherState>
|
||||
View collectionIcon = getWorkspace().getHomescreenIconByItemId(info.container);
|
||||
if (collectionIcon instanceof FolderIcon folderIcon
|
||||
&& collectionIcon.getTag() instanceof FolderInfo) {
|
||||
if (new FolderGridOrganizer(getDeviceProfile())
|
||||
if (createFolderGridOrganizer(getDeviceProfile())
|
||||
.setFolderInfo((FolderInfo) folderIcon.getTag())
|
||||
.isItemInPreview(info.rank)) {
|
||||
folderIcon.invalidate();
|
||||
|
||||
@@ -26,6 +26,7 @@ import static com.android.launcher3.LauncherState.EDIT_MODE;
|
||||
import static com.android.launcher3.LauncherState.NORMAL;
|
||||
import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent;
|
||||
import static com.android.launcher3.config.FeatureFlags.ALWAYS_USE_HARDWARE_OPTIMIZATION_FOR_FOLDER_ANIMATIONS;
|
||||
import static com.android.launcher3.folder.FolderGridOrganizer.createFolderGridOrganizer;
|
||||
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_LABEL_UPDATED;
|
||||
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED;
|
||||
import static com.android.launcher3.testing.shared.TestProtocol.FOLDER_OPENED_MESSAGE;
|
||||
@@ -1106,7 +1107,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
}
|
||||
|
||||
private void updateItemLocationsInDatabaseBatch(boolean isBind) {
|
||||
FolderGridOrganizer verifier = new FolderGridOrganizer(
|
||||
FolderGridOrganizer verifier = createFolderGridOrganizer(
|
||||
mActivityContext.getDeviceProfile()).setFolderInfo(mInfo);
|
||||
|
||||
ArrayList<ItemInfo> items = new ArrayList<>();
|
||||
@@ -1404,7 +1405,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
|
||||
@Override
|
||||
public void onAdd(ItemInfo item, int rank) {
|
||||
FolderGridOrganizer verifier = new FolderGridOrganizer(
|
||||
FolderGridOrganizer verifier = createFolderGridOrganizer(
|
||||
mActivityContext.getDeviceProfile()).setFolderInfo(mInfo);
|
||||
verifier.updateRankAndPos(item, rank);
|
||||
mLauncherDelegate.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0, item.cellX,
|
||||
|
||||
@@ -21,6 +21,7 @@ import static android.view.View.ALPHA;
|
||||
import static com.android.launcher3.BubbleTextView.TEXT_ALPHA_PROPERTY;
|
||||
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
|
||||
import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW;
|
||||
import static com.android.launcher3.folder.FolderGridOrganizer.createFolderGridOrganizer;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
@@ -99,7 +100,7 @@ public class FolderAnimationManager {
|
||||
|
||||
mContext = folder.getContext();
|
||||
mDeviceProfile = folder.mActivityContext.getDeviceProfile();
|
||||
mPreviewVerifier = new FolderGridOrganizer(mDeviceProfile);
|
||||
mPreviewVerifier = createFolderGridOrganizer(mDeviceProfile);
|
||||
|
||||
mIsOpening = isOpening;
|
||||
|
||||
|
||||
@@ -47,12 +47,19 @@ public class FolderGridOrganizer {
|
||||
/**
|
||||
* Note: must call {@link #setFolderInfo(FolderInfo)} manually for verifier to work.
|
||||
*/
|
||||
public FolderGridOrganizer(DeviceProfile profile) {
|
||||
mMaxCountX = profile.numFolderColumns;
|
||||
mMaxCountY = profile.numFolderRows;
|
||||
public FolderGridOrganizer(int maxCountX, int maxCountY) {
|
||||
mMaxCountX = maxCountX;
|
||||
mMaxCountY = maxCountY;
|
||||
mMaxItemsPerPage = mMaxCountX * mMaxCountY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a FolderGridOrganizer for the given DeviceProfile
|
||||
*/
|
||||
public static FolderGridOrganizer createFolderGridOrganizer(DeviceProfile profile) {
|
||||
return new FolderGridOrganizer(profile.numFolderColumns, profile.numFolderRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the organizer with the provided folder info
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.launcher3.folder;
|
||||
import static com.android.launcher3.Flags.enableCursorHoverStates;
|
||||
import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
|
||||
import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW;
|
||||
import static com.android.launcher3.folder.FolderGridOrganizer.createFolderGridOrganizer;
|
||||
import static com.android.launcher3.folder.PreviewItemManager.INITIAL_ITEM_ANIMATION_DURATION;
|
||||
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_AUTO_LABELED;
|
||||
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_PRIMARY;
|
||||
@@ -223,7 +224,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
|
||||
icon.setAccessibilityDelegate(activity.getAccessibilityDelegate());
|
||||
|
||||
icon.mPreviewVerifier = new FolderGridOrganizer(activity.getDeviceProfile());
|
||||
icon.mPreviewVerifier = createFolderGridOrganizer(activity.getDeviceProfile());
|
||||
icon.mPreviewVerifier.setFolderInfo(folderInfo);
|
||||
icon.updatePreviewItems(false);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.launcher3.folder;
|
||||
|
||||
import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
|
||||
import static com.android.launcher3.AbstractFloatingView.TYPE_FOLDER;
|
||||
import static com.android.launcher3.folder.FolderGridOrganizer.createFolderGridOrganizer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
@@ -100,10 +101,21 @@ public class FolderPagedView extends PagedView<PageIndicatorDots> implements Cli
|
||||
private boolean mViewsBound = false;
|
||||
|
||||
public FolderPagedView(Context context, AttributeSet attrs) {
|
||||
this(
|
||||
context,
|
||||
attrs,
|
||||
createFolderGridOrganizer(ActivityContext.lookupContext(context).getDeviceProfile())
|
||||
);
|
||||
}
|
||||
|
||||
public FolderPagedView(
|
||||
Context context,
|
||||
AttributeSet attrs,
|
||||
FolderGridOrganizer folderGridOrganizer
|
||||
) {
|
||||
super(context, attrs);
|
||||
ActivityContext activityContext = ActivityContext.lookupContext(context);
|
||||
DeviceProfile profile = activityContext.getDeviceProfile();
|
||||
mOrganizer = new FolderGridOrganizer(profile);
|
||||
mOrganizer = folderGridOrganizer;
|
||||
|
||||
mIsRtl = Utilities.isRtl(getResources());
|
||||
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
|
||||
|
||||
@@ -568,7 +568,7 @@ public class LoaderTask implements Runnable {
|
||||
private void processFolderItems() {
|
||||
// Sort the folder items, update ranks, and make sure all preview items are high res.
|
||||
List<FolderGridOrganizer> verifiers = mApp.getInvariantDeviceProfile().supportedProfiles
|
||||
.stream().map(FolderGridOrganizer::new).toList();
|
||||
.stream().map(FolderGridOrganizer::createFolderGridOrganizer).toList();
|
||||
for (CollectionInfo collection : mBgDataModel.collections) {
|
||||
if (!(collection instanceof FolderInfo folder)) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user