From aa8ef119f18864f4ab41c12f9c2ad6d7f643a0a9 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 12 Jun 2015 20:04:41 -0700 Subject: Refactoring ItemInfo > Changing dragObject to ItemInfo > Removing dropPos which is always null > Removing requiresDbUpdate which is only used in CellLayout Change-Id: I753ddaae0880c8a9bfee5a1266095ff34610284a --- src/com/android/launcher3/AppInfo.java | 7 +- src/com/android/launcher3/ButtonDropTarget.java | 7 +- src/com/android/launcher3/CellLayout.java | 41 +++++----- src/com/android/launcher3/DeleteDropTarget.java | 6 +- src/com/android/launcher3/DragController.java | 8 +- src/com/android/launcher3/DropTarget.java | 2 +- src/com/android/launcher3/Folder.java | 4 +- src/com/android/launcher3/FolderIcon.java | 10 +-- src/com/android/launcher3/FolderInfo.java | 3 +- src/com/android/launcher3/InfoDropTarget.java | 17 +--- src/com/android/launcher3/ItemInfo.java | 29 ++----- src/com/android/launcher3/Launcher.java | 10 +-- src/com/android/launcher3/LauncherModel.java | 7 +- src/com/android/launcher3/SearchDropTargetBar.java | 2 +- src/com/android/launcher3/ShortcutInfo.java | 3 +- src/com/android/launcher3/UninstallDropTarget.java | 10 +-- src/com/android/launcher3/Workspace.java | 90 ++++++---------------- .../LauncherAccessibilityDelegate.java | 2 +- .../launcher3/allapps/AllAppsContainerView.java | 2 +- .../android/launcher3/model/PackageItemInfo.java | 5 +- .../launcher3/widget/WidgetHostViewLoader.java | 3 +- .../launcher3/widget/WidgetsContainerView.java | 2 +- 22 files changed, 92 insertions(+), 178 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java index c95d5585a..7249c6406 100644 --- a/src/com/android/launcher3/AppInfo.java +++ b/src/com/android/launcher3/AppInfo.java @@ -28,13 +28,11 @@ import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.util.ComponentKey; import java.util.ArrayList; -import java.util.Arrays; /** * Represents an app in AllAppsView. */ public class AppInfo extends ItemInfo { - private static final String TAG = "Launcher3.AppInfo"; /** * The intent used to start the application. @@ -118,8 +116,7 @@ public class AppInfo extends ItemInfo { return "ApplicationInfo(title=" + title + " id=" + this.id + " type=" + this.itemType + " container=" + this.container + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY - + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos) - + " user=" + user + ")"; + + " spanX=" + spanX + " spanY=" + spanY + " user=" + user + ")"; } /** @@ -128,7 +125,7 @@ public class AppInfo extends ItemInfo { public static void dumpApplicationInfoList(String tag, String label, ArrayList list) { Log.d(tag, label + " size=" + list.size()); for (AppInfo info: list) { - Log.d(tag, " title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap + Log.d(tag, " title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap + " firstInstallTime=" + info.firstInstallTime + " componentName=" + info.componentName.getPackageName()); } diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index b7f89d02a..574f229eb 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -24,7 +24,6 @@ import android.animation.ValueAnimator.AnimatorUpdateListener; import android.annotation.TargetApi; import android.content.Context; import android.content.res.ColorStateList; -import android.content.res.Configuration; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.PointF; @@ -185,8 +184,8 @@ public abstract class ButtonDropTarget extends TextView } } - @Override - public final void onDragStart(DragSource source, Object info, int dragAction) { + @Override + public final void onDragStart(DragSource source, ItemInfo info, int dragAction) { mActive = supportsDrop(source, info); mDrawable.setColorFilter(null); if (mCurrentColorAnim != null) { @@ -202,7 +201,7 @@ public abstract class ButtonDropTarget extends TextView return supportsDrop(dragObject.dragSource, dragObject.dragInfo); } - protected abstract boolean supportsDrop(DragSource source, Object info); + protected abstract boolean supportsDrop(DragSource source, ItemInfo info); @Override public boolean isDropEnabled() { diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 2cde3d53d..ee784631e 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -50,6 +50,7 @@ import android.view.animation.DecelerateInterpolator; import com.android.launcher3.BubbleTextView.BubbleTextShadowHandler; import com.android.launcher3.FolderIcon.FolderRingAnimator; +import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.accessibility.DragAndDropAccessibilityDelegate; import com.android.launcher3.accessibility.FolderAccessibilityHelper; import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper; @@ -1084,23 +1085,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler { mDragCell[0] = mDragCell[1] = -1; } - /** - * Find a vacant area that will fit the given bounds nearest the requested - * cell location. Uses Euclidean distance to score multiple vacant areas. - * - * @param pixelX The X location at which you want to search for a vacant area. - * @param pixelY The Y location at which you want to search for a vacant area. - * @param spanX Horizontal span of the object. - * @param spanY Vertical span of the object. - * @param result Array in which to place the result, or null (in which case a new array will - * be allocated) - * @return The X, Y cell of a vacant area that can contain this object, - * nearest the requested location. - */ - int[] findNearestVacantArea(int pixelX, int pixelY, int spanX, int spanY, int[] result) { - return findNearestVacantArea(pixelX, pixelY, spanX, spanY, spanX, spanY, result, null); - } - /** * Find a vacant area that will fit the given bounds nearest the requested * cell location. Uses Euclidean distance to score multiple vacant areas. @@ -2198,6 +2182,15 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler { mOccupied[i][j] = mTmpOccupied[i][j]; } } + + long screenId = mLauncher.getWorkspace().getIdForScreen(this); + int container = Favorites.CONTAINER_DESKTOP; + + if (mLauncher.isHotseatLayout(this)) { + screenId = -1; + container = Favorites.CONTAINER_HOTSEAT; + } + int childCount = mShortcutsAndWidgets.getChildCount(); for (int i = 0; i < childCount; i++) { View child = mShortcutsAndWidgets.getChildAt(i); @@ -2206,17 +2199,21 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler { // We do a null check here because the item info can be null in the case of the // AllApps button in the hotseat. if (info != null) { - if (info.cellX != lp.tmpCellX || info.cellY != lp.tmpCellY || - info.spanX != lp.cellHSpan || info.spanY != lp.cellVSpan) { - info.requiresDbUpdate = true; - } + final boolean requiresDbUpdate = (info.cellX != lp.tmpCellX + || info.cellY != lp.tmpCellY || info.spanX != lp.cellHSpan + || info.spanY != lp.cellVSpan); + info.cellX = lp.cellX = lp.tmpCellX; info.cellY = lp.cellY = lp.tmpCellY; info.spanX = lp.cellHSpan; info.spanY = lp.cellVSpan; + + if (requiresDbUpdate) { + LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, + info.cellX, info.cellY, info.spanX, info.spanY); + } } } - mLauncher.getWorkspace().updateItemLocationsInDatabase(this); } private void setUseTempCoords(boolean useTempCoords) { diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java index 9c8659c29..ae6e3ba0b 100644 --- a/src/com/android/launcher3/DeleteDropTarget.java +++ b/src/com/android/launcher3/DeleteDropTarget.java @@ -46,20 +46,20 @@ public class DeleteDropTarget extends ButtonDropTarget { setDrawable(R.drawable.ic_remove_launcher); } - public static boolean supportsDrop(Object info) { + public static boolean supportsDrop(ItemInfo info) { return (info instanceof ShortcutInfo) || (info instanceof LauncherAppWidgetInfo) || (info instanceof FolderInfo); } @Override - protected boolean supportsDrop(DragSource source, Object info) { + protected boolean supportsDrop(DragSource source, ItemInfo info) { return source.supportsDeleteDropTarget() && supportsDrop(info); } @Override @Thunk void completeDrop(DragObject d) { - ItemInfo item = (ItemInfo) d.dragInfo; + ItemInfo item = d.dragInfo; if ((d.dragSource instanceof Workspace) || (d.dragSource instanceof Folder)) { removeWorkspaceOrFolderItem(mLauncher, item, null); } diff --git a/src/com/android/launcher3/DragController.java b/src/com/android/launcher3/DragController.java index 2191455d5..410271d29 100644 --- a/src/com/android/launcher3/DragController.java +++ b/src/com/android/launcher3/DragController.java @@ -135,14 +135,14 @@ public class DragController { * @param dragAction The drag action: either {@link DragController#DRAG_ACTION_MOVE} * or {@link DragController#DRAG_ACTION_COPY} */ - void onDragStart(DragSource source, Object info, int dragAction); + void onDragStart(DragSource source, ItemInfo info, int dragAction); /** * The drag has ended */ void onDragEnd(); } - + /** * Used to create a new DragLayer from XML. * @@ -178,7 +178,7 @@ public class DragController { * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. * Makes dragging feel more precise, e.g. you can clip out a transparent border */ - public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, + public void startDrag(View v, Bitmap bmp, DragSource source, ItemInfo dragInfo, Rect viewImageBounds, int dragAction, float initialDragViewScale) { int[] loc = mCoordinatesTemp; mLauncher.getDragLayer().getLocationInDragLayer(v, loc); @@ -211,7 +211,7 @@ public class DragController { * @param accessible whether this drag should occur in accessibility mode */ public DragView startDrag(Bitmap b, int dragLayerX, int dragLayerY, - DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion, + DragSource source, ItemInfo dragInfo, int dragAction, Point dragOffset, Rect dragRegion, float initialDragViewScale, boolean accessible) { if (PROFILE_DRAWING_DURING_DRAG) { android.os.Debug.startMethodTracing("Launcher"); diff --git a/src/com/android/launcher3/DropTarget.java b/src/com/android/launcher3/DropTarget.java index c8fac5466..374846445 100644 --- a/src/com/android/launcher3/DropTarget.java +++ b/src/com/android/launcher3/DropTarget.java @@ -47,7 +47,7 @@ public interface DropTarget { public DragView dragView = null; /** The data associated with the object being dragged */ - public Object dragInfo = null; + public ItemInfo dragInfo = null; /** Where the drag originated */ public DragSource dragSource = null; diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java index 85f58a1b1..fbb2394ed 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -598,7 +598,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList } @Override - public void onDragStart(DragSource source, Object info, int dragAction) { } + public void onDragStart(DragSource source, ItemInfo info, int dragAction) { } @Override public void onDragEnd() { @@ -647,7 +647,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList } public boolean acceptDrop(DragObject d) { - final ItemInfo item = (ItemInfo) d.dragInfo; + final ItemInfo item = d.dragInfo; final int itemType = item.itemType; return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && diff --git a/src/com/android/launcher3/FolderIcon.java b/src/com/android/launcher3/FolderIcon.java index 8d534d2fe..de0df0dee 100644 --- a/src/com/android/launcher3/FolderIcon.java +++ b/src/com/android/launcher3/FolderIcon.java @@ -330,8 +330,8 @@ public class FolderIcon extends FrameLayout implements FolderListener { !mFolder.isFull() && item != mInfo && !mInfo.opened); } - public boolean acceptDrop(Object dragInfo) { - final ItemInfo item = (ItemInfo) dragInfo; + public boolean acceptDrop(ItemInfo dragInfo) { + final ItemInfo item = dragInfo; return !mFolder.isDestroyed() && willAcceptItem(item); } @@ -339,8 +339,8 @@ public class FolderIcon extends FrameLayout implements FolderListener { mInfo.add(item); } - public void onDragEnter(Object dragInfo) { - if (mFolder.isDestroyed() || !willAcceptItem((ItemInfo) dragInfo)) return; + public void onDragEnter(ItemInfo dragInfo) { + if (mFolder.isDestroyed() || !willAcceptItem(dragInfo)) return; CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams(); CellLayout layout = (CellLayout) getParent().getParent(); mFolderRingAnimator.setCell(lp.cellX, lp.cellY); @@ -356,7 +356,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { // Workspace#onDropExternal. mOpenAlarm.setAlarm(ON_OPEN_DELAY); } - mDragInfo = (ItemInfo) dragInfo; + mDragInfo = dragInfo; } public void onDragOver(Object dragInfo) { diff --git a/src/com/android/launcher3/FolderInfo.java b/src/com/android/launcher3/FolderInfo.java index aea21c95b..6e0dcd421 100644 --- a/src/com/android/launcher3/FolderInfo.java +++ b/src/com/android/launcher3/FolderInfo.java @@ -22,7 +22,6 @@ import android.content.Context; import com.android.launcher3.compat.UserHandleCompat; import java.util.ArrayList; -import java.util.Arrays; /** * Represents a folder containing shortcuts or apps. @@ -140,7 +139,7 @@ public class FolderInfo extends ItemInfo { return "FolderInfo(id=" + this.id + " type=" + this.itemType + " container=" + this.container + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX - + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos) + ")"; + + " spanY=" + spanY + ")"; } public boolean hasOption(int optionFlag) { diff --git a/src/com/android/launcher3/InfoDropTarget.java b/src/com/android/launcher3/InfoDropTarget.java index d93cdcc1b..b4a144526 100644 --- a/src/com/android/launcher3/InfoDropTarget.java +++ b/src/com/android/launcher3/InfoDropTarget.java @@ -20,8 +20,6 @@ import android.content.ComponentName; import android.content.Context; import android.util.AttributeSet; -import com.android.launcher3.compat.UserHandleCompat; - public class InfoDropTarget extends ButtonDropTarget { public InfoDropTarget(Context context, AttributeSet attrs) { @@ -41,7 +39,7 @@ public class InfoDropTarget extends ButtonDropTarget { setDrawable(R.drawable.ic_info_launcher); } - public static void startDetailsActivityForInfo(Object info, Launcher launcher) { + public static void startDetailsActivityForInfo(ItemInfo info, Launcher launcher) { ComponentName componentName = null; if (info instanceof AppInfo) { componentName = ((AppInfo) info).componentName; @@ -50,24 +48,17 @@ public class InfoDropTarget extends ButtonDropTarget { } else if (info instanceof PendingAddItemInfo) { componentName = ((PendingAddItemInfo) info).componentName; } - final UserHandleCompat user; - if (info instanceof ItemInfo) { - user = ((ItemInfo) info).user; - } else { - user = UserHandleCompat.myUserHandle(); - } - if (componentName != null) { - launcher.startApplicationDetailsActivity(componentName, user); + launcher.startApplicationDetailsActivity(componentName, info.user); } } @Override - protected boolean supportsDrop(DragSource source, Object info) { + protected boolean supportsDrop(DragSource source, ItemInfo info) { return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info); } - public static boolean supportsDrop(Context context, Object info) { + public static boolean supportsDrop(Context context, ItemInfo info) { return info instanceof AppInfo || info instanceof PendingAddItemInfo; } diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java index f7e0ea488..4bc501987 100644 --- a/src/com/android/launcher3/ItemInfo.java +++ b/src/com/android/launcher3/ItemInfo.java @@ -24,8 +24,6 @@ import android.graphics.Bitmap; import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.compat.UserManagerCompat; -import java.util.Arrays; - /** * Represents an item in the launcher. */ @@ -35,14 +33,14 @@ public class ItemInfo { * Intent extra to store the profile. Format: UserHandle */ static final String EXTRA_PROFILE = "profile"; - + public static final int NO_ID = -1; - + /** * The id in the settings database for this item */ public long id = NO_ID; - + /** * One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION}, * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT}, @@ -50,20 +48,20 @@ public class ItemInfo { * {@link LauncherSettings.Favorites#ITEM_TYPE_APPWIDGET}. */ public int itemType; - + /** - * The id of the container that holds this item. For the desktop, this will be + * The id of the container that holds this item. For the desktop, this will be * {@link LauncherSettings.Favorites#CONTAINER_DESKTOP}. For the all applications folder it * will be {@link #NO_ID} (since it is not stored in the settings DB). For user folders * it will be the id of the folder. */ public long container = NO_ID; - + /** * Iindicates the screen in which the shortcut appears. */ public long screenId = -1; - + /** * Indicates the X position of the associated cell. */ @@ -99,11 +97,6 @@ public class ItemInfo { */ public int rank = 0; - /** - * Indicates that this item needs to be updated in the db - */ - public boolean requiresDbUpdate = false; - /** * Title of the item */ @@ -114,11 +107,6 @@ public class ItemInfo { */ public CharSequence contentDescription; - /** - * The position of the item in a drag-and-drop operation. - */ - public int[] dropPos = null; - public UserHandleCompat user; public ItemInfo() { @@ -194,7 +182,6 @@ public class ItemInfo { public String toString() { return "Item(id=" + this.id + " type=" + this.itemType + " container=" + this.container + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX - + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos) - + " user=" + user + ")"; + + " spanY=" + spanY + " user=" + user + ")"; } } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 0a20fa48d..c9b782982 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -253,7 +253,7 @@ public class Launcher extends Activity private AppWidgetManagerCompat mAppWidgetManager; private LauncherAppWidgetHost mAppWidgetHost; - @Thunk ItemInfo mPendingAddInfo = new ItemInfo(); + @Thunk final ItemInfo mPendingAddInfo = new ItemInfo(); private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo; private int mPendingAddWidgetId = -1; @@ -1500,7 +1500,6 @@ public class Launcher extends Activity private void completeAddShortcut(Intent data, long container, long screenId, int cellX, int cellY) { int[] cellXY = mTmpAddItemCellCoordinates; - int[] touchXY = mPendingAddInfo.dropPos; CellLayout layout = getCellLayout(container, screenId); ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data); @@ -1527,10 +1526,6 @@ public class Launcher extends Activity true)) { return; } - } else if (touchXY != null) { - // when dragging and dropping, just find the closest free spot - int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); - foundCellSpan = (result != null); } else { foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); } @@ -2214,7 +2209,6 @@ public class Launcher extends Activity mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; - mPendingAddInfo.dropPos = null; } void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, final @@ -2286,7 +2280,6 @@ public class Launcher extends Activity resetAddInfo(); mPendingAddInfo.container = container; mPendingAddInfo.screenId = screenId; - mPendingAddInfo.dropPos = null; if (cell != null) { mPendingAddInfo.cellX = cell[0]; @@ -2310,7 +2303,6 @@ public class Launcher extends Activity resetAddInfo(); mPendingAddInfo.container = info.container = container; mPendingAddInfo.screenId = info.screenId = screenId; - mPendingAddInfo.dropPos = null; mPendingAddInfo.minSpanX = info.minSpanX; mPendingAddInfo.minSpanY = info.minSpanY; diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 7414a2204..bc1bc17df 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -660,12 +660,7 @@ public class LauncherModel extends BroadcastReceiver modelShortcut.cellX == shortcut.cellX && modelShortcut.cellY == shortcut.cellY && modelShortcut.spanX == shortcut.spanX && - modelShortcut.spanY == shortcut.spanY && - ((modelShortcut.dropPos == null && shortcut.dropPos == null) || - (modelShortcut.dropPos != null && - shortcut.dropPos != null && - modelShortcut.dropPos[0] == shortcut.dropPos[0] && - modelShortcut.dropPos[1] == shortcut.dropPos[1]))) { + modelShortcut.spanY == shortcut.spanY) { // For all intents and purposes, this is the same object return; } diff --git a/src/com/android/launcher3/SearchDropTargetBar.java b/src/com/android/launcher3/SearchDropTargetBar.java index 4cdf1cac9..7c8f4415a 100644 --- a/src/com/android/launcher3/SearchDropTargetBar.java +++ b/src/com/android/launcher3/SearchDropTargetBar.java @@ -196,7 +196,7 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D * DragController.DragListener implementation */ @Override - public void onDragStart(DragSource source, Object info, int dragAction) { + public void onDragStart(DragSource source, ItemInfo info, int dragAction) { showDeleteTarget(); } diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java index 56c0b9d2f..fe76634b3 100644 --- a/src/com/android/launcher3/ShortcutInfo.java +++ b/src/com/android/launcher3/ShortcutInfo.java @@ -29,7 +29,6 @@ import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.compat.UserManagerCompat; import java.util.ArrayList; -import java.util.Arrays; /** * Represents a launchable icon on the workspaces and in folders. @@ -241,7 +240,7 @@ public class ShortcutInfo extends ItemInfo { return "ShortcutInfo(title=" + title + "intent=" + intent + "id=" + this.id + " type=" + this.itemType + " container=" + this.container + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX + " spanY=" + spanY - + " dropPos=" + Arrays.toString(dropPos) + " user=" + user + ")"; + + " user=" + user + ")"; } public static void dumpShortcutInfoList(String tag, String label, diff --git a/src/com/android/launcher3/UninstallDropTarget.java b/src/com/android/launcher3/UninstallDropTarget.java index 0819f8ce0..7c548a5f8 100644 --- a/src/com/android/launcher3/UninstallDropTarget.java +++ b/src/com/android/launcher3/UninstallDropTarget.java @@ -8,7 +8,7 @@ import android.os.Bundle; import android.os.UserManager; import android.util.AttributeSet; import android.util.Pair; -import com.android.launcher3.R; + import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.util.Thunk; @@ -32,7 +32,7 @@ public class UninstallDropTarget extends ButtonDropTarget { } @Override - protected boolean supportsDrop(DragSource source, Object info) { + protected boolean supportsDrop(DragSource source, ItemInfo info) { return supportsDrop(getContext(), info); } @@ -81,7 +81,7 @@ public class UninstallDropTarget extends ButtonDropTarget { @Override void completeDrop(final DragObject d) { final Pair componentInfo = getAppInfoFlags(d.dragInfo); - final UserHandleCompat user = ((ItemInfo) d.dragInfo).user; + final UserHandleCompat user = d.dragInfo.user; if (startUninstallActivity(mLauncher, d.dragInfo)) { final Runnable checkIfUninstallWasSuccess = new Runnable() { @@ -99,9 +99,9 @@ public class UninstallDropTarget extends ButtonDropTarget { } } - public static boolean startUninstallActivity(Launcher launcher, Object info) { + public static boolean startUninstallActivity(Launcher launcher, ItemInfo info) { final Pair componentInfo = getAppInfoFlags(info); - final UserHandleCompat user = ((ItemInfo) info).user; + final UserHandleCompat user = info.user; return launcher.startApplicationUninstallActivity( componentInfo.first, componentInfo.second, user); } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index fb0a54d3c..d53d78174 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -28,7 +28,6 @@ import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; import android.content.res.TypedArray; @@ -167,7 +166,6 @@ public class Workspace extends PagedView // return an (x, y) value from helper functions. Do NOT use them to maintain other state. private int[] mTempCell = new int[2]; private int[] mTempPt = new int[2]; - private int[] mTempEstimate = new int[2]; @Thunk float[] mDragViewVisualCenter = new float[2]; private float[] mTempCellLayoutCenterCoordinates = new float[2]; private Matrix mTempInverseMatrix = new Matrix(); @@ -369,7 +367,7 @@ public class Workspace extends PagedView } @Override - public void onDragStart(final DragSource source, Object info, int dragAction) { + public void onDragStart(final DragSource source, ItemInfo info, int dragAction) { if (ENFORCE_DRAG_EVENT_ORDER) { enfoceDragParity("onDragStart", 0, 0); } @@ -2285,15 +2283,17 @@ public class Workspace extends PagedView icon.clearPressedBackground(); } - if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { + Object dragObject = child.getTag(); + if (!(dragObject instanceof ItemInfo)) { String msg = "Drag started with a view that has no tag set. This " + "will cause a crash (issue 11627249) down the line. " + "View: " + child + " tag: " + child.getTag(); throw new IllegalStateException(msg); } - DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), - DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale, accessible); + DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, + (ItemInfo) dragObject, DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, + dragRect, scale, accessible); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); if (child.getParent() instanceof ShortcutAndWidgetContainer) { @@ -2333,7 +2333,8 @@ public class Workspace extends PagedView Point dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2); Rect dragRect = new Rect(0, 0, iconSize, iconSize); - if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { + Object dragObject = child.getTag(); + if (!(dragObject instanceof ItemInfo)) { String msg = "Drag started with a view that has no tag set. This " + "will cause a crash (issue 11627249) down the line. " + "View: " + child + " tag: " + child.getTag(); @@ -2341,8 +2342,9 @@ public class Workspace extends PagedView } // Start the drag - DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), - DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale, false); + DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, + (ItemInfo) dragObject, DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, + dragRect, scale, false); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); // Recycle temporary bitmaps @@ -2383,9 +2385,8 @@ public class Workspace extends PagedView spanX = dragCellInfo.spanX; spanY = dragCellInfo.spanY; } else { - final ItemInfo dragInfo = (ItemInfo) d.dragInfo; - spanX = dragInfo.spanX; - spanY = dragInfo.spanY; + spanX = d.dragInfo.spanX; + spanY = d.dragInfo.spanY; } int minSpanX = spanX; @@ -2400,12 +2401,12 @@ public class Workspace extends PagedView mTargetCell); float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); - if (mCreateUserFolderOnDrop && willCreateUserFolder((ItemInfo) d.dragInfo, + if (mCreateUserFolderOnDrop && willCreateUserFolder(d.dragInfo, dropTargetLayout, mTargetCell, distance, true)) { return true; } - if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder((ItemInfo) d.dragInfo, + if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder(d.dragInfo, dropTargetLayout, mTargetCell, distance)) { return true; } @@ -2471,7 +2472,7 @@ public class Workspace extends PagedView return (aboveShortcut && willBecomeShortcut); } - boolean willAddToExistingUserFolder(Object dragInfo, CellLayout target, int[] targetCell, + boolean willAddToExistingUserFolder(ItemInfo dragInfo, CellLayout target, int[] targetCell, float distance) { if (distance > mMaxDistanceForFolderCreation) return false; View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); @@ -2627,7 +2628,7 @@ public class Workspace extends PagedView // Aside from the special case where we're dropping a shortcut onto a shortcut, // we need to find the nearest cell location that is vacant - ItemInfo item = (ItemInfo) d.dragInfo; + ItemInfo item = d.dragInfo; int minSpanX = item.spanX; int minSpanY = item.spanY; if (item.minSpanX > 0 && item.minSpanY > 0) { @@ -3117,7 +3118,7 @@ public class Workspace extends PagedView Rect r = new Rect(); CellLayout layout = null; - ItemInfo item = (ItemInfo) d.dragInfo; + ItemInfo item = d.dragInfo; if (item == null) { if (LauncherAppState.isDogfoodBuild()) { throw new NullPointerException("DragObject has null info"); @@ -3178,7 +3179,7 @@ public class Workspace extends PagedView mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null); } - ItemInfo info = (ItemInfo) d.dragInfo; + ItemInfo info = d.dragInfo; int minSpanX = item.spanX; int minSpanY = item.spanY; @@ -3357,24 +3358,6 @@ public class Workspace extends PagedView mLauncher.getDragLayer().getDescendantRectRelativeToSelf(this, outRect); } - /** - * Add the item specified by dragInfo to the given layout. - * @return true if successful - */ - public boolean addExternalItemToScreen(ItemInfo dragInfo, CellLayout layout) { - if (layout.findCellForSpan(mTempEstimate, dragInfo.spanX, dragInfo.spanY)) { - onDropExternal(dragInfo.dropPos, (ItemInfo) dragInfo, (CellLayout) layout, false); - return true; - } - mLauncher.showOutOfSpaceMessage(mLauncher.isHotseatLayout(layout)); - return false; - } - - private void onDropExternal(int[] touchXY, Object dragInfo, - CellLayout cellLayout, boolean insertAtFirst) { - onDropExternal(touchXY, dragInfo, cellLayout, insertAtFirst, null); - } - /** * Drop an item that didn't originate on one of the workspace screens. * It may have come from Launcher (e.g. from all apps or customize), or it may have @@ -3383,7 +3366,7 @@ public class Workspace extends PagedView * NOTE: This can also be called when we are outside of a drag event, when we want * to add an item to one of the workspace screens. */ - private void onDropExternal(final int[] touchXY, final Object dragInfo, + private void onDropExternal(final int[] touchXY, final ItemInfo dragInfo, final CellLayout cellLayout, boolean insertAtFirst, DragObject d) { final Runnable exitSpringLoadedRunnable = new Runnable() { @Override @@ -3393,7 +3376,7 @@ public class Workspace extends PagedView } }; - ItemInfo info = (ItemInfo) dragInfo; + ItemInfo info = dragInfo; int spanX = info.spanX; int spanY = info.spanY; if (mDragInfo != null) { @@ -3420,14 +3403,14 @@ public class Workspace extends PagedView cellLayout, mTargetCell); float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); - if (willCreateUserFolder((ItemInfo) d.dragInfo, cellLayout, mTargetCell, - distance, true) || willAddToExistingUserFolder((ItemInfo) d.dragInfo, - cellLayout, mTargetCell, distance)) { + if (willCreateUserFolder(d.dragInfo, cellLayout, mTargetCell, distance, true) + || willAddToExistingUserFolder( + d.dragInfo, cellLayout, mTargetCell, distance)) { findNearestVacantCell = false; } } - final ItemInfo item = (ItemInfo) d.dragInfo; + final ItemInfo item = d.dragInfo; boolean updateWidgetSize = false; if (findNearestVacantCell) { int minSpanX = item.spanX; @@ -3788,29 +3771,6 @@ public class Workspace extends PagedView } } - void updateItemLocationsInDatabase(CellLayout cl) { - int count = cl.getShortcutsAndWidgets().getChildCount(); - - long screenId = getIdForScreen(cl); - int container = Favorites.CONTAINER_DESKTOP; - - if (mLauncher.isHotseatLayout(cl)) { - screenId = -1; - container = Favorites.CONTAINER_HOTSEAT; - } - - for (int i = 0; i < count; i++) { - View v = cl.getShortcutsAndWidgets().getChildAt(i); - ItemInfo info = (ItemInfo) v.getTag(); - // Null check required as the AllApps button doesn't have an item info - if (info != null && info.requiresDbUpdate) { - info.requiresDbUpdate = false; - LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, info.cellX, - info.cellY, info.spanX, info.spanY); - } - } - } - void saveWorkspaceToDb() { saveWorkspaceScreenToDb((CellLayout) mLauncher.getHotseat().getLayout()); int count = getChildCount(); diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index fe7b25edd..c11aab995 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -375,7 +375,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme @Override - public void onDragStart(DragSource source, Object info, int dragAction) { + public void onDragStart(DragSource source, ItemInfo info, int dragAction) { // No-op } diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 0651fb02e..368111aa4 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -605,7 +605,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc int currentScreen = mLauncher.getCurrentWorkspaceScreen(); Workspace workspace = (Workspace) target; CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen); - ItemInfo itemInfo = (ItemInfo) d.dragInfo; + ItemInfo itemInfo = d.dragInfo; if (layout != null) { layout.calculateSpans(itemInfo); showOutOfSpaceMessage = diff --git a/src/com/android/launcher3/model/PackageItemInfo.java b/src/com/android/launcher3/model/PackageItemInfo.java index 30f228c68..ddc9cbfd9 100644 --- a/src/com/android/launcher3/model/PackageItemInfo.java +++ b/src/com/android/launcher3/model/PackageItemInfo.java @@ -20,8 +20,6 @@ import android.graphics.Bitmap; import com.android.launcher3.ItemInfo; -import java.util.Arrays; - /** * Represents a {@link Package} in the widget tray section. */ @@ -59,7 +57,6 @@ public class PackageItemInfo extends ItemInfo { return "PackageItemInfo(title=" + title + " id=" + this.id + " type=" + this.itemType + " container=" + this.container + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY - + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos) - + " user=" + user + ")"; + + " spanX=" + spanX + " spanY=" + spanY + " user=" + user + ")"; } } diff --git a/src/com/android/launcher3/widget/WidgetHostViewLoader.java b/src/com/android/launcher3/widget/WidgetHostViewLoader.java index 30b3d581a..bdd117c73 100644 --- a/src/com/android/launcher3/widget/WidgetHostViewLoader.java +++ b/src/com/android/launcher3/widget/WidgetHostViewLoader.java @@ -13,6 +13,7 @@ import com.android.launcher3.AppWidgetResizeFrame; import com.android.launcher3.DragController.DragListener; import com.android.launcher3.DragLayer; import com.android.launcher3.DragSource; +import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppWidgetProviderInfo; import com.android.launcher3.compat.AppWidgetManagerCompat; @@ -43,7 +44,7 @@ public class WidgetHostViewLoader implements DragListener { } @Override - public void onDragStart(DragSource source, Object info, int dragAction) { } + public void onDragStart(DragSource source, ItemInfo info, int dragAction) { } @Override public void onDragEnd() { diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java index 5afd7c493..0f43a34e2 100644 --- a/src/com/android/launcher3/widget/WidgetsContainerView.java +++ b/src/com/android/launcher3/widget/WidgetsContainerView.java @@ -317,7 +317,7 @@ public class WidgetsContainerView extends BaseContainerView int currentScreen = mLauncher.getCurrentWorkspaceScreen(); Workspace workspace = (Workspace) target; CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen); - ItemInfo itemInfo = (ItemInfo) d.dragInfo; + ItemInfo itemInfo = d.dragInfo; if (layout != null) { layout.calculateSpans(itemInfo); showOutOfSpaceMessage = -- cgit v1.2.3