diff --git a/MyTracks/src/com/google/android/apps/mytracks/ChartView.java b/MyTracks/src/com/google/android/apps/mytracks/ChartView.java index aeb635b38..e9e308508 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/ChartView.java +++ b/MyTracks/src/com/google/android/apps/mytracks/ChartView.java @@ -593,7 +593,7 @@ public class ChartView extends View { final float x = getWaypointX(waypoint); c.drawLine(x, h - bottomBorder, x, topBorder, gridPaint); - c.translate(x - markerWidth / 2, markerHeight); + c.translate(x - (float) markerWidth / 2.0f, (float) markerHeight); if (waypoints.get(i).getType() == Waypoint.TYPE_STATISTICS) { statsMarker.draw(c); } else { diff --git a/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java b/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java index c6e8acfa3..349114e62 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. * @@ -172,14 +175,18 @@ public class MapOverlay extends Overlay { */ public void addLocation(Location l) { // Queue up in the pending queue until it's merged with {@code #points}. - pendingPoints.offer(new CachedLocation(l)); + if (!pendingPoints.offer(new CachedLocation(l))) { + Log.e(TAG, "Unable to add pending points"); + } } /** * Adds a segment split to the map overlay. */ public void addSegmentSplit() { - pendingPoints.offer(new CachedLocation()); + if (!pendingPoints.offer(new CachedLocation())) { + Log.e(TAG, "Unable to add pending points"); + } } public void addWaypoint(Waypoint wpt) { @@ -203,7 +210,7 @@ public class MapOverlay extends Overlay { return waypoints.size(); } } - + public void clearPoints() { synchronized (points) { points.clear(); @@ -238,7 +245,7 @@ public class MapOverlay extends Overlay { // Get the current viewing window. if (trackDrawingEnabled) { Rect viewRect = getMapViewRect(mapView); - + // Draw the selected track: drawTrack(canvas, projection, viewRect); @@ -249,12 +256,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 +270,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 +311,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 +325,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 +351,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 +361,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 +377,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 +387,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 +398,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/io/SendToFusionTables.java b/MyTracks/src/com/google/android/apps/mytracks/io/SendToFusionTables.java index 5dbd57c6b..87220185f 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/SendToFusionTables.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/SendToFusionTables.java @@ -644,7 +644,7 @@ public class SendToFusionTables implements Runnable { // to fit the completion percentage range alloted to track data upload. double totalPercentage = (totalLocationsRead + totalLocationsPrepared + totalLocationsUploaded) - / (totalLocations * 3); + / (totalLocations * 3.0); double scaledPercentage = totalPercentage * (PROGRESS_UPLOAD_DATA_MAX - PROGRESS_UPLOAD_DATA_MIN) + PROGRESS_UPLOAD_DATA_MIN; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/backup/ExternalFileBackup.java b/MyTracks/src/com/google/android/apps/mytracks/io/backup/ExternalFileBackup.java index 1fbcf9485..16f18d0df 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/backup/ExternalFileBackup.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/backup/ExternalFileBackup.java @@ -15,6 +15,8 @@ */ package com.google.android.apps.mytracks.io.backup; +import static com.google.android.apps.mytracks.Constants.TAG; + import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.content.TrackPointsColumns; import com.google.android.apps.mytracks.content.TracksColumns; @@ -205,7 +207,9 @@ class ExternalFileBackup { } catch (IOException e) { // We tried to delete the partially created file, but do nothing // if that also fails. - outputFile.delete(); + if (!outputFile.delete()) { + Log.w(TAG, "Failed to delete file " + outputFile.getAbsolutePath()); + } throw e; } finally { diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/TempFileCleaner.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/TempFileCleaner.java index 6f590342b..ec200f823 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/TempFileCleaner.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/TempFileCleaner.java @@ -1,12 +1,12 @@ /* * Copyright 2010 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 @@ -15,7 +15,10 @@ */ package com.google.android.apps.mytracks.io.file; +import static com.google.android.apps.mytracks.Constants.TAG; + import android.os.Environment; +import android.util.Log; import java.io.File; @@ -24,18 +27,18 @@ import java.io.File; * @author Sandor Dornbush */ public class TempFileCleaner { - + private long currentTimeMillis; public static void clean() { (new TempFileCleaner(System.currentTimeMillis())).cleanImpl(); } - + // @VisibleForTesting TempFileCleaner(long time) { currentTimeMillis = time; } - + private void cleanImpl() { if (!Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { @@ -64,7 +67,9 @@ public class TempFileCleaner { long oldest = currentTimeMillis - 1000 * 3600; for (File f : dir.listFiles()) { if (f.lastModified() < oldest) { - f.delete(); + if (!f.delete()) { + Log.w(TAG, "Failed to delete file " + f.getAbsolutePath()); + } count++; } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriterImpl.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriterImpl.java index 7ed50c8c3..dd18b5a11 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriterImpl.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriterImpl.java @@ -15,6 +15,8 @@ */ package com.google.android.apps.mytracks.io.file; +import static com.google.android.apps.mytracks.Constants.TAG; + import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.content.MyTracksLocation; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; @@ -120,7 +122,9 @@ class TrackWriterImpl implements TrackWriter { } catch (InterruptedException e) { Log.i(Constants.TAG, "The track write was interrupted"); if (file != null) { - file.delete(); + if (!file.delete()) { + Log.w(TAG, "Failed to delete file " + file.getAbsolutePath()); + } } success = false; errorMessage = R.string.error_operation_cancelled; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsFeature.java b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsFeature.java index 27633e064..87aa2f236 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsFeature.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsFeature.java @@ -3,6 +3,7 @@ package com.google.android.apps.mytracks.io.mymaps; import com.google.android.maps.GeoPoint; +import java.util.Random; import java.util.Vector; /** @@ -48,6 +49,8 @@ class MyMapsFeature { /** The metadata of this feature in a format efficient for transmission. */ private MyMapsFeatureMetadata featureInfo = new MyMapsFeatureMetadata(); + private final Random random = new Random(); + /** * Initializes a valid but empty feature. It will default to a * {@link #MARKER} with a blue placemark with a dot as an icon at the @@ -61,7 +64,7 @@ class MyMapsFeature { * * @param point The new point to add */ - public synchronized void addPoint(GeoPoint point) { + public void addPoint(GeoPoint point) { latitudeE6.add(point.getLatitudeE6()); longitudeE6.add(point.getLongitudeE6()); } @@ -70,10 +73,10 @@ class MyMapsFeature { * Generates a new local id for this feature based on the current time and * a random number. */ - public synchronized void generateAndroidId() { - Long time = System.currentTimeMillis(); - Integer random = (int) (Math.random() * 10000); - androidId = time.toString() + "." + random.toString(); + void generateAndroidId() { + long time = System.currentTimeMillis(); + int rand = random.nextInt(10000); + androidId = time + "." + rand; } /** @@ -81,7 +84,7 @@ class MyMapsFeature { * * @return The local id for this feature */ - public String getAndroidId() { + String getAndroidId() { return androidId; } diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/SensorManagerFactory.java b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/SensorManagerFactory.java index 43e0a4be0..7c468be2c 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/SensorManagerFactory.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/SensorManagerFactory.java @@ -1,12 +1,12 @@ /* * Copyright 2009 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 @@ -45,7 +45,9 @@ public class SensorManagerFactory { if (prefs == null) { return null; } - + + context = context.getApplicationContext(); + String sensor = prefs.getString(context.getString(R.string.sensor_type_key), null); Log.i(Constants.TAG, "Creating sensor of type: " + sensor);