OSDN Git Service

fix export on saved images
authorJohn Hoford <hoford@google.com>
Mon, 9 Sep 2013 20:04:54 +0000 (13:04 -0700)
committerJohn Hoford <hoford@google.com>
Mon, 9 Sep 2013 22:25:36 +0000 (15:25 -0700)
bug:9466453
Change-Id: I6280e6352d6c7f672692db514e46803df3f91b38

src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java
src/com/android/gallery3d/filtershow/pipeline/ImageSavingTask.java
src/com/android/gallery3d/filtershow/tools/SaveImage.java
src/com/android/gallery3d/filtershow/ui/ExportDialog.java

index b57723a..1876f25 100644 (file)
@@ -181,6 +181,16 @@ public class ImagePreset {
         return false;
     }
 
+    public boolean contains(byte type) {
+        for (FilterRepresentation representation : mFilters) {
+            if (representation.getFilterType() == type
+                    && !representation.isNil()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     public boolean isPanoramaSafe() {
         for (FilterRepresentation representation : mFilters) {
             if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY
index 5c416bc..a771530 100644 (file)
@@ -97,7 +97,7 @@ public class ImageSavingTask extends ProcessingTask {
                         postUpdate(updateProgress);
                     }
                 });
-        Uri uri = saveImage.processAndSaveImage(preset, !flatten,
+        Uri uri = saveImage.processAndSaveImage(preset, flatten,
                 request.quality, request.sizeFactor);
         URIResult result = new URIResult();
         result.uri = uri;
index 51dddfd..8c0d1ec 100644 (file)
@@ -35,6 +35,7 @@ import com.android.gallery3d.common.Utils;
 import com.android.gallery3d.exif.ExifInterface;
 import com.android.gallery3d.filtershow.FilterShowActivity;
 import com.android.gallery3d.filtershow.cache.ImageLoader;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
 import com.android.gallery3d.filtershow.filters.FiltersManager;
 import com.android.gallery3d.filtershow.imageshow.MasterImage;
 import com.android.gallery3d.filtershow.pipeline.CachingPipeline;
@@ -314,10 +315,20 @@ public class SaveImage {
         }
     }
 
-    public Uri processAndSaveImage(ImagePreset preset, boolean doAuxBackup,
+    private void updateExifData(ExifInterface exif, long time) {
+        // Set tags
+        exif.addDateTimeStampTag(ExifInterface.TAG_DATE_TIME, time,
+                TimeZone.getDefault());
+        exif.setTag(exif.buildTag(ExifInterface.TAG_ORIENTATION,
+                ExifInterface.Orientation.TOP_LEFT));
+        // Remove old thumbnail
+        exif.removeCompressedThumbnail();
+    }
+
+    public Uri processAndSaveImage(ImagePreset preset, boolean flatten,
                                    int quality, float sizeFactor) {
 
-        Uri uri = resetToOriginalImageIfNeeded(preset, doAuxBackup);
+        Uri uri = resetToOriginalImageIfNeeded(preset, !flatten);
         if (uri != null) {
             return null;
         }
@@ -332,33 +343,44 @@ public class SaveImage {
         // newSourceUri is then pointing to the new location.
         // If no file is moved, newSourceUri will be the same as mSourceUri.
         Uri newSourceUri = mSourceUri;
-        if (doAuxBackup) {
+        if (!flatten) {
             newSourceUri = moveSrcToAuxIfNeeded(mSourceUri, mDestinationFile);
         }
 
         Uri savedUri = mSelectedImageUri;
         if (mPreviewImage != null) {
-            Object xmp = getPanoramaXMPData(newSourceUri, preset);
-            ExifInterface exif = getExifData(newSourceUri);
-            // Set tags
-            long time = System.currentTimeMillis();
-            exif.addDateTimeStampTag(ExifInterface.TAG_DATE_TIME, time,
-                    TimeZone.getDefault());
-            exif.setTag(exif.buildTag(ExifInterface.TAG_ORIENTATION,
-                    ExifInterface.Orientation.TOP_LEFT));
-            // Remove old thumbnail
-            exif.removeCompressedThumbnail();
-            // If we succeed in writing the bitmap as a jpeg, return a uri.
-            if (putExifData(mDestinationFile, exif, mPreviewImage, quality)) {
-                putPanoramaXMPData(mDestinationFile, xmp);
-                // mDestinationFile will save the newSourceUri info in the XMP.
-                XmpPresets.writeFilterXMP(mContext, newSourceUri,
-                        mDestinationFile, preset);
-
-                // After this call, mSelectedImageUri will be actually
-                // pointing at the new file mDestinationFile.
-                savedUri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri,
-                        mDestinationFile, time, doAuxBackup);
+            if (flatten) {
+                Object xmp = getPanoramaXMPData(newSourceUri, preset);
+                ExifInterface exif = getExifData(newSourceUri);
+                long time = System.currentTimeMillis();
+                updateExifData(exif, time);
+                if (putExifData(mDestinationFile, exif, mPreviewImage, quality)) {
+                    putPanoramaXMPData(mDestinationFile, xmp);
+                    ContentValues values = getContentValues(mContext, mSelectedImageUri, mDestinationFile, time);
+                    Object result = mContext.getContentResolver().insert(
+                            Images.Media.EXTERNAL_CONTENT_URI, values);
+
+                }
+
+            } else {
+
+                Object xmp = getPanoramaXMPData(newSourceUri, preset);
+                ExifInterface exif = getExifData(newSourceUri);
+                long time = System.currentTimeMillis();
+                updateExifData(exif, time);
+                // If we succeed in writing the bitmap as a jpeg, return a uri.
+                if (putExifData(mDestinationFile, exif, mPreviewImage, quality)) {
+                    putPanoramaXMPData(mDestinationFile, xmp);
+                    // mDestinationFile will save the newSourceUri info in the XMP.
+                    if (!flatten) {
+                        XmpPresets.writeFilterXMP(mContext, newSourceUri,
+                                mDestinationFile, preset);
+                    }
+                    // After this call, mSelectedImageUri will be actually
+                    // pointing at the new file mDestinationFile.
+                    savedUri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri,
+                            mDestinationFile, time, !flatten);
+                }
             }
         }
 
@@ -387,27 +409,27 @@ public class SaveImage {
 
                 Object xmp = getPanoramaXMPData(newSourceUri, preset);
                 ExifInterface exif = getExifData(newSourceUri);
-
-                updateProgress();
-                // Set tags
                 long time = System.currentTimeMillis();
-                exif.addDateTimeStampTag(ExifInterface.TAG_DATE_TIME, time,
-                        TimeZone.getDefault());
-                exif.setTag(exif.buildTag(ExifInterface.TAG_ORIENTATION,
-                        ExifInterface.Orientation.TOP_LEFT));
-                // Remove old thumbnail
-                exif.removeCompressedThumbnail();
+                updateProgress();
 
+                updateExifData(exif, time);
                 updateProgress();
 
                 // If we succeed in writing the bitmap as a jpeg, return a uri.
                 if (putExifData(mDestinationFile, exif, bitmap, quality)) {
                     putPanoramaXMPData(mDestinationFile, xmp);
                     // mDestinationFile will save the newSourceUri info in the XMP.
-                    XmpPresets.writeFilterXMP(mContext, newSourceUri,
-                            mDestinationFile, preset);
+                    if (!flatten) {
+                        XmpPresets.writeFilterXMP(mContext, newSourceUri,
+                                mDestinationFile, preset);
+                        uri = updateFile(mContext, savedUri, mDestinationFile, time);
+
+                    } else {
 
-                    uri = updateFile(mContext, savedUri, mDestinationFile, time);
+                        ContentValues values = getContentValues(mContext, mSelectedImageUri, mDestinationFile, time);
+                        Object result = mContext.getContentResolver().insert(
+                                Images.Media.EXTERNAL_CONTENT_URI, values);
+                    }
                 }
                 updateProgress();
 
@@ -508,9 +530,12 @@ public class SaveImage {
             File destination) {
         Uri selectedImageUri = filterShowActivity.getSelectedImageUri();
         Uri sourceImageUri = MasterImage.getImage().getUri();
-
+        boolean flatten = false;
+        if (preset.contains(FilterRepresentation.TYPE_TINYPLANET)){
+            flatten = true;
+        }
         Intent processIntent = ProcessingService.getSaveIntent(filterShowActivity, preset,
-                destination, selectedImageUri, sourceImageUri, false, 90, 1f);
+                destination, selectedImageUri, sourceImageUri, flatten, 90, 1f);
 
         filterShowActivity.startService(processIntent);
 
index b0046e1..7e0d107 100644 (file)
@@ -157,7 +157,7 @@ public class ExportDialog extends DialogFragment implements View.OnClickListener
             case R.id.done:
                 FilterShowActivity activity = (FilterShowActivity) getActivity();
                 Uri sourceUri = MasterImage.getImage().getUri();
-                File dest = SaveImage.getNewFile(activity, sourceUri);
+                File dest = SaveImage.getNewFile(activity,  activity.getSelectedImageUri());
                 float scaleFactor = mExportWidth / (float) mOriginalBounds.width();
                 Intent processIntent = ProcessingService.getSaveIntent(activity, MasterImage
                         .getImage().getPreset(), dest, activity.getSelectedImageUri(), sourceUri,