summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/data')
-rw-r--r--src/com/android/gallery3d/data/DataManager.java33
-rw-r--r--src/com/android/gallery3d/data/LocalImage.java66
-rw-r--r--src/com/android/gallery3d/data/MediaObject.java23
-rw-r--r--src/com/android/gallery3d/data/PanoramaMetadataJob.java2
-rw-r--r--src/com/android/gallery3d/data/UriImage.java66
5 files changed, 45 insertions, 145 deletions
diff --git a/src/com/android/gallery3d/data/DataManager.java b/src/com/android/gallery3d/data/DataManager.java
index 408a24b13..4ec7b6d98 100644
--- a/src/com/android/gallery3d/data/DataManager.java
+++ b/src/com/android/gallery3d/data/DataManager.java
@@ -16,15 +16,15 @@
package com.android.gallery3d.data;
-import android.content.Intent;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
-import android.support.v4.content.LocalBroadcastManager;
import com.android.gallery3d.app.GalleryApp;
+import com.android.gallery3d.app.StitchingChangeListener;
import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.Utils;
+import com.android.gallery3d.data.MediaObject.PanoramaSupportCallback;
import com.android.gallery3d.data.MediaSet.ItemConsumer;
import com.android.gallery3d.data.MediaSource.PathId;
import com.android.gallery3d.picasasource.PicasaSource;
@@ -49,7 +49,7 @@ import java.util.WeakHashMap;
// path. And it's used to identify a specific media set even if the process is
// killed and re-created, so child keys should be stable identifiers.
-public class DataManager {
+public class DataManager implements StitchingChangeListener {
public static final int INCLUDE_IMAGE = 1;
public static final int INCLUDE_VIDEO = 2;
public static final int INCLUDE_ALL = INCLUDE_IMAGE | INCLUDE_VIDEO;
@@ -247,10 +247,8 @@ public class DataManager {
return getMediaObject(path).getSupportedOperations();
}
- // getAll will cause this call to wait if any of the operations
- // are expensive to compute. Do not call in UI thread.
- public int getSupportedOperations(Path path, boolean getAll) {
- return getMediaObject(path).getSupportedOperations(getAll);
+ public void getPanoramaSupport(Path path, PanoramaSupportCallback callback) {
+ getMediaObject(path).getPanoramaSupport(callback);
}
public void delete(Path path) {
@@ -351,4 +349,25 @@ public class DataManager {
}
}
}
+
+ @Override
+ public void onStitchingQueued(Uri uri) {
+ // Do nothing.
+ }
+
+ @Override
+ public void onStitchingResult(Uri uri) {
+ Path path = findPathByUri(uri, null);
+ if (path != null) {
+ MediaObject mediaObject = getMediaObject(path);
+ if (mediaObject != null) {
+ mediaObject.clearCachedPanoramaSupport();
+ }
+ }
+ }
+
+ @Override
+ public void onStitchingProgress(Uri uri, int progress) {
+ // Do nothing.
+ }
}
diff --git a/src/com/android/gallery3d/data/LocalImage.java b/src/com/android/gallery3d/data/LocalImage.java
index 61961d87a..b2be1246a 100644
--- a/src/com/android/gallery3d/data/LocalImage.java
+++ b/src/com/android/gallery3d/data/LocalImage.java
@@ -19,7 +19,6 @@ package com.android.gallery3d.data;
import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.ContentValues;
-import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -33,14 +32,11 @@ import android.provider.MediaStore.MediaColumns;
import android.util.Log;
import com.android.gallery3d.app.GalleryApp;
+import com.android.gallery3d.app.PanoramaMetadataSupport;
import com.android.gallery3d.app.StitchingProgressManager;
import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.BitmapUtils;
-import com.android.gallery3d.util.Future;
-import com.android.gallery3d.util.FutureListener;
import com.android.gallery3d.util.GalleryUtils;
-import com.android.gallery3d.util.LightCycleHelper;
-import com.android.gallery3d.util.LightCycleHelper.PanoramaMetadata;
import com.android.gallery3d.util.ThreadPool.Job;
import com.android.gallery3d.util.ThreadPool.JobContext;
import com.android.gallery3d.util.UpdateHelper;
@@ -104,11 +100,7 @@ public class LocalImage extends LocalMediaItem {
public int rotation;
- private Object mLock = new Object();
- private Future<PanoramaMetadata> mGetPanoMetadataTask;
- private boolean mPanoramaMetadataInitialized;
- private PanoramaMetadata mPanoramaMetadata;
- private SupportedOperationsListener mListener;
+ private PanoramaMetadataSupport mPanoramaMetadata = new PanoramaMetadataSupport(this);
public LocalImage(Path path, GalleryApp application, Cursor cursor) {
super(path, nextVersionNumber());
@@ -257,63 +249,17 @@ public class LocalImage extends LocalMediaItem {
if (GalleryUtils.isValidLocation(latitude, longitude)) {
operation |= SUPPORT_SHOW_ON_MAP;
}
-
- if (mPanoramaMetadata != null && mPanoramaMetadata.mUsePanoramaViewer) {
- operation |= SUPPORT_PANORAMA;
- if (mPanoramaMetadata.mIsPanorama360) {
- operation |= SUPPORT_PANORAMA360;
- // disable destructive rotate and crop for 360 degree panorama
- operation &= ~(SUPPORT_ROTATE | SUPPORT_CROP);
- }
- }
return operation;
}
@Override
- public int getSupportedOperations(boolean getAll) {
- synchronized (mLock) {
- if (getAll && !mPanoramaMetadataInitialized) {
- if (mGetPanoMetadataTask == null) {
- mGetPanoMetadataTask = getThreadPool().submit(
- new PanoramaMetadataJob(mApplication.getAndroidContext(),
- getContentUri()));
- }
- mPanoramaMetadata = mGetPanoMetadataTask.get();
- mPanoramaMetadataInitialized = true;
- }
- }
- return getSupportedOperations();
+ public void getPanoramaSupport(PanoramaSupportCallback callback) {
+ mPanoramaMetadata.getPanoramaSupport(mApplication, callback);
}
@Override
- public void setSupportedOperationsListener(SupportedOperationsListener l) {
- synchronized (mLock) {
- if (l == null) {
- if (mGetPanoMetadataTask != null) {
- mGetPanoMetadataTask.cancel();
- mGetPanoMetadataTask = null;
- }
- } else {
- if (mGetPanoMetadataTask == null) {
- mGetPanoMetadataTask = getThreadPool().submit(
- new PanoramaMetadataJob(mApplication.getAndroidContext(),
- getContentUri()),
- new FutureListener<PanoramaMetadata>() {
- @Override
- public void onFutureDone(Future<PanoramaMetadata> future) {
- mGetPanoMetadataTask = null;
- if (future.isCancelled()) return;
- mPanoramaMetadata = future.get();
- mPanoramaMetadataInitialized = true;
- if (mListener != null) {
- mListener.onChange(LocalImage.this, getSupportedOperations());
- }
- }
- });
- }
- }
- mListener = l;
- }
+ public void clearCachedPanoramaSupport() {
+ mPanoramaMetadata.clearCachedValues();
}
@Override
diff --git a/src/com/android/gallery3d/data/MediaObject.java b/src/com/android/gallery3d/data/MediaObject.java
index 14cd5242a..a41b275fb 100644
--- a/src/com/android/gallery3d/data/MediaObject.java
+++ b/src/com/android/gallery3d/data/MediaObject.java
@@ -18,8 +18,6 @@ package com.android.gallery3d.data;
import android.net.Uri;
-import com.android.gallery3d.util.ThreadPool;
-
public abstract class MediaObject {
@SuppressWarnings("unused")
private static final String TAG = "MediaObject";
@@ -43,16 +41,8 @@ public abstract class MediaObject {
public static final int SUPPORT_BACK = 1 << 14;
public static final int SUPPORT_ACTION = 1 << 15;
public static final int SUPPORT_CAMERA_SHORTCUT = 1 << 16;
- // The panorama specific bits are expensive to compute.
- // Use SupportedOperationsListener to request them.
- public static final int SUPPORT_PANORAMA = 1 << 30;
- public static final int SUPPORT_PANORAMA360 = 1 << 31;
public static final int SUPPORT_ALL = 0xffffffff;
- public static interface SupportedOperationsListener {
- public void onChange(MediaObject item, int operations);
- }
-
// These are the bits returned from getMediaType():
public static final int MEDIA_TYPE_UNKNOWN = 1;
public static final int MEDIA_TYPE_IMAGE = 2;
@@ -80,9 +70,9 @@ public abstract class MediaObject {
protected final Path mPath;
- private static ThreadPool sThreadPool = new ThreadPool(1, 1);
- public static ThreadPool getThreadPool() {
- return sThreadPool;
+ public interface PanoramaSupportCallback {
+ void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama,
+ boolean isPanorama360);
}
public MediaObject(Path path, long version) {
@@ -99,12 +89,11 @@ public abstract class MediaObject {
return 0;
}
- public int getSupportedOperations(boolean getAll) {
- return getSupportedOperations();
+ public void getPanoramaSupport(PanoramaSupportCallback callback) {
+ callback.panoramaInfoAvailable(this, false, false);
}
- public void setSupportedOperationsListener(SupportedOperationsListener l) {
- // nothing to do
+ public void clearCachedPanoramaSupport() {
}
public void delete() {
diff --git a/src/com/android/gallery3d/data/PanoramaMetadataJob.java b/src/com/android/gallery3d/data/PanoramaMetadataJob.java
index e0a69c41f..ab99d6a81 100644
--- a/src/com/android/gallery3d/data/PanoramaMetadataJob.java
+++ b/src/com/android/gallery3d/data/PanoramaMetadataJob.java
@@ -24,7 +24,7 @@ import com.android.gallery3d.util.LightCycleHelper.PanoramaMetadata;
import com.android.gallery3d.util.ThreadPool.Job;
import com.android.gallery3d.util.ThreadPool.JobContext;
-class PanoramaMetadataJob implements Job<PanoramaMetadata> {
+public class PanoramaMetadataJob implements Job<PanoramaMetadata> {
Context mContext;
Uri mUri;
diff --git a/src/com/android/gallery3d/data/UriImage.java b/src/com/android/gallery3d/data/UriImage.java
index aaa36a917..e8875b572 100644
--- a/src/com/android/gallery3d/data/UriImage.java
+++ b/src/com/android/gallery3d/data/UriImage.java
@@ -17,7 +17,6 @@
package com.android.gallery3d.data;
import android.content.ContentResolver;
-import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory.Options;
@@ -26,12 +25,9 @@ import android.net.Uri;
import android.os.ParcelFileDescriptor;
import com.android.gallery3d.app.GalleryApp;
+import com.android.gallery3d.app.PanoramaMetadataSupport;
import com.android.gallery3d.common.BitmapUtils;
import com.android.gallery3d.common.Utils;
-import com.android.gallery3d.util.Future;
-import com.android.gallery3d.util.FutureListener;
-import com.android.gallery3d.util.LightCycleHelper;
-import com.android.gallery3d.util.LightCycleHelper.PanoramaMetadata;
import com.android.gallery3d.util.ThreadPool.CancelListener;
import com.android.gallery3d.util.ThreadPool.Job;
import com.android.gallery3d.util.ThreadPool.JobContext;
@@ -59,12 +55,7 @@ public class UriImage extends MediaItem {
private int mWidth;
private int mHeight;
private int mRotation;
-
- private Object mLock = new Object();
- private Future<PanoramaMetadata> mGetPanoMetadataTask;
- private boolean mPanoramaMetadataInitialized;
- private PanoramaMetadata mPanoramaMetadata;
- private SupportedOperationsListener mListener;
+ private PanoramaMetadataSupport mPanoramaMetadata = new PanoramaMetadataSupport(this);
private GalleryApp mApplication;
@@ -225,62 +216,17 @@ public class UriImage extends MediaItem {
if (BitmapUtils.isSupportedByRegionDecoder(mContentType)) {
supported |= SUPPORT_FULL_IMAGE;
}
- if (mPanoramaMetadata != null && mPanoramaMetadata.mUsePanoramaViewer) {
- supported |= SUPPORT_PANORAMA;
- if (mPanoramaMetadata.mIsPanorama360) {
- supported |= SUPPORT_PANORAMA360;
- // disable destructive crop for 360 degree panorama
- supported &= ~SUPPORT_CROP;
- }
- }
return supported;
}
@Override
- public int getSupportedOperations(boolean getAll) {
- synchronized (mLock) {
- if (getAll && !mPanoramaMetadataInitialized) {
- if (mGetPanoMetadataTask == null) {
- mGetPanoMetadataTask = getThreadPool().submit(
- new PanoramaMetadataJob(mApplication.getAndroidContext(),
- getContentUri()));
- }
- mPanoramaMetadata = mGetPanoMetadataTask.get();
- mPanoramaMetadataInitialized = true;
- }
- }
- return getSupportedOperations();
+ public void getPanoramaSupport(PanoramaSupportCallback callback) {
+ mPanoramaMetadata.getPanoramaSupport(mApplication, callback);
}
@Override
- public void setSupportedOperationsListener(SupportedOperationsListener l) {
- synchronized (mLock) {
- if (l != null) {
- if (mGetPanoMetadataTask != null) {
- mGetPanoMetadataTask.cancel();
- mGetPanoMetadataTask = null;
- }
- } else {
- if (mGetPanoMetadataTask == null) {
- mGetPanoMetadataTask = getThreadPool().submit(
- new PanoramaMetadataJob(mApplication.getAndroidContext(),
- getContentUri()),
- new FutureListener<PanoramaMetadata>() {
- @Override
- public void onFutureDone(Future<PanoramaMetadata> future) {
- mGetPanoMetadataTask = null;
- if (future.isCancelled()) return;
- mPanoramaMetadata = future.get();
- mPanoramaMetadataInitialized = true;
- if (mListener != null) {
- mListener.onChange(UriImage.this, getSupportedOperations());
- }
- }
- });
- }
- }
- mListener = l;
- }
+ public void clearCachedPanoramaSupport() {
+ mPanoramaMetadata.clearCachedValues();
}
private boolean isSharable() {