Add marker count on the track list page

This commit is contained in:
Jimmy Shih
2013-10-29 15:35:59 -07:00
parent 2f9b8775e8
commit 64c03a40a7
10 changed files with 155 additions and 93 deletions
+27 -13
View File
@@ -23,6 +23,7 @@ limitations under the License.
android:layout_height="match_parent"
android:layout_width="match_parent"
android:scaleType="centerCrop" />
<!-- Table 1 -->
<TableLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
@@ -33,9 +34,9 @@ limitations under the License.
android:shrinkColumns="1"
android:stretchColumns="1"
style="@style/ListItem" >
<!-- First row -->
<!-- Table 1: Row 1 -->
<TableRow>
<!-- First column -->
<!-- Table 1: Row 1: Column 1: (icon) -->
<ImageView
android:contentDescription="@string/icon_track"
android:id="@+id/list_item_icon"
@@ -44,44 +45,57 @@ limitations under the License.
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_width="wrap_content" />
<!-- Second column -->
<!-- Table 1: Row 1: Column 2: (Table 2) -->
<TableLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:shrinkColumns="0"
android:stretchColumns="0" >
<TableRow>
<!-- Table 2: Row 1: Column 1: (name) -->
<TextView
android:ellipsize="end"
android:id="@+id/list_item_name"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:singleLine="true"
style="@style/TextMedium" />
<!-- Table 2: Row 1: Column 2: (date) -->
<TextView
android:id="@+id/list_item_date"
style="@style/ListItemDate" />
</TableRow>
<TableRow>
<!-- Need to match the style set in ListItemUtils.setListItem -->
<TextView
android:ellipsize="end"
android:id="@+id/list_item_time_distance"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:singleLine="true"
style="@style/TextSmall" />
<!-- Table 2: Row 2: Column 1: (shared owner, total time, total distance, and marker count) -->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent" >
<TextView
android:ellipsize="end"
android:id="@+id/list_item_owner_time_distance"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:singleLine="true"
style="@style/TextSmall" />
<TextView
android:drawablePadding="4dp"
android:id="@+id/list_item_marker_count"
android:layout_gravity="bottom"
style="@style/TextSmall" />
</LinearLayout>
<!-- Table 2: Row 2: Column 2: (time) -->
<TextView
android:id="@+id/list_item_time"
style="@style/ListItemDate" />
</TableRow>
</TableLayout>
</TableRow>
<!-- Second row -->
<TableRow>
<!-- Table 1: Row 2: (category and description) -->
<TextView
android:ellipsize="end"
android:id="@+id/list_item_description"
android:id="@+id/list_item_category_description"
android:layout_column="1"
android:maxLines="2"
android:singleLine="false"
+1 -1
View File
@@ -46,7 +46,7 @@ limitations under the License.
android:id="@+id/track_edit_activity_type"
android:imeOptions="actionNext"
android:layout_gravity="bottom"
android:layout_height="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="0dp"
style="@style/EditCategory" />
+1 -1
View File
@@ -16,7 +16,7 @@ limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:paddingBottom="4dp"
android:paddingLeft="24dp"
android:paddingTop="32dp"
@@ -173,10 +173,10 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
public void bindView(View view, Context context, Cursor cursor) {
int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE);
int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME);
int photoUrlIndex = cursor.getColumnIndex(WaypointsColumns.PHOTOURL);
int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME);
int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY);
int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION);
int photoUrlIndex = cursor.getColumnIndex(WaypointsColumns.PHOTOURL);
boolean statistics = WaypointType.values()[cursor.getInt(typeIndex)]
== WaypointType.STATISTICS;
@@ -184,14 +184,14 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
: R.drawable.ic_marker_blue_pushpin;
String name = cursor.getString(nameIndex);
String sharedOwner = track.getSharedOwner();
String photoUrl = cursor.getString(photoUrlIndex);
long time = cursor.getLong(timeIndex);
String category = statistics ? null : cursor.getString(categoryIndex);
String description = statistics ? null : cursor.getString(descriptionIndex);
String photoUrl = cursor.getString(photoUrlIndex);
ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId,
R.string.icon_marker, name, sharedOwner, null, null, photoUrl, time, category,
description);
R.string.icon_marker, name, sharedOwner, null, null, 0, time, category, description,
photoUrl);
}
};
listView.setAdapter(resourceCursorAdapter);
@@ -86,10 +86,11 @@ public class SearchListActivity extends AbstractSendToGoogleActivity implements
private static final String SHARED_OWNER_FIELD = "sharedOwner";
private static final String TOTAL_TIME_FIELD = "totalTime";
private static final String TOTAL_DISTANCE_FIELD = "totalDistance";
private static final String PHOTO_URL_FIELD = "photoUrl";
private static final String MARKER_COUNT_FIELD = "markerCount";
private static final String START_TIME_FIELD = "startTime";
private static final String CATEGORY_FIELD = "category";
private static final String DESCRIPTION_FIELD = "description";
private static final String PHOTO_URL_FIELD = "photoUrl";
private static final String TRACK_ID_FIELD = "trackId";
private static final String MARKER_ID_FIELD = "markerId";
@@ -233,14 +234,15 @@ public class SearchListActivity extends AbstractSendToGoogleActivity implements
String sharedOwner = (String) resultMap.get(SHARED_OWNER_FIELD);
String totalTime = (String) resultMap.get(TOTAL_TIME_FIELD);
String totalDistance = (String) resultMap.get(TOTAL_DISTANCE_FIELD);
String photoUrl = (String) resultMap.get(PHOTO_URL_FIELD);
int markerCount = (Integer) resultMap.get(MARKER_COUNT_FIELD);
Long startTime = (Long) resultMap.get(START_TIME_FIELD);
String category = (String) resultMap.get(CATEGORY_FIELD);
String description = (String) resultMap.get(DESCRIPTION_FIELD);
String photoUrl = (String) resultMap.get(PHOTO_URL_FIELD);
ListItemUtils.setListItem(SearchListActivity.this, view, isRecording, isPaused, iconId,
iconContentDescriptionId, name, sharedOwner, totalTime, totalDistance, photoUrl,
startTime, category, description);
iconContentDescriptionId, name, sharedOwner, totalTime, totalDistance, markerCount,
startTime, category, description, photoUrl);
return view;
}
};
@@ -496,10 +498,11 @@ public class SearchListActivity extends AbstractSendToGoogleActivity implements
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(PHOTO_URL_FIELD, waypoint.getPhotoUrl());
resultMap.put(MARKER_COUNT_FIELD, 0);
resultMap.put(START_TIME_FIELD, waypoint.getLocation().getTime());
resultMap.put(CATEGORY_FIELD, statistics ? null : waypoint.getCategory());
resultMap.put(DESCRIPTION_FIELD, statistics ? null : waypoint.getDescription());
resultMap.put(PHOTO_URL_FIELD, waypoint.getPhotoUrl());
resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId());
resultMap.put(MARKER_ID_FIELD, waypoint.getId());
}
@@ -524,10 +527,11 @@ public class SearchListActivity extends AbstractSendToGoogleActivity implements
resultMap.put(TOTAL_TIME_FIELD, StringUtils.formatElapsedTime(tripStatitics.getTotalTime()));
resultMap.put(TOTAL_DISTANCE_FIELD,
StringUtils.formatDistance(this, tripStatitics.getTotalDistance(), metricUnits));
resultMap.put(PHOTO_URL_FIELD, null);
resultMap.put(MARKER_COUNT_FIELD, myTracksProviderUtils.getWaypointCount(track.getId()));
resultMap.put(START_TIME_FIELD, tripStatitics.getStartTime());
resultMap.put(CATEGORY_FIELD, category);
resultMap.put(DESCRIPTION_FIELD, track.getDescription());
resultMap.put(PHOTO_URL_FIELD, null);
resultMap.put(TRACK_ID_FIELD, track.getId());
resultMap.put(MARKER_ID_FIELD, null);
}
@@ -361,11 +361,12 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
int sharedOwnerIndex = cursor.getColumnIndex(TracksColumns.SHAREDOWNER);
int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME);
int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE);
int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY);
int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);
boolean isRecording = cursor.getLong(idIndex) == recordingTrackId;
long trackId = cursor.getLong(idIndex);
boolean isRecording = trackId == recordingTrackId;
String icon = cursor.getString(iconIndex);
int iconId = TrackIconUtils.getIconDrawable(icon);
String name = cursor.getString(nameIndex);
@@ -373,13 +374,14 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
String totalDistance = StringUtils.formatDistance(
TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits);
long startTime = cursor.getLong(startTimeIndex);
String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex);
int markerCount = myTracksProviderUtils.getWaypointCount(trackId);
long startTime = cursor.getLong(startTimeIndex);
String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex);
String description = cursor.getString(descriptionIndex);
ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused,
iconId, R.string.icon_track, name, sharedOwner, totalTime, totalDistance, null,
startTime, category, description);
iconId, R.string.icon_track, name, sharedOwner, totalTime, totalDistance, markerCount,
startTime, category, description, null);
}
};
listView.setAdapter(sectionResourceCursorAdapter);
@@ -21,6 +21,7 @@ import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.format.DateUtils;
import android.view.Display;
@@ -54,16 +55,17 @@ public class ListItemUtils {
* @param sharedOwner if shared with me track, the owner, else null
* @param totalTime the total time value
* @param totalDistance the total distance value
* @param photoUrl the photo url
* @param markerCount the marker count
* @param startTime the start time value
* @param category the category value
* @param description the description value
* @param photoUrl the photo url
*/
@SuppressWarnings("deprecation")
public static void setListItem(Activity activity, View view, boolean isRecording,
boolean isPaused, int iconId, int iconContentDescriptionId, String name, String sharedOwner,
String totalTime, String totalDistance, String photoUrl, long startTime, String category,
String description) {
String totalTime, String totalDistance, int markerCount, long startTime, String category,
String description, String photoUrl) {
if (isRecording) {
iconId = isPaused ? R.drawable.ic_track_paused : R.drawable.ic_track_recording;
@@ -80,16 +82,60 @@ public class ListItemUtils {
nameTextView.setText(name);
// Set sharedOwner/totalTime/totalDistance
TextView timeDistanceTextView = (TextView) view.findViewById(R.id.list_item_time_distance);
TextView ownerTimeDistanceTextView = (TextView) view.findViewById(
R.id.list_item_owner_time_distance);
String ownerTimeDistance;
if (isRecording) {
timeDistanceTextView.setTextColor(activity.getResources()
ownerTimeDistanceTextView.setTextColor(activity.getResources()
.getColor(isPaused ? android.R.color.white : R.color.recording_text));
ownerTimeDistance = activity.getString(
isPaused ? R.string.generic_paused : R.string.generic_recording);
} else {
// Need to match the style set in list_item.xml
timeDistanceTextView.setTextAppearance(activity, R.style.TextSmall);
ownerTimeDistanceTextView.setTextAppearance(activity, R.style.TextSmall);
ownerTimeDistance = getOwnerTimeDistance(sharedOwner, totalTime, totalDistance);
if (markerCount > 0) {
ownerTimeDistance += " \u2027 ";
}
}
setTextView(timeDistanceTextView,
getTimeDistance(activity, isRecording, isPaused, sharedOwner, totalTime, totalDistance));
setTextView(ownerTimeDistanceTextView, ownerTimeDistance);
// Set markerCount
TextView markerCountTextView = (TextView) view.findViewById(R.id.list_item_marker_count);
if (markerCount > 0) {
markerCountTextView.setVisibility(View.VISIBLE);
Drawable markerDrawable = activity.getResources()
.getDrawable(R.drawable.ic_menu_insert_marker);
int size = markerCountTextView.getLineHeight();
markerDrawable.setBounds(0, 0, size, size);
markerCountTextView.setCompoundDrawables(markerDrawable, null, null, null);
markerCountTextView.setText(markerCount + "");
} else {
markerCountTextView.setVisibility(View.GONE);
}
// Set date/time
String[] dateTime = getDateTime(isRecording, activity, startTime);
TextView dateTextView = (TextView) view.findViewById(R.id.list_item_date);
setTextView(dateTextView, dateTime[0]);
TextView timeTextView = (TextView) view.findViewById(R.id.list_item_time);
setTextView(timeTextView, dateTime[1]);
/*
* If column0 is GONE, change to INVISIBLE so column1 is placed at the
* correct position.
*/
if (timeTextView.getVisibility() == View.VISIBLE
&& ownerTimeDistanceTextView.getVisibility() == View.GONE) {
ownerTimeDistanceTextView.setVisibility(View.INVISIBLE);
}
// Set category and description
TextView categoryDescription = (TextView) view.findViewById(
R.id.list_item_category_description);
setTextView(categoryDescription,
isRecording ? null : StringUtils.getCategoryDescription(category, description));
ImageView photo = (ImageView) view.findViewById(R.id.list_item_background);
if (photoUrl == null || photoUrl.equals("")) {
@@ -100,45 +146,17 @@ public class ListItemUtils {
PhotoUtils.setImageVew(
photo, Uri.parse(photoUrl), defaultDisplay.getWidth(), getPhotoHeight(activity), false);
}
// Set date/time
String[] startTimeDisplay = getStartTime(isRecording, activity, startTime);
TextView dateTextView = (TextView) view.findViewById(R.id.list_item_date);
setTextView(dateTextView, startTimeDisplay[0]);
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,
isRecording ? null : StringUtils.getCategoryDescription(category, description));
}
/**
* Gets the time/distance text.
* Gets a string for share owner, total time, and total distance.
*
* @param context the context
* @param isRecording true if recording
* @param isPaused true if paused
* @param sharedOwner the shared owner
* @param totalTime the total time
* @param totalDistance the total distance
* @param sharedOwner the share owner. Can be null
* @param totalTime the total time. Can be null
* @param totalDistance the total distance. Can be null
*/
private static String getTimeDistance(Context context, boolean isRecording, boolean isPaused,
private static String getOwnerTimeDistance(
String sharedOwner, String totalTime, String totalDistance) {
if (isRecording) {
return context.getString(isPaused ? R.string.generic_paused : R.string.generic_recording);
}
StringBuffer buffer = new StringBuffer();
if (sharedOwner != null && sharedOwner.length() != 0) {
buffer.append(sharedOwner);
@@ -159,29 +177,28 @@ public class ListItemUtils {
}
/**
* Gets the start time text.
* Gets the date and time as an array of two strings.
*
* @param isRecording true if recording
* @param context the context
* @param startTime the start time
* @return array of two strings.
* @param time the start time
*/
private static String[] getStartTime(boolean isRecording, Context context, long startTime) {
if (isRecording || startTime == 0L) {
private static String[] getDateTime(boolean isRecording, Context context, long time) {
if (isRecording || time == 0L) {
return new String[] { null, null };
}
if (DateUtils.isToday(startTime)) {
if (DateUtils.isToday(time)) {
return new String[] { DateUtils.getRelativeTimeSpanString(
startTime, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE).toString(), null };
}
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL;
if (!isThisYear(startTime)) {
flags |= DateUtils.FORMAT_NUMERIC_DATE;
int dateFlags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL;
if (!isThisYear(time)) {
dateFlags |= DateUtils.FORMAT_NUMERIC_DATE;
}
return new String[] { DateUtils.formatDateTime(context, startTime, flags),
DateUtils.formatDateTime(
context, startTime, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME) };
int timeFlags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME;
return new String[] { DateUtils.formatDateTime(context, time, dateFlags),
DateUtils.formatDateTime(context, time, timeFlags) };
}
/**
@@ -190,6 +190,13 @@ public interface MyTracksProviderUtils {
*/
public Cursor getWaypointCursor(long trackId, long minWaypointId, int maxWaypoints);
/**
* Gets the number of waypoints for a track.
*
* @param trackId the track id
*/
public int getWaypointCount(long trackId);
/**
* Inserts a waypoint.
*
@@ -657,6 +657,24 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
return getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID, maxWaypoints);
}
@Override
public int getWaypointCount(long trackId) {
if (trackId < 0) {
return 0;
}
String[] projection = new String[] { "count(*) AS count" };
String selection = WaypointsColumns.TRACKID + "=?";
String[] selectionArgs = new String[] { Long.toString(trackId) };
Cursor cursor = contentResolver.query(
WaypointsColumns.CONTENT_URI, projection, selection, selectionArgs, WaypointsColumns._ID);
cursor.moveToFirst();
int count = cursor.getInt(0);
// not count the first waypoint
return count > 0 ? count - 1 : 0;
}
@Override
public Uri insertWaypoint(Waypoint waypoint) {
waypoint.setId(-1L);
@@ -225,8 +225,8 @@ public class TripStatisticsUpdaterTest extends TestCase {
Location location = getLocation(i + locationOffset, (i + locationOffset) * .001, MOVING_SPEED,
startTime + (timeOffset + i) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT,
PreferencesUtils.STATS_WEIGHT_DEFAULT, true);
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.FOOT,
PreferencesUtils.STATS_WEIGHT_DEFAULT);
tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime());
@@ -272,8 +272,8 @@ public class TripStatisticsUpdaterTest extends TestCase {
Location location = getLocation(
locationOffset, locationOffset * .001, 0, startTime + (i + timeOffset) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT,
PreferencesUtils.STATS_WEIGHT_DEFAULT, false);
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, false, ActivityType.FOOT,
PreferencesUtils.STATS_WEIGHT_DEFAULT);
tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime());
@@ -310,8 +310,8 @@ public class TripStatisticsUpdaterTest extends TestCase {
Location location = getLocation(i + locationOffset, (i + locationOffset) * .001, 99999,
startTime + (timeOffset + i) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT,
PreferencesUtils.STATS_WEIGHT_DEFAULT, true);
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.FOOT,
PreferencesUtils.STATS_WEIGHT_DEFAULT);
tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertTrue(tripStatistics.getMovingTime() <= tripStatistics.getTotalTime());