OSDN Git Service

Save edited picasa to "Edited Online Photos" album
authorDoris Liu <tianliu@google.com>
Wed, 17 Oct 2012 23:15:51 +0000 (16:15 -0700)
committerDoris Liu <tianliu@google.com>
Thu, 18 Oct 2012 01:44:10 +0000 (18:44 -0700)
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
src/com/android/gallery3d/app/PhotoPage.java
src/com/android/gallery3d/data/LocalAlbum.java
src/com/android/gallery3d/data/Path.java
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java
src/com/android/gallery3d/util/BucketNames.java
src/com/android/gallery3d/util/MediaSetUtils.java

index b6c47b2..d62bfdc 100644 (file)
     <string name="multiface_crop_help">Touch a face to begin.</string>
     <!-- Toast/alert that the image is being saved to the SD card -->
     <string name="saving_image">Saving picture\u2026</string>
+
+    <!-- Toast/alert that the image is being saved after editing in filtershow [CHAR LIMIT=40]-->
+    <string name="filtershow_saving_image">Saving picture to <xliff:g id="album_name">%1$s</xliff:g> \u2026</string>
+
     <!-- Eorror toast message that the image cannot be saved [CHAR LIMIT=40]-->
     <string name="save_error">Couldn\'t save cropped image.</string>
 
     <!-- The label for the folder contains downloaded pictures. [CHAR LIMIT=20]-->
     <string name="folder_download">Download</string>
 
+    <!-- The label for the folder contains edited online pictures. [CHAR LIMIT=40]-->
+    <string name="folder_edited_online_photos">Edited Online Photos</string>
+
     <!-- The label for the folder contains pictures that was imported from an
          external camera. [CHAR LIMIT=20]-->
     <string name="folder_imported">Imported</string>
index 90b82ce..ecb4832 100644 (file)
@@ -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);
         }
     }
index 8bbc364..e05aac0 100644 (file)
@@ -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;
         }
index a4840bd..fcae65e 100644 (file)
@@ -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);
index c07ef1a..fa9277e 100644 (file)
@@ -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<ProgressDialog>(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();
index 49cc33a..23f4972 100644 (file)
@@ -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<ProcessedBitmap, Void, Uri> {
 
-    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<ProcessedBitmap, Void, Uri> {
                 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");
index 043dd3d..df7684a 100644 (file)
@@ -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";
 }
index 9f5cbba..83b6b32 100644 (file)
@@ -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);