diff --git a/MyTracks/res/layout/mytracks_list_item.xml b/MyTracks/res/layout/mytracks_list_item.xml
index 57df6bc87..4980291db 100644
--- a/MyTracks/res/layout/mytracks_list_item.xml
+++ b/MyTracks/res/layout/mytracks_list_item.xml
@@ -15,69 +15,60 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
+ android:orientation="vertical"
+ android:paddingBottom="2dip"
+ android:paddingTop="2dip">
-
+
-
+
+
-
-
-
+ android:singleLine = "true"
+ android:textAppearance="?android:attr/textAppearanceSmall"/>
-
-
-
diff --git a/MyTracks/res/layout/mytracks_marker_item.xml b/MyTracks/res/layout/mytracks_marker_item.xml
index 3d355a645..04130b7a6 100644
--- a/MyTracks/res/layout/mytracks_marker_item.xml
+++ b/MyTracks/res/layout/mytracks_marker_item.xml
@@ -32,7 +32,8 @@ limitations under the License.
android:layout_height="wrap_content"
android:layout_marginLeft="6dip"
android:layout_marginTop="6dip"
- android:src="@drawable/ylw_pushpin"/>
+ android:src="@drawable/ylw_pushpin"
+ android:contentDescription="@string/marker_list_icon_description"/>
diff --git a/MyTracks/res/layout/search_list.xml b/MyTracks/res/layout/search_list.xml
new file mode 100644
index 000000000..b9322466b
--- /dev/null
+++ b/MyTracks/res/layout/search_list.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MyTracks/res/values/strings.xml b/MyTracks/res/values/strings.xml
index 6c9e16f3a..0f7606407 100644
--- a/MyTracks/res/values/strings.xml
+++ b/MyTracks/res/values/strings.xml
@@ -815,6 +815,10 @@ limitations under the License.
Screenshot: marker_list_context_menu.png">
Edit
+
+ Marker
+
- Search My Tracks tracks and waypoints
+ Search My Tracks
+
+
+ No tracks or waypoints matched your search.
Show on map
+
+ Track
+
+
+ In track \'%1$s\'.
+
resultMap) {
- resultMap.put("icon", waypoint.getType() == Waypoint.TYPE_STATISTICS ? R.drawable.ylw_pushpin
- : R.drawable.blue_pushpin);
- resultMap.put("name", waypoint.getName());
- resultMap.put("description", waypoint.getDescription());
- resultMap.put("category", waypoint.getCategory());
- resultMap.put("time", String.format("%tc", waypoint.getLocation().getTime()));
- resultMap.put("trackId", waypoint.getTrackId());
- resultMap.put("waypointId", waypoint.getId());
+ // Look up the owner track.
+ // TODO: It may be more appropriate to do this as a join in the retrieval phase of the search.
+ String trackName = null;
+ long trackId = waypoint.getTrackId();
+ if (trackId > 0) {
+ Track track = providerUtils.getTrack(trackId);
+ if (track != null) {
+ trackName = track.getName();
+ }
+ }
+
+ resultMap.put(ICON_FIELD, waypoint.getType() == Waypoint.TYPE_STATISTICS
+ ? R.drawable.ylw_pushpin : R.drawable.blue_pushpin);
+ resultMap.put(NAME_FIELD, waypoint.getName());
+ resultMap.put(DESCRIPTION_FIELD, waypoint.getDescription());
+ resultMap.put(CATEGORY_FIELD, waypoint.getCategory());
+ // In the same place as we show time for tracks, show the track name for waypoints.
+ resultMap.put(TIME_FIELD, getString(R.string.track_list_track_name, trackName));
+ resultMap.put(STATS_FIELD, StringUtils.formatDateTime(this, waypoint.getLocation().getTime()));
+ resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId());
+ resultMap.put(WAYPOINT_ID_FIELD, waypoint.getId());
}
private void prepareTrackForDisplay(Track track, Map resultMap) {
- resultMap.put("icon", R.drawable.track);
- resultMap.put("name", track.getName());
- resultMap.put("description", track.getDescription());
- resultMap.put("category", track.getCategory());
- resultMap.put("time", String.format("%tc", track.getStatistics().getStartTime()));
- resultMap.put("trackId", track.getId());
+ TripStatistics stats = track.getStatistics();
+
+ resultMap.put(ICON_FIELD, R.drawable.track);
+ resultMap.put(NAME_FIELD, track.getName());
+ resultMap.put(DESCRIPTION_FIELD, track.getDescription());
+ resultMap.put(CATEGORY_FIELD, track.getCategory());
+ resultMap.put(TIME_FIELD, StringUtils.formatDateTime(this, stats.getStartTime()));
+ resultMap.put(STATS_FIELD,
+ StringUtils.formatTimeDistance(this, stats.getTotalDistance(), stats.getTotalTime(),
+ metricUnits));
+ resultMap.put(TRACK_ID_FIELD, track.getId());
}
/**
@@ -176,18 +224,20 @@ public class SearchActivity extends ListActivity {
// TODO: Custom view for search results.
R.layout.mytracks_list_item,
new String[] {
- "icon",
- "name",
- "description",
- "category",
- "time"
+ ICON_FIELD,
+ NAME_FIELD,
+ DESCRIPTION_FIELD,
+ CATEGORY_FIELD,
+ TIME_FIELD,
+ STATS_FIELD,
},
new int[] {
- R.id.trackdetails_item_icon,
- R.id.trackdetails_item_name,
- R.id.trackdetails_item_description,
- R.id.trackdetails_item_category,
- R.id.trackdetails_item_time
+ R.id.track_list_item_icon,
+ R.id.track_list_item_name,
+ R.id.track_list_item_description,
+ R.id.track_list_item_category,
+ R.id.track_list_item_time,
+ R.id.track_list_item_stats,
});
setListAdapter(adapter);
@@ -203,12 +253,12 @@ public class SearchActivity extends ListActivity {
private Intent createViewDataIntent(Map clickedData) {
Intent intent = new Intent(Intent.ACTION_VIEW);
- if (clickedData.containsKey("waypointId")) {
- long waypointId = (Long) clickedData.get("waypointId");
+ if (clickedData.containsKey(WAYPOINT_ID_FIELD)) {
+ long waypointId = (Long) clickedData.get(WAYPOINT_ID_FIELD);
Uri uri = ContentUris.withAppendedId(WaypointsColumns.CONTENT_URI, waypointId);
intent.setDataAndType(uri, WaypointsColumns.CONTENT_ITEMTYPE);
} else {
- long trackId = (Long) clickedData.get("trackId");
+ long trackId = (Long) clickedData.get(TRACK_ID_FIELD);
Uri uri = ContentUris.withAppendedId(TracksColumns.CONTENT_URI, trackId);
intent.setDataAndType(uri, TracksColumns.CONTENT_ITEMTYPE);
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackList.java b/MyTracks/src/com/google/android/apps/mytracks/TrackList.java
index 1a227f6ff..6a61f8eb5 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/TrackList.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/TrackList.java
@@ -24,7 +24,6 @@ import com.google.android.apps.mytracks.io.sendtogoogle.UploadServiceChooserActi
import com.google.android.apps.mytracks.services.ServiceUtils;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.apps.mytracks.util.StringUtils;
-import com.google.android.apps.mytracks.util.UnitConversions;
import com.google.android.maps.mytracks.R;
import android.app.ListActivity;
@@ -311,9 +310,9 @@ public class TrackList extends ListActivity
new String[] { TracksColumns.NAME, TracksColumns.STARTTIME,
TracksColumns.TOTALDISTANCE, TracksColumns.DESCRIPTION,
TracksColumns.CATEGORY },
- new int[] { R.id.trackdetails_item_name, R.id.trackdetails_item_time,
- R.id.trackdetails_item_stats, R.id.trackdetails_item_description,
- R.id.trackdetails_item_category });
+ new int[] { R.id.track_list_item_name, R.id.track_list_item_time,
+ R.id.track_list_item_stats, R.id.track_list_item_description,
+ R.id.track_list_item_category });
final int startTimeIdx =
tracksCursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
@@ -330,28 +329,10 @@ public class TrackList extends ListActivity
long time = cursor.getLong(startTimeIdx);
textView.setText(StringUtils.formatDateTime(TrackList.this, time));
} else if (columnIndex == totalDistanceIdx) {
- double length = cursor.getDouble(totalDistanceIdx);
- String lengthUnit = null;
- if (metricUnits) {
- if (length > 1000.0) {
- length /= 1000.0;
- lengthUnit = getString(R.string.unit_kilometer);
- } else {
- lengthUnit = getString(R.string.unit_meter);
- }
- } else {
- if (length > UnitConversions.MI_TO_M) {
- length /= UnitConversions.MI_TO_M;
- lengthUnit = getString(R.string.unit_mile);
- } else {
- length *= UnitConversions.M_TO_FT;
- lengthUnit = getString(R.string.unit_feet);
- }
- }
- textView.setText(String.format("%s %.2f %s",
- StringUtils.formatElapsedTime(cursor.getLong(totalTimeIdx)),
- length,
- lengthUnit));
+ double totalDistance = cursor.getDouble(totalDistanceIdx);
+ long totalTime = cursor.getLong(totalTimeIdx);
+ String totalDistanceStr = StringUtils.formatTimeDistance(TrackList.this, totalDistance, totalTime, metricUnits);
+ textView.setText(totalDistanceStr);
} else {
textView.setText(cursor.getString(columnIndex));
if (textView.getText().length() < 1) {
@@ -362,6 +343,7 @@ public class TrackList extends ListActivity
}
return true;
}
+
});
setListAdapter(adapter);
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/SearchEngine.java b/MyTracks/src/com/google/android/apps/mytracks/content/SearchEngine.java
index 7c269bb88..c94139abd 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/content/SearchEngine.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/content/SearchEngine.java
@@ -18,7 +18,6 @@ package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.util.LocationUtils;
-import android.content.Context;
import android.database.Cursor;
import android.location.Location;
@@ -149,10 +148,6 @@ public class SearchEngine {
private final MyTracksProviderUtils providerUtils;
- public SearchEngine(Context ctx) {
- providerUtils = MyTracksProviderUtils.Factory.get(ctx);
- }
-
public SearchEngine(MyTracksProviderUtils providerUtils) {
this.providerUtils = providerUtils;
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/StringUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/StringUtils.java
index 0354c2735..6aab3f21c 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/StringUtils.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/StringUtils.java
@@ -77,8 +77,41 @@ public class StringUtils implements DescriptionGenerator {
return DateUtils.formatElapsedTime(time / 1000);
}
+ /**
+ * Formats the elapsed time and total distance.
+ *
+ * @param context the current context
+ * @param totalDistance the total distance in meters
+ * @param totalTime the total time in milliseconds
+ * @param metric whether to use metric units
+ * @return the formatted string
+ */
+ public static String formatTimeDistance(Context context, double totalDistance, long totalTime, boolean metric) {
+ String distanceUnit;
+ if (metric) {
+ if (totalDistance > 2000.0) {
+ totalDistance /= 1000.0;
+ distanceUnit = context.getString(R.string.unit_kilometer);
+ } else {
+ distanceUnit = context.getString(R.string.unit_meter);
+ }
+ } else {
+ if (totalDistance > 2 * UnitConversions.MI_TO_M) {
+ totalDistance /= UnitConversions.MI_TO_M;
+ distanceUnit = context.getString(R.string.unit_mile);
+ } else {
+ totalDistance *= UnitConversions.M_TO_FT;
+ distanceUnit = context.getString(R.string.unit_feet);
+ }
+ }
+ return String.format("%s %.2f %s",
+ formatElapsedTime(totalTime),
+ totalDistance,
+ distanceUnit);
+ }
+
private static final NumberFormat SINGLE_DECIMAL_PLACE_FORMAT = NumberFormat.getNumberInstance();
-
+
static {
SINGLE_DECIMAL_PLACE_FORMAT.setMaximumFractionDigits(1);
SINGLE_DECIMAL_PLACE_FORMAT.setMinimumFractionDigits(1);
@@ -342,7 +375,7 @@ public class StringUtils implements DescriptionGenerator {
/**
* Returns the 'Created by My Tracks on Android' string.
- *
+ *
* @param context the context
* @param addLink true to add a link to the My Tracks web site
*/
@@ -355,7 +388,7 @@ public class StringUtils implements DescriptionGenerator {
return String.format(format, "", "");
}
}
-
+
private String getSpeedString(double speed, int speedLabel, int paceLabel,
boolean displaySpeed) {
double speedInKph = speed * 3.6;