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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_vertical"
android:gravity="top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:padding="8dp" >
android:paddingBottom="12dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="8dp" >
<ImageView
android:contentDescription="@string/icon_track"
android:id="@+id/list_item_icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
android:layout_width="wrap_content"
android:paddingTop="4dp" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
@@ -35,36 +39,33 @@ limitations under the License.
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/list_item_name"
android:singleLine="true"
style="@style/TextLarge" />
<TextView
android:id="@+id/list_item_category"
android:layout_marginLeft="8dp"
android:singleLine="true"
style="@style/TextSmall" />
</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" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:orientation="vertical" >
<TextView
android:id="@+id/list_item_name"
android:layout_width="fill_parent"
android:singleLine="true"
style="@style/TextLarge" />
</LinearLayout>
<TextView
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>
<TextView
android:id="@+id/list_item_recording"
android:singleLine="true"
style="@style/TextSmall" />
android:id="@+id/list_item_time_distance"
android:singleLine="true"
android:textColor="@android:color/primary_text_dark"
style="@style/TextSmall" />
<TextView
android:id="@+id/list_item_recording"
android:singleLine="true"
style="@style/TextSmall" />
<TextView
android:id="@+id/list_item_description"
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.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/track_list_header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingBottom="2dp"
android:paddingLeft="5dp"
android:paddingTop="2dp"
android:paddingBottom="4dp"
android:paddingLeft="24dp"
android:paddingTop="32dp"
android:text="@string/track_list_shared_with_me"
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:padding">8dp</item>
</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 -->
<style name="ScrollView">
<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.ListItemUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R;
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;
String category = statistics ? null : cursor.getString(categoryIndex);
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,
R.string.icon_marker, cursor.getString(nameIndex), category, null, null, startTime,
description);
R.string.icon_marker, cursor.getString(nameIndex), category, null, null,
cursor.getLong(timeIndex), description);
}
};
listView.setAdapter(resourceCursorAdapter);
@@ -219,7 +219,7 @@ public class SearchListActivity extends AbstractMyTracksActivity
String category = (String) resultMap.get(CATEGORY_FIELD);
String totalTime = (String) resultMap.get(TOTAL_TIME_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);
ListItemUtils.setListItem(SearchListActivity.this, view, isRecording, isPaused, iconId,
@@ -466,7 +466,6 @@ public class SearchListActivity extends AbstractMyTracksActivity
}
boolean statistics = waypoint.getType() == WaypointType.STATISTICS;
long time = waypoint.getLocation().getTime();
resultMap.put(IS_RECORDING_FIELD, false);
resultMap.put(IS_PAUSED_FIELD, true);
@@ -478,8 +477,7 @@ public class SearchListActivity extends AbstractMyTracksActivity
resultMap.put(TOTAL_TIME_FIELD, trackName == null ? null
: getString(R.string.search_list_marker_track_location, trackName));
resultMap.put(TOTAL_DISTANCE_FIELD, null);
resultMap.put(
START_TIME_FIELD, time == 0L ? null : StringUtils.formatRelativeDateTime(this, time));
resultMap.put(START_TIME_FIELD, waypoint.getLocation().getTime());
resultMap.put(DESCRIPTION_FIELD, statistics ? null : waypoint.getDescription());
resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId());
resultMap.put(MARKER_ID_FIELD, waypoint.getId());
@@ -492,23 +490,20 @@ public class SearchListActivity extends AbstractMyTracksActivity
* @param resultMap the result map
*/
private void prepareTrackForDisplay(Track track, Map<String, Object> resultMap) {
boolean isRecording = track.getId() == recordingTrackId;
String name = track.getName();
TripStatistics tripStatitics = track.getTripStatistics();
long startTime = tripStatitics.getStartTime();
String startTimeDisplay = StringUtils.formatDateTime(this, startTime).equals(name) ? null
: StringUtils.formatRelativeDateTime(this, startTime);
String icon = track.getIcon();
String category = icon != null && !icon.equals("") ? null : track.getCategory();
resultMap.put(IS_RECORDING_FIELD, isRecording);
resultMap.put(IS_RECORDING_FIELD, track.getId() == recordingTrackId);
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(NAME_FIELD, name);
resultMap.put(CATEGORY_FIELD, track.getCategory());
resultMap.put(NAME_FIELD, track.getName());
resultMap.put(CATEGORY_FIELD, category);
resultMap.put(TOTAL_TIME_FIELD, StringUtils.formatElapsedTime(tripStatitics.getTotalTime()));
resultMap.put(TOTAL_DISTANCE_FIELD,
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(TRACK_ID_FIELD, track.getId());
resultMap.put(MARKER_ID_FIELD, null);
@@ -392,18 +392,19 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);
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 category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex);
String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
String totalDistance = StringUtils.formatDistance(
TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits);
long startTime = cursor.getLong(startTimeIndex);
String startTimeDisplay = StringUtils.formatDateTime(context, startTime).equals(name) ? null
: StringUtils.formatRelativeDateTime(context, startTime);
String description = cursor.getString(descriptionIndex);
ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused,
iconId, R.string.icon_track, name, cursor.getString(categoryIndex), totalTime,
totalDistance, startTimeDisplay, cursor.getString(descriptionIndex));
iconId, R.string.icon_track, name, category, totalTime,
totalDistance, startTime, description);
}
};
listView.setAdapter(sectionResourceCursorAdapter);
@@ -414,7 +415,7 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
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
@@ -50,7 +50,7 @@ public class ListItemUtils {
*/
public static void setListItem(Context context, View view, boolean isRecording, boolean isPaused,
int iconId, int iconContentDescriptionId, String name, String category, String totalTime,
String totalDistance, String startTime, String description) {
String totalDistance, long startTime, String description) {
if (isRecording) {
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);
nameTextView.setText(name);
TextView categoryTextView = (TextView) view.findViewById(R.id.list_item_category);
setTextView(categoryTextView, category, 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 timeDistanceTextView = (TextView) view.findViewById(R.id.list_item_time_distance);
setTextView(timeDistanceTextView, getTimeDistance(isRecording, totalTime, totalDistance), 0);
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);
String value = isRecording ? context.getString(
@@ -87,9 +82,49 @@ public class ListItemUtils {
setTextView(recordingTextView, value, color);
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.
*
@@ -25,7 +25,6 @@ import android.text.format.DateUtils;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
@@ -65,19 +64,22 @@ public class StringUtils {
}
/**
* Formats the relative date and time based on user's phone date/time
* preferences.
* Formats the time based on user's phone date/time preferences.
*
* @param context the context
* @param time the time in milliseconds
*/
public static String formatRelativeDateTime(Context context, long time) {
long now = Calendar.getInstance().getTimeInMillis();
if (now - time > DateUtils.WEEK_IN_MILLIS) {
return formatDateTime(context, time);
public static String formatTime(Context context, long time) {
if (time == 0L) {
return null;
}
if (DateUtils.isToday(time)) {
return DateUtils.getRelativeTimeSpanString(time, System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString();
} else {
return DateUtils.getRelativeTimeSpanString(
time, now, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString();
return DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_DATE
| DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_MONTH
| DateUtils.FORMAT_ABBREV_TIME);
}
}