forked from upstream-mirrors/OpenTracks
Adjust UI layout for photos
This commit is contained in:
@@ -68,12 +68,12 @@ limitations under the License.
|
|||||||
</TableLayout>
|
</TableLayout>
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/list_item_photo"
|
android:id="@+id/list_item_photo"
|
||||||
android:layout_gravity="center"
|
android:adjustViewBounds="true"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:scaleType="centerCrop" />
|
android:scaleType="fitStart" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<TableLayout
|
<TableLayout
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
@@ -27,10 +27,11 @@ limitations under the License.
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
<ImageView
|
<ImageView
|
||||||
|
android:adjustViewBounds="true"
|
||||||
android:id="@+id/marker_detail_waypoint_photo"
|
android:id="@+id/marker_detail_waypoint_photo"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:scaleType="centerInside" />
|
android:scaleType="fitStart" />
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/marker_detail_waypoint_name"
|
android:id="@+id/marker_detail_waypoint_name"
|
||||||
style="@style/TextLarge.WithTopMargin" />
|
style="@style/TextLarge.WithTopMargin" />
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ public class MarkerDetailFragment extends Fragment {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
int displayHeight = defaultDisplay.getHeight();
|
int displayHeight = defaultDisplay.getHeight();
|
||||||
bitmap = PhotoUtils.setImageVew(
|
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);
|
TextView name = (TextView) getView().findViewById(R.id.marker_detail_waypoint_name);
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class ListItemUtils {
|
|||||||
Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
|
Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
|
||||||
// Set the initial width to 35% of the display width
|
// Set the initial width to 35% of the display width
|
||||||
int width = (int) (defaultDisplay.getWidth() * .35);
|
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
|
// Set date/time
|
||||||
|
|||||||
@@ -44,11 +44,9 @@ public class PhotoUtils {
|
|||||||
* @param uri the image uri
|
* @param uri the image uri
|
||||||
* @param displayWidth the display width
|
* @param displayWidth the display width
|
||||||
* @param displayHeight the display height
|
* @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(
|
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
|
// Get the image dimensions
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
@@ -61,7 +59,6 @@ public class PhotoUtils {
|
|||||||
int targetHeight = displayHeight;
|
int targetHeight = displayHeight;
|
||||||
if (targetHeight == 0) {
|
if (targetHeight == 0) {
|
||||||
targetHeight = (int) (targetWidth * ((float) options.outHeight / (float) options.outWidth));
|
targetHeight = (int) (targetWidth * ((float) options.outHeight / (float) options.outWidth));
|
||||||
imageView.getLayoutParams().height = targetHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set imageWidth and imageHeight based on image rotation
|
// Set imageWidth and imageHeight based on image rotation
|
||||||
@@ -79,8 +76,7 @@ public class PhotoUtils {
|
|||||||
|
|
||||||
// Get a scaled down version of the image
|
// Get a scaled down version of the image
|
||||||
options.inJustDecodeBounds = false;
|
options.inJustDecodeBounds = false;
|
||||||
options.inSampleSize = getInSampleSize(
|
options.inSampleSize = getInSampleSize(imageWidth, imageHeight, targetWidth, targetHeight);
|
||||||
imageWidth, imageHeight, targetWidth, targetHeight, fitWithIn);
|
|
||||||
options.inPurgeable = true;
|
options.inPurgeable = true;
|
||||||
|
|
||||||
Bitmap scaledBitmap = BitmapFactory.decodeFile(uri.getPath(), options);
|
Bitmap scaledBitmap = BitmapFactory.decodeFile(uri.getPath(), options);
|
||||||
@@ -133,11 +129,9 @@ public class PhotoUtils {
|
|||||||
* @param imageHeight the image height
|
* @param imageHeight the image height
|
||||||
* @param targetWidth the target width
|
* @param targetWidth the target width
|
||||||
* @param targetHeight the target height
|
* @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(
|
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;
|
float widthRatio = 1;
|
||||||
if (imageWidth > targetWidth) {
|
if (imageWidth > targetWidth) {
|
||||||
widthRatio = (float) imageWidth / (float) 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
|
* 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
|
* image will not be larger than the target dimensions. Use Math.floor to
|
||||||
* target area, return the smaller sample ratio so the image will be greater
|
* not under sample.
|
||||||
* than the target dimensions. Use Math.floor to not under sample.
|
|
||||||
*/
|
*/
|
||||||
return (int) Math.floor(
|
return (int) Math.floor(Math.max(widthRatio, heightRatio));
|
||||||
fitWithin ? Math.max(widthRatio, heightRatio) : Math.min(widthRatio, heightRatio));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user