Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e7fd89a authored by nicolasroard's avatar nicolasroard Committed by Android Git Automerger
Browse files

am 3b311c3f: Fix saving

* commit '3b311c3f':
  Fix saving
parents fb19dbad 3b311c3f
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public class ImageSavingTask extends ProcessingTask {
        boolean flatten;
        int quality;
        float sizeFactor;
        Bitmap previewImage;
    }

    static class UpdateBitmap implements Update {
@@ -57,7 +58,8 @@ public class ImageSavingTask extends ProcessingTask {
    }

    public void saveImage(Uri sourceUri, Uri selectedUri,
                          File destinationFile, ImagePreset preset, boolean flatten,
                          File destinationFile, ImagePreset preset,
                          Bitmap previewImage, boolean flatten,
                          int quality, float sizeFactor) {
        SaveRequest request = new SaveRequest();
        request.sourceUri = sourceUri;
@@ -67,6 +69,7 @@ public class ImageSavingTask extends ProcessingTask {
        request.flatten = flatten;
        request.quality = quality;
        request.sizeFactor = sizeFactor;
        request.previewImage = previewImage;
        postRequest(request);
    }

@@ -75,6 +78,7 @@ public class ImageSavingTask extends ProcessingTask {
        Uri sourceUri = request.sourceUri;
        Uri selectedUri = request.selectedUri;
        File destinationFile = request.destinationFile;
        Bitmap previewImage = request.previewImage;
        ImagePreset preset = request.preset;
        boolean flatten = request.flatten;
        // We create a small bitmap showing the result that we can
@@ -83,7 +87,7 @@ public class ImageSavingTask extends ProcessingTask {
        updateBitmap.bitmap = createNotificationBitmap(sourceUri, preset);
        postUpdate(updateBitmap);
        SaveImage saveImage = new SaveImage(mProcessingService, sourceUri,
                selectedUri, destinationFile,
                selectedUri, destinationFile, previewImage,
                new SaveImage.Callback() {
                    @Override
                    public void onProgress(int max, int current) {
+5 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.FilterShowActivity;
import com.android.gallery3d.filtershow.filters.FiltersManager;
import com.android.gallery3d.filtershow.filters.ImageFilter;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
import com.android.gallery3d.filtershow.tools.SaveImage;

import java.io.File;
@@ -209,6 +210,7 @@ public class ProcessingService extends Service {
            mNeedsAlive = false;
            mSaving = true;
            handleSaveRequest(sourceUri, selectedUri, destinationFile, preset,
                    MasterImage.getImage().getHighresImage(),
                    flatten, quality, sizeFactor);
        }
        return START_REDELIVER_INTENT;
@@ -227,8 +229,8 @@ public class ProcessingService extends Service {
    }

    public void handleSaveRequest(Uri sourceUri, Uri selectedUri,
            File destinationFile, ImagePreset preset, boolean flatten,
            int quality, float sizeFactor) {
            File destinationFile, ImagePreset preset, Bitmap previewImage,
            boolean flatten, int quality, float sizeFactor) {
        mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        mNotificationId++;
@@ -246,7 +248,7 @@ public class ProcessingService extends Service {
        // Process the image

        mImageSavingTask.saveImage(sourceUri, selectedUri, destinationFile,
                preset, flatten, quality, sizeFactor);
                preset, previewImage, flatten, quality, sizeFactor);
    }

    public void updateNotificationWithBitmap(Bitmap bitmap) {
+63 −23
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.ImageColumns;
import android.util.Log;
import android.widget.Toast;

import com.android.gallery3d.common.Utils;
import com.android.gallery3d.exif.ExifInterface;
@@ -79,6 +80,7 @@ public class SaveImage {
    private final Callback mCallback;
    private final File mDestinationFile;
    private final Uri mSelectedImageUri;
    private final Bitmap mPreviewImage;

    private int mCurrentProcessingStep = 1;

@@ -126,10 +128,11 @@ public class SaveImage {
     * @return the newSourceUri
     */
    public SaveImage(Context context, Uri sourceUri, Uri selectedImageUri,
                     File destination, Callback callback)  {
                     File destination, Bitmap previewImage, Callback callback)  {
        mContext = context;
        mSourceUri = sourceUri;
        mCallback = callback;
        mPreviewImage = previewImage;
        if (destination == null) {
            mDestinationFile = getNewFile(context, selectedImageUri);
        } else {
@@ -332,6 +335,33 @@ public class SaveImage {
            newSourceUri = moveSrcToAuxIfNeeded(mSourceUri, mDestinationFile);
        }

        Uri savedUri = mSelectedImageUri;
        if (mPreviewImage != null) {
            Object xmp = getPanoramaXMPData(newSourceUri, preset);
            ExifInterface exif = getExifData(newSourceUri);
            // Set tags
            long time = System.currentTimeMillis();
            exif.addDateTimeStampTag(ExifInterface.TAG_DATE_TIME, time,
                    TimeZone.getDefault());
            exif.setTag(exif.buildTag(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.Orientation.TOP_LEFT));
            // Remove old thumbnail
            exif.removeCompressedThumbnail();
            // If we succeed in writing the bitmap as a jpeg, return a uri.
            if (putExifData(mDestinationFile, exif, mPreviewImage, quality)) {
                putPanoramaXMPData(mDestinationFile, xmp);
                // mDestinationFile will save the newSourceUri info in the XMP.
                XmpPresets.writeFilterXMP(mContext, newSourceUri,
                        mDestinationFile, preset);

                // After this call, mSelectedImageUri will be actually
                // pointing at the new file mDestinationFile.
                savedUri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri,
                        mDestinationFile, time, doAuxBackup);
            }
            Toast.makeText(mContext, "Computing high resolution image...", Toast.LENGTH_LONG);
        }

        // Stopgap fix for low-memory devices.
        while (noBitmap) {
            try {
@@ -377,10 +407,7 @@ public class SaveImage {
                    XmpPresets.writeFilterXMP(mContext, newSourceUri,
                            mDestinationFile, preset);

                    // After this call, mSelectedImageUri will be actually
                    // pointing at the new file mDestinationFile.
                    uri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri,
                            mDestinationFile, time, doAuxBackup);
                    uri = updateFile(mContext, savedUri, mDestinationFile, time);
                }
                updateProgress();

@@ -605,6 +632,34 @@ public class SaveImage {
    public static Uri linkNewFileToUri(Context context, Uri sourceUri,
            File file, long time, boolean deleteOriginal) {
        File oldSelectedFile = getLocalFileFromUri(context, sourceUri);
        final ContentValues values = getContentValues(context, sourceUri, file, time);

        Uri result = sourceUri;

        // In the case of incoming Uri is just a local file Uri (like a cached
        // file), we can't just update the Uri. We have to create a new Uri.
        boolean fileUri = isFileUri(sourceUri);

        if (fileUri || oldSelectedFile == null || !deleteOriginal) {
            result = context.getContentResolver().insert(
                    Images.Media.EXTERNAL_CONTENT_URI, values);
        } else {
            context.getContentResolver().update(sourceUri, values, null, null);
            if (oldSelectedFile.exists()) {
                oldSelectedFile.delete();
            }
        }
        return result;
    }

    public static Uri updateFile(Context context, Uri sourceUri, File file, long time) {
        final ContentValues values = getContentValues(context, sourceUri, file, time);
        context.getContentResolver().update(sourceUri, values, null, null);
        return sourceUri;
    }

    private static ContentValues getContentValues(Context context, Uri sourceUri,
                                                  File file, long time) {
        final ContentValues values = new ContentValues();

        time /= 1000;
@@ -622,8 +677,9 @@ public class SaveImage {
                ImageColumns.DATE_TAKEN,
                ImageColumns.LATITUDE, ImageColumns.LONGITUDE,
        };

        SaveImage.querySource(context, sourceUri, projection,
                new SaveImage.ContentResolverQueryCallback() {
                new ContentResolverQueryCallback() {

                    @Override
                    public void onCursorResult(Cursor cursor) {
@@ -639,23 +695,7 @@ public class SaveImage {
                        }
                    }
                });

        Uri result = sourceUri;

        // In the case of incoming Uri is just a local file Uri (like a cached
        // file), we can't just update the Uri. We have to create a new Uri.
        boolean fileUri = isFileUri(sourceUri);

        if (fileUri || oldSelectedFile == null || !deleteOriginal) {
            result = context.getContentResolver().insert(
                    Images.Media.EXTERNAL_CONTENT_URI, values);
        } else {
            context.getContentResolver().update(sourceUri, values, null, null);
            if (oldSelectedFile.exists()) {
                oldSelectedFile.delete();
            }
        }
        return result;
        return values;
    }

    /**