Improve marker list layout with photo markers

This commit is contained in:
Jimmy Shih
2013-10-21 11:28:16 -07:00
parent 0e8de4c91a
commit 2e4f4cc4c2
5 changed files with 136 additions and 117 deletions
@@ -20,6 +20,7 @@ import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.net.Uri;
import android.text.format.DateUtils;
import android.view.Display;
@@ -36,6 +37,8 @@ import java.util.Calendar;
*/
public class ListItemUtils {
private static final int LIST_PREFERRED_ITEM_HEIGHT_DEFAULT = 128;
private ListItemUtils() {}
/**
@@ -87,17 +90,14 @@ public class ListItemUtils {
setTextView(timeDistanceTextView,
getTimeDistance(activity, isRecording, isPaused, sharedOwner, totalTime, totalDistance));
// Set photoUrl
ImageView photo = (ImageView) view.findViewById(R.id.list_item_photo);
ImageView photo = (ImageView) view.findViewById(R.id.list_item_background);
if (photoUrl == null || photoUrl.equals("")) {
photo.setVisibility(View.GONE);
} else {
photo.setVisibility(View.VISIBLE);
Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
// Set the initial width to 33% of the display width.
int width = (int) (defaultDisplay.getWidth() * .33);
int height = 0;
PhotoUtils.setImageVew(photo, Uri.parse(photoUrl), width, height);
PhotoUtils.setImageVew(
photo, Uri.parse(photoUrl), defaultDisplay.getWidth(), getPhotoHeight(activity), false);
}
// Set date/time
@@ -108,6 +108,15 @@ public class ListItemUtils {
TextView timeTextView = (TextView) view.findViewById(R.id.list_item_time);
setTextView(timeTextView, startTimeDisplay[1]);
/*
* If column0 is GONE, change to INVISIBLE so column1 is placed at the
* correct position.
*/
if (timeTextView.getVisibility() == View.VISIBLE
&& timeDistanceTextView.getVisibility() == View.GONE) {
timeDistanceTextView.setVisibility(View.INVISIBLE);
}
// Set category/description
TextView descriptionTextView = (TextView) view.findViewById(R.id.list_item_description);
setTextView(descriptionTextView,
@@ -201,4 +210,17 @@ public class ListItemUtils {
textView.setText(value);
}
}
/**
* Gets the photo height.
*
* @param context the context
*/
private static int getPhotoHeight(Context context) {
int[] attrs = new int[] { android.R.attr.listPreferredItemHeight };
TypedArray typeArray = context.obtainStyledAttributes(attrs);
int height = typeArray.getDimensionPixelSize(0, LIST_PREFERRED_ITEM_HEIGHT_DEFAULT);
typeArray.recycle();
return 2 * height;
}
}
@@ -37,13 +37,17 @@ public class PhotoUtils {
*
* @param imageView the image view
* @param uri the image uri
* @param displayWidth the display width
* @param displayHeight the display height
* @param targetWidth the target width
* @param targetHeight the target height
* @param fitWithin true to fit within the target area in order to display the
* entire image (no cropping). False to fill the entire target area.
* (allow cropping).
*/
public static void setImageVew(
ImageView imageView, Uri uri, int displayWidth, int displayHeight) {
ImageView imageView, Uri uri, int targetWidth, int targetHeight, boolean fitWithin) {
if (cancelBitmapLoader(imageView, uri)) {
BitmapLoader bitmapLoader = new BitmapLoader(imageView, uri, displayWidth, displayHeight);
BitmapLoader bitmapLoader = new BitmapLoader(
imageView, uri, targetWidth, targetHeight, fitWithin);
WeakReference<BitmapLoader> bitmapLoaderReference = new WeakReference<BitmapLoader>(
bitmapLoader);
imageView.setTag(bitmapLoaderReference);