am 8424adf5: am 1e2efc8a: Start listening again after LauncherProvider clears widgets.
Merge commit '8424adf5e3096c2ad3fd064f0df6ce97a0709944' into eclair-mr2-plus-aosp
* commit '8424adf5e3096c2ad3fd064f0df6ce97a0709944':
Start listening again after LauncherProvider clears widgets.
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 2c59b4c..be1ee67 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -26,6 +26,7 @@
import android.app.WallpaperManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -36,9 +37,11 @@
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.os.Handler;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -151,6 +154,8 @@
private static final Object sLock = new Object();
private static int sScreen = DEFAULT_SCREEN;
+ private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
+
private LayoutInflater mInflater;
private DragController mDragController;
@@ -200,7 +205,6 @@
mInflater = getLayoutInflater();
mAppWidgetManager = AppWidgetManager.getInstance(this);
-
mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
mAppWidgetHost.startListening();
@@ -214,6 +218,8 @@
setContentView(R.layout.launcher);
setupViews();
+ registerContentObservers();
+
lockAllApps();
mSavedState = savedInstanceState;
@@ -903,6 +909,8 @@
unbindDesktopItems();
AppInfoCache.unbindDrawables();
+
+ getContentResolver().unregisterContentObserver(mWidgetObserver);
}
@Override
@@ -1269,6 +1277,12 @@
startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
}
+ private void registerContentObservers() {
+ ContentResolver resolver = getContentResolver();
+ resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
+ true, mWidgetObserver);
+ }
+
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
@@ -1319,6 +1333,13 @@
}
/**
+ * 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
* leak the previous Home screen on orientation change.
*/
@@ -1764,6 +1785,20 @@
}
/**
+ * 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.
*/
public int getCurrentWorkspaceScreen() {