OSDN Git Service

Fix ICS compatibility issues
authorJohn Reck <jreck@google.com>
Tue, 12 Mar 2013 19:55:27 +0000 (12:55 -0700)
committerJohn Reck <jreck@google.com>
Tue, 12 Mar 2013 20:09:01 +0000 (13:09 -0700)
Change-Id: I43f3236b9da0424fde66d3ad4d46403223fde8bf

res/layout/photo_set_item.xml
src/com/android/photos/SelectionManager.java
src/com/android/photos/adapters/PhotoThumbnailAdapter.java
src/com/android/photos/views/SquareImageView.java [new file with mode: 0644]

index b56184e..e80957d 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
-<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
+<com.android.photos.views.SquareImageView xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="200dip"
+    android:layout_height="wrap_content"
     android:id="@+id/thumbnail">
 
-</ImageView>
\ No newline at end of file
+</com.android.photos.views.SquareImageView>
\ No newline at end of file
index d7e61d1..979dcc7 100644 (file)
 
 package com.android.photos;
 
-import android.annotation.TargetApi;
 import android.app.Activity;
 import android.content.Intent;
 import android.net.Uri;
 import android.nfc.NfcAdapter;
+import android.nfc.NfcAdapter.CreateBeamUrisCallback;
 import android.nfc.NfcEvent;
 import android.provider.MediaStore.Files.FileColumns;
 import android.widget.ShareActionProvider;
@@ -31,7 +31,7 @@ import com.android.gallery3d.util.GalleryUtils;
 
 import java.util.ArrayList;
 
-public class SelectionManager implements NfcAdapter.CreateBeamUrisCallback {
+public class SelectionManager {
     private Activity mActivity;
     private NfcAdapter mNfcAdapter;
     private SelectedUriSource mUriSource;
@@ -41,12 +41,19 @@ public class SelectionManager implements NfcAdapter.CreateBeamUrisCallback {
         public ArrayList<Uri> getSelectedShareableUris();
     }
 
-    @TargetApi(16)
     public SelectionManager(Activity activity) {
         mActivity = activity;
         if (ApiHelper.AT_LEAST_16) {
             mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);
-            mNfcAdapter.setBeamPushUrisCallback(this, mActivity);
+            mNfcAdapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
+                @Override
+                public Uri[] createBeamUris(NfcEvent arg0) {
+                 // This will have been preceded by a call to onItemSelectedStateChange
+                    if (mCachedShareableUris == null) return null;
+                    return mCachedShareableUris.toArray(
+                            new Uri[mCachedShareableUris.size()]);
+                }
+            }, mActivity);
         }
     }
 
@@ -116,11 +123,4 @@ public class SelectionManager implements NfcAdapter.CreateBeamUrisCallback {
         mShareIntent.removeExtra(Intent.EXTRA_STREAM);
         mShareIntent.setAction(null).setType(null);
     }
-
-    @Override
-    public Uri[] createBeamUris(NfcEvent event) {
-        // This will have been preceded by a call to onItemSelectedStateChange
-        if (mCachedShareableUris == null) return null;
-        return mCachedShareableUris.toArray(new Uri[mCachedShareableUris.size()]);
-    }
 }
index 5715795..3776ca5 100644 (file)
@@ -59,10 +59,6 @@ public class PhotoThumbnailAdapter extends CursorAdapter implements GalleryThumb
     @Override
     public View newView(Context context, Cursor cursor, ViewGroup parent) {
         View view = mInflater.inflate(R.layout.photo_set_item, parent, false);
-        LayoutParams params = view.getLayoutParams();
-        int columnWidth = ((GridView) parent).getColumnWidth();
-        params.height = columnWidth;
-        view.setLayoutParams(params);
         return view;
     }
 
diff --git a/src/com/android/photos/views/SquareImageView.java b/src/com/android/photos/views/SquareImageView.java
new file mode 100644 (file)
index 0000000..14eff10
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.photos.views;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+
+
+public class SquareImageView extends ImageView {
+
+    public SquareImageView(Context context) {
+        super(context);
+    }
+
+    public SquareImageView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
+        if (widthMode == MeasureSpec.EXACTLY && heightMode != MeasureSpec.EXACTLY) {
+            int width = MeasureSpec.getSize(widthMeasureSpec);
+            int height = width;
+            if (heightMode == MeasureSpec.AT_MOST) {
+                height = Math.min(height, MeasureSpec.getSize(heightMeasureSpec));
+            }
+            setMeasuredDimension(width, height);
+        } else {
+            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+        }
+    }
+}