OSDN Git Service

Fix Video thumbnail filmstrip size
authorAlan Newberger <alann@google.com>
Fri, 23 Jan 2015 22:23:10 +0000 (14:23 -0800)
committerAlan Newberger <alann@google.com>
Sat, 24 Jan 2015 00:40:11 +0000 (16:40 -0800)
Video size comes in asynchronously, and after refactor wasn't
wired up to query the metadata instead of the initial mediastore
size. This CL hides FilmstripItemData dimensions behind FilmstripItem
so that VideoItem can override and provide a Size via its existing
methods that use metadata if present.

Bug: 19000322

Change-Id: Ifddd6c90169c80d9fd69a1549e1086d5f1abfd85

src/com/android/camera/data/FilmstripItem.java
src/com/android/camera/data/FilmstripItemBase.java
src/com/android/camera/data/FilmstripItemData.java
src/com/android/camera/data/PlaceholderItem.java
src/com/android/camera/data/SessionItem.java
src/com/android/camera/data/VideoItem.java
src/com/android/camera/widget/FilmstripView.java

index 3c8fd34..d08c68e 100644 (file)
@@ -21,6 +21,7 @@ import android.net.Uri;
 import android.view.View;
 
 import com.android.camera.debug.Log;
+import com.android.camera.util.Size;
 import com.android.camera2.R;
 import com.google.common.base.Optional;
 
@@ -121,4 +122,17 @@ public interface FilmstripItem {
      * @return a bitmap thumbnail for this item.
      */
     public Optional<Bitmap> generateThumbnail(int boundingWidthPx, int boundingHeightPx);
+
+    /**
+     * Dimensions of this item.
+     *
+     * @return physical width and height in pixels.
+     */
+    public Size getDimensions();
+
+    /**
+     * Returns the rotation of the image in degrees clockwise. The valid values
+     * are 0, 90, 180, and 270.
+     */
+    public int getOrientation();
 }
index 4f9f51f..317be52 100644 (file)
@@ -23,6 +23,7 @@ import android.view.View;
 
 import com.android.camera.Storage;
 import com.android.camera.debug.Log;
+import com.android.camera.util.Size;
 import com.bumptech.glide.BitmapRequestBuilder;
 import com.bumptech.glide.Glide;
 import com.google.common.base.Optional;
@@ -79,8 +80,8 @@ public abstract class FilmstripItemBase<T extends FilmstripItemData> implements
     public Optional<MediaDetails> getMediaDetails() {
         MediaDetails mediaDetails = new MediaDetails();
         mediaDetails.addDetail(MediaDetails.INDEX_TITLE, mData.getTitle());
-        mediaDetails.addDetail(MediaDetails.INDEX_WIDTH, mData.getDimensions().getWidth());
-        mediaDetails.addDetail(MediaDetails.INDEX_HEIGHT, mData.getDimensions().getHeight());
+        mediaDetails.addDetail(MediaDetails.INDEX_WIDTH, getDimensions().getWidth());
+        mediaDetails.addDetail(MediaDetails.INDEX_HEIGHT, getDimensions().getHeight());
         mediaDetails.addDetail(MediaDetails.INDEX_PATH, mData.getFilePath());
         mediaDetails.addDetail(MediaDetails.INDEX_DATETIME,
               mDateFormatter.format(mData.getLastModifiedDate()));
@@ -106,6 +107,16 @@ public abstract class FilmstripItemBase<T extends FilmstripItemData> implements
         return mMetaData;
     }
 
+    @Override
+    public Size getDimensions() {
+        return mData.getDimensions();
+    }
+
+    @Override
+    public int getOrientation() {
+        return mData.getOrientation();
+    }
+
     // TODO: Move the glide classes to a specific rendering class.
     protected BitmapRequestBuilder<Uri, Bitmap> glideFullResBitmap(Uri uri,
           int width, int height) {
index 82aad76..1d75bbe 100644 (file)
@@ -124,7 +124,7 @@ public class FilmstripItemData {
      *
      * @return physical width and height in pixels.
      */
-    public Size getDimensions() {
+    /* package */ Size getDimensions() {
         return mDimensions;
     }
 
@@ -139,7 +139,7 @@ public class FilmstripItemData {
      * Returns the rotation of the image in degrees clockwise. The valid values
      * are 0, 90, 180, and 270.
      */
-    public int getOrientation() {
+    /* package */ int getOrientation() {
         return mOrientation;
     }
 
index 72c899f..8aff527 100644 (file)
@@ -132,4 +132,14 @@ public class PlaceholderItem implements FilmstripItem {
     public Optional<Bitmap> generateThumbnail(int boundingWidthPx, int boundingHeightPx) {
         return Optional.absent();
     }
+
+    @Override
+    public Size getDimensions() {
+        return mItemData.getDimensions();
+    }
+
+    @Override
+    public int getOrientation() {
+        return mItemData.getOrientation();
+    }
 }
index 699cce6..4401dc7 100644 (file)
@@ -142,4 +142,13 @@ public class SessionItem implements FilmstripItem {
         Glide.clear(view);
     }
 
+    @Override
+    public Size getDimensions() {
+        return mData.getDimensions();
+    }
+
+    @Override
+    public int getOrientation() {
+        return mData.getOrientation();
+    }
 }
index e91e903..1e465f0 100644 (file)
@@ -27,6 +27,7 @@ import android.widget.ImageView;
 
 import com.android.camera.data.FilmstripItemAttributes.Attributes;
 import com.android.camera.debug.Log;
+import com.android.camera.util.Size;
 import com.android.camera2.R;
 import com.bumptech.glide.Glide;
 import com.google.common.base.Optional;
@@ -60,6 +61,8 @@ public class VideoItem extends FilmstripItemBase<VideoItemData> {
 
     private final VideoItemFactory mVideoItemFactory;
 
+    private Size mCachedSize;
+
     public VideoItem(Context context, VideoItemData data, VideoItemFactory videoItemFactory) {
         super(context, data, VIDEO_ITEM_ATTRIBUTES);
         mVideoItemFactory = videoItemFactory;
@@ -102,6 +105,17 @@ public class VideoItem extends FilmstripItemBase<VideoItemData> {
     }
 
     @Override
+    public Size getDimensions() {
+        int width = getWidth();
+        int height = getHeight();
+        if (mCachedSize == null ||
+                width != mCachedSize.getWidth() || height != mCachedSize.getHeight()) {
+            mCachedSize = new Size(width, height);
+        }
+        return mCachedSize;
+    }
+
+    @Override
     public boolean delete() {
         ContentResolver cr = mContext.getContentResolver();
         cr.delete(VideoDataQuery.CONTENT_URI,
index 897bd36..f910b16 100644 (file)
@@ -773,9 +773,9 @@ public class FilmstripView extends ViewGroup {
         }
 
         Point dim = CameraUtil.resizeToFill(
-              imageData.getData().getDimensions().getWidth(),
-              imageData.getData().getDimensions().getHeight(),
-              imageData.getData().getOrientation(),
+              imageData.getDimensions().getWidth(),
+              imageData.getDimensions().getHeight(),
+              imageData.getOrientation(),
               boundWidth,
               boundHeight);
 
@@ -874,8 +874,8 @@ public class FilmstripView extends ViewGroup {
         item.setMaximumBitmapRequested();
         // Request full size bitmap, or max that DataAdapter will create.
         int index = item.getAdapterIndex();
-        int h = mDataAdapter.getFilmstripItemAt(index).getData().getDimensions().getHeight();
-        int w = mDataAdapter.getFilmstripItemAt(index).getData().getDimensions().getWidth();
+        int h = mDataAdapter.getFilmstripItemAt(index).getDimensions().getHeight();
+        int w = mDataAdapter.getFilmstripItemAt(index).getDimensions().getWidth();
         item.resizeView(w, h);
     }
 
@@ -1549,9 +1549,9 @@ public class FilmstripView extends ViewGroup {
         final FilmstripItem data = mDataAdapter.getFilmstripItemAt(index);
         Point dim = CameraUtil
                 .resizeToFill(
-                      data.getData().getDimensions().getWidth(),
-                      data.getData().getDimensions().getHeight(),
-                      data.getData().getOrientation(),
+                      data.getDimensions().getWidth(),
+                      data.getDimensions().getHeight(),
+                      data.getOrientation(),
                       getMeasuredWidth(),
                       getMeasuredHeight());
         final int offsetX = dim.x + mViewGapInPixel;
@@ -1794,9 +1794,9 @@ public class FilmstripView extends ViewGroup {
                 // If there is no scrolling at all, adjust mCenterX to place
                 // the current item at the center.
                 Point dim = CameraUtil.resizeToFill(
-                      data.getData().getDimensions().getWidth(),
-                      data.getData().getDimensions().getHeight(),
-                      data.getData().getOrientation(),
+                      data.getDimensions().getWidth(),
+                      data.getDimensions().getHeight(),
+                      data.getOrientation(),
                       getMeasuredWidth(),
                       getMeasuredHeight());
                 mCenterX = curr.getLeftPosition() + dim.x / 2;
@@ -2484,10 +2484,10 @@ public class FilmstripView extends ViewGroup {
             if (imageData == null || !imageData.getAttributes().canZoomInPlace()) {
                 return FULL_SCREEN_SCALE;
             }
-            float imageWidth = imageData.getData().getDimensions().getWidth();
-            if (imageData.getData().getOrientation() == 90
-                    || imageData.getData().getOrientation() == 270) {
-                imageWidth = imageData.getData().getDimensions().getHeight();
+            float imageWidth = imageData.getDimensions().getWidth();
+            if (imageData.getOrientation() == 90
+                    || imageData.getOrientation() == 270) {
+                imageWidth = imageData.getDimensions().getHeight();
             }
             float scale = imageWidth / curr.getWidth();
             if (allowOverScale) {
@@ -2516,7 +2516,7 @@ public class FilmstripView extends ViewGroup {
             if (uri == null || uri == Uri.EMPTY) {
                 return;
             }
-            int orientation = imageData.getData().getOrientation();
+            int orientation = imageData.getOrientation();
             mZoomView.loadBitmap(uri, orientation, viewRect);
         }