diff --git a/myTracks/src/androidTest/java/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java b/myTracks/src/androidTest/java/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java index 8d43dfd75..d940608ec 100644 --- a/myTracks/src/androidTest/java/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java +++ b/myTracks/src/androidTest/java/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java @@ -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()); diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/AggregatedStatsActivity.java b/myTracks/src/main/java/com/google/android/apps/mytracks/AggregatedStatsActivity.java index d0ea24bc8..ed1424e78 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/AggregatedStatsActivity.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/AggregatedStatsActivity.java @@ -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 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 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; + } +} diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/TrackDetailActivity.java b/myTracks/src/main/java/com/google/android/apps/mytracks/TrackDetailActivity.java index 6627cc6ab..7e9e552f4 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/TrackDetailActivity.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/TrackDetailActivity.java @@ -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); } } \ No newline at end of file diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/TrackEditActivity.java b/myTracks/src/main/java/com/google/android/apps/mytracks/TrackEditActivity.java index f8076eaaf..8792166e7 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/TrackEditActivity.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/TrackEditActivity.java @@ -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))); } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/ChartFragment.java b/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/ChartFragment.java index e19fcc5f8..c88b9e184 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/ChartFragment.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/ChartFragment.java @@ -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; diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/ChooseActivityTypeDialogFragment.java b/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/ChooseActivityTypeDialogFragment.java index 23563f969..436b43679 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/ChooseActivityTypeDialogFragment.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/ChooseActivityTypeDialogFragment.java @@ -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 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; diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java b/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java index 23ea49c0d..d76acfa74 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/MarkerDetailFragment.java @@ -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); } } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/StatsFragment.java b/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/StatsFragment.java index 8909a2a0c..a74dd66e0 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/StatsFragment.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/fragments/StatsFragment.java @@ -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()); } } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java b/myTracks/src/main/java/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java index 2cf8508a3..23b7b9394 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java @@ -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 trackIds; private final List 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++; diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/services/TrackRecordingService.java b/myTracks/src/main/java/com/google/android/apps/mytracks/services/TrackRecordingService.java index 7e28a8b8c..0bd90f57e 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -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]); - } - }); } } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/settings/RecordingSettingsActivity.java b/myTracks/src/main/java/com/google/android/apps/mytracks/settings/RecordingSettingsActivity.java index 8cdf82466..4e45f165f 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/settings/RecordingSettingsActivity.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/settings/RecordingSettingsActivity.java @@ -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); } } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java b/myTracks/src/main/java/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java index b3e2067ff..7fa2475ff 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java @@ -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); - } } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/util/CalorieUtils.java b/myTracks/src/main/java/com/google/android/apps/mytracks/util/CalorieUtils.java deleted file mode 100644 index d8ff73bb1..000000000 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/util/CalorieUtils.java +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/util/PreferencesUtils.java b/myTracks/src/main/java/com/google/android/apps/mytracks/util/PreferencesUtils.java index 8513da0b9..a07a2b2e9 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/util/PreferencesUtils.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/util/PreferencesUtils.java @@ -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; - } } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/util/StatsUtils.java b/myTracks/src/main/java/com/google/android/apps/mytracks/util/StatsUtils.java index 2b1699019..a68ee1c8a 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/util/StatsUtils.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/util/StatsUtils.java @@ -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); diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/util/StringUtils.java b/myTracks/src/main/java/com/google/android/apps/mytracks/util/StringUtils.java index 028cf05b4..be7795226 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/util/StringUtils.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/util/StringUtils.java @@ -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); } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java b/myTracks/src/main/java/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java index 3cd98a5f1..f84351386 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java @@ -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); - } - } - } } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/util/TrackUtils.java b/myTracks/src/main/java/com/google/android/apps/mytracks/util/TrackUtils.java index 9c95d4c8e..67c6e494e 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/util/TrackUtils.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/util/TrackUtils.java @@ -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); - } - } } } diff --git a/myTracks/src/main/java/com/google/android/apps/mytracks/util/UnitConversions.java b/myTracks/src/main/java/com/google/android/apps/mytracks/util/UnitConversions.java index 73a198ca8..30d548c67 100644 --- a/myTracks/src/main/java/com/google/android/apps/mytracks/util/UnitConversions.java +++ b/myTracks/src/main/java/com/google/android/apps/mytracks/util/UnitConversions.java @@ -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 diff --git a/myTracks/src/main/res/layout-land/stats_content.xml b/myTracks/src/main/res/layout-land/stats_content.xml index 05c1afde5..6be9c2191 100644 --- a/myTracks/src/main/res/layout-land/stats_content.xml +++ b/myTracks/src/main/res/layout-land/stats_content.xml @@ -24,7 +24,7 @@ limitations under the License. layout="@layout/stats_large_item" /> + layout="@layout/stats_activity_type" /> - - - - \ No newline at end of file diff --git a/myTracks/src/main/res/layout/stats_calorie.xml b/myTracks/src/main/res/layout/stats_activity_type.xml similarity index 82% rename from myTracks/src/main/res/layout/stats_calorie.xml rename to myTracks/src/main/res/layout/stats_activity_type.xml index 952fe2fc8..aaa983107 100644 --- a/myTracks/src/main/res/layout/stats_calorie.xml +++ b/myTracks/src/main/res/layout/stats_activity_type.xml @@ -22,15 +22,6 @@ limitations under the License. style="@style/StatsLargeLabel" /> - - - - - - + @@ -24,7 +24,7 @@ limitations under the License. layout="@layout/stats_large_item" /> + layout="@layout/stats_activity_type" /> Segment - - Weight (lb) - - - Weight (kg) - Elevation - - Calories - - - Calories can\'t be calculated with %1$s - Fastest pace @@ -2283,10 +2263,6 @@ limitations under the License. translation_description="Abbreviation for minutes per mile. E.g., '5 min/mi'."> min/mi - - Cal -