From 67bf67eafefeda59bb0d2db8e048a5b989076850 Mon Sep 17 00:00:00 2001 From: ztenghui Date: Thu, 27 Jun 2013 17:14:41 -0700 Subject: Try to restore the original file instead of copying when appropiate. bug:9468909 Change-Id: I09ac244459389b0fdf6f64a79987c176ba8756d8 --- .../gallery3d/filtershow/tools/SaveCopyTask.java | 43 +++++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'src') 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 { 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 { // 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 { 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 { * @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 { } 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 { * @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; -- cgit v1.2.3