OSDN Git Service

fix showing wrong image post save
authorJohn Hoford <hoford@google.com>
Fri, 11 Oct 2013 21:51:11 +0000 (14:51 -0700)
committerJohn Hoford <hoford@google.com>
Fri, 11 Oct 2013 23:47:08 +0000 (16:47 -0700)
bug:11174327
bug:11130809
Change-Id: I53ee2f73c5a871d9255fea547a0d93a989f15a4f

src/com/android/gallery3d/filtershow/pipeline/ImageSavingTask.java
src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java
src/com/android/gallery3d/filtershow/tools/SaveImage.java

index a771530..5fa89ac 100644 (file)
@@ -49,6 +49,10 @@ public class ImageSavingTask extends ProcessingTask {
         int current;
     }
 
+    static class UpdatePreviewSaved implements Update {
+        Uri uri;
+    }
+
     static class URIResult implements Result {
         Uri uri;
     }
@@ -84,12 +88,19 @@ public class ImageSavingTask extends ProcessingTask {
         // We create a small bitmap showing the result that we can
         // give to the notification
         UpdateBitmap updateBitmap = new UpdateBitmap();
-        updateBitmap.bitmap = createNotificationBitmap(sourceUri, preset);
+        updateBitmap.bitmap = createNotificationBitmap(previewImage, sourceUri, preset);
         postUpdate(updateBitmap);
         SaveImage saveImage = new SaveImage(mProcessingService, sourceUri,
                 selectedUri, destinationFile, previewImage,
                 new SaveImage.Callback() {
                     @Override
+                    public void onPreviewSaved(Uri uri){
+                        UpdatePreviewSaved previewSaved = new UpdatePreviewSaved();
+                        previewSaved.uri = uri;
+                        postUpdate(previewSaved);
+                    }
+
+                    @Override
                     public void onProgress(int max, int current) {
                         UpdateProgress updateProgress = new UpdateProgress();
                         updateProgress.max = max;
@@ -112,6 +123,10 @@ public class ImageSavingTask extends ProcessingTask {
 
     @Override
     public void onUpdate(Update message) {
+        if (message instanceof UpdatePreviewSaved){
+            Uri uri = ((UpdatePreviewSaved) message).uri;
+            mProcessingService.completePreviewSaveImage(uri);
+        }
         if (message instanceof UpdateBitmap) {
             Bitmap bitmap = ((UpdateBitmap) message).bitmap;
             mProcessingService.updateNotificationWithBitmap(bitmap);
@@ -122,9 +137,13 @@ public class ImageSavingTask extends ProcessingTask {
         }
     }
 
-    private Bitmap createNotificationBitmap(Uri sourceUri, ImagePreset preset) {
+    private Bitmap createNotificationBitmap(Bitmap preview, Uri sourceUri, ImagePreset preset) {
         int notificationBitmapSize = Resources.getSystem().getDimensionPixelSize(
                 android.R.dimen.notification_large_icon_width);
+        if (preview != null) {
+            return Bitmap.createScaledBitmap(preview,
+                    notificationBitmapSize, notificationBitmapSize, true);
+        }
         Bitmap bitmap = ImageLoader.loadConstrainedBitmap(sourceUri, getContext(),
                 notificationBitmapSize, null, true);
         CachingPipeline pipeline = new CachingPipeline(FiltersManager.getManager(), "Thumb");
index c6a4f80..68574bd 100644 (file)
@@ -261,6 +261,12 @@ public class ProcessingService extends Service {
         mNotifyMgr.notify(mNotificationId, mBuilder.build());
     }
 
+    public void completePreviewSaveImage(Uri result) {
+        if (!mNeedsAlive && !mFiltershowActivity.isSimpleEditAction()) {
+            mFiltershowActivity.completeSaveImage(result);
+        }
+    }
+
     public void completeSaveImage(Uri result) {
         if (SHOW_IMAGE) {
             // TODO: we should update the existing image in Gallery instead
index d286958..8425f60 100644 (file)
@@ -63,6 +63,7 @@ public class SaveImage {
      * Callback for updates
      */
     public interface Callback {
+        void onPreviewSaved(Uri uri);
         void onProgress(int max, int current);
     }
 
@@ -381,6 +382,9 @@ public class SaveImage {
                             mDestinationFile, time, !flatten);
                 }
             }
+            if (mCallback != null) {
+                mCallback.onPreviewSaved(savedUri);
+            }
         }
 
         // Stopgap fix for low-memory devices.
@@ -542,9 +546,6 @@ public class SaveImage {
             Toast.makeText(filterShowActivity,
                     toastMessage,
                     Toast.LENGTH_SHORT).show();
-
-            // terminate for now
-            filterShowActivity.completeSaveImage(selectedImageUri);
         }
     }