forked from upstream-mirrors/OpenTracks
Add relative date time for start time within the past week.
Place the list item on the right by itself.
This commit is contained in:
@@ -19,41 +19,53 @@ limitations under the License.
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:orientation="vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="8dp" >
|
||||
<ImageView
|
||||
android:contentDescription="@string/icon_track"
|
||||
android:id="@+id/list_item_icon"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:src="@drawable/track" />
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="horizontal" >
|
||||
android:orientation="vertical" >
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_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="fill_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
|
||||
android:id="@+id/list_item_start_time"
|
||||
style="@style/ListItemStats" />
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/list_item_name"
|
||||
android:singleLine="true"
|
||||
style="@style/TextLarge.WithIcon" />
|
||||
<TextView
|
||||
android:id="@+id/list_item_category"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:singleLine="true"
|
||||
android:id="@+id/list_item_description"
|
||||
android:singleLine="false"
|
||||
android:textColor="@android:color/secondary_text_dark"
|
||||
style="@style/TextSmall" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_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
|
||||
android:id="@+id/list_item_start_time"
|
||||
style="@style/ListItemStats" />
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/list_item_description"
|
||||
android:singleLine="false"
|
||||
android:textColor="@android:color/secondary_text_dark"
|
||||
style="@style/TextSmall" />
|
||||
</LinearLayout>
|
||||
@@ -28,7 +28,7 @@ limitations under the License.
|
||||
android:layout_width="fill_parent" />
|
||||
<ImageButton
|
||||
android:background="@drawable/my_location"
|
||||
android:contentDescription="@string/my_location"
|
||||
android:contentDescription="@string/icon_my_location"
|
||||
android:id="@+id/map_my_location"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentRight="true"
|
||||
|
||||
@@ -825,6 +825,24 @@ limitations under the License.
|
||||
What are waypoint markers?
|
||||
</string>
|
||||
|
||||
<!-- Icon -->
|
||||
<string name="icon_marker"
|
||||
translation_description="The accessibility description for the 'Marker' icon.">
|
||||
Marker
|
||||
</string>
|
||||
<string name="icon_my_location"
|
||||
translation_description="The accessibility description for the 'My Location' icon.">
|
||||
My Location
|
||||
</string>
|
||||
<string name="icon_recording"
|
||||
translation_description="The accessibility description for the 'Recording' icon.">
|
||||
Recording
|
||||
</string>
|
||||
<string name="icon_track"
|
||||
translation_description="The accessibility description for the 'Track' icon.">
|
||||
Track
|
||||
</string>
|
||||
|
||||
<!-- Import -->
|
||||
<string name="import_error"
|
||||
translation_description="When importing all the tracks, a toast message indicating import error
|
||||
@@ -1119,11 +1137,6 @@ limitations under the License.
|
||||
</string>
|
||||
|
||||
<!-- My Location -->
|
||||
<string name="my_location"
|
||||
translation_description="The accessibility description for the My Location button on the map
|
||||
view.">
|
||||
My Location
|
||||
</string>
|
||||
<string name="my_location_approximate_location"
|
||||
translation_description="When displaying the user's current location, a status message
|
||||
indicating that GPS is not available and an approximate location is used instead.">
|
||||
@@ -2127,10 +2140,6 @@ limitations under the License.
|
||||
translation_description="In the track detail page, the title when recording.">
|
||||
Recording...
|
||||
</string>
|
||||
<string name="track_icon_description"
|
||||
translation_description="The accessibility description for the track icon.">
|
||||
Track
|
||||
</string>
|
||||
<string name="track_edit_activity_type"
|
||||
translation_description="In the page to edit a track, the label for the text field to edit the
|
||||
activity type, including some examples of activity types.">
|
||||
|
||||
@@ -122,11 +122,6 @@ limitations under the License.
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:textSize">22sp</item>
|
||||
</style>
|
||||
<!-- The style for large size text with an icon on the left -->
|
||||
<style name="TextLarge.WithIcon">
|
||||
<item name="android:drawablePadding">8dp</item>
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
</style>
|
||||
<!-- The style for medium size text -->
|
||||
<style name="TextMedium">
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
|
||||
@@ -25,7 +25,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;
|
||||
@@ -139,12 +138,12 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
|
||||
boolean statistics = cursor.getInt(typeIndex) == Waypoint.TYPE_STATISTICS;
|
||||
String name = cursor.getString(nameIndex);
|
||||
int iconId = statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin;
|
||||
String contentDescription = getString(R.string.icon_marker);
|
||||
String category = statistics ? null : cursor.getString(categoryIndex);
|
||||
long time = cursor.getLong(timeIndex);
|
||||
String startTime = time == 0
|
||||
? null : StringUtils.formatDateTime(MarkerListActivity.this, time);
|
||||
String description = statistics ? null : cursor.getString(descriptionIndex);
|
||||
ListItemUtils.setListItem(view, name, iconId, category, null, null, startTime, description);
|
||||
ListItemUtils.setListItem(MarkerListActivity.this,
|
||||
view, name, iconId, contentDescription, category, null, null, time, description);
|
||||
}
|
||||
};
|
||||
listView.setAdapter(resourceCursorAdapter);
|
||||
|
||||
@@ -73,6 +73,7 @@ public class SearchListActivity extends AbstractMyTracksActivity {
|
||||
|
||||
private static final String NAME_FIELD = "name";
|
||||
private static final String ICON_FIELD = "icon";
|
||||
private static final String ICON_CONTENT_DESCRIPTION_FIELD = "iconContentDescription";
|
||||
private static final String CATEGORY_FIELD = "category";
|
||||
private static final String TOTAL_TIME_FIELD = "totalTime";
|
||||
private static final String TOTAL_DISTANCE_FIELD = "totalDistance";
|
||||
@@ -161,14 +162,17 @@ public class SearchListActivity extends AbstractMyTracksActivity {
|
||||
Map<String, Object> resultMap = getItem(position);
|
||||
String name = (String) resultMap.get(NAME_FIELD);
|
||||
int iconId = (Integer) resultMap.get(ICON_FIELD);
|
||||
String iconContentDescription = (String) resultMap.get(ICON_CONTENT_DESCRIPTION_FIELD);
|
||||
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(view,
|
||||
ListItemUtils.setListItem(SearchListActivity.this,
|
||||
view,
|
||||
name,
|
||||
iconId,
|
||||
iconContentDescription,
|
||||
category,
|
||||
totalTime,
|
||||
totalDistance,
|
||||
@@ -382,11 +386,9 @@ public class SearchListActivity extends AbstractMyTracksActivity {
|
||||
boolean statistics = waypoint.getType() == Waypoint.TYPE_STATISTICS;
|
||||
resultMap.put(NAME_FIELD, waypoint.getName());
|
||||
resultMap.put(ICON_FIELD, statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin);
|
||||
resultMap.put(ICON_CONTENT_DESCRIPTION_FIELD, getString(R.string.icon_marker));
|
||||
resultMap.put(CATEGORY_FIELD, statistics ? null : waypoint.getCategory());
|
||||
|
||||
long time = waypoint.getLocation().getTime();
|
||||
String startTime = StringUtils.formatDateTime(this, time);
|
||||
resultMap.put(START_TIME_FIELD, time == 0 || startTime.equals(trackName) ? null : startTime);
|
||||
resultMap.put(START_TIME_FIELD, waypoint.getLocation().getTime());
|
||||
|
||||
// Display the marker's track name in the total time field
|
||||
resultMap.put(TOTAL_TIME_FIELD, trackName == null ? null
|
||||
@@ -408,16 +410,14 @@ public class SearchListActivity extends AbstractMyTracksActivity {
|
||||
TripStatistics tripStatitics = track.getStatistics();
|
||||
resultMap.put(NAME_FIELD, track.getName());
|
||||
resultMap.put(ICON_FIELD, isRecording ? R.drawable.menu_record_track : R.drawable.track);
|
||||
resultMap.put(ICON_CONTENT_DESCRIPTION_FIELD, getString(isRecording ? R.string.icon_recording
|
||||
: R.string.icon_track));
|
||||
resultMap.put(CATEGORY_FIELD, track.getCategory());
|
||||
resultMap.put(TOTAL_TIME_FIELD, isRecording ? null : StringUtils.formatElapsedTime(
|
||||
tripStatitics.getTotalTime()));
|
||||
resultMap.put(TOTAL_DISTANCE_FIELD, isRecording ? null : StringUtils.formatDistance(
|
||||
this, tripStatitics.getTotalDistance(), metricUnits));
|
||||
String startTime = StringUtils.formatDateTime(this, tripStatitics.getStartTime());
|
||||
if (startTime.equals(track.getName())) {
|
||||
startTime = null;
|
||||
}
|
||||
resultMap.put(START_TIME_FIELD, startTime);
|
||||
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);
|
||||
|
||||
@@ -22,13 +22,13 @@ import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection
|
||||
import com.google.android.apps.mytracks.services.sensors.SensorManager;
|
||||
import com.google.android.apps.mytracks.services.sensors.SensorManagerFactory;
|
||||
import com.google.android.apps.mytracks.services.sensors.SensorUtils;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -221,7 +221,7 @@ public class SensorStateActivity extends AbstractMyTracksActivity {
|
||||
* @param sensorDataSet sensor data set
|
||||
*/
|
||||
private String getLastSensorTime(Sensor.SensorDataSet sensorDataSet) {
|
||||
return StringUtils.formatTime(this, sensorDataSet.getCreationTime());
|
||||
return DateFormat.format("h:mm:ss aa", sensorDataSet.getCreationTime()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -217,20 +217,20 @@ public class TrackListActivity extends FragmentActivity {
|
||||
boolean isRecording = cursor.getLong(idIndex) == recordingTrackId;
|
||||
String name = cursor.getString(nameIndex);
|
||||
int iconId = isRecording ? R.drawable.menu_record_track : R.drawable.track;
|
||||
String iconContentDescription = getString(isRecording ? R.string.icon_recording
|
||||
: R.string.icon_track);
|
||||
String category = cursor.getString(categoryIndex);
|
||||
String totalTime = isRecording
|
||||
? null : StringUtils.formatElapsedTime(cursor.getLong(timeIndex));
|
||||
String totalDistance = isRecording ? null : StringUtils.formatDistance(
|
||||
TrackListActivity.this, cursor.getDouble(distanceIndex), metricUnits);
|
||||
String startTime =
|
||||
StringUtils.formatDateTime(TrackListActivity.this, cursor.getLong(startIndex));
|
||||
if (startTime.equals(name)) {
|
||||
startTime = null;
|
||||
}
|
||||
long startTime = cursor.getLong(startIndex);
|
||||
String description = cursor.getString(descriptionIndex);
|
||||
ListItemUtils.setListItem(view,
|
||||
ListItemUtils.setListItem(TrackListActivity.this,
|
||||
view,
|
||||
name,
|
||||
iconId,
|
||||
iconContentDescription,
|
||||
category,
|
||||
totalTime,
|
||||
totalDistance,
|
||||
|
||||
@@ -18,7 +18,9 @@ package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
@@ -33,26 +35,32 @@ public class ListItemUtils {
|
||||
/**
|
||||
* Sets a list item.
|
||||
*
|
||||
* @param context the context
|
||||
* @param view the list item view
|
||||
* @param name the name value
|
||||
* @param iconId the icon id
|
||||
* @param iconContentDescription the icon content description
|
||||
* @param category the category value
|
||||
* @param totalTime the total time value
|
||||
* @param totalDistance the total distance value
|
||||
* @param startTime the start time value
|
||||
* @param description the description value
|
||||
*/
|
||||
public static void setListItem(View view,
|
||||
public static void setListItem(Context context, View view,
|
||||
String name,
|
||||
int iconId,
|
||||
String iconContentDescription,
|
||||
String category,
|
||||
String totalTime,
|
||||
String totalDistance,
|
||||
String startTime,
|
||||
long startTime,
|
||||
String description) {
|
||||
ImageView iconImageView = (ImageView) view.findViewById(R.id.list_item_icon);
|
||||
iconImageView.setImageResource(iconId);
|
||||
iconImageView.setContentDescription(iconContentDescription);
|
||||
|
||||
TextView nameTextView = (TextView) view.findViewById(R.id.list_item_name);
|
||||
nameTextView.setText(name);
|
||||
nameTextView.setCompoundDrawablesWithIntrinsicBounds(iconId, 0, 0, 0);
|
||||
|
||||
TextView categoryTextView = (TextView) view.findViewById(R.id.list_item_category);
|
||||
setTextView(categoryTextView, category);
|
||||
@@ -63,8 +71,11 @@ public class ListItemUtils {
|
||||
TextView totalDistanceTextView = (TextView) view.findViewById(R.id.list_item_total_distance);
|
||||
setTextView(totalDistanceTextView, totalDistance);
|
||||
|
||||
String startTimeDisplay = startTime == 0L
|
||||
|| StringUtils.formatDateTime(context, startTime).equals(name) ? null
|
||||
: StringUtils.formatRelativeDateTime(context, startTime);
|
||||
TextView startTimeTextView = (TextView) view.findViewById(R.id.list_item_start_time);
|
||||
setTextView(startTimeTextView, startTime);
|
||||
setTextView(startTimeTextView, startTimeDisplay);
|
||||
|
||||
TextView descriptionTextView = (TextView) view.findViewById(R.id.list_item_description);
|
||||
setTextView(descriptionTextView, description);
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.text.format.DateUtils;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -42,7 +43,6 @@ public class StringUtils {
|
||||
"yyyy-MM-dd'T'HH:mm:ss");
|
||||
private static final Pattern ISO_8601_EXTRAS = Pattern.compile(
|
||||
"^(\\.\\d+)?(?:Z|([+-])(\\d{2}):(\\d{2}))?$");
|
||||
|
||||
static {
|
||||
ISO_8601_DATE_TIME_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
ISO_8601_BASE.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
@@ -50,25 +50,31 @@ public class StringUtils {
|
||||
|
||||
private StringUtils() {}
|
||||
|
||||
/**
|
||||
* Formats the time based on user's phone date/time preferences.
|
||||
*
|
||||
* @param context the context
|
||||
* @param time the time in milliseconds
|
||||
*/
|
||||
public static String formatTime(Context context, long time) {
|
||||
return android.text.format.DateFormat.getTimeFormat(context).format(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the date and time based on user's phone date/time preferences.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param time the time in milliseconds
|
||||
*/
|
||||
public static String formatDateTime(Context context, long time) {
|
||||
return android.text.format.DateFormat.getDateFormat(context).format(time) + " "
|
||||
+ formatTime(context, time);
|
||||
+ DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_TIME).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the relative date and 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);
|
||||
} else {
|
||||
return DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS,
|
||||
DateUtils.FORMAT_ABBREV_RELATIVE).toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.text.format.DateFormat;
|
||||
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
@@ -29,23 +28,6 @@ import java.util.TimeZone;
|
||||
*/
|
||||
public class StringUtilsTest extends AndroidTestCase {
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatDateTime(android.content.Context, long)}.
|
||||
*/
|
||||
public void testFormatTime() {
|
||||
assertEquals(DateFormat.getTimeFormat(getContext()).format(0L),
|
||||
StringUtils.formatTime(getContext(), 0L));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatDateTime(android.content.Context, long)}.
|
||||
*/
|
||||
public void testFormatDateTime() {
|
||||
String expected = DateFormat.getDateFormat(getContext()).format(0L) + " "
|
||||
+ DateFormat.getTimeFormat(getContext()).format(0L);
|
||||
assertEquals(expected, StringUtils.formatDateTime(getContext(), 0L));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatDateTimeIso8601(long)}.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user