Removed calories and weight.

This commit is contained in:
Dennis Guse
2019-07-09 21:28:13 +02:00
parent 6678d5b36b
commit 88cd919d92
28 changed files with 141 additions and 819 deletions
@@ -2,7 +2,6 @@
package com.google.android.apps.mytracks.stats;
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import android.location.Location;
@@ -19,8 +18,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
private static final long ONE_SECOND = 1000;
private static final long TEN_SECONDS = 10 * ONE_SECOND;
private static final float MOVING_SPEED = 11.1f;
private static final double DEFAULT_WEIGHT = 65.0;
private TripStatisticsUpdater tripStatisticsUpdater = null;
@Override
@@ -214,9 +212,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
// Each time slice is 10 seconds.
Location location = getLocation(i + locationOffset, (i + locationOffset) * .001, MOVING_SPEED,
startTime + (timeOffset + i) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.WALKING,
DEFAULT_WEIGHT);
tripStatisticsUpdater.addLocation(location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime());
@@ -262,9 +258,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
for (int i = 0; i < points; i++) {
Location location = getLocation(
locationOffset, locationOffset * .001, 0, startTime + (i + timeOffset) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, false, ActivityType.WALKING,
DEFAULT_WEIGHT);
tripStatisticsUpdater.addLocation(location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime());
@@ -298,9 +292,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
// 99999 means a speed should bigger than given speed.
Location location = getLocation(i + locationOffset, (i + locationOffset) * .001, 99999,
startTime + (timeOffset + i) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.WALKING,
DEFAULT_WEIGHT);
tripStatisticsUpdater.addLocation(location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertTrue(tripStatistics.getMovingTime() <= tripStatistics.getTotalTime());
@@ -1,65 +1,63 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
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.CalorieUtils.ActivityType;
import com.google.android.apps.mytracks.util.StatsUtils;
import com.google.android.maps.mytracks.R;
import android.os.Bundle;
import java.util.List;
/**
* An activity to view aggregated stats from all recorded tracks.
*
* @author Fergus Nelson
*/
public class AggregatedStatsActivity extends AbstractMyTracksActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StatsUtils.setTripStatisticsValues(
this, this, null, getTripStatistics(), ActivityType.WALKING, null);
StatsUtils.setLocationValues(this, this, null, null, false);
}
@Override
protected int getLayoutResId() {
return R.layout.stats;
}
/**
* Gets the aggregated trip statistics for all the recorded tracks or null if
* there is no track.
*/
private TripStatistics getTripStatistics() {
List<Track> tracks = MyTracksProviderUtils.Factory.get(this).getAllTracks();
TripStatistics tripStatistics = null;
if (!tracks.isEmpty()) {
tripStatistics = new TripStatistics(tracks.iterator().next().getTripStatistics());
for (int i = 1; i < tracks.size(); i++) {
tripStatistics.merge(tracks.get(i).getTripStatistics());
}
}
return tripStatistics;
}
}
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
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.StatsUtils;
import com.google.android.maps.mytracks.R;
import android.os.Bundle;
import java.util.List;
/**
* An activity to view aggregated stats from all recorded tracks.
*
* @author Fergus Nelson
*/
public class AggregatedStatsActivity extends AbstractMyTracksActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StatsUtils.setTripStatisticsValues(this, this, null, getTripStatistics(), null);
StatsUtils.setLocationValues(this, this, null, null, false);
}
@Override
protected int getLayoutResId() {
return R.layout.stats;
}
/**
* Gets the aggregated trip statistics for all the recorded tracks or null if
* there is no track.
*/
private TripStatistics getTripStatistics() {
List<Track> tracks = MyTracksProviderUtils.Factory.get(this).getAllTracks();
TripStatistics tripStatistics = null;
if (!tracks.isEmpty()) {
tripStatistics = new TripStatistics(tracks.iterator().next().getTripStatistics());
for (int i = 1; i < tracks.size(); i++) {
tripStatistics.merge(tracks.get(i).getTripStatistics());
}
}
return tripStatistics;
}
}
@@ -30,8 +30,6 @@ import com.google.android.apps.mytracks.fragments.FrequencyDialogFragment;
import com.google.android.apps.mytracks.fragments.StatsFragment;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.apps.mytracks.settings.SettingsActivity;
import com.google.android.apps.mytracks.util.CalorieUtils;
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
import com.google.android.apps.mytracks.util.FileUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
@@ -540,16 +538,9 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
}
@Override
public void onChooseActivityTypeDone(String iconValue, boolean newWeight) {
public void onChooseActivityTypeDone(String iconValue) {
Track track = myTracksProviderUtils.getTrack(trackId);
String category = getString(TrackIconUtils.getIconActivityType(iconValue));
TrackUtils.updateTrack(
this, track, null, category, null, myTracksProviderUtils, trackRecordingServiceConnection, newWeight);
// Add toast if cannot calculate calorie
if (CalorieUtils.getActivityType(this, category) == ActivityType.INVALID) {
String message = getString(R.string.stats_calorie_no_calculation, category);
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
TrackUtils.updateTrack(this, track, null, category, null, myTracksProviderUtils);
}
}
@@ -63,8 +63,6 @@ public class TrackEditActivity extends AbstractMyTracksActivity implements Choos
private Spinner activityTypeIcon;
private EditText description;
private boolean newWeight = false;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
@@ -153,7 +151,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity implements Choos
public void onClick(View v) {
TrackUtils.updateTrack(TrackEditActivity.this, track, name.getText().toString(),
activityType.getText().toString(), description.getText().toString(),
myTracksProviderUtils, trackRecordingServiceConnection, newWeight);
myTracksProviderUtils);
finish();
}
});
@@ -204,10 +202,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity implements Choos
}
@Override
public void onChooseActivityTypeDone(String value, boolean hasNewWeight) {
if (!newWeight) {
newWeight = hasNewWeight;
}
public void onChooseActivityTypeDone(String value) {
setActivityTypeIcon(value);
activityType.setText(getString(TrackIconUtils.getIconActivityType(value)));
}
@@ -39,7 +39,6 @@ import com.google.android.apps.mytracks.content.TrackDataType;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater;
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.UnitConversions;
@@ -458,8 +457,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
double power = Double.NaN;
if (tripStatisticsUpdater != null) {
tripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, false, ActivityType.INVALID, 0.0);
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
if (chartByDistance) {
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
@@ -56,7 +56,7 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
/**
* Called when choose activity type is done.
*/
void onChooseActivityTypeDone(String iconValue, boolean newWeight);
void onChooseActivityTypeDone(String iconValue);
}
public static final String CHOOSE_ACTIVITY_TYPE_DIALOG_TAG = "chooseActivityType";
@@ -94,14 +94,6 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
final Activity activity, final String category, final ChooseActivityTypeCaller caller) {
View view = activity.getLayoutInflater().inflate(R.layout.choose_activity_type, null);
GridView gridView = view.findViewById(R.id.choose_activity_type_grid_view);
final View weightContainer = view.findViewById(R.id.choose_activity_type_weight_container);
TextView weightLabel = view.findViewById(R.id.choose_activity_type_weight_label);
weightLabel.setText(
PreferencesUtils.isMetricUnits(activity) ? R.string.description_weight_metric
: R.string.description_weight_imperial);
final TextView weight = view.findViewById(R.id.choose_activity_type_weight);
List<Integer> imageIds = new ArrayList<>();
for (String iconValue : TrackIconUtils.getAllIconValues()) {
@@ -120,25 +112,14 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
activity, imageIds, width, height, padding);
gridView.setAdapter(imageAdapter);
final String weightValue = StringUtils.formatWeight(
PreferencesUtils.getWeightDisplayValue(activity));
final AlertDialog alertDialog = new AlertDialog.Builder(activity).setNegativeButton(
R.string.generic_cancel, null)
.setPositiveButton(R.string.generic_ok, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
boolean newWeight = false;
if (weightContainer.getVisibility() == View.VISIBLE) {
String newValue = weight.getText().toString();
if (!newValue.equals(weightValue)) {
newWeight = true;
PreferencesUtils.storeWeightValue(activity, newValue);
}
}
int selected = imageAdapter.getSelected();
caller.onChooseActivityTypeDone(
TrackIconUtils.getAllIconValues().get(selected), newWeight);
caller.onChooseActivityTypeDone(TrackIconUtils.getAllIconValues().get(selected));
}
}).setTitle(R.string.track_edit_activity_type_hint).setView(view).create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@@ -150,8 +131,6 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
imageAdapter.setSelected(position);
imageAdapter.notifyDataSetChanged();
}
updateWeightContainer(weightContainer, position);
weight.setText(weightValue);
DialogUtils.setDialogTitleDivider(activity, alertDialog);
}
});
@@ -162,7 +141,6 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
alertDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(true);
imageAdapter.setSelected(position);
imageAdapter.notifyDataSetChanged();
updateWeightContainer(weightContainer, position);
}
});
return alertDialog;
@@ -16,29 +16,11 @@
package com.google.android.apps.mytracks.fragments;
import com.google.android.apps.mytracks.MarkerEditActivity;
import com.google.android.apps.mytracks.TrackDetailActivity;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import com.google.android.apps.mytracks.util.CalorieUtils;
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.ListItemUtils;
import com.google.android.apps.mytracks.util.PhotoUtils;
import com.google.android.apps.mytracks.util.StatsUtils;
import com.google.android.apps.mytracks.util.StringUtils;
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;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
@@ -54,6 +36,23 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.google.android.apps.mytracks.MarkerEditActivity;
import com.google.android.apps.mytracks.TrackDetailActivity;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
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.ListItemUtils;
import com.google.android.apps.mytracks.util.PhotoUtils;
import com.google.android.apps.mytracks.util.StatsUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.apps.mytracks.util.TrackIconUtils;
import com.google.android.maps.mytracks.R;
/**
* A fragment to show marker details.
*
@@ -294,11 +293,7 @@ public class MarkerDetailFragment extends Fragment {
setLocation(R.id.marker_detail_statistics_location, false);
Track track = myTracksProviderUtils.getTrack(waypoint.getTrackId());
ActivityType activityType = track != null ? CalorieUtils.getActivityType(
getActivity(), track.getCategory())
: ActivityType.INVALID;
StatsUtils.setTripStatisticsValues(
getActivity(), null, getView(), waypoint.getTripStatistics(), activityType, null);
StatsUtils.setTripStatisticsValues(getActivity(), null, getView(), waypoint.getTripStatistics(), null);
StatsUtils.setLocationValues(getActivity(), null, getView(), waypoint.getLocation(), false);
}
}
@@ -16,6 +16,19 @@
package com.google.android.apps.mytracks.fragments;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Spinner;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.google.android.apps.mytracks.TrackDetailActivity;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TrackDataHub;
@@ -23,8 +36,6 @@ import com.google.android.apps.mytracks.content.TrackDataListener;
import com.google.android.apps.mytracks.content.TrackDataType;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.util.CalorieUtils;
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StatsUtils;
@@ -32,18 +43,6 @@ import com.google.android.apps.mytracks.util.TrackIconUtils;
import com.google.android.apps.mytracks.util.UnitConversions;
import com.google.android.maps.mytracks.R;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Spinner;
import java.util.EnumSet;
/**
@@ -297,11 +296,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
* Updates the UI.
*/
private void updateUi(FragmentActivity activity) {
ActivityType activityType = CalorieUtils.getActivityType(activity, category);
String trackIconValue = TrackIconUtils.getIconValue(activity, category);
StatsUtils.setTripStatisticsValues(
activity, activity, null, lastTripStatistics, activityType, trackIconValue);
StatsUtils.setLocationValues(
activity, activity, null, lastLocation, isSelectedTrackRecording());
StatsUtils.setTripStatisticsValues(activity, activity, null, lastTripStatistics, trackIconValue);
StatsUtils.setLocationValues(activity, activity, null, lastLocation, isSelectedTrackRecording());
}
}
@@ -25,8 +25,6 @@ import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import com.google.android.apps.mytracks.services.TrackRecordingService;
import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater;
import com.google.android.apps.mytracks.util.CalorieUtils;
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
import com.google.android.apps.mytracks.util.FileUtils;
import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
@@ -108,7 +106,6 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
private final long importTrackId;
private final MyTracksProviderUtils myTracksProviderUtils;
private final int recordingDistanceInterval;
private final double weight;
private final List<Long> trackIds;
private final List<Waypoint> waypoints;
@@ -146,8 +143,6 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
this.recordingDistanceInterval = PreferencesUtils.getInt(context,
R.string.recording_distance_interval_key,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
this.weight = PreferencesUtils.getFloat(
context, R.string.weight_key, PreferencesUtils.getDefaultWeight(context));
trackIds = new ArrayList<>();
waypoints = new ArrayList<>();
}
@@ -224,8 +219,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
TripStatisticsUpdater markerTripStatisticsUpdater = new TripStatisticsUpdater(
track.getTripStatistics().getStartTime());
LocationIterator locationIterator = null;
ActivityType activityType = CalorieUtils.getActivityType(context, track.getCategory());
try {
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
track.getId(), -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
@@ -245,10 +239,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
return;
}
location = locationIterator.next();
trackTripStatisticstrackUpdater.addLocation(
location, recordingDistanceInterval, false, ActivityType.INVALID, 0.0);
markerTripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, true, activityType, weight);
trackTripStatisticstrackUpdater.addLocation(location, recordingDistanceInterval);
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
}
if (waypoint.getLocation().getTime() > location.getTime()) {
location = null;
@@ -563,9 +555,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
trackData.tripStatisticsUpdater = new TripStatisticsUpdater(
location.getTime() != -1L ? location.getTime() : trackData.importTime);
}
ActivityType activityType = CalorieUtils.getActivityType(context, category);
trackData.tripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, true, activityType, weight);
trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
trackData.bufferedLocations[trackData.numBufferedLocations] = location;
trackData.numBufferedLocations++;
@@ -62,8 +62,6 @@ import com.google.android.apps.mytracks.services.tasks.PeriodicTaskExecutor;
import com.google.android.apps.mytracks.services.tasks.SplitPeriodicTaskFactory;
import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater;
import com.google.android.apps.mytracks.util.CalorieUtils;
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
@@ -131,8 +129,7 @@ public class TrackRecordingService extends Service {
private int recordingGpsAccuracy;
private int autoResumeTrackTimeout;
private long currentRecordingInterval;
private double weight;
// The following variables are set when recording:
private TripStatisticsUpdater trackTripStatisticsUpdater;
private TripStatisticsUpdater markerTripStatisticsUpdater;
@@ -230,10 +227,6 @@ public class TrackRecordingService extends Service {
R.string.auto_resume_track_timeout_key,
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
}
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.weight_key))) {
weight = PreferencesUtils.getFloat(
context, R.string.weight_key, PreferencesUtils.getDefaultWeight(context));
}
}
};
@@ -625,8 +618,6 @@ public class TrackRecordingService extends Service {
}
markerTripStatisticsUpdater = new TripStatisticsUpdater(markerStartTime);
ActivityType activityType = CalorieUtils.getActivityType(context, track.getCategory());
LocationIterator locationIterator = null;
try {
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
@@ -634,11 +625,9 @@ public class TrackRecordingService extends Service {
while (locationIterator.hasNext()) {
Location location = locationIterator.next();
trackTripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, true, activityType, weight);
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
if (location.getTime() > markerStartTime) {
markerTripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, true, activityType, weight);
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
}
}
} catch (RuntimeException e) {
@@ -768,7 +757,6 @@ public class TrackRecordingService extends Service {
track.setIcon(iconValue);
track.setCategory(getString(TrackIconUtils.getIconActivityType(iconValue)));
myTracksProviderUtils.updateTrack(track);
CalorieUtils.updateTrackCalorie(context, track);
}
}
}
@@ -993,11 +981,8 @@ public class TrackRecordingService extends Service {
try {
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId());
long trackPointId = Long.parseLong(uri.getLastPathSegment());
ActivityType activityType = CalorieUtils.getActivityType(context, track.getCategory());
trackTripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, true, activityType, weight);
markerTripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, true, activityType, weight);
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location));
} catch (SQLiteException e) {
/*
@@ -1335,47 +1320,5 @@ public class TrackRecordingService extends Service {
deathRecipient.binderDied();
}
}
@Override
public void updateCalorie() {
if (!canAccess()) {
return;
}
trackRecordingService.updateCalorie();
}
}
/**
* Updates the calorie of current recording track after the current track is
* edited by user.
*/
public void updateCalorie() {
if (executorService == null || executorService.isShutdown() || executorService.isTerminated()) {
return;
}
executorService.submit(new Runnable() {
@Override
public void run() {
if (!isRecording()) {
Log.w(TAG, "Ignore updateCalorie. Not recording.");
return;
}
Track track = myTracksProviderUtils.getTrack(recordingTrackId);
if (track == null) {
Log.w(TAG, "Ignore updateCalorie. No track.");
return;
}
double[] calories = CalorieUtils.updateTrackCalorie(context, track);
// Update track statistics
trackTripStatisticsUpdater.updateCalorie(calories[0]);
// Update marker statistics
markerTripStatisticsUpdater.updateCalorie(calories[1]);
}
});
}
}
@@ -353,7 +353,7 @@ public class RecordingSettingsActivity extends AbstractSettingsActivity
}
@Override
public void onChooseActivityTypeDone(String iconValue, boolean newWeight) {
public void onChooseActivityTypeDone(String iconValue) {
activityTypePreference.updateValue(iconValue);
}
}
@@ -17,11 +17,10 @@
package com.google.android.apps.mytracks.stats;
import android.location.Location;
import androidx.annotation.VisibleForTesting;
import android.util.Log;
import com.google.android.apps.mytracks.util.CalorieUtils;
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
import androidx.annotation.VisibleForTesting;
import com.google.android.apps.mytracks.util.LocationUtils;
import static com.google.android.apps.mytracks.services.TrackRecordingService.MAX_NO_MOVEMENT_SPEED;
@@ -124,14 +123,8 @@ public class TripStatisticsUpdater {
*
* @param location the location
* @param minRecordingDistance the min recording distance
* @param calculateCalorie true means calculate calorie
* @param activityType the activity type of current track which is used to
* calculate calorie
* @param weight the weight to calculate calorie which is used to calculate
* calorie
*/
public void addLocation(Location location, int minRecordingDistance,
boolean calculateCalorie, ActivityType activityType, double weight) {
public void addLocation(Location location, int minRecordingDistance) {
// Always update time
updateTime(location.getTime());
if (!LocationUtils.isValidLocation(location)) {
@@ -193,12 +186,6 @@ public class TripStatisticsUpdater {
location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
}
if (calculateCalorie) {
// Update calorie
double calorie = CalorieUtils.getCalorie(lastMovingLocation, location,
gradeBuffer.getAverage(), weight, activityType);
currentSegment.addCalorie(calorie);
}
lastLocation = location;
lastMovingLocation = location;
}
@@ -338,14 +325,4 @@ public class TripStatisticsUpdater {
return true;
}
}
/**
* Updates the calorie value;
*
* @param calorie
*/
public void updateCalorie(double calorie) {
tripStatistics.setCalorie(calorie);
currentSegment.setCalorie(0);
}
}
@@ -1,303 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.database.Cursor;
import android.location.Location;
/**
* Utilities to calculate calories.
*
* @author youtaol
*/
public class CalorieUtils {
/**
* Activity types.
*/
public enum ActivityType {
CYCLING, RUNNING, WALKING, INVALID
}
private CalorieUtils() {}
/**
* Resting VO2 is 3.5 milliliters per kilogram of body weight per minute
* (ml/kg/min). The resting VO2 is the same for everyone.
*/
private static final double RESTING_VO2 = 3.5;
/**
* Standard gravity in meters per second squared (m/s^2).
*/
private static final double EARTH_GRAVITY = 9.81;
/**
* Lumped constant for all frictional losses (tires, bearings, chain).
*/
private static final double K1 = 0.0053;
/**
* Lumped constant for aerodynamic drag (kg/m)
*/
private static final double K2 = 0.185;
/**
* Gets the activity type.
*
* @param context the context
* @param activityType the activity type
*/
public static ActivityType getActivityType(Context context, String activityType) {
if (activityType == null || activityType.equals("")) {
return ActivityType.INVALID;
}
switch (TrackIconUtils.getIconValue(context, activityType)) {
case TrackIconUtils.WALK:
return ActivityType.WALKING;
case TrackIconUtils.RUN:
return ActivityType.RUNNING;
case TrackIconUtils.BIKE:
return ActivityType.CYCLING;
}
return ActivityType.INVALID;
}
/**
* Updates calories for a track and its waypoints.
*
* @param context the context
* @param track the track
* @return an array of two doubles, first is the track calorie, second is the
* last statistics waypoint calorie
*/
public static double[] updateTrackCalorie(Context context, Track track) {
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
ActivityType activityType = getActivityType(context, track.getCategory());
if (activityType == ActivityType.INVALID) {
clearCalorie(myTracksProviderUtils, track);
return new double[] { 0.0, 0.0 };
}
TripStatisticsUpdater trackTripStatisticsUpdater = new TripStatisticsUpdater(
track.getTripStatistics().getStartTime());
TripStatisticsUpdater markerTripStatisticsUpdater = new TripStatisticsUpdater(
track.getTripStatistics().getStartTime());
int recordingDistanceInterval = PreferencesUtils.getInt(context,
R.string.recording_distance_interval_key,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
double weight = PreferencesUtils.getFloat(
context, R.string.weight_key, PreferencesUtils.getDefaultWeight(context));
LocationIterator locationIterator = null;
Cursor cursor = null;
try {
Waypoint waypoint = null;
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
track.getId(), -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
cursor = myTracksProviderUtils.getWaypointCursor(track.getId(), -1L, -1);
if (cursor != null && cursor.moveToFirst()) {
/*
* Yes, this will skip the first waypoint and that is intentional as the
* first waypoint holds the stats for the track.
*/
waypoint = getNextStatisticsWaypoint(myTracksProviderUtils, cursor);
}
while (locationIterator.hasNext()) {
Location location = locationIterator.next();
trackTripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, true, activityType, weight);
markerTripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, true, activityType, weight);
if (waypoint != null && waypoint.getLocation().getTime() == location.getTime()
&& waypoint.getLocation().getLatitude() == location.getLatitude()
&& waypoint.getLocation().getLongitude() == location.getLongitude()) {
waypoint.getTripStatistics()
.setCalorie(markerTripStatisticsUpdater.getTripStatistics().getCalorie());
myTracksProviderUtils.updateWaypoint(waypoint);
markerTripStatisticsUpdater = new TripStatisticsUpdater(location.getTime());
waypoint = getNextStatisticsWaypoint(myTracksProviderUtils, cursor);
}
}
} finally {
if (locationIterator != null) {
locationIterator.close();
}
if (cursor != null) {
cursor.close();
}
}
double trackCalorie = trackTripStatisticsUpdater.getTripStatistics().getCalorie();
track.getTripStatistics().setCalorie(trackCalorie);
myTracksProviderUtils.updateTrack(track);
return new double[] {
trackCalorie, markerTripStatisticsUpdater.getTripStatistics().getCalorie() };
}
/**
* Gets the calorie in kcal between two locations.
*
* @param start the start location
* @param stop the stop location
* @param grade the grade
* @param weight the weight in kilogram. For cycling, weight of the rider plus
* bike. For foot, weight of the user
* @param activityType the activity type
*/
public static double getCalorie(
Location start, Location stop, double grade, double weight, ActivityType activityType) {
if (activityType == ActivityType.INVALID) {
return 0.0;
}
if (grade < 0) {
grade = 0.0;
}
// Speed in m/s
double speed = (start.getSpeed() + stop.getSpeed()) / 2.0;
// Duration in min
double duration = (double) (stop.getTime() - start.getTime()) * UnitConversions.MS_TO_S
* UnitConversions.S_TO_MIN;
if (activityType == ActivityType.CYCLING) {
/*
* Power in watt (Joule/second). See
* http://en.wikipedia.org/wiki/Bicycle_performance.
*/
double power = EARTH_GRAVITY * weight * speed * (K1 + grade) + K2 * (speed * speed * speed);
// WorkRate in kgm/min
double workRate = power * UnitConversions.W_TO_KGM;
/*
* VO2 in kgm/min/kg 1.8 = oxygen cost of producing 1 kgm/min of power
* output. 7 = oxygen cost of unloaded cycling plus resting oxygen
* consumption
*/
double vo2 = (1.8 * workRate / weight) + 7;
// Calorie in kcal
return vo2 * duration * weight * UnitConversions.KGM_TO_KCAL;
} else {
double vo2 = activityType == ActivityType.RUNNING ? getRunningVo2(speed, grade)
: getWalkingVo2(speed, grade);
/*
* Calorie in kcal (mL/kg/min * min * kg * L/mL * kcal/L)
*/
return vo2 * duration * weight * UnitConversions.ML_TO_L * UnitConversions.L_TO_KCAL;
}
}
/**
* Clears calorie in the track and its waypoints.
*
* @param myTracksProviderUtils the my tracks provider utils
* @param track the track
*/
private static void clearCalorie(MyTracksProviderUtils myTracksProviderUtils, Track track) {
track.getTripStatistics().setCalorie(0);
myTracksProviderUtils.updateTrack(track);
try (Cursor cursor = myTracksProviderUtils.getWaypointCursor(track.getId(), -1L, -1)) {
if (cursor != null && cursor.moveToFirst()) {
/*
* Yes, this will skip the first waypoint and that is intentional as the
* first waypoint holds the stats for the track.
*/
Waypoint waypoint = getNextStatisticsWaypoint(myTracksProviderUtils, cursor);
while (waypoint != null) {
waypoint.getTripStatistics().setCalorie(0);
myTracksProviderUtils.updateWaypoint(waypoint);
waypoint = getNextStatisticsWaypoint(myTracksProviderUtils, cursor);
}
}
}
}
/**
* Gets the next statistics waypoint from a cursor.
*
* @param myTracksProviderUtils the my tracks provider utils
* @param cursor the cursor
*/
private static Waypoint getNextStatisticsWaypoint(
MyTracksProviderUtils myTracksProviderUtils, Cursor cursor) {
if (cursor == null) {
return null;
}
while (cursor.moveToNext()) {
Waypoint waypoint = myTracksProviderUtils.createWaypoint(cursor);
if (waypoint.getType() == WaypointType.STATISTICS) {
return waypoint;
}
}
return null;
}
/**
* Gets the running VO2 in ml/kg/min. This equation is appropriate for speeds
* greater than 5 mi/hr (or 3 mi/hr or greater if the subject is truly
* jogging).
*
* @param speed the speed in m/s
* @param grade the grade
*/
private static double getRunningVo2(double speed, double grade) {
// Change from m/s to m/min
speed = speed / UnitConversions.S_TO_MIN;
/*
* 0.2 = oxygen cost per meter of moving each kg of body weight while
* running (horizontally). 0.9 = oxygen cost per meter of moving total body
* mass against gravity (vertically).
*/
return 0.2 * speed + 0.9 * speed * grade + RESTING_VO2;
}
/**
* Gets the walking VO2 in ml/kg/min. This equation is appropriate for speed
* from 1.9 to 4 mi/hr.
*
* @param speed the speed in m/s
* @param grade the grade
*/
private static double getWalkingVo2(double speed, double grade) {
// Change from m/s to m/min
speed = speed / UnitConversions.S_TO_MIN;
/*
* 0.1 = oxygen cost per meter of moving each kilogram (kg) of body weight
* while walking (horizontally). 1.8 = oxygen cost per meter of moving total
* body mass against gravity (vertically).
*/
return 0.1 * speed + 1.8 * speed * grade + RESTING_VO2;
}
}
@@ -304,48 +304,4 @@ public class PreferencesUtils {
}
setString(context, keyId, list + ";" + value);
}
/**
* Gets the default weight.
*
* @param context the context
*/
public static float getDefaultWeight(Context context) {
if (isMetricUnits(context)) {
return 65.0f; // in kg
} else {
return 68.0389f; // 150 lb in kg
}
}
/**
* Stores the weight value, always in metric units.
*
* @param displayValue the display value
*/
public static void storeWeightValue(Context context, String displayValue) {
double value;
try {
value = Double.parseDouble(displayValue);
if (!isMetricUnits(context)) {
value = value * UnitConversions.LB_TO_KG;
}
} catch (NumberFormatException e) {
Log.e(TAG, "invalid value " + displayValue);
value = getDefaultWeight(context);
}
setFloat(context, R.string.weight_key, (float) value);
}
/**
* Gets the weight display value.
*
* @param context the context
*/
public static double getWeightDisplayValue(Context context) {
double value = getFloat(context, R.string.weight_key, getDefaultWeight(context));
if (!isMetricUnits(context)) {
value = value * UnitConversions.KG_TO_LB;
}
return value;
}
}
@@ -17,7 +17,6 @@
package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
@@ -38,7 +37,6 @@ public class StatsUtils {
private static final String GRADE_PERCENTAGE = "%";
private static final String GRADE_FORMAT = "%1$d";
private static final String CALORIES_FORMAT = "%1$,.0f";
private StatsUtils() {}
@@ -124,12 +122,11 @@ public class StatsUtils {
* @param view the containing view for finding views. If null, the activity
* cannot be null
* @param tripStatistics the trip statistics
* @param activityType the activity type
* @param trackIconValue the track icon value or null to hide the track icon
* spinner
*/
public static void setTripStatisticsValues(Context context, Activity activity, View view,
TripStatistics tripStatistics, ActivityType activityType, String trackIconValue) {
TripStatistics tripStatistics, String trackIconValue) {
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
boolean reportSpeed = PreferencesUtils.isReportSpeed(context);
@@ -138,11 +135,7 @@ public class StatsUtils {
setDistanceValue(
context, getView(activity, view, R.id.stats_distance), totalDistance, metricUnits);
// Set calorie
double calorie = tripStatistics == null || activityType == ActivityType.INVALID ? Double.NaN
: tripStatistics.getCalorie();
setCalorie(context, getView(activity, view, R.id.stats_calorie), calorie);
// Set activity type
Spinner spinner = (Spinner) getView(activity, view, R.id.stats_activity_type_icon);
spinner.setVisibility(trackIconValue != null ? View.VISIBLE : View.GONE);
if (trackIconValue != null) {
@@ -225,19 +218,6 @@ public class StatsUtils {
setItem(context, view, reportSpeed ? speedLabelId : paceLabelId, parts[0], parts[1]);
}
/**
* Sets calorie.
*
* @param context the context
* @param view the containing view
* @param calorie the value of calorie
*/
private static void setCalorie(Context context, View view, double calorie) {
String value = Double.isNaN(calorie) ? null
: String.format(Locale.getDefault(), CALORIES_FORMAT, calorie);
setItem(context, view, R.string.stats_calorie, value, context.getString(R.string.unit_calorie));
}
/**
* Sets distance value.
*
@@ -332,20 +312,22 @@ public class StatsUtils {
* @param value the value, can be null
* @param unit the unit. Null to hide the unit
*/
private static void setItem(
Context context, View view, int labelId, CharSequence value, CharSequence unit) {
private static void setItem(Context context, View view, int labelId, CharSequence value, CharSequence unit) {
TextView labelTextView = view.findViewById(R.id.stats_label);
if (labelTextView != null) {
if (labelId == -1) {
labelTextView.setVisibility(View.GONE);
} else {
labelTextView.setVisibility(View.VISIBLE);
labelTextView.setText(labelId);
}
}
TextView valueTextView = view.findViewById(R.id.stats_value);
TextView unitTextView = view.findViewById(R.id.stats_unit);
if (labelTextView == null || valueTextView == null || unitTextView == null) {
if (valueTextView == null || unitTextView == null) {
return;
}
if (labelId == -1) {
labelTextView.setVisibility(View.GONE);
} else {
labelTextView.setVisibility(View.VISIBLE);
labelTextView.setText(labelId);
}
if (value == null) {
value = context.getString(R.string.value_unknown);
@@ -151,10 +151,6 @@ public class StringUtils {
}
}
public static String formatWeight(double value) {
return formatDecimal(value, 1);
}
public static String formatDecimal(double value) {
return formatDecimal(value, 2);
}
@@ -193,25 +193,4 @@ public class TrackRecordingServiceConnectionUtils {
Toast.makeText(context, R.string.marker_add_error, Toast.LENGTH_LONG).show();
return -1L;
}
/**
* Updates the calorie of current recording track.
*
* @param trackRecordingServiceConnection
*/
public static void updateCalorie(TrackRecordingServiceConnection trackRecordingServiceConnection) {
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection
.getServiceIfBound();
if (trackRecordingService == null) {
Log.d(TAG, "Unable to update calorie, no track recording service");
} else {
try {
trackRecordingService.updateCalorie();
} catch (RemoteException e) {
Log.e(TAG, "Unable to update calorie", e);
} catch (IllegalStateException e) {
Log.e(TAG, "Unable to update calorie.", e);
}
}
}
}
@@ -19,8 +19,6 @@ package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.maps.mytracks.R;
import android.content.Context;
@@ -37,14 +35,11 @@ public class TrackUtils {
+ TracksColumns.STARTTIME + " DESC";
public static void updateTrack(Context context, Track track, String name, String category,
String description, MyTracksProviderUtils myTracksProviderUtils,
TrackRecordingServiceConnection trackRecordingServiceConnection, boolean newWeight) {
String description, MyTracksProviderUtils myTracksProviderUtils) {
if (name != null) {
track.setName(name);
}
boolean updateCalorie = false;
if (category != null) {
updateCalorie = !category.equals(track.getCategory()) || newWeight;
track.setCategory(category);
track.setIcon(TrackIconUtils.getIconValue(context, category));
}
@@ -54,14 +49,5 @@ public class TrackUtils {
}
track.setModifiedTime(System.currentTimeMillis());
myTracksProviderUtils.updateTrack(track);
if (updateCalorie) {
if (track.getId() == PreferencesUtils.getLong(context, R.string.recording_track_id_key)) {
// Update calorie through track recording service
TrackRecordingServiceConnectionUtils.updateCalorie(trackRecordingServiceConnection);
} else {
CalorieUtils.updateTrackCalorie(context, track);
}
}
}
}
@@ -67,28 +67,6 @@ public class UnitConversions {
// multiplication factor to convert meters to feet
public static final double M_TO_FT = M_TO_MI * MI_TO_FT;
// Weight
// multiplication factor to convert kilograms to pounds
public static final double KG_TO_LB = 2.2046;
// multiplication factor to convert pounds to kilograms
public static final double LB_TO_KG = 1 / KG_TO_LB;
// Calories
// multiplication factor to convert milliliters to liters
public static final double ML_TO_L = 1 / 1000.0;
// multiplication factor to convert liter to kcal
public static final double L_TO_KCAL = 5.0;
// multiplication factor to convert watt to kgm/min
public static final double W_TO_KGM = 6.12;
// multiplication factor to convert kgm to kcal
public static final double KGM_TO_KCAL = 1 / 427.0;
// Others
// multiplication factor to convert meters per second to kilometers per hour
@@ -24,7 +24,7 @@ limitations under the License.
layout="@layout/stats_large_item" />
<include
android:id="@+id/stats_calorie"
layout="@layout/stats_calorie" />
layout="@layout/stats_activity_type" />
<View
android:layout_height="match_parent"
android:layout_width="1dp"
@@ -27,29 +27,4 @@ limitations under the License.
android:padding="4dp"
android:stretchMode="spacingWidth"
android:verticalSpacing="4dp" />
<LinearLayout
android:id="@+id/choose_activity_type_weight_container"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/choose_activity_type_weight_label"
android:layout_marginBottom="2dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="4dp"
android:paddingLeft="12dp"
style="@style/TextMedium" />
<EditText
android:id="@+id/choose_activity_type_weight"
android:inputType="numberDecimal"
android:layout_marginBottom="4dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="2dp"
android:layout_width="match_parent"
android:selectAllOnFocus="true"
android:singleLine="true"
style="@style/TextMedium" />
</LinearLayout>
</LinearLayout>
@@ -22,15 +22,6 @@ limitations under the License.
style="@style/StatsLargeLabel" />
<!-- Value container -->
<LinearLayout style="@style/StatsLargeValueContainer" >
<!-- Value -->
<TextView
android:id="@+id/stats_value"
style="@style/StatsLargeValue" />
<!-- Unit -->
<TextView
android:id="@+id/stats_unit"
style="@style/StatsUnit" />
<!-- Activity type -->
<Spinner
android:id="@+id/stats_activity_type_icon"
android:layout_height="wrap_content"
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Distance and calorie -->
<!-- Distance and activity type -->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent" >
@@ -24,7 +24,7 @@ limitations under the License.
layout="@layout/stats_large_item" />
<include
android:id="@+id/stats_calorie"
layout="@layout/stats_calorie" />
layout="@layout/stats_activity_type" />
</LinearLayout>
<!-- Total time and moving time -->
<LinearLayout
-24
View File
@@ -529,14 +529,6 @@ limitations under the License.
translation_description="Label for a track segment">
Segment
</string>
<string name="description_weight_imperial"
translation_description="Label for weight in pounds.">
Weight (lb)
</string>
<string name="description_weight_metric"
translation_description="Label for weight in kilograms.">
Weight (kg)
</string>
<!-- Eula -->
<string name="eula_accept"
@@ -1988,18 +1980,6 @@ limitations under the License.
Character limit: ~23 (1 line)">
Elevation
</string>
<string name="stats_calorie"
translation_description="In the 'Stats' page, the calorie burned.
Character limit: ~23 (1 line)">
Calories
</string>
<string name="stats_calorie_no_calculation"
translation_description="In the 'Stats' page, the message when calories cannot be calculated.
%1$s activity type. E.g., 'driving'.">
Calories can\'t be calculated with %1$s
</string>
<string name="stats_fastest_pace"
translation_description="In the 'Stats' page, the fastest pace.">
Fastest pace
@@ -2283,10 +2263,6 @@ limitations under the License.
translation_description="Abbreviation for minutes per mile. E.g., '5 min/mi'.">
min/mi
</string>
<string name="unit_calorie"
translation_description="Abbreviation for calorie. E.g., '5 Cal'.">
Cal
</string>
<!-- Value -->
<string name="value_adapt_accuracy"
@@ -106,9 +106,4 @@ interface ITrackRecordingService {
* return a Sensor.SensorState enum value.
*/
int getSensorState();
/**
* Updates the calorie of current recording track.
*/
void updateCalorie();
}
@@ -156,9 +156,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
if (!cursor.isNull(maxGradeIndex)) {
tripStatistics.setMaxGrade(cursor.getFloat(maxGradeIndex));
}
if (!cursor.isNull(caloriesIndex)) {
tripStatistics.setCalorie(cursor.getFloat(caloriesIndex));
}
if (!cursor.isNull(iconIndex)) {
track.setIcon(cursor.getString(iconIndex));
}
@@ -322,8 +319,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
values.put(TracksColumns.MODIFIEDTIME, track.getModifiedTime());
values.put(TracksColumns.SHAREDWITHME, track.isSharedWithMe());
values.put(TracksColumns.SHAREDOWNER, track.getSharedOwner());
values.put(TracksColumns.CALORIE, tripStatistics.getCalorie());
return values;
}
@@ -474,10 +470,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
tripStatistics.setMaxGrade(cursor.getFloat(maxGradeIndex));
hasTripStatistics = true;
}
if (!cursor.isNull(calorieIndex)) {
tripStatistics.setCalorie(cursor.getFloat(calorieIndex));
hasTripStatistics = true;
}
if (hasTripStatistics) {
waypoint.setTripStatistics(tripStatistics);
}
@@ -710,7 +702,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
values.put(WaypointsColumns.ELEVATIONGAIN, tripStatistics.getTotalElevationGain());
values.put(WaypointsColumns.MINGRADE, tripStatistics.getMinGrade());
values.put(WaypointsColumns.MAXGRADE, tripStatistics.getMaxGrade());
values.put(WaypointsColumns.CALORIE, tripStatistics.getCalorie());
}
values.put(WaypointsColumns.PHOTOURL, waypoint.getPhotoUrl());
@@ -88,7 +88,7 @@ public interface TracksColumns extends BaseColumns {
// The owner of the shared with me track
String SHAREDOWNER = "sharedOwner";
// Calorie burned of the track
String CALORIE = "calorie";
@@ -62,9 +62,6 @@ public class TripStatistics implements Parcelable {
// The min and max grade seen on this trip.
private final ExtremityMonitor gradeExtremities = new ExtremityMonitor();
// The calorie of current track.
private double calorie = 0.0;
/**
* Default constructor.
*/
@@ -89,7 +86,6 @@ public class TripStatistics implements Parcelable {
other.elevationExtremities.getMin(), other.elevationExtremities.getMax());
totalElevationGain = other.totalElevationGain;
gradeExtremities.set(other.gradeExtremities.getMin(), other.gradeExtremities.getMax());
calorie = other.calorie;
}
/**
@@ -122,7 +118,6 @@ public class TripStatistics implements Parcelable {
gradeExtremities.update(other.gradeExtremities.getMin());
gradeExtremities.update(other.gradeExtremities.getMax());
}
calorie += other.calorie;
}
/**
@@ -493,8 +488,7 @@ public class TripStatistics implements Parcelable {
+ "; Max Longitude: " + getRightDegrees() + "; Max Speed: " + getMaxSpeed()
+ "; Min Elevation: " + getMinElevation() + "; Max Elevation: " + getMaxElevation()
+ "; Elevation Gain: " + getTotalElevationGain() + "; Min Grade: " + getMinGrade()
+ "; Max Grade: " + getMaxGrade() + "; Calorie: " + getCalorie()
+ "}";
+ "; Max Grade: " + getMaxGrade() + "}";
}
/**
@@ -530,8 +524,7 @@ public class TripStatistics implements Parcelable {
double minGrade = source.readDouble();
double maxGrade = source.readDouble();
data.gradeExtremities.set(minGrade, maxGrade);
data.calorie = source.readDouble();
return data;
}
@@ -568,31 +561,5 @@ public class TripStatistics implements Parcelable {
dest.writeDouble(totalElevationGain);
dest.writeDouble(gradeExtremities.getMin());
dest.writeDouble(gradeExtremities.getMax());
dest.writeDouble(calorie);
}
/**
* Adds calorie value.
*
* @param calorieAdded add the value to the total calorie
*/
public void addCalorie(double calorieAdded) {
calorie += calorieAdded;
}
/**
* Sets calorie value.
*
* @param calorie the new value of calorie
*/
public void setCalorie(double calorie) {
this.calorie = calorie;
}
/**
* Gets calorie value.
*/
public double getCalorie() {
return calorie;
}
}