Merge "Volantis Device Identifier Helper" into ub-camera-glacier
diff --git a/res/layout-land/aspect_ratio_dialog_content.xml b/res/layout-land/aspect_ratio_dialog_content.xml
index c183f1d..7aca76f 100644
--- a/res/layout-land/aspect_ratio_dialog_content.xml
+++ b/res/layout-land/aspect_ratio_dialog_content.xml
@@ -38,8 +38,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/photo_size_selection_title"
-        android:textSize="22sp"
-        android:textColor="@color/dialog_text_color"
+        style="@style/fullscreen_dialog_title"
         android:layout_margin="28dp" />
     <TextView
         android:layout_width="match_parent"
diff --git a/res/layout-land/location_dialog_content.xml b/res/layout-land/location_dialog_content.xml
index 2577f69..e3dab88 100644
--- a/res/layout-land/location_dialog_content.xml
+++ b/res/layout-land/location_dialog_content.xml
@@ -30,8 +30,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/remember_location_title"
-            android:textSize="22sp"
-            android:textColor="@color/dialog_text_color"
+            style="@style/fullscreen_dialog_title"
             android:layout_marginLeft="28dp"
             android:layout_marginRight="28dp"
             android:layout_marginBottom="28dp" />
diff --git a/res/layout-port/aspect_ratio_dialog_content.xml b/res/layout-port/aspect_ratio_dialog_content.xml
index 087909e..4086889 100644
--- a/res/layout-port/aspect_ratio_dialog_content.xml
+++ b/res/layout-port/aspect_ratio_dialog_content.xml
@@ -27,8 +27,7 @@
         android:layout_margin="28dp"
         android:gravity="center"
         android:text="@string/photo_size_selection_title"
-        android:textSize="22sp"
-        android:textColor="@color/dialog_text_color" />
+        style="@style/fullscreen_dialog_title" />
     <include
         layout="@layout/aspect_ratio_selector"
         android:layout_width="match_parent"
diff --git a/res/layout-port/location_dialog_content.xml b/res/layout-port/location_dialog_content.xml
index 0e1e453..fee5d64 100644
--- a/res/layout-port/location_dialog_content.xml
+++ b/res/layout-port/location_dialog_content.xml
@@ -22,8 +22,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/remember_location_title"
-        android:textSize="22sp"
-        android:textColor="@color/dialog_text_color"
+        style="@style/fullscreen_dialog_title"
         android:layout_margin="28dp" />
     <ImageView
         android:layout_width="wrap_content"
diff --git a/res/values/styles.xml b/res/values/styles.xml
index ad38594..7c0f7ca 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -216,13 +216,18 @@
         <item name="android:layout_width">match_parent</item>
         <item name="android:layout_height">match_parent</item>
     </style>
+    <style name="fullscreen_dialog_title">
+        <item name="android:textSize">24sp</item>
+        <item name="android:fontFamily">sans-serif-regular</item>
+        <item name="android:textColor">@color/dialog_text_color</item>
+    </style>
     <style name="BlueButton">
         <item name="android:layout_width">144dp</item>
         <item name="android:layout_height">48dp</item>
         <item name="android:background">@drawable/button_cling</item>
-        <item name="android:fontFamily">sans-serif-regular</item>
-        <item name="android:textColor">@color/blue_button_text_color</item>
         <item name="android:textSize">14sp</item>
+        <item name="android:fontFamily">sans-serif-medium</item>
+        <item name="android:textColor">@color/blue_button_text_color</item>
         <item name="android:padding">12dp</item>
     </style>
 </resources>
diff --git a/src/com/android/camera/data/CameraDataAdapter.java b/src/com/android/camera/data/CameraDataAdapter.java
index 07100ef..7fd2d09 100644
--- a/src/com/android/camera/data/CameraDataAdapter.java
+++ b/src/com/android/camera/data/CameraDataAdapter.java
@@ -180,7 +180,7 @@
         int pos = findDataByContentUri(uri);
         if (pos != -1) {
             // a duplicate one, just do a substitute.
-            Log.v(TAG, "found duplicate data");
+            Log.v(TAG, "found duplicate data: " + uri);
             updateData(pos, newData);
             return false;
         } else {
@@ -339,6 +339,7 @@
         @Override
         protected List<LocalData> doInBackground(ContentResolver... contentResolvers) {
             if (mMinPhotoId != LocalMediaData.QUERY_ALL_MEDIA_ID) {
+                Log.v(TAG, "updating media metadata with photos newer than id: " + mMinPhotoId);
                 final ContentResolver cr = contentResolvers[0];
                 return LocalMediaData.PhotoData.query(cr, LocalMediaData.PhotoData.CONTENT_URI,
                         mMinPhotoId);
@@ -348,11 +349,19 @@
 
         @Override
         protected void onPostExecute(List<LocalData> newPhotoData) {
+            if (newPhotoData == null) {
+                Log.w(TAG, "null data returned from new photos query");
+                return;
+            }
+            Log.v(TAG, "new photos query return num items: " + newPhotoData.size());
             if (!newPhotoData.isEmpty()) {
                 LocalData newestPhoto = newPhotoData.get(0);
                 // We may overlap with another load task or a query task, in which case we want
                 // to be sure we never decrement the oldest seen id.
-                mLastPhotoId = Math.max(mLastPhotoId, newestPhoto.getContentId());
+                long newLastPhotoId = newestPhoto.getContentId();
+                Log.v(TAG, "updating last photo id (old:new) " +
+                        mLastPhotoId + ":" + newLastPhotoId);
+                mLastPhotoId = Math.max(mLastPhotoId, newLastPhotoId);
             }
             // We may add data that is already present, but if we do, it will be deduped in addData.
             // addData does not dedupe session items, so we ignore them here
@@ -406,12 +415,27 @@
 
             long lastPhotoId = LocalMediaData.QUERY_ALL_MEDIA_ID;
             if (!photoData.isEmpty()) {
+                // This relies on {@link LocalMediaData.QUERY_ORDER} returning
+                // items sorted descending by ID, as such we can just pull the
+                // ID from the first item in the result to establish the last
+                // (max) photo ID.
                 lastPhotoId = photoData.get(0).getContentId();
             }
 
-            l.addAll(photoData);
-            l.addAll(videoData);
+            if (photoData != null) {
+                Log.v(TAG, "retrieved photo metadata, number of items: " + photoData.size());
+                l.addAll(photoData);
+            }
+            if (videoData != null) {
+                Log.v(TAG, "retrieved video metadata, number of items: " + videoData.size());
+                l.addAll(videoData);
+            }
+            Log.v(TAG, "sorting video/photo metadata");
+            // Photos should be sorted within photo/video by ID, which in most
+            // cases should correlate well to the date taken/modified. This sort
+            // operation makes all photos/videos sorted by date in one list.
             l.sort(new LocalData.NewestFirstComparator());
+            Log.v(TAG, "sorted video/photo metadata");
 
             // Load enough metadata so it's already loaded when we open the filmstrip.
             for (int i = 0; i < MAX_METADATA && i < l.size(); i++) {
diff --git a/src/com/android/camera/data/LocalMediaData.java b/src/com/android/camera/data/LocalMediaData.java
index ab57058..83399e6 100644
--- a/src/com/android/camera/data/LocalMediaData.java
+++ b/src/com/android/camera/data/LocalMediaData.java
@@ -333,8 +333,10 @@
 
         static final Uri CONTENT_URI = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
 
-        private static final String QUERY_ORDER = MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC, "
-                + MediaStore.Images.ImageColumns._ID + " DESC";
+        // Sort all data by ID. This must be aligned with
+        // {@link CameraDataAdapter.QueryTask} which relies on the highest ID
+        // being first in any data returned.
+        private static final String QUERY_ORDER = MediaStore.Images.ImageColumns._ID + " DESC";
         /**
          * These values should be kept in sync with column IDs (COL_*) above.
          */
diff --git a/src/com/android/camera/widget/FilmstripView.java b/src/com/android/camera/widget/FilmstripView.java
index 8743c43..37d3ea7 100644
--- a/src/com/android/camera/widget/FilmstripView.java
+++ b/src/com/android/camera/widget/FilmstripView.java
@@ -1254,18 +1254,22 @@
                 // It's in full-screen mode.
                 fadeAndScaleRightViewItem(itemID);
             } else {
-                if (curr.getVisibility() == INVISIBLE) {
-                    curr.setVisibility(VISIBLE);
-                }
+                boolean setToVisible = (curr.getVisibility() == INVISIBLE);
+
                 if (itemID == mCurrentItem + 1) {
                     curr.setAlpha(1f - scaleFraction);
                 } else {
                     if (scaleFraction == 0f) {
                         curr.setAlpha(1f);
                     } else {
-                        curr.setVisibility(INVISIBLE);
+                        setToVisible = false;
                     }
                 }
+
+                if (setToVisible) {
+                    curr.setVisibility(VISIBLE);
+                }
+
                 curr.setTranslationX(
                         (mViewItem[mCurrentItem].getLeftPosition() - curr.getLeftPosition()) *
                                 scaleFraction);