forked from upstream-mirrors/OpenTracks
Add an activity setup button in stat page when the activity type is not support to calculate calorie.
This commit is contained in:
@@ -142,5 +142,12 @@ limitations under the License.
|
|||||||
<include
|
<include
|
||||||
android:id="@+id/stats_calorie"
|
android:id="@+id/stats_calorie"
|
||||||
layout="@layout/stats_small_item" />
|
layout="@layout/stats_small_item" />
|
||||||
|
<!-- Setup activity type-->
|
||||||
|
<Button
|
||||||
|
android:id="@+id/stats_calorie_setup"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:text="@string/stats_calorie_setup" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</merge>
|
</merge>
|
||||||
@@ -2146,11 +2146,11 @@ limitations under the License.
|
|||||||
Character limit: ~23 (1 line)">
|
Character limit: ~23 (1 line)">
|
||||||
Calories
|
Calories
|
||||||
</string>
|
</string>
|
||||||
<string name="stats_calorie_invalid_type"
|
<string name="stats_calorie_setup"
|
||||||
translation_description="In the 'Stats' page, the calorie value label while pending.
|
translation_description="In the 'Stats' page, the button to setup calorie.
|
||||||
|
|
||||||
Character limit: ~23 (1 line)">
|
Character limit: ~23 (1 line)">
|
||||||
Calories(Invalid type)
|
Setup Activity Type
|
||||||
</string>
|
</string>
|
||||||
<string name="stats_fastest_pace"
|
<string name="stats_fastest_pace"
|
||||||
translation_description="In the 'Stats' page, the fastest pace.">
|
translation_description="In the 'Stats' page, the fastest pace.">
|
||||||
|
|||||||
@@ -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.MyTracksProviderUtils;
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
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.apps.mytracks.util.StatsUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
@@ -36,7 +37,8 @@ public class AggregatedStatsActivity extends AbstractMyTracksActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
StatsUtils.setTripStatisticsValues(this, getTripStatistics());
|
StatsUtils.setTripStatisticsValues(this, getTripStatistics(),
|
||||||
|
PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||||
StatsUtils.setLocationValues(this, null, false);
|
StatsUtils.setLocationValues(this, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -181,8 +181,10 @@ public class TrackEditActivity extends AbstractMyTracksActivity
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
track.setName(name.getText().toString());
|
track.setName(name.getText().toString());
|
||||||
String category = activityType.getText().toString();
|
String category = activityType.getText().toString();
|
||||||
if(!category.equals(track.getCategory())) {
|
if (!category.equals(track.getCategory())) {
|
||||||
double calorie = CalorieUtils.calculateTrackCalorie(getApplicationContext(), track, category);
|
// TODO Is there no race condition when setCalorie is called.
|
||||||
|
double calorie = CalorieUtils.calculateTrackCalorie(getApplicationContext(), track,
|
||||||
|
category);
|
||||||
track.getTripStatistics().setCalorie(calorie);
|
track.getTripStatistics().setCalorie(calorie);
|
||||||
}
|
}
|
||||||
track.setCategory(category);
|
track.setCategory(category);
|
||||||
|
|||||||
@@ -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.content.Waypoint.WaypointType;
|
||||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||||
import com.google.android.apps.mytracks.util.PhotoUtils;
|
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.apps.mytracks.util.StatsUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
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);
|
TextView name = (TextView) getView().findViewById(R.id.marker_detail_statistics_name);
|
||||||
name.setText(getString(R.string.generic_name_line, waypoint.getName()));
|
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);
|
StatsUtils.setLocationValues(getActivity(), waypoint.getLocation(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,7 +259,11 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
* Updates the UI.
|
* Updates the UI.
|
||||||
*/
|
*/
|
||||||
private void updateUi(FragmentActivity activity) {
|
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());
|
StatsUtils.setLocationValues(activity, lastLocation, isSelectedTrackRecording());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ public class CalorieUtils {
|
|||||||
return TripStatistics.INVALID_CALORIE;
|
return TripStatistics.INVALID_CALORIE;
|
||||||
}
|
}
|
||||||
|
|
||||||
double calorie = 0;
|
double calorie = 0.0;
|
||||||
MyTracksProviderUtils providerUtils = MyTracksProviderUtils.Factory.get(context);
|
MyTracksProviderUtils providerUtils = MyTracksProviderUtils.Factory.get(context);
|
||||||
long trackId = track.getId();
|
long trackId = track.getId();
|
||||||
LocationIterator points = providerUtils.getTrackPointLocationIterator(trackId, -1, false,
|
LocationIterator points = providerUtils.getTrackPointLocationIterator(trackId, -1, false,
|
||||||
|
|||||||
@@ -16,12 +16,16 @@
|
|||||||
|
|
||||||
package com.google.android.apps.mytracks.util;
|
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.apps.mytracks.stats.TripStatistics;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -110,7 +114,7 @@ public class StatsUtils {
|
|||||||
* @param tripStatistics the trip statistics
|
* @param tripStatistics the trip statistics
|
||||||
* @param trackId the id of track
|
* @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 metricUnits = PreferencesUtils.isMetricUnits(activity);
|
||||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
|
boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
|
||||||
|
|
||||||
@@ -188,7 +192,7 @@ public class StatsUtils {
|
|||||||
if (tripStatistics != null) {
|
if (tripStatistics != null) {
|
||||||
calories = tripStatistics.getCalorie();
|
calories = tripStatistics.getCalorie();
|
||||||
}
|
}
|
||||||
setCalorie(activity, R.id.stats_calorie, calories);
|
setCalorie(activity, R.id.stats_calorie, calories, trackId);
|
||||||
} else {
|
} else {
|
||||||
calorieHorizontalLine.setVisibility(View.GONE);
|
calorieHorizontalLine.setVisibility(View.GONE);
|
||||||
calorieContainer.setVisibility(View.GONE);
|
calorieContainer.setVisibility(View.GONE);
|
||||||
@@ -341,15 +345,37 @@ public class StatsUtils {
|
|||||||
* @param activity the activity
|
* @param activity the activity
|
||||||
* @param itemId the item id
|
* @param itemId the item id
|
||||||
* @param calorie the value of calorie
|
* @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) {
|
private static void setCalorie(final Activity activity, int itemId, double calorie,
|
||||||
String calorieString = String.format(Locale.getDefault(), CALORIES_FORMAT, 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.
|
// Current activity type is not supported.
|
||||||
if (calorie == TripStatistics.INVALID_CALORIE) {
|
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ public class TripStatistics implements Parcelable {
|
|||||||
* This value means the calorie value is invalid due to activity type is not
|
* This value means the calorie value is invalid due to activity type is not
|
||||||
* supported.
|
* supported.
|
||||||
*/
|
*/
|
||||||
public static final double INVALID_CALORIE = -1;
|
public static final double INVALID_CALORIE = -1.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
@@ -129,7 +129,9 @@ public class TripStatistics implements Parcelable {
|
|||||||
gradeExtremities.update(other.gradeExtremities.getMin());
|
gradeExtremities.update(other.gradeExtremities.getMin());
|
||||||
gradeExtremities.update(other.gradeExtremities.getMax());
|
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) {
|
public void addCalorie(double calorieAdded) {
|
||||||
if (calorieAdded != INVALID_CALORIE) {
|
if (calorieAdded != INVALID_CALORIE) {
|
||||||
this.calorie += calorieAdded;
|
calorie = calorie == INVALID_CALORIE ? calorieAdded : calorie + calorieAdded;
|
||||||
} else {
|
} else {
|
||||||
this.calorie = INVALID_CALORIE;
|
calorie = INVALID_CALORIE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user