diff options
Diffstat (limited to 'src/com/android/launcher3/folder')
8 files changed, 65 insertions, 27 deletions
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index 55a539a7b6..084f829884 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -25,6 +25,7 @@ import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustom import static com.android.launcher3.config.FeatureFlags.ALWAYS_USE_HARDWARE_OPTIMIZATION_FOR_FOLDER_ANIMATIONS; 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; import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs; import android.animation.Animator; @@ -209,7 +210,9 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo @ViewDebug.IntToString(from = STATE_OPEN, to = "STATE_OPEN"), }) private int mState = STATE_CLOSED; - private OnFolderStateChangedListener mOnFolderStateChangedListener; + private final List<OnFolderStateChangedListener> mOnFolderStateChangedListeners = + new ArrayList<>(); + private OnFolderStateChangedListener mPriorityOnFolderStateChangedListener; @ViewDebug.ExportedProperty(category = "launcher") private boolean mRearrangeOnClose = false; boolean mItemsInvalidated = false; @@ -535,7 +538,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo mFolderName.selectAll(); } } - mFolderName.showKeyboard(true /* shouldFocus */); + mFolderName.showKeyboard(); mFolderName.displayCompletions( Stream.of(mInfo.suggestedFolderNames.getLabels()) .filter(Objects::nonNull) @@ -644,6 +647,11 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo * is played. */ private void animateOpen(List<WorkspaceItemInfo> items, int pageNo) { + if (items == null || items.size() <= 1) { + Log.d(TAG, "Couldn't animate folder open because items is: " + items); + return; + } + Folder openFolder = getOpen(mActivityContext); if (openFolder != null && openFolder != this) { // Close any open folder before opening a folder. @@ -692,7 +700,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo public void onAnimationEnd(Animator animation) { setState(STATE_OPEN); announceAccessibilityChanges(); - AccessibilityManagerCompat.sendFolderOpenedEventToTest(getContext()); + AccessibilityManagerCompat.sendTestProtocolEventToTest(getContext(), + FOLDER_OPENED_MESSAGE); mContent.setFocusOnFirstChild(); } @@ -1075,7 +1084,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<ItemInfo> items = new ArrayList<>(); int total = mInfo.contents.size(); @@ -1374,7 +1383,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); @@ -1658,18 +1667,43 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo return windowBottomPx - folderBottomPx; } + /** + * Save this listener for the special case of when we update the state and concurrently + * add another listener to {@link #mOnFolderStateChangedListeners} to avoid a + * ConcurrentModificationException + */ + public void setPriorityOnFolderStateChangedListener(OnFolderStateChangedListener listener) { + mPriorityOnFolderStateChangedListener = listener; + } + private void setState(@FolderState int newState) { mState = newState; - if (mOnFolderStateChangedListener != null) { - mOnFolderStateChangedListener.onFolderStateChanged(mState); + if (mPriorityOnFolderStateChangedListener != null) { + mPriorityOnFolderStateChangedListener.onFolderStateChanged(mState); + } + for (OnFolderStateChangedListener listener : mOnFolderStateChangedListeners) { + if (listener != null) { + listener.onFolderStateChanged(mState); + } + } + } + + /** + * Adds the provided listener to the running list of Folder listeners + * {@link #mOnFolderStateChangedListeners} + */ + public void addOnFolderStateChangedListener(@Nullable OnFolderStateChangedListener listener) { + if (listener != null) { + mOnFolderStateChangedListeners.add(listener); } } - public void setOnFolderStateChangedListener(@Nullable OnFolderStateChangedListener listener) { - mOnFolderStateChangedListener = listener; + /** Removes the provided listener from the running list of Folder listeners */ + public void removeOnFolderStateChangedListener(OnFolderStateChangedListener listener) { + mOnFolderStateChangedListeners.remove(listener); } - /** Listener that can be registered via {@link Folder#setOnFolderStateChangedListener} */ + /** Listener that can be registered via {@link #addOnFolderStateChangedListener} */ public interface OnFolderStateChangedListener { /** See {@link Folder.FolderState} */ void onFolderStateChanged(@FolderState int newState); 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..cc247619e4 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,11 +41,13 @@ 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; @@ -127,6 +129,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 +192,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 53d0efbe85..f058ae4d02 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -16,7 +16,7 @@ package com.android.launcher3.folder; -import static com.android.launcher3.config.FeatureFlags.ENABLE_CURSOR_HOVER_STATES; +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.PreviewItemManager.INITIAL_ITEM_ANIMATION_DURATION; @@ -86,7 +86,6 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; - /** * An icon that can appear on in the workspace representing an {@link Folder}. */ @@ -221,7 +220,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); @@ -634,6 +633,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel } } + /** Sets the visibility of the icon's title text */ public void setTextVisible(boolean visible) { if (visible) { mFolderName.setVisibility(VISIBLE); @@ -805,7 +805,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel @Override public void onHoverChanged(boolean hovered) { super.onHoverChanged(hovered); - if (ENABLE_CURSOR_HOVER_STATES.get()) { + if (enableCursorHoverStates()) { mBackground.setHovered(hovered); } } 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<PageIndicatorDots> 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/folder/LauncherDelegate.java b/src/com/android/launcher3/folder/LauncherDelegate.java index c06a0f3c53..66c9109b82 100644 --- a/src/com/android/launcher3/folder/LauncherDelegate.java +++ b/src/com/android/launcher3/folder/LauncherDelegate.java @@ -28,7 +28,6 @@ import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; -import com.android.launcher3.celllayout.CellPosMapper; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.logging.InstanceId; import com.android.launcher3.logging.StatsLogManager.StatsLogger; @@ -177,8 +176,8 @@ public class LauncherDelegate { @Override ModelWriter getModelWriter() { if (mWriter == null) { - mWriter = LauncherAppState.getInstance((Context) mContext).getModel() - .getWriter(false, false, CellPosMapper.DEFAULT, null); + mWriter = LauncherAppState.getInstance((Context) mContext).getModel().getWriter( + false, mContext.getCellPosMapper(), null); } return mWriter; } diff --git a/src/com/android/launcher3/folder/PreviewBackground.java b/src/com/android/launcher3/folder/PreviewBackground.java index b320cebcfc..ec038038ad 100644 --- a/src/com/android/launcher3/folder/PreviewBackground.java +++ b/src/com/android/launcher3/folder/PreviewBackground.java @@ -48,6 +48,7 @@ import androidx.annotation.VisibleForTesting; import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; import com.android.launcher3.R; +import com.android.launcher3.celllayout.DelegatedCellDrawing; import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; @@ -55,7 +56,7 @@ import com.android.launcher3.views.ActivityContext; * This object represents a FolderIcon preview background. It stores drawing / measurement * information, handles drawing, and animation (accept state <--> rest state). */ -public class PreviewBackground extends CellLayout.DelegatedCellDrawing { +public class PreviewBackground extends DelegatedCellDrawing { private static final boolean DRAW_SHADOW = false; private static final boolean DRAW_STROKE = false; diff --git a/src/com/android/launcher3/folder/PreviewItemManager.java b/src/com/android/launcher3/folder/PreviewItemManager.java index 2e5f2e5d60..b39e968e63 100644 --- a/src/com/android/launcher3/folder/PreviewItemManager.java +++ b/src/com/android/launcher3/folder/PreviewItemManager.java @@ -43,6 +43,7 @@ import com.android.launcher3.Utilities; import com.android.launcher3.graphics.PreloadIconDrawable; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.WorkspaceItemInfo; +import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; import java.util.ArrayList; @@ -434,7 +435,8 @@ public class PreviewItemManager { drawable.setLevel(item.getProgressLevel()); p.drawable = drawable; } else { - p.drawable = item.newIcon(mContext, FLAG_THEMED); + p.drawable = item.newIcon(mContext, + Themes.isThemedIconEnabled(mContext) ? FLAG_THEMED : 0); } p.drawable.setBounds(0, 0, mIconSize, mIconSize); p.item = item; |