Add latitude and longitude in marker detail page

This commit is contained in:
Jimmy Shih
2013-12-05 12:37:07 -08:00
parent 384efcbfdc
commit 68afba0c31
4 changed files with 45 additions and 7 deletions
@@ -55,6 +55,9 @@ limitations under the License.
<TextView
android:id="@+id/marker_detail_waypoint_description"
style="@style/TextSmall" />
<TextView
android:id="@+id/marker_detail_waypoint_location"
style="@style/TextSmall" />
</LinearLayout>
</FrameLayout>
</FrameLayout>
@@ -70,6 +73,9 @@ limitations under the License.
android:id="@+id/marker_detail_statistics_name"
android:paddingTop="8dp"
style="@style/TextMedium" />
<TextView
android:id="@+id/marker_detail_statistics_location"
style="@style/TextSmall" />
<TextView
android:paddingBottom="6dp"
android:paddingTop="4dp"
@@ -33,6 +33,7 @@ import com.google.android.apps.mytracks.util.TrackIconUtils;
import com.google.android.maps.mytracks.R;
import android.content.Intent;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -267,8 +268,7 @@ public class MarkerDetailFragment extends Fragment {
handler.postDelayed(hideText, HIDE_TEXT_DELAY);
}
TextView name = (TextView) getView().findViewById(R.id.marker_detail_waypoint_name);
ListItemUtils.setTextView(getActivity(), name, waypoint.getName(), hasPhoto);
setName(R.id.marker_detail_waypoint_name, hasPhoto);
TextView category = (TextView) getView().findViewById(R.id.marker_detail_waypoint_category);
ListItemUtils.setTextView(
@@ -277,9 +277,12 @@ public class MarkerDetailFragment extends Fragment {
TextView description = (TextView) getView()
.findViewById(R.id.marker_detail_waypoint_description);
ListItemUtils.setTextView(getActivity(), description, waypoint.getDescription(), hasPhoto);
setLocation(R.id.marker_detail_waypoint_location, hasPhoto);
} else {
TextView name = (TextView) getView().findViewById(R.id.marker_detail_statistics_name);
ListItemUtils.setTextView(getActivity(), name, waypoint.getName(), false);
setName(R.id.marker_detail_statistics_name, false);
setLocation(R.id.marker_detail_statistics_location, false);
Track track = myTracksProviderUtils.getTrack(waypoint.getTrackId());
ActivityType activityType = track != null ? CalorieUtils.getActivityType(
@@ -290,4 +293,24 @@ public class MarkerDetailFragment extends Fragment {
StatsUtils.setLocationValues(getActivity(), null, getView(), waypoint.getLocation(), false);
}
}
private void setName(int resId, boolean addShadow) {
TextView textView = (TextView) getView().findViewById(resId);
ListItemUtils.setTextView(getActivity(), textView, waypoint.getName(), addShadow);
}
private void setLocation(int resId, boolean addShadow) {
TextView textView = (TextView) getView().findViewById(resId);
Location location = waypoint.getLocation();
String value;
if (location == null) {
value = null;
} else {
value = "[" + getString(R.string.stats_latitude) + " "
+ StringUtils.formatCoordinate(location.getLatitude()) + ", "
+ getString(R.string.stats_longitude) + " "
+ StringUtils.formatCoordinate(location.getLongitude()) + "]";
}
ListItemUtils.setTextView(getActivity(), textView, value, addShadow);
}
}
@@ -36,9 +36,7 @@ import java.util.Locale;
*/
public class StatsUtils {
private static final String COORDINATE_DEGREE = "\u00B0";
private static final String GRADE_PERCENTAGE = "%";
private static final String GRADE_FORMAT = "%1$d";
private static final String CALORIES_FORMAT = "%1$,.0f";
@@ -321,7 +319,7 @@ public class StatsUtils {
private static void setCoordinateValue(
Context context, View view, int labelId, double coordinate) {
String value = Double.isNaN(coordinate) || Double.isInfinite(coordinate) ? null
: Location.convert(coordinate, Location.FORMAT_DEGREES) + COORDINATE_DEGREE;
: StringUtils.formatCoordinate(coordinate);
setItem(context, view, labelId, value, null);
}
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.util;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.location.Location;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
@@ -39,6 +40,7 @@ import java.util.regex.Pattern;
*/
public class StringUtils {
private static final String COORDINATE_DEGREE = "\u00B0";
private static final SimpleDateFormat ISO_8601_DATE_TIME_FORMAT = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
private static final SimpleDateFormat ISO_8601_BASE = new SimpleDateFormat(
@@ -162,6 +164,15 @@ public class StringUtils {
return result.replaceAll("[0]*$", "").replaceAll("\\.$", "");
}
/**
* Formats a coordinate
*
* @param coordinate the coordinate
*/
public static String formatCoordinate(double coordinate) {
return Location.convert(coordinate, Location.FORMAT_DEGREES) + COORDINATE_DEGREE;
}
/**
* Gets the distance in an array of two strings. The first string is the
* distance. The second string is the unit. The first string is null if the