diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2016-12-08 00:46:10 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-12-08 00:46:10 +0000 |
commit | 621e2006473899c2047d66e3ef4b49c6d0db5a13 (patch) | |
tree | 80fe0a5265f2cdf0f5187101753837fb43f80807 | |
parent | b4a192b5dacd7cf327032d01443665a5e6124182 (diff) | |
parent | d5462aa31b53eb690a3f57c7c6c0cc4021271de6 (diff) | |
download | android_packages_apps_Trebuchet-621e2006473899c2047d66e3ef4b49c6d0db5a13.tar.gz android_packages_apps_Trebuchet-621e2006473899c2047d66e3ef4b49c6d0db5a13.tar.bz2 android_packages_apps_Trebuchet-621e2006473899c2047d66e3ef4b49c6d0db5a13.zip |
Merge "Simplifyling widget inflation and addition flow." into ub-launcher3-master
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 49 | ||||
-rw-r--r-- | src/com/android/launcher3/PendingAppWidgetHostView.java | 8 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 60 | ||||
-rw-r--r-- | src/com/android/launcher3/folder/Folder.java | 3 |
4 files changed, 50 insertions, 70 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 887a8bd2d..2f7a31f34 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1470,9 +1470,7 @@ public class Launcher extends Activity } LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]); - - mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, - isWorkspaceLocked()); + mWorkspace.addInScreen(view, info); } /** @@ -1507,20 +1505,15 @@ public class Launcher extends Activity hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); } hostView.setVisibility(View.VISIBLE); - addAppWidgetToWorkspace(hostView, launcherInfo, appWidgetInfo, isWorkspaceLocked()); + prepareAppWidget(hostView, launcherInfo); + mWorkspace.addInScreen(hostView, launcherInfo); } - private void addAppWidgetToWorkspace( - AppWidgetHostView hostView, LauncherAppWidgetInfo item, - LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) { + private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) { hostView.setTag(item); item.onBindAppWidget(this, hostView); - hostView.setFocusable(true); hostView.setOnFocusChangeListener(mFocusHandler); - - mWorkspace.addInScreen(hostView, item.container, item.screenId, - item.cellX, item.cellY, item.spanX, item.spanY, insert); } private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @@ -2105,8 +2098,7 @@ public class Launcher extends Activity // Create the view FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); - mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, - isWorkspaceLocked()); + mWorkspace.addInScreen(newFolder, folderInfo); // Force measure the new folder icon CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); parent.getShortcutsAndWidgets().measureChild(newFolder); @@ -3365,8 +3357,7 @@ public class Launcher extends Activity } } } - workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX, - item.cellY, 1, 1); + workspace.addInScreenFromBind(view, item); if (animateIcons) { // Animate all the applications up now view.setAlpha(0f); @@ -3408,15 +3399,6 @@ public class Launcher extends Activity workspace.requestLayout(); } - private void bindSafeModeWidget(LauncherAppWidgetInfo item) { - PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, true); - view.updateIcon(mIconCache); - view.updateAppWidget(null); - view.setOnClickListener(this); - addAppWidgetToWorkspace(view, item, null, false); - mWorkspace.requestLayout(); - } - /** * Add the views for a widget to the workspace. * @@ -3433,7 +3415,11 @@ public class Launcher extends Activity } if (mIsSafeModeEnabled) { - bindSafeModeWidget(item); + PendingAppWidgetHostView view = + new PendingAppWidgetHostView(this, item, mIconCache, true); + prepareAppWidget(view, item); + mWorkspace.addInScreen(view, item); + mWorkspace.requestLayout(); return; } @@ -3521,6 +3507,7 @@ public class Launcher extends Activity } } + final AppWidgetHostView view; if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " @@ -3536,16 +3523,12 @@ public class Launcher extends Activity item.minSpanX = appWidgetInfo.minSpanX; item.minSpanY = appWidgetInfo.minSpanY; - addAppWidgetToWorkspace( - mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo), - item, appWidgetInfo, false); + view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo); } else { - PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, false); - view.updateIcon(mIconCache); - view.updateAppWidget(null); - view.setOnClickListener(this); - addAppWidgetToWorkspace(view, item, null, false); + view = new PendingAppWidgetHostView(this, item, mIconCache, false); } + prepareAppWidget(view, item); + mWorkspace.addInScreen(view, item); mWorkspace.requestLayout(); if (DEBUG_WIDGETS) { diff --git a/src/com/android/launcher3/PendingAppWidgetHostView.java b/src/com/android/launcher3/PendingAppWidgetHostView.java index 7c9b76bdf..7c92f80f0 100644 --- a/src/com/android/launcher3/PendingAppWidgetHostView.java +++ b/src/com/android/launcher3/PendingAppWidgetHostView.java @@ -65,7 +65,7 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen @TargetApi(Build.VERSION_CODES.LOLLIPOP) public PendingAppWidgetHostView(Context context, LauncherAppWidgetInfo info, - boolean disabledForSafeMode) { + IconCache cache, boolean disabledForSafeMode) { super(new ContextThemeWrapper(context, R.style.WidgetContainerTheme)); mLauncher = Launcher.getLauncher(context); @@ -84,6 +84,10 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen if (Utilities.ATLEAST_LOLLIPOP) { setElevation(getResources().getDimension(R.dimen.pending_widget_elevation)); } + + updateIcon(cache); + updateAppWidget(null); + setOnClickListener(mLauncher); } @Override @@ -119,7 +123,7 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen mDrawableSizeChanged = true; } - public void updateIcon(IconCache cache) { + private void updateIcon(IconCache cache) { Bitmap icon = cache.getIcon(mIconLookupIntent, mInfo.user); if (mIcon == icon) { return; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index bd2141239..54d9b2ea1 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1043,23 +1043,28 @@ public class Workspace extends PagedView } } - // See implementation for parameter definition. - void addInScreen(View child, long container, long screenId, - int x, int y, int spanX, int spanY) { - addInScreen(child, container, screenId, x, y, spanX, spanY, false, false); - } - - // At bind time, we use the rank (screenId) to compute x and y for hotseat items. - // See implementation for parameter definition. - public void addInScreenFromBind(View child, long container, long screenId, int x, int y, - int spanX, int spanY) { - addInScreen(child, container, screenId, x, y, spanX, spanY, false, true); + /** + * At bind time, we use the rank (screenId) to compute x and y for hotseat items. + * See {@link #addInScreen}. + */ + public void addInScreenFromBind(View child, ItemInfo info) { + int x = info.cellX; + int y = info.cellY; + if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + int screenId = (int) info.screenId; + x = mLauncher.getHotseat().getCellXFromOrder(screenId); + y = mLauncher.getHotseat().getCellYFromOrder(screenId); + } + addInScreen(child, info.container, info.screenId, x, y, info.spanX, info.spanY); } - // See implementation for parameter definition. - void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, - boolean insert) { - addInScreen(child, container, screenId, x, y, spanX, spanY, insert, false); + /** + * Adds the specified child in the specified screen based on the {@param info} + * See {@link #addInScreen}. + */ + public void addInScreen(View child, ItemInfo info) { + addInScreen(child, info.container, info.screenId, info.cellX, info.cellY, + info.spanX, info.spanY); } /** @@ -1072,13 +1077,9 @@ public class Workspace extends PagedView * @param y The Y position of the child in the screen's grid. * @param spanX The number of cells spanned horizontally by the child. * @param spanY The number of cells spanned vertically by the child. - * @param insert When true, the child is inserted at the beginning of the children list. - * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute - * the x and y position in which to place hotseat items. Otherwise - * we use the x and y position to compute the rank. */ - void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, - boolean insert, boolean computeXYFromRank) { + private void addInScreen(View child, long container, long screenId, int x, int y, + int spanX, int spanY) { if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { if (getScreenWithId(screenId) == null) { Log.e(TAG, "Skipping child, screenId " + screenId + " not found"); @@ -1101,13 +1102,6 @@ public class Workspace extends PagedView if (child instanceof FolderIcon) { ((FolderIcon) child).setTextVisible(false); } - - if (computeXYFromRank) { - x = mLauncher.getHotseat().getCellXFromOrder((int) screenId); - y = mLauncher.getHotseat().getCellYFromOrder((int) screenId); - } else { - screenId = mLauncher.getHotseat().getOrderInHotseat(x, y); - } } else { // Show folder title if not in the hotseat if (child instanceof FolderIcon) { @@ -1138,7 +1132,7 @@ public class Workspace extends PagedView int childId = mLauncher.getViewIdForItem(info); boolean markCellsAsOccupied = !(child instanceof Folder); - if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) { + if (!layout.addViewToCellLayout(child, -1, childId, lp, markCellsAsOccupied)) { // TODO: This branch occurs when the workspace is adding views // outside of the defined grid // maybe we should be deleting these items from the LauncherModel? @@ -2519,7 +2513,7 @@ public class Workspace extends PagedView if (d.dragSource != this) { final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1] }; - onDropExternal(touchXY, d.dragInfo, dropTargetLayout, false, d); + onDropExternal(touchXY, d.dragInfo, dropTargetLayout, d); } else if (mDragInfo != null) { final View cell = mDragInfo.cell; boolean droppedOnOriginalCellDuringTransition = false; @@ -3265,7 +3259,7 @@ public class Workspace extends PagedView * to add an item to one of the workspace screens. */ private void onDropExternal(final int[] touchXY, final ItemInfo dragInfo, - final CellLayout cellLayout, boolean insertAtFirst, DragObject d) { + final CellLayout cellLayout, DragObject d) { final Runnable exitSpringLoadedRunnable = new Runnable() { @Override public void run() { @@ -3415,8 +3409,8 @@ public class Workspace extends PagedView LauncherModel.addOrMoveItemInDatabase(mLauncher, info, container, screenId, mTargetCell[0], mTargetCell[1]); - addInScreen(view, container, screenId, mTargetCell[0], mTargetCell[1], info.spanX, - info.spanY, insertAtFirst); + addInScreen(view, container, screenId, mTargetCell[0], mTargetCell[1], + info.spanX, info.spanY); cellLayout.onDropChild(view); cellLayout.getShortcutsAndWidgets().measureChild(view); diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index e813bb450..a81b4caba 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -1225,8 +1225,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC // We add the child after removing the folder to prevent both from existing // at the same time in the CellLayout. We need to add the new item with // addInScreenFromBind() to ensure that hotseat items are placed correctly. - mLauncher.getWorkspace().addInScreenFromBind(newIcon, mInfo.container, - mInfo.screenId, mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY); + mLauncher.getWorkspace().addInScreenFromBind(newIcon, mInfo); // Focus the newly created child newIcon.requestFocus(); |