summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2009-06-03 17:07:33 -0700
committerOwen Lin <owenlin@google.com>2009-06-03 17:07:33 -0700
commitf271893766a8ade5eea73fc65831f0dd678e3705 (patch)
treeea655547a55daa7de03e1d05290b8c69b303cf3d /src/com
parent0f9c339253b0fabed60efd731869e68d18893837 (diff)
downloadLegacyCamera-f271893766a8ade5eea73fc65831f0dd678e3705.zip
LegacyCamera-f271893766a8ade5eea73fc65831f0dd678e3705.tar.gz
LegacyCamera-f271893766a8ade5eea73fc65831f0dd678e3705.tar.bz2
Pass image list from ImageGallery to ViewImage to support the uber type
image list.
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/GalleryPicker.java3
-rw-r--r--src/com/android/camera/ImageGallery.java26
-rw-r--r--src/com/android/camera/ViewImage.java74
-rw-r--r--src/com/android/camera/gallery/BaseImageList.java9
-rw-r--r--src/com/android/camera/gallery/ImageListUber.java21
-rw-r--r--src/com/android/camera/gallery/VideoObject.java4
6 files changed, 55 insertions, 82 deletions
diff --git a/src/com/android/camera/GalleryPicker.java b/src/com/android/camera/GalleryPicker.java
index 6bfe2e4..d37b9be 100644
--- a/src/com/android/camera/GalleryPicker.java
+++ b/src/com/android/camera/GalleryPicker.java
@@ -413,8 +413,7 @@ public class GalleryPicker extends Activity {
allImages = ImageManager.allImages(
getContentResolver(),
ImageManager.DataLocation.ALL,
- ImageManager.INCLUDE_IMAGES
- | ImageManager.INCLUDE_VIDEOS,
+ ImageManager.INCLUDE_IMAGES | ImageManager.INCLUDE_VIDEOS,
ImageManager.SORT_DESCENDING);
} else {
allImages = ImageManager.emptyImageList();
diff --git a/src/com/android/camera/ImageGallery.java b/src/com/android/camera/ImageGallery.java
index 062de68..24f6d29 100644
--- a/src/com/android/camera/ImageGallery.java
+++ b/src/com/android/camera/ImageGallery.java
@@ -637,28 +637,18 @@ public class ImageGallery extends Activity implements
if (isPickIntent()) {
launchCropperOrFinish(img);
} else {
- Uri targetUri = img.fullSizeImageUri();
- Uri thisUri = getIntent().getData();
- if (thisUri != null) {
- String bucket = thisUri.getQueryParameter("bucketId");
- if (bucket != null) {
- targetUri = targetUri.buildUpon()
- .appendQueryParameter("bucketId", bucket)
- .build();
- }
- }
- Intent intent = new Intent(Intent.ACTION_VIEW, targetUri);
-
+ Intent intent;
if (img instanceof VideoObject) {
+ intent = new Intent(
+ Intent.ACTION_VIEW, img.fullSizeImageUri());
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ } else {
+ intent = new Intent(this, ViewImage.class);
+ intent.putExtra(ViewImage.KEY_IMAGE_LIST, mAllImages);
+ intent.setData(img.fullSizeImageUri());
}
-
- try {
- startActivity(intent);
- } catch (Exception ex) {
- // sdcard removal??
- }
+ startActivity(intent);
}
}
}
diff --git a/src/com/android/camera/ViewImage.java b/src/com/android/camera/ViewImage.java
index 9ce5e5c..4cfa544 100644
--- a/src/com/android/camera/ViewImage.java
+++ b/src/com/android/camera/ViewImage.java
@@ -19,6 +19,8 @@ package com.android.camera;
import com.android.camera.gallery.Cancelable;
import com.android.camera.gallery.IImage;
import com.android.camera.gallery.IImageList;
+import com.android.camera.gallery.SingleImageList;
+import com.android.camera.gallery.VideoObject;
import android.app.Activity;
import android.content.Context;
@@ -60,6 +62,8 @@ import java.util.concurrent.ExecutionException;
// button to see the previous or next image. In slide show mode it shows one
// image after another, with some transition effect.
public class ViewImage extends Activity implements View.OnClickListener {
+ private static final String KEY_URI = "uri";
+
private static final String TAG = "ViewImage";
private ImageGetter mGetter;
@@ -83,7 +87,6 @@ public class ViewImage extends Activity implements View.OnClickListener {
private boolean mShowActionIcons;
private View mActionIconPanel;
- private boolean mSortAscending = false;
private int mSlideShowInterval;
private int mLastSlideShowImage;
private ThumbnailController mThumbController;
@@ -106,6 +109,8 @@ public class ViewImage extends Activity implements View.OnClickListener {
static final int HYSTERESIS = PADDING * 2;
static final int BASE_SCROLL_DURATION = 1000; // ms
+ public static final String KEY_IMAGE_LIST = "image_list";
+
IImageList mAllImages;
private int mSlideShowImageCurrent = 0;
@@ -374,7 +379,6 @@ public class ViewImage extends Activity implements View.OnClickListener {
.setAlphabeticShortcut('z')
.setVisible(false);
-
return true;
}
@@ -562,17 +566,15 @@ public class ViewImage extends Activity implements View.OnClickListener {
}
Uri uri = getIntent().getData();
-
+ IImageList imageList = getIntent().getParcelableExtra(KEY_IMAGE_LIST);
if (instanceState != null) {
- if (instanceState.containsKey("uri")) {
- uri = Uri.parse(instanceState.getString("uri"));
- }
+ uri = instanceState.getParcelable(KEY_URI);
+ imageList = instanceState.getParcelable(KEY_IMAGE_LIST);
}
- if (uri == null) {
+ if (!init(uri, imageList)) {
finish();
return;
}
- init(uri);
Bundle b = getIntent().getExtras();
@@ -847,38 +849,15 @@ public class ViewImage extends Activity implements View.OnClickListener {
mGetter = new ImageGetter(this);
}
- private boolean desiredSortOrder() {
- String sortOrder = mPrefs.getString("pref_gallery_sort_key", null);
- boolean sortAscending = false;
- if (sortOrder != null) {
- sortAscending = sortOrder.equals("ascending");
- }
- if (mCameraReviewMode) {
- // Force left-arrow older pictures, right-arrow newer pictures.
- sortAscending = true;
- }
- return sortAscending;
- }
-
- private void init(Uri uri) {
- if (uri == null) {
- return;
- }
-
- mSortAscending = desiredSortOrder();
- int sort = mSortAscending
- ? ImageManager.SORT_ASCENDING
- : ImageManager.SORT_DESCENDING;
- mAllImages = ImageManager.makeImageList(uri, getContentResolver(),
- sort);
-
- uri = uri.buildUpon().query(null).build();
-
+ private boolean init(Uri uri, IImageList imageList) {
+ if (uri == null) return false;
+ mAllImages = imageList == null ? new SingleImageList(uri) : imageList;
+ mAllImages.open(getContentResolver());
IImage image = mAllImages.getImageForUri(uri);
- if (image != null) {
- mCurrentPosition = mAllImages.getImageIndex(image);
- mLastSlideShowImage = mCurrentPosition;
- }
+ if (image == null) return false;
+ mCurrentPosition = mAllImages.getImageIndex(image);
+ mLastSlideShowImage = mCurrentPosition;
+ return true;
}
private Uri getCurrentUri() {
@@ -902,22 +881,16 @@ public class ViewImage extends Activity implements View.OnClickListener {
@Override
public void onSaveInstanceState(Bundle b) {
super.onSaveInstanceState(b);
-
- Uri uri = getCurrentUri();
- if (uri != null) {
- b.putString("uri", uri.toString());
- }
-
- if (mMode == MODE_SLIDESHOW) {
- b.putBoolean("slideshow", true);
- }
+ b.putParcelable(KEY_URI,
+ mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri());
+ b.putBoolean("slideshow", mMode == MODE_SLIDESHOW);
}
@Override
public void onStart() {
super.onStart();
- init(mSavedUri);
+ init(mSavedUri, mAllImages);
if (mCameraReviewMode) {
updateLastImage();
}
@@ -1358,7 +1331,8 @@ class ImageGetter {
if (imageNumber >= 0 && imageNumber < imageCount) {
IImage image = mViewImage.mAllImages
.getImageAt(lastPosition + offset);
- if (mCB.wantsFullImage(lastPosition, offset)) {
+ if (mCB.wantsFullImage(lastPosition, offset)
+ && !(image instanceof VideoObject)) {
int sizeToUse = mCB.fullImageSizeToUse(
lastPosition, offset);
if (image != null && !isCanceled()) {
diff --git a/src/com/android/camera/gallery/BaseImageList.java b/src/com/android/camera/gallery/BaseImageList.java
index a006689..a1d2c5d 100644
--- a/src/com/android/camera/gallery/BaseImageList.java
+++ b/src/com/android/camera/gallery/BaseImageList.java
@@ -423,9 +423,12 @@ public abstract class BaseImageList implements IImageList {
cursor.moveToPosition(-1); // before first
for (int i = 0; cursor.moveToNext(); ++i) {
if (getImageId(cursor) == matchId) {
- Log.v(TAG, "find object at " + i + ", it takes"
- + (SystemClock.elapsedRealtime() - startTimestamp));
- return loadImageFromCursor(cursor);
+ BaseImage image = mCache.get(i);
+ if (image == null) {
+ image = loadImageFromCursor(cursor);
+ mCache.put(i, image);
+ }
+ return image;
}
}
return null;
diff --git a/src/com/android/camera/gallery/ImageListUber.java b/src/com/android/camera/gallery/ImageListUber.java
index 69bc2e1..06651ed 100644
--- a/src/com/android/camera/gallery/ImageListUber.java
+++ b/src/com/android/camera/gallery/ImageListUber.java
@@ -21,9 +21,9 @@ 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 android.util.Log;
import java.io.IOException;
import java.util.Arrays;
@@ -32,7 +32,9 @@ import java.util.HashMap;
import java.util.PriorityQueue;
/**
- * A union of different <code>IImageList</code>.
+ * A union of different <code>IImageList</code>. This class can merge several
+ * <code>IImageList</code> into one list and sort them according to the
+ * timestamp (The sorting must be same as all the given lists).
*/
public class ImageListUber implements IImageList {
@SuppressWarnings("unused")
@@ -70,7 +72,8 @@ public class ImageListUber implements IImageList {
}
protected ImageListUber(Parcel in) {
- Parcelable array[] = in.readParcelableArray(null);
+ Parcelable array[] =
+ in.readParcelableArray(ImageListUber.class.getClassLoader());
mSubList = new IImageList[array.length];
System.arraycopy(array, 0, mSubList, 0, array.length);
int sort = in.readInt();
@@ -79,10 +82,6 @@ public class ImageListUber implements IImageList {
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 =
@@ -311,6 +310,14 @@ public class ImageListUber implements IImageList {
}
}
+ /**
+ * A merging slot is used to trace the current position of a sublist. For
+ * each given sub list, there will be one corresponding merge slot. We
+ * use merge-sort-like algorithm to build the merged list. At begining,
+ * we put all the slots in a sorted heap (by timestamp). Each time, we
+ * pop the slot with earliest timestamp out, get the image, and then move
+ * the index forward, and put it back to the heap.
+ */
private static class MergeSlot {
private int mOffset = -1;
private final IImageList mList;
diff --git a/src/com/android/camera/gallery/VideoObject.java b/src/com/android/camera/gallery/VideoObject.java
index 5da63bf..40a5f74 100644
--- a/src/com/android/camera/gallery/VideoObject.java
+++ b/src/com/android/camera/gallery/VideoObject.java
@@ -16,7 +16,7 @@
package com.android.camera.gallery;
-import com.android.camera.ImageManager;
+import com.android.camera.Util;
import android.content.ContentResolver;
import android.graphics.Bitmap;
@@ -64,7 +64,7 @@ public class VideoObject extends BaseImage implements IImage {
@Override
public Bitmap fullSizeBitmap(int targetWidthHeight) {
- return ImageManager.NO_IMAGE_BITMAP;
+ return Util.createVideoThumbnail(mDataPath);
}
@Override