From 0afdeb9bcc11e620cd11142aee43c093d3b8f0d8 Mon Sep 17 00:00:00 2001 From: Rodrigo Damazio Date: Thu, 9 Jun 2011 22:22:57 -0300 Subject: [PATCH] Fixing a few less common issues from the Market console. --- .../android/apps/mytracks/MapOverlay.java | 46 +++++++++++-------- .../apps/mytracks/content/TrackDataHub.java | 1 + .../tasks/FroyoStatusAnnouncerTask.java | 9 ++-- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java b/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java index c6e8acfa3..403b1abe5 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java @@ -15,6 +15,8 @@ */ 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.util.LocationUtils; import com.google.android.maps.GeoPoint; @@ -33,6 +35,7 @@ import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.location.Location; +import android.util.Log; import java.util.ArrayList; import java.util.List; @@ -71,7 +74,7 @@ public class MapOverlay extends Overlay { private GeoPoint lastReferencePoint; private Rect lastViewRect; private Path lastPath; - + /** * Represents a pre-processed {@code Location} to speed up drawing. * 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) { this.valid = LocationUtils.isValidLocation(location); - this.geoPoint = valid ? LocationUtils.getGeoPoint(location) : null; + this.geoPoint = valid ? LocationUtils.getGeoPoint(location) : null; } }; public MapOverlay(Context context) { this.context = context; - + this.waypoints = new ArrayList(); this.points = new ArrayList(1024); this.pendingPoints = new ArrayBlockingQueue( @@ -164,7 +167,7 @@ public class MapOverlay extends Overlay { /** * Add a location to the map overlay. - * + * * NOTE: This method doesn't take ownership of the given location, so it is * safe to reuse the same location while calling this method. * @@ -203,7 +206,7 @@ public class MapOverlay extends Overlay { return waypoints.size(); } } - + public void clearPoints() { synchronized (points) { points.clear(); @@ -235,10 +238,15 @@ public class MapOverlay extends Overlay { // It's safe to keep projection within a single draw operation. final Projection projection = getMapProjection(mapView); + if (projection == null) { + Log.w(TAG, "No projection, unable to draw"); + return; + } + // Get the current viewing window. if (trackDrawingEnabled) { Rect viewRect = getMapViewRect(mapView); - + // Draw the selected track: drawTrack(canvas, projection, viewRect); @@ -249,12 +257,12 @@ public class MapOverlay extends Overlay { // Draw the current location drawMyLocation(canvas, projection); } - + // Visible for testing. Projection getMapProjection(MapView mapView) { return mapView.getProjection(); } - + // Visible for testing. Rect getMapViewRect(MapView mapView) { int w = mapView.getLongitudeSpan(); @@ -263,12 +271,12 @@ public class MapOverlay extends Overlay { int cy = mapView.getMapCenter().getLatitudeE6(); return new Rect(cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2); } - + // Visible for testing. Path newPath() { return new Path(); } - + // Visible for testing. Path getLastPath() { return lastPath; @@ -304,9 +312,9 @@ public class MapOverlay extends Overlay { synchronized (points) { // Merge the pending points with the list of cached locations. final GeoPoint referencePoint = projection.fromPixels(0, 0); - int newPoints = pendingPoints.drainTo(points); + int newPoints = pendingPoints.drainTo(points); boolean newProjection = !viewRect.equals(lastViewRect) || - !referencePoint.equals(lastReferencePoint); + !referencePoint.equals(lastReferencePoint); if (newPoints == 0 && lastPath != null && !newProjection) { // No need to recreate path (same points and viewing area). path = lastPath; @@ -318,12 +326,12 @@ public class MapOverlay extends Overlay { } else if (lastPath != null && !newProjection) { // Incremental update of the path, without repositioning the view. path = lastPath; - updatePath(projection, viewRect, path, numPoints - newPoints); + updatePath(projection, viewRect, path, numPoints - newPoints); } else { // The view has changed so we have to start from scratch. path = newPath(); path.incReserve(numPoints); - updatePath(projection, viewRect, path, 0); + updatePath(projection, viewRect, path, 0); } lastPath = path; } @@ -344,7 +352,7 @@ public class MapOverlay extends Overlay { } } } - + // Draw the "Start" marker. for (int i = 0; i < points.size(); ++i) { if (points.get(i).valid) { @@ -354,7 +362,7 @@ public class MapOverlay extends Overlay { } } } - + private void updatePath(Projection projection, Rect viewRect, Path path, int startLocationIdx) { // Whether to start a new segment on new valid and visible point. @@ -370,7 +378,7 @@ public class MapOverlay extends Overlay { newSegment = true; continue; } - + final GeoPoint geoPoint = loc.geoPoint; // Check if this breaks the existing segment. boolean visible = alwaysVisible || viewRect.contains( @@ -380,7 +388,7 @@ public class MapOverlay extends Overlay { newSegment = true; } lastVisible = visible; - + // Either move to beginning of a new segment or continue the old one. projection.toPixels(geoPoint, pt); if (newSegment) { @@ -391,7 +399,7 @@ public class MapOverlay extends Overlay { } } } - + // Visible for testing. Point drawElement(Canvas canvas, Projection projection, GeoPoint geoPoint, Drawable element, int offsetX, int offsetY) { diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java b/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java index b5bf78e61..5ee3e7b5d 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java +++ b/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java @@ -989,6 +989,7 @@ public class TrackDataHub { // 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. long numTotalPoints = lastStoredLocationId - localFirstSeenLocationId; + numTotalPoints = Math.max(0L, numTotalPoints); pointSamplingFrequency = (int) (1 + numTotalPoints / targetNumPoints); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/tasks/FroyoStatusAnnouncerTask.java b/MyTracks/src/com/google/android/apps/mytracks/services/tasks/FroyoStatusAnnouncerTask.java index 5bdec230a..6438537c4 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/tasks/FroyoStatusAnnouncerTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/tasks/FroyoStatusAnnouncerTask.java @@ -1,12 +1,12 @@ /* * Copyright 2011 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 @@ -59,7 +59,8 @@ public class FroyoStatusAnnouncerTask extends StatusAnnouncerTask { @Override protected void onTtsInit(int status) { super.onTtsInit(status); - if (status == TextToSpeech.SUCCESS) { + + if (status == TextToSpeech.SUCCESS && tts != null) { tts.setOnUtteranceCompletedListener(utteranceListener); } }