summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2013-07-24 20:06:20 -0700
committerRuben Brunk <rubenbrunk@google.com>2013-07-25 09:50:23 -0700
commit16967913de669502464cdd1aa2a389c24d123f70 (patch)
treecd9926a22fcdf6228a65c8ccecb38764e70e2abd /src
parent6a8e8a1a0f3e8e62cd350733e275047475380d6b (diff)
downloadandroid_packages_apps_Snap-16967913de669502464cdd1aa2a389c24d123f70.tar.gz
android_packages_apps_Snap-16967913de669502464cdd1aa2a389c24d123f70.tar.bz2
android_packages_apps_Snap-16967913de669502464cdd1aa2a389c24d123f70.zip
Added support to export to a flattened photo.
Bug: 10008212 - Adds a menu item to allow a photo with edits to be flattened into a separate photo. - Fixes bug where crop intents fail to save cropped images. Change-Id: I1dcf1bb9ba22e72378f24e7971a74f81b8db7564
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java8
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/ImageSavingTask.java10
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java13
-rw-r--r--src/com/android/gallery3d/filtershow/tools/SaveImage.java23
4 files changed, 35 insertions, 19 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index c03ba78c2..7929e252d 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -815,6 +815,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
mShowingImageStatePanel ? "ShowPanel" : "HidePanel");
return true;
}
+ case R.id.exportFlattenButton: {
+ Uri sourceUri = MasterImage.getImage().getUri();
+ File dest = SaveImage.getNewFile(this, sourceUri);
+ Intent processIntent = ProcessingService.getSaveIntent(this, MasterImage.getImage()
+ .getPreset(), dest, getSelectedImageUri(), sourceUri, true);
+ startService(processIntent);
+ return true;
+ }
case android.R.id.home: {
saveImage();
return true;
diff --git a/src/com/android/gallery3d/filtershow/pipeline/ImageSavingTask.java b/src/com/android/gallery3d/filtershow/pipeline/ImageSavingTask.java
index e93ec1687..ebd3ed91b 100644
--- a/src/com/android/gallery3d/filtershow/pipeline/ImageSavingTask.java
+++ b/src/com/android/gallery3d/filtershow/pipeline/ImageSavingTask.java
@@ -33,6 +33,7 @@ public class ImageSavingTask extends ProcessingTask {
Uri selectedUri;
File destinationFile;
ImagePreset preset;
+ boolean flatten;
}
static class UpdateBitmap implements Update {
@@ -53,12 +54,13 @@ public class ImageSavingTask extends ProcessingTask {
}
public void saveImage(Uri sourceUri, Uri selectedUri,
- File destinationFile, ImagePreset preset) {
+ File destinationFile, ImagePreset preset, boolean flatten) {
SaveRequest request = new SaveRequest();
request.sourceUri = sourceUri;
request.selectedUri = selectedUri;
request.destinationFile = destinationFile;
request.preset = preset;
+ request.flatten = flatten;
postRequest(request);
}
@@ -68,13 +70,12 @@ public class ImageSavingTask extends ProcessingTask {
Uri selectedUri = request.selectedUri;
File destinationFile = request.destinationFile;
ImagePreset preset = request.preset;
-
+ boolean flatten = request.flatten;
// We create a small bitmap showing the result that we can
// give to the notification
UpdateBitmap updateBitmap = new UpdateBitmap();
updateBitmap.bitmap = createNotificationBitmap(sourceUri, preset);
postUpdate(updateBitmap);
-
SaveImage saveImage = new SaveImage(mProcessingService, sourceUri,
selectedUri, destinationFile,
new SaveImage.Callback() {
@@ -86,8 +87,7 @@ public class ImageSavingTask extends ProcessingTask {
postUpdate(updateProgress);
}
});
-
- Uri uri = saveImage.processAndSaveImage(preset);
+ Uri uri = saveImage.processAndSaveImage(preset, !flatten);
URIResult result = new URIResult();
result.uri = uri;
return result;
diff --git a/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java b/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java
index 8f1b2a266..f0f3e5399 100644
--- a/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java
+++ b/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java
@@ -48,6 +48,7 @@ public class ProcessingService extends Service {
private static final String SELECTED_URI = "selectedUri";
private static final String DESTINATION_FILE = "destinationFile";
private static final String SAVING = "saving";
+ private static final String FLATTEN = "flatten";
private ProcessingTaskController mProcessingTaskController;
private ImageSavingTask mImageSavingTask;
@@ -116,7 +117,7 @@ public class ProcessingService extends Service {
}
public static Intent getSaveIntent(Context context, ImagePreset preset, File destination,
- Uri selectedImageUri, Uri sourceImageUri) {
+ Uri selectedImageUri, Uri sourceImageUri, boolean doFlatten) {
Intent processIntent = new Intent(context, ProcessingService.class);
processIntent.putExtra(ProcessingService.SOURCE_URI,
sourceImageUri.toString());
@@ -128,6 +129,9 @@ public class ProcessingService extends Service {
processIntent.putExtra(ProcessingService.PRESET,
preset.getJsonString(context.getString(R.string.saved)));
processIntent.putExtra(ProcessingService.SAVING, true);
+ if (doFlatten) {
+ processIntent.putExtra(ProcessingService.FLATTEN, true);
+ }
return processIntent;
}
@@ -162,6 +166,7 @@ public class ProcessingService extends Service {
String source = intent.getStringExtra(SOURCE_URI);
String selected = intent.getStringExtra(SELECTED_URI);
String destination = intent.getStringExtra(DESTINATION_FILE);
+ boolean flatten = intent.getBooleanExtra(FLATTEN, false);
Uri sourceUri = Uri.parse(source);
Uri selectedUri = null;
if (selected != null) {
@@ -175,7 +180,7 @@ public class ProcessingService extends Service {
preset.readJsonFromString(presetJson);
mNeedsAlive = false;
mSaving = true;
- handleSaveRequest(sourceUri, selectedUri, destinationFile, preset);
+ handleSaveRequest(sourceUri, selectedUri, destinationFile, preset, flatten);
}
return START_REDELIVER_INTENT;
}
@@ -193,7 +198,7 @@ public class ProcessingService extends Service {
}
public void handleSaveRequest(Uri sourceUri, Uri selectedUri,
- File destinationFile, ImagePreset preset) {
+ File destinationFile, ImagePreset preset, boolean flatten) {
mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationId++;
@@ -210,7 +215,7 @@ public class ProcessingService extends Service {
// Process the image
- mImageSavingTask.saveImage(sourceUri, selectedUri, destinationFile, preset);
+ mImageSavingTask.saveImage(sourceUri, selectedUri, destinationFile, preset, flatten);
}
public void updateNotificationWithBitmap(Bitmap bitmap) {
diff --git a/src/com/android/gallery3d/filtershow/tools/SaveImage.java b/src/com/android/gallery3d/filtershow/tools/SaveImage.java
index 9c881d170..d5fe29584 100644
--- a/src/com/android/gallery3d/filtershow/tools/SaveImage.java
+++ b/src/com/android/gallery3d/filtershow/tools/SaveImage.java
@@ -270,7 +270,7 @@ public class SaveImage {
return ret;
}
- private Uri resetToOriginalImageIfNeeded(ImagePreset preset) {
+ private Uri resetToOriginalImageIfNeeded(ImagePreset preset, boolean doAuxBackup) {
Uri uri = null;
if (!preset.hasModifications()) {
// This can happen only when preset has no modification but save
@@ -284,7 +284,7 @@ public class SaveImage {
if (srcFile != null) {
srcFile.renameTo(mDestinationFile);
uri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri,
- mDestinationFile, System.currentTimeMillis());
+ mDestinationFile, System.currentTimeMillis(), doAuxBackup);
}
}
return uri;
@@ -300,9 +300,9 @@ public class SaveImage {
}
}
- public Uri processAndSaveImage(ImagePreset preset) {
+ public Uri processAndSaveImage(ImagePreset preset, boolean doAuxBackup) {
- Uri uri = resetToOriginalImageIfNeeded(preset);
+ Uri uri = resetToOriginalImageIfNeeded(preset, doAuxBackup);
if (uri != null) {
return null;
}
@@ -316,7 +316,10 @@ public class SaveImage {
// If necessary, move the source file into the auxiliary directory,
// newSourceUri is then pointing to the new location.
// If no file is moved, newSourceUri will be the same as mSourceUri.
- Uri newSourceUri = moveSrcToAuxIfNeeded(mSourceUri, mDestinationFile);
+ Uri newSourceUri = mSourceUri;
+ if (doAuxBackup) {
+ newSourceUri = moveSrcToAuxIfNeeded(mSourceUri, mDestinationFile);
+ }
// Stopgap fix for low-memory devices.
while (noBitmap) {
@@ -360,7 +363,7 @@ public class SaveImage {
// After this call, mSelectedImageUri will be actually
// pointing at the new file mDestinationFile.
uri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri,
- mDestinationFile, time);
+ mDestinationFile, time, doAuxBackup);
}
updateProgress();
@@ -436,7 +439,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 linkNewFileToUri(context, sourceUri, file, time);
+ return linkNewFileToUri(context, sourceUri, file, time, false);
}
public static void saveImage(ImagePreset preset, final FilterShowActivity filterShowActivity,
@@ -445,7 +448,7 @@ public class SaveImage {
Uri sourceImageUri = MasterImage.getImage().getUri();
Intent processIntent = ProcessingService.getSaveIntent(filterShowActivity, preset,
- destination, selectedImageUri, sourceImageUri);
+ destination, selectedImageUri, sourceImageUri, false);
filterShowActivity.startService(processIntent);
@@ -565,7 +568,7 @@ public class SaveImage {
* @return the final Uri referring to the <code>file</code>.
*/
public static Uri linkNewFileToUri(Context context, Uri sourceUri,
- File file, long time) {
+ File file, long time, boolean deleteOriginal) {
File oldSelectedFile = getLocalFileFromUri(context, sourceUri);
final ContentValues values = new ContentValues();
@@ -603,7 +606,7 @@ public class SaveImage {
});
Uri result = sourceUri;
- if (oldSelectedFile == null) {
+ if (oldSelectedFile == null || !deleteOriginal) {
result = context.getContentResolver().insert(
Images.Media.EXTERNAL_CONTENT_URI, values);
} else {