From 860eccdfd57bc0bc762f3e45147dafc1dfdbb915 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Sun, 8 Nov 2009 18:23:36 -0800 Subject: Fix bug where the preview wasn't starting because using an unknown window token. --- .../wallpaper/livepicker/LiveWallpaperPreview.java | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/com') diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java index 374f5ec..7cd446f 100644 --- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java +++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java @@ -48,6 +48,7 @@ public class LiveWallpaperPreview extends Activity { private String mSettings; private String mPackageName; private Intent mWallpaperIntent; + private View mView; static void showPreview(Activity activity, int code, Intent intent, WallpaperInfo info) { Intent preview = new Intent(activity, LiveWallpaperPreview.class); @@ -69,19 +70,17 @@ public class LiveWallpaperPreview extends Activity { } setContentView(R.layout.live_wallpaper_preview); + mView = findViewById(R.id.configure); mSettings = extras.getString(EXTRA_LIVE_WALLPAPER_SETTINGS); mPackageName = extras.getString(EXTRA_LIVE_WALLPAPER_PACKAGE); if (mSettings == null) { - findViewById(R.id.configure).setVisibility(View.GONE); + mView.setVisibility(View.GONE); } mWallpaperManager = WallpaperManager.getInstance(this); - WallpaperConnection connection = new WallpaperConnection(mWallpaperIntent); - if (connection.connect()) { - mWallpaperConnection = connection; - } + mWallpaperConnection = new WallpaperConnection(mWallpaperIntent); } public void setLiveWallpaper(View v) { @@ -129,7 +128,15 @@ public class LiveWallpaperPreview extends Activity { } } } - + + @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + if (!mWallpaperConnection.connect()) { + mWallpaperConnection = null; + } + } + @Override public void onDetachedFromWindow() { super.onDetachedFromWindow(); @@ -180,10 +187,11 @@ public class LiveWallpaperPreview extends Activity { if (mWallpaperConnection == this) { mService = IWallpaperService.Stub.asInterface(service); try { - final View view = getWindow().getDecorView().getRootView(); + final View view = mView; + final View root = view.getRootView(); mService.attach(this, view.getWindowToken(), WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA, - true, view.getWidth(), view.getHeight()); + true, root.getWidth(), view.getHeight()); } catch (RemoteException e) { Log.w(LOG_TAG, "Failed attaching wallpaper; clearing", e); } -- cgit v1.2.3