summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2009-08-25 18:28:29 +0800
committerChih-Chung Chang <chihchung@google.com>2009-08-26 15:34:23 +0800
commitf5bf8ca5870fed38fe91e3e018ebc13cc1738364 (patch)
tree1a2d1f798d583768a0a29d3f27633c2062bee406 /src
parent3d66a954bc3b809669c762341065f29a4c5c0689 (diff)
downloadpackages_apps_LegacyCamera-f5bf8ca5870fed38fe91e3e018ebc13cc1738364.zip
packages_apps_LegacyCamera-f5bf8ca5870fed38fe91e3e018ebc13cc1738364.tar.gz
packages_apps_LegacyCamera-f5bf8ca5870fed38fe91e3e018ebc13cc1738364.tar.bz2
Create ImageListParam as a spec for creating image lists.
Also merge deactivate() and close(). Change-Id: Idc76eda25bfcefab949e46412dca366228b3f437
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/Camera.java4
-rw-r--r--src/com/android/camera/CropImage.java6
-rw-r--r--src/com/android/camera/GalleryPicker.java17
-rw-r--r--src/com/android/camera/GridViewSpecial.java2
-rw-r--r--src/com/android/camera/ImageGallery.java26
-rw-r--r--src/com/android/camera/ImageManager.java262
-rw-r--r--src/com/android/camera/ReviewImage.java36
-rw-r--r--src/com/android/camera/VideoCamera.java7
-rw-r--r--src/com/android/camera/ViewImage.java48
-rw-r--r--src/com/android/camera/gallery/BaseImageList.java41
-rw-r--r--src/com/android/camera/gallery/DrmImageList.java22
-rw-r--r--src/com/android/camera/gallery/IImageList.java10
-rw-r--r--src/com/android/camera/gallery/ImageList.java28
-rw-r--r--src/com/android/camera/gallery/ImageListUber.java72
-rw-r--r--src/com/android/camera/gallery/SingleImageList.java14
-rw-r--r--src/com/android/camera/gallery/VideoList.java20
16 files changed, 266 insertions, 349 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index 04b47bd..f724760 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -1301,7 +1301,7 @@ public class Camera extends Activity implements View.OnClickListener,
}
private void updateLastImage() {
- IImageList list = ImageManager.allImages(
+ IImageList list = ImageManager.makeImageList(
mContentResolver,
dataLocation(),
ImageManager.INCLUDE_IMAGES,
@@ -1315,7 +1315,7 @@ public class Camera extends Activity implements View.OnClickListener,
} else {
mThumbController.setData(null, null);
}
- list.deactivate();
+ list.close();
}
private void restartPreview() {
diff --git a/src/com/android/camera/CropImage.java b/src/com/android/camera/CropImage.java
index 3d47edd..bdb3fa0 100644
--- a/src/com/android/camera/CropImage.java
+++ b/src/com/android/camera/CropImage.java
@@ -133,8 +133,8 @@ public class CropImage extends MonitoredActivity {
if (mBitmap == null) {
Uri target = intent.getData();
- mAllImages = ImageManager.makeImageList(target,
- mContentResolver, ImageManager.SORT_ASCENDING);
+ mAllImages = ImageManager.makeImageList(mContentResolver, target,
+ ImageManager.SORT_ASCENDING);
mImage = mAllImages.getImageForUri(target);
if (mImage != null) {
// Don't read in really large bitmaps. Use the (big) thumbnail
@@ -419,7 +419,7 @@ public class CropImage extends MonitoredActivity {
@Override
protected void onDestroy() {
if (mAllImages != null) {
- mAllImages.deactivate();
+ mAllImages.close();
}
super.onDestroy();
}
diff --git a/src/com/android/camera/GalleryPicker.java b/src/com/android/camera/GalleryPicker.java
index 9ded305..b0f8531 100644
--- a/src/com/android/camera/GalleryPicker.java
+++ b/src/com/android/camera/GalleryPicker.java
@@ -425,22 +425,23 @@ public class GalleryPicker extends Activity {
private void checkBucketIds(ArrayList<Item> allItems) {
final IImageList allImages;
if (!mScanning && !mUnmounted) {
- allImages = ImageManager.allImages(
+ allImages = ImageManager.makeImageList(
getContentResolver(),
ImageManager.DataLocation.ALL,
ImageManager.INCLUDE_IMAGES | ImageManager.INCLUDE_VIDEOS,
- ImageManager.SORT_DESCENDING);
+ ImageManager.SORT_DESCENDING,
+ null);
} else {
- allImages = ImageManager.emptyImageList();
+ allImages = ImageManager.makeEmptyImageList();
}
if (mAbort) {
- allImages.deactivate();
+ allImages.close();
return;
}
HashMap<String, String> hashMap = allImages.getBucketIds();
- allImages.deactivate();
+ allImages.close();
if (mAbort) return;
for (Map.Entry<String, String> entry : hashMap.entrySet()) {
@@ -748,14 +749,14 @@ public class GalleryPicker extends Activity {
}
// image lists created by createImageList() are collected in mAllLists.
- // They will be deactivated in clearImageList, so they don't hold open files
+ // They will be closed in clearImageList, so they don't hold open files
// on SD card. We will be killed if we don't close files when the SD card
// is unmounted.
ArrayList<IImageList> mAllLists = new ArrayList<IImageList>();
private IImageList createImageList(int mediaTypes, String bucketId,
ContentResolver cr) {
- IImageList list = ImageManager.allImages(
+ IImageList list = ImageManager.makeImageList(
cr,
ImageManager.DataLocation.ALL,
mediaTypes,
@@ -767,7 +768,7 @@ public class GalleryPicker extends Activity {
private void clearImageLists() {
for (IImageList list : mAllLists) {
- list.deactivate();
+ list.close();
}
mAllLists.clear();
}
diff --git a/src/com/android/camera/GridViewSpecial.java b/src/com/android/camera/GridViewSpecial.java
index 21dc3fe..8b85b67 100644
--- a/src/com/android/camera/GridViewSpecial.java
+++ b/src/com/android/camera/GridViewSpecial.java
@@ -113,7 +113,7 @@ class GridViewSpecial extends View {
private ImageLoader mLoader;
private Listener mListener = null;
private DrawAdapter mDrawAdapter = null;
- private IImageList mAllImages = ImageManager.emptyImageList();
+ private IImageList mAllImages = ImageManager.makeEmptyImageList();
private int mSizeChoice = 1; // default is big cell size
// These are set in onLayout().
diff --git a/src/com/android/camera/ImageGallery.java b/src/com/android/camera/ImageGallery.java
index 5803f48..2f6527a 100644
--- a/src/com/android/camera/ImageGallery.java
+++ b/src/com/android/camera/ImageGallery.java
@@ -71,6 +71,7 @@ public class ImageGallery extends Activity implements
private static final String TAG = "ImageGallery";
private static final float INVALID_POSITION = -1f;
+ private ImageManager.ImageListParam mParam;
private IImageList mAllImages;
private int mInclusion;
boolean mSortAscending = false;
@@ -369,8 +370,8 @@ public class ImageGallery extends Activity implements
}
// Now that we've paused the threads that are using the cursor it is
- // safe to deactivate it.
- mAllImages.deactivate();
+ // safe to close it.
+ mAllImages.close();
mAllImages = null;
}
@@ -378,7 +379,7 @@ public class ImageGallery extends Activity implements
stopCheckingThumbnails();
mGvs.stop();
if (mAllImages != null) {
- mAllImages.deactivate();
+ mAllImages.close();
mAllImages = null;
}
@@ -396,7 +397,8 @@ public class ImageGallery extends Activity implements
true);
}
- mAllImages = allImages(!unmounted && !scanning);
+ mParam = allImages(!unmounted && !scanning);
+ mAllImages = ImageManager.makeImageList(getContentResolver(), mParam);
mGvs.setImageList(mAllImages);
mGvs.setDrawAdapter(this);
@@ -608,15 +610,14 @@ public class ImageGallery extends Activity implements
}
}
- // Returns the image list which contains the subset of image/video we want.
- private IImageList allImages(boolean storageAvailable) {
- Uri uri = getIntent().getData();
- IImageList imageList;
+ // Returns the image list parameter which contains the subset of image/video
+ // we want.
+ private ImageManager.ImageListParam allImages(boolean storageAvailable) {
if (!storageAvailable) {
- imageList = ImageManager.emptyImageList();
+ return ImageManager.getEmptyImageListParam();
} else {
- imageList = ImageManager.allImages(
- getContentResolver(),
+ Uri uri = getIntent().getData();
+ return ImageManager.getImageListParam(
ImageManager.DataLocation.EXTERNAL,
mInclusion,
mSortAscending
@@ -626,7 +627,6 @@ public class ImageGallery extends Activity implements
? uri.getQueryParameter("bucketId")
: null);
}
- return imageList;
}
private void toggleMultiSelected(IImage image) {
@@ -664,7 +664,7 @@ public class ImageGallery extends Activity implements
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
intent = new Intent(this, ViewImage.class);
- intent.putExtra(ViewImage.KEY_IMAGE_LIST, mAllImages);
+ intent.putExtra(ViewImage.KEY_IMAGE_LIST, mParam);
intent.setData(image.fullSizeImageUri());
}
startActivity(intent);
diff --git a/src/com/android/camera/ImageManager.java b/src/com/android/camera/ImageManager.java
index fbcca6f..ec46c16 100644
--- a/src/com/android/camera/ImageManager.java
+++ b/src/com/android/camera/ImageManager.java
@@ -38,6 +38,7 @@ import android.location.Location;
import android.net.Uri;
import android.os.Environment;
import android.os.Parcel;
+import android.os.Parcelable;
import android.provider.DrmStore;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
@@ -65,23 +66,68 @@ public class ImageManager {
private static final Uri VIDEO_STORAGE_URI =
Uri.parse("content://media/external/video/media");
- /**
- * Enumerate type for the location of the images in gallery.
- */
- public static enum DataLocation { NONE, INTERNAL, EXTERNAL, ALL }
+ // ImageListParam specifies all the parameters we need to create an image
+ // list (we also need a ContentResolver).
+ public static class ImageListParam implements Parcelable {
+ public DataLocation mLocation;
+ public int mInclusion;
+ public int mSort;
+ public String mBucketId;
- public static final Bitmap DEFAULT_THUMBNAIL =
- Bitmap.createBitmap(32, 32, Bitmap.Config.RGB_565);
- public static final Bitmap NO_IMAGE_BITMAP =
- Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
+ // This is only used if we are creating a single image list.
+ public Uri mSingleImageUri;
- public static final int SORT_ASCENDING = 1;
- public static final int SORT_DESCENDING = 2;
+ // This is only used if we are creating an empty image list.
+ public boolean mIsEmptyImageList;
+
+ public ImageListParam() {}
+
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(mLocation.ordinal());
+ out.writeInt(mInclusion);
+ out.writeInt(mSort);
+ out.writeString(mBucketId);
+ out.writeParcelable(mSingleImageUri, flags);
+ out.writeInt(mIsEmptyImageList ? 1 : 0);
+ }
+
+ private ImageListParam(Parcel in) {
+ mLocation = DataLocation.values()[in.readInt()];
+ mInclusion = in.readInt();
+ mSort = in.readInt();
+ mBucketId = in.readString();
+ mSingleImageUri = in.readParcelable(null);
+ mIsEmptyImageList = (in.readInt() != 0);
+ }
+
+ public static final Parcelable.Creator CREATOR
+ = new Parcelable.Creator() {
+ public ImageListParam createFromParcel(Parcel in) {
+ return new ImageListParam(in);
+ }
+
+ public ImageListParam[] newArray(int size) {
+ return new ImageListParam[size];
+ }
+ };
+
+ public int describeContents() {
+ return 0;
+ }
+ }
+
+ // Location
+ public static enum DataLocation { NONE, INTERNAL, EXTERNAL, ALL }
+ // Inclusion
public static final int INCLUDE_IMAGES = (1 << 0);
public static final int INCLUDE_DRM_IMAGES = (1 << 1);
public static final int INCLUDE_VIDEOS = (1 << 2);
+ // Sort
+ public static final int SORT_ASCENDING = 1;
+ public static final int SORT_DESCENDING = 2;
+
public static final String CAMERA_IMAGE_BUCKET_NAME =
Environment.getExternalStorageDirectory().toString()
+ "/DCIM/Camera";
@@ -223,8 +269,7 @@ public class ImageManager {
try {
long id = ContentUris.parseId(mUri);
BaseImageList il = new ImageList(
- STORAGE_URI, THUMB_URI, SORT_ASCENDING, null);
- il.open(mCr);
+ mCr, STORAGE_URI, THUMB_URI, SORT_ASCENDING, null);
// TODO: Redesign the process of adding new images. We should
// create an <code>IImage</code> in "ImageManager.addImage"
@@ -269,33 +314,97 @@ public class ImageManager {
uri, cr, orientation, source, jpegData);
}
- public static IImageList makeImageList(Uri uri, ContentResolver cr,
+ // This is the factory function to create an image list.
+ public static IImageList makeImageList(ContentResolver cr,
+ ImageListParam param) {
+
+ DataLocation location = param.mLocation;
+ int inclusion = param.mInclusion;
+ int sort = param.mSort;
+ String bucketId = param.mBucketId;
+ Uri singleImageUri = param.mSingleImageUri;
+ boolean isEmptyImageList = param.mIsEmptyImageList;
+
+ if (cr == null) {
+ return null;
+ }
+
+ if (isEmptyImageList) {
+ return new EmptyImageList();
+ }
+
+ if (singleImageUri != null) {
+ return new SingleImageList(cr, singleImageUri);
+ }
+
+ // false ==> don't require write access
+ boolean haveSdCard = hasStorage(false);
+
+ // use this code to merge videos and stills into the same list
+ ArrayList<BaseImageList> l = new ArrayList<BaseImageList>();
+
+ if (haveSdCard && location != DataLocation.INTERNAL) {
+ if ((inclusion & INCLUDE_IMAGES) != 0) {
+ l.add(new ImageList(
+ cr, STORAGE_URI, THUMB_URI, sort, bucketId));
+ }
+ if ((inclusion & INCLUDE_VIDEOS) != 0) {
+ l.add(new VideoList(cr, VIDEO_STORAGE_URI, sort, bucketId));
+ }
+ }
+ if (location == DataLocation.INTERNAL || location == DataLocation.ALL) {
+ if ((inclusion & INCLUDE_IMAGES) != 0) {
+ l.add(new ImageList(cr,
+ Images.Media.INTERNAL_CONTENT_URI,
+ Images.Thumbnails.INTERNAL_CONTENT_URI,
+ sort, bucketId));
+ }
+ if ((inclusion & INCLUDE_DRM_IMAGES) != 0) {
+ l.add(new DrmImageList(
+ cr, 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<BaseImageList> iter = l.iterator();
+ while (iter.hasNext()) {
+ BaseImageList sublist = iter.next();
+ if (sublist.isEmpty()) iter.remove();
+ }
+
+ if (l.size() == 1) {
+ BaseImageList list = l.get(0);
+ return list;
+ }
+
+ ImageListUber uber = new ImageListUber(
+ l.toArray(new IImageList[l.size()]), sort);
+ return uber;
+ }
+
+ // This is a convenience function to create an image list from a Uri.
+ public static IImageList makeImageList(ContentResolver cr, Uri uri,
int sort) {
String uriString = (uri != null) ? uri.toString() : "";
// TODO: we need to figure out whether we're viewing
// DRM images in a better way. Is there a constant
// for content://drm somewhere??
- IImageList imageList;
if (uriString.startsWith("content://drm")) {
- imageList = ImageManager.allImages(
- cr, ImageManager.DataLocation.ALL,
- ImageManager.INCLUDE_DRM_IMAGES, sort);
+ return makeImageList(cr, DataLocation.ALL, INCLUDE_DRM_IMAGES, sort,
+ null);
} else if (uriString.startsWith("content://media/external/video")) {
- imageList = ImageManager.allImages(
- cr, ImageManager.DataLocation.EXTERNAL,
- ImageManager.INCLUDE_VIDEOS, sort);
+ return makeImageList(cr, DataLocation.EXTERNAL, INCLUDE_VIDEOS, sort,
+ null);
} else if (isSingleImageMode(uriString)) {
- imageList = new SingleImageList(uri);
- ((SingleImageList) imageList).open(cr);
+ return makeSingleImageList(cr, uri);
} else {
String bucketId = uri.getQueryParameter("bucketId");
- imageList = ImageManager.allImages(
- cr, ImageManager.DataLocation.ALL,
- ImageManager.INCLUDE_IMAGES, sort, bucketId);
+ return makeImageList(cr, DataLocation.ALL, INCLUDE_IMAGES, sort,
+ bucketId);
}
- return imageList;
}
static boolean isSingleImageMode(String uriString) {
@@ -306,29 +415,12 @@ 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) {
}
- public void deactivate() {
- }
-
public HashMap<String, String> getBucketIds() {
return new HashMap<String, String>();
}
@@ -369,69 +461,41 @@ public class ImageManager {
}
}
- public static IImageList emptyImageList() {
- return new EmptyImageList();
+ public static ImageListParam getImageListParam(DataLocation location,
+ int inclusion, int sort, String bucketId) {
+ ImageListParam param = new ImageListParam();
+ param.mLocation = location;
+ param.mInclusion = inclusion;
+ param.mSort = sort;
+ param.mBucketId = bucketId;
+ return param;
}
- public static IImageList allImages(ContentResolver cr,
- DataLocation location, int inclusion, int sort) {
- return allImages(cr, location, inclusion, sort, null);
+ public static ImageListParam getSingleImageListParam(Uri uri) {
+ ImageListParam param = new ImageListParam();
+ param.mSingleImageUri = uri;
+ return param;
}
- public static IImageList allImages(ContentResolver cr,
- DataLocation location, int inclusion, int sort, String bucketId) {
- if (cr == null) {
- return null;
- }
-
- // false ==> don't require write access
- boolean haveSdCard = hasStorage(false);
-
- // use this code to merge videos and stills into the same list
- ArrayList<BaseImageList> l = new ArrayList<BaseImageList>();
-
- if (haveSdCard && location != DataLocation.INTERNAL) {
- if ((inclusion & INCLUDE_IMAGES) != 0) {
- l.add(new ImageList(
- STORAGE_URI, THUMB_URI, sort, bucketId));
- }
- if ((inclusion & INCLUDE_VIDEOS) != 0) {
- l.add(new VideoList(VIDEO_STORAGE_URI, sort, bucketId));
- }
- }
- if (location == DataLocation.INTERNAL || location == DataLocation.ALL) {
- if ((inclusion & INCLUDE_IMAGES) != 0) {
- l.add(new ImageList(
- Images.Media.INTERNAL_CONTENT_URI,
- Images.Thumbnails.INTERNAL_CONTENT_URI,
- sort, bucketId));
- }
- if ((inclusion & INCLUDE_DRM_IMAGES) != 0) {
- l.add(new DrmImageList(
- DrmStore.Images.CONTENT_URI, sort, bucketId));
- }
- }
+ public static ImageListParam getEmptyImageListParam() {
+ ImageListParam param = new ImageListParam();
+ param.mIsEmptyImageList = true;
+ return param;
+ }
- // Optimization: If some of the lists are empty, remove them.
- // If there is only one remaining list, return it directly.
- Iterator<BaseImageList> iter = l.iterator();
- while (iter.hasNext()) {
- BaseImageList sublist = iter.next();
- sublist.open(cr);
- if (sublist.isEmpty()) iter.remove();
- sublist.close();
- }
+ public static IImageList makeImageList(ContentResolver cr,
+ DataLocation location, int inclusion, int sort, String bucketId) {
+ ImageListParam param = getImageListParam(location, inclusion, sort,
+ bucketId);
+ return makeImageList(cr, param);
+ }
- if (l.size() == 1) {
- BaseImageList list = l.get(0);
- list.open(cr);
- return list;
- }
+ public static IImageList makeEmptyImageList() {
+ return makeImageList(null, getEmptyImageListParam());
+ }
- ImageListUber uber = new ImageListUber(
- l.toArray(new IImageList[l.size()]), sort);
- uber.open(cr);
- return uber;
+ public static IImageList makeSingleImageList(ContentResolver cr, Uri uri) {
+ return makeImageList(cr, getSingleImageListParam(uri));
}
private static boolean checkFsWritable() {
diff --git a/src/com/android/camera/ReviewImage.java b/src/com/android/camera/ReviewImage.java
index b972636..3eadbe9 100644
--- a/src/com/android/camera/ReviewImage.java
+++ b/src/com/android/camera/ReviewImage.java
@@ -88,6 +88,7 @@ public class ReviewImage extends Activity implements View.OnClickListener {
public static final String KEY_IMAGE_LIST = "image_list";
private static final String STATE_SHOW_CONTROLS = "show_controls";
+ ImageManager.ImageListParam mParam;
IImageList mAllImages;
private final ImageViewTouchBase [] mSlideShowImageViews =
@@ -465,17 +466,13 @@ public class ReviewImage extends Activity implements View.OnClickListener {
v.setRecycler(mCache);
}
- Uri uri = getIntent().getData();
- IImageList imageList = getIntent().getParcelableExtra(KEY_IMAGE_LIST);
+ mParam = getIntent().getParcelableExtra(KEY_IMAGE_LIST);
if (instanceState != null) {
- uri = instanceState.getParcelable(STATE_URI);
+ mSavedUri = instanceState.getParcelable(STATE_URI);
mShowControls = instanceState.getBoolean(STATE_SHOW_CONTROLS, true);
- }
-
- if (!init(uri, imageList)) {
- finish();
- return;
+ } else {
+ mSavedUri = getIntent().getData();
}
int[] pickIds = {R.id.attach, R.id.cancel};
@@ -520,18 +517,15 @@ public class ReviewImage extends Activity implements View.OnClickListener {
}
private IImageList buildImageListFromUri(Uri uri) {
- String sortOrder = mPrefs.getString(
- "pref_gallery_sort_key", "descending");
int sort = ImageManager.SORT_ASCENDING;
- return ImageManager.makeImageList(uri, getContentResolver(), sort);
+ return ImageManager.makeImageList(getContentResolver(), uri, sort);
}
- private boolean init(Uri uri, IImageList imageList) {
+ private boolean init(Uri uri) {
if (uri == null) return false;
- mAllImages = (imageList == null)
+ mAllImages = (mParam == null)
? buildImageListFromUri(uri)
- : imageList;
- mAllImages.open(getContentResolver());
+ : ImageManager.makeImageList(getContentResolver(), mParam);
IImage image = mAllImages.getImageForUri(uri);
if (image == null) return false;
mCurrentPosition = mAllImages.getImageIndex(image);
@@ -557,7 +551,10 @@ public class ReviewImage extends Activity implements View.OnClickListener {
super.onStart();
mPaused = false;
- init(mSavedUri, mAllImages);
+ if (!init(mSavedUri)) {
+ finish();
+ return;
+ }
// normally this will never be zero but if one "backs" into this
// activity after removing the sdcard it could be zero. in that
@@ -591,9 +588,12 @@ public class ReviewImage extends Activity implements View.OnClickListener {
// removing all callback in the message queue
mHandler.removeAllGetterCallbacks();
- mSavedUri = getCurrentUri();
+ if (mAllImages != null) {
+ mSavedUri = getCurrentUri();
+ mAllImages.close();
+ mAllImages = null;
+ }
- mAllImages.deactivate();
hideOnScreenControls();
mImageView.clear();
mCache.clear();
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index 5821e67..49f3c29 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -1257,8 +1257,9 @@ public class VideoCamera extends Activity implements View.OnClickListener,
}
private void updateLastVideo() {
- IImageList list =
- ImageManager.allImages(mContentResolver, dataLocation(),
+ IImageList list = ImageManager.makeImageList(
+ mContentResolver,
+ dataLocation(),
ImageManager.INCLUDE_VIDEOS,
ImageManager.SORT_ASCENDING,
ImageManager.CAMERA_IMAGE_BUCKET_ID);
@@ -1270,7 +1271,7 @@ public class VideoCamera extends Activity implements View.OnClickListener,
} else {
mThumbController.setData(null, null);
}
- list.deactivate();
+ list.close();
}
private void updateRecordingTime() {
diff --git a/src/com/android/camera/ViewImage.java b/src/com/android/camera/ViewImage.java
index 386219e..52bc0c1 100644
--- a/src/com/android/camera/ViewImage.java
+++ b/src/com/android/camera/ViewImage.java
@@ -114,9 +114,7 @@ public class ViewImage extends Activity implements View.OnClickListener {
IImageList mAllImages;
- // this is used to store the state of the image list. Right now, it is the
- // image list itself.
- private IImageList mAllImagesState;
+ private ImageManager.ImageListParam mParam;
private int mSlideShowImageCurrent = 0;
private final ImageViewTouchBase [] mSlideShowImageViews =
@@ -555,26 +553,23 @@ public class ViewImage extends Activity implements View.OnClickListener {
mActionIconPanel = findViewById(R.id.action_icon_panel);
- Uri uri = getIntent().getData();
- IImageList imageList = getIntent().getParcelableExtra(KEY_IMAGE_LIST);
- boolean slideshow = intent.getBooleanExtra(EXTRA_SLIDESHOW, false);
+ mParam = getIntent().getParcelableExtra(KEY_IMAGE_LIST);
+ boolean slideshow;
if (instanceState != null) {
- uri = instanceState.getParcelable(STATE_URI);
+ mSavedUri = instanceState.getParcelable(STATE_URI);
slideshow = instanceState.getBoolean(STATE_SLIDESHOW, false);
mShowControls = instanceState.getBoolean(STATE_SHOW_CONTROLS, true);
- }
-
- if (!init(uri, imageList)) {
- finish();
- return;
+ } else {
+ mSavedUri = getIntent().getData();
+ slideshow = intent.getBooleanExtra(EXTRA_SLIDESHOW, false);
}
// We only show action icons for URIs that we know we can share and
// delete. Although we get read permission (for the images) from
// applications like MMS, we cannot pass the permission to other
// activities due to the current framework design.
- if (!MenuHelper.isWhiteListUri(uri)) {
+ if (!MenuHelper.isWhiteListUri(mSavedUri)) {
mShowActionIcons = false;
}
@@ -590,7 +585,7 @@ public class ViewImage extends Activity implements View.OnClickListener {
}
// Don't show the "delete" icon for SingleImageList.
- if (ImageManager.isSingleImageMode(uri.toString())) {
+ if (ImageManager.isSingleImageMode(mSavedUri.toString())) {
mActionIconPanel.findViewById(R.id.discard).setVisibility(View.GONE);
}
@@ -849,16 +844,14 @@ public class ViewImage extends Activity implements View.OnClickListener {
int sort = sortOrder.equals("ascending")
? ImageManager.SORT_ASCENDING
: ImageManager.SORT_DESCENDING;
- return ImageManager.makeImageList(uri, getContentResolver(), sort);
+ return ImageManager.makeImageList(getContentResolver(), uri, sort);
}
- private boolean init(Uri uri, IImageList imageList) {
+ private boolean init(Uri uri) {
if (uri == null) return false;
- mAllImagesState = (imageList == null)
+ mAllImages = (mParam == null)
? buildImageListFromUri(uri)
- : imageList;
- mAllImages = mAllImagesState;
- mAllImages.open(getContentResolver());
+ : ImageManager.makeImageList(getContentResolver(), mParam);
IImage image = mAllImages.getImageForUri(uri);
if (image == null) return false;
mCurrentPosition = mAllImages.getImageIndex(image);
@@ -885,7 +878,10 @@ public class ViewImage extends Activity implements View.OnClickListener {
super.onStart();
mPaused = false;
- init(mSavedUri, mAllImagesState);
+ if (!init(mSavedUri)) {
+ finish();
+ return;
+ }
// normally this will never be zero but if one "backs" into this
// activity after removing the sdcard it could be zero. in that
@@ -923,11 +919,11 @@ public class ViewImage extends Activity implements View.OnClickListener {
// removing all callback in the message queue
mHandler.removeAllGetterCallbacks();
- mSavedUri = getCurrentUri();
-
- mAllImages.deactivate();
- mAllImages.close();
- mAllImages = null;
+ if (mAllImages != null) {
+ mSavedUri = getCurrentUri();
+ mAllImages.close();
+ mAllImages = null;
+ }
hideOnScreenControls();
mImageView.clear();
diff --git a/src/com/android/camera/gallery/BaseImageList.java b/src/com/android/camera/gallery/BaseImageList.java
index ac0cafb..439182c 100644
--- a/src/com/android/camera/gallery/BaseImageList.java
+++ b/src/com/android/camera/gallery/BaseImageList.java
@@ -27,7 +27,6 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.net.Uri;
-import android.os.Parcel;
import android.provider.BaseColumns;
import android.provider.MediaStore.Images.ImageColumns;
import android.provider.MediaStore.Images.Thumbnails;
@@ -59,27 +58,11 @@ public abstract class BaseImageList implements IImageList {
protected Uri mThumbUri;
protected boolean mCursorDeactivated = false;
- public BaseImageList(Uri uri, int sort, String bucketId) {
+ public BaseImageList(ContentResolver resolver, Uri uri, int sort, String bucketId) {
mSort = sort;
mBaseUri = uri;
mBucketId = bucketId;
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();
@@ -105,8 +88,14 @@ public abstract class BaseImageList implements IImageList {
mCache.clear();
}
- // TODO: merge close() and deactivate()
public void close() {
+ try {
+ invalidateCursor();
+ } catch (IllegalStateException e) {
+ // IllegalStateException may be thrown if the cursor is stale.
+ Log.e(TAG, "Caught exception while deactivating cursor.", e);
+ }
+ mMiniThumbFile.deactivate();
mContentResolver = null;
if (mCursor != null) {
mCursor.close();
@@ -114,10 +103,6 @@ public abstract class BaseImageList implements IImageList {
}
}
- public int describeContents() {
- return 0;
- }
-
/**
* Store a given thumbnail in the database.
*/
@@ -348,16 +333,6 @@ public abstract class BaseImageList implements IImageList {
}
}
- public void deactivate() {
- try {
- invalidateCursor();
- } catch (IllegalStateException e) {
- // IllegalStateException may be thrown if the cursor is stale.
- Log.e(TAG, "Caught exception while deactivating cursor.", e);
- }
- mMiniThumbFile.deactivate();
- }
-
public int getCount() {
Cursor cursor = getCursor();
synchronized (cursor) {
diff --git a/src/com/android/camera/gallery/DrmImageList.java b/src/com/android/camera/gallery/DrmImageList.java
index 976a937..fdc43bd 100644
--- a/src/com/android/camera/gallery/DrmImageList.java
+++ b/src/com/android/camera/gallery/DrmImageList.java
@@ -22,7 +22,6 @@ import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
-import android.os.Parcel;
import android.provider.DrmStore;
/**
@@ -41,8 +40,9 @@ 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(Uri imageUri, int sort, String bucketId) {
- super(imageUri, null, sort, bucketId);
+ public DrmImageList(ContentResolver resolver, Uri imageUri, int sort,
+ String bucketId) {
+ super(resolver, imageUri, null, sort, bucketId);
}
@Override
@@ -51,22 +51,6 @@ 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) {
}
diff --git a/src/com/android/camera/gallery/IImageList.java b/src/com/android/camera/gallery/IImageList.java
index 8eed1be..9d8b597 100644
--- a/src/com/android/camera/gallery/IImageList.java
+++ b/src/com/android/camera/gallery/IImageList.java
@@ -18,7 +18,6 @@ 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;
@@ -46,11 +45,9 @@ import java.util.HashMap;
/**
* The interface of all image collections used in gallery.
*/
-public interface IImageList extends Parcelable {
+public interface IImageList {
public HashMap<String, String> getBucketIds();
- public void deactivate();
-
/**
* Returns the count of image objects.
*
@@ -101,11 +98,6 @@ public interface IImageList extends Parcelable {
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 33b8d01..88254d5 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,32 +61,12 @@ public class ImageList extends BaseImageList implements IImageList {
/**
* ImageList constructor.
*/
- public ImageList(Uri imageUri, Uri thumbUri, int sort, String bucketId) {
- super(imageUri, sort, bucketId);
+ public ImageList(ContentResolver resolver, Uri imageUri, Uri thumbUri,
+ int sort, String bucketId) {
+ super(resolver, 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 4a433dd..3c50976 100644
--- a/src/com/android/camera/gallery/ImageListUber.java
+++ b/src/com/android/camera/gallery/ImageListUber.java
@@ -18,8 +18,6 @@ package com.android.camera.gallery;
import android.content.ContentResolver;
import android.net.Uri;
-import android.os.Parcel;
-import android.os.Parcelable;
import com.android.camera.ImageManager;
import com.android.camera.Util;
@@ -60,38 +58,17 @@ public class ImageListUber implements IImageList {
sort == ImageManager.SORT_ASCENDING
? new AscendingComparator()
: new DescendingComparator());
- }
-
- 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(ImageListUber.class.getClassLoader());
- mSubList = new IImageList[array.length];
- System.arraycopy(array, 0, mSubList, 0, array.length);
- int sort = in.readInt();
+ mSkipList = new long[16];
+ mSkipListSize = 0;
mSkipCounts = new int[mSubList.length];
- mQueue = new PriorityQueue<MergeSlot>(4,
- sort == ImageManager.SORT_ASCENDING
- ? new AscendingComparator()
- : new DescendingComparator());
- }
-
- 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];
+ mLastListIndex = -1;
+ mQueue.clear();
+ for (int i = 0, n = mSubList.length; i < n; ++i) {
+ IImageList list = mSubList[i];
+ MergeSlot slot = new MergeSlot(list, i);
+ if (slot.next()) mQueue.add(slot);
}
- };
+ }
public HashMap<String, String> getBucketIds() {
HashMap<String, String> hashMap = new HashMap<String, String>();
@@ -115,12 +92,6 @@ public class ImageListUber implements IImageList {
}
}
- public void deactivate() {
- for (IImageList subList : mSubList) {
- subList.deactivate();
- }
- }
-
public int getCount() {
int count = 0;
for (IImageList subList : mSubList) {
@@ -333,32 +304,9 @@ public class ImageListUber implements IImageList {
}
}
- public int describeContents() {
- return 0;
- }
-
- public void open(ContentResolver cr) {
- mSkipList = new long[16];
- mSkipListSize = 0;
- mSkipCounts = new int[mSubList.length];
- mLastListIndex = -1;
- mQueue.clear();
- 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();
- }
+ mSubList[i].close();
}
}
}
diff --git a/src/com/android/camera/gallery/SingleImageList.java b/src/com/android/camera/gallery/SingleImageList.java
index 05230af..d5d56ed 100644
--- a/src/com/android/camera/gallery/SingleImageList.java
+++ b/src/com/android/camera/gallery/SingleImageList.java
@@ -36,13 +36,8 @@ public class SingleImageList extends BaseImageList {
private IImage mSingleImage;
- public SingleImageList(Uri uri) {
- super(uri, ImageManager.SORT_ASCENDING, null);
- }
-
- @Override
- public void open(ContentResolver resolver) {
- mContentResolver = resolver;
+ public SingleImageList(ContentResolver resolver, Uri uri) {
+ super(resolver, uri, ImageManager.SORT_ASCENDING, null);
mSingleImage = new UriImage(this, resolver, mBaseUri);
}
@@ -51,11 +46,6 @@ public class SingleImageList extends BaseImageList {
}
@Override
- public void deactivate() {
- // nothing to do here
- }
-
- @Override
public int getCount() {
return 1;
}
diff --git a/src/com/android/camera/gallery/VideoList.java b/src/com/android/camera/gallery/VideoList.java
index 965146d..a3f7780 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;
@@ -76,22 +76,8 @@ public class VideoList extends BaseImageList {
miniThumbMagic, mimeType, dateTaken, title, displayName);
}
- 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 VideoList(ContentResolver resolver, Uri uri, int sort, String bucketId) {
+ super(resolver, uri, sort, bucketId);
}
public HashMap<String, String> getBucketIds() {