Review comments followup
These are review comments followup from ag/17399997
Bug: b/218187058
Test: manually test thet Launcher3 features work correctly
Change-Id: I9865a37c1ed663370dc28e7678994f3d961e3cd1
diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java
index 300f22b..4b4a017 100644
--- a/src/com/android/launcher3/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher3/AppWidgetResizeFrame.java
@@ -383,7 +383,7 @@
// Handle invalid resize across CellLayouts in the two panel UI.
if (mCellLayout.getParent() instanceof Workspace) {
- Workspace workspace = (Workspace) mCellLayout.getParent();
+ Workspace<?> workspace = (Workspace<?>) mCellLayout.getParent();
CellLayout pairedCellLayout = workspace.getScreenPair(mCellLayout);
if (pairedCellLayout != null) {
Rect focusedCellLayoutBound = sTmpRect;
@@ -570,7 +570,7 @@
final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
final CellLayout pairedCellLayout;
if (mCellLayout.getParent() instanceof Workspace) {
- Workspace workspace = (Workspace) mCellLayout.getParent();
+ Workspace<?> workspace = (Workspace<?>) mCellLayout.getParent();
pairedCellLayout = workspace.getScreenPair(mCellLayout);
} else {
pairedCellLayout = null;
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index f7133c4..87bbac6 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -1203,7 +1203,7 @@
return getContext().getString(R.string.move_to_hotseat_position,
Math.max(cellX, cellY) + 1);
} else {
- Workspace workspace = getWorkspace();
+ Workspace<?> workspace = getWorkspace();
int row = cellY + 1;
int col = workspace.mIsRtl ? mCountX - cellX : cellX + 1;
int panelCount = workspace.getPanelCount();
@@ -1217,7 +1217,7 @@
}
}
- private Workspace getWorkspace() {
+ private Workspace<?> getWorkspace() {
return Launcher.cast(mActivity).getWorkspace();
}
diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java
index b94cdbf..9ae695d 100644
--- a/src/com/android/launcher3/DropTargetBar.java
+++ b/src/com/android/launcher3/DropTargetBar.java
@@ -179,7 +179,7 @@
}
Launcher launcher = Launcher.getLauncher(getContext());
- Workspace workspace = launcher.getWorkspace();
+ Workspace<?> workspace = launcher.getWorkspace();
DeviceProfile dp = launcher.getDeviceProfile();
int buttonHorizontalPadding = dp.dropTargetHorizontalPaddingPx;
int buttonVerticalPadding = dp.dropTargetVerticalPaddingPx;
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index 9c749aa7..d1d6c18 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -41,7 +41,7 @@
@ViewDebug.ExportedProperty(category = "launcher")
private boolean mHasVerticalHotseat;
- private Workspace mWorkspace;
+ private Workspace<?> mWorkspace;
private boolean mSendTouchToWorkspace;
@Nullable
private Consumer<Boolean> mOnVisibilityAggregatedCallback;
@@ -122,7 +122,7 @@
InsettableFrameLayout.dispatchInsets(this, insets);
}
- public void setWorkspace(Workspace w) {
+ public void setWorkspace(Workspace<?> w) {
mWorkspace = w;
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 3cc8a81..923e614 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2360,7 +2360,7 @@
// Get the list of added items and intersect them with the set of items here
final Collection<Animator> bounceAnims = new ArrayList<>();
boolean canAnimatePageChange = canAnimatePageChange();
- Workspace workspace = mWorkspace;
+ Workspace<?> workspace = mWorkspace;
int newItemsScreenId = -1;
int end = items.size();
View newView = null;
diff --git a/src/com/android/launcher3/LauncherAnimUtils.java b/src/com/android/launcher3/LauncherAnimUtils.java
index 4f3ae59..808bf96 100644
--- a/src/com/android/launcher3/LauncherAnimUtils.java
+++ b/src/com/android/launcher3/LauncherAnimUtils.java
@@ -72,8 +72,8 @@
* of all the ones set, to have a smooth experience even in the case of overlapping scaling
* animation.
*/
- public static final MultiScalePropertyFactory<Workspace> WORKSPACE_SCALE_PROPERTY_FACTORY =
- new MultiScalePropertyFactory<Workspace>("workspace_scale_property");
+ public static final MultiScalePropertyFactory<Workspace<?>> WORKSPACE_SCALE_PROPERTY_FACTORY =
+ new MultiScalePropertyFactory<Workspace<?>>("workspace_scale_property");
/** Property to set the scale of hotseat. */
public static final MultiScalePropertyFactory<Hotseat> HOTSEAT_SCALE_PROPERTY_FACTORY =
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index 1e09b2d..84b95ec 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -67,18 +67,18 @@
*/
public class WorkspaceStateTransitionAnimation {
- private static final FloatProperty<Workspace> WORKSPACE_SCALE_PROPERTY =
+ private static final FloatProperty<Workspace<?>> WORKSPACE_SCALE_PROPERTY =
WORKSPACE_SCALE_PROPERTY_FACTORY.get(SCALE_INDEX_WORKSPACE_STATE);
private static final FloatProperty<Hotseat> HOTSEAT_SCALE_PROPERTY =
HOTSEAT_SCALE_PROPERTY_FACTORY.get(SCALE_INDEX_WORKSPACE_STATE);
private final Launcher mLauncher;
- private final Workspace mWorkspace;
+ private final Workspace<?> mWorkspace;
private float mNewScale;
- public WorkspaceStateTransitionAnimation(Launcher launcher, Workspace workspace) {
+ public WorkspaceStateTransitionAnimation(Launcher launcher, Workspace<?> workspace) {
mLauncher = launcher;
mWorkspace = workspace;
}
@@ -224,7 +224,7 @@
* Returns a spring based animator for the scale property of {@param workspace}.
*/
public static ValueAnimator getWorkspaceSpringScaleAnimator(Launcher launcher,
- Workspace workspace, float scale) {
+ Workspace<?> workspace, float scale) {
return getSpringScaleAnimator(launcher, workspace, scale, WORKSPACE_SCALE_PROPERTY);
}
diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
index 18c05eb..462daf5 100644
--- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
@@ -19,7 +19,7 @@
import com.android.launcher3.ButtonDropTarget;
import com.android.launcher3.CellLayout;
import com.android.launcher3.Launcher;
-import com.android.launcher3.LauncherSettings.Favorites;
+import com.android.launcher3.LauncherSettings;
import com.android.launcher3.PendingAddItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.Workspace;
@@ -153,61 +153,9 @@
} else if (action == MOVE) {
return beginAccessibleDrag(host, item, fromKeyboard);
} else if (action == ADD_TO_WORKSPACE) {
- final int[] coordinates = new int[2];
- final int screenId = findSpaceOnWorkspace(item, coordinates);
- if (screenId == -1) {
- return false;
- }
- mContext.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> {
- if (item instanceof AppInfo) {
- WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
- mContext.getModelWriter().addItemToDatabase(info,
- Favorites.CONTAINER_DESKTOP,
- screenId, coordinates[0], coordinates[1]);
-
- mContext.bindItems(
- Collections.singletonList(info),
- /* forceAnimateIcons= */ true,
- /* focusFirstItemForAccessibility= */ true);
- announceConfirmation(R.string.item_added_to_workspace);
- } else if (item instanceof PendingAddItemInfo) {
- PendingAddItemInfo info = (PendingAddItemInfo) item;
- Workspace workspace = mContext.getWorkspace();
- workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
- mContext.addPendingItem(info, Favorites.CONTAINER_DESKTOP,
- screenId, coordinates, info.spanX, info.spanY);
- }
- else if (item instanceof WorkspaceItemInfo) {
- WorkspaceItemInfo info = ((WorkspaceItemInfo) item).clone();
- mContext.getModelWriter().addItemToDatabase(info,
- Favorites.CONTAINER_DESKTOP,
- screenId, coordinates[0], coordinates[1]);
- mContext.bindItems(Collections.singletonList(info), true, true);
- }
- }));
- return true;
+ return addToWorkspace(item, true);
} else if (action == MOVE_TO_WORKSPACE) {
- Folder folder = Folder.getOpen(mContext);
- folder.close(true);
- WorkspaceItemInfo info = (WorkspaceItemInfo) item;
- folder.getInfo().remove(info, false);
-
- final int[] coordinates = new int[2];
- final int screenId = findSpaceOnWorkspace(item, coordinates);
- if (screenId == -1) {
- return false;
- }
- mContext.getModelWriter().moveItemInDatabase(info,
- Favorites.CONTAINER_DESKTOP,
- screenId, coordinates[0], coordinates[1]);
-
- // Bind the item in next frame so that if a new workspace page was created,
- // it will get laid out.
- new Handler().post(() -> {
- mContext.bindItems(Collections.singletonList(item), true);
- announceConfirmation(R.string.item_moved);
- });
- return true;
+ return moveToWorkspace(item);
} else if (action == RESIZE) {
final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
List<OptionItem> actions = getSupportedResizeActions(host, info);
@@ -403,4 +351,76 @@
}
return screenId;
}
+
+ /**
+ * Functionality to add the item {@link ItemInfo} to the workspace
+ * @param item item to be added
+ * @param accessibility true if the first item to be added to the workspace
+ * should be focused for accessibility.
+ *
+ * @return true if the item could be successfully added
+ */
+ public boolean addToWorkspace(ItemInfo item, boolean accessibility) {
+ final int[] coordinates = new int[2];
+ final int screenId = findSpaceOnWorkspace(item, coordinates);
+ if (screenId == -1) {
+ return false;
+ }
+ mContext.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> {
+ if (item instanceof AppInfo) {
+ WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
+ mContext.getModelWriter().addItemToDatabase(info,
+ LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ screenId, coordinates[0], coordinates[1]);
+
+ mContext.bindItems(
+ Collections.singletonList(info),
+ /* forceAnimateIcons= */ true,
+ /* focusFirstItemForAccessibility= */ accessibility);
+ announceConfirmation(R.string.item_added_to_workspace);
+ } else if (item instanceof PendingAddItemInfo) {
+ PendingAddItemInfo info = (PendingAddItemInfo) item;
+ Workspace<?> workspace = mContext.getWorkspace();
+ workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
+ mContext.addPendingItem(info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ screenId, coordinates, info.spanX, info.spanY);
+ } else if (item instanceof WorkspaceItemInfo) {
+ WorkspaceItemInfo info = ((WorkspaceItemInfo) item).clone();
+ mContext.getModelWriter().addItemToDatabase(info,
+ LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ screenId, coordinates[0], coordinates[1]);
+ mContext.bindItems(Collections.singletonList(info), true, accessibility);
+ }
+ }));
+ return true;
+ }
+ /**
+ * Functionality to move the item {@link ItemInfo} to the workspace
+ * @param item item to be moved
+ *
+ * @return true if the item could be successfully added
+ */
+ public boolean moveToWorkspace(ItemInfo item) {
+ Folder folder = Folder.getOpen(mContext);
+ folder.close(true);
+ WorkspaceItemInfo info = (WorkspaceItemInfo) item;
+ folder.getInfo().remove(info, false);
+
+ final int[] coordinates = new int[2];
+ final int screenId = findSpaceOnWorkspace(item, coordinates);
+ if (screenId == -1) {
+ return false;
+ }
+ mContext.getModelWriter().moveItemInDatabase(info,
+ LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ screenId, coordinates[0], coordinates[1]);
+
+ // Bind the item in next frame so that if a new workspace page was created,
+ // it will get laid out.
+ new Handler().post(() -> {
+ mContext.bindItems(Collections.singletonList(item), true);
+ announceConfirmation(R.string.item_moved);
+ });
+ return true;
+ }
}
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index 5ee4203..14e10918 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -104,7 +104,10 @@
mFocusIndicatorHelper = new ViewGroupFocusHelper(this);
}
- public void setup(DragController dragController, Workspace workspace) {
+ /**
+ * Set up the drag layer with the parameters.
+ */
+ public void setup(DragController dragController, Workspace<?> workspace) {
mDragController = dragController;
recreateControllers();
mWorkspaceDragScrim = new Scrim(this);
diff --git a/src/com/android/launcher3/dragndrop/SpringLoadedDragController.java b/src/com/android/launcher3/dragndrop/SpringLoadedDragController.java
index 6325877..fb8a1bc 100644
--- a/src/com/android/launcher3/dragndrop/SpringLoadedDragController.java
+++ b/src/com/android/launcher3/dragndrop/SpringLoadedDragController.java
@@ -55,7 +55,7 @@
public void onAlarm(Alarm alarm) {
if (mScreen != null) {
// Snap to the screen that we are hovering over now
- Workspace w = mLauncher.getWorkspace();
+ Workspace<?> w = mLauncher.getWorkspace();
if (!w.isVisible(mScreen)) {
w.snapToPage(w.indexOfChild(mScreen));
}
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java
index 7c665c6..5fe2435 100644
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -342,7 +342,7 @@
Rect to = finalRect;
if (to == null) {
to = new Rect();
- Workspace workspace = launcher.getWorkspace();
+ Workspace<?> workspace = launcher.getWorkspace();
// Set cellLayout and this to it's final state to compute final animation locations
workspace.setFinalTransitionTransform();
float scaleX = getScaleX();
diff --git a/src/com/android/launcher3/pageindicators/PageIndicator.java b/src/com/android/launcher3/pageindicators/PageIndicator.java
index 5967be7..ec69193 100644
--- a/src/com/android/launcher3/pageindicators/PageIndicator.java
+++ b/src/com/android/launcher3/pageindicators/PageIndicator.java
@@ -28,21 +28,22 @@
/**
* Sets the flag if the Page Indicator should autohide.
- * @param shouldAutoHide
*/
default void setShouldAutoHide(boolean shouldAutoHide) {
- //No-op by default
+ // No-op by default
}
+
/**
* Pauses all currently running animations.
*/
default void pauseAnimations() {
- //No-op by default
+ // No-op by default
}
+
/**
* Force-ends all currently running or paused animations.
*/
default void skipAnimationsToEnd() {
- //No-op by default
+ // No-op by default
}
}
diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java
index f06e5ce..df8a3e2 100644
--- a/src/com/android/launcher3/popup/ArrowPopup.java
+++ b/src/com/android/launcher3/popup/ArrowPopup.java
@@ -351,7 +351,7 @@
if (mColorExtractors == null) {
return;
}
- Workspace workspace = launcher.getWorkspace();
+ Workspace<?> workspace = launcher.getWorkspace();
if (workspace == null) {
return;
}
diff --git a/src/com/android/launcher3/states/SpringLoadedState.java b/src/com/android/launcher3/states/SpringLoadedState.java
index 9be3cc5..52356ce 100644
--- a/src/com/android/launcher3/states/SpringLoadedState.java
+++ b/src/com/android/launcher3/states/SpringLoadedState.java
@@ -46,7 +46,7 @@
@Override
public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) {
DeviceProfile grid = launcher.getDeviceProfile();
- Workspace ws = launcher.getWorkspace();
+ Workspace<?> ws = launcher.getWorkspace();
if (ws.getChildCount() == 0) {
return super.getWorkspaceScaleAndTranslation(launcher);
}
diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java
index 2eae99a..a6b481a 100644
--- a/src/com/android/launcher3/testing/TestInformationHandler.java
+++ b/src/com/android/launcher3/testing/TestInformationHandler.java
@@ -178,7 +178,7 @@
case TestProtocol.REQUEST_WORKSPACE_CELL_LAYOUT_SIZE:
return getLauncherUIProperty(Bundle::putIntArray, launcher -> {
- final Workspace workspace = launcher.getWorkspace();
+ final Workspace<?> workspace = launcher.getWorkspace();
final int screenId = workspace.getScreenIdForPageIndex(
workspace.getCurrentPage());
final CellLayout cellLayout = workspace.getScreenWithId(screenId);
@@ -189,7 +189,7 @@
final WorkspaceCellCenterRequest request = extra.getParcelable(
TestProtocol.TEST_INFO_REQUEST_FIELD);
return getLauncherUIProperty(Bundle::putParcelable, launcher -> {
- final Workspace workspace = launcher.getWorkspace();
+ final Workspace<?> workspace = launcher.getWorkspace();
// TODO(b/216387249): allow caller selecting different pages.
CellLayout cellLayout = (CellLayout) workspace.getPageAt(
workspace.getCurrentPage());
diff --git a/src/com/android/launcher3/touch/WorkspaceTouchListener.java b/src/com/android/launcher3/touch/WorkspaceTouchListener.java
index fe0bf6d..17bbdf1 100644
--- a/src/com/android/launcher3/touch/WorkspaceTouchListener.java
+++ b/src/com/android/launcher3/touch/WorkspaceTouchListener.java
@@ -64,7 +64,7 @@
private final Rect mTempRect = new Rect();
private final Launcher mLauncher;
- private final Workspace mWorkspace;
+ private final Workspace<?> mWorkspace;
private final PointF mTouchDownPoint = new PointF();
private final float mTouchSlop;
@@ -72,7 +72,7 @@
private final GestureDetector mGestureDetector;
- public WorkspaceTouchListener(Launcher launcher, Workspace workspace) {
+ public WorkspaceTouchListener(Launcher launcher, Workspace<?> workspace) {
mLauncher = launcher;
mWorkspace = workspace;
// Use twice the touch slop as we are looking for long press which is more
diff --git a/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java b/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java
index f1276dd..43e9820 100644
--- a/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java
+++ b/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java
@@ -32,7 +32,7 @@
// Don't use all the wallpaper for parallax until you have at least this many pages
private static final int MIN_PARALLAX_PAGE_SPAN = 4;
- private final Workspace mWorkspace;
+ private final Workspace<?> mWorkspace;
private final boolean mIsRtl;
private final Handler mHandler;
@@ -43,7 +43,7 @@
private boolean mLockedToDefaultPage;
private int mNumScreens;
- public WallpaperOffsetInterpolator(Workspace workspace) {
+ public WallpaperOffsetInterpolator(Workspace<?> workspace) {
mWorkspace = workspace;
mIsRtl = Utilities.isRtl(workspace.getResources());
mHandler = new OffsetHandler(workspace.getContext());