diff options
author | ztenghui <ztenghui@google.com> | 2013-06-27 17:14:41 -0700 |
---|---|---|
committer | ztenghui <ztenghui@google.com> | 2013-07-02 17:04:46 -0700 |
commit | 8d90cb8d8629a56be63cff10035232f587c2d4bd (patch) | |
tree | 15e4c2d3610f164ac978f079864b061933a5de52 /src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java | |
parent | ce9ceff5776a9b0479c30cbeb2a9388b44df1865 (diff) | |
download | android_packages_apps_Gallery2-8d90cb8d8629a56be63cff10035232f587c2d4bd.tar.gz android_packages_apps_Gallery2-8d90cb8d8629a56be63cff10035232f587c2d4bd.tar.bz2 android_packages_apps_Gallery2-8d90cb8d8629a56be63cff10035232f587c2d4bd.zip |
Try to restore the original file instead of copying when appropiate.
bug:9468909
Change-Id: I09ac244459389b0fdf6f64a79987c176ba8756d8
Diffstat (limited to 'src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java')
-rw-r--r-- | src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java b/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java index 1d5500ef4..6c1b2d017 100644 --- a/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java +++ b/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java @@ -279,9 +279,28 @@ public class SaveCopyTask extends AsyncTask<ImagePreset, Void, Uri> { if (params[0] == null || mSourceUri == null || mSelectedImageUri == null) { return null; } + ImagePreset preset = params[0]; - BitmapFactory.Options options = new BitmapFactory.Options(); Uri uri = null; + if (!preset.hasModifications()) { + // This can happen only when preset has no modification but save + // button is enabled, it means the file is loaded with filters in + // the XMP, then all the filters are removed or restore to default. + // In this case, when mSourceUri exists, rename it to the + // destination file. + File srcFile = getLocalFileFromUri(mContext, mSourceUri); + // If the source is not a local file, then skip this renaming and + // create a local copy as usual. + if (srcFile != null) { + srcFile.renameTo(mDestinationFile); + uri = insertContent(mContext, mSelectedImageUri, mDestinationFile, + System.currentTimeMillis()); + removeSelectedImage(); + return uri; + } + } + + BitmapFactory.Options options = new BitmapFactory.Options(); boolean noBitmap = true; int num_tries = 0; @@ -331,12 +350,7 @@ public class SaveCopyTask extends AsyncTask<ImagePreset, Void, Uri> { // Since we have a new image inserted to media store, we can // safely remove the old one which is selected by the user. if (USE_AUX_DIR) { - String scheme = mSelectedImageUri.getScheme(); - if (scheme != null && scheme.equals(ContentResolver.SCHEME_CONTENT)) { - if (mSelectedImageUri.getAuthority().equals(MediaStore.AUTHORITY)) { - mContext.getContentResolver().delete(mSelectedImageUri, null, null); - } - } + removeSelectedImage(); } noBitmap = false; UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR, @@ -353,6 +367,15 @@ public class SaveCopyTask extends AsyncTask<ImagePreset, Void, Uri> { return uri; } + private void removeSelectedImage() { + String scheme = mSelectedImageUri.getScheme(); + if (scheme != null && scheme.equals(ContentResolver.SCHEME_CONTENT)) { + if (mSelectedImageUri.getAuthority().equals(MediaStore.AUTHORITY)) { + mContext.getContentResolver().delete(mSelectedImageUri, null, null); + } + } + } + /** * Move the source file to auxiliary directory if needed and return the Uri * pointing to this new source file. @@ -362,7 +385,7 @@ public class SaveCopyTask extends AsyncTask<ImagePreset, Void, Uri> { * @return the newSourceUri pointing to the new source image. */ private Uri moveSrcToAuxIfNeeded(Uri srcUri, File dstFile) { - File srcFile = getFileFromUri(mContext, srcUri); + File srcFile = getLocalFileFromUri(mContext, srcUri); if (srcFile == null) { Log.d(LOGTAG, "Source file is not a local file, no update."); return srcUri; @@ -437,7 +460,7 @@ public class SaveCopyTask extends AsyncTask<ImagePreset, Void, Uri> { } private static File getSaveDirectory(Context context, Uri sourceUri) { - File file = getFileFromUri(context, sourceUri); + File file = getLocalFileFromUri(context, sourceUri); if (file != null) { return file.getParentFile(); } else { @@ -450,7 +473,7 @@ public class SaveCopyTask extends AsyncTask<ImagePreset, Void, Uri> { * @return The file object. Return null if srcUri is invalid or not a local * file. */ - private static File getFileFromUri(Context context, Uri srcUri) { + private static File getLocalFileFromUri(Context context, Uri srcUri) { if (srcUri == null) { Log.e(LOGTAG, "srcUri is null."); return null; |