Add UriImage support for viewing LightCycle panoramas.

Change-Id: I7f61cef39370fd23b9481708dc3c902c17873074
diff --git a/src/com/android/gallery3d/app/PhotoDataAdapter.java b/src/com/android/gallery3d/app/PhotoDataAdapter.java
index 5ba2afc..04518b5 100644
--- a/src/com/android/gallery3d/app/PhotoDataAdapter.java
+++ b/src/com/android/gallery3d/app/PhotoDataAdapter.java
@@ -37,7 +37,6 @@
 import com.android.gallery3d.ui.TileImageViewAdapter;
 import com.android.gallery3d.util.Future;
 import com.android.gallery3d.util.FutureListener;
-import com.android.gallery3d.util.LightCycleHelper;
 import com.android.gallery3d.util.MediaSetUtils;
 import com.android.gallery3d.util.ThreadPool;
 import com.android.gallery3d.util.ThreadPool.Job;
@@ -482,7 +481,7 @@
         MediaItem item = getItem(mCurrentIndex + offset);
         boolean usePanoramaViewer = false;
         if (item != null) {
-            usePanoramaViewer = LightCycleHelper.isPanorama(item.getFilePath());
+            usePanoramaViewer = item.usePanoramaViewer();
         }
         return usePanoramaViewer;
     }
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index 69484be..75fcb2a 100644
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -45,7 +45,6 @@
 import com.android.gallery3d.common.Utils;
 import com.android.gallery3d.data.DataManager;
 import com.android.gallery3d.data.FilterDeleteSet;
-import com.android.gallery3d.data.LocalImage;
 import com.android.gallery3d.data.MediaDetails;
 import com.android.gallery3d.data.MediaItem;
 import com.android.gallery3d.data.MediaObject;
@@ -887,8 +886,7 @@
         if (playVideo) {
             playVideo(mActivity, item.getPlayUri(), item.getName());
         } else if (viewPanorama) {
-            LocalImage img = (LocalImage) item;
-            LightCycleHelper.viewPanorama(mActivity, img.getFilePath());
+            LightCycleHelper.viewPanorama(mActivity, item.getContentUri());
         } else {
             toggleBars();
         }
diff --git a/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java b/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java
index 90f6060..1bfd64f 100644
--- a/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java
+++ b/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java
@@ -218,7 +218,7 @@
 
     @Override
     public boolean usePanoramaViewer(int offset) {
-        return LightCycleHelper.isPanorama(mItem.getFilePath());
+        return mItem.usePanoramaViewer();
     }
 
     @Override
diff --git a/src/com/android/gallery3d/data/LocalImage.java b/src/com/android/gallery3d/data/LocalImage.java
index 078229a..a00525c 100644
--- a/src/com/android/gallery3d/data/LocalImage.java
+++ b/src/com/android/gallery3d/data/LocalImage.java
@@ -19,6 +19,7 @@
 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;
@@ -99,6 +100,9 @@
 
     public int rotation;
 
+    private boolean mUsePanoramaViewer;
+    private boolean mUsePanoramaViewerInitialized;
+
     public LocalImage(Path path, GalleryApp application, Cursor cursor) {
         super(path, nextVersionNumber());
         mApplication = application;
@@ -241,9 +245,7 @@
             operation |= SUPPORT_SHOW_ON_MAP;
         }
 
-        if (LightCycleHelper.isPanorama(filePath) &&
-                LightCycleHelper.hasLightCycleView(
-                        mApplication.getAndroidContext())) {
+        if (usePanoramaViewer()) {
             operation |= SUPPORT_VIEW_PANORAMA;
         }
         return operation;
@@ -343,4 +345,16 @@
     public String getFilePath() {
         return filePath;
     }
+
+    @Override
+    public boolean usePanoramaViewer() {
+        if (!mUsePanoramaViewerInitialized) {
+            Context context = mApplication.getAndroidContext();
+            mUsePanoramaViewer = LightCycleHelper.hasLightCycleView(context)
+                    && LightCycleHelper.isPanorama(mApplication.getContentResolver(),
+                            getContentUri());
+            mUsePanoramaViewerInitialized = true;
+        }
+        return mUsePanoramaViewer;
+    }
 }
diff --git a/src/com/android/gallery3d/data/MediaItem.java b/src/com/android/gallery3d/data/MediaItem.java
index 2fcd1da..9d2040a 100644
--- a/src/com/android/gallery3d/data/MediaItem.java
+++ b/src/com/android/gallery3d/data/MediaItem.java
@@ -107,6 +107,10 @@
         return "";
     }
 
+    public boolean usePanoramaViewer() {
+        return false;
+    }
+
     // Returns width and height of the media item.
     // Returns 0, 0 if the information is not available.
     public abstract int getWidth();
diff --git a/src/com/android/gallery3d/data/UriImage.java b/src/com/android/gallery3d/data/UriImage.java
index 8fc873e..6e33a95 100644
--- a/src/com/android/gallery3d/data/UriImage.java
+++ b/src/com/android/gallery3d/data/UriImage.java
@@ -17,6 +17,7 @@
 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;
@@ -27,6 +28,7 @@
 import com.android.gallery3d.app.GalleryApp;
 import com.android.gallery3d.common.BitmapUtils;
 import com.android.gallery3d.common.Utils;
+import com.android.gallery3d.util.LightCycleHelper;
 import com.android.gallery3d.util.ThreadPool.CancelListener;
 import com.android.gallery3d.util.ThreadPool.Job;
 import com.android.gallery3d.util.ThreadPool.JobContext;
@@ -54,6 +56,8 @@
     private int mWidth;
     private int mHeight;
     private int mRotation;
+    private boolean mUsePanoramaViewer;
+    private boolean mUsePanoramaViewerInitialized;
 
     private GalleryApp mApplication;
 
@@ -214,6 +218,9 @@
         if (BitmapUtils.isSupportedByRegionDecoder(mContentType)) {
             supported |= SUPPORT_FULL_IMAGE;
         }
+        if (usePanoramaViewer()) {
+            supported |= SUPPORT_VIEW_PANORAMA;
+        }
         return supported;
     }
 
@@ -283,4 +290,16 @@
     public int getRotation() {
         return mRotation;
     }
+
+    @Override
+    public boolean usePanoramaViewer() {
+        if (!mUsePanoramaViewerInitialized) {
+            Context context = mApplication.getAndroidContext();
+            mUsePanoramaViewer = LightCycleHelper.hasLightCycleView(context)
+                    && LightCycleHelper.isPanorama(mApplication.getContentResolver(),
+                            getContentUri());
+            mUsePanoramaViewerInitialized = true;
+        }
+        return mUsePanoramaViewer;
+    }
 }
diff --git a/src_pd/com/android/gallery3d/util/LightCycleHelper.java b/src_pd/com/android/gallery3d/util/LightCycleHelper.java
index f8f720f..dcedc2d 100644
--- a/src_pd/com/android/gallery3d/util/LightCycleHelper.java
+++ b/src_pd/com/android/gallery3d/util/LightCycleHelper.java
@@ -17,8 +17,10 @@
 package com.android.gallery3d.util;
 
 import android.app.Activity;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
+import android.net.Uri;
 
 import com.android.camera.CameraModule;
 
@@ -36,11 +38,11 @@
         return false;
     }
 
-    public static void viewPanorama(Activity activity, String filePath) {
+    public static void viewPanorama(Activity activity, Uri uri) {
         /* Do nothing */
     }
 
-    public static boolean isPanorama(String filename) {
+    public static boolean isPanorama(ContentResolver contentResolver, Uri uri) {
         return false;
     }