Improve the list view layout.

This commit is contained in:
Jimmy Shih
2013-02-13 15:28:53 -08:00
parent 4f8e8adc23
commit 0b5af64ca1
8 changed files with 110 additions and 86 deletions
+30 -29
View File
@@ -15,17 +15,21 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_vertical" android:gravity="top"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:minHeight="?android:attr/listPreferredItemHeight" android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal" android:orientation="horizontal"
android:padding="8dp" > android:paddingBottom="12dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="8dp" >
<ImageView <ImageView
android:contentDescription="@string/icon_track" android:contentDescription="@string/icon_track"
android:id="@+id/list_item_icon" android:id="@+id/list_item_icon"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" /> android:layout_width="wrap_content"
android:paddingTop="4dp" />
<LinearLayout <LinearLayout
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
@@ -35,36 +39,33 @@ limitations under the License.
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:orientation="horizontal" > android:orientation="horizontal" >
<TextView <LinearLayout
android:id="@+id/list_item_name" android:layout_height="wrap_content"
android:singleLine="true" android:layout_weight="1"
style="@style/TextLarge" /> android:layout_width="0dp"
<TextView android:orientation="vertical" >
android:id="@+id/list_item_category" <TextView
android:layout_marginLeft="8dp" android:id="@+id/list_item_name"
android:singleLine="true" android:layout_width="fill_parent"
style="@style/TextSmall" /> android:singleLine="true"
</LinearLayout> style="@style/TextLarge" />
<LinearLayout </LinearLayout>
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/list_item_total_time"
android:layout_marginRight="8dp"
style="@style/ListItemStats" />
<TextView
android:id="@+id/list_item_total_distance"
android:layout_marginRight="8dp"
style="@style/ListItemStats" />
<TextView <TextView
android:id="@+id/list_item_start_time" android:id="@+id/list_item_start_time"
style="@style/ListItemStats" /> android:layout_gravity="bottom"
android:singleLine="true"
android:textColor="@android:color/secondary_text_dark"
style="@style/TextSmall" />
</LinearLayout> </LinearLayout>
<TextView <TextView
android:id="@+id/list_item_recording" android:id="@+id/list_item_time_distance"
android:singleLine="true" android:singleLine="true"
style="@style/TextSmall" /> android:textColor="@android:color/primary_text_dark"
style="@style/TextSmall" />
<TextView
android:id="@+id/list_item_recording"
android:singleLine="true"
style="@style/TextSmall" />
<TextView <TextView
android:id="@+id/list_item_description" android:id="@+id/list_item_description"
android:singleLine="false" android:singleLine="false"
+3 -4
View File
@@ -15,11 +15,10 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android" <TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/track_list_header"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:paddingBottom="2dp" android:paddingBottom="4dp"
android:paddingLeft="5dp" android:paddingLeft="24dp"
android:paddingTop="2dp" android:paddingTop="32dp"
android:text="@string/track_list_shared_with_me" android:text="@string/track_list_shared_with_me"
style="?android:attr/listSeparatorTextViewStyle" /> style="?android:attr/listSeparatorTextViewStyle" />
-5
View File
@@ -106,11 +106,6 @@ limitations under the License.
<item name="android:layout_gravity">center</item> <item name="android:layout_gravity">center</item>
<item name="android:padding">8dp</item> <item name="android:padding">8dp</item>
</style> </style>
<!-- list item stats -->
<style name="ListItemStats" parent="@style/TextSmall">
<item name="android:singleLine">true</item>
<item name="android:textColor">@android:color/secondary_text_dark</item>
</style>
<!-- scroll view --> <!-- scroll view -->
<style name="ScrollView"> <style name="ScrollView">
<item name="android:layout_height">match_parent</item> <item name="android:layout_height">match_parent</item>
@@ -26,7 +26,6 @@ import com.google.android.apps.mytracks.util.ApiAdapterFactory;
import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.ListItemUtils; import com.google.android.apps.mytracks.util.ListItemUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.content.Context; import android.content.Context;
@@ -170,13 +169,10 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
int iconId = statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin; int iconId = statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin;
String category = statistics ? null : cursor.getString(categoryIndex); String category = statistics ? null : cursor.getString(categoryIndex);
String description = statistics ? null : cursor.getString(descriptionIndex); String description = statistics ? null : cursor.getString(descriptionIndex);
long time = cursor.getLong(timeIndex);
String startTime = time == 0L ? null
: StringUtils.formatRelativeDateTime(MarkerListActivity.this, time);
ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId, ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId,
R.string.icon_marker, cursor.getString(nameIndex), category, null, null, startTime, R.string.icon_marker, cursor.getString(nameIndex), category, null, null,
description); cursor.getLong(timeIndex), description);
} }
}; };
listView.setAdapter(resourceCursorAdapter); listView.setAdapter(resourceCursorAdapter);
@@ -219,7 +219,7 @@ public class SearchListActivity extends AbstractMyTracksActivity
String category = (String) resultMap.get(CATEGORY_FIELD); String category = (String) resultMap.get(CATEGORY_FIELD);
String totalTime = (String) resultMap.get(TOTAL_TIME_FIELD); String totalTime = (String) resultMap.get(TOTAL_TIME_FIELD);
String totalDistance = (String) resultMap.get(TOTAL_DISTANCE_FIELD); String totalDistance = (String) resultMap.get(TOTAL_DISTANCE_FIELD);
String startTime = (String) resultMap.get(START_TIME_FIELD); Long startTime = (Long) resultMap.get(START_TIME_FIELD);
String description = (String) resultMap.get(DESCRIPTION_FIELD); String description = (String) resultMap.get(DESCRIPTION_FIELD);
ListItemUtils.setListItem(SearchListActivity.this, view, isRecording, isPaused, iconId, ListItemUtils.setListItem(SearchListActivity.this, view, isRecording, isPaused, iconId,
@@ -466,7 +466,6 @@ public class SearchListActivity extends AbstractMyTracksActivity
} }
boolean statistics = waypoint.getType() == WaypointType.STATISTICS; boolean statistics = waypoint.getType() == WaypointType.STATISTICS;
long time = waypoint.getLocation().getTime();
resultMap.put(IS_RECORDING_FIELD, false); resultMap.put(IS_RECORDING_FIELD, false);
resultMap.put(IS_PAUSED_FIELD, true); resultMap.put(IS_PAUSED_FIELD, true);
@@ -478,8 +477,7 @@ public class SearchListActivity extends AbstractMyTracksActivity
resultMap.put(TOTAL_TIME_FIELD, trackName == null ? null resultMap.put(TOTAL_TIME_FIELD, trackName == null ? null
: getString(R.string.search_list_marker_track_location, trackName)); : getString(R.string.search_list_marker_track_location, trackName));
resultMap.put(TOTAL_DISTANCE_FIELD, null); resultMap.put(TOTAL_DISTANCE_FIELD, null);
resultMap.put( resultMap.put(START_TIME_FIELD, waypoint.getLocation().getTime());
START_TIME_FIELD, time == 0L ? null : StringUtils.formatRelativeDateTime(this, time));
resultMap.put(DESCRIPTION_FIELD, statistics ? null : waypoint.getDescription()); resultMap.put(DESCRIPTION_FIELD, statistics ? null : waypoint.getDescription());
resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId()); resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId());
resultMap.put(MARKER_ID_FIELD, waypoint.getId()); resultMap.put(MARKER_ID_FIELD, waypoint.getId());
@@ -492,23 +490,20 @@ public class SearchListActivity extends AbstractMyTracksActivity
* @param resultMap the result map * @param resultMap the result map
*/ */
private void prepareTrackForDisplay(Track track, Map<String, Object> resultMap) { private void prepareTrackForDisplay(Track track, Map<String, Object> resultMap) {
boolean isRecording = track.getId() == recordingTrackId;
String name = track.getName();
TripStatistics tripStatitics = track.getTripStatistics(); TripStatistics tripStatitics = track.getTripStatistics();
long startTime = tripStatitics.getStartTime(); String icon = track.getIcon();
String startTimeDisplay = StringUtils.formatDateTime(this, startTime).equals(name) ? null String category = icon != null && !icon.equals("") ? null : track.getCategory();
: StringUtils.formatRelativeDateTime(this, startTime);
resultMap.put(IS_RECORDING_FIELD, isRecording); resultMap.put(IS_RECORDING_FIELD, track.getId() == recordingTrackId);
resultMap.put(IS_PAUSED_FIELD, recordingTrackPaused); resultMap.put(IS_PAUSED_FIELD, recordingTrackPaused);
resultMap.put(ICON_ID_FIELD, TrackIconUtils.getIconDrawable(track.getIcon())); resultMap.put(ICON_ID_FIELD, TrackIconUtils.getIconDrawable(icon));
resultMap.put(ICON_CONTENT_DESCRIPTION_ID_FIELD, R.string.icon_track); resultMap.put(ICON_CONTENT_DESCRIPTION_ID_FIELD, R.string.icon_track);
resultMap.put(NAME_FIELD, name); resultMap.put(NAME_FIELD, track.getName());
resultMap.put(CATEGORY_FIELD, track.getCategory()); resultMap.put(CATEGORY_FIELD, category);
resultMap.put(TOTAL_TIME_FIELD, StringUtils.formatElapsedTime(tripStatitics.getTotalTime())); resultMap.put(TOTAL_TIME_FIELD, StringUtils.formatElapsedTime(tripStatitics.getTotalTime()));
resultMap.put(TOTAL_DISTANCE_FIELD, resultMap.put(TOTAL_DISTANCE_FIELD,
StringUtils.formatDistance(this, tripStatitics.getTotalDistance(), metricUnits)); StringUtils.formatDistance(this, tripStatitics.getTotalDistance(), metricUnits));
resultMap.put(START_TIME_FIELD, startTimeDisplay); resultMap.put(START_TIME_FIELD, tripStatitics.getStartTime());
resultMap.put(DESCRIPTION_FIELD, track.getDescription()); resultMap.put(DESCRIPTION_FIELD, track.getDescription());
resultMap.put(TRACK_ID_FIELD, track.getId()); resultMap.put(TRACK_ID_FIELD, track.getId());
resultMap.put(MARKER_ID_FIELD, null); resultMap.put(MARKER_ID_FIELD, null);
@@ -392,18 +392,19 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION); int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);
boolean isRecording = cursor.getLong(idIndex) == recordingTrackId; boolean isRecording = cursor.getLong(idIndex) == recordingTrackId;
int iconId = TrackIconUtils.getIconDrawable(cursor.getString(iconIndex)); String icon = cursor.getString(iconIndex);
int iconId = TrackIconUtils.getIconDrawable(icon);
String name = cursor.getString(nameIndex); String name = cursor.getString(nameIndex);
String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex);
String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex)); String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
String totalDistance = StringUtils.formatDistance( String totalDistance = StringUtils.formatDistance(
TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits); TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits);
long startTime = cursor.getLong(startTimeIndex); long startTime = cursor.getLong(startTimeIndex);
String startTimeDisplay = StringUtils.formatDateTime(context, startTime).equals(name) ? null String description = cursor.getString(descriptionIndex);
: StringUtils.formatRelativeDateTime(context, startTime);
ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused, ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused,
iconId, R.string.icon_track, name, cursor.getString(categoryIndex), totalTime, iconId, R.string.icon_track, name, category, totalTime,
totalDistance, startTimeDisplay, cursor.getString(descriptionIndex)); totalDistance, startTime, description);
} }
}; };
listView.setAdapter(sectionResourceCursorAdapter); listView.setAdapter(sectionResourceCursorAdapter);
@@ -414,7 +415,7 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
@Override @Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
return new CursorLoader(TrackListActivity.this, TracksColumns.CONTENT_URI, PROJECTION, null, return new CursorLoader(TrackListActivity.this, TracksColumns.CONTENT_URI, PROJECTION, null,
null, TracksColumns.SHAREDWITHME + " ASC, " + TracksColumns._ID + " DESC"); null, TracksColumns.SHAREDWITHME + " ASC, " + TracksColumns.STARTTIME + " DESC");
} }
@Override @Override
@@ -50,7 +50,7 @@ public class ListItemUtils {
*/ */
public static void setListItem(Context context, View view, boolean isRecording, boolean isPaused, public static void setListItem(Context context, View view, boolean isRecording, boolean isPaused,
int iconId, int iconContentDescriptionId, String name, String category, String totalTime, int iconId, int iconContentDescriptionId, String name, String category, String totalTime,
String totalDistance, String startTime, String description) { String totalDistance, long startTime, String description) {
if (isRecording) { if (isRecording) {
iconId = isPaused ? R.drawable.track_paused : R.drawable.track_recording; iconId = isPaused ? R.drawable.track_paused : R.drawable.track_recording;
@@ -65,17 +65,12 @@ public class ListItemUtils {
TextView nameTextView = (TextView) view.findViewById(R.id.list_item_name); TextView nameTextView = (TextView) view.findViewById(R.id.list_item_name);
nameTextView.setText(name); nameTextView.setText(name);
TextView categoryTextView = (TextView) view.findViewById(R.id.list_item_category); TextView timeDistanceTextView = (TextView) view.findViewById(R.id.list_item_time_distance);
setTextView(categoryTextView, category, 0); setTextView(timeDistanceTextView, getTimeDistance(isRecording, totalTime, totalDistance), 0);
TextView totalTimeTextView = (TextView) view.findViewById(R.id.list_item_total_time);
setTextView(totalTimeTextView, isRecording ? null : totalTime, 0);
TextView totalDistanceTextView = (TextView) view.findViewById(R.id.list_item_total_distance);
setTextView(totalDistanceTextView, isRecording ? null : totalDistance, 0);
TextView startTimeTextView = (TextView) view.findViewById(R.id.list_item_start_time); TextView startTimeTextView = (TextView) view.findViewById(R.id.list_item_start_time);
setTextView(startTimeTextView, isRecording ? null : startTime, 0); setTextView(
startTimeTextView, isRecording ? null : StringUtils.formatTime(context, startTime), 0);
TextView recordingTextView = (TextView) view.findViewById(R.id.list_item_recording); TextView recordingTextView = (TextView) view.findViewById(R.id.list_item_recording);
String value = isRecording ? context.getString( String value = isRecording ? context.getString(
@@ -87,9 +82,49 @@ public class ListItemUtils {
setTextView(recordingTextView, value, color); setTextView(recordingTextView, value, color);
TextView descriptionTextView = (TextView) view.findViewById(R.id.list_item_description); TextView descriptionTextView = (TextView) view.findViewById(R.id.list_item_description);
setTextView(descriptionTextView, isRecording ? null : description, 0); setTextView(descriptionTextView, getDescription(isRecording, category, description), 0);
} }
/**
* Gets the time/distance text.
*
* @param isRecording true if recording
* @param totalTime the total time
* @param totalDistance the total distance
*/
private static String getTimeDistance(boolean isRecording, String totalTime, String totalDistance) {
if (isRecording) {
return null;
}
if (totalDistance == null || totalDistance.length() == 0) {
return totalTime;
}
if (totalTime == null || totalTime.length() == 0) {
return totalDistance;
}
return totalTime + " (" + totalDistance + ")";
}
/**
* Gets the description text.
*
* @param isRecording true if recording
* @param category the category
* @param description the description
*/
private static String getDescription(boolean isRecording, String category, String description) {
if (isRecording) {
return null;
}
if (category == null || category.length() == 0) {
return description;
}
if (description == null || description.length() == 0) {
return category;
}
return "[" + category + "] " + description;
}
/** /**
* Sets a text view. * Sets a text view.
* *
@@ -25,7 +25,6 @@ import android.text.format.DateUtils;
import java.text.ParsePosition; import java.text.ParsePosition;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
@@ -65,19 +64,22 @@ public class StringUtils {
} }
/** /**
* Formats the relative date and time based on user's phone date/time * Formats the time based on user's phone date/time preferences.
* preferences.
* *
* @param context the context * @param context the context
* @param time the time in milliseconds * @param time the time in milliseconds
*/ */
public static String formatRelativeDateTime(Context context, long time) { public static String formatTime(Context context, long time) {
long now = Calendar.getInstance().getTimeInMillis(); if (time == 0L) {
if (now - time > DateUtils.WEEK_IN_MILLIS) { return null;
return formatDateTime(context, time); }
if (DateUtils.isToday(time)) {
return DateUtils.getRelativeTimeSpanString(time, System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString();
} else { } else {
return DateUtils.getRelativeTimeSpanString( return DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_DATE
time, now, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString(); | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_MONTH
| DateUtils.FORMAT_ABBREV_TIME);
} }
} }