diff options
Diffstat (limited to 'src/com/android/launcher2/AppsCustomizePagedView.java')
-rw-r--r-- | src/com/android/launcher2/AppsCustomizePagedView.java | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index 901b661db..95ce33752 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -240,6 +240,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen WidgetPreviewLoader mWidgetPreviewLoader; + private boolean mInBulkBind; + private boolean mNeedToUpdatePageCountsAndInvalidateData; + public AppsCustomizePagedView(Context context, AttributeSet attrs) { super(context, attrs); mLayoutInflater = LayoutInflater.from(context); @@ -440,38 +443,57 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen super.onMeasure(widthMeasureSpec, heightMeasureSpec); } - public void onPackagesUpdated() { + public void onPackagesUpdated(ArrayList<Object> widgetsAndShortcuts) { // Get the list of widgets and shortcuts mWidgets.clear(); - List<AppWidgetProviderInfo> widgets = - AppWidgetManager.getInstance(mLauncher).getInstalledProviders(); - Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); - List<ResolveInfo> shortcuts = mPackageManager.queryIntentActivities(shortcutsIntent, 0); - for (AppWidgetProviderInfo widget : widgets) { - widget.label = widget.label.trim(); - if (widget.minWidth > 0 && widget.minHeight > 0) { - // Ensure that all widgets we show can be added on a workspace of this size - int[] spanXY = Launcher.getSpanForWidget(mLauncher, widget); - int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, widget); - int minSpanX = Math.min(spanXY[0], minSpanXY[0]); - int minSpanY = Math.min(spanXY[1], minSpanXY[1]); - if (minSpanX <= LauncherModel.getCellCountX() && + for (Object o : widgetsAndShortcuts) { + if (o instanceof AppWidgetProviderInfo) { + AppWidgetProviderInfo widget = (AppWidgetProviderInfo) o; + widget.label = widget.label.trim(); + if (widget.minWidth > 0 && widget.minHeight > 0) { + // Ensure that all widgets we show can be added on a workspace of this size + int[] spanXY = Launcher.getSpanForWidget(mLauncher, widget); + int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, widget); + int minSpanX = Math.min(spanXY[0], minSpanXY[0]); + int minSpanY = Math.min(spanXY[1], minSpanXY[1]); + if (minSpanX <= LauncherModel.getCellCountX() && minSpanY <= LauncherModel.getCellCountY()) { - mWidgets.add(widget); + mWidgets.add(widget); + } else { + Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" + + widget.minWidth + ", " + widget.minHeight + ")"); + } } else { - Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" + - widget.minWidth + ", " + widget.minHeight + ")"); + Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" + + widget.minWidth + ", " + widget.minHeight + ")"); } } else { - Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" + - widget.minWidth + ", " + widget.minHeight + ")"); + // just add shortcuts + mWidgets.add(o); + } + } + updatePageCountsAndInvalidateData(); + } + + public void setBulkBind(boolean bulkBind) { + if (bulkBind) { + mInBulkBind = true; + } else { + mInBulkBind = false; + if (mNeedToUpdatePageCountsAndInvalidateData) { + updatePageCountsAndInvalidateData(); } } - mWidgets.addAll(shortcuts); - Collections.sort(mWidgets, - new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager)); - updatePageCounts(); - invalidateOnDataChange(); + } + + private void updatePageCountsAndInvalidateData() { + if (mInBulkBind) { + mNeedToUpdatePageCountsAndInvalidateData = true; + } else { + updatePageCounts(); + invalidateOnDataChange(); + mNeedToUpdatePageCountsAndInvalidateData = false; + } } @Override @@ -1526,8 +1548,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public void setApps(ArrayList<ApplicationInfo> list) { mApps = list; Collections.sort(mApps, LauncherModel.getAppNameComparator()); - updatePageCounts(); - invalidateOnDataChange(); + updatePageCountsAndInvalidateData(); } private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { // We add it in place, in alphabetical order @@ -1542,8 +1563,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } public void addApps(ArrayList<ApplicationInfo> list) { addAppsWithoutInvalidate(list); - updatePageCounts(); - invalidateOnDataChange(); + updatePageCountsAndInvalidateData(); } private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) { ComponentName removeComponent = item.intent.getComponent(); @@ -1569,8 +1589,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } public void removeApps(ArrayList<ApplicationInfo> appInfos) { removeAppsWithoutInvalidate(appInfos); - updatePageCounts(); - invalidateOnDataChange(); + updatePageCountsAndInvalidateData(); } public void updateApps(ArrayList<ApplicationInfo> list) { // We remove and re-add the updated applications list because it's properties may have @@ -1578,8 +1597,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // place in the list. removeAppsWithoutInvalidate(list); addAppsWithoutInvalidate(list); - updatePageCounts(); - invalidateOnDataChange(); + updatePageCountsAndInvalidateData(); } public void reset() { |