Add support to show both moving time and total time.

This commit is contained in:
Jimmy Shih
2012-08-22 15:52:14 -07:00
parent b3ad974bbb
commit b0bb09db08
9 changed files with 192 additions and 130 deletions
+28 -4
View File
@@ -29,21 +29,32 @@ limitations under the License.
<!-- Total time/moving time --> <!-- Total time/moving time -->
<TableRow> <TableRow>
<TextView <TextView
android:id="@+id/stats_total_time_label" android:text="@string/stats_total_time"
style="@style/StatsLabel" />
<TextView
android:id="@+id/stats_moving_time_label"
android:layout_column="2"
android:text="@string/stats_moving_time"
style="@style/StatsLabel" /> style="@style/StatsLabel" />
</TableRow> </TableRow>
<TableRow> <TableRow>
<TextView <TextView
android:id="@+id/stats_total_time_value" android:id="@+id/stats_total_time_value"
style="@style/StatsValue" /> style="@style/StatsValue" />
<TextView
android:id="@+id/stats_moving_time_spacer"
style="@style/StatsSpacer" />
<TextView
android:id="@+id/stats_moving_time_value"
style="@style/StatsValue" />
</TableRow> </TableRow>
<!-- Average speed/average moving speed and max speed (average pace/average moving pace and fastest pace) --> <!-- Average speed/average moving speed (average pace/average moving pace) -->
<TableRow> <TableRow>
<TextView <TextView
android:id="@+id/stats_average_speed_label" android:id="@+id/stats_average_speed_label"
style="@style/StatsLabel" /> style="@style/StatsLabel" />
<TextView <TextView
android:id="@+id/stats_max_speed_label" android:id="@+id/stats_average_moving_speed_label"
android:layout_column="2" android:layout_column="2"
style="@style/StatsLabel" /> style="@style/StatsLabel" />
</TableRow> </TableRow>
@@ -51,7 +62,20 @@ limitations under the License.
<TextView <TextView
android:id="@+id/stats_average_speed_value" android:id="@+id/stats_average_speed_value"
style="@style/StatsValue" /> style="@style/StatsValue" />
<TextView style="@style/StatsSpacer" /> <TextView
android:id="@+id/stats_average_moving_speed_spacer"
style="@style/StatsSpacer" />
<TextView
android:id="@+id/stats_average_moving_speed_value"
style="@style/StatsValue" />
</TableRow>
<!-- Max speed (fastest pace) -->
<TableRow>
<TextView
android:id="@+id/stats_max_speed_label"
style="@style/StatsLabel" />
</TableRow>
<TableRow>
<TextView <TextView
android:id="@+id/stats_max_speed_value" android:id="@+id/stats_max_speed_value"
style="@style/StatsValue" /> style="@style/StatsValue" />
+33 -22
View File
@@ -39,10 +39,7 @@ limitations under the License.
android:layout_width="0dp" android:layout_width="0dp"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="8dp" > android:paddingLeft="8dp" >
<LinearLayout <LinearLayout style="@style/TrackWidgetStat" >
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal" >
<TextView <TextView
android:id="@+id/track_widget_distance_value" android:id="@+id/track_widget_distance_value"
style="@style/TrackWidgetValue" /> style="@style/TrackWidgetValue" />
@@ -50,34 +47,48 @@ limitations under the License.
android:text="@string/stats_total_distance" android:text="@string/stats_total_distance"
style="@style/TrackWidgetLabel" /> style="@style/TrackWidgetLabel" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout style="@style/TrackWidgetSeparator" />
android:background="@color/track_widget_line" <LinearLayout style="@style/TrackWidgetStat" >
android:layout_height="1dp"
android:layout_width="fill_parent" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal" >
<TextView <TextView
android:id="@+id/track_widget_time_value" android:id="@+id/track_widget_total_time_value"
style="@style/TrackWidgetValue" /> style="@style/TrackWidgetValue" />
<TextView <TextView
android:id="@+id/track_widget_time_label" android:text="@string/stats_total_time"
style="@style/TrackWidgetLabel" />
</LinearLayout>
<LinearLayout style="@style/TrackWidgetSeparator" />
<LinearLayout style="@style/TrackWidgetStat" >
<TextView
android:id="@+id/track_widget_average_speed_value"
style="@style/TrackWidgetValue" />
<TextView
android:id="@+id/track_widget_average_speed_label"
style="@style/TrackWidgetLabel" /> style="@style/TrackWidgetLabel" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:background="@color/track_widget_line" android:id="@+id/track_widget_moving_time_separator"
android:layout_height="1dp" style="@style/TrackWidgetSeparator" />
android:layout_width="fill_parent" />
<LinearLayout <LinearLayout
android:layout_height="wrap_content" android:id="@+id/track_widget_moving_time_stat"
android:layout_width="fill_parent" style="@style/TrackWidgetStat" >
android:orientation="horizontal" >
<TextView <TextView
android:id="@+id/track_widget_speed_value" android:id="@+id/track_widget_moving_time_value"
style="@style/TrackWidgetValue" /> style="@style/TrackWidgetValue" />
<TextView <TextView
android:id="@+id/track_widget_speed_label" android:text="@string/stats_moving_time"
style="@style/TrackWidgetLabel" />
</LinearLayout>
<LinearLayout
android:id="@+id/track_widget_average_moving_speed_separator"
style="@style/TrackWidgetSeparator" />
<LinearLayout
android:id="@+id/track_widget_average_moving_speed_stat"
style="@style/TrackWidgetStat" >
<TextView
android:id="@+id/track_widget_average_moving_speed_value"
style="@style/TrackWidgetValue" />
<TextView
android:id="@+id/track_widget_average_moving_speed_label"
style="@style/TrackWidgetLabel" /> style="@style/TrackWidgetLabel" />
</LinearLayout> </LinearLayout>
<ImageButton <ImageButton
+1 -1
View File
@@ -53,7 +53,7 @@ limitations under the License.
<string name="stats_show_coordinate_key">statsShowCoordinate</string> <string name="stats_show_coordinate_key">statsShowCoordinate</string>
<string name="stats_show_elevation_key">statsShowElevation</string> <string name="stats_show_elevation_key">statsShowElevation</string>
<string name="stats_show_grade_key">statsShowGrade</string> <string name="stats_show_grade_key">statsShowGrade</string>
<string name="stats_use_total_time_key">statsUseTotalTime</string> <string name="stats_show_moving_time_key">statsShowMovingTime</string>
<string name="track_color_mode_medium_key">trackColorModeMedium</string> <string name="track_color_mode_medium_key">trackColorModeMedium</string>
<string name="track_color_mode_percentage_key">trackColorModePercentage</string> <string name="track_color_mode_percentage_key">trackColorModePercentage</string>
<string name="track_color_mode_slow_key">trackColorModeSlow</string> <string name="track_color_mode_slow_key">trackColorModeSlow</string>
-7
View File
@@ -2038,13 +2038,6 @@ limitations under the License.
Character limit: ~23 (1 line)"> Character limit: ~23 (1 line)">
Preferred rate Preferred rate
</string> </string>
<string name="settings_stats_time_title"
translation_description="In the 'Stats' settings, the option to change the time measurement,
either total time or moving time.
Character limit: ~23 (1 line)">
Time measurement
</string>
<string name="settings_stats_units_imperial" <string name="settings_stats_units_imperial"
translation_description="In the 'Stats' settings, the option to use imperial units, with translation_description="In the 'Stats' settings, the option to use imperial units, with
examples."> examples.">
+17 -5
View File
@@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<resources> <resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The style for the about value --> <!-- The style for the about value -->
<style name="AboutValue" parent="@style/TextMedium"> <style name="AboutValue" parent="@style/TextMedium">
<item name="android:paddingLeft">48dp</item> <item name="android:paddingLeft">48dp</item>
@@ -180,10 +180,6 @@ limitations under the License.
</style> </style>
<!-- Theme selector --> <!-- Theme selector -->
<style name="ThemeSelector" parent="android:Theme" /> <style name="ThemeSelector" parent="android:Theme" />
<!-- The style for the track widget label -->
<style name="TrackWidgetLabel" parent="@style/TextSmall">
<item name="android:width">100dp</item>
</style>
<!-- The style for the track widget button --> <!-- The style for the track widget button -->
<style name="TrackWidgetButton"> <style name="TrackWidgetButton">
<item name="android:layout_gravity">center_horizontal</item> <item name="android:layout_gravity">center_horizontal</item>
@@ -192,6 +188,22 @@ limitations under the License.
<item name="android:layout_width">fill_parent</item> <item name="android:layout_width">fill_parent</item>
<item name="android:padding">8dp</item> <item name="android:padding">8dp</item>
</style> </style>
<!-- The style for the track widget label -->
<style name="TrackWidgetLabel" parent="@style/TextSmall">
<item name="android:width">100dp</item>
</style>
<!-- The style for the track widget separator -->
<style name="TrackWidgetSeparator">
<item name="android:background">@color/track_widget_line</item>
<item name="android:layout_height">1dp</item>
<item name="android:layout_width">fill_parent</item>
</style>
<!-- The style for the track widget stat -->
<style name="TrackWidgetStat">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:orientation">horizontal</item>
</style>
<!-- The style for the track widget value --> <!-- The style for the track widget value -->
<style name="TrackWidgetValue" parent="@style/TextSmall"> <style name="TrackWidgetValue" parent="@style/TextSmall">
<item name="android:layout_weight">1</item> <item name="android:layout_weight">1</item>
+4 -6
View File
@@ -26,13 +26,11 @@ limitations under the License.
android:defaultValue="true" android:defaultValue="true"
android:key="@string/report_speed_key" android:key="@string/report_speed_key"
android:title="@string/settings_stats_rate_title" /> android:title="@string/settings_stats_rate_title" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/stats_use_total_time_key"
android:summaryOff="@string/stats_moving_time"
android:summaryOn="@string/stats_total_time"
android:title="@string/settings_stats_time_title" />
<PreferenceCategory android:title="@string/settings_show" > <PreferenceCategory android:title="@string/settings_show" >
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/stats_show_moving_time_key"
android:title="@string/stats_moving_time" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/stats_show_elevation_key" android:key="@string/stats_show_elevation_key"
@@ -80,7 +80,7 @@ public class PreferencesUtils {
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false; public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
public static final boolean STATS_SHOW_ELEVATION_DEFAULT = false; public static final boolean STATS_SHOW_ELEVATION_DEFAULT = false;
public static final boolean STATS_SHOW_GRADE_DEFAULT = false; public static final boolean STATS_SHOW_GRADE_DEFAULT = false;
public static final boolean STATS_USE_TOTAL_TIME_DEFAULT = true; public static final boolean STATS_SHOW_MOVING_TIME_DEFAULT = false;
public static final int TRACK_COLOR_MODE_MEDIUM_DEFAULT = 15; public static final int TRACK_COLOR_MODE_MEDIUM_DEFAULT = 15;
public static final int TRACK_COLOR_MODE_PERCENTAGE_DEFAULT = 25; public static final int TRACK_COLOR_MODE_PERCENTAGE_DEFAULT = 25;
@@ -104,46 +104,49 @@ public class StatsUtils {
activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT); activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
boolean reportSpeed = PreferencesUtils.getBoolean( boolean reportSpeed = PreferencesUtils.getBoolean(
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT); activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
boolean useTotalTime = PreferencesUtils.getBoolean( boolean showMovingTime = PreferencesUtils.getBoolean(activity,
activity, R.string.stats_use_total_time_key, PreferencesUtils.STATS_USE_TOTAL_TIME_DEFAULT); R.string.stats_show_moving_time_key, PreferencesUtils.STATS_SHOW_MOVING_TIME_DEFAULT);
// Set total distance // Set total distance
double totalDistance = tripStatistics == null ? Double.NaN : tripStatistics.getTotalDistance(); double totalDistance = tripStatistics == null ? Double.NaN : tripStatistics.getTotalDistance();
setDistanceValue(activity, R.id.stats_total_distance_value, totalDistance, metricUnits); setDistanceValue(activity, R.id.stats_total_distance_value, totalDistance, metricUnits);
// Set total time/moving time // Set total time
setTimeLabel(activity, R.id.stats_total_time_label, R.string.stats_total_time, setTimeValue(activity, R.id.stats_total_time_value,
R.string.stats_moving_time, useTotalTime); tripStatistics != null ? tripStatistics.getTotalTime() : -1L);
long totalTime;
if (tripStatistics == null) { // Set moving time
totalTime = -1L; setItemVisibility(activity, R.id.stats_moving_time_label, R.id.stats_moving_time_spacer,
} else { R.id.stats_moving_time_value, showMovingTime);
totalTime = useTotalTime ? tripStatistics.getTotalTime() : tripStatistics.getMovingTime(); if (showMovingTime) {
} setTimeValue(activity, R.id.stats_moving_time_value,
setTimeValue(activity, R.id.stats_total_time_value, totalTime); tripStatistics != null ? tripStatistics.getMovingTime() : -1L);
// Set average speed/moving average speed
if (useTotalTime) {
setSpeedLabel(activity, R.id.stats_average_speed_label, R.string.stats_average_speed,
R.string.stats_average_pace, reportSpeed);
} else {
setSpeedLabel(activity, R.id.stats_average_speed_label, R.string.stats_average_moving_speed,
R.string.stats_average_moving_pace, reportSpeed);
}
double averageSpeed;
if (tripStatistics == null) {
averageSpeed = Double.NaN;
} else {
averageSpeed = useTotalTime ? tripStatistics.getAverageSpeed()
: tripStatistics.getAverageMovingSpeed();
} }
// Set average speed
setSpeedLabel(activity, R.id.stats_average_speed_label, R.string.stats_average_speed,
R.string.stats_average_pace, reportSpeed);
double averageSpeed = tripStatistics != null ? tripStatistics.getAverageSpeed() : Double.NaN;
setSpeedValue(activity, R.id.stats_average_speed_value, averageSpeed, metricUnits, reportSpeed); setSpeedValue(activity, R.id.stats_average_speed_value, averageSpeed, metricUnits, reportSpeed);
// Set average moving speed
setItemVisibility(activity, R.id.stats_average_moving_speed_label,
R.id.stats_average_moving_speed_spacer, R.id.stats_average_moving_speed_value,
showMovingTime);
if (showMovingTime) {
setSpeedLabel(activity, R.id.stats_average_moving_speed_label,
R.string.stats_average_moving_speed, R.string.stats_average_moving_pace, reportSpeed);
double averageMovingSpeed = tripStatistics != null ? tripStatistics.getAverageMovingSpeed()
: Double.NaN;
setSpeedValue(activity, R.id.stats_average_moving_speed_value, averageMovingSpeed,
metricUnits, reportSpeed);
}
// Set max speed // Set max speed
setSpeedLabel(activity, R.id.stats_max_speed_label, R.string.stats_max_speed, setSpeedLabel(activity, R.id.stats_max_speed_label, R.string.stats_max_speed,
R.string.stats_fastest_pace, reportSpeed); R.string.stats_fastest_pace, reportSpeed);
double maxSpeed = tripStatistics == null ? Double.NaN : tripStatistics.getMaxSpeed(); double maxSpeed = tripStatistics == null ? Double.NaN : tripStatistics.getMaxSpeed();
setSpeedValue(activity, R.id.stats_max_speed_value, maxSpeed, metricUnits, reportSpeed); setSpeedValue(activity, R.id.stats_max_speed_value, maxSpeed, metricUnits, reportSpeed);
// Set elevation // Set elevation
boolean showElevation = PreferencesUtils.getBoolean( boolean showElevation = PreferencesUtils.getBoolean(
@@ -189,23 +192,21 @@ public class StatsUtils {
setGradeValue(activity, R.id.stats_max_grade_value, maxGrade); setGradeValue(activity, R.id.stats_max_grade_value, maxGrade);
} }
} }
/** private static void setItemVisibility(
* Sets a time label. Activity activity, int labelId, int spacerId, int valueId, boolean show) {
* View label = activity.findViewById(labelId);
* @param activity the activity View spacer = activity.findViewById(spacerId);
* @param id the time label resource id View value = activity.findViewById(valueId);
* @param totalTimeId the total time string id if (label != null) {
* @param movingTimeId the moving time string id label.setVisibility(show ? View.VISIBLE : View.GONE);
* @param totalTime true to use total time }
*/ if (spacer != null) {
private static void setTimeLabel(Activity activity, int id, int totalTimeId, int movingTimeId, spacer.setVisibility(show ? View.VISIBLE : View.GONE);
boolean totalTime) { }
TextView textView = (TextView) activity.findViewById(id); if (value != null) {
if (textView == null) { value.setVisibility(show ? View.VISIBLE : View.GONE);
return;
} }
textView.setText(totalTime ? totalTimeId : movingTimeId);
} }
/** /**
@@ -79,12 +79,12 @@ public class TrackWidgetProvider extends AppWidgetProvider
private String unknown; private String unknown;
private String trackStartedBroadcastAction; private String trackStartedBroadcastAction;
private String trackStoppedBroadcastAction; private String trackStoppedBroadcastAction;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private long selectedTrackId; private long selectedTrackId;
private boolean metricUnits; private boolean metricUnits;
private boolean reportSpeed; private boolean reportSpeed;
private boolean useTotalTime; private boolean showMovingTime;
public TrackWidgetProvider() { public TrackWidgetProvider() {
super(); super();
@@ -93,21 +93,21 @@ public class TrackWidgetProvider extends AppWidgetProvider
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (key == null || PreferencesUtils.getKey(context, R.string.metric_units_key).equals(key)) { if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.metric_units_key))) {
metricUnits = PreferencesUtils.getBoolean( metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT); context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
} }
if (key == null || PreferencesUtils.getKey(context, R.string.report_speed_key).equals(key)) { if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.report_speed_key))) {
reportSpeed = PreferencesUtils.getBoolean( reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT); context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
} }
if (key == null if (key == null
|| PreferencesUtils.getKey(context, R.string.stats_use_total_time_key).equals(key)) { || key.equals(PreferencesUtils.getKey(context, R.string.stats_show_moving_time_key))) {
useTotalTime = PreferencesUtils.getBoolean(context, R.string.stats_use_total_time_key, showMovingTime = PreferencesUtils.getBoolean(context, R.string.stats_show_moving_time_key,
PreferencesUtils.STATS_USE_TOTAL_TIME_DEFAULT); PreferencesUtils.STATS_SHOW_MOVING_TIME_DEFAULT);
} }
if (key == null if (key == null
|| PreferencesUtils.getKey(context, R.string.selected_track_id_key).equals(key)) { || key.equals(PreferencesUtils.getKey(context, R.string.selected_track_id_key))) {
selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key); selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
} }
if (key != null) { if (key != null) {
@@ -155,15 +155,15 @@ public class TrackWidgetProvider extends AppWidgetProvider
context = aContext; context = aContext;
trackObserver = new TrackObserver(); trackObserver = new TrackObserver();
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
unknown = context.getString(R.string.value_unknown); unknown = context.getString(R.string.value_unknown);
trackStartedBroadcastAction = context.getString(R.string.track_started_broadcast_action); trackStartedBroadcastAction = context.getString(R.string.track_started_broadcast_action);
trackStoppedBroadcastAction = context.getString(R.string.track_stopped_broadcast_action); trackStoppedBroadcastAction = context.getString(R.string.track_stopped_broadcast_action);
sharedPreferences = context.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE); sharedPreferences = context.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE);
sharedPreferences.registerOnSharedPreferenceChangeListener(this); sharedPreferences.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(sharedPreferences, null); onSharedPreferenceChanged(sharedPreferences, null);
context.getContentResolver() context.getContentResolver()
.registerContentObserver(TracksColumns.CONTENT_URI, true, trackObserver); .registerContentObserver(TracksColumns.CONTENT_URI, true, trackObserver);
} }
@@ -197,16 +197,17 @@ public class TrackWidgetProvider extends AppWidgetProvider
*/ */
private void updateButton(RemoteViews remoteViews, String action) { private void updateButton(RemoteViews remoteViews, String action) {
boolean isRecording = trackStartedBroadcastAction.equals(action); boolean isRecording = trackStartedBroadcastAction.equals(action);
remoteViews.setViewVisibility(R.id.track_widget_record_button, isRecording ? View.GONE remoteViews.setViewVisibility(
: View.VISIBLE); R.id.track_widget_record_button, isRecording ? View.GONE : View.VISIBLE);
remoteViews.setViewVisibility(R.id.track_widget_stop_button, isRecording ? View.VISIBLE remoteViews.setViewVisibility(
: View.INVISIBLE); R.id.track_widget_stop_button, isRecording ? View.VISIBLE : View.INVISIBLE);
Intent intent = new Intent(context, ControlRecordingService.class).setAction( Intent intent = new Intent(context, ControlRecordingService.class).setAction(
context.getString(isRecording ? R.string.track_action_end : R.string.track_action_start)); context.getString(isRecording ? R.string.track_action_end : R.string.track_action_start));
PendingIntent pendingIntent = PendingIntent.getService( PendingIntent pendingIntent = PendingIntent.getService(
context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(isRecording ? R.id.track_widget_stop_button remoteViews.setOnClickPendingIntent(
: R.id.track_widget_record_button, pendingIntent); isRecording ? R.id.track_widget_stop_button : R.id.track_widget_record_button,
pendingIntent);
} }
/** /**
@@ -215,31 +216,48 @@ public class TrackWidgetProvider extends AppWidgetProvider
* @param remoteViews the remote views * @param remoteViews the remote views
*/ */
private void updateView(RemoteViews remoteViews) { private void updateView(RemoteViews remoteViews) {
Track track = selectedTrackId != PreferencesUtils.SELECTED_TRACK_ID_DEFAULT Track track = selectedTrackId != PreferencesUtils.SELECTED_TRACK_ID_DEFAULT ? myTracksProviderUtils
? myTracksProviderUtils.getTrack(selectedTrackId) : myTracksProviderUtils.getLastTrack(); .getTrack(selectedTrackId)
: myTracksProviderUtils.getLastTrack();
TripStatistics tripStatistics = track == null ? null : track.getTripStatistics(); TripStatistics tripStatistics = track == null ? null : track.getTripStatistics();
String distance = tripStatistics == null ? unknown
String distanceValue = tripStatistics == null ? unknown
: StringUtils.formatDistance(context, tripStatistics.getTotalDistance(), metricUnits); : StringUtils.formatDistance(context, tripStatistics.getTotalDistance(), metricUnits);
int timeLabelId = useTotalTime ? R.string.stats_total_time : R.string.stats_moving_time; remoteViews.setTextViewText(R.id.track_widget_distance_value, distanceValue);
String time = tripStatistics == null ? unknown : StringUtils.formatElapsedTime(
useTotalTime ? tripStatistics.getTotalTime() String totalTimeValue = tripStatistics == null ? unknown
: tripStatistics.getMovingTime()); : StringUtils.formatElapsedTime(tripStatistics.getTotalTime());
int speedLabelId; remoteViews.setTextViewText(R.id.track_widget_total_time_value, totalTimeValue);
if (useTotalTime) {
speedLabelId = reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace; String averageSpeedLabel = context.getString(
} else { reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
speedLabelId = reportSpeed ? R.string.stats_average_moving_speed remoteViews.setTextViewText(R.id.track_widget_average_speed_label, averageSpeedLabel);
: R.string.stats_average_moving_pace; String averageSpeedValue = tripStatistics == null ? unknown
: StringUtils.formatSpeed(
context, tripStatistics.getAverageSpeed(), metricUnits, reportSpeed);
remoteViews.setTextViewText(R.id.track_widget_average_speed_value, averageSpeedValue);
setStatVisibility(remoteViews, R.id.track_widget_moving_time_stat,
R.id.track_widget_moving_time_separator, showMovingTime);
if (showMovingTime) {
String movingTimeValue = tripStatistics == null ? unknown
: StringUtils.formatElapsedTime(tripStatistics.getMovingTime());
remoteViews.setTextViewText(R.id.track_widget_moving_time_value, movingTimeValue);
} }
String speed = tripStatistics == null ? unknown : StringUtils.formatSpeed( setStatVisibility(remoteViews, R.id.track_widget_average_moving_speed_stat,
context, useTotalTime ? tripStatistics.getAverageSpeed() R.id.track_widget_average_moving_speed_separator, showMovingTime);
: tripStatistics.getAverageMovingSpeed(), metricUnits, reportSpeed); if (showMovingTime) {
remoteViews.setTextViewText(R.id.track_widget_distance_value, distance); String averageMovingSpeedLabel = context.getString(
remoteViews.setTextViewText(R.id.track_widget_time_label, context.getString(timeLabelId)); reportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);
remoteViews.setTextViewText(R.id.track_widget_time_value, time); remoteViews.setTextViewText(
remoteViews.setTextViewText(R.id.track_widget_speed_label, context.getString(speedLabelId)); R.id.track_widget_average_moving_speed_label, averageMovingSpeedLabel);
remoteViews.setTextViewText(R.id.track_widget_speed_value, speed); String averageMovingSpeedValue = tripStatistics == null ? unknown
: StringUtils.formatSpeed(
context, tripStatistics.getAverageMovingSpeed(), metricUnits, reportSpeed);
remoteViews.setTextViewText(
R.id.track_widget_average_moving_speed_value, averageMovingSpeedValue);
}
Intent intent; Intent intent;
if (track != null) { if (track != null) {
@@ -251,8 +269,13 @@ public class TrackWidgetProvider extends AppWidgetProvider
TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(context); TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(context);
taskStackBuilder.addNextIntent(intent); taskStackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, 0); PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, 0);
remoteViews.setOnClickPendingIntent( remoteViews.setOnClickPendingIntent(R.id.track_widget_statistics, pendingIntent);
R.id.track_widget_statistics, pendingIntent);
remoteViews.setOnClickPendingIntent(R.id.track_widget_icon, pendingIntent); remoteViews.setOnClickPendingIntent(R.id.track_widget_icon, pendingIntent);
} }
private void setStatVisibility(
RemoteViews remoteViews, int statId, int separatorId, boolean show) {
remoteViews.setViewVisibility(statId, show ? View.VISIBLE : View.GONE);
remoteViews.setViewVisibility(separatorId, show ? View.VISIBLE : View.GONE);
}
} }