int quality;
float sizeFactor;
Bitmap previewImage;
+ boolean exit;
}
static class UpdateBitmap implements Update {
static class UpdatePreviewSaved implements Update {
Uri uri;
+ boolean exit;
}
static class URIResult implements Result {
Uri uri;
+ boolean exit;
}
public ImageSavingTask(ProcessingService service) {
public void saveImage(Uri sourceUri, Uri selectedUri,
File destinationFile, ImagePreset preset,
Bitmap previewImage, boolean flatten,
- int quality, float sizeFactor) {
+ int quality, float sizeFactor, boolean exit) {
SaveRequest request = new SaveRequest();
request.sourceUri = sourceUri;
request.selectedUri = selectedUri;
request.quality = quality;
request.sizeFactor = sizeFactor;
request.previewImage = previewImage;
+ request.exit = exit;
postRequest(request);
}
Bitmap previewImage = request.previewImage;
ImagePreset preset = request.preset;
boolean flatten = request.flatten;
+ final boolean exit = request.exit;
// We create a small bitmap showing the result that we can
// give to the notification
UpdateBitmap updateBitmap = new UpdateBitmap();
public void onPreviewSaved(Uri uri){
UpdatePreviewSaved previewSaved = new UpdatePreviewSaved();
previewSaved.uri = uri;
+ previewSaved.exit = exit;
postUpdate(previewSaved);
}
}
});
Uri uri = saveImage.processAndSaveImage(preset, flatten,
- request.quality, request.sizeFactor);
+ request.quality, request.sizeFactor, request.exit);
URIResult result = new URIResult();
result.uri = uri;
+ result.exit = request.exit;
return result;
}
@Override
public void onResult(Result message) {
URIResult result = (URIResult) message;
- mProcessingService.completeSaveImage(result.uri);
+ mProcessingService.completeSaveImage(result.uri, result.exit);
}
@Override
public void onUpdate(Update message) {
if (message instanceof UpdatePreviewSaved){
Uri uri = ((UpdatePreviewSaved) message).uri;
- mProcessingService.completePreviewSaveImage(uri);
+ boolean exit = ((UpdatePreviewSaved) message).exit;
+ mProcessingService.completePreviewSaveImage(uri, exit);
}
if (message instanceof UpdateBitmap) {
Bitmap bitmap = ((UpdateBitmap) message).bitmap;
private static final String SAVING = "saving";
private static final String FLATTEN = "flatten";
private static final String SIZE_FACTOR = "sizeFactor";
+ private static final String EXIT = "exit";
private ProcessingTaskController mProcessingTaskController;
private ImageSavingTask mImageSavingTask;
}
public static Intent getSaveIntent(Context context, ImagePreset preset, File destination,
- Uri selectedImageUri, Uri sourceImageUri, boolean doFlatten, int quality, float sizeFactor) {
+ Uri selectedImageUri, Uri sourceImageUri, boolean doFlatten, int quality,
+ float sizeFactor, boolean needsExit) {
Intent processIntent = new Intent(context, ProcessingService.class);
processIntent.putExtra(ProcessingService.SOURCE_URI,
sourceImageUri.toString());
processIntent.putExtra(ProcessingService.PRESET,
preset.getJsonString(ImagePreset.JASON_SAVED));
processIntent.putExtra(ProcessingService.SAVING, true);
+ processIntent.putExtra(ProcessingService.EXIT, needsExit);
if (doFlatten) {
processIntent.putExtra(ProcessingService.FLATTEN, true);
}
int quality = intent.getIntExtra(QUALITY, 100);
float sizeFactor = intent.getFloatExtra(SIZE_FACTOR, 1);
boolean flatten = intent.getBooleanExtra(FLATTEN, false);
+ boolean exit = intent.getBooleanExtra(EXIT, false);
Uri sourceUri = Uri.parse(source);
Uri selectedUri = null;
if (selected != null) {
mSaving = true;
handleSaveRequest(sourceUri, selectedUri, destinationFile, preset,
MasterImage.getImage().getHighresImage(),
- flatten, quality, sizeFactor);
+ flatten, quality, sizeFactor, exit);
}
return START_REDELIVER_INTENT;
}
public void handleSaveRequest(Uri sourceUri, Uri selectedUri,
File destinationFile, ImagePreset preset, Bitmap previewImage,
- boolean flatten, int quality, float sizeFactor) {
+ boolean flatten, int quality, float sizeFactor, boolean exit) {
mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-
- mNotificationId++;
+ mNotifyMgr.cancelAll();
mBuilder =
new Notification.Builder(this)
// Process the image
mImageSavingTask.saveImage(sourceUri, selectedUri, destinationFile,
- preset, previewImage, flatten, quality, sizeFactor);
+ preset, previewImage, flatten, quality, sizeFactor, exit);
}
public void updateNotificationWithBitmap(Bitmap bitmap) {
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
- public void completePreviewSaveImage(Uri result) {
- if (!mNeedsAlive && !mFiltershowActivity.isSimpleEditAction()) {
+ public void completePreviewSaveImage(Uri result, boolean exit) {
+ if (exit && !mNeedsAlive && !mFiltershowActivity.isSimpleEditAction()) {
mFiltershowActivity.completeSaveImage(result);
}
}
- public void completeSaveImage(Uri result) {
+ public void completeSaveImage(Uri result, boolean exit) {
if (SHOW_IMAGE) {
// TODO: we should update the existing image in Gallery instead
Intent viewImage = new Intent(Intent.ACTION_VIEW, result);
viewImage.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(viewImage);
}
+ mNotifyMgr.cancel(mNotificationId);
+ if (!exit) {
+ stopForeground(true);
+ stopSelf();
+ return;
+ }
stopForeground(true);
stopSelf();
if (mNeedsAlive) {
}
public Uri processAndSaveImage(ImagePreset preset, boolean flatten,
- int quality, float sizeFactor) {
+ int quality, float sizeFactor, boolean exit) {
- Uri uri = resetToOriginalImageIfNeeded(preset, !flatten);
+ Uri uri = null;
+ if (exit) {
+ uri = resetToOriginalImageIfNeeded(preset, !flatten);
+ }
if (uri != null) {
return null;
}
Images.Media.EXTERNAL_CONTENT_URI, values);
}
-
} else {
-
Object xmp = getPanoramaXMPData(newSourceUri, preset);
ExifInterface exif = getExifData(newSourceUri);
long time = System.currentTimeMillis();
flatten = true;
}
Intent processIntent = ProcessingService.getSaveIntent(filterShowActivity, preset,
- destination, selectedImageUri, sourceImageUri, flatten, 90, 1f);
+ destination, selectedImageUri, sourceImageUri, flatten, 90, 1f, true);
filterShowActivity.startService(processIntent);