Adjust UI layout for photos

This commit is contained in:
Jimmy Shih
2013-08-19 17:48:00 -07:00
parent 5f16df912a
commit f29cf16e13
5 changed files with 13 additions and 20 deletions
+2 -2
View File
@@ -68,12 +68,12 @@ limitations under the License.
</TableLayout>
<ImageView
android:id="@+id/list_item_photo"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_width="0dp"
android:scaleType="centerCrop" />
android:scaleType="fitStart" />
</LinearLayout>
<TableLayout
android:layout_height="wrap_content"
@@ -27,10 +27,11 @@ limitations under the License.
android:layout_width="match_parent"
android:orientation="vertical" >
<ImageView
android:adjustViewBounds="true"
android:id="@+id/marker_detail_waypoint_photo"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:scaleType="centerInside" />
android:scaleType="fitStart" />
<TextView
android:id="@+id/marker_detail_waypoint_name"
style="@style/TextLarge.WithTopMargin" />
@@ -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);
@@ -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
@@ -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));
}
}