diff --git a/MyTracks/src/com/dsi/ant/AntInterface.java b/MyTracks/src/com/dsi/ant/AntInterface.java index 0e425e57d..5fd5ee345 100644 --- a/MyTracks/src/com/dsi/ant/AntInterface.java +++ b/MyTracks/src/com/dsi/ant/AntInterface.java @@ -61,10 +61,10 @@ public class AntInterface { private static Object INSTANCE_LOCK = new Object(); /** The context to use. */ - private static Context sContext = null; + private Context sContext = null; /** Listens to changes to service connection status. */ - private static ServiceListener sServiceListener; + private ServiceListener sServiceListener; /** Is the ANT Radio Proxy Service connected. */ private static boolean sServiceConnected = false; @@ -210,7 +210,7 @@ public class AntInterface { /** * Class for interacting with the ANT interface. */ - private static ServiceConnection sIAntConnection = new ServiceConnection() { + private final ServiceConnection sIAntConnection = new ServiceConnection() { public void onServiceConnected(ComponentName pClassName, IBinder pService) { // This is called when the connection with the service has been // established, giving us the service object we can use to @@ -1223,7 +1223,7 @@ public class AntInterface { */ public boolean requestForceClaimInterface(String appName) throws AntInterfaceException { - if((null == appName) || ("" == appName)) + if((null == appName) || ("".equals(appName))) { throw new IllegalArgumentException(); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java index cb385f35c..3e2767bf2 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java @@ -19,9 +19,9 @@ import java.util.List; /** * Activity for viewing the combined statistics for all the recorded tracks. - * + * * Other features to add - menu items to change setings. - * + * * @author Fergus Nelson */ public class AggregatedStatsActivity extends Activity implements @@ -43,7 +43,7 @@ public class AggregatedStatsActivity extends Activity implements Log.d(Constants.TAG, "StatsActivity: onSharedPreferences changed " + key); if (key != null) { - if (key.equals(R.string.metric_units_key)) { + if (key.equals(getString(R.string.metric_units_key))) { metricUnits = sharedPreferences.getBoolean( getString(R.string.metric_units_key), true); utils.setMetricUnits(metricUnits); @@ -86,8 +86,8 @@ public class AggregatedStatsActivity extends Activity implements } /** - * 1. Reads tracks from the db - * 2. Merges the trip stats from the tracks + * 1. Reads tracks from the db + * 2. Merges the trip stats from the tracks * 3. Updates the view */ private void loadAggregatedStats() { diff --git a/MyTracks/src/com/google/android/apps/mytracks/ChartView.java b/MyTracks/src/com/google/android/apps/mytracks/ChartView.java index 0a6e665ad..aeb635b38 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/ChartView.java +++ b/MyTracks/src/com/google/android/apps/mytracks/ChartView.java @@ -49,6 +49,7 @@ import java.util.ArrayList; * @author Leif Hendrik Wilden */ public class ChartView extends View { + private static final int MIN_ZOOM_LEVEL = 1; /* * Scrolling logic: @@ -62,7 +63,6 @@ public class ChartView extends View { * Zoom logic: */ private int zoomLevel = 1; - private final int minZoomLevel = 1; private int maxZoomLevel = 10; private static final int MAX_INTERVALS = 5; @@ -333,7 +333,7 @@ public class ChartView extends View { * @return true if the chart can be zoomed out */ public boolean canZoomOut() { - return zoomLevel > minZoomLevel; + return zoomLevel > MIN_ZOOM_LEVEL; } /** 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 eeb769b88..8fd6f2e41 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/SendToFusionTables.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/SendToFusionTables.java @@ -49,6 +49,7 @@ import android.util.Log; import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URLEncoder; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -420,10 +421,10 @@ public class SendToFusionTables implements Runnable { * @return the kml. */ private String getKmlPoint(Location location) { - StringBuilder builder = new StringBuilder(""); - appendCoordinate(location, builder); - builder.append(""); - return builder.toString(); + StringBuilder builder = new StringBuilder(""); + appendCoordinate(location, builder); + builder.append(""); + return builder.toString(); } /** @@ -599,7 +600,7 @@ public class SendToFusionTables implements Runnable { // I am leaving the number of waypoints very high which should not be a // problem because we don't try to load them into objects all at the // same time. - boolean success = true; + boolean success = true; Cursor c = null; try { c = providerUtils.getWaypointsCursor( @@ -613,9 +614,9 @@ public class SendToFusionTables implements Runnable { Waypoint wpt = providerUtils.createWaypoint(c); Log.d(Constants.TAG, "SendToFusionTables: Creating waypoint."); success = createNewPoint(wpt.getName(), wpt.getDescription(), wpt.getLocation(), - MARKER_TYPE_WAYPOINT); + MARKER_TYPE_WAYPOINT); if (!success) { - break; + break; } } } @@ -681,8 +682,8 @@ public class SendToFusionTables implements Runnable { boolean success = response.isSuccessStatusCode; if (success) { byte[] result = new byte[1024]; - response.getContent().read(result); - String s = Strings.fromBytesUtf8(result); + int read = response.getContent().read(result); + String s = new String(result, 0, read, Charset.forName("UTF8")); String[] lines = s.split(Strings.LINE_SEPARATOR); if (lines[0].equals("tableid")) { tableId = lines[1]; 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 d74a9c8f4..7ed50c8c3 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 @@ -195,7 +195,7 @@ class TrackWriterImpl implements TrackWriter { directory, track.getName(), writer.getExtension()); if (fileName == null) { Log.e(Constants.TAG, - "Unable to get a unique filename for " + fileName); + "Unable to get a unique filename for " + track.getName()); return false; } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/gdata/AndroidGDataClient.java b/MyTracks/src/com/google/android/apps/mytracks/io/gdata/AndroidGDataClient.java index 7b037bb75..449056870 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/gdata/AndroidGDataClient.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/gdata/AndroidGDataClient.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 @@ -137,7 +137,7 @@ public class AndroidGDataClient implements GDataClient { /* * (non-Javadoc) - * + * * @see GDataClient#encodeUri(java.lang.String) */ public String encodeUri(String uri) { @@ -155,7 +155,7 @@ public class AndroidGDataClient implements GDataClient { /* * (non-Javadoc) - * + * * @see com.google.wireless.gdata.client.GDataClient#createQueryParams() */ public QueryParams createQueryParams() { @@ -273,7 +273,7 @@ public class AndroidGDataClient implements GDataClient { String errorMessage = null; HttpEntity entity = response.getEntity(); try { - if (response != null && entity != null) { + if (entity != null) { InputStream in = entity.getContent(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[8192]; @@ -329,7 +329,7 @@ public class AndroidGDataClient implements GDataClient { /* * (non-Javadoc) - * + * * @see GDataClient#getFeedAsStream(java.lang.String, java.lang.String) */ public InputStream getFeedAsStream(String feedUrl, String authToken) @@ -358,7 +358,7 @@ public class AndroidGDataClient implements GDataClient { /* * (non-Javadoc) - * + * * @see GDataClient#createEntry */ public InputStream createEntry(String feedUrl, String authToken, @@ -377,7 +377,7 @@ public class AndroidGDataClient implements GDataClient { /* * (non-Javadoc) - * + * * @see GDataClient#updateEntry */ public InputStream updateEntry(String editUri, String authToken, @@ -395,7 +395,7 @@ public class AndroidGDataClient implements GDataClient { /* * (non-Javadoc) - * + * * @see GDataClient#deleteEntry */ public void deleteEntry(String editUri, String authToken) 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 2cd24d641..27633e064 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,7 +3,6 @@ package com.google.android.apps.mytracks.io.mymaps; import com.google.android.maps.GeoPoint; -import java.io.Serializable; import java.util.Vector; /** @@ -12,7 +11,7 @@ import java.util.Vector; * {@link MyMapsFeatureMetadata} object so that it can be more efficiently * transmitted to other activities. */ -class MyMapsFeature implements Serializable { +class MyMapsFeature { private static final long serialVersionUID = 8439035544430497236L; @@ -102,7 +101,7 @@ class MyMapsFeature implements Serializable { * * @param description The new description of this feature */ - public synchronized void setDescription(String description) { + public void setDescription(String description) { featureInfo.setDescription(description); } @@ -196,7 +195,7 @@ class MyMapsFeature implements Serializable { * * @param title The new title of this feature */ - public synchronized void setTitle(String title) { + public void setTitle(String title) { featureInfo.setTitle(title); } @@ -207,7 +206,7 @@ class MyMapsFeature implements Serializable { * @param type The new type of the feature. That type must be one of * {@link #MARKER}, {@link #LINE}, or {@link #SHAPE} */ - public synchronized void setType(int type) { + public void setType(int type) { featureInfo.setType(type); } @@ -217,7 +216,7 @@ class MyMapsFeature implements Serializable { * * @param color The new ARGB color of this feature */ - public synchronized void setColor(int color) { + public void setColor(int color) { featureInfo.setColor(color); } @@ -227,7 +226,7 @@ class MyMapsFeature implements Serializable { * * @param url The new icon url of the feature */ - public synchronized void setIconUrl(String url) { + public void setIconUrl(String url) { featureInfo.setIconUrl(url); } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsFeatureMetadata.java b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsFeatureMetadata.java index 7e94d24b9..acb1486c7 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsFeatureMetadata.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsFeatureMetadata.java @@ -82,6 +82,6 @@ class MyMapsFeatureMetadata { } public void setIconUrl(String url) { - iconUrl = new String(url); + iconUrl = url; } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsMapMetadata.java b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsMapMetadata.java index 4ffb459b8..eab3b657d 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsMapMetadata.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/MyMapsMapMetadata.java @@ -23,7 +23,7 @@ class MyMapsMapMetadata { } public void setTitle(String title) { - this.title = new String(title); + this.title = title; } public String getDescription() { @@ -31,7 +31,7 @@ class MyMapsMapMetadata { } public void setDescription(String description) { - this.description = new String(description); + this.description = description; } public boolean getSearchable() { @@ -47,6 +47,6 @@ class MyMapsMapMetadata { } public void setGDataEditUri(String editUri) { - this.gdataEditUri = new String(editUri); + this.gdataEditUri = editUri; } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/XmlMapsGDataParserFactory.java b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/XmlMapsGDataParserFactory.java index 15c0a884e..3bba20e56 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/XmlMapsGDataParserFactory.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/XmlMapsGDataParserFactory.java @@ -85,8 +85,8 @@ class XmlMapsGDataParserFactory implements GDataParserFactory { @Override public GDataSerializer createSerializer(Entry en) { - if (en.getClass() == MapFeatureEntry.class) { - return new XmlMapsGDataSerializer(xmlFactory, en); + if (en instanceof MapFeatureEntry) { + return new XmlMapsGDataSerializer(xmlFactory, (MapFeatureEntry) en); } else { return new XmlEntryGDataSerializer(xmlFactory, en); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/XmlMapsGDataSerializer.java b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/XmlMapsGDataSerializer.java index 80598788d..3251f2624 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/XmlMapsGDataSerializer.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/mymaps/XmlMapsGDataSerializer.java @@ -1,7 +1,6 @@ // Copyright 2010 Google Inc. All Rights Reserved. package com.google.android.apps.mytracks.io.mymaps; -import com.google.wireless.gdata.data.Entry; import com.google.wireless.gdata.data.StringUtils; import com.google.wireless.gdata.parser.ParseException; import com.google.wireless.gdata.parser.xml.XmlGDataParser; @@ -10,14 +9,14 @@ import com.google.wireless.gdata.serializer.xml.XmlEntryGDataSerializer; import android.util.Log; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Map; +import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlSerializer; + /** * Serializer of maps data for GData. */ @@ -29,11 +28,11 @@ class XmlMapsGDataSerializer extends XmlEntryGDataSerializer { private XmlParserFactory factory; private OutputStream stream; - public XmlMapsGDataSerializer(XmlParserFactory factory, Entry entry) { + public XmlMapsGDataSerializer(XmlParserFactory factory, MapFeatureEntry entry) { super(factory, entry); this.factory = factory; - this.entry = (MapFeatureEntry) entry; + this.entry = entry; } @Override diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java index 1a1767241..d3dc3c4c9 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -15,20 +15,20 @@ */ package com.google.android.apps.mytracks.services; -import static com.google.android.apps.mytracks.Constants.TAG; import static com.google.android.apps.mytracks.Constants.RESUME_TRACK_EXTRA_NAME; +import static com.google.android.apps.mytracks.Constants.TAG; -import com.google.android.apps.mytracks.MyTracks; import com.google.android.apps.mytracks.Constants; +import com.google.android.apps.mytracks.MyTracks; import com.google.android.apps.mytracks.content.MyTracksLocation; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Sensor; +import com.google.android.apps.mytracks.content.Sensor.SensorDataSet; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.WaypointCreationRequest; import com.google.android.apps.mytracks.content.WaypointsColumns; -import com.google.android.apps.mytracks.content.Sensor.SensorDataSet; import com.google.android.apps.mytracks.services.sensors.SensorManager; import com.google.android.apps.mytracks.services.sensors.SensorManagerFactory; import com.google.android.apps.mytracks.services.tasks.PeriodicTaskExecutor; @@ -56,7 +56,6 @@ import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.net.Uri; -import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -570,7 +569,6 @@ public class TrackRecordingService extends Service implements LocationListener { recordingTrackId)) { return; } - lastRecordedLocationId++; } } else { Log.d(TAG, @@ -845,7 +843,7 @@ public class TrackRecordingService extends Service implements LocationListener { "shouldResumeTrack: lastModified = " + lastModified + ", autoResumeTrackTimeout: " + autoResumeTrackTimeout); return lastModified > 0 && System.currentTimeMillis() - lastModified <= - autoResumeTrackTimeout * 60 * 1000; + autoResumeTrackTimeout * 60L * 1000L; } public boolean isRecording() { diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/tasks/PeriodicTaskExecutor.java b/MyTracks/src/com/google/android/apps/mytracks/services/tasks/PeriodicTaskExecutor.java index f307e4741..74dfaf641 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/tasks/PeriodicTaskExecutor.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/tasks/PeriodicTaskExecutor.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 @@ -67,7 +67,7 @@ public class PeriodicTaskExecutor { if (!service.isRecording()) { return; } - + if (!isTimeFrequency()) { if (timerExecutor != null) { timerExecutor.shutdown(); @@ -77,7 +77,7 @@ public class PeriodicTaskExecutor { if (taskFrequency == 0) { return; } - + // Try to make the task. task = factory.create(service); // Returning null is ok. @@ -90,7 +90,7 @@ public class PeriodicTaskExecutor { if (timerExecutor == null) { timerExecutor = new TimerTaskExecutor(task, service); } - timerExecutor.scheduleTask(taskFrequency * 60000); + timerExecutor.scheduleTask(taskFrequency * 60000L); } else { // For distance based splits. calculateNextTaskDistance(); @@ -119,7 +119,7 @@ public class PeriodicTaskExecutor { if (!service.isRecording() || task == null) { return; } - + if (!isDistanceFrequency()) { nextTaskDistance = Double.MAX_VALUE; Log.d(TAG, "SplitManager: Distance splits disabled."); diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/ResourceUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/ResourceUtils.java index 884f4b95a..1d9603919 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/ResourceUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/ResourceUtils.java @@ -1,12 +1,12 @@ /* * Copyright 2008 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 @@ -57,10 +57,11 @@ public class ResourceUtils { public static void readBinaryFileToOutputStream( Context activity, int id, OutputStream os) { BufferedInputStream in = null; + BufferedOutputStream out = null; try { in = new BufferedInputStream( activity.getResources().openRawResource(id)); - BufferedOutputStream out = new BufferedOutputStream(os); + out = new BufferedOutputStream(os); int b; while ((b = in.read()) != -1) { out.write(b); @@ -76,6 +77,14 @@ public class ResourceUtils { // Ignore } } + + if (out != null) { + try { + out.close(); + } catch (IOException e) { + // Ignore + } + } } } diff --git a/SignalStrengthSampler/src/com/google/android/apps/mytracks/signalstrength/SignalStrengthService.java b/SignalStrengthSampler/src/com/google/android/apps/mytracks/signalstrength/SignalStrengthService.java index 8a9cf4cd3..70d417368 100644 --- a/SignalStrengthSampler/src/com/google/android/apps/mytracks/signalstrength/SignalStrengthService.java +++ b/SignalStrengthSampler/src/com/google/android/apps/mytracks/signalstrength/SignalStrengthService.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,10 +15,10 @@ */ package com.google.android.apps.mytracks.signalstrength; -import static com.google.android.apps.mytracks.signalstrength.SignalStrengthConstants.*; +import static com.google.android.apps.mytracks.signalstrength.SignalStrengthConstants.START_SAMPLING; +import static com.google.android.apps.mytracks.signalstrength.SignalStrengthConstants.STOP_SAMPLING; +import static com.google.android.apps.mytracks.signalstrength.SignalStrengthConstants.TAG; -import com.google.android.apps.mytracks.content.MyTracksProviderUtils; -import com.google.android.apps.mytracks.content.MyTracksProviderUtilsImpl; import com.google.android.apps.mytracks.content.WaypointCreationRequest; import com.google.android.apps.mytracks.services.ITrackRecordingService; import com.google.android.apps.mytracks.signalstrength.SignalStrengthListener.SignalStrengthCallback; @@ -206,7 +206,7 @@ public class SignalStrengthService extends Service // Tell the user we've stopped Toast.makeText(this, R.string.stopped_sampling, Toast.LENGTH_SHORT).show(); - + // Stop stopSelf(); }