diff --git a/MyTracks/res/layout/list_item.xml b/MyTracks/res/layout/list_item.xml index 28d559265..0892c208d 100644 --- a/MyTracks/res/layout/list_item.xml +++ b/MyTracks/res/layout/list_item.xml @@ -23,6 +23,7 @@ limitations under the License. android:layout_height="match_parent" android:layout_width="match_parent" android:scaleType="centerCrop" /> + - + - + - + + + - + + + + + + - + diff --git a/MyTracks/res/layout/track_list_header.xml b/MyTracks/res/layout/track_list_header.xml index b9c7b085c..203fa145c 100644 --- a/MyTracks/res/layout/track_list_header.xml +++ b/MyTracks/res/layout/track_list_header.xml @@ -16,7 +16,7 @@ limitations under the License. --> 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) }; } /** diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java index 405126eea..937836af4 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java @@ -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. * diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java index 0b8d5a83d..8a5e24274 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java @@ -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); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java index c457f4758..efcba5995 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java @@ -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());