Start listening again after LauncherProvider clears widgets.

After the LauncherProvider resets the database and wipes
out the host info, the Launcher must tell the AppWidgetHost
to listen again.

Originally 87e688d8... in packages/apps/Launcher.

Fixes http://b/2238470
This commit is contained in:
Jeff Sharkey
2009-11-06 15:17:59 -08:00
parent 386d8871dc
commit 1e2efc8a6d
+36 -1
View File
@@ -26,6 +26,7 @@ import android.app.WallpaperInfo;
import android.app.WallpaperManager; import android.app.WallpaperManager;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@@ -36,9 +37,11 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable; import android.os.Parcelable;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
@@ -151,6 +154,8 @@ public final class Launcher extends Activity
private static final Object sLock = new Object(); private static final Object sLock = new Object();
private static int sScreen = DEFAULT_SCREEN; private static int sScreen = DEFAULT_SCREEN;
private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
private LayoutInflater mInflater; private LayoutInflater mInflater;
private DragController mDragController; private DragController mDragController;
@@ -200,7 +205,6 @@ public final class Launcher extends Activity
mInflater = getLayoutInflater(); mInflater = getLayoutInflater();
mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetManager = AppWidgetManager.getInstance(this);
mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
mAppWidgetHost.startListening(); mAppWidgetHost.startListening();
@@ -214,6 +218,8 @@ public final class Launcher extends Activity
setContentView(R.layout.launcher); setContentView(R.layout.launcher);
setupViews(); setupViews();
registerContentObservers();
lockAllApps(); lockAllApps();
mSavedState = savedInstanceState; mSavedState = savedInstanceState;
@@ -903,6 +909,8 @@ public final class Launcher extends Activity
unbindDesktopItems(); unbindDesktopItems();
AppInfoCache.unbindDrawables(); AppInfoCache.unbindDrawables();
getContentResolver().unregisterContentObserver(mWidgetObserver);
} }
@Override @Override
@@ -1269,6 +1277,12 @@ public final class Launcher extends Activity
startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
} }
private void registerContentObservers() {
ContentResolver resolver = getContentResolver();
resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
true, mWidgetObserver);
}
@Override @Override
public boolean dispatchKeyEvent(KeyEvent event) { public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getAction() == KeyEvent.ACTION_DOWN) {
@@ -1318,6 +1332,13 @@ public final class Launcher extends Activity
folder.onClose(); folder.onClose();
} }
/**
* Re-listen when widgets are reset.
*/
private void onAppWidgetReset() {
mAppWidgetHost.startListening();
}
/** /**
* Go through the and disconnect any of the callbacks in the drawables and the views or we * Go through the and disconnect any of the callbacks in the drawables and the views or we
* leak the previous Home screen on orientation change. * leak the previous Home screen on orientation change.
@@ -1763,6 +1784,20 @@ public final class Launcher extends Activity
} }
} }
/**
* Receives notifications whenever the appwidgets are reset.
*/
private class AppWidgetResetObserver extends ContentObserver {
public AppWidgetResetObserver() {
super(new Handler());
}
@Override
public void onChange(boolean selfChange) {
onAppWidgetReset();
}
}
/** /**
* Implementation of the method from LauncherModel.Callbacks. * Implementation of the method from LauncherModel.Callbacks.
*/ */