AI 143187: am: CL 142933 Fixes #1725672. Rebind the drawer's content early to avoid the dreaded "blank drawer" bug.

Original author: romainguy
  Merged from: //branches/cupcake/...

Automated import of CL 143187
This commit is contained in:
Romain Guy 2009-03-27 16:58:13 -07:00 committed by The Android Open Source Project
parent 340be220fb
commit 829f56a020
2 changed files with 13 additions and 25 deletions

View File

@ -1237,6 +1237,8 @@ public final class Launcher extends Activity implements View.OnClickListener, On
return; return;
} }
mAllAppsGrid.setAdapter(drawerAdapter);
final Workspace workspace = mWorkspace; final Workspace workspace = mWorkspace;
int count = workspace.getChildCount(); int count = workspace.getChildCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@ -1260,7 +1262,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mBinder.mTerminate = true; mBinder.mTerminate = true;
} }
mBinder = new DesktopBinder(this, shortcuts, appWidgets, drawerAdapter); mBinder = new DesktopBinder(this, shortcuts, appWidgets);
mBinder.startBindingItems(); mBinder.startBindingItems();
} }
@ -1314,7 +1316,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
if (end >= count) { if (end >= count) {
finishBindDesktopItems(); finishBindDesktopItems();
binder.startBindingDrawer(); binder.startBindingAppWidgetsWhenIdle();
} else { } else {
binder.obtainMessage(DesktopBinder.MESSAGE_BIND_ITEMS, i, count).sendToTarget(); binder.obtainMessage(DesktopBinder.MESSAGE_BIND_ITEMS, i, count).sendToTarget();
} }
@ -1361,12 +1363,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mDrawer.unlock(); mDrawer.unlock();
} }
private void bindDrawer(Launcher.DesktopBinder binder,
ApplicationsAdapter drawerAdapter) {
mAllAppsGrid.setAdapter(drawerAdapter);
binder.startBindingAppWidgetsWhenIdle();
}
private void bindAppWidgets(Launcher.DesktopBinder binder, private void bindAppWidgets(Launcher.DesktopBinder binder,
LinkedList<LauncherAppWidgetInfo> appWidgets) { LinkedList<LauncherAppWidgetInfo> appWidgets) {
@ -1377,10 +1373,14 @@ public final class Launcher extends Activity implements View.OnClickListener, On
final LauncherAppWidgetInfo item = appWidgets.removeFirst(); final LauncherAppWidgetInfo item = appWidgets.removeFirst();
final int appWidgetId = item.appWidgetId; final int appWidgetId = item.appWidgetId;
final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); final AppWidgetProviderInfo appWidgetInfo =
mAppWidgetManager.getAppWidgetInfo(appWidgetId);
item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
if (LOGD) d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s", appWidgetId, appWidgetInfo)); if (LOGD) {
d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s",
appWidgetId, appWidgetInfo));
}
item.hostView.setAppWidget(appWidgetId, appWidgetInfo); item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
item.hostView.setTag(item); item.hostView.setTag(item);
@ -1968,25 +1968,21 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private static class DesktopBinder extends Handler implements MessageQueue.IdleHandler { private static class DesktopBinder extends Handler implements MessageQueue.IdleHandler {
static final int MESSAGE_BIND_ITEMS = 0x1; static final int MESSAGE_BIND_ITEMS = 0x1;
static final int MESSAGE_BIND_APPWIDGETS = 0x2; static final int MESSAGE_BIND_APPWIDGETS = 0x2;
static final int MESSAGE_BIND_DRAWER = 0x3;
// Number of items to bind in every pass // Number of items to bind in every pass
static final int ITEMS_COUNT = 6; static final int ITEMS_COUNT = 6;
private final ArrayList<ItemInfo> mShortcuts; private final ArrayList<ItemInfo> mShortcuts;
private final LinkedList<LauncherAppWidgetInfo> mAppWidgets; private final LinkedList<LauncherAppWidgetInfo> mAppWidgets;
private final ApplicationsAdapter mDrawerAdapter;
private final WeakReference<Launcher> mLauncher; private final WeakReference<Launcher> mLauncher;
public boolean mTerminate = false; public volatile boolean mTerminate = false;
DesktopBinder(Launcher launcher, ArrayList<ItemInfo> shortcuts, DesktopBinder(Launcher launcher, ArrayList<ItemInfo> shortcuts,
ArrayList<LauncherAppWidgetInfo> appWidgets, ArrayList<LauncherAppWidgetInfo> appWidgets) {
ApplicationsAdapter drawerAdapter) {
mLauncher = new WeakReference<Launcher>(launcher); mLauncher = new WeakReference<Launcher>(launcher);
mShortcuts = shortcuts; mShortcuts = shortcuts;
mDrawerAdapter = drawerAdapter;
// Sort widgets so active workspace is bound first // Sort widgets so active workspace is bound first
final int currentScreen = launcher.mWorkspace.getCurrentScreen(); final int currentScreen = launcher.mWorkspace.getCurrentScreen();
@ -2007,10 +2003,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
obtainMessage(MESSAGE_BIND_ITEMS, 0, mShortcuts.size()).sendToTarget(); obtainMessage(MESSAGE_BIND_ITEMS, 0, mShortcuts.size()).sendToTarget();
} }
public void startBindingDrawer() {
obtainMessage(MESSAGE_BIND_DRAWER).sendToTarget();
}
public void startBindingAppWidgetsWhenIdle() { public void startBindingAppWidgetsWhenIdle() {
// Ask for notification when message queue becomes idle // Ask for notification when message queue becomes idle
final MessageQueue messageQueue = Looper.myQueue(); final MessageQueue messageQueue = Looper.myQueue();
@ -2039,10 +2031,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
launcher.bindItems(this, mShortcuts, msg.arg1, msg.arg2); launcher.bindItems(this, mShortcuts, msg.arg1, msg.arg2);
break; break;
} }
case MESSAGE_BIND_DRAWER: {
launcher.bindDrawer(this, mDrawerAdapter);
break;
}
case MESSAGE_BIND_APPWIDGETS: { case MESSAGE_BIND_APPWIDGETS: {
launcher.bindAppWidgets(this, mAppWidgets); launcher.bindAppWidgets(this, mAppWidgets);
break; break;

View File

@ -47,7 +47,7 @@ import java.net.URISyntaxException;
* for the Launcher. * for the Launcher.
*/ */
public class LauncherModel { public class LauncherModel {
static final boolean DEBUG_LOADERS = false; static final boolean DEBUG_LOADERS = true;
static final String LOG_TAG = "HomeLoaders"; static final String LOG_TAG = "HomeLoaders";
private static final int UI_NOTIFICATION_RATE = 4; private static final int UI_NOTIFICATION_RATE = 4;