forked from upstream-mirrors/OpenTracks
Fixing a few less common issues from the Market console.
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks;
|
package com.google.android.apps.mytracks;
|
||||||
|
|
||||||
|
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||||
import com.google.android.maps.GeoPoint;
|
import com.google.android.maps.GeoPoint;
|
||||||
@@ -33,6 +35,7 @@ import android.graphics.Point;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -71,7 +74,7 @@ public class MapOverlay extends Overlay {
|
|||||||
private GeoPoint lastReferencePoint;
|
private GeoPoint lastReferencePoint;
|
||||||
private Rect lastViewRect;
|
private Rect lastViewRect;
|
||||||
private Path lastPath;
|
private Path lastPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a pre-processed {@code Location} to speed up drawing.
|
* Represents a pre-processed {@code Location} to speed up drawing.
|
||||||
* This class is more like a data object and doesn't provide accessors.
|
* This class is more like a data object and doesn't provide accessors.
|
||||||
@@ -93,13 +96,13 @@ public class MapOverlay extends Overlay {
|
|||||||
*/
|
*/
|
||||||
public CachedLocation(Location location) {
|
public CachedLocation(Location location) {
|
||||||
this.valid = LocationUtils.isValidLocation(location);
|
this.valid = LocationUtils.isValidLocation(location);
|
||||||
this.geoPoint = valid ? LocationUtils.getGeoPoint(location) : null;
|
this.geoPoint = valid ? LocationUtils.getGeoPoint(location) : null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public MapOverlay(Context context) {
|
public MapOverlay(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
this.waypoints = new ArrayList<Waypoint>();
|
this.waypoints = new ArrayList<Waypoint>();
|
||||||
this.points = new ArrayList<CachedLocation>(1024);
|
this.points = new ArrayList<CachedLocation>(1024);
|
||||||
this.pendingPoints = new ArrayBlockingQueue<CachedLocation>(
|
this.pendingPoints = new ArrayBlockingQueue<CachedLocation>(
|
||||||
@@ -164,7 +167,7 @@ public class MapOverlay extends Overlay {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a location to the map overlay.
|
* Add a location to the map overlay.
|
||||||
*
|
*
|
||||||
* NOTE: This method doesn't take ownership of the given location, so it is
|
* NOTE: This method doesn't take ownership of the given location, so it is
|
||||||
* safe to reuse the same location while calling this method.
|
* safe to reuse the same location while calling this method.
|
||||||
*
|
*
|
||||||
@@ -203,7 +206,7 @@ public class MapOverlay extends Overlay {
|
|||||||
return waypoints.size();
|
return waypoints.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearPoints() {
|
public void clearPoints() {
|
||||||
synchronized (points) {
|
synchronized (points) {
|
||||||
points.clear();
|
points.clear();
|
||||||
@@ -235,10 +238,15 @@ public class MapOverlay extends Overlay {
|
|||||||
|
|
||||||
// It's safe to keep projection within a single draw operation.
|
// It's safe to keep projection within a single draw operation.
|
||||||
final Projection projection = getMapProjection(mapView);
|
final Projection projection = getMapProjection(mapView);
|
||||||
|
if (projection == null) {
|
||||||
|
Log.w(TAG, "No projection, unable to draw");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the current viewing window.
|
// Get the current viewing window.
|
||||||
if (trackDrawingEnabled) {
|
if (trackDrawingEnabled) {
|
||||||
Rect viewRect = getMapViewRect(mapView);
|
Rect viewRect = getMapViewRect(mapView);
|
||||||
|
|
||||||
// Draw the selected track:
|
// Draw the selected track:
|
||||||
drawTrack(canvas, projection, viewRect);
|
drawTrack(canvas, projection, viewRect);
|
||||||
|
|
||||||
@@ -249,12 +257,12 @@ public class MapOverlay extends Overlay {
|
|||||||
// Draw the current location
|
// Draw the current location
|
||||||
drawMyLocation(canvas, projection);
|
drawMyLocation(canvas, projection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visible for testing.
|
// Visible for testing.
|
||||||
Projection getMapProjection(MapView mapView) {
|
Projection getMapProjection(MapView mapView) {
|
||||||
return mapView.getProjection();
|
return mapView.getProjection();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visible for testing.
|
// Visible for testing.
|
||||||
Rect getMapViewRect(MapView mapView) {
|
Rect getMapViewRect(MapView mapView) {
|
||||||
int w = mapView.getLongitudeSpan();
|
int w = mapView.getLongitudeSpan();
|
||||||
@@ -263,12 +271,12 @@ public class MapOverlay extends Overlay {
|
|||||||
int cy = mapView.getMapCenter().getLatitudeE6();
|
int cy = mapView.getMapCenter().getLatitudeE6();
|
||||||
return new Rect(cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2);
|
return new Rect(cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visible for testing.
|
// Visible for testing.
|
||||||
Path newPath() {
|
Path newPath() {
|
||||||
return new Path();
|
return new Path();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visible for testing.
|
// Visible for testing.
|
||||||
Path getLastPath() {
|
Path getLastPath() {
|
||||||
return lastPath;
|
return lastPath;
|
||||||
@@ -304,9 +312,9 @@ public class MapOverlay extends Overlay {
|
|||||||
synchronized (points) {
|
synchronized (points) {
|
||||||
// Merge the pending points with the list of cached locations.
|
// Merge the pending points with the list of cached locations.
|
||||||
final GeoPoint referencePoint = projection.fromPixels(0, 0);
|
final GeoPoint referencePoint = projection.fromPixels(0, 0);
|
||||||
int newPoints = pendingPoints.drainTo(points);
|
int newPoints = pendingPoints.drainTo(points);
|
||||||
boolean newProjection = !viewRect.equals(lastViewRect) ||
|
boolean newProjection = !viewRect.equals(lastViewRect) ||
|
||||||
!referencePoint.equals(lastReferencePoint);
|
!referencePoint.equals(lastReferencePoint);
|
||||||
if (newPoints == 0 && lastPath != null && !newProjection) {
|
if (newPoints == 0 && lastPath != null && !newProjection) {
|
||||||
// No need to recreate path (same points and viewing area).
|
// No need to recreate path (same points and viewing area).
|
||||||
path = lastPath;
|
path = lastPath;
|
||||||
@@ -318,12 +326,12 @@ public class MapOverlay extends Overlay {
|
|||||||
} else if (lastPath != null && !newProjection) {
|
} else if (lastPath != null && !newProjection) {
|
||||||
// Incremental update of the path, without repositioning the view.
|
// Incremental update of the path, without repositioning the view.
|
||||||
path = lastPath;
|
path = lastPath;
|
||||||
updatePath(projection, viewRect, path, numPoints - newPoints);
|
updatePath(projection, viewRect, path, numPoints - newPoints);
|
||||||
} else {
|
} else {
|
||||||
// The view has changed so we have to start from scratch.
|
// The view has changed so we have to start from scratch.
|
||||||
path = newPath();
|
path = newPath();
|
||||||
path.incReserve(numPoints);
|
path.incReserve(numPoints);
|
||||||
updatePath(projection, viewRect, path, 0);
|
updatePath(projection, viewRect, path, 0);
|
||||||
}
|
}
|
||||||
lastPath = path;
|
lastPath = path;
|
||||||
}
|
}
|
||||||
@@ -344,7 +352,7 @@ public class MapOverlay extends Overlay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the "Start" marker.
|
// Draw the "Start" marker.
|
||||||
for (int i = 0; i < points.size(); ++i) {
|
for (int i = 0; i < points.size(); ++i) {
|
||||||
if (points.get(i).valid) {
|
if (points.get(i).valid) {
|
||||||
@@ -354,7 +362,7 @@ public class MapOverlay extends Overlay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePath(Projection projection, Rect viewRect, Path path,
|
private void updatePath(Projection projection, Rect viewRect, Path path,
|
||||||
int startLocationIdx) {
|
int startLocationIdx) {
|
||||||
// Whether to start a new segment on new valid and visible point.
|
// Whether to start a new segment on new valid and visible point.
|
||||||
@@ -370,7 +378,7 @@ public class MapOverlay extends Overlay {
|
|||||||
newSegment = true;
|
newSegment = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final GeoPoint geoPoint = loc.geoPoint;
|
final GeoPoint geoPoint = loc.geoPoint;
|
||||||
// Check if this breaks the existing segment.
|
// Check if this breaks the existing segment.
|
||||||
boolean visible = alwaysVisible || viewRect.contains(
|
boolean visible = alwaysVisible || viewRect.contains(
|
||||||
@@ -380,7 +388,7 @@ public class MapOverlay extends Overlay {
|
|||||||
newSegment = true;
|
newSegment = true;
|
||||||
}
|
}
|
||||||
lastVisible = visible;
|
lastVisible = visible;
|
||||||
|
|
||||||
// Either move to beginning of a new segment or continue the old one.
|
// Either move to beginning of a new segment or continue the old one.
|
||||||
projection.toPixels(geoPoint, pt);
|
projection.toPixels(geoPoint, pt);
|
||||||
if (newSegment) {
|
if (newSegment) {
|
||||||
@@ -391,7 +399,7 @@ public class MapOverlay extends Overlay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visible for testing.
|
// Visible for testing.
|
||||||
Point drawElement(Canvas canvas, Projection projection, GeoPoint geoPoint,
|
Point drawElement(Canvas canvas, Projection projection, GeoPoint geoPoint,
|
||||||
Drawable element, int offsetX, int offsetY) {
|
Drawable element, int offsetX, int offsetY) {
|
||||||
|
|||||||
@@ -989,6 +989,7 @@ public class TrackDataHub {
|
|||||||
// no matter how many points we get in the newest batch, we'll never exceed
|
// no matter how many points we get in the newest batch, we'll never exceed
|
||||||
// MAX_DISPLAYED_TRACK_POINTS = 2 * TARGET_DISPLAYED_TRACK_POINTS before resampling.
|
// MAX_DISPLAYED_TRACK_POINTS = 2 * TARGET_DISPLAYED_TRACK_POINTS before resampling.
|
||||||
long numTotalPoints = lastStoredLocationId - localFirstSeenLocationId;
|
long numTotalPoints = lastStoredLocationId - localFirstSeenLocationId;
|
||||||
|
numTotalPoints = Math.max(0L, numTotalPoints);
|
||||||
pointSamplingFrequency = (int) (1 + numTotalPoints / targetNumPoints);
|
pointSamplingFrequency = (int) (1 + numTotalPoints / targetNumPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011 Google Inc.
|
* Copyright 2011 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* 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
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
* the License at
|
* the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
@@ -59,7 +59,8 @@ public class FroyoStatusAnnouncerTask extends StatusAnnouncerTask {
|
|||||||
@Override
|
@Override
|
||||||
protected void onTtsInit(int status) {
|
protected void onTtsInit(int status) {
|
||||||
super.onTtsInit(status);
|
super.onTtsInit(status);
|
||||||
if (status == TextToSpeech.SUCCESS) {
|
|
||||||
|
if (status == TextToSpeech.SUCCESS && tts != null) {
|
||||||
tts.setOnUtteranceCompletedListener(utteranceListener);
|
tts.setOnUtteranceCompletedListener(utteranceListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user