summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2009-05-29 14:38:35 -0700
committerOwen Lin <owenlin@google.com>2009-06-03 16:01:16 -0700
commit0f9c339253b0fabed60efd731869e68d18893837 (patch)
tree643abec50988cc2e5b9d873cc4749b188aa1cb75 /src/com/android
parentdeb57259b0055c08a44cd43933276ccf485dcd2d (diff)
downloadLegacyCamera-0f9c339253b0fabed60efd731869e68d18893837.zip
LegacyCamera-0f9c339253b0fabed60efd731869e68d18893837.tar.gz
LegacyCamera-0f9c339253b0fabed60efd731869e68d18893837.tar.bz2
Make ImageList parcelable so that they can pass by intent.
Diffstat (limited to 'src/com/android')
-rwxr-xr-xsrc/com/android/camera/ImageManager.java91
-rw-r--r--src/com/android/camera/gallery/BaseImageList.java34
-rw-r--r--src/com/android/camera/gallery/DrmImageList.java24
-rw-r--r--src/com/android/camera/gallery/IImageList.java31
-rw-r--r--src/com/android/camera/gallery/ImageList.java28
-rw-r--r--src/com/android/camera/gallery/ImageListUber.java62
-rw-r--r--src/com/android/camera/gallery/SingleImageList.java12
-rw-r--r--src/com/android/camera/gallery/VideoList.java22
8 files changed, 233 insertions, 71 deletions
diff --git a/src/com/android/camera/ImageManager.java b/src/com/android/camera/ImageManager.java
index 50509a6..d0ca0f8 100755
--- a/src/com/android/camera/ImageManager.java
+++ b/src/com/android/camera/ImageManager.java
@@ -37,6 +37,7 @@ import android.graphics.Bitmap;
import android.location.Location;
import android.net.Uri;
import android.os.Environment;
+import android.os.Parcel;
import android.provider.DrmStore;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
@@ -218,8 +219,9 @@ public class ImageManager {
boolean complete = false;
try {
long id = ContentUris.parseId(mUri);
- BaseImageList il = new ImageList(mCr, STORAGE_URI,
- THUMB_URI, SORT_ASCENDING, null);
+ BaseImageList il = new ImageList(
+ STORAGE_URI, THUMB_URI, SORT_ASCENDING, null);
+ il.open(mCr);
// TODO: Redesign the process of adding new images. We should
// create an <code>IImage</code> in "ImageManager.addImage"
@@ -278,7 +280,8 @@ public class ImageManager {
cr, ImageManager.DataLocation.ALL,
ImageManager.INCLUDE_DRM_IMAGES, sort);
} else if (isSingleImageMode(uriString)) {
- imageList = new SingleImageList(cr, uri);
+ imageList = new SingleImageList(uri);
+ ((SingleImageList) imageList).open(cr);
} else {
String bucketId = uri.getQueryParameter("bucketId");
imageList = ImageManager.allImages(
@@ -296,6 +299,23 @@ public class ImageManager {
}
private static class EmptyImageList implements IImageList {
+ public static final Creator<EmptyImageList> CREATOR =
+ new Creator<EmptyImageList>() {
+ public EmptyImageList createFromParcel(Parcel in) {
+ return new EmptyImageList();
+ }
+
+ public EmptyImageList[] newArray(int size) {
+ return new EmptyImageList[size];
+ }
+ };
+
+ public void open(ContentResolver resolver) {
+ }
+
+ public void close() {
+ }
+
public void checkThumbnail(int index) {
}
@@ -333,6 +353,13 @@ public class ImageManager {
public int getImageIndex(IImage image) {
throw new UnsupportedOperationException();
}
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel dest, int flags) {
+ }
}
public static IImageList emptyImageList() {
@@ -354,64 +381,50 @@ public class ImageManager {
boolean haveSdCard = hasStorage(false);
// use this code to merge videos and stills into the same list
- ArrayList<IImageList> l = new ArrayList<IImageList>();
+ ArrayList<BaseImageList> l = new ArrayList<BaseImageList>();
if (haveSdCard && location != DataLocation.INTERNAL) {
if ((inclusion & INCLUDE_IMAGES) != 0) {
- try {
- l.add(new ImageList(cr, STORAGE_URI,
- THUMB_URI, sort, bucketId));
- } catch (UnsupportedOperationException ex) {
- // ignore exception
- }
+ l.add(new ImageList(
+ STORAGE_URI, THUMB_URI, sort, bucketId));
}
if ((inclusion & INCLUDE_VIDEOS) != 0) {
- try {
- l.add(new VideoList(cr, VIDEO_STORAGE_URI, sort, bucketId));
- } catch (UnsupportedOperationException ex) {
- // ignore exception
- }
+ l.add(new VideoList(VIDEO_STORAGE_URI, sort, bucketId));
}
}
if (location == DataLocation.INTERNAL || location == DataLocation.ALL) {
if ((inclusion & INCLUDE_IMAGES) != 0) {
- try {
- l.add(new ImageList(cr,
- Images.Media.INTERNAL_CONTENT_URI,
- Images.Thumbnails.INTERNAL_CONTENT_URI,
- sort, bucketId));
- } catch (UnsupportedOperationException ex) {
- // ignore exception
- }
+ l.add(new ImageList(
+ Images.Media.INTERNAL_CONTENT_URI,
+ Images.Thumbnails.INTERNAL_CONTENT_URI,
+ sort, bucketId));
}
if ((inclusion & INCLUDE_DRM_IMAGES) != 0) {
- try {
- l.add(new DrmImageList(cr,
- DrmStore.Images.CONTENT_URI,
- sort, bucketId));
- } catch (UnsupportedOperationException ex) {
- // ignore exception
- }
+ l.add(new DrmImageList(
+ DrmStore.Images.CONTENT_URI, sort, bucketId));
}
}
// Optimization: If some of the lists are empty, remove them.
// If there is only one remaining list, return it directly.
-
- Iterator<IImageList> iter = l.iterator();
+ Iterator<BaseImageList> iter = l.iterator();
while (iter.hasNext()) {
- IImageList sublist = iter.next();
- if (sublist.isEmpty()) {
- iter.remove();
- }
+ BaseImageList sublist = iter.next();
+ sublist.open(cr);
+ if (sublist.isEmpty()) iter.remove();
+ sublist.close();
}
if (l.size() == 1) {
- return l.get(0);
+ BaseImageList list = l.get(0);
+ list.open(cr);
+ return list;
}
- IImageList [] imageList = l.toArray(new IImageList[l.size()]);
- return new ImageListUber(imageList, sort);
+ ImageListUber uber = new ImageListUber(
+ l.toArray(new IImageList[l.size()]), sort);
+ uber.open(cr);
+ return uber;
}
private static boolean checkFsWritable() {
diff --git a/src/com/android/camera/gallery/BaseImageList.java b/src/com/android/camera/gallery/BaseImageList.java
index 1d29231..a006689 100644
--- a/src/com/android/camera/gallery/BaseImageList.java
+++ b/src/com/android/camera/gallery/BaseImageList.java
@@ -26,6 +26,7 @@ import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
+import android.os.Parcel;
import android.os.SystemClock;
import android.provider.BaseColumns;
import android.provider.MediaStore.Images.ImageColumns;
@@ -56,16 +57,43 @@ public abstract class BaseImageList implements IImageList {
protected Uri mThumbUri;
protected boolean mCursorDeactivated = false;
- public BaseImageList(ContentResolver cr, Uri uri, int sort,
- String bucketId) {
+ public BaseImageList(Uri uri, int sort, String bucketId) {
mSort = sort;
mBaseUri = uri;
mBucketId = bucketId;
- mContentResolver = cr;
mMiniThumbFile = new MiniThumbFile(uri);
+ }
+
+ protected BaseImageList(Parcel in) {
+ mSort = in.readInt();
+ mBaseUri = (Uri) in.readParcelable(null);
+ mBucketId = in.readString();
+ mMiniThumbFile = new MiniThumbFile(mBaseUri);
+ }
+
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(mSort);
+ out.writeParcelable(mBaseUri, flags);
+ out.writeString(mBucketId);
+ }
+
+ public void open(ContentResolver resolver) {
+ mContentResolver = resolver;
mCursor = createCursor();
}
+ public void close() {
+ mContentResolver = null;
+ if (mCursor != null) {
+ mCursor.close();
+ mCursor = null;
+ }
+ }
+
+ public int describeContents() {
+ return 0;
+ }
+
/**
* Store a given thumbnail in the database.
*/
diff --git a/src/com/android/camera/gallery/DrmImageList.java b/src/com/android/camera/gallery/DrmImageList.java
index 2a55343..0a88f26 100644
--- a/src/com/android/camera/gallery/DrmImageList.java
+++ b/src/com/android/camera/gallery/DrmImageList.java
@@ -22,6 +22,7 @@ import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
+import android.os.Parcel;
import android.provider.DrmStore;
/**
@@ -40,9 +41,8 @@ public class DrmImageList extends ImageList implements IImageList {
private static final int INDEX_DATA_PATH = 1;
private static final int INDEX_MIME_TYPE = 2;
- public DrmImageList(ContentResolver cr, Uri imageUri,
- int sort, String bucketId) {
- super(cr, imageUri, null, sort, bucketId);
+ public DrmImageList(Uri imageUri, int sort, String bucketId) {
+ super(imageUri, null, sort, bucketId);
}
@Override
@@ -51,6 +51,22 @@ public class DrmImageList extends ImageList implements IImageList {
mBaseUri, DRM_IMAGE_PROJECTION, null, null, sortOrder());
}
+ @SuppressWarnings("hiding")
+ public static final Creator<DrmImageList> CREATOR =
+ new Creator<DrmImageList>() {
+ public DrmImageList createFromParcel(Parcel in) {
+ return new DrmImageList(in);
+ }
+
+ public DrmImageList[] newArray(int size) {
+ return new DrmImageList[size];
+ }
+ };
+
+ protected DrmImageList(Parcel in) {
+ super(in);
+ }
+
@Override
public void checkThumbnail(int index) {
}
@@ -108,4 +124,4 @@ public class DrmImageList extends ImageList implements IImageList {
mSort == ImageManager.SORT_ASCENDING ? " ASC" : " DESC";
return DrmStore.Images.TITLE + ascending + "," + DrmStore.Images._ID;
}
-} \ No newline at end of file
+}
diff --git a/src/com/android/camera/gallery/IImageList.java b/src/com/android/camera/gallery/IImageList.java
index b334e67..8eed1be 100644
--- a/src/com/android/camera/gallery/IImageList.java
+++ b/src/com/android/camera/gallery/IImageList.java
@@ -16,7 +16,9 @@
package com.android.camera.gallery;
+import android.content.ContentResolver;
import android.net.Uri;
+import android.os.Parcelable;
import java.io.IOException;
import java.util.HashMap;
@@ -44,23 +46,22 @@ import java.util.HashMap;
/**
* The interface of all image collections used in gallery.
*/
-public interface IImageList {
+public interface IImageList extends Parcelable {
public HashMap<String, String> getBucketIds();
- public abstract void deactivate();
+ public void deactivate();
/**
* Returns the count of image objects.
*
* @return the number of images
*/
- public abstract int getCount();
+ public int getCount();
/**
* @return true if the count of image objects is zero.
*/
-
- public abstract boolean isEmpty();
+ public boolean isEmpty();
/**
* Returns the image at the ith position.
@@ -68,7 +69,7 @@ public interface IImageList {
* @param i the position
* @return the image at the ith position
*/
- public abstract IImage getImageAt(int i);
+ public IImage getImageAt(int i);
/**
* Returns the image with a particular Uri.
@@ -76,20 +77,20 @@ public interface IImageList {
* @param uri
* @return the image with a particular Uri. null if not found.
*/
- public abstract IImage getImageForUri(Uri uri);
+ public IImage getImageForUri(Uri uri);
/**
*
* @param image
* @return true if the image was removed.
*/
- public abstract boolean removeImage(IImage image);
+ public boolean removeImage(IImage image);
/**
* Removes the image at the ith position.
* @param i the position
*/
- public abstract boolean removeImageAt(int i);
+ public boolean removeImageAt(int i);
public int getImageIndex(IImage image);
@@ -97,5 +98,15 @@ public interface IImageList {
* Generate thumbnail for the image (if it has not been generated.)
* @param index the position of the image
*/
- public abstract void checkThumbnail(int index) throws IOException;
+ public void checkThumbnail(int index) throws IOException;
+
+ /**
+ * Opens this list for operation.
+ */
+ public void open(ContentResolver resolver);
+
+ /**
+ * Closes this list to release resources, no further operation is allowed.
+ */
+ public void close();
}
diff --git a/src/com/android/camera/gallery/ImageList.java b/src/com/android/camera/gallery/ImageList.java
index 2c96265..563c657 100644
--- a/src/com/android/camera/gallery/ImageList.java
+++ b/src/com/android/camera/gallery/ImageList.java
@@ -18,9 +18,9 @@ package com.android.camera.gallery;
import com.android.camera.ImageManager;
-import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
+import android.os.Parcel;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.Media;
@@ -61,12 +61,32 @@ public class ImageList extends BaseImageList implements IImageList {
/**
* ImageList constructor.
*/
- public ImageList(ContentResolver cr, Uri imageUri,
- Uri thumbUri, int sort, String bucketId) {
- super(cr, imageUri, sort, bucketId);
+ public ImageList(Uri imageUri, Uri thumbUri, int sort, String bucketId) {
+ super(imageUri, sort, bucketId);
mThumbUri = thumbUri;
}
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ super.writeToParcel(out, flags);
+ out.writeParcelable(mThumbUri, flags);
+ }
+
+ public static final Creator<ImageList> CREATOR = new Creator<ImageList>() {
+ public ImageList createFromParcel(Parcel in) {
+ return new ImageList(in);
+ }
+
+ public ImageList[] newArray(int size) {
+ return new ImageList[size];
+ }
+ };
+
+ protected ImageList(Parcel in) {
+ super(in);
+ mThumbUri = (Uri) in.readParcelable(null);
+ }
+
private static final String WHERE_CLAUSE =
"(" + Media.MIME_TYPE + " in (?, ?, ?))";
private static final String WHERE_CLAUSE_WITH_BUCKET_ID =
diff --git a/src/com/android/camera/gallery/ImageListUber.java b/src/com/android/camera/gallery/ImageListUber.java
index 4962094..69bc2e1 100644
--- a/src/com/android/camera/gallery/ImageListUber.java
+++ b/src/com/android/camera/gallery/ImageListUber.java
@@ -19,8 +19,11 @@ package com.android.camera.gallery;
import com.android.camera.ImageManager;
import com.android.camera.Util;
+import android.content.ContentResolver;
import android.net.Uri;
import android.util.Log;
+import android.os.Parcel;
+import android.os.Parcelable;
import java.io.IOException;
import java.util.Arrays;
@@ -31,7 +34,6 @@ import java.util.PriorityQueue;
/**
* A union of different <code>IImageList</code>.
*/
-//TODO: add unittest for this class
public class ImageListUber implements IImageList {
@SuppressWarnings("unused")
private static final String TAG = "ImageListUber";
@@ -58,12 +60,42 @@ public class ImageListUber implements IImageList {
sort == ImageManager.SORT_ASCENDING
? new AscendingComparator()
: new DescendingComparator());
- for (int i = 0, n = sublist.length; i < n; ++i) {
- MergeSlot slot = new MergeSlot(sublist[i], i);
+ }
+
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeParcelableArray(mSubList, flags);
+ out.writeInt(mQueue.comparator() instanceof AscendingComparator
+ ? ImageManager.SORT_ASCENDING
+ : ImageManager.SORT_DESCENDING);
+ }
+
+ protected ImageListUber(Parcel in) {
+ Parcelable array[] = in.readParcelableArray(null);
+ mSubList = new IImageList[array.length];
+ System.arraycopy(array, 0, mSubList, 0, array.length);
+ int sort = in.readInt();
+ mSkipCounts = new int[mSubList.length];
+ mQueue = new PriorityQueue<MergeSlot>(4,
+ sort == ImageManager.SORT_ASCENDING
+ ? new AscendingComparator()
+ : new DescendingComparator());
+ for (int i = 0, n = mSubList.length; i < n; ++i) {
+ MergeSlot slot = new MergeSlot(mSubList[i], i);
if (slot.next()) mQueue.add(slot);
}
}
+ public static final Creator<ImageListUber> CREATOR =
+ new Creator<ImageListUber>() {
+ public ImageListUber createFromParcel(Parcel in) {
+ return new ImageListUber(in);
+ }
+
+ public ImageListUber[] newArray(int size) {
+ return new ImageListUber[size];
+ }
+ };
+
public HashMap<String, String> getBucketIds() {
HashMap<String, String> hashMap = new HashMap<String, String>();
for (IImageList list : mSubList) {
@@ -299,4 +331,28 @@ public class ImageListUber implements IImageList {
return true;
}
}
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void open(ContentResolver cr) {
+ for (int i = 0, n = mSubList.length; i < n; ++i) {
+ IImageList list = mSubList[i];
+ if (list instanceof BaseImageList) {
+ ((BaseImageList) list).open(cr);
+ }
+ MergeSlot slot = new MergeSlot(list, i);
+ if (slot.next()) mQueue.add(slot);
+ }
+ }
+
+ public void close() {
+ for (int i = 0, n = mSubList.length; i < n; ++i) {
+ IImageList list = mSubList[i];
+ if (list instanceof BaseImageList) {
+ ((BaseImageList) list).close();
+ }
+ }
+ }
}
diff --git a/src/com/android/camera/gallery/SingleImageList.java b/src/com/android/camera/gallery/SingleImageList.java
index 6feca73..1156c29 100644
--- a/src/com/android/camera/gallery/SingleImageList.java
+++ b/src/com/android/camera/gallery/SingleImageList.java
@@ -34,11 +34,15 @@ public class SingleImageList extends BaseImageList {
@SuppressWarnings("unused")
private static final String TAG = "BaseImageList";
- private final IImage mSingleImage;
+ private IImage mSingleImage;
- public SingleImageList(ContentResolver cr, Uri uri) {
- super(cr, uri, ImageManager.SORT_ASCENDING, null);
- mSingleImage = new UriImage(this, cr, uri);
+ public SingleImageList(Uri uri) {
+ super(uri, ImageManager.SORT_ASCENDING, null);
+ }
+
+ @Override
+ public void open(ContentResolver resolver) {
+ mSingleImage = new UriImage(this, resolver, mBaseUri);
}
public HashMap<String, String> getBucketIds() {
diff --git a/src/com/android/camera/gallery/VideoList.java b/src/com/android/camera/gallery/VideoList.java
index 9f40dc2..4962343 100644
--- a/src/com/android/camera/gallery/VideoList.java
+++ b/src/com/android/camera/gallery/VideoList.java
@@ -18,9 +18,9 @@ package com.android.camera.gallery;
import com.android.camera.ImageManager;
-import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
+import android.os.Parcel;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Video.Media;
@@ -71,8 +71,22 @@ public class VideoList extends BaseImageList {
miniThumbMagic, mimeType, dateTaken, title, displayName);
}
- public VideoList(ContentResolver cr, Uri uri, int sort, String bucketId) {
- super(cr, uri, sort, bucketId);
+ public VideoList(Uri uri, int sort, String bucketId) {
+ super(uri, sort, bucketId);
+ }
+
+ public static final Creator<VideoList> CREATOR = new Creator<VideoList>() {
+ public VideoList createFromParcel(Parcel in) {
+ return new VideoList(in);
+ }
+
+ public VideoList[] newArray(int size) {
+ return new VideoList[size];
+ }
+ };
+
+ protected VideoList(Parcel in) {
+ super(in);
}
public HashMap<String, String> getBucketIds() {
@@ -118,4 +132,4 @@ public class VideoList extends BaseImageList {
return Media.DATE_TAKEN +
(mSort == ImageManager.SORT_ASCENDING ? " ASC " : " DESC");
}
-} \ No newline at end of file
+}