Play video from flim strip.

Change-Id: Iaedf42d7dabee53f75a20c57f9e6916864ea271f
diff --git a/src/com/android/camera/NewCameraActivity.java b/src/com/android/camera/NewCameraActivity.java
index 3313ede..3e6d50a 100644
--- a/src/com/android/camera/NewCameraActivity.java
+++ b/src/com/android/camera/NewCameraActivity.java
@@ -243,6 +243,7 @@
             mDataAdapter.flush();
             ImageView v = (ImageView) getLayoutInflater().inflate(
                     R.layout.secure_album_placeholder, null);
+            // Put a lock placeholder as the last image by setting its date to 0.
             mDataAdapter.addLocalData(
                     new LocalData.LocalViewData(
                             v,
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index ed42de8..6c3b364 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -51,8 +51,10 @@
 import android.view.WindowManager;
 import android.view.animation.AlphaAnimation;
 import android.view.animation.Animation;
+import android.widget.Toast;
 
 import com.android.gallery3d.R;
+import com.android.gallery3d.app.MovieActivity;
 import com.android.gallery3d.common.ApiHelper;
 
 import java.io.Closeable;
@@ -774,4 +776,17 @@
             return result;
         }
     }
+
+    public static void playVideo(Context context, Uri uri, String title) {
+        try {
+            Intent intent = new Intent(Intent.ACTION_VIEW)
+                    .setDataAndType(uri, "video/*")
+                    .putExtra(Intent.EXTRA_TITLE, title)
+                    .putExtra(MovieActivity.KEY_TREAT_UP_AS_BACK, true);
+            context.startActivity(intent);
+        } catch (ActivityNotFoundException e) {
+            Toast.makeText(context, context.getString(R.string.video_err),
+                    Toast.LENGTH_SHORT).show();
+        }
+    }
 }
diff --git a/src/com/android/camera/data/CameraDataAdapter.java b/src/com/android/camera/data/CameraDataAdapter.java
index 32b3afe..4450461 100644
--- a/src/com/android/camera/data/CameraDataAdapter.java
+++ b/src/com/android/camera/data/CameraDataAdapter.java
@@ -23,8 +23,6 @@
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.provider.MediaStore;
-import android.provider.MediaStore.Images;
-import android.provider.MediaStore.Video;
 import android.util.Log;
 import android.view.View;
 
@@ -266,7 +264,7 @@
             List<LocalData> l = new ArrayList<LocalData>();
             // Photos
             Cursor c = resolver[0].query(
-                    Images.Media.EXTERNAL_CONTENT_URI,
+                    LocalData.Photo.CONTENT_URI,
                     LocalData.Photo.QUERY_PROJECTION,
                     MediaStore.Images.Media.DATA + " like ? ", CAMERA_PATH,
                     LocalData.Photo.QUERY_ORDER);
@@ -291,7 +289,7 @@
             }
 
             c = resolver[0].query(
-                    Video.Media.EXTERNAL_CONTENT_URI,
+                    LocalData.Video.CONTENT_URI,
                     LocalData.Video.QUERY_PROJECTION,
                     MediaStore.Video.Media.DATA + " like ? ", CAMERA_PATH,
                     LocalData.Video.QUERY_ORDER);
diff --git a/src/com/android/camera/data/LocalData.java b/src/com/android/camera/data/LocalData.java
index 9ebc9ca..704e8ed 100644
--- a/src/com/android/camera/data/LocalData.java
+++ b/src/com/android/camera/data/LocalData.java
@@ -24,14 +24,21 @@
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.media.MediaMetadataRetriever;
+import android.net.Uri;
 import android.os.AsyncTask;
+import android.provider.MediaStore;
 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;
 import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
 import android.widget.ImageView;
 
+import com.android.camera.Util;
 import com.android.camera.ui.FilmStripView;
 import com.android.gallery3d.R;
 
@@ -125,9 +132,8 @@
             return false;
         }
 
-        protected ImageView getImageView(Context c,
+        protected View fillViewBackground(Context c, View v,
                 int decodeWidth, int decodeHeight, Drawable placeHolder) {
-            ImageView v = new ImageView(c);
             v.setBackground(placeHolder);
 
             BitmapLoadTask task = getBitmapLoadTask(v, decodeWidth, decodeHeight);
@@ -138,7 +144,7 @@
         @Override
         public View getView(Context c,
                 int decodeWidth, int decodeHeight, Drawable placeHolder) {
-            return getImageView(c, decodeWidth, decodeHeight, placeHolder);
+            return fillViewBackground(c, new ImageView(c), decodeWidth, decodeHeight, placeHolder);
         }
 
         @Override
@@ -165,16 +171,16 @@
         public abstract int getType();
 
         protected abstract BitmapLoadTask getBitmapLoadTask(
-                ImageView v, int decodeWidth, int decodeHeight);
+                View 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... )"
          */
         protected abstract class BitmapLoadTask extends AsyncTask<Void, Void, Bitmap> {
-            protected ImageView mView;
+            protected View mView;
 
-            protected BitmapLoadTask(ImageView v) {
+            protected BitmapLoadTask(View v) {
                 mView = v;
             }
 
@@ -186,7 +192,7 @@
                     return;
                 }
                 BitmapDrawable d = new BitmapDrawable(bitmap);
-                d.setGravity(android.view.Gravity.FILL);
+                d.setGravity(Gravity.FILL);
                 mView.setBackground(d);
             }
         }
@@ -203,6 +209,8 @@
         public static final int COL_WIDTH = 7;
         public static final int COL_HEIGHT = 8;
 
+        static final Uri CONTENT_URI = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
+
         static final String QUERY_ORDER = ImageColumns.DATE_TAKEN + " DESC, "
                 + ImageColumns._ID + " DESC";
         static final String[] QUERY_PROJECTION = {
@@ -217,7 +225,7 @@
             ImageColumns.HEIGHT,        // 8, int
         };
 
-        private static final int mSupportedAction =
+        private static final int mSupportedActions =
                 FilmStripView.ImageData.ACTION_DEMOTE
                 | FilmStripView.ImageData.ACTION_PROMOTE;
 
@@ -277,12 +285,12 @@
 
         @Override
         public boolean isActionSupported(int action) {
-            return ((action & mSupportedAction) != 0);
+            return ((action & mSupportedActions) != 0);
         }
 
         @Override
         protected BitmapLoadTask getBitmapLoadTask(
-                ImageView v, int decodeWidth, int decodeHeight) {
+                View v, int decodeWidth, int decodeHeight) {
             return new PhotoBitmapLoadTask(v, decodeWidth, decodeHeight);
         }
 
@@ -300,7 +308,7 @@
             private int mDecodeWidth;
             private int mDecodeHeight;
 
-            public PhotoBitmapLoadTask(ImageView v, int decodeWidth, int decodeHeight) {
+            public PhotoBitmapLoadTask(View v, int decodeWidth, int decodeHeight) {
                 super(v);
                 mDecodeWidth = decodeWidth;
                 mDecodeHeight = decodeHeight;
@@ -345,10 +353,11 @@
         public static final int COL_WIDTH = 6;
         public static final int COL_HEIGHT = 7;
 
+        static final Uri CONTENT_URI = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
+
         private static final int mSupportedActions =
                 FilmStripView.ImageData.ACTION_DEMOTE
-                | FilmStripView.ImageData.ACTION_PROMOTE
-                | FilmStripView.ImageData.ACTION_PLAY;
+                | FilmStripView.ImageData.ACTION_PROMOTE;
 
         static final String QUERY_ORDER = VideoColumns.DATE_TAKEN + " DESC, "
                 + VideoColumns._ID + " DESC";
@@ -364,6 +373,8 @@
             VideoColumns.RESOLUTION
         };
 
+        private Uri mPlayUri;
+
         static Video buildFromCursor(Cursor c) {
             Video d = new Video();
             d.id = c.getLong(COL_ID);
@@ -374,6 +385,8 @@
             d.path = c.getString(COL_DATA);
             d.width = c.getInt(COL_WIDTH);
             d.height = c.getInt(COL_HEIGHT);
+            d.mPlayUri = CONTENT_URI.buildUpon()
+                    .appendPath(String.valueOf(d.id)).build();
             MediaMetadataRetriever retriever = new MediaMetadataRetriever();
             retriever.setDataSource(d.path);
             String rotation = retriever.extractMetadata(
@@ -410,23 +423,35 @@
         }
 
         @Override
-        public View getView(Context c,
+        public View getView(final Context c,
                 int decodeWidth, int decodeHeight, Drawable placeHolder) {
-            ImageView v = getImageView(c, decodeWidth, decodeHeight, placeHolder);
-            v.setImageResource(R.drawable.ic_control_play);
-            v.setScaleType(ImageView.ScaleType.CENTER);
-            return v;
+            FrameLayout f = new FrameLayout(c);
+            fillViewBackground(c, f, decodeWidth, decodeHeight, placeHolder);
+            ImageView icon = new ImageView(c);
+            icon.setImageResource(R.drawable.ic_control_play);
+            icon.setScaleType(ImageView.ScaleType.CENTER);
+            icon.setLayoutParams(new FrameLayout.LayoutParams(
+                    ViewGroup.LayoutParams.WRAP_CONTENT,
+                    ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
+            icon.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    Util.playVideo(c, mPlayUri, title);
+                }
+            });
+            f.addView(icon);
+            return f;
         }
 
         @Override
         protected BitmapLoadTask getBitmapLoadTask(
-                ImageView v, int decodeWidth, int decodeHeight) {
+                View v, int decodeWidth, int decodeHeight) {
             return new VideoBitmapLoadTask(v);
         }
 
         private final class VideoBitmapLoadTask extends BitmapLoadTask {
 
-            public VideoBitmapLoadTask(ImageView v) {
+            public VideoBitmapLoadTask(View v) {
                 super(v);
             }
 
@@ -507,7 +532,6 @@
 
         @Override
         public boolean isActionSupported(int action) {
-            if (action == FilmStripView.ImageData.ACTION_PLAY) return true;
             return false;
         }
 
diff --git a/src/com/android/camera/ui/FilmStripView.java b/src/com/android/camera/ui/FilmStripView.java
index 4d1d6e0..3bc14c6 100644
--- a/src/com/android/camera/ui/FilmStripView.java
+++ b/src/com/android/camera/ui/FilmStripView.java
@@ -86,7 +86,6 @@
         public static final int ACTION_NONE = 0;
         public static final int ACTION_PROMOTE = 1;
         public static final int ACTION_DEMOTE = (1 << 1);
-        public static final int ACTION_PLAY = (1 << 2);
 
         // SIZE_FULL means disgard the width or height when deciding the view size
         // of this ImageData, just use full screen size.