From 876e462ffa47d297100a2c8c4427d749e1ed0ed8 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 2 Nov 2018 13:50:40 -0700 Subject: Removing separate hotseat widget, instead using a QSB acroll all UI. The QSB is responsible for updating its UI according to various states. Bug: 109828640 Change-Id: Ic8cbf3d404d5870de0f6b8fe25a332b8d21bae20 --- src/com/android/launcher3/Workspace.java | 116 +++++++++++-------------------- 1 file changed, 42 insertions(+), 74 deletions(-) (limited to 'src/com/android/launcher3/Workspace.java') diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 3f7d68d12..7a8d984d7 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -85,8 +85,8 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Action; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.IntArray; -import com.android.launcher3.util.IntSparseArrayMap; import com.android.launcher3.util.IntSet; +import com.android.launcher3.util.IntSparseArrayMap; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.util.Thunk; @@ -880,7 +880,7 @@ public class Workspace extends PagedView final CellLayout layout; if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { - layout = mLauncher.getHotseat().getLayout(); + layout = mLauncher.getHotseat(); // Hide folder title in the hotseat if (child instanceof FolderIcon) { @@ -1517,7 +1517,7 @@ public class Workspace extends PagedView @Override protected void enableAccessibleDrag(boolean enable) { super.enableAccessibleDrag(enable); - setEnableForLayout(mLauncher.getHotseat().getLayout(),enable); + setEnableForLayout(mLauncher.getHotseat(),enable); } }); } @@ -1625,11 +1625,7 @@ public class Workspace extends PagedView mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter); // We want the point to be mapped to the dragTarget. - if (mLauncher.isHotseatLayout(dropTargetLayout)) { - mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); - } else { - mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter); - } + mapPointFromDropLayout(mLauncher.getHotseat(), mDragViewVisualCenter); int spanX; int spanY; @@ -1831,11 +1827,7 @@ public class Workspace extends PagedView // We want the point to be mapped to the dragTarget. if (dropTargetLayout != null) { - if (mLauncher.isHotseatLayout(dropTargetLayout)) { - mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); - } else { - mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter); - } + mapPointFromDropLayout(mLauncher.getHotseat(), mDragViewVisualCenter); } boolean droppedOnOriginalCell = false; @@ -2195,7 +2187,7 @@ public class Workspace extends PagedView * Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's * coordinate space. The argument xy is modified with the return result. */ - void mapPointFromSelfToChild(View v, float[] xy) { + private void mapPointFromSelfToChild(View v, float[] xy) { xy[0] = xy[0] - v.getLeft(); xy[1] = xy[1] - v.getTop(); } @@ -2211,14 +2203,23 @@ public class Workspace extends PagedView mTempXY[1] <= hotseat.getBottom(); } - void mapPointFromSelfToHotseatLayout(Hotseat hotseat, float[] xy) { - mTempXY[0] = (int) xy[0]; - mTempXY[1] = (int) xy[1]; - mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempXY, true); - mLauncher.getDragLayer().mapCoordInSelfToDescendant(hotseat.getLayout(), mTempXY); - - xy[0] = mTempXY[0]; - xy[1] = mTempXY[1]; + /** + * Updates the point in {@param xy} to point to the co-ordinate space of {@param layout} + * @param layout either hotseat of a page in workspace + * @param xy the point location in workspace co-ordinate space + */ + private void mapPointFromDropLayout(CellLayout layout, float[] xy) { + if (mLauncher.isHotseatLayout(layout)) { + mTempXY[0] = (int) xy[0]; + mTempXY[1] = (int) xy[1]; + mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempXY, true); + mLauncher.getDragLayer().mapCoordInSelfToDescendant(layout, mTempXY); + + xy[0] = mTempXY[0]; + xy[1] = mTempXY[1]; + } else { + mapPointFromSelfToChild(layout, xy); + } } private boolean isDragWidget(DragObject d) { @@ -2254,11 +2255,7 @@ public class Workspace extends PagedView // Handle the drag over if (mDragTargetLayout != null) { // We want the point to be mapped to the dragTarget. - if (mLauncher.isHotseatLayout(mDragTargetLayout)) { - mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); - } else { - mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter); - } + mapPointFromDropLayout(mLauncher.getHotseat(), mDragViewVisualCenter); int minSpanX = item.spanX; int minSpanY = item.spanY; @@ -2329,7 +2326,7 @@ public class Workspace extends PagedView // Test to see if we are over the hotseat first if (mLauncher.getHotseat() != null && !isDragWidget(d)) { if (isPointInSelfOverHotseat(d.x, d.y)) { - layout = mLauncher.getHotseat().getLayout(); + layout = mLauncher.getHotseat(); } } @@ -2967,8 +2964,7 @@ public class Workspace extends PagedView * Returns a specific CellLayout */ CellLayout getParentCellLayoutForView(View v) { - ArrayList layouts = getWorkspaceAndHotseatCellLayouts(); - for (CellLayout layout : layouts) { + for (CellLayout layout : getWorkspaceAndHotseatCellLayouts()) { if (layout.getShortcutsAndWidgets().indexOfChild(v) > -1) { return layout; } @@ -2977,56 +2973,31 @@ public class Workspace extends PagedView } /** - * Returns a list of all the CellLayouts in the workspace. + * Returns a list of all the CellLayouts on the Homescreen. */ - ArrayList getWorkspaceAndHotseatCellLayouts() { - ArrayList layouts = new ArrayList<>(); + private CellLayout[] getWorkspaceAndHotseatCellLayouts() { int screenCount = getChildCount(); - for (int screen = 0; screen < screenCount; screen++) { - layouts.add(((CellLayout) getChildAt(screen))); - } + final CellLayout[] layouts; if (mLauncher.getHotseat() != null) { - layouts.add(mLauncher.getHotseat().getLayout()); + layouts = new CellLayout[screenCount + 1]; + layouts[screenCount] = mLauncher.getHotseat(); + } else { + layouts = new CellLayout[screenCount]; } - return layouts; - } - - /** - * We should only use this to search for specific children. Do not use this method to modify - * ShortcutsAndWidgetsContainer directly. Includes ShortcutAndWidgetContainers from - * the hotseat and workspace pages - */ - ArrayList getAllShortcutAndWidgetContainers() { - ArrayList childrenLayouts = new ArrayList<>(); - int screenCount = getChildCount(); for (int screen = 0; screen < screenCount; screen++) { - childrenLayouts.add(((CellLayout) getChildAt(screen)).getShortcutsAndWidgets()); + layouts[screen] = (CellLayout) getChildAt(screen); } - if (mLauncher.getHotseat() != null) { - childrenLayouts.add(mLauncher.getHotseat().getLayout().getShortcutsAndWidgets()); - } - return childrenLayouts; + return layouts; } public View getHomescreenIconByItemId(final int id) { - return getFirstMatch(new ItemOperator() { - - @Override - public boolean evaluate(ItemInfo info, View v) { - return info != null && info.id == id; - } - }); + return getFirstMatch((info, v) -> info != null && info.id == id); } public LauncherAppWidgetHostView getWidgetForAppWidgetId(final int appWidgetId) { - return (LauncherAppWidgetHostView) getFirstMatch(new ItemOperator() { - - @Override - public boolean evaluate(ItemInfo info, View v) { - return (info instanceof LauncherAppWidgetInfo) && - ((LauncherAppWidgetInfo) info).appWidgetId == appWidgetId; - } - }); + return (LauncherAppWidgetHostView) getFirstMatch((info, v) -> + (info instanceof LauncherAppWidgetInfo) && + ((LauncherAppWidgetInfo) info).appWidgetId == appWidgetId); } public View getFirstMatch(final ItemOperator operator) { @@ -3063,8 +3034,7 @@ public class Workspace extends PagedView * shortcuts are not removed. */ public void removeItemsByMatcher(final ItemInfoMatcher matcher) { - ArrayList cellLayouts = getWorkspaceAndHotseatCellLayouts(); - for (final CellLayout layoutParent: cellLayouts) { + for (final CellLayout layoutParent: getWorkspaceAndHotseatCellLayouts()) { final ViewGroup layout = layoutParent.getShortcutsAndWidgets(); IntSparseArrayMap idToViewMap = new IntSparseArrayMap<>(); @@ -3122,10 +3092,8 @@ public class Workspace extends PagedView * @param op the operator to map over the shortcuts */ public void mapOverItems(boolean recurse, ItemOperator op) { - ArrayList containers = getAllShortcutAndWidgetContainers(); - final int containerCount = containers.size(); - for (int containerIdx = 0; containerIdx < containerCount; containerIdx++) { - ShortcutAndWidgetContainer container = containers.get(containerIdx); + for (CellLayout layout : getWorkspaceAndHotseatCellLayouts()) { + ShortcutAndWidgetContainer container = layout.getShortcutsAndWidgets(); // map over all the shortcuts on the workspace final int itemCount = container.getChildCount(); for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) { -- cgit v1.2.3