diff --git a/MyTracks/res/layout/stats_content.xml b/MyTracks/res/layout/stats_content.xml
index 9fa4abfff..b5748d095 100644
--- a/MyTracks/res/layout/stats_content.xml
+++ b/MyTracks/res/layout/stats_content.xml
@@ -142,5 +142,12 @@ limitations under the License.
+
+
\ No newline at end of file
diff --git a/MyTracks/res/values/strings.xml b/MyTracks/res/values/strings.xml
index ebca1149e..869e117f0 100644
--- a/MyTracks/res/values/strings.xml
+++ b/MyTracks/res/values/strings.xml
@@ -2146,11 +2146,11 @@ limitations under the License.
Character limit: ~23 (1 line)">
Calories
-
- Calories(Invalid type)
+ Setup Activity Type
diff --git a/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java
index e270e44b6..32c8c417d 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.stats.TripStatistics;
+import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StatsUtils;
import com.google.android.maps.mytracks.R;
@@ -36,7 +37,8 @@ public class AggregatedStatsActivity extends AbstractMyTracksActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- StatsUtils.setTripStatisticsValues(this, getTripStatistics());
+ StatsUtils.setTripStatisticsValues(this, getTripStatistics(),
+ PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
StatsUtils.setLocationValues(this, null, false);
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java
index 0439c5691..70cd0c416 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java
@@ -181,8 +181,10 @@ public class TrackEditActivity extends AbstractMyTracksActivity
public void onClick(View v) {
track.setName(name.getText().toString());
String category = activityType.getText().toString();
- if(!category.equals(track.getCategory())) {
- double calorie = CalorieUtils.calculateTrackCalorie(getApplicationContext(), track, category);
+ if (!category.equals(track.getCategory())) {
+ // TODO Is there no race condition when setCalorie is called.
+ double calorie = CalorieUtils.calculateTrackCalorie(getApplicationContext(), track,
+ category);
track.getTripStatistics().setCalorie(calorie);
}
track.setCategory(category);
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java
index 8cdaa71e5..c544891fa 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java
@@ -24,6 +24,7 @@ import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PhotoUtils;
+import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StatsUtils;
import com.google.android.maps.mytracks.R;
@@ -192,7 +193,8 @@ public class MarkerDetailFragment extends Fragment {
TextView name = (TextView) getView().findViewById(R.id.marker_detail_statistics_name);
name.setText(getString(R.string.generic_name_line, waypoint.getName()));
- StatsUtils.setTripStatisticsValues(getActivity(), waypoint.getTripStatistics());
+ StatsUtils.setTripStatisticsValues(getActivity(), waypoint.getTripStatistics(),
+ PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
StatsUtils.setLocationValues(getActivity(), waypoint.getLocation(), false);
}
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/StatsFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/StatsFragment.java
index 72576cfab..b2d1352ae 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/fragments/StatsFragment.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/StatsFragment.java
@@ -259,7 +259,11 @@ public class StatsFragment extends Fragment implements TrackDataListener {
* Updates the UI.
*/
private void updateUi(FragmentActivity activity) {
- StatsUtils.setTripStatisticsValues(activity, lastTripStatistics);
+ StatsUtils.setTripStatisticsValues(
+ activity,
+ lastTripStatistics,
+ trackDataHub == null ? PreferencesUtils.RECORDING_TRACK_ID_DEFAULT : trackDataHub
+ .getSelectedTrackId());
StatsUtils.setLocationValues(activity, lastLocation, isSelectedTrackRecording());
}
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java
index 7a7de0d02..e78cc399a 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java
@@ -285,7 +285,7 @@ public class CalorieUtils {
return TripStatistics.INVALID_CALORIE;
}
- double calorie = 0;
+ double calorie = 0.0;
MyTracksProviderUtils providerUtils = MyTracksProviderUtils.Factory.get(context);
long trackId = track.getId();
LocationIterator points = providerUtils.getTrackPointLocationIterator(trackId, -1, false,
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java
index f77b11a1e..975b36300 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java
@@ -16,12 +16,16 @@
package com.google.android.apps.mytracks.util;
+import com.google.android.apps.mytracks.TrackEditActivity;
import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
+import android.content.Intent;
import android.location.Location;
import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
import android.widget.TextView;
import java.util.Locale;
@@ -110,7 +114,7 @@ public class StatsUtils {
* @param tripStatistics the trip statistics
* @param trackId the id of track
*/
- public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) {
+ public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics, long trackId) {
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
@@ -188,7 +192,7 @@ public class StatsUtils {
if (tripStatistics != null) {
calories = tripStatistics.getCalorie();
}
- setCalorie(activity, R.id.stats_calorie, calories);
+ setCalorie(activity, R.id.stats_calorie, calories, trackId);
} else {
calorieHorizontalLine.setVisibility(View.GONE);
calorieContainer.setVisibility(View.GONE);
@@ -341,15 +345,37 @@ public class StatsUtils {
* @param activity the activity
* @param itemId the item id
* @param calorie the value of calorie
- * @param trackId the id of track
+ * @param trackId the id of track which is used to start track edit activity
+ * when user want to change the activity type
*/
- private static void setCalorie(Activity activity, int itemId, double calorie) {
- String calorieString = String.format(Locale.getDefault(), CALORIES_FORMAT, calorie);
+ private static void setCalorie(final Activity activity, int itemId, double calorie,
+ final long trackId) {
+ String calorieString;
+ View view = activity.findViewById(itemId);
+ Button button = (Button) activity.findViewById(R.id.stats_calorie_setup);
// Current activity type is not supported.
if (calorie == TripStatistics.INVALID_CALORIE) {
- calorieString = activity.getString(R.string.value_unknown);
+ // Return when it is not a valid track, which may be aggregated stats or
+ // marker.
+ if (trackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
+ return;
+ }
+ button.setVisibility(View.VISIBLE);
+ view.setVisibility(View.GONE);
+ button.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = IntentUtils.newIntent(activity, TrackEditActivity.class).putExtra(
+ TrackEditActivity.EXTRA_TRACK_ID, trackId);
+ activity.startActivity(intent);
+ }
+ });
+ } else {
+ button.setVisibility(View.GONE);
+ view.setVisibility(View.VISIBLE);
+ calorieString = String.format(Locale.getDefault(), CALORIES_FORMAT, calorie);
+ setItem(activity, itemId, R.string.stats_calorie, calorieString,
+ activity.getString(R.string.unit_calorie));
}
- setItem(activity, itemId, R.string.stats_calorie, calorieString,
- activity.getString(R.string.unit_calorie));
}
}
\ No newline at end of file
diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/stats/TripStatistics.java b/MyTracksLib/src/com/google/android/apps/mytracks/stats/TripStatistics.java
index 000169906..80aadb902 100644
--- a/MyTracksLib/src/com/google/android/apps/mytracks/stats/TripStatistics.java
+++ b/MyTracksLib/src/com/google/android/apps/mytracks/stats/TripStatistics.java
@@ -70,7 +70,7 @@ public class TripStatistics implements Parcelable {
* This value means the calorie value is invalid due to activity type is not
* supported.
*/
- public static final double INVALID_CALORIE = -1;
+ public static final double INVALID_CALORIE = -1.0;
/**
* Default constructor.
@@ -129,7 +129,9 @@ public class TripStatistics implements Parcelable {
gradeExtremities.update(other.gradeExtremities.getMin());
gradeExtremities.update(other.gradeExtremities.getMax());
}
- calorie += other.calorie;
+ if (other.calorie != INVALID_CALORIE) {
+ calorie += other.calorie;
+ }
}
/**
@@ -585,9 +587,9 @@ public class TripStatistics implements Parcelable {
*/
public void addCalorie(double calorieAdded) {
if (calorieAdded != INVALID_CALORIE) {
- this.calorie += calorieAdded;
+ calorie = calorie == INVALID_CALORIE ? calorieAdded : calorie + calorieAdded;
} else {
- this.calorie = INVALID_CALORIE;
+ calorie = INVALID_CALORIE;
}
}