OSDN Git Service

Move setting wallpaper to a background thread.
authorRuben Brunk <rubenbrunk@google.com>
Fri, 22 Feb 2013 04:13:20 +0000 (20:13 -0800)
committerRuben Brunk <rubenbrunk@google.com>
Fri, 22 Feb 2013 17:50:33 +0000 (09:50 -0800)
Bug: 8088767
Change-Id: I168032418a15f766ac09e18cd12707c7270b07f3

res/values/filtershow_strings.xml
src/com/android/gallery3d/filtershow/FilterShowActivity.java

index 66fb390..a06fc24 100644 (file)
@@ -23,6 +23,8 @@
     <string name="cannot_load_image">Cannot load the image!</string>
     <!--  String displayed when showing the original image [CHAR LIMIT=NONE] -->
     <string name="original_picture_text">@string/original</string>
+    <!--  String displayed when setting the homepage wallpaper in the background [CHAR LIMIT=NONE] -->
+    <string name="setting_wallpaper">Setting wallpaper</string>
 
     <!--  generic strings -->
 
index f7147ea..70e8009 100644 (file)
@@ -71,6 +71,7 @@ import com.android.gallery3d.filtershow.imageshow.ImageZoom;
 import com.android.gallery3d.filtershow.imageshow.MasterImage;
 import com.android.gallery3d.filtershow.presets.ImagePreset;
 import com.android.gallery3d.filtershow.provider.SharedImageProvider;
+import com.android.gallery3d.filtershow.tools.BitmapTask;
 import com.android.gallery3d.filtershow.tools.SaveCopyTask;
 import com.android.gallery3d.filtershow.ui.FilterIconButton;
 import com.android.gallery3d.filtershow.ui.FramedTextButton;
@@ -1090,11 +1091,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
                     mCropExtras.getOutputFormat(), this);
         }
         if (mSaveAsWallpaper) {
-            try {
-                WallpaperManager.getInstance(this).setBitmap(filtered);
-            } catch (IOException e) {
-                Log.w(LOGTAG, "fail to set wall paper", e);
-            }
+            setWallpaperInBackground(filtered);
         }
         if (mReturnAsExtra) {
             if (filtered != null) {
@@ -1117,6 +1114,28 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         }
     }
 
+    void setWallpaperInBackground(final Bitmap bmap) {
+        Toast.makeText(this, R.string.setting_wallpaper, Toast.LENGTH_LONG).show();
+        BitmapTask.Callbacks<FilterShowActivity> cb = new BitmapTask.Callbacks<FilterShowActivity>() {
+            @Override
+            public void onComplete(Bitmap result) {}
+
+            @Override
+            public void onCancel() {}
+
+            @Override
+            public Bitmap onExecute(FilterShowActivity param) {
+                try {
+                    WallpaperManager.getInstance(param).setBitmap(bmap);
+                } catch (IOException e) {
+                    Log.w(LOGTAG, "fail to set wall paper", e);
+                }
+                return null;
+            }
+        };
+        (new BitmapTask<FilterShowActivity>(cb)).execute(this);
+    }
+
     public void done() {
         if (mOutputted) {
             hideSavingProgress();