Fixing slow binding when returning to Launcher
Bug: 8978842 Bug: 8660324 Change-Id: Idfa37c05ed299faa465ea66de4b43d30da77ecbc
This commit is contained in:
1 parent
447bf84d24
commit
c402cd9992
4 files changed
+112
-56
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
mWidgets.addAll(shortcuts);
|
||||
Collections.sort(mWidgets,
|
||||
new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager));
|
||||
updatePageCounts();
|
||||
invalidateOnDataChange();
|
||||
updatePageCountsAndInvalidateData();
|
||||
}
|
||||
|
||||
public void setBulkBind(boolean bulkBind) {
|
||||
if (bulkBind) {
|
||||
mInBulkBind = true;
|
||||
} else {
|
||||
mInBulkBind = false;
|
||||
if (mNeedToUpdatePageCountsAndInvalidateData) {
|
||||
updatePageCountsAndInvalidateData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
Reference in new issue
Block a user