Style and warning fixes.

This commit is contained in:
Rodrigo Damazio
2011-07-12 20:42:25 -03:00
parent e32ff7116d
commit bccfbaa03b
33 changed files with 185 additions and 193 deletions
@@ -463,6 +463,7 @@ public class ChartActivity extends Activity implements TrackDataListener {
return true; // Reload data return true; // Reload data
} }
@SuppressWarnings("hiding")
@Override @Override
public boolean onReportSpeedChanged(boolean reportSpeed) { public boolean onReportSpeedChanged(boolean reportSpeed) {
boolean changed = reportSpeed != this.reportSpeed; boolean changed = reportSpeed != this.reportSpeed;
@@ -1,12 +1,12 @@
/* /*
* Copyright 2008 Google Inc. * Copyright 2008 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
@@ -56,8 +56,8 @@ public class DeleteAllTracks extends Handler {
builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setPositiveButton(context.getString(R.string.yes), builder.setPositiveButton(context.getString(R.string.yes),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) { public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss(); dialogInterface.dismiss();
Log.w(Constants.TAG, "deleting all!"); Log.w(Constants.TAG, "deleting all!");
MyTracksProviderUtils.Factory.get(context).deleteAllTracks(); MyTracksProviderUtils.Factory.get(context).deleteAllTracks();
SharedPreferences prefs = SharedPreferences prefs =
@@ -74,8 +74,8 @@ public class DeleteAllTracks extends Handler {
}); });
builder.setNegativeButton(context.getString(R.string.no), builder.setNegativeButton(context.getString(R.string.no),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) { public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss(); dialogInterface.dismiss();
} }
}); });
dialog = builder.create(); dialog = builder.create();
@@ -386,8 +386,8 @@ public class MyTracks extends TabActivity implements OnTouchListener {
builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setPositiveButton(getString(R.string.yes), builder.setPositiveButton(getString(R.string.yes),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) { public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss(); dialogInterface.dismiss();
providerUtils.deleteTrack(trackId); providerUtils.deleteTrack(trackId);
if (trackId == dataHub.getSelectedTrackId()) { if (trackId == dataHub.getSelectedTrackId()) {
dataHub.unloadCurrentTrack(); dataHub.unloadCurrentTrack();
@@ -395,8 +395,8 @@ public class MyTracks extends TabActivity implements OnTouchListener {
}}); }});
builder.setNegativeButton(getString(R.string.no), builder.setNegativeButton(getString(R.string.no),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) { public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss(); dialogInterface.dismiss();
} }
}); });
dialog = builder.create(); dialog = builder.create();
@@ -340,7 +340,7 @@ public class SettingsActivity extends PreferenceActivity {
.setPositiveButton(android.R.string.ok, .setPositiveButton(android.R.string.ok,
new OnClickListener() { new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int button) { public void onClick(DialogInterface dialogInterface, int button) {
onResetPreferencesConfirmed(); onResetPreferencesConfirmed();
} }
}) })
@@ -59,7 +59,7 @@ public class WaypointsList extends ListActivity
private int contextPosition = -1; private int contextPosition = -1;
private long trackId = -1; private long trackId = -1;
private long waypointId = -1; private long selectedWaypointId = -1;
private ListView listView = null; private ListView listView = null;
private Button insertWaypointButton = null; private Button insertWaypointButton = null;
private Button insertStatisticsButton = null; private Button insertStatisticsButton = null;
@@ -77,7 +77,7 @@ public class WaypointsList extends ListActivity
AdapterView.AdapterContextMenuInfo info = AdapterView.AdapterContextMenuInfo info =
(AdapterView.AdapterContextMenuInfo) menuInfo; (AdapterView.AdapterContextMenuInfo) menuInfo;
contextPosition = info.position; contextPosition = info.position;
waypointId = WaypointsList.this.listView.getAdapter() selectedWaypointId = WaypointsList.this.listView.getAdapter()
.getItemId(contextPosition); .getItemId(contextPosition);
Waypoint waypoint = providerUtils.getWaypoint(info.id); Waypoint waypoint = providerUtils.getWaypoint(info.id);
if (waypoint != null) { if (waypoint != null) {
@@ -108,18 +108,18 @@ public class WaypointsList extends ListActivity
if (!super.onMenuItemSelected(featureId, item)) { if (!super.onMenuItemSelected(featureId, item)) {
switch (item.getItemId()) { switch (item.getItemId()) {
case Constants.MENU_SHOW: { case Constants.MENU_SHOW: {
onListItemClick(null, null, 0, waypointId); onListItemClick(null, null, 0, selectedWaypointId);
return true; return true;
} }
case Constants.MENU_EDIT: { case Constants.MENU_EDIT: {
Intent intent = new Intent(this, WaypointDetails.class); Intent intent = new Intent(this, WaypointDetails.class);
intent.putExtra("trackid", trackId); intent.putExtra("trackid", trackId);
intent.putExtra(WaypointDetails.WAYPOINT_ID_EXTRA, waypointId); intent.putExtra(WaypointDetails.WAYPOINT_ID_EXTRA, selectedWaypointId);
startActivity(intent); startActivity(intent);
return true; return true;
} }
case Constants.MENU_DELETE: { case Constants.MENU_DELETE: {
deleteWaypoint(waypointId); deleteWaypoint(selectedWaypointId);
} }
} }
} }
@@ -297,8 +297,8 @@ public class WaypointsList extends ListActivity
builder.setPositiveButton(getString(R.string.yes), builder.setPositiveButton(getString(R.string.yes),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int i) { public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss(); dialogInterface.dismiss();
providerUtils.deleteWaypoint(waypointId, providerUtils.deleteWaypoint(waypointId,
new StringUtils(WaypointsList.this)); new StringUtils(WaypointsList.this));
} }
@@ -306,8 +306,8 @@ public class WaypointsList extends ListActivity
builder.setNegativeButton(getString(R.string.no), builder.setNegativeButton(getString(R.string.no),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int i) { public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss(); dialogInterface.dismiss();
} }
}); });
dialog = builder.create(); dialog = builder.create();
@@ -154,7 +154,7 @@ public class TrackDataHub {
private Handler listenerHandler; private Handler listenerHandler;
/** Manager for external listeners (those from activities). */ /** Manager for external listeners (those from activities). */
private final TrackDataListeners listeners; private final TrackDataListeners dataListeners;
/** Wrapper for interacting with system data managers. */ /** Wrapper for interacting with system data managers. */
private DataSourcesWrapper dataSources; private DataSourcesWrapper dataSources;
@@ -213,7 +213,7 @@ public class TrackDataHub {
TrackDataHub(Context ctx, TrackDataListeners listeners, SharedPreferences preferences, TrackDataHub(Context ctx, TrackDataListeners listeners, SharedPreferences preferences,
MyTracksProviderUtils providerUtils, int targetNumPoints) { MyTracksProviderUtils providerUtils, int targetNumPoints) {
this.context = ctx; this.context = ctx;
this.listeners = listeners; this.dataListeners = listeners;
this.preferences = preferences; this.preferences = preferences;
this.providerUtils = providerUtils; this.providerUtils = providerUtils;
this.targetNumPoints = targetNumPoints; this.targetNumPoints = targetNumPoints;
@@ -437,8 +437,9 @@ public class TrackDataHub {
public void registerTrackDataListener( public void registerTrackDataListener(
TrackDataListener listener, EnumSet<ListenerDataType> dataTypes) { TrackDataListener listener, EnumSet<ListenerDataType> dataTypes) {
synchronized (listeners) { synchronized (dataListeners) {
ListenerRegistration registration = listeners.registerTrackDataListener(listener, dataTypes); ListenerRegistration registration =
dataListeners.registerTrackDataListener(listener, dataTypes);
// Don't load any data or start internal listeners if start() hasn't been // Don't load any data or start internal listeners if start() hasn't been
// called. When it is called, we'll do both things. // called. When it is called, we'll do both things.
@@ -451,8 +452,8 @@ public class TrackDataHub {
} }
public void unregisterTrackDataListener(TrackDataListener listener) { public void unregisterTrackDataListener(TrackDataListener listener) {
synchronized (listeners) { synchronized (dataListeners) {
listeners.unregisterTrackDataListener(listener); dataListeners.unregisterTrackDataListener(listener);
// Don't load any data or start internal listeners if start() hasn't been // Don't load any data or start internal listeners if start() hasn't been
// called. When it is called, we'll do both things. // called. When it is called, we'll do both things.
@@ -467,8 +468,8 @@ public class TrackDataHub {
*/ */
public void reloadDataForListener(TrackDataListener listener) { public void reloadDataForListener(TrackDataListener listener) {
ListenerRegistration registration; ListenerRegistration registration;
synchronized (listeners) { synchronized (dataListeners) {
registration = listeners.getRegistration(listener); registration = dataListeners.getRegistration(listener);
registration.resetState(); registration.resetState();
loadNewDataForListener(registration); loadNewDataForListener(registration);
} }
@@ -477,7 +478,7 @@ public class TrackDataHub {
/** /**
* Reloads all track data received so far into the specified listeners. * Reloads all track data received so far into the specified listeners.
* *
* Assumes it's called from a block that synchronizes on {@link #listeners}. * Assumes it's called from a block that synchronizes on {@link #dataListeners}.
*/ */
private void loadNewDataForListener(final ListenerRegistration registration) { private void loadNewDataForListener(final ListenerRegistration registration) {
if (!isStarted()) { if (!isStarted()) {
@@ -492,7 +493,7 @@ public class TrackDataHub {
// If a listener happens to be added after this method but before the Runnable below is // If a listener happens to be added after this method but before the Runnable below is
// executed, it will have triggered a separate call to load data only up to the point this // executed, it will have triggered a separate call to load data only up to the point this
// listener got to. This is ensured by being synchronized on listeners. // listener got to. This is ensured by being synchronized on listeners.
final boolean isOnlyListener = (listeners.getNumListeners() == 1); final boolean isOnlyListener = (dataListeners.getNumListeners() == 1);
runInListenerThread(new Runnable() { runInListenerThread(new Runnable() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -577,8 +578,8 @@ public class TrackDataHub {
Log.w(TAG, "Not started, not reloading"); Log.w(TAG, "Not started, not reloading");
return; return;
} }
synchronized (listeners) { synchronized (dataListeners) {
if (!listeners.hasListeners()) { if (!dataListeners.hasListeners()) {
Log.d(TAG, "No listeners, not reloading"); Log.d(TAG, "No listeners, not reloading");
return; return;
} }
@@ -651,7 +652,7 @@ public class TrackDataHub {
for (TrackDataListener listener : displayListeners) { for (TrackDataListener listener : displayListeners) {
// TODO: Do the reloading just once for all interested listeners // TODO: Do the reloading just once for all interested listeners
if (listener.onReportSpeedChanged(reportSpeed)) { if (listener.onReportSpeedChanged(reportSpeed)) {
synchronized (listeners) { synchronized (dataListeners) {
reloadDataForListener(listener); reloadDataForListener(listener);
} }
} }
@@ -671,7 +672,7 @@ public class TrackDataHub {
for (TrackDataListener listener : displayListeners) { for (TrackDataListener listener : displayListeners) {
if (listener.onUnitsChanged(useMetricUnits)) { if (listener.onUnitsChanged(useMetricUnits)) {
synchronized (listeners) { synchronized (dataListeners) {
reloadDataForListener(listener); reloadDataForListener(listener);
} }
} }
@@ -739,7 +740,7 @@ public class TrackDataHub {
if (isGpsLocation) { if (isGpsLocation) {
// We consider a good fix to be a recent one with reasonable accuracy. // We consider a good fix to be a recent one with reasonable accuracy.
hasFix = !isLocationOld(location, now, MAX_LOCATION_AGE_MS); hasFix = !isLocationOld(location, now, MAX_LOCATION_AGE_MS);
hasGoodFix = (location != null && location.getAccuracy() <= minRequiredAccuracy); hasGoodFix = (location.getAccuracy() <= minRequiredAccuracy);
} else { } else {
if (!isLocationOld(lastSeenLocation, now, MAX_LOCATION_AGE_MS)) { if (!isLocationOld(lastSeenLocation, now, MAX_LOCATION_AGE_MS)) {
// This is a network location, but we have a recent/valid GPS location, just ignore this. // This is a network location, but we have a recent/valid GPS location, just ignore this.
@@ -961,7 +962,7 @@ public class TrackDataHub {
Log.i(TAG, "Resampling point set after " + numLoadedPoints + " points."); Log.i(TAG, "Resampling point set after " + numLoadedPoints + " points.");
resetState(); resetState();
synchronized (listeners) { synchronized (dataListeners) {
sampledListeners = getListenersFor(ListenerDataType.POINT_UPDATES); sampledListeners = getListenersFor(ListenerDataType.POINT_UPDATES);
sampledOutListeners = getListenersFor(ListenerDataType.SAMPLED_OUT_POINT_UPDATES); sampledOutListeners = getListenersFor(ListenerDataType.SAMPLED_OUT_POINT_UPDATES);
} }
@@ -1046,7 +1047,7 @@ public class TrackDataHub {
listener.onNewTrackPointsDone(); listener.onNewTrackPointsDone();
// Update the listener state // Update the listener state
ListenerRegistration registration = listeners.getRegistration(listener); ListenerRegistration registration = dataListeners.getRegistration(listener);
if (registration != null) { if (registration != null) {
registration.lastTrackId = currentSelectedTrackId; registration.lastTrackId = currentSelectedTrackId;
registration.lastPointId = localLastSeenLocationId; registration.lastPointId = localLastSeenLocationId;
@@ -1059,7 +1060,7 @@ public class TrackDataHub {
private void notifyNewPoint(Location location, private void notifyNewPoint(Location location,
long locationId, long locationId,
long lastStoredLocationId, long lastStoredLocationId,
int numLoadedPoints, int loadedPoints,
int pointSamplingFrequency, int pointSamplingFrequency,
Set<TrackDataListener> sampledListeners, Set<TrackDataListener> sampledListeners,
Set<TrackDataListener> sampledOutListeners) { Set<TrackDataListener> sampledOutListeners) {
@@ -1078,7 +1079,7 @@ public class TrackDataHub {
// - Is the last point and we are not recording this track. // - Is the last point and we are not recording this track.
boolean recordingSelected = isRecordingSelected(); boolean recordingSelected = isRecordingSelected();
boolean includeInSample = boolean includeInSample =
(numLoadedPoints % pointSamplingFrequency == 0 || (loadedPoints % pointSamplingFrequency == 0 ||
(!recordingSelected && locationId == lastStoredLocationId)); (!recordingSelected && locationId == lastStoredLocationId));
if (!includeInSample) { if (!includeInSample) {
@@ -1106,13 +1107,13 @@ public class TrackDataHub {
} }
private Set<TrackDataListener> getListenersFor(ListenerDataType type) { private Set<TrackDataListener> getListenersFor(ListenerDataType type) {
synchronized (listeners) { synchronized (dataListeners) {
return listeners.getListenersFor(type); return dataListeners.getListenersFor(type);
} }
} }
private EnumSet<ListenerDataType> getNeededListenerTypes() { private EnumSet<ListenerDataType> getNeededListenerTypes() {
EnumSet<ListenerDataType> neededTypes = listeners.getAllRegisteredTypes(); EnumSet<ListenerDataType> neededTypes = dataListeners.getAllRegisteredTypes();
// We always want preference updates. // We always want preference updates.
neededTypes.add(ListenerDataType.DISPLAY_PREFERENCES); neededTypes.add(ListenerDataType.DISPLAY_PREFERENCES);
@@ -196,7 +196,7 @@ public class SendToFusionTables implements Runnable {
// Create a new table: // Create a new table:
progressIndicator.setProgressValue(PROGRESS_FUSION_TABLE_CREATE); progressIndicator.setProgressValue(PROGRESS_FUSION_TABLE_CREATE);
progressIndicator.setProgressMessage(R.string.progress_message_creating_fusiontable); progressIndicator.setProgressMessage(R.string.progress_message_creating_fusiontable);
if (!createNewTable(track) || !makeTableUnlisted(tableId)) { if (!createNewTable(track) || !makeTableUnlisted()) {
return; return;
} }
@@ -245,7 +245,7 @@ public class SendToFusionTables implements Runnable {
return runUpdate(query); return runUpdate(query);
} }
private boolean makeTableUnlisted(String tableId) { private boolean makeTableUnlisted() {
Log.d(Constants.TAG, "Setting visibility to unlisted."); Log.d(Constants.TAG, "Setting visibility to unlisted.");
String query = "UPDATE TABLE " + tableId + " SET VISIBILITY = UNLISTED"; String query = "UPDATE TABLE " + tableId + " SET VISIBILITY = UNLISTED";
return runUpdate(query); return runUpdate(query);
@@ -185,7 +185,7 @@ public class BackupActivityHelper {
*/ */
private void restoreFromDateAsync(final Date date) { private void restoreFromDateAsync(final Date date) {
// Show a progress dialog // Show a progress dialog
final ProgressDialog progressDialog = ProgressDialog.show( ProgressDialog.show(
activity, activity,
activity.getString(R.string.progress_title), activity.getString(R.string.progress_title),
activity.getString(R.string.backup_import_progress_message), activity.getString(R.string.backup_import_progress_message),
@@ -85,7 +85,7 @@ class DatabaseDumper {
public void writeHeaders(Cursor cursor, int numRows, DataOutputStream writer) public void writeHeaders(Cursor cursor, int numRows, DataOutputStream writer)
throws IOException { throws IOException {
initializeCachedValues(cursor); initializeCachedValues(cursor);
writeQueryMetadata(cursor, numRows, writer); writeQueryMetadata(numRows, writer);
} }
/** /**
@@ -151,7 +151,7 @@ class DatabaseDumper {
* @throws IOException if there are any errors while writing * @throws IOException if there are any errors while writing
*/ */
private void writeQueryMetadata( private void writeQueryMetadata(
Cursor cursor, int numRows, DataOutputStream writer) throws IOException { int numRows, DataOutputStream writer) throws IOException {
// Write column data // Write column data
writer.writeInt(columnNames.length); writer.writeInt(columnNames.length);
for (int i = 0; i < columnNames.length; i++) { for (int i = 0; i < columnNames.length; i++) {
@@ -69,22 +69,22 @@ public class DocsHelper {
private static final String OPENDOCUMENT_SPREADSHEET_MIME_TYPE = private static final String OPENDOCUMENT_SPREADSHEET_MIME_TYPE =
"application/x-vnd.oasis.opendocument.spreadsheet"; "application/x-vnd.oasis.opendocument.spreadsheet";
private static final String ATOM_FEED_MIME_TYPE = "application/atom+xml"; private static final String ATOM_FEED_MIME_TYPE = "application/atom+xml";
/** /**
* Creates a new MyTracks spreadsheet with the given name. * Creates a new MyTracks spreadsheet with the given name.
* *
* @param context The context associated with this request. * @param context The context associated with this request.
* @param docListWrapper The GData handle for the Document List service. * @param docListWrapper The GData handle for the Document List service.
* @param name The name for the newly-created spreadsheet. * @param name The name for the newly-created spreadsheet.
* @return The spreadsheet ID, if one is created. {@code null} will be * @return The spreadsheet ID, if one is created. {@code null} will be
* returned if a GData error didn't occur, but no spreadsheet ID was * returned if a GData error didn't occur, but no spreadsheet ID was
* returned. * returned.
*/ */
public String createSpreadsheet(final Context context, public String createSpreadsheet(final Context context,
final GDataWrapper<GDataServiceClient> docListWrapper, final String name) throws IOException { final GDataWrapper<GDataServiceClient> docListWrapper, final String name) throws IOException {
final AtomicReference<String> idSaver = new AtomicReference<String>(); final AtomicReference<String> idSaver = new AtomicReference<String>();
boolean result = docListWrapper.runQuery(new QueryFunction<GDataServiceClient>() { boolean success = docListWrapper.runQuery(new QueryFunction<GDataServiceClient>() {
@Override @Override
public void query(GDataServiceClient client) throws IOException, public void query(GDataServiceClient client) throws IOException,
GDataWrapper.AuthenticationException { GDataWrapper.AuthenticationException {
@@ -95,7 +95,7 @@ public class DocsHelper {
OPENDOCUMENT_SPREADSHEET_MIME_TYPE); OPENDOCUMENT_SPREADSHEET_MIME_TYPE);
conn.addRequestProperty("Slug", name); conn.addRequestProperty("Slug", name);
conn.addRequestProperty("Authorization", conn.addRequestProperty("Authorization",
"GoogleLogin auth=" + "GoogleLogin auth=" +
docListWrapper.getAuthManager().getAuthToken()); docListWrapper.getAuthManager().getAuthToken());
conn.setDoOutput(true); conn.setDoOutput(true);
OutputStream os = conn.getOutputStream(); OutputStream os = conn.getOutputStream();
@@ -141,24 +141,24 @@ public class DocsHelper {
if (idStringStart == -1) { if (idStringStart == -1) {
return; return;
} }
String id = result.substring( String id = result.substring(
idStringStart + DOCS_SPREADSHEET_URL.length(), idTagCloseIndex); idStringStart + DOCS_SPREADSHEET_URL.length(), idTagCloseIndex);
Log.i(Constants.TAG, "Created new spreadsheet: " + id); Log.i(Constants.TAG, "Created new spreadsheet: " + id);
idSaver.set(id); idSaver.set(id);
}}); }});
if (!result) { if (!success) {
throw newIOException(docListWrapper, throw newIOException(docListWrapper,
"Failed to create new spreadsheet."); "Failed to create new spreadsheet.");
} }
return idSaver.get(); return idSaver.get();
} }
/** /**
* Retrieve the ID of a spreadsheet with the given name. * Retrieve the ID of a spreadsheet with the given name.
* *
* @param docListWrapper The GData handle for the Document List service. * @param docListWrapper The GData handle for the Document List service.
* @param title The name of the spreadsheet whose ID is to be retrieved. * @param title The name of the spreadsheet whose ID is to be retrieved.
* @return The spreadsheet ID, if it can be retrieved. {@code null} will * @return The spreadsheet ID, if it can be retrieved. {@code null} will
@@ -177,7 +177,7 @@ public class DocsHelper {
GDataParser listParser; GDataParser listParser;
try { try {
listParser = client.getParserForFeed(Entry.class, listParser = client.getParserForFeed(Entry.class,
DOCS_MY_SPREADSHEETS_FEED_URL, DOCS_MY_SPREADSHEETS_FEED_URL,
docListWrapper.getAuthManager().getAuthToken()); docListWrapper.getAuthManager().getAuthToken());
listParser.init(); listParser.init();
@@ -201,22 +201,22 @@ public class DocsHelper {
}); });
if (!result) { if (!result) {
throw newIOException(docListWrapper, throw newIOException(docListWrapper,
"Failed to retrieve spreadsheet list."); "Failed to retrieve spreadsheet list.");
} }
return idSaver.get(); return idSaver.get();
} }
/** /**
* Retrieve the ID of the first worksheet in the named spreadsheet. * Retrieve the ID of the first worksheet in the named spreadsheet.
* *
* @param trixWrapper The GData handle for the spreadsheet service. * @param trixWrapper The GData handle for the spreadsheet service.
* @param spreadsheetId The GData ID for the given spreadsheet. * @param spreadsheetId The GData ID for the given spreadsheet.
* @return The worksheet ID, if it can be retrieved. {@code null} will be * @return The worksheet ID, if it can be retrieved. {@code null} will be
* returned if the GData request returns without error, but without an * returned if the GData request returns without error, but without an
* ID. * ID.
* @throws IOException If an error occurs during the GData request. * @throws IOException If an error occurs during the GData request.
*/ */
public String getWorksheetId(final GDataWrapper<GDataServiceClient> trixWrapper, public String getWorksheetId(final GDataWrapper<GDataServiceClient> trixWrapper,
final String spreadsheetId) throws IOException { final String spreadsheetId) throws IOException {
@@ -250,17 +250,17 @@ public class DocsHelper {
} }
} }
}); });
if (!result) { if (!result) {
throw newIOException(trixWrapper, "Failed to retrieve worksheet ID."); throw newIOException(trixWrapper, "Failed to retrieve worksheet ID.");
} }
return idSaver.get(); return idSaver.get();
} }
/** /**
* Add a row to a worksheet containing the stats for a given track. * Add a row to a worksheet containing the stats for a given track.
* *
* @param context The context associated with this request. * @param context The context associated with this request.
* @param trixAuth The GData authorization for the spreadsheet service. * @param trixAuth The GData authorization for the spreadsheet service.
* @param spreadsheetId The spreadsheet to be modified. * @param spreadsheetId The spreadsheet to be modified.
@@ -270,17 +270,17 @@ public class DocsHelper {
* imperial units will be used. * imperial units will be used.
* @throws IOException If an error occurs while updating the worksheet. * @throws IOException If an error occurs while updating the worksheet.
*/ */
public void addTrackRow(Context context, AuthManager trixAuth, public void addTrackRow(Context context, AuthManager trixAuth,
String spreadsheetId, String worksheetId, Track track, String spreadsheetId, String worksheetId, Track track,
boolean metricUnits) throws IOException { boolean metricUnits) throws IOException {
String worksheetUri = String.format(DOCS_SPREADSHEET_URL_FORMAT, String worksheetUri = String.format(DOCS_SPREADSHEET_URL_FORMAT,
spreadsheetId, worksheetId); spreadsheetId, worksheetId);
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getStatistics();
String distanceUnit = context.getString(metricUnits ? String distanceUnit = context.getString(metricUnits ?
R.string.kilometer : R.string.mile); R.string.kilometer : R.string.mile);
String speedUnit = context.getString(metricUnits ? String speedUnit = context.getString(metricUnits ?
R.string.kilometer_per_hour : R.string.mile_per_hour); R.string.kilometer_per_hour : R.string.mile_per_hour);
String elevationUnit = context.getString(metricUnits ? String elevationUnit = context.getString(metricUnits ?
R.string.meter : R.string.feet); R.string.meter : R.string.feet);
@@ -310,7 +310,7 @@ public class DocsHelper {
tagBuilder.append("map", String.format("%s?msa=0&msid=%s", tagBuilder.append("map", String.format("%s?msa=0&msid=%s",
Constants.MAPSHOP_BASE_URL, track.getMapId())); Constants.MAPSHOP_BASE_URL, track.getMapId()));
} }
String postText = new StringBuilder() String postText = new StringBuilder()
.append("<entry xmlns='http://www.w3.org/2005/Atom' " .append("<entry xmlns='http://www.w3.org/2005/Atom' "
+ "xmlns:gsx='http://schemas.google.com/spreadsheets/" + "xmlns:gsx='http://schemas.google.com/spreadsheets/"
@@ -323,7 +323,7 @@ public class DocsHelper {
"Inserting at: " + spreadsheetId + " => " + worksheetUri); "Inserting at: " + spreadsheetId + " => " + worksheetUri);
Log.i(Constants.TAG, postText); Log.i(Constants.TAG, postText);
writeRowData(trixAuth, worksheetUri, postText); writeRowData(trixAuth, worksheetUri, postText);
Log.i(Constants.TAG, "Post finished."); Log.i(Constants.TAG, "Post finished.");
@@ -331,13 +331,13 @@ public class DocsHelper {
/** /**
* Writes spreadsheet row data to the indicated worksheet. * Writes spreadsheet row data to the indicated worksheet.
* *
* @param trixAuth The GData authorization for the spreadsheet service. * @param trixAuth The GData authorization for the spreadsheet service.
* @param worksheetUri The URI of the worksheet to be altered. * @param worksheetUri The URI of the worksheet to be altered.
* @param postText The XML tags describing the change to be made. * @param postText The XML tags describing the change to be made.
* @throws IOException Thrown if an error occurs during the write. * @throws IOException Thrown if an error occurs during the write.
*/ */
protected void writeRowData(AuthManager trixAuth, String worksheetUri, protected void writeRowData(AuthManager trixAuth, String worksheetUri,
String postText) throws IOException { String postText) throws IOException {
// No need for a wrapper because we know that the authorization was good // No need for a wrapper because we know that the authorization was good
// enough to get this far. // enough to get this far.
@@ -364,9 +364,9 @@ public class DocsHelper {
rd.close(); rd.close();
} }
private static IOException newIOException(GDataWrapper<GDataServiceClient> wrapper, private static IOException newIOException(GDataWrapper<GDataServiceClient> wrapper,
String message) { String message) {
return new IOException(String.format("%s: %d: %s", message, return new IOException(String.format("%s: %d: %s", message,
wrapper.getErrorType(), wrapper.getErrorMessage())); wrapper.getErrorType(), wrapper.getErrorMessage()));
} }
} }
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2010 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
@@ -51,7 +51,7 @@ public class CsvTrackWriter implements TrackFormatWriter {
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
static { static {
SHORT_FORMAT.setMaximumFractionDigits(4); SHORT_FORMAT.setMaximumFractionDigits(4);
TIMESTAMP_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); TIMESTAMP_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
} }
@@ -65,6 +65,7 @@ public class CsvTrackWriter implements TrackFormatWriter {
return TrackFileFormat.CSV.getExtension(); return TrackFileFormat.CSV.getExtension();
} }
@SuppressWarnings("hiding")
@Override @Override
public void prepare(Track track, OutputStream out) { public void prepare(Track track, OutputStream out) {
this.track = track; this.track = track;
@@ -67,6 +67,7 @@ public class GpxTrackWriter implements TrackFormatWriter {
+ "\" lon=\"" + coordinateFormatter.format(l.getLongitude()) + "\""; + "\" lon=\"" + coordinateFormatter.format(l.getLongitude()) + "\"";
} }
@SuppressWarnings("hiding")
@Override @Override
public void prepare(Track track, OutputStream out) { public void prepare(Track track, OutputStream out) {
this.track = track; this.track = track;
@@ -1,12 +1,12 @@
/* /*
* Copyright 2008 Google Inc. * Copyright 2008 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
@@ -52,6 +52,7 @@ public class KmlTrackWriter implements TrackFormatWriter {
this.stringUtils = stringUtils; this.stringUtils = stringUtils;
} }
@SuppressWarnings("hiding")
@Override @Override
public void prepare(Track track, OutputStream out) { public void prepare(Track track, OutputStream out) {
this.track = track; this.track = track;
@@ -157,6 +157,7 @@ public class SaveActivity extends Activity {
if (controller != null) { if (controller != null) {
return controller.createProgressDialog(); return controller.createProgressDialog();
} }
//$FALL-THROUGH$
default: default:
return super.onCreateDialog(id); return super.onCreateDialog(id);
} }
@@ -71,6 +71,7 @@ public class TcxTrackWriter implements TrackFormatWriter {
timestampFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); timestampFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
} }
@SuppressWarnings("hiding")
@Override @Override
public void prepare(Track track, OutputStream out) { public void prepare(Track track, OutputStream out) {
this.track = track; this.track = track;
@@ -280,9 +280,7 @@ class TrackWriterImpl implements TrackWriter {
} }
} }
} finally { } finally {
if (cursor != null) { cursor.close();
cursor.close();
}
} }
} }
} }
@@ -96,7 +96,7 @@ class WriteProgressController {
private final DialogInterface.OnCancelListener dialogCancelListener = private final DialogInterface.OnCancelListener dialogCancelListener =
new DialogInterface.OnCancelListener() { new DialogInterface.OnCancelListener() {
@Override @Override
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialogInterface) {
writer.stopWriteTrack(); writer.stopWriteTrack();
} }
}; };
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2010 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
@@ -24,7 +24,7 @@ import android.util.Log;
/** /**
* A class that manages reading the shared preferences for the service. * A class that manages reading the shared preferences for the service.
* *
* @author Sandor Dornbush * @author Sandor Dornbush
*/ */
public class PreferenceManager implements OnSharedPreferenceChangeListener { public class PreferenceManager implements OnSharedPreferenceChangeListener {
@@ -52,14 +52,14 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
throw new IllegalStateException("Couldn't get shared preferences"); throw new IllegalStateException("Couldn't get shared preferences");
} }
sharedPreferences.registerOnSharedPreferenceChangeListener(this); sharedPreferences.registerOnSharedPreferenceChangeListener(this);
announcementFrequencyKey = announcementFrequencyKey =
service.getString(R.string.announcement_frequency_key); service.getString(R.string.announcement_frequency_key);
autoResumeTrackCurrentRetryKey = autoResumeTrackCurrentRetryKey =
service.getString(R.string.auto_resume_track_current_retry_key); service.getString(R.string.auto_resume_track_current_retry_key);
autoResumeTrackTimeoutKey = autoResumeTrackTimeoutKey =
service.getString(R.string.auto_resume_track_timeout_key); service.getString(R.string.auto_resume_track_timeout_key);
maxRecordingDistanceKey = maxRecordingDistanceKey =
service.getString(R.string.max_recording_distance_key); service.getString(R.string.max_recording_distance_key);
metricUnitsKey = metricUnitsKey =
service.getString(R.string.metric_units_key); service.getString(R.string.metric_units_key);
@@ -75,7 +75,7 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
service.getString(R.string.selected_track_key); service.getString(R.string.selected_track_key);
splitFrequencyKey = splitFrequencyKey =
service.getString(R.string.split_frequency_key); service.getString(R.string.split_frequency_key);
// Refresh all properties. // Refresh all properties.
onSharedPreferenceChanged(sharedPreferences, null); onSharedPreferenceChanged(sharedPreferences, null);
} }
@@ -87,7 +87,7 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
* @param key the key that changed (may be null to update all preferences) * @param key the key that changed (may be null to update all preferences)
*/ */
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, public void onSharedPreferenceChanged(SharedPreferences preferences,
String key) { String key) {
if (service == null) { if (service == null) {
Log.w(Constants.TAG, Log.w(Constants.TAG,
@@ -152,7 +152,7 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
if (key == null || key.equals(recordingTrackKey)) { if (key == null || key.equals(recordingTrackKey)) {
long recordingTrackId = sharedPreferences.getLong(recordingTrackKey, -1); long recordingTrackId = sharedPreferences.getLong(recordingTrackKey, -1);
// Only read the id if it is valid. // Only read the id if it is valid.
// Setting it to -1 should only happen in // Setting it to -1 should only happen in
// TrackRecordingService.endCurrentTrack() // TrackRecordingService.endCurrentTrack()
if (recordingTrackId > 0) { if (recordingTrackId > 0) {
service.setRecordingTrackId(recordingTrackId); service.setRecordingTrackId(recordingTrackId);
@@ -167,7 +167,7 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
sharedPreferences.getBoolean(metricUnitsKey, true)); sharedPreferences.getBoolean(metricUnitsKey, true));
} }
} }
public void setAutoResumeTrackCurrentRetry(int retryAttempts) { public void setAutoResumeTrackCurrentRetry(int retryAttempts) {
sharedPreferences sharedPreferences
.edit() .edit()
@@ -181,14 +181,14 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
.putLong(recordingTrackKey, id) .putLong(recordingTrackKey, id)
.commit(); .commit();
} }
public void setSelectedTrack(long id) { public void setSelectedTrack(long id) {
sharedPreferences sharedPreferences
.edit() .edit()
.putLong(selectedTrackKey, id) .putLong(selectedTrackKey, id)
.commit(); .commit();
} }
public void shutdown() { public void shutdown() {
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this); sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
service = null; service = null;
@@ -301,7 +301,7 @@ public class TrackRecordingService extends Service {
private void resumeTrack(int startId) { private void resumeTrack(int startId) {
Log.d(TAG, "TrackRecordingService: requested resume"); Log.d(TAG, "TrackRecordingService: requested resume");
// Make sure that the current track exists and is fresh enough. // Make sure that the current track exists and is fresh enough.
if (recordingTrack == null || !shouldResumeTrack(recordingTrack)) { if (recordingTrack == null || !shouldResumeTrack(recordingTrack)) {
Log.i(TAG, Log.i(TAG,
@@ -312,7 +312,7 @@ public class TrackRecordingService extends Service {
stopSelfResult(startId); stopSelfResult(startId);
return; return;
} }
Log.i(TAG, "TrackRecordingService: resuming"); Log.i(TAG, "TrackRecordingService: resuming");
} }
@@ -361,7 +361,7 @@ public class TrackRecordingService extends Service {
super.onDestroy(); super.onDestroy();
} }
private void setAutoResumeTrackRetries(SharedPreferences sharedPreferences, int retryAttempts) { private void setAutoResumeTrackRetries(int retryAttempts) {
Log.d(TAG, "Updating auto-resume retry attempts to: " + retryAttempts); Log.d(TAG, "Updating auto-resume retry attempts to: " + retryAttempts);
prefManager.setAutoResumeTrackCurrentRetry(retryAttempts); prefManager.setAutoResumeTrackCurrentRetry(retryAttempts);
} }
@@ -386,7 +386,7 @@ public class TrackRecordingService extends Service {
} }
// Increase number of retry attempts. // Increase number of retry attempts.
setAutoResumeTrackRetries(sharedPreferences, retries + 1); setAutoResumeTrackRetries(retries + 1);
// Check for special cases. // Check for special cases.
if (autoResumeTrackTimeout == 0) { if (autoResumeTrackTimeout == 0) {
@@ -579,8 +579,7 @@ public class TrackRecordingService extends Service {
} }
// Reset the number of auto-resume retries. // Reset the number of auto-resume retries.
setAutoResumeTrackRetries( setAutoResumeTrackRetries(0);
getSharedPreferences(Constants.SETTINGS_NAME, 0), 0);
// Persist the current recording track. // Persist the current recording track.
prefManager.setRecordingTrack(recordingTrackId); prefManager.setRecordingTrack(recordingTrackId);
@@ -695,8 +694,6 @@ public class TrackRecordingService extends Service {
} }
Location lastRecordedLocation = providerUtils.getLastLocation(); Location lastRecordedLocation = providerUtils.getLastLocation();
long lastRecordedLocationId =
providerUtils.getLastLocationId(recordingTrackId);
double distanceToLastRecorded = Double.POSITIVE_INFINITY; double distanceToLastRecorded = Double.POSITIVE_INFINITY;
if (lastRecordedLocation != null) { if (lastRecordedLocation != null) {
distanceToLastRecorded = location.distanceTo(lastRecordedLocation); distanceToLastRecorded = location.distanceTo(lastRecordedLocation);
@@ -722,9 +719,7 @@ public class TrackRecordingService extends Service {
// Need to write the last location. This will happen when // Need to write the last location. This will happen when
// lastRecordedLocation.distance(lastLocation) < // lastRecordedLocation.distance(lastLocation) <
// minRecordingDistance // minRecordingDistance
if (!insertLocation(recordingTrack, lastLocation, if (!insertLocation(lastLocation, lastRecordedLocation, recordingTrackId)) {
lastRecordedLocation, lastRecordedLocationId,
recordingTrackId)) {
return; return;
} }
} }
@@ -737,11 +732,9 @@ public class TrackRecordingService extends Service {
if (lastLocation != null && !isMoving) { if (lastLocation != null && !isMoving) {
// Last location was the last stationary location. Need to go back and // Last location was the last stationary location. Need to go back and
// add it. // add it.
if (!insertLocation(recordingTrack, lastLocation, if (!insertLocation(lastLocation, lastRecordedLocation, recordingTrackId)) {
lastRecordedLocation, lastRecordedLocationId, recordingTrackId)) {
return; return;
} }
lastRecordedLocationId++;
isMoving = true; isMoving = true;
} }
@@ -762,8 +755,7 @@ public class TrackRecordingService extends Service {
providerUtils.insertTrackPoint(separator, recordingTrackId); providerUtils.insertTrackPoint(separator, recordingTrackId);
} }
if (!insertLocation(recordingTrack, location, lastRecordedLocation, if (!insertLocation(location, lastRecordedLocation, recordingTrackId)) {
lastRecordedLocationId, recordingTrackId)) {
return; return;
} }
} else { } else {
@@ -790,18 +782,13 @@ public class TrackRecordingService extends Service {
* Inserts a new location in the track points db and updates the corresponding * Inserts a new location in the track points db and updates the corresponding
* track in the track db. * track in the track db.
* *
* @param recordingTrack the track that is currently being recorded
* @param location the location to be inserted * @param location the location to be inserted
* @param lastRecordedLocation the last recorded location before this one (or * @param lastRecordedLocation the last recorded location before this one (or
* null if none) * null if none)
* @param lastRecordedLocationId the id of the last recorded location (or -1
* if none)
* @param trackId the id of the track * @param trackId the id of the track
* @return true if successful. False if SQLite3 threw an exception. * @return true if successful. False if SQLite3 threw an exception.
*/ */
private boolean insertLocation(Track recordingTrack, Location location, private boolean insertLocation(Location location, Location lastRecordedLocation, long trackId) {
Location lastRecordedLocation, long lastRecordedLocationId,
long trackId) {
// Keep track of length along recorded track (needed when a waypoint is // Keep track of length along recorded track (needed when a waypoint is
// inserted): // inserted):
@@ -1003,22 +990,22 @@ public class TrackRecordingService extends Service {
announcementExecutor.shutdown(); announcementExecutor.shutdown();
splitExecutor.shutdown(); splitExecutor.shutdown();
isRecording = false; isRecording = false;
Track recordingTrack = providerUtils.getTrack(recordingTrackId); Track recordedTrack = providerUtils.getTrack(recordingTrackId);
if (recordingTrack != null) { if (recordedTrack != null) {
TripStatistics stats = recordingTrack.getStatistics(); TripStatistics stats = recordedTrack.getStatistics();
stats.setStopTime(System.currentTimeMillis()); stats.setStopTime(System.currentTimeMillis());
stats.setTotalTime(stats.getStopTime() - stats.getStartTime()); stats.setTotalTime(stats.getStopTime() - stats.getStartTime());
long lastRecordedLocationId = long lastRecordedLocationId =
providerUtils.getLastLocationId(recordingTrackId); providerUtils.getLastLocationId(recordingTrackId);
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
if (lastRecordedLocationId >= 0 if (lastRecordedLocationId >= 0
&& recordingTrack.getStopId() >= 0) { && recordedTrack.getStopId() >= 0) {
values.put(TracksColumns.STOPID, lastRecordedLocationId); values.put(TracksColumns.STOPID, lastRecordedLocationId);
} }
values.put(TracksColumns.STOPTIME, stats.getStopTime()); values.put(TracksColumns.STOPTIME, stats.getStopTime());
values.put(TracksColumns.TOTALTIME, stats.getTotalTime()); values.put(TracksColumns.TOTALTIME, stats.getTotalTime());
getContentResolver().update(TracksColumns.CONTENT_URI, values, getContentResolver().update(TracksColumns.CONTENT_URI, values,
"_id=" + recordingTrack.getId(), null); "_id=" + recordedTrack.getId(), null);
} }
showNotification(); showNotification();
long recordedTrackId = recordingTrackId; long recordedTrackId = recordingTrackId;
@@ -82,7 +82,7 @@ public abstract class AntSensorManager extends SensorManager {
/** Receives and logs all status ANT intents. */ /** Receives and logs all status ANT intents. */
private final BroadcastReceiver statusReceiver = new BroadcastReceiver() { private final BroadcastReceiver statusReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context ctx, Intent intent) {
String antAction = intent.getAction(); String antAction = intent.getAction();
Log.i(TAG, "enter status onReceive" + antAction); Log.i(TAG, "enter status onReceive" + antAction);
} }
@@ -91,7 +91,7 @@ public abstract class AntSensorManager extends SensorManager {
/** Receives all data ANT intents. */ /** Receives all data ANT intents. */
private final BroadcastReceiver dataReceiver = new BroadcastReceiver() { private final BroadcastReceiver dataReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context ctx, Intent intent) {
String antAction = intent.getAction(); String antAction = intent.getAction();
Log.i(TAG, "enter data onReceive" + antAction); Log.i(TAG, "enter data onReceive" + antAction);
@@ -130,10 +130,12 @@ public class StatusAnnouncerTask implements PeriodicTask {
return; return;
} }
checkReady(); synchronized (this) {
if (!ready) { checkReady();
Log.e(TAG, "StatusAnnouncer Tts not ready."); if (!ready) {
return; Log.e(TAG, "StatusAnnouncer Tts not ready.");
return;
}
} }
if (!speechAllowed) { if (!speechAllowed) {
@@ -35,7 +35,7 @@ public class ApiFeatures {
Build.VERSION.SDK); Build.VERSION.SDK);
private static ApiFeatures instance; private static ApiFeatures instance;
/** /**
* The API platform adapter supported by this system. * The API platform adapter supported by this system.
*/ */
@@ -54,6 +54,7 @@ public class ApiFeatures {
/** /**
* Injects a specific singleton instance, to be used for unit tests. * Injects a specific singleton instance, to be used for unit tests.
*/ */
@SuppressWarnings("hiding")
public static void injectInstance(ApiFeatures instance) { public static void injectInstance(ApiFeatures instance) {
ApiFeatures.instance = instance; ApiFeatures.instance = instance;
} }
@@ -106,11 +107,11 @@ public class ApiFeatures {
public boolean hasStrictMode() { public boolean hasStrictMode() {
return getApiLevel() >= 9; return getApiLevel() >= 9;
} }
public boolean isAudioFocusSupported() { public boolean isAudioFocusSupported() {
return getApiLevel() >= 8; return getApiLevel() >= 8;
} }
/** /**
* There's a bug (#1587) in Cupcake and Donut which prevents you from * There's a bug (#1587) in Cupcake and Donut which prevents you from
* using a SQLiteQueryBuilder twice. That is, if you call buildQuery * using a SQLiteQueryBuilder twice. That is, if you call buildQuery
@@ -1,12 +1,12 @@
/* /*
* Copyright 2008 Google Inc. * Copyright 2008 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
@@ -30,14 +30,14 @@ import java.util.Stack;
/** /**
* Utility class for decimating tracks at a given level of precision. * Utility class for decimating tracks at a given level of precision.
* *
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
*/ */
public class LocationUtils { public class LocationUtils {
/** /**
* Computes the distance on the two sphere between the point c0 and the line * Computes the distance on the two sphere between the point c0 and the line
* segment c1 to c2. * segment c1 to c2.
* *
* @param c0 the first coordinate * @param c0 the first coordinate
* @param c1 the beginning of the line segment * @param c1 the beginning of the line segment
* @param c2 the end of the lone segment * @param c2 the end of the lone segment
@@ -79,7 +79,7 @@ public class LocationUtils {
/** /**
* Decimates the given locations for a given zoom level. This uses a * Decimates the given locations for a given zoom level. This uses a
* Douglas-Peucker decimation algorithm. * Douglas-Peucker decimation algorithm.
* *
* @param tolerance in meters * @param tolerance in meters
* @param locations input * @param locations input
* @param decimated output * @param decimated output
@@ -142,7 +142,7 @@ public class LocationUtils {
/** /**
* Decimates the given track for the given precision. * Decimates the given track for the given precision.
* *
* @param track a track * @param track a track
* @param precision desired precision in meters * @param precision desired precision in meters
*/ */
@@ -155,7 +155,7 @@ public class LocationUtils {
/** /**
* Limits number of points by dropping any points beyond the given number of * Limits number of points by dropping any points beyond the given number of
* points. Note: That'll actually discard points. * points. Note: That'll actually discard points.
* *
* @param track a track * @param track a track
* @param numberOfPoints maximum number of points * @param numberOfPoints maximum number of points
*/ */
@@ -169,7 +169,7 @@ public class LocationUtils {
/** /**
* Splits a track in multiple tracks where each piece has less or equal than * Splits a track in multiple tracks where each piece has less or equal than
* maxPoints. * maxPoints.
* *
* @param track the track to split * @param track the track to split
* @param maxPoints maximum number of points for each piece * @param maxPoints maximum number of points for each piece
* @return a list of one or more track pieces * @return a list of one or more track pieces
@@ -197,14 +197,14 @@ public class LocationUtils {
result.add(piece); result.add(piece);
} }
n += (pieceLocations.size() - 1); n += (pieceLocations.size() - 1);
} while (n < nTotal && piece != null && piece.getLocations().size() > 1); } while (n < nTotal && piece.getLocations().size() > 1);
return result; return result;
} }
/** /**
* Test if a given GeoPoint is valid, i.e. within physical bounds. * Test if a given GeoPoint is valid, i.e. within physical bounds.
* *
* @param geoPoint the point to be tested * @param geoPoint the point to be tested
* @return true, if it is a physical location on earth. * @return true, if it is a physical location on earth.
*/ */
@@ -218,7 +218,7 @@ public class LocationUtils {
* on Earth. Note: The special separator locations (which have latitude = * on Earth. Note: The special separator locations (which have latitude =
* 100) will not qualify as valid. Neither will locations with lat=0 and lng=0 * 100) will not qualify as valid. Neither will locations with lat=0 and lng=0
* as these are most likely "bad" measurements which often cause trouble. * as these are most likely "bad" measurements which often cause trouble.
* *
* @param location the location to test * @param location the location to test
* @return true if the location is a valid location. * @return true if the location is a valid location.
*/ */
@@ -229,7 +229,7 @@ public class LocationUtils {
/** /**
* Gets a location from a GeoPoint. * Gets a location from a GeoPoint.
* *
* @param p a GeoPoint * @param p a GeoPoint
* @return the corresponding location * @return the corresponding location
*/ */
@@ -58,12 +58,12 @@ public class TrackWidgetProvider
public TrackObserver() { public TrackObserver() {
super(contentHandler); super(contentHandler);
} }
public void onChange(boolean selfChange) { public void onChange(boolean selfChange) {
updateTrack(null); updateTrack(null);
} }
} }
private final Handler contentHandler; private final Handler contentHandler;
private MyTracksProviderUtils providerUtils; private MyTracksProviderUtils providerUtils;
private Context context; private Context context;
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2010 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
@@ -48,20 +48,19 @@ public class XmlDocsGDataParserFactory implements GDataParserFactory {
} }
} }
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings("rawtypes")
@Override @Override
public GDataParser createParser(Class cls, InputStream is) public GDataParser createParser(Class cls, InputStream is)
throws ParseException { throws ParseException {
try { try {
return createParserForClass(cls, is); return createParserForClass(is);
} catch (XmlPullParserException e) { } catch (XmlPullParserException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
} }
private GDataParser createParserForClass( private GDataParser createParserForClass(InputStream is)
Class<? extends Entry> cls, InputStream is)
throws ParseException, XmlPullParserException { throws ParseException, XmlPullParserException {
return new XmlGDataParser(is, xmlFactory.createParser()); return new XmlGDataParser(is, xmlFactory.createParser());
} }
@@ -48,7 +48,7 @@ import org.xml.sax.SAXException;
/** /**
* Tests for the GPX importer. * Tests for the GPX importer.
* *
* @author Steffen Horlacher * @author Steffen Horlacher
*/ */
public class GpxImporterTest extends AndroidTestCase { public class GpxImporterTest extends AndroidTestCase {
@@ -180,51 +180,45 @@ public class GpxImporterTest extends AndroidTestCase {
/** /**
* Test with invalid location - track should be deleted. * Test with invalid location - track should be deleted.
*/ */
public void testImportLocationFailure() throws ParserConfigurationException, public void testImportLocationFailure() throws ParserConfigurationException, IOException {
SAXException, IOException {
testInvalidXML(INVALID_LOCATION_TEST_GPX); testInvalidXML(INVALID_LOCATION_TEST_GPX);
} }
/** /**
* Test with invalid time - track should be deleted. * Test with invalid time - track should be deleted.
*/ */
public void testImportTimeFailure() throws ParserConfigurationException, public void testImportTimeFailure() throws ParserConfigurationException, IOException {
SAXException, IOException {
testInvalidXML(INVALID_TIME_TEST_GPX); testInvalidXML(INVALID_TIME_TEST_GPX);
} }
/** /**
* Test with invalid xml - track should be deleted. * Test with invalid xml - track should be deleted.
*/ */
public void testImportXMLFailure() throws ParserConfigurationException, public void testImportXMLFailure() throws ParserConfigurationException, IOException {
SAXException, IOException {
testInvalidXML(INVALID_XML_TEST_GPX); testInvalidXML(INVALID_XML_TEST_GPX);
} }
/** /**
* Test with invalid altitude - track should be deleted. * Test with invalid altitude - track should be deleted.
*/ */
public void testImportInvalidAltitude() throws ParserConfigurationException, public void testImportInvalidAltitude() throws ParserConfigurationException, IOException {
SAXException, IOException {
testInvalidXML(INVALID_ALTITUDE_TEST_GPX); testInvalidXML(INVALID_ALTITUDE_TEST_GPX);
} }
/** /**
* Test with invalid latitude - track should be deleted. * Test with invalid latitude - track should be deleted.
*/ */
public void testImportInvalidLatitude() throws ParserConfigurationException, public void testImportInvalidLatitude() throws ParserConfigurationException, IOException {
SAXException, IOException {
testInvalidXML(INVALID_LATITUDE_TEST_GPX); testInvalidXML(INVALID_LATITUDE_TEST_GPX);
} }
/** /**
* Test with invalid longitude - track should be deleted. * Test with invalid longitude - track should be deleted.
*/ */
public void testImportInvalidLongitude() throws ParserConfigurationException, public void testImportInvalidLongitude() throws ParserConfigurationException, IOException {
SAXException, IOException {
testInvalidXML(INVALID_LONGITUDE_TEST_GPX); testInvalidXML(INVALID_LONGITUDE_TEST_GPX);
} }
private void testInvalidXML(String xml) throws ParserConfigurationException, private void testInvalidXML(String xml) throws ParserConfigurationException,
IOException { IOException {
expect(providerUtils.insertTrack((Track) AndroidMock.anyObject())) expect(providerUtils.insertTrack((Track) AndroidMock.anyObject()))
@@ -31,9 +31,9 @@ public class KmlTrackWriterTest extends TrackFormatWriterTest {
} }
@Override @Override
public String generateTrackDescription(Track track, public String generateTrackDescription(Track trackToDescribe,
Vector<Double> distances, Vector<Double> elevations) { Vector<Double> distances, Vector<Double> elevations) {
assertSame(KmlTrackWriterTest.super.track, track); assertSame(KmlTrackWriterTest.super.track, trackToDescribe);
assertTrue(distances.isEmpty()); assertTrue(distances.isEmpty());
assertTrue(elevations.isEmpty()); assertTrue(elevations.isEmpty());
return FULL_TRACK_DESCRIPTION; return FULL_TRACK_DESCRIPTION;
@@ -59,6 +59,7 @@ public class ResultListAdapterTest extends AndroidTestCase {
this.urlId = urlId; this.urlId = urlId;
} }
@SuppressWarnings("hiding")
private void saveContentView(View contentView) { private void saveContentView(View contentView) {
if (this.contentView == null) { if (this.contentView == null) {
this.contentView = contentView; this.contentView = contentView;
@@ -331,7 +331,7 @@ public class TrackRecordingServiceTest
} }
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context ctx, Intent intent) {
Log.d("MyTracksTest", "Got broadcast: " + intent); Log.d("MyTracksTest", "Got broadcast: " + intent);
synchronized (receivedIntents) { synchronized (receivedIntents) {
receivedIntents.add(intent); receivedIntents.add(intent);
@@ -38,6 +38,7 @@ public class AntSensorManagerTest extends AndroidTestCase {
super.handleMessage(rawMessage); super.handleMessage(rawMessage);
} }
@SuppressWarnings("hiding")
@Override @Override
public boolean handleMessage(byte messageId, byte[] messageData) { public boolean handleMessage(byte messageId, byte[] messageData) {
this.messageId = messageId; this.messageId = messageId;
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2010 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
@@ -28,7 +28,7 @@ import java.util.List;
/** /**
* A class to monitor the network signal strength. * A class to monitor the network signal strength.
* *
* TODO: i18n * TODO: i18n
* *
* @author Sandor Dornbush * @author Sandor Dornbush
@@ -60,6 +60,7 @@ public class SignalStrengthListenerCupcake extends PhoneStateListener
return PhoneStateListener.LISTEN_SIGNAL_STRENGTH; return PhoneStateListener.LISTEN_SIGNAL_STRENGTH;
} }
@SuppressWarnings("hiding")
@Override @Override
public void onSignalStrengthChanged(int signalStrength) { public void onSignalStrengthChanged(int signalStrength) {
Log.d(TAG, "Signal Strength: " + signalStrength); Log.d(TAG, "Signal Strength: " + signalStrength);
@@ -95,7 +96,7 @@ public class SignalStrengthListenerCupcake extends PhoneStateListener
/** /**
* Builds a description for the current signal strength. * Builds a description for the current signal strength.
* *
* @return A human readable description of the network state * @return A human readable description of the network state
*/ */
private String getDescription() { private String getDescription() {
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2010 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
@@ -26,7 +26,7 @@ import android.util.Log;
/** /**
* A class to monitor the network signal strength. * A class to monitor the network signal strength.
* *
* TODO: i18n * TODO: i18n
* *
* @author Sandor Dornbush * @author Sandor Dornbush
@@ -44,6 +44,7 @@ public class SignalStrengthListenerEclair extends SignalStrengthListenerCupcake
return PhoneStateListener.LISTEN_SIGNAL_STRENGTHS; return PhoneStateListener.LISTEN_SIGNAL_STRENGTHS;
} }
@SuppressWarnings("hiding")
@Override @Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) { public void onSignalStrengthsChanged(SignalStrength signalStrength) {
Log.d(TAG, "Signal Strength Modern: " + signalStrength); Log.d(TAG, "Signal Strength Modern: " + signalStrength);
@@ -69,16 +69,16 @@ public class SignalStrengthService extends Service
@Override @Override
public void onStart(Intent intent, int startId) { public void onStart(Intent intent, int startId) {
handleCommand(intent, startId); handleCommand(intent);
} }
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
handleCommand(intent, startId); handleCommand(intent);
return START_STICKY; return START_STICKY;
} }
private void handleCommand(Intent intent, int startId) { private void handleCommand(Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if (START_SAMPLING.equals(action)) { if (START_SAMPLING.equals(action)) {
startSampling(); startSampling();