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 7a41e4b51..8aac97b16 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/StringUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/StringUtils.java @@ -151,7 +151,8 @@ public class StringUtils { /** * Gets the distance in an array of two strings. The first string is the - * distance. The second string is the unit. + * distance. The second string is the unit. The first string is null if the + * distance is invalid. * * @param context the context * @param distance the distance @@ -160,7 +161,7 @@ public class StringUtils { public static String[] getDistanceParts(Context context, double distance, boolean metricUnits) { String[] result = new String[2]; if (Double.isNaN(distance) || Double.isInfinite(distance)) { - result[0] = context.getString(R.string.value_unknown); + result[0] = null; result[1] = context.getString(metricUnits ? R.string.unit_meter : R.string.unit_feet); return result; } @@ -222,8 +223,9 @@ public class StringUtils { } /** - * Gets the speed in an array of two strings. The first string is the - * speed. The second string is the unit. + * Gets the speed in an array of two strings. The first string is the speed. + * The second string is the unit. The first string is null if speed is + * invalid. * * @param context the context * @param speed the speed @@ -241,7 +243,7 @@ public class StringUtils { } result[1] = context.getString(unitId); if (Double.isNaN(speed) || Double.isInfinite(speed)) { - result[0] = context.getString(R.string.value_unknown); + result[0] = null; return result; } speed *= UnitConversions.MS_TO_KMH; diff --git a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java index b31afbea8..77f281f3e 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java +++ b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java @@ -314,6 +314,9 @@ public class TrackWidgetProvider extends AppWidgetProvider { TripStatistics tripStatistics, boolean metricUnits) { double totalDistance = tripStatistics == null ? Double.NaN : tripStatistics.getTotalDistance(); String[] totalDistanceParts = StringUtils.getDistanceParts(context, totalDistance, metricUnits); + if (totalDistanceParts[0] == null) { + totalDistanceParts[0] = context.getString(R.string.value_unknown); + } remoteViews.setTextViewText(ids[0], context.getString(R.string.stats_distance)); remoteViews.setTextViewText(ids[1], totalDistanceParts[0]); remoteViews.setTextViewText(ids[2], totalDistanceParts[1]); @@ -367,6 +370,11 @@ public class TrackWidgetProvider extends AppWidgetProvider { Double speed = tripStatistics == null ? Double.NaN : tripStatistics.getAverageSpeed(); String[] speedParts = StringUtils.getSpeedParts(context, speed, metricUnits, reportSpeed); + + if (speedParts[0] == null) { + speedParts[0] = context.getString(R.string.value_unknown); + } + remoteViews.setTextViewText(ids[1], speedParts[0]); remoteViews.setTextViewText(ids[2], speedParts[1]); } @@ -406,6 +414,11 @@ public class TrackWidgetProvider extends AppWidgetProvider { Double speed = tripStatistics == null ? Double.NaN : tripStatistics.getAverageMovingSpeed(); String[] speedParts = StringUtils.getSpeedParts(context, speed, metricUnits, reportSpeed); + + if (speedParts[0] == null) { + speedParts[0] = context.getString(R.string.value_unknown); + } + remoteViews.setTextViewText(ids[1], speedParts[0]); remoteViews.setTextViewText(ids[2], speedParts[1]); }