forked from upstream-mirrors/OpenTracks
To save power, modify StatsFragment to not listen to location changes.
This commit is contained in:
@@ -355,6 +355,14 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
|| key.equals(PreferencesUtils.getKey(context, R.string.min_required_accuracy_key))) {
|
|| key.equals(PreferencesUtils.getKey(context, R.string.min_required_accuracy_key))) {
|
||||||
minRequiredAccuracy = PreferencesUtils.getInt(context, R.string.min_required_accuracy_key,
|
minRequiredAccuracy = PreferencesUtils.getInt(context, R.string.min_required_accuracy_key,
|
||||||
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
|
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
|
||||||
|
if (key != null) {
|
||||||
|
for (TrackDataListener trackDataListener :
|
||||||
|
trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||||
|
if (trackDataListener.onMinRequiredAccuracy(minRequiredAccuracy)) {
|
||||||
|
loadDataForListener(trackDataListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (key == null
|
if (key == null
|
||||||
|| key.equals(PreferencesUtils.getKey(context, R.string.min_recording_distance_key))) {
|
|| key.equals(PreferencesUtils.getKey(context, R.string.min_recording_distance_key))) {
|
||||||
@@ -409,6 +417,7 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||||
trackDataListener.onMetricUnitsChanged(metricUnits);
|
trackDataListener.onMetricUnitsChanged(metricUnits);
|
||||||
trackDataListener.onReportSpeedChanged(reportSpeed);
|
trackDataListener.onReportSpeedChanged(reportSpeed);
|
||||||
|
trackDataListener.onMinRequiredAccuracy(minRequiredAccuracy);
|
||||||
trackDataListener.onMinRecordingDistanceChanged(minRecordingDistance);
|
trackDataListener.onMinRecordingDistanceChanged(minRecordingDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,6 +453,7 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
if (trackDataTypes.contains(TrackDataType.PREFERENCE)) {
|
if (trackDataTypes.contains(TrackDataType.PREFERENCE)) {
|
||||||
trackDataListener.onMetricUnitsChanged(metricUnits);
|
trackDataListener.onMetricUnitsChanged(metricUnits);
|
||||||
trackDataListener.onReportSpeedChanged(reportSpeed);
|
trackDataListener.onReportSpeedChanged(reportSpeed);
|
||||||
|
trackDataListener.onMinRequiredAccuracy(minRequiredAccuracy);
|
||||||
trackDataListener.onMinRecordingDistanceChanged(minRecordingDistance);
|
trackDataListener.onMinRecordingDistanceChanged(minRecordingDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,6 +134,14 @@ public interface TrackDataListener {
|
|||||||
*/
|
*/
|
||||||
public boolean onReportSpeedChanged(boolean reportSpeed);
|
public boolean onReportSpeedChanged(boolean reportSpeed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the min required accuracy preference value is changed.
|
||||||
|
*
|
||||||
|
* @param minRequiredAccuracy the new value
|
||||||
|
* @return true to reload all the data, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean onMinRequiredAccuracy(int minRequiredAccuracy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the min recording distance preference value is changed.
|
* Called when the min recording distance preference value is changed.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -297,6 +297,12 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMinRequiredAccuracy(int minRequiredAccuracy) {
|
||||||
|
// We don't care.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMinRecordingDistanceChanged(int value) {
|
public boolean onMinRecordingDistanceChanged(int value) {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
|
|||||||
@@ -554,6 +554,12 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMinRequiredAccuracy(int minRequiredAccuracy) {
|
||||||
|
// We don't care.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMinRecordingDistanceChanged(int minRecordingDistance) {
|
public boolean onMinRecordingDistanceChanged(int minRecordingDistance) {
|
||||||
// We don't care.
|
// We don't care.
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import com.google.android.apps.mytracks.content.TrackDataListener;
|
|||||||
import com.google.android.apps.mytracks.content.TrackDataType;
|
import com.google.android.apps.mytracks.content.TrackDataType;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
|
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.apps.mytracks.util.StatsUtils;
|
import com.google.android.apps.mytracks.util.StatsUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
public static final String STATS_FRAGMENT_TAG = "statsFragment";
|
public static final String STATS_FRAGMENT_TAG = "statsFragment";
|
||||||
|
|
||||||
|
private static final long MAX_LOCATION_AGE_MS = 60 * 1000; // 1 minute
|
||||||
private static final int ONE_SECOND = 1000;
|
private static final int ONE_SECOND = 1000;
|
||||||
|
|
||||||
private TrackDataHub trackDataHub;
|
private TrackDataHub trackDataHub;
|
||||||
@@ -54,6 +57,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
private Location lastLocation = null;
|
private Location lastLocation = null;
|
||||||
private TripStatistics lastTripStatistics = null;
|
private TripStatistics lastTripStatistics = null;
|
||||||
|
private int minRequiredAccuracy = PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT;
|
||||||
|
|
||||||
// A runnable to update the total time field.
|
// A runnable to update the total time field.
|
||||||
private final Runnable updateTotalTime = new Runnable() {
|
private final Runnable updateTotalTime = new Runnable() {
|
||||||
@@ -96,40 +100,12 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationStateChanged(LocationState state) {
|
public void onLocationStateChanged(LocationState state) {
|
||||||
if (isResumed() && state != LocationState.GOOD_FIX) {
|
// We don't care.
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (isResumed()) {
|
|
||||||
lastLocation = null;
|
|
||||||
StatsUtils.setLocationValues(getActivity(), lastLocation, isSelectedTrackRecording());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(final Location location) {
|
public void onLocationChanged(final Location location) {
|
||||||
if (isResumed()) {
|
// We don't care.
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (isResumed()) {
|
|
||||||
if (isSelectedTrackRecording() && !isSelectedTrackPaused()) {
|
|
||||||
lastLocation = location;
|
|
||||||
StatsUtils.setLocationValues(getActivity(), location, isSelectedTrackRecording());
|
|
||||||
} else {
|
|
||||||
if (lastLocation != null) {
|
|
||||||
lastLocation = null;
|
|
||||||
StatsUtils.setLocationValues(
|
|
||||||
getActivity(), lastLocation, isSelectedTrackRecording());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -159,17 +135,17 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearTrackPoints() {
|
public void clearTrackPoints() {
|
||||||
// We don't care.
|
lastLocation = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSampledInTrackPoint(Location location) {
|
public void onSampledInTrackPoint(Location location) {
|
||||||
// We don't care.
|
lastLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSampledOutTrackPoint(Location location) {
|
public void onSampledOutTrackPoint(Location location) {
|
||||||
// We don't care.
|
lastLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -179,7 +155,28 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewTrackPointsDone() {
|
public void onNewTrackPointsDone() {
|
||||||
// We don't care.
|
if (isResumed()) {
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (isResumed()) {
|
||||||
|
if (!isSelectedTrackRecording() || isSelectedTrackPaused()) {
|
||||||
|
lastLocation = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastLocation != null) {
|
||||||
|
boolean hasFix = !isLocationOld(lastLocation);
|
||||||
|
boolean hasGoodFix = lastLocation.getAccuracy() <= minRequiredAccuracy;
|
||||||
|
|
||||||
|
if (!hasFix || !hasGoodFix) {
|
||||||
|
lastLocation = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StatsUtils.setLocationValues(getActivity(), lastLocation, isSelectedTrackRecording());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -227,6 +224,12 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMinRequiredAccuracy(int newValue) {
|
||||||
|
minRequiredAccuracy = newValue;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMinRecordingDistanceChanged(int minRecordingDistance) {
|
public boolean onMinRecordingDistanceChanged(int minRecordingDistance) {
|
||||||
// We don't care.
|
// We don't care.
|
||||||
@@ -240,7 +243,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
private synchronized void resumeTrackDataHub() {
|
private synchronized void resumeTrackDataHub() {
|
||||||
trackDataHub = ((TrackDetailActivity) getActivity()).getTrackDataHub();
|
trackDataHub = ((TrackDetailActivity) getActivity()).getTrackDataHub();
|
||||||
trackDataHub.registerTrackDataListener(this, EnumSet.of(TrackDataType.SELECTED_TRACK,
|
trackDataHub.registerTrackDataListener(this, EnumSet.of(TrackDataType.SELECTED_TRACK,
|
||||||
TrackDataType.TRACKS_TABLE, TrackDataType.LOCATION, TrackDataType.PREFERENCE));
|
TrackDataType.TRACKS_TABLE, TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE,
|
||||||
|
TrackDataType.SAMPLED_OUT_TRACK_POINTS_TABLE, TrackDataType.PREFERENCE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -268,6 +272,16 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
return trackDataHub != null && trackDataHub.isSelectedTrackPaused();
|
return trackDataHub != null && trackDataHub.isSelectedTrackPaused();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if a location is old.
|
||||||
|
*
|
||||||
|
* @param location the location
|
||||||
|
*/
|
||||||
|
private boolean isLocationOld(Location location) {
|
||||||
|
return !LocationUtils.isValidLocation(location)
|
||||||
|
|| (System.currentTimeMillis() - location.getTime() > MAX_LOCATION_AGE_MS);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the UI.
|
* Updates the UI.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user