OSDN Git Service

Decode screenshots when they show 0x0 dimensions
authorDoris Liu <tianliu@google.com>
Fri, 7 Dec 2012 20:41:39 +0000 (12:41 -0800)
committerDoris Liu <tianliu@google.com>
Fri, 7 Dec 2012 21:33:13 +0000 (13:33 -0800)
Bug: 7470758
Change-Id: If4012899e120ad68cdc8ca12bf6f8de8c5c96019

res/values/strings.xml
src/com/android/gallery3d/ui/DetailsHelper.java
src/com/android/gallery3d/ui/DialogDetailsView.java

index 82b6a1c..3eb9095 100644 (file)
     <!-- String indicating camera flash is not used. [CHAR LIMIT=14] -->
     <string name="flash_off">No flash</string>
 
+    <!-- String indicating image width or height is unknown. [CHAR LIMIT=14] -->
+    <string name="unknown">Unknown</string>
+
     <!-- String for the empty not filtered image [CHAR LIMIT=10] -->
     <string name="ffx_original">Original</string>
     <!-- String for brown-colored old-fashion looking filter (filtershow_fx_0000_vintage) [CHAR LIMIT=10] -->
index 3016011..47296f6 100644 (file)
@@ -16,6 +16,8 @@
 package com.android.gallery3d.ui;
 
 import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.view.View.MeasureSpec;
 
 import com.android.gallery3d.R;
@@ -44,6 +46,10 @@ public class DetailsHelper {
         public void hide();
     }
 
+    public interface ResolutionResolvingListener {
+        public void onResolutionAvailable(int width, int height);
+    }
+
     public DetailsHelper(AbstractGalleryActivity activity, GLView rootPane, DetailsSource source) {
         mContainer = new DialogDetailsView(activity, source);
     }
@@ -75,6 +81,12 @@ public class DetailsHelper {
         return sAddressResolver.resolveAddress(latlng, listener);
     }
 
+    public static void resolveResolution(String path, ResolutionResolvingListener listener) {
+        Bitmap bitmap = BitmapFactory.decodeFile(path);
+        if (bitmap == null) return;
+        listener.onResolutionAvailable(bitmap.getWidth(), bitmap.getHeight());
+    }
+
     public static void pause() {
         if (sAddressResolver != null) sAddressResolver.cancel();
     }
index 8d96b82..058c036 100644 (file)
@@ -37,6 +37,7 @@ import com.android.gallery3d.ui.DetailsAddressResolver.AddressResolvingListener;
 import com.android.gallery3d.ui.DetailsHelper.CloseListener;
 import com.android.gallery3d.ui.DetailsHelper.DetailsSource;
 import com.android.gallery3d.ui.DetailsHelper.DetailsViewContainer;
+import com.android.gallery3d.ui.DetailsHelper.ResolutionResolvingListener;
 
 import java.util.ArrayList;
 import java.util.Map.Entry;
@@ -111,9 +112,13 @@ public class DialogDetailsView implements DetailsViewContainer {
         });
     }
 
-    private class DetailsAdapter extends BaseAdapter implements AddressResolvingListener {
+
+    private class DetailsAdapter extends BaseAdapter
+        implements AddressResolvingListener, ResolutionResolvingListener {
         private final ArrayList<String> mItems;
         private int mLocationIndex;
+        private int mWidthIndex = -1;
+        private int mHeightIndex = -1;
 
         public DetailsAdapter(MediaDetails details) {
             Context context = mActivity.getAndroidContext();
@@ -123,6 +128,8 @@ public class DialogDetailsView implements DetailsViewContainer {
         }
 
         private void setDetails(Context context, MediaDetails details) {
+            boolean resolutionIsValid = true;
+            String path = null;
             for (Entry<Integer, Object> detail : details) {
                 String value;
                 switch (detail.getKey()) {
@@ -170,6 +177,26 @@ public class DialogDetailsView implements DetailsViewContainer {
                         }
                         break;
                     }
+                    case MediaDetails.INDEX_WIDTH:
+                        mWidthIndex = mItems.size();
+                        value = detail.getValue().toString();
+                        if (value.equalsIgnoreCase("0")) {
+                            value = context.getString(R.string.unknown);
+                            resolutionIsValid = false;
+                        }
+                        break;
+                    case MediaDetails.INDEX_HEIGHT: {
+                        mHeightIndex = mItems.size();
+                        value = detail.getValue().toString();
+                        if (value.equalsIgnoreCase("0")) {
+                            value = context.getString(R.string.unknown);
+                            resolutionIsValid = false;
+                        }
+                        break;
+                    }
+                    case MediaDetails.INDEX_PATH:
+                        // Get the path and then fall through to the default case
+                        path = detail.getValue().toString();
                     default: {
                         Object valueObj = detail.getValue();
                         // This shouldn't happen, log its key to help us diagnose the problem.
@@ -189,6 +216,9 @@ public class DialogDetailsView implements DetailsViewContainer {
                             context, key), value);
                 }
                 mItems.add(value);
+                if (!resolutionIsValid) {
+                    DetailsHelper.resolveResolution(path, this);
+                }
             }
         }
 
@@ -235,6 +265,20 @@ public class DialogDetailsView implements DetailsViewContainer {
             mItems.set(mLocationIndex, address);
             notifyDataSetChanged();
         }
+
+        @Override
+        public void onResolutionAvailable(int width, int height) {
+            if (width == 0 || height == 0) return;
+            // Update the resolution with the new width and height
+            Context context = mActivity.getAndroidContext();
+            String widthString = String.format("%s: %d", DetailsHelper.getDetailsName(
+                    context, MediaDetails.INDEX_WIDTH), width);
+            String heightString = String.format("%s: %d", DetailsHelper.getDetailsName(
+                    context, MediaDetails.INDEX_HEIGHT), height);
+            mItems.set(mWidthIndex, String.valueOf(widthString));
+            mItems.set(mHeightIndex, String.valueOf(heightString));
+            notifyDataSetChanged();
+        }
     }
 
     @Override