Merge heads

This commit is contained in:
youtaol
2013-07-12 10:43:51 +08:00
parent a484963572
commit f4ccb8dbd4
94 changed files with 829 additions and 750 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
android:versionCode="68"
android:versionCode="69"
android:versionName="2.0.5"
package="com.google.android.maps.mytracks" >
<!-- Permission to initialize services -->
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -107,7 +107,9 @@ public class MapOverlay {
public CachedLocation(Location location) {
this.valid = LocationUtils.isValidLocation(location);
this.latLng = valid ? new LatLng(location.getLatitude(), location.getLongitude()) : null;
this.speed = (int) Math.floor(location.getSpeed() * UnitConversions.MS_TO_KMH);
this.speed = location.hasSpeed() ? (int) Math.floor(
location.getSpeed() * UnitConversions.MS_TO_KMH)
: -1;
}
/**
@@ -714,7 +714,8 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
hasGoodFix = false;
} else {
hasFix = !LocationUtils.isLocationOld(currentLocation);
hasGoodFix = currentLocation.getAccuracy() <= recordingGpsAccuracy;
hasGoodFix = currentLocation.hasAccuracy()
&& currentLocation.getAccuracy() < recordingGpsAccuracy;
}
if (!hasFix) {
message = getString(R.string.gps_wait_for_signal);
@@ -148,7 +148,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
if (lastLocation != null) {
boolean hasFix = !LocationUtils.isLocationOld(lastLocation);
boolean hasGoodFix = lastLocation.getAccuracy() <= recordingGpsAccuracy;
boolean hasGoodFix = lastLocation.hasAccuracy()
&& lastLocation.getAccuracy() < recordingGpsAccuracy;
if (!hasFix || !hasGoodFix) {
lastLocation = null;
@@ -888,7 +888,7 @@ public class TrackRecordingService extends Service {
return;
}
if (location.getAccuracy() > recordingGpsAccuracy) {
if (!location.hasAccuracy() || location.getAccuracy() >= recordingGpsAccuracy) {
Log.d(TAG, "Ignore onLocationChangedAsync. Poor accuracy.");
return;
}
@@ -35,12 +35,6 @@ import android.util.Log;
*/
public class TripStatisticsUpdater {
/**
* The number of distance readings to smooth to get a stable signal.
*/
@VisibleForTesting
static final int DISTANCE_SMOOTHING_FACTOR = 25;
/**
* The number of elevation readings to smooth to get a somewhat accurate
* signal.
@@ -48,6 +42,18 @@ public class TripStatisticsUpdater {
@VisibleForTesting
static final int ELEVATION_SMOOTHING_FACTOR = 25;
/**
* The number of run readings to smooth for calculating grade.
*/
@VisibleForTesting
static final int RUN_SMOOTHING_FACTOR = 25;
/**
* The number of rise readings to smooth for calculating grade.
*/
@VisibleForTesting
static final int RISE_SMOOTHING_FACTOR = 25;
/**
* The number of grade readings to smooth to get a somewhat accurate signal.
*/
@@ -67,7 +73,7 @@ public class TripStatisticsUpdater {
/**
* Ignore any acceleration faster than this. Will ignore any speeds that imply
* accelaration greater than 2g's 2g = 19.6 m/s^2 = 0.0002 m/ms^2 = 0.02
* acceleration greater than 2g's 2g = 19.6 m/s^2 = 0.0002 m/ms^2 = 0.02
* m/(m*ms)
*/
private static final double MAX_ACCELERATION = 0.02;
@@ -84,18 +90,21 @@ public class TripStatisticsUpdater {
// Current segment's last moving location
private Location lastMovingLocation;
// A buffer of the recent speed readings (m/s) for calculating max speed
private final DoubleBuffer speedBuffer = new DoubleBuffer(SPEED_SMOOTHING_FACTOR);
// A buffer of the recent elevation readings (m)
private final DoubleBuffer elevationBuffer = new DoubleBuffer(ELEVATION_SMOOTHING_FACTOR);
// A buffer of the recent distance readings (m) for calculating grade
private final DoubleBuffer distanceBuffer = new DoubleBuffer(DISTANCE_SMOOTHING_FACTOR);
// A buffer of the recent run readings (m) for calculating grade
private final DoubleBuffer runBuffer = new DoubleBuffer(RUN_SMOOTHING_FACTOR);
// A buffer of the recent rise readings (m) for calculating grade
private final DoubleBuffer riseBuffer = new DoubleBuffer(RISE_SMOOTHING_FACTOR);
// A buffer of the recent grade calculations (%)
private final DoubleBuffer gradeBuffer = new DoubleBuffer(GRADE_SMOOTHING_FACTOR);
// A buffer of the recent speed readings (m/s) for calculating max speed
private final DoubleBuffer speedBuffer = new DoubleBuffer(SPEED_SMOOTHING_FACTOR);
/**
* Creates a new trip statistics updater.
*
@@ -128,8 +137,11 @@ public class TripStatisticsUpdater {
* @param minRecordingDistance the min recording distance
*/
public void addLocation(Location location, int minRecordingDistance) {
// Always update time
updateTime(location.getTime());
if (!LocationUtils.isValidLocation(location)) {
updateTime(location.getTime());
// Either pause or resume marker
if (location.getLatitude() == TrackRecordingService.PAUSE_LATITUDE) {
if (lastLocation != null && lastMovingLocation != null
&& lastLocation != lastMovingLocation) {
@@ -140,40 +152,58 @@ public class TripStatisticsUpdater {
currentSegment = init(location.getTime());
lastLocation = null;
lastMovingLocation = null;
speedBuffer.reset();
elevationBuffer.reset();
distanceBuffer.reset();
runBuffer.reset();
riseBuffer.reset();
gradeBuffer.reset();
speedBuffer.reset();
return;
}
double elevationDifference = updateElevation(location.getAltitude());
currentSegment.updateLatitudeExtremities(location.getLatitude());
currentSegment.updateLongitudeExtremities(location.getLongitude());
if (location.hasAltitude()) {
updateElevation(location.getAltitude());
}
if (lastLocation == null || lastMovingLocation == null) {
updateTime(location.getTime());
lastLocation = location;
lastMovingLocation = location;
return;
}
double movingDistance = lastMovingLocation.distanceTo(location);
if (movingDistance < minRecordingDistance && location.getSpeed() < MAX_NO_MOVEMENT_SPEED) {
updateTime(location.getTime());
lastLocation = location;
return;
if (movingDistance < minRecordingDistance) {
if (!location.hasSpeed() || location.getSpeed() < MAX_NO_MOVEMENT_SPEED) {
lastLocation = location;
return;
}
}
long movingTime = location.getTime() - lastLocation.getTime();
if (movingTime < 0) {
updateTime(location.getTime());
lastLocation = location;
return;
}
// Update total distance
currentSegment.addTotalDistance(movingDistance);
// Update moving time
currentSegment.addMovingTime(movingTime);
updateSpeed(
location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
updateGrade(lastLocation.distanceTo(location), elevationDifference);
updateTime(location.getTime());
// Update grade
if (location.hasAltitude() && lastLocation.hasAltitude()) {
float run = lastLocation.distanceTo(location);
double rise = location.getAltitude() - lastLocation.getAltitude();
updateGrade(run, rise);
}
// Update max speed
if (location.hasSpeed() && lastLocation.hasSpeed()) {
updateSpeed(
location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
}
lastLocation = location;
lastMovingLocation = location;
}
@@ -217,38 +247,46 @@ public class TripStatisticsUpdater {
* @param elevation the elevation
*/
@VisibleForTesting
double updateElevation(double elevation) {
void updateElevation(double elevation) {
currentSegment.updateElevationExtremities(elevation);
// update elevation gain
double oldAverage = elevationBuffer.getAverage();
elevationBuffer.setNext(elevation);
double newAverage = elevationBuffer.getAverage();
currentSegment.updateElevationExtremities(newAverage);
double elevationDifference = elevationBuffer.isFull() ? newAverage - oldAverage : 0.0;
if (elevationDifference > 0) {
currentSegment.addTotalElevationGain(elevationDifference);
if (elevationBuffer.isFull()) {
double difference = newAverage - oldAverage;
if (difference > 0) {
currentSegment.addTotalElevationGain(difference);
}
}
return elevationDifference;
}
/**
* Updates a grade reading.
*
* @param distance the distance the user just traveled
* @param elevationDifference the elevation difference between the current
* reading and the previous reading
* @param run the run
* @param rise the rise
*/
@VisibleForTesting
void updateGrade(double distance, double elevationDifference) {
distanceBuffer.setNext(distance);
double smoothedDistance = distanceBuffer.getAverage();
void updateGrade(double run, double rise) {
runBuffer.setNext(run);
riseBuffer.setNext(rise);
if (!runBuffer.isFull() || !riseBuffer.isFull()) {
return;
}
double smoothedRun = runBuffer.getAverage();
/*
* With the error in the altitude measurement it is dangerous to divide by
* anything less than 5.
*/
if (!elevationBuffer.isFull() || !distanceBuffer.isFull() || smoothedDistance < 5.0) {
if (smoothedRun < 5.0) {
return;
}
gradeBuffer.setNext(elevationDifference / smoothedDistance);
gradeBuffer.setNext(riseBuffer.getAverage() / smoothedRun);
currentSegment.updateGradeExtremities(gradeBuffer.getAverage());
}
@@ -54,7 +54,8 @@ public class StatsUtils {
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
// Set speed/pace
double speed = !isRecording || location == null ? Double.NaN : location.getSpeed();
double speed = isRecording && location != null && location.hasSpeed() ? location.getSpeed()
: Double.NaN;
setSpeed(activity, R.id.stats_speed, R.string.stats_speed, R.string.stats_pace, speed,
metricUnits, reportSpeed);
@@ -65,7 +66,8 @@ public class StatsUtils {
View elevation = activity.findViewById(R.id.stats_elevation);
if (showGradeElevation && isRecording) {
double altitude = location == null ? Double.NaN : location.getAltitude();
double altitude = location != null && location.hasAltitude() ? location.getAltitude()
: Double.NaN;
elevation.setVisibility(View.VISIBLE);
setElevationValue(activity, R.id.stats_elevation, -1, altitude, metricUnits);
} else {
@@ -79,8 +81,8 @@ public class StatsUtils {
View coordinateContainer = activity.findViewById(R.id.stats_coordinate_container);
if (showCoordinate && isRecording) {
double latitude = location == null ? Double.NaN : location.getLatitude();
double longitude = location == null ? Double.NaN : location.getLongitude();
double latitude = location != null ? location.getLatitude() : Double.NaN;
double longitude = location != null ? location.getLongitude() : Double.NaN;
coordinateHorizontalLine.setVisibility(View.VISIBLE);
coordinateContainer.setVisibility(View.VISIBLE);
setCoordinateValue(activity, R.id.stats_latitude, R.string.stats_latitude, latitude);