summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/data
diff options
context:
space:
mode:
authorSascha Haeberling <haeberling@google.com>2013-07-31 11:28:21 -0700
committerSascha Haeberling <haeberling@google.com>2013-08-01 15:50:13 -0700
commitf1f5186f7d3fd8bf35009d9e65a43914c664d82b (patch)
tree27f2c00994fdc2a7128ef3b2bcb7a2467e040b8c /src/com/android/camera/data
parent28d86a33744fc5ae60949a43ff27930579b9bda8 (diff)
downloadandroid_packages_apps_Snap-f1f5186f7d3fd8bf35009d9e65a43914c664d82b.tar.gz
android_packages_apps_Snap-f1f5186f7d3fd8bf35009d9e65a43914c664d82b.tar.bz2
android_packages_apps_Snap-f1f5186f7d3fd8bf35009d9e65a43914c664d82b.zip
Adds back the PhotoSphere View icon in filmstrip.
This also exercises the "leave a place cleaner than you found it" rule by cleaning up stuff: - Formatting according to the Android format rules - Removing unused code - Putting braces where they belong. Change-Id: Ie1dbfe9195bf3e20d9624d7ae85eeba16df8f931
Diffstat (limited to 'src/com/android/camera/data')
-rw-r--r--src/com/android/camera/data/CameraDataAdapter.java12
-rw-r--r--src/com/android/camera/data/LocalData.java92
-rw-r--r--src/com/android/camera/data/PanoramaMetadataLoader.java106
3 files changed, 195 insertions, 15 deletions
diff --git a/src/com/android/camera/data/CameraDataAdapter.java b/src/com/android/camera/data/CameraDataAdapter.java
index 436919776..443aaa05d 100644
--- a/src/com/android/camera/data/CameraDataAdapter.java
+++ b/src/com/android/camera/data/CameraDataAdapter.java
@@ -29,6 +29,7 @@ import android.view.View;
import com.android.camera.Storage;
import com.android.camera.ui.FilmStripView;
import com.android.camera.ui.FilmStripView.ImageData;
+import com.android.gallery3d.util.LightCycleHelper.PanoramaViewHelper;
import java.util.ArrayList;
import java.util.Collections;
@@ -457,5 +458,16 @@ public class CameraDataAdapter implements FilmStripView.DataAdapter {
public void recycle() {
// do nothing.
}
+
+ @Override
+ public void isPhotoSphere(Context context, PanoramaSupportCallback callback) {
+ // Not a photo sphere panorama.
+ callback.panoramaInfoAvailable(false, false);
+ }
+
+ @Override
+ public void viewPhotoSphere(PanoramaViewHelper helper) {
+ // do nothing.
+ }
}
}
diff --git a/src/com/android/camera/data/LocalData.java b/src/com/android/camera/data/LocalData.java
index 384456ed2..0a51be956 100644
--- a/src/com/android/camera/data/LocalData.java
+++ b/src/com/android/camera/data/LocalData.java
@@ -28,8 +28,8 @@ import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.MediaStore;
+import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.ImageColumns;
-import android.provider.MediaStore.Video;
import android.provider.MediaStore.Video.VideoColumns;
import android.util.Log;
import android.view.Gravity;
@@ -40,14 +40,18 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import com.android.camera.Util;
+import com.android.camera.data.PanoramaMetadataLoader.PanoramaMetadataCallback;
import com.android.camera.ui.FilmStripView;
import com.android.gallery3d.R;
+import com.android.gallery3d.util.LightCycleHelper.PanoramaMetadata;
+import com.android.gallery3d.util.LightCycleHelper.PanoramaViewHelper;
import java.io.File;
import java.util.Comparator;
import java.util.Date;
-/* An abstract interface that represents the local media data. Also implements
+/**
+ * An abstract interface that represents the local media data. Also implements
* Comparable interface so we can sort in DataAdapter.
*/
public interface LocalData extends FilmStripView.ImageData {
@@ -68,8 +72,8 @@ public interface LocalData extends FilmStripView.ImageData {
// Compare taken/modified date of LocalData in descent order to make
// newer data in the front.
- // The negavive numbers here are always considered "bigger" than
- // postive ones. Thus, if any one of the numbers is negative, the logic
+ // The negative numbers here are always considered "bigger" than
+ // positive ones. Thus, if any one of the numbers is negative, the logic
// is reversed.
private static int compareDate(long v1, long v2) {
if (v1 >= 0 && v2 >= 0) {
@@ -93,10 +97,11 @@ public interface LocalData extends FilmStripView.ImageData {
// Implementations below.
- /*
- * A base class for all the local media files. The bitmap is loaded in background
- * thread. Subclasses should implement their own background loading thread by
- * subclassing BitmapLoadTask and overriding doInBackground() to return a bitmap.
+ /**
+ * A base class for all the local media files. The bitmap is loaded in
+ * background thread. Subclasses should implement their own background
+ * loading thread by subclassing BitmapLoadTask and overriding
+ * doInBackground() to return a bitmap.
*/
abstract static class LocalMediaData implements LocalData {
protected long id;
@@ -109,6 +114,12 @@ public interface LocalData extends FilmStripView.ImageData {
protected int width;
protected int height;
+ /** The panorama metadata information of this media data. */
+ private PanoramaMetadata mPanoramaMetadata;
+
+ /** Used to load photo sphere metadata from image files. */
+ private PanoramaMetadataLoader mPanoramaMetadataLoader = null;
+
// true if this data has a corresponding visible view.
protected Boolean mUsing = false;
@@ -153,6 +164,38 @@ public interface LocalData extends FilmStripView.ImageData {
return f.delete();
}
+
+ @Override
+ public void viewPhotoSphere(PanoramaViewHelper helper) {
+ helper.showPanorama(getContentUri());
+ }
+
+ @Override
+ public void isPhotoSphere(Context context, final PanoramaSupportCallback callback) {
+ // If we already have metadata, use it.
+ if (mPanoramaMetadata != null) {
+ callback.panoramaInfoAvailable(mPanoramaMetadata.mUsePanoramaViewer,
+ mPanoramaMetadata.mIsPanorama360);
+ }
+
+ // Otherwise prepare a loader, if we don't have one already.
+ if (mPanoramaMetadataLoader == null) {
+ mPanoramaMetadataLoader = new PanoramaMetadataLoader(getContentUri());
+ }
+
+ // Load the metadata asynchronously.
+ mPanoramaMetadataLoader.getPanoramaMetadata(context, new PanoramaMetadataCallback() {
+ @Override
+ public void onPanoramaMetadataLoaded(PanoramaMetadata metadata) {
+ // Store the metadata and remove the loader to free up space.
+ mPanoramaMetadata = metadata;
+ mPanoramaMetadataLoader = null;
+ callback.panoramaInfoAvailable(metadata.mUsePanoramaViewer,
+ metadata.mIsPanorama360);
+ }
+ });
+ }
+
protected ImageView fillImageView(Context ctx, ImageView v,
int decodeWidth, int decodeHeight, Drawable placeHolder) {
v.setScaleType(ImageView.ScaleType.FIT_XY);
@@ -190,13 +233,21 @@ public interface LocalData extends FilmStripView.ImageData {
}
}
+ /**
+ * Returns the content URI of this data item.
+ */
+ private Uri getContentUri() {
+ Uri baseUri = Images.Media.EXTERNAL_CONTENT_URI;
+ return baseUri.buildUpon().appendPath(String.valueOf(id)).build();
+ }
+
@Override
public abstract int getType();
protected abstract BitmapLoadTask getBitmapLoadTask(
ImageView v, int decodeWidth, int decodeHeight);
- /*
+ /**
* An AsyncTask class that loads the bitmap in the background thread.
* Sub-classes should implement their own "protected Bitmap doInBackground(Void... )"
*/
@@ -254,10 +305,10 @@ public interface LocalData extends FilmStripView.ImageData {
private static final int mSupportedDataActions =
LocalData.ACTION_DELETE;
- // 32K buffer.
+ /** 32K buffer. */
private static final byte[] DECODE_TEMP_STORAGE = new byte[32 * 1024];
- // from MediaStore, can only be 0, 90, 180, 270;
+ /** from MediaStore, can only be 0, 90, 180, 270 */
public int orientation;
static Photo buildFromCursor(Cursor c) {
@@ -364,7 +415,7 @@ public interface LocalData extends FilmStripView.ImageData {
return null;
}
Matrix m = new Matrix();
- m.setRotate((float) orientation);
+ m.setRotate(orientation);
b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, false);
}
return b;
@@ -527,7 +578,7 @@ public interface LocalData extends FilmStripView.ImageData {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
}
if (bitmap == null) {
- bitmap = (Bitmap) retriever.getFrameAtTime();
+ bitmap = retriever.getFrameAtTime();
}
retriever.release();
return bitmap;
@@ -535,13 +586,13 @@ public interface LocalData extends FilmStripView.ImageData {
}
}
- /*
+ /**
* A LocalData that does nothing but only shows a view.
*/
public static class LocalViewData implements LocalData {
private int mWidth;
private int mHeight;
- View mView;
+ private View mView;
private long mDateTaken;
private long mDateModified;
@@ -614,6 +665,17 @@ public interface LocalData extends FilmStripView.ImageData {
public void recycle() {
// do nothing.
}
+
+ @Override
+ public void isPhotoSphere(Context context, PanoramaSupportCallback callback) {
+ // Not a photo sphere panorama.
+ callback.panoramaInfoAvailable(false, false);
+ }
+
+ @Override
+ public void viewPhotoSphere(PanoramaViewHelper helper) {
+ // do nothing.
+ }
}
}
diff --git a/src/com/android/camera/data/PanoramaMetadataLoader.java b/src/com/android/camera/data/PanoramaMetadataLoader.java
new file mode 100644
index 000000000..21b5f8a3d
--- /dev/null
+++ b/src/com/android/camera/data/PanoramaMetadataLoader.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera.data;
+
+import android.content.Context;
+import android.net.Uri;
+
+import com.android.gallery3d.util.LightCycleHelper;
+import com.android.gallery3d.util.LightCycleHelper.PanoramaMetadata;
+
+import java.util.ArrayList;
+
+/**
+ * This class breaks out the off-thread panorama support.
+ */
+public class PanoramaMetadataLoader {
+ /**
+ * Classes implementing this interface can get information about loaded
+ * photo sphere metadata.
+ */
+ public static interface PanoramaMetadataCallback {
+ /**
+ * Called with the loaded metadata or <code>null</code>.
+ */
+ public void onPanoramaMetadataLoaded(PanoramaMetadata metadata);
+ }
+
+ private PanoramaMetadata mPanoramaMetadata;
+ private ArrayList<PanoramaMetadataCallback> mCallbacksWaiting;
+ private Uri mMediaUri;
+
+ /**
+ * Instantiated the meta data loader for the image resource with the given
+ * URI.
+ */
+ public PanoramaMetadataLoader(Uri uri) {
+ mMediaUri = uri;
+ }
+
+ /**
+ * Asynchronously extract and return panorama metadata from the item with
+ * the given URI.
+ * <p>
+ * NOTE: This call is backed by a cache to speed up successive calls, which
+ * will return immediately. Use {@link #clearCachedValues()} is called.
+ */
+ public synchronized void getPanoramaMetadata(final Context context,
+ PanoramaMetadataCallback callback) {
+ if (mPanoramaMetadata != null) {
+ // Return the cached data right away, no need to fetch it again.
+ callback.onPanoramaMetadataLoaded(mPanoramaMetadata);
+ } else {
+ if (mCallbacksWaiting == null) {
+ mCallbacksWaiting = new ArrayList<PanoramaMetadataCallback>();
+
+ // TODO: Don't create a new thread each time, use a pool or
+ // single instance.
+ (new Thread() {
+ @Override
+ public void run() {
+ onLoadingDone(LightCycleHelper.getPanoramaMetadata(context,
+ mMediaUri));
+ }
+ }).start();
+ }
+ mCallbacksWaiting.add(callback);
+ }
+ }
+
+ /**
+ * Clear cached value and stop all running loading threads.
+ */
+ public synchronized void clearCachedValues() {
+ if (mPanoramaMetadata != null) {
+ mPanoramaMetadata = null;
+ }
+
+ // TODO: Cancel running loading thread if active.
+ }
+
+ private synchronized void onLoadingDone(PanoramaMetadata metadata) {
+ mPanoramaMetadata = metadata;
+ if (mPanoramaMetadata == null) {
+ // Error getting panorama data from file. Treat as not panorama.
+ mPanoramaMetadata = LightCycleHelper.NOT_PANORAMA;
+ }
+ for (PanoramaMetadataCallback cb : mCallbacksWaiting) {
+ cb.onPanoramaMetadataLoaded(mPanoramaMetadata);
+ }
+ mCallbacksWaiting = null;
+ }
+}