diff options
author | Michael Jurka <mikejurka@google.com> | 2013-05-20 15:49:32 +0200 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2013-08-17 02:35:26 -0700 |
commit | 9f18e8f78ef2772edf94987cfb5129c71e62aac5 (patch) | |
tree | 2df21569651ab63b70eb863e310739fac884e282 /src/com/cyanogenmod | |
parent | 5a0686bd65fcb249be11f1053849013750637e84 (diff) | |
download | android_packages_apps_Trebuchet-9f18e8f78ef2772edf94987cfb5129c71e62aac5.tar.gz android_packages_apps_Trebuchet-9f18e8f78ef2772edf94987cfb5129c71e62aac5.tar.bz2 android_packages_apps_Trebuchet-9f18e8f78ef2772edf94987cfb5129c71e62aac5.zip |
Fixing slow binding when returning to Launcher
Bug: 8978842
Bug: 8660324
Change-Id: Idfa37c05ed299faa465ea66de4b43d30da77ecbc
Diffstat (limited to 'src/com/cyanogenmod')
4 files changed, 119 insertions, 48 deletions
diff --git a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java index 6f6b7bd5f..6596a7933 100755 --- a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java +++ b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java @@ -288,6 +288,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); @@ -570,38 +573,35 @@ 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.getWorkspaceCellCountX() && + 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.getWorkspaceCellCountX() && minSpanY <= LauncherModel.getWorkspaceCellCountY()) { - if (widget.provider != null) { - if (!mHiddenAppsPackages.contains(widget.provider.getPackageName())) { - 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); Intent createLiveFolder = new Intent(LiveFolder.Constants.CREATE_LIVE_FOLDER); List<ResolveInfo> lst = mPackageManager.queryIntentActivities(createLiveFolder, @@ -610,8 +610,29 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen 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 @@ -2138,8 +2159,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public void setApps(ArrayList<ApplicationInfo> list) { mApps = list; filterAppsWithoutInvalidate(); - updatePageCounts(); - invalidateOnDataChange(); + updatePageCountsAndInvalidateData(); } private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { // We add it in place, in alphabetical order @@ -2153,8 +2173,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public void addApps(ArrayList<ApplicationInfo> list) { addAppsWithoutInvalidate(list); filterAppsWithoutInvalidate(); - updatePageCounts(); - invalidateOnDataChange(); + updatePageCountsAndInvalidateData(); } private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) { ComponentName removeComponent = item.intent.getComponent(); @@ -2199,8 +2218,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public void removeApps(ArrayList<String> packageNames) { removeAppsWithPackageNameWithoutInvalidate(packageNames); filterAppsWithoutInvalidate(); - updatePageCounts(); - invalidateOnDataChange(); + updatePageCountsAndInvalidateData(); } public void updateApps(ArrayList<ApplicationInfo> list) { // We remove and re-add the updated applications list because it's properties may have @@ -2209,8 +2227,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen removeAppsWithoutInvalidate(list); addAppsWithoutInvalidate(list); filterAppsWithoutInvalidate(); - updatePageCounts(); - invalidateOnDataChange(); + updatePageCountsAndInvalidateData(); } public void filterAppsWithoutInvalidate() { mFilteredApps = new ArrayList<ApplicationInfo>(mApps); @@ -2232,8 +2249,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } public void filterApps() { filterAppsWithoutInvalidate(); - updatePageCounts(); - invalidateOnDataChange(); + updatePageCountsAndInvalidateData(); } public void reset() { diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java index 7cb807202..9ab911194 100644 --- a/src/com/cyanogenmod/trebuchet/Launcher.java +++ b/src/com/cyanogenmod/trebuchet/Launcher.java @@ -137,6 +137,7 @@ public final class Launcher extends Activity static final boolean PROFILE_STARTUP = false; static final boolean DEBUG_WIDGETS = false; static final boolean DEBUG_STRICT_MODE = false; + static final boolean DEBUG_RESUME_TIME = false; private static final int MENU_GROUP_WALLPAPER = 1; private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1; @@ -432,7 +433,8 @@ public final class Launcher extends Activity // Update customization drawer _after_ restoring the states if (mAppsCustomizeContent != null) { - mAppsCustomizeContent.onPackagesUpdated(); + mAppsCustomizeContent.onPackagesUpdated( + LauncherModel.getSortedWidgetsAndShortcuts(this)); } if (PROFILE_STARTUP) { @@ -807,12 +809,29 @@ public final class Launcher extends Activity mRestoring = false; mOnResumeNeedsLoad = false; } - // We might have postponed some bind calls until onResume (see waitUntilResume) -- - // execute them here - for (int i = 0; i < mOnResumeCallbacks.size(); i++) { - mOnResumeCallbacks.get(i).run(); + if (mOnResumeCallbacks.size() > 0) { + // We might have postponed some bind calls until onResume (see waitUntilResume) -- + // execute them here + long startTimeCallbacks = 0; + if (DEBUG_RESUME_TIME) { + startTimeCallbacks = System.currentTimeMillis(); + } + + if (mAppsCustomizeContent != null) { + mAppsCustomizeContent.setBulkBind(true); + } + for (int i = 0; i < mOnResumeCallbacks.size(); i++) { + mOnResumeCallbacks.get(i).run(); + } + if (mAppsCustomizeContent != null) { + mAppsCustomizeContent.setBulkBind(false); + } + mOnResumeCallbacks.clear(); + if (DEBUG_RESUME_TIME) { + Log.d(TAG, "Time spent processing callbacks in onResume: " + + (System.currentTimeMillis() - startTimeCallbacks)); + } } - mOnResumeCallbacks.clear(); // Reset the pressed state of icons that were locked in the press state while activities // were launching @@ -3666,9 +3685,13 @@ public final class Launcher extends Activity * @return true if we are currently paused. The caller might be able to * skip some work in that case since we will come back again. */ - private boolean waitUntilResume(Runnable run) { + private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { if (mPaused) { Log.i(TAG, "Deferring update until onResume"); + if (deletePreviousRunnables) { + while (mOnResumeCallbacks.remove(run)) { + } + } mOnResumeCallbacks.add(run); return true; } else { @@ -3676,6 +3699,10 @@ public final class Launcher extends Activity } } + private boolean waitUntilResume(Runnable run) { + return waitUntilResume(run, false); + } + /** * If the activity is currently paused, signal that we need to re-run the loader * in onResume. @@ -4140,9 +4167,23 @@ public final class Launcher extends Activity /** * A number of packages were updated. */ - public void bindPackagesUpdated() { + + private ArrayList<Object> mWidgetsAndShortcuts; + private Runnable mBindPackagesUpdatedRunnable = new Runnable() { + public void run() { + bindPackagesUpdated(mWidgetsAndShortcuts); + mWidgetsAndShortcuts = null; + } + }; + + public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { + if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { + mWidgetsAndShortcuts = widgetsAndShortcuts; + return; + } + if (mAppsCustomizeContent != null) { - mAppsCustomizeContent.onPackagesUpdated(); + mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); } } diff --git a/src/com/cyanogenmod/trebuchet/LauncherAppWidgetHost.java b/src/com/cyanogenmod/trebuchet/LauncherAppWidgetHost.java index 2f1639256..530ed318c 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherAppWidgetHost.java +++ b/src/com/cyanogenmod/trebuchet/LauncherAppWidgetHost.java @@ -50,6 +50,6 @@ public class LauncherAppWidgetHost extends AppWidgetHost { protected void onProvidersChanged() { // Once we get the message that widget packages are updated, we need to rebind items // in AppsCustomize accordingly. - mLauncher.bindPackagesUpdated(); + mLauncher.bindPackagesUpdated(LauncherModel.getSortedWidgetsAndShortcuts(mLauncher)); } } diff --git a/src/com/cyanogenmod/trebuchet/LauncherModel.java b/src/com/cyanogenmod/trebuchet/LauncherModel.java index a4308f517..94829242a 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherModel.java +++ b/src/com/cyanogenmod/trebuchet/LauncherModel.java @@ -156,7 +156,7 @@ public class LauncherModel extends BroadcastReceiver { public void bindAppsAdded(ArrayList<ApplicationInfo> apps); public void bindAppsUpdated(ArrayList<ApplicationInfo> apps); public void bindAppsRemoved(ArrayList<String> packageNames, boolean permanent); - public void bindPackagesUpdated(); + public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts); public boolean isAllAppsVisible(); public void bindSearchablesChanged(); public void onPageBoundSynchronously(int page); @@ -2202,18 +2202,32 @@ public class LauncherModel extends BroadcastReceiver { }); } + final ArrayList<Object> widgetsAndShortcuts = + getSortedWidgetsAndShortcuts(context); mHandler.post(new Runnable() { @Override public void run() { Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; - if (callbacks == cb) { - callbacks.bindPackagesUpdated(); + if (callbacks == cb && cb != null) { + callbacks.bindPackagesUpdated(widgetsAndShortcuts); } } }); } } + // Returns a list of ResolveInfos/AppWindowInfos in sorted order + public static ArrayList<Object> getSortedWidgetsAndShortcuts(Context context) { + PackageManager packageManager = context.getPackageManager(); + final ArrayList<Object> widgetsAndShortcuts = new ArrayList<Object>(); + widgetsAndShortcuts.addAll(AppWidgetManager.getInstance(context).getInstalledProviders()); + Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); + widgetsAndShortcuts.addAll(packageManager.queryIntentActivities(shortcutsIntent, 0)); + Collections.sort(widgetsAndShortcuts, + new LauncherModel.WidgetAndShortcutNameComparator(packageManager)); + return widgetsAndShortcuts; + } + /** * This is called from the code that adds shortcuts from the intent receiver. This * doesn't have a Cursor, but |