From 0addfc7f6342184a67cdd8b5cc3872c6a5c87e55 Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Wed, 17 Oct 2012 16:15:51 -0700 Subject: [PATCH] Save edited picasa to "Edited Online Photos" album Bug: 7346157 This CL includes the following changes: 1) Save the new image to a new folder named "Edited Online Photos" 2) After the picture is saved, the user will be in the "Edited Online Photos" folder 3) Change the toast during saving to "Saving to" + new folder name Change-Id: Ic505925425419ba9e3c7dac31fd403bf73d6887d --- res/values/strings.xml | 7 +++++++ src/com/android/gallery3d/app/PhotoPage.java | 10 ++++++++++ src/com/android/gallery3d/data/LocalAlbum.java | 4 +++- src/com/android/gallery3d/data/Path.java | 6 ++++++ .../gallery3d/filtershow/FilterShowActivity.java | 21 +++++++++++++++++---- .../gallery3d/filtershow/tools/SaveCopyTask.java | 12 ++++++++---- src/com/android/gallery3d/util/BucketNames.java | 1 + src/com/android/gallery3d/util/MediaSetUtils.java | 3 +++ 8 files changed, 55 insertions(+), 9 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index b6c47b2c8..d62bfdc55 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -70,6 +70,10 @@ Touch a face to begin. Saving picture\u2026 + + + Saving picture to %1$s \u2026 + Couldn\'t save cropped image. @@ -459,6 +463,9 @@ Download + + Edited Online Photos + Imported diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 90b82cefc..ecb48329a 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -1180,6 +1180,16 @@ public class PhotoPage extends ActivityState implements Path path = mApplication.getDataManager() .findPathByUri(intent.getData(), intent.getType()); if (path != null) { + Path albumPath = mApplication.getDataManager().getDefaultSetOf(path); + if (!albumPath.equalsIgnoreCase(mOriginalSetPathString)) { + // If the edited image is stored in a different album, we need + // to start a new activity state to show the new image + Bundle data = new Bundle(getData()); + data.putString(KEY_MEDIA_SET_PATH, albumPath.toString()); + data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, path.toString()); + mActivity.getStateManager().startState(PhotoPage.class, data); + return; + } mModel.setCurrentPhoto(path, mCurrentIndex); } } diff --git a/src/com/android/gallery3d/data/LocalAlbum.java b/src/com/android/gallery3d/data/LocalAlbum.java index 8bbc364ec..e05aac01b 100644 --- a/src/com/android/gallery3d/data/LocalAlbum.java +++ b/src/com/android/gallery3d/data/LocalAlbum.java @@ -274,7 +274,7 @@ public class LocalAlbum extends MediaSet { return true; } - private static String getLocalizedName(Resources res, int bucketId, + public static String getLocalizedName(Resources res, int bucketId, String name) { if (bucketId == MediaSetUtils.CAMERA_BUCKET_ID) { return res.getString(R.string.folder_camera); @@ -284,6 +284,8 @@ public class LocalAlbum extends MediaSet { return res.getString(R.string.folder_imported); } else if (bucketId == MediaSetUtils.SNAPSHOT_BUCKET_ID) { return res.getString(R.string.folder_screenshot); + } else if (bucketId == MediaSetUtils.EDITED_ONLINE_PHOTOS_BUCKET_ID) { + return res.getString(R.string.folder_edited_online_photos); } else { return name; } diff --git a/src/com/android/gallery3d/data/Path.java b/src/com/android/gallery3d/data/Path.java index a4840bdbf..fcae65e66 100644 --- a/src/com/android/gallery3d/data/Path.java +++ b/src/com/android/gallery3d/data/Path.java @@ -79,6 +79,7 @@ public class Path { } @Override + // TODO: toString() should be more efficient, will fix it later public String toString() { synchronized (Path.class) { StringBuilder sb = new StringBuilder(); @@ -91,6 +92,11 @@ public class Path { } } + public boolean equalsIgnoreCase (String p) { + String path = toString(); + return path.equalsIgnoreCase(p); + } + public static Path fromString(String s) { synchronized (Path.class) { String[] segments = split(s); diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index c07ef1a36..fa9277ebe 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -6,6 +6,7 @@ import android.app.ActionBar; import android.app.Activity; import android.app.ProgressDialog; import android.content.ContentValues; +import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.graphics.Bitmap; @@ -34,6 +35,7 @@ import android.widget.ShareActionProvider.OnShareTargetSelectedListener; import android.widget.Toast; import com.android.gallery3d.R; +import com.android.gallery3d.data.LocalAlbum; import com.android.gallery3d.filtershow.cache.ImageLoader; import com.android.gallery3d.filtershow.filters.ImageFilter; import com.android.gallery3d.filtershow.filters.ImageFilterBorder; @@ -64,6 +66,7 @@ import com.android.gallery3d.filtershow.tools.SaveCopyTask; import com.android.gallery3d.filtershow.ui.ImageButtonTitle; import com.android.gallery3d.filtershow.ui.ImageCurves; import com.android.gallery3d.filtershow.ui.Spline; +import com.android.gallery3d.util.GalleryUtils; import java.io.File; import java.lang.ref.WeakReference; @@ -363,7 +366,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, return (133 * msize) / metrics.densityDpi; } - private void showSavingProgress() { + private void showSavingProgress(String albumName) { ProgressDialog progress; if (mSavingProgressDialog != null) { progress = mSavingProgressDialog.get(); @@ -373,7 +376,13 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, } } // TODO: Allow cancellation of the saving process - progress = ProgressDialog.show(this, "", getString(R.string.saving_image), true, false); + String progressText; + if (albumName == null) { + progressText = getString(R.string.saving_image); + } else { + progressText = getString(R.string.filtershow_saving_image, albumName); + } + progress = ProgressDialog.show(this, "", progressText, true, false); mSavingProgressDialog = new WeakReference(progress); } @@ -411,7 +420,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, mSharingImage = true; // Process and save the image in the background. - showSavingProgress(); + showSavingProgress(null); mImageShow.saveImage(this, mSharedOutputFile); return true; } @@ -823,7 +832,11 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, public void saveImage() { if (mImageShow.hasModifications()) { - showSavingProgress(); + // Get the name of the album, to which the image will be saved + File saveDir = SaveCopyTask.getFinalSaveDirectory(this, mImageLoader.getUri()); + int bucketId = GalleryUtils.getBucketId(saveDir.getPath()); + String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null); + showSavingProgress(albumName); mImageShow.saveImage(this, null); } else { finish(); diff --git a/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java b/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java index 49cc33a2a..23f497258 100644 --- a/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java +++ b/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java @@ -30,6 +30,7 @@ import android.provider.MediaStore.Images.ImageColumns; import android.view.Gravity; import android.widget.Toast; +import com.android.camera.R; import com.android.gallery3d.filtershow.presets.ImagePreset; //import com.android.gallery3d.R; @@ -49,9 +50,8 @@ import java.text.SimpleDateFormat; */ public class SaveCopyTask extends AsyncTask { - public static final String DOWNLOAD = "download"; - public static final String DEFAULT_SAVE_DIRECTORY = "Download"; private static final int DEFAULT_COMPRESS_QUALITY = 95; + private static final String DEFAULT_SAVE_DIRECTORY = "EditedOnlinePhotos"; /** * Saves the bitmap in the final destination @@ -114,13 +114,17 @@ public class SaveCopyTask extends AsyncTask { System.currentTimeMillis())); } - public static File getNewFile(Context context, Uri sourceUri) { + public static File getFinalSaveDirectory(Context context, Uri sourceUri) { File saveDirectory = getSaveDirectory(context, sourceUri); if ((saveDirectory == null) || !saveDirectory.canWrite()) { saveDirectory = new File(Environment.getExternalStorageDirectory(), - DOWNLOAD); + DEFAULT_SAVE_DIRECTORY); } + return saveDirectory; + } + public static File getNewFile(Context context, Uri sourceUri) { + File saveDirectory = getFinalSaveDirectory(context, sourceUri); String filename = new SimpleDateFormat(TIME_STAMP_NAME).format(new Date( System.currentTimeMillis())); return new File(saveDirectory, filename + ".JPG"); diff --git a/src/com/android/gallery3d/util/BucketNames.java b/src/com/android/gallery3d/util/BucketNames.java index 043dd3d10..df7684a04 100644 --- a/src/com/android/gallery3d/util/BucketNames.java +++ b/src/com/android/gallery3d/util/BucketNames.java @@ -23,4 +23,5 @@ public class BucketNames { public static final String IMPORTED = "Imported"; public static final String DOWNLOAD = "download"; + public static final String EDITED_ONLINE_PHOTOS = "EditedOnlinePhotos"; } diff --git a/src/com/android/gallery3d/util/MediaSetUtils.java b/src/com/android/gallery3d/util/MediaSetUtils.java index 9f5cbba1c..83b6b320b 100644 --- a/src/com/android/gallery3d/util/MediaSetUtils.java +++ b/src/com/android/gallery3d/util/MediaSetUtils.java @@ -33,6 +33,9 @@ public class MediaSetUtils { public static final int DOWNLOAD_BUCKET_ID = GalleryUtils.getBucketId( Environment.getExternalStorageDirectory().toString() + "/" + BucketNames.DOWNLOAD); + public static final int EDITED_ONLINE_PHOTOS_BUCKET_ID = GalleryUtils.getBucketId( + Environment.getExternalStorageDirectory().toString() + "/" + + BucketNames.EDITED_ONLINE_PHOTOS); public static final int IMPORTED_BUCKET_ID = GalleryUtils.getBucketId( Environment.getExternalStorageDirectory().toString() + "/" + BucketNames.IMPORTED); -- 2.11.0