From f29cf16e135442f5be231500d1aa32da77e8e7e8 Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Mon, 19 Aug 2013 17:48:00 -0700 Subject: [PATCH] Adjust UI layout for photos --- MyTracks/res/layout/list_item.xml | 4 ++-- .../res/layout/marker_detail_fragment.xml | 3 ++- .../fragments/MarkerDetailFragment.java | 2 +- .../apps/mytracks/util/ListItemUtils.java | 2 +- .../apps/mytracks/util/PhotoUtils.java | 22 ++++++------------- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/MyTracks/res/layout/list_item.xml b/MyTracks/res/layout/list_item.xml index b30288fd3..a9d419c92 100644 --- a/MyTracks/res/layout/list_item.xml +++ b/MyTracks/res/layout/list_item.xml @@ -68,12 +68,12 @@ limitations under the License. + android:scaleType="fitStart" /> + android:scaleType="fitStart" /> diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java index d7e85a81f..3f1de531a 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java @@ -181,7 +181,7 @@ public class MarkerDetailFragment extends Fragment { @SuppressWarnings("deprecation") int displayHeight = defaultDisplay.getHeight(); bitmap = PhotoUtils.setImageVew( - imageView, Uri.parse(photoUrl), displayWidth, displayHeight, true); + imageView, Uri.parse(photoUrl), displayWidth, displayHeight); } TextView name = (TextView) getView().findViewById(R.id.marker_detail_waypoint_name); diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/ListItemUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/ListItemUtils.java index c3716bdee..d895f94fa 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/ListItemUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/ListItemUtils.java @@ -96,7 +96,7 @@ public class ListItemUtils { Display defaultDisplay = activity.getWindowManager().getDefaultDisplay(); // Set the initial width to 35% of the display width int width = (int) (defaultDisplay.getWidth() * .35); - PhotoUtils.setImageVew(photo, Uri.parse(photoUrl), width, 0, false); + PhotoUtils.setImageVew(photo, Uri.parse(photoUrl), width, 0); } // Set date/time diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/PhotoUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/PhotoUtils.java index b333fb932..f29f96fec 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/PhotoUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/PhotoUtils.java @@ -44,12 +44,10 @@ public class PhotoUtils { * @param uri the image uri * @param displayWidth the display width * @param displayHeight the display height - * @param fitWithIn true to fit within the display area. False to crop and fill - * the display area. */ public static Bitmap setImageVew( - ImageView imageView, Uri uri, int displayWidth, int displayHeight, boolean fitWithIn) { - + ImageView imageView, Uri uri, int displayWidth, int displayHeight) { + // Get the image dimensions BitmapFactory.Options options = new BitmapFactory.Options(); @@ -61,7 +59,6 @@ public class PhotoUtils { int targetHeight = displayHeight; if (targetHeight == 0) { targetHeight = (int) (targetWidth * ((float) options.outHeight / (float) options.outWidth)); - imageView.getLayoutParams().height = targetHeight; } // Set imageWidth and imageHeight based on image rotation @@ -79,8 +76,7 @@ public class PhotoUtils { // Get a scaled down version of the image options.inJustDecodeBounds = false; - options.inSampleSize = getInSampleSize( - imageWidth, imageHeight, targetWidth, targetHeight, fitWithIn); + options.inSampleSize = getInSampleSize(imageWidth, imageHeight, targetWidth, targetHeight); options.inPurgeable = true; Bitmap scaledBitmap = BitmapFactory.decodeFile(uri.getPath(), options); @@ -133,11 +129,9 @@ public class PhotoUtils { * @param imageHeight the image height * @param targetWidth the target width * @param targetHeight the target height - * @param fitWithin true to fit within the target area. False to crop and fill - * all target area. */ private static int getInSampleSize( - int imageWidth, int imageHeight, int targetWidth, int targetHeight, boolean fitWithin) { + int imageWidth, int imageHeight, int targetWidth, int targetHeight) { float widthRatio = 1; if (imageWidth > targetWidth) { widthRatio = (float) imageWidth / (float) targetWidth; @@ -150,11 +144,9 @@ public class PhotoUtils { /* * To fit within the target area, return the larger sample ratio so the - * image will not be larger than the target dimensions. To crop and fill the - * target area, return the smaller sample ratio so the image will be greater - * than the target dimensions. Use Math.floor to not under sample. + * image will not be larger than the target dimensions. Use Math.floor to + * not under sample. */ - return (int) Math.floor( - fitWithin ? Math.max(widthRatio, heightRatio) : Math.min(widthRatio, heightRatio)); + return (int) Math.floor(Math.max(widthRatio, heightRatio)); } }