diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2016-11-22 16:52:39 +0530 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2016-12-07 13:16:08 -0800 |
commit | d5462aa31b53eb690a3f57c7c6c0cc4021271de6 (patch) | |
tree | 63d1162421f45d222ca89e2f41fefcedecf2f6bb /src/com/android/launcher3/Launcher.java | |
parent | 4633be64e863a96c63f814a2386b23b02d43910b (diff) | |
download | android_packages_apps_Trebuchet-d5462aa31b53eb690a3f57c7c6c0cc4021271de6.tar.gz android_packages_apps_Trebuchet-d5462aa31b53eb690a3f57c7c6c0cc4021271de6.tar.bz2 android_packages_apps_Trebuchet-d5462aa31b53eb690a3f57c7c6c0cc4021271de6.zip |
Simplifyling widget inflation and addition flow.
> Removing insert parameter used to select the index of the view.
ShortcutAndWidgetContainer no longet relies on the index and instead
uses x and y to refer a particulat view.
> Creating helper methods to easily insert the icon by passing ItemInfo
directly. LauncherModel.addItemToDatabase synchronously updates the
ItemInfo with proper postion information. So we can directly use the
info instead of passing each parameter separately.
Bug: 32904959
Change-Id: I021c1b818f2f42604b95a6970e06aacc7211292a
Diffstat (limited to 'src/com/android/launcher3/Launcher.java')
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 9160a012e..8cc0fca96 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) { |