summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorztenghui <ztenghui@google.com>2013-07-22 11:08:28 -0700
committerztenghui <ztenghui@google.com>2013-07-22 13:16:09 -0700
commitfa07148c9336b520de25acec7aa077e3c7b22427 (patch)
treed860a74a7058aef3036b840584a37539f8a99c53 /src
parent76d39416cba8f8fe9f09f3387c324895d72b7afc (diff)
downloadandroid_packages_apps_Snap-fa07148c9336b520de25acec7aa077e3c7b22427.tar.gz
android_packages_apps_Snap-fa07148c9336b520de25acec7aa077e3c7b22427.tar.bz2
android_packages_apps_Snap-fa07148c9336b520de25acec7aa077e3c7b22427.zip
Fix saving issues with online image.
bug:9468909 Change-Id: I10762dba307999d87fac08b3a2ce7e104264a813
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/tools/SaveImage.java33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/com/android/gallery3d/filtershow/tools/SaveImage.java b/src/com/android/gallery3d/filtershow/tools/SaveImage.java
index 3489fbe73..9c881d170 100644
--- a/src/com/android/gallery3d/filtershow/tools/SaveImage.java
+++ b/src/com/android/gallery3d/filtershow/tools/SaveImage.java
@@ -283,7 +283,7 @@ public class SaveImage {
// create a local copy as usual.
if (srcFile != null) {
srcFile.renameTo(mDestinationFile);
- uri = SaveImage.updateUriContent(mContext, mSelectedImageUri,
+ uri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri,
mDestinationFile, System.currentTimeMillis());
}
}
@@ -359,7 +359,7 @@ public class SaveImage {
// After this call, mSelectedImageUri will be actually
// pointing at the new file mDestinationFile.
- uri = SaveImage.updateUriContent(mContext, mSelectedImageUri,
+ uri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri,
mDestinationFile, time);
}
updateProgress();
@@ -436,7 +436,7 @@ public class SaveImage {
String filename = new SimpleDateFormat(TIME_STAMP_NAME).format(new Date(time));
File saveDirectory = getFinalSaveDirectory(context, sourceUri);
File file = new File(saveDirectory, filename + ".JPG");
- return updateUriContent(context, sourceUri, file, time);
+ return linkNewFileToUri(context, sourceUri, file, time);
}
public static void saveImage(ImagePreset preset, final FilterShowActivity filterShowActivity,
@@ -556,10 +556,16 @@ public class SaveImage {
}
/**
- * Update the content Uri with the new file and proper source properties.
- * The old file will be removed if it is local.
+ * If the <code>sourceUri</code> is a local content Uri, update the
+ * <code>sourceUri</code> to point to the <code>file</code>.
+ * At the same time, the old file <code>sourceUri</code> used to point to
+ * will be removed if it is local.
+ * If the <code>sourceUri</code> is not a local content Uri, then the
+ * <code>file</code> will be inserted as a new content Uri.
+ * @return the final Uri referring to the <code>file</code>.
*/
- public static Uri updateUriContent(Context context, Uri sourceUri, File file, long time) {
+ public static Uri linkNewFileToUri(Context context, Uri sourceUri,
+ File file, long time) {
File oldSelectedFile = getLocalFileFromUri(context, sourceUri);
final ContentValues values = new ContentValues();
@@ -596,13 +602,18 @@ public class SaveImage {
}
});
- context.getContentResolver().update(sourceUri, values, null, null);
-
- if (oldSelectedFile != null && oldSelectedFile.exists()) {
- oldSelectedFile.delete();
+ Uri result = sourceUri;
+ if (oldSelectedFile == null) {
+ result = context.getContentResolver().insert(
+ Images.Media.EXTERNAL_CONTENT_URI, values);
+ } else {
+ context.getContentResolver().update(sourceUri, values, null, null);
+ if (oldSelectedFile.exists()) {
+ oldSelectedFile.delete();
+ }
}
- return sourceUri;
+ return result;
}
}