Add secure camera support.

Change-Id: I672d76cb4de37c46394a5e8ee2899cf571158a2c
diff --git a/src/com/android/camera/NewCameraActivity.java b/src/com/android/camera/NewCameraActivity.java
index 3aee150..2705bcf 100644
--- a/src/com/android/camera/NewCameraActivity.java
+++ b/src/com/android/camera/NewCameraActivity.java
@@ -37,8 +37,10 @@
 import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
+import android.widget.ImageView;
 
 import com.android.camera.data.CameraDataAdapter;
+import com.android.camera.data.LocalData;
 import com.android.camera.ui.CameraSwitcher.CameraSwitchListener;
 import com.android.camera.ui.FilmStripView;
 import com.android.camera.ui.NewCameraRootView;
@@ -148,8 +150,6 @@
         String action = intent.getAction();
         if (INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action)) {
             mSecureCamera = true;
-            // Use a new album when this is started from the lock screen.
-        //TODO:    sSecureAlbumId++;
         } else if (ACTION_IMAGE_CAPTURE_SECURE.equals(action)) {
             mSecureCamera = true;
         } else {
@@ -232,7 +232,20 @@
         mCurrentModule.onResumeAfterSuper();
 
         // The loading is done in background and will update the filmstrip later.
-        mDataAdapter.requestLoad(getContentResolver());
+        if (!mSecureCamera) {
+            mDataAdapter.requestLoad(getContentResolver());
+        } else {
+            // Flush out all the original data first.
+            mDataAdapter.flush();
+            ImageView v = (ImageView) getLayoutInflater().inflate(
+                    R.layout.secure_album_placeholder, null);
+            mDataAdapter.addLocalData(
+                    new LocalData.LocalViewData(
+                            v,
+                            v.getDrawable().getIntrinsicWidth(),
+                            v.getDrawable().getIntrinsicHeight(),
+                            0, 0));
+        }
     }
 
     @Override
diff --git a/src/com/android/camera/data/CameraDataAdapter.java b/src/com/android/camera/data/CameraDataAdapter.java
index 6e2ff10..32b3afe 100644
--- a/src/com/android/camera/data/CameraDataAdapter.java
+++ b/src/com/android/camera/data/CameraDataAdapter.java
@@ -164,6 +164,55 @@
         }
     }
 
+    // Update all the data but keep the camera data if already set.
+    private void replaceData(List<LocalData> list) {
+        boolean changed = (list != mImages);
+        LocalData cameraData = null;
+        if (mImages != null && mImages.size() > 0) {
+            cameraData = mImages.get(0);
+            if (cameraData.getType() != ImageData.TYPE_CAMERA_PREVIEW) {
+                cameraData = null;
+            }
+        }
+
+        mImages = list;
+        if (cameraData != null) {
+            // camera view exists, so we make sure at least 1 data is in the list.
+            if (mImages == null) {
+                mImages = new ArrayList<LocalData>();
+            }
+            mImages.add(0, cameraData);
+            if (mListener != null) {
+                // Only the camera data is not changed, everything else is changed.
+                mListener.onDataUpdated(new UpdateReporter() {
+                    @Override
+                    public boolean isDataRemoved(int id) {
+                        return false;
+                    }
+
+                    @Override
+                    public boolean isDataUpdated(int id) {
+                        if (id == 0) return false;
+                        return true;
+                    }
+                });
+            }
+        } else {
+            // both might be null.
+            if (changed) {
+                mListener.onDataLoaded();
+            }
+        }
+    }
+
+    public void flush() {
+        replaceData(null);
+    }
+
+    public void addLocalData(LocalData data) {
+        insertData(data);
+    }
+
     private LocalData buildCameraImageData(int width, int height) {
         LocalData d = new CameraPreviewData(width, height);
         return d;
@@ -277,43 +326,7 @@
 
         @Override
         protected void onPostExecute(List<LocalData> l) {
-            boolean changed = (l != mImages);
-            LocalData cameraData = null;
-            if (mImages != null && mImages.size() > 0) {
-                cameraData = mImages.get(0);
-                if (cameraData.getType() != ImageData.TYPE_CAMERA_PREVIEW) {
-                    cameraData = null;
-                }
-            }
-
-            mImages = l;
-            if (cameraData != null) {
-                // camera view exists, so we make sure at least 1 data is in the list.
-                if (mImages == null) {
-                    mImages = new ArrayList<LocalData>();
-                }
-                mImages.add(0, cameraData);
-                if (mListener != null) {
-                    // Only the camera data is not changed, everything else is changed.
-                    mListener.onDataUpdated(new UpdateReporter() {
-                        @Override
-                        public boolean isDataRemoved(int id) {
-                            return false;
-                        }
-
-                        @Override
-                        public boolean isDataUpdated(int id) {
-                            if (id == 0) return false;
-                            return true;
-                        }
-                    });
-                }
-            } else {
-                // both might be null.
-                if (changed) {
-                    mListener.onDataLoaded();
-                }
-            }
+            replaceData(l);
         }
     }
 
@@ -378,5 +391,4 @@
             // do nothing.
         }
     }
-
 }
diff --git a/src/com/android/camera/data/LocalData.java b/src/com/android/camera/data/LocalData.java
index 9f9be8e..f81c9e5 100644
--- a/src/com/android/camera/data/LocalData.java
+++ b/src/com/android/camera/data/LocalData.java
@@ -39,7 +39,7 @@
 /* An abstract interface that represents the local media data. Also implements
  * Comparable interface so we can sort in DataAdapter.
  */
-abstract interface LocalData extends FilmStripView.ImageData {
+public abstract interface LocalData extends FilmStripView.ImageData {
     static final String TAG = "LocalData";
 
     abstract View getView(Context c, int width, int height, Drawable placeHolder);
@@ -438,5 +438,77 @@
             }
         }
     }
+
+    /*
+     * 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 long mDateTaken;
+        private long mDateModified;
+
+        public LocalViewData(View v,
+                int width, int height,
+                int dateTaken, int dateModified) {
+            mView = v;
+            mWidth = width;
+            mHeight = height;
+            mDateTaken = dateTaken;
+            mDateModified = dateModified;
+        }
+
+        @Override
+        public long getDateTaken() {
+            return mDateTaken;
+        }
+
+        @Override
+        public long getDateModified() {
+            return mDateModified;
+        }
+
+        @Override
+        public String getTitle() {
+            return "";
+        }
+
+        @Override
+        public int getWidth() {
+            return mWidth;
+        }
+
+        @Override
+        public int getHeight() {
+            return mHeight;
+        }
+
+        @Override
+        public int getType() {
+            return FilmStripView.ImageData.TYPE_PHOTO;
+        }
+
+        @Override
+        public boolean isActionSupported(int action) {
+            if (action == FilmStripView.ImageData.ACTION_PLAY) return true;
+            return false;
+        }
+
+        @Override
+        public View getView(Context c, int width, int height, Drawable placeHolder) {
+            return mView;
+        }
+
+        @Override
+        public void prepare() {
+            // do nothing.
+        }
+
+        @Override
+        public void recycle() {
+            // do nothing.
+        }
+    }
 }