diff --git a/MyTracks/src/com/google/android/apps/mytracks/BootReceiver.java b/MyTracks/src/com/google/android/apps/mytracks/BootReceiver.java index 248735b7f..5b227c6a0 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/BootReceiver.java +++ b/MyTracks/src/com/google/android/apps/mytracks/BootReceiver.java @@ -16,7 +16,6 @@ package com.google.android.apps.mytracks; import static android.content.Intent.ACTION_BOOT_COMPLETED; -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.services.RemoveTempFilesService; @@ -49,7 +48,7 @@ public class BootReceiver extends BroadcastReceiver { Log.d(TAG, "BootReceiver.onReceive: " + intent.getAction()); if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) { Intent startIntent = new Intent(context, TrackRecordingService.class) - .putExtra(RESUME_TRACK_EXTRA_NAME, true); + .putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true); context.startService(startIntent); Intent removeTempFilesIntent = new Intent(context, RemoveTempFilesService.class); diff --git a/MyTracks/src/com/google/android/apps/mytracks/Constants.java b/MyTracks/src/com/google/android/apps/mytracks/Constants.java index b6e1066f2..ee5e9cf38 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/Constants.java +++ b/MyTracks/src/com/google/android/apps/mytracks/Constants.java @@ -13,118 +13,58 @@ * License for the specific language governing permissions and limitations under * the License. */ + package com.google.android.apps.mytracks; /** - * Constants used by the MyTracks application. - * + * Common constants. + * * @author Leif Hendrik Wilden */ -public abstract class Constants { +public class Constants { + + private Constants() {} /** - * Should be used by all log statements - */ - public static final String TAG = "MyTracks"; - - /** - * Name of the top-level directory inside the SD card where our files will - * be read from/written to. - */ - public static final String SDCARD_TOP_DIR = "MyTracks"; - - /** - * The number of distance readings to smooth to get a stable signal. - */ - public static final int DISTANCE_SMOOTHING_FACTOR = 25; - - /** - * The number of elevation readings to smooth to get a somewhat accurate - * signal. - */ - public static final int ELEVATION_SMOOTHING_FACTOR = 25; - - /** - * The number of grade readings to smooth to get a somewhat accurate signal. - */ - public static final int GRADE_SMOOTHING_FACTOR = 5; - - /** - * The number of speed reading to smooth to get a somewhat accurate signal. - */ - public static final int SPEED_SMOOTHING_FACTOR = 25; - - /** - * Maximum number of track points displayed by the map overlay. - */ - public static final int MAX_DISPLAYED_TRACK_POINTS = 10000; - - /** - * Target number of track points displayed by the map overlay. - * We may display more than this number of points. - */ - public static final int TARGET_DISPLAYED_TRACK_POINTS = 5000; - - /** - * Maximum number of track points ever loaded at once from the provider into - * memory. - * With a recording frequency of 2 seconds, 15000 corresponds to 8.3 hours. - */ - public static final int MAX_LOADED_TRACK_POINTS = 20000; - - /** - * Maximum number of track points ever loaded at once from the provider into - * memory in a single call to read points. - */ - public static final int MAX_LOADED_TRACK_POINTS_PER_BATCH = 1000; - - /** - * Maximum number of way points displayed by the map overlay. - */ - public static final int MAX_DISPLAYED_WAYPOINTS_POINTS = 128; - - /** - * Maximum number of way points that will be loaded at one time. - */ - public static final int MAX_LOADED_WAYPOINTS_POINTS = 10000; - - /** - * Any time segment where the distance traveled is less than this value will - * not be considered moving. - */ - public static final double MAX_NO_MOVEMENT_DISTANCE = 2; - - /** - * Anything faster than that (in meters per second) will be considered moving. - */ - public static final double MAX_NO_MOVEMENT_SPEED = 0.224; - - /** - * Ignore any acceleration faster than this. - * Will ignore any speeds that imply accelaration greater than 2g's - * 2g = 19.6 m/s^2 = 0.0002 m/ms^2 = 0.02 m/(m*ms) - */ - public static final double MAX_ACCELERATION = 0.02; - - /** Maximum age of a GPS location to be considered current. */ - public static final long MAX_LOCATION_AGE_MS = 60 * 1000; // 1 minute - - /** - * The type of account that we can use for gdata uploads. + * The google account type. */ public static final String ACCOUNT_TYPE = "com.google"; /** - * The name of extra intent property to indicate whether we want to resume - * a previously recorded track. + * Maximum number of track points displayed by the map overlay. Set to 2X of + * {@link Constants#TARGET_DISPLAYED_TRACK_POINTS} */ - public static final String - RESUME_TRACK_EXTRA_NAME = "com.google.android.apps.mytracks.RESUME_TRACK"; + public static final int MAX_DISPLAYED_TRACK_POINTS = 10000; + /** + * Maximum number of waypoints displayed by the map overlay. + */ + public static final int MAX_DISPLAYED_WAYPOINTS_POINTS = 128; + + /** + * Maximum number of track points that will be loaded at one time. With + * recording frequency of 2 seconds, 20000 corresponds to 11.1 hours. + */ + public static final int MAX_LOADED_TRACK_POINTS = 20000; + + /** + * Maximum number of waypoints that will be loaded at one time. + */ + public static final int MAX_LOADED_WAYPOINTS_POINTS = 10000; + + /** + * The settings file name. + */ public static final String SETTINGS_NAME = "SettingsActivity"; /** - * This is an abstract utility class. + * The log tag. */ - protected Constants() { } + public static final String TAG = "MyTracks"; + + /** + * Target number of track points displayed by the map overlay. We may display + * more than this number of points. + */ + public static final int TARGET_DISPLAYED_TRACK_POINTS = 5000; } diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java b/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java index 65189d67d..1a7d929c3 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java +++ b/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java @@ -17,7 +17,6 @@ package com.google.android.apps.mytracks.content; import static com.google.android.apps.mytracks.Constants.MAX_DISPLAYED_WAYPOINTS_POINTS; -import static com.google.android.apps.mytracks.Constants.MAX_LOCATION_AGE_MS; import static com.google.android.apps.mytracks.Constants.TARGET_DISPLAYED_TRACK_POINTS; import com.google.android.apps.mytracks.Constants; @@ -53,6 +52,11 @@ public class TrackDataHub implements DataSourceListener { private static final String TAG = TrackDataHub.class.getSimpleName(); + /** + * Maximum age of a location to be considered current. + */ + private static final long MAX_LOCATION_AGE_MS = 60 * 1000; // 1 minute + private final Context context; private final TrackDataManager trackDataManager; private final MyTracksProviderUtils myTracksProviderUtils; 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 beb95ea1c..56423f5c1 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -16,8 +16,6 @@ package com.google.android.apps.mytracks.services; -import static com.google.android.apps.mytracks.Constants.RESUME_TRACK_EXTRA_NAME; - import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.TrackDetailActivity; import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; @@ -82,6 +80,14 @@ import java.util.concurrent.Executors; public class TrackRecordingService extends Service { private static final String TAG = TrackRecordingService.class.getSimpleName(); + + /** + * The name of extra intent property to indicate whether we want to resume a + * previously recorded track. + */ + public static final String + RESUME_TRACK_EXTRA_NAME = "com.google.android.apps.mytracks.RESUME_TRACK"; + public static final double PAUSE_LATITUDE = 100.0; public static final double RESUME_LATITUDE = 200.0; diff --git a/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java b/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java index 9b18f8ced..f58ea4993 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java +++ b/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java @@ -18,7 +18,6 @@ package com.google.android.apps.mytracks.stats; import static com.google.android.apps.mytracks.Constants.TAG; -import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.services.TrackRecordingService; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.common.annotations.VisibleForTesting; @@ -36,6 +35,43 @@ import android.util.Log; */ public class TripStatisticsUpdater { + /** + * The number of distance readings to smooth to get a stable signal. + */ + @VisibleForTesting + static final int DISTANCE_SMOOTHING_FACTOR = 25; + + /** + * The number of elevation readings to smooth to get a somewhat accurate + * signal. + */ + @VisibleForTesting + static final int ELEVATION_SMOOTHING_FACTOR = 25; + + /** + * The number of grade readings to smooth to get a somewhat accurate signal. + */ + @VisibleForTesting + static final int GRADE_SMOOTHING_FACTOR = 5; + + /** + * The number of speed reading to smooth to get a somewhat accurate signal. + */ + @VisibleForTesting + static final int SPEED_SMOOTHING_FACTOR = 25; + + /** + * Anything faster than that (in meters per second) will be considered moving. + */ + private static final double MAX_NO_MOVEMENT_SPEED = 0.224; + + /** + * Ignore any acceleration faster than this. Will ignore any speeds that imply + * accelaration greater than 2g's 2g = 19.6 m/s^2 = 0.0002 m/ms^2 = 0.02 + * m/(m*ms) + */ + private static final double MAX_ACCELERATION = 0.02; + // The track's trip statistics private final TripStatistics tripStatistics; @@ -49,17 +85,16 @@ public class TripStatisticsUpdater { private Location lastMovingLocation; // A buffer of the recent speed readings (m/s) for calculating max speed - private final DoubleBuffer speedBuffer = new DoubleBuffer(Constants.SPEED_SMOOTHING_FACTOR); + private final DoubleBuffer speedBuffer = new DoubleBuffer(SPEED_SMOOTHING_FACTOR); // A buffer of the recent elevation readings (m) - private final DoubleBuffer elevationBuffer = new DoubleBuffer( - Constants.ELEVATION_SMOOTHING_FACTOR); + private final DoubleBuffer elevationBuffer = new DoubleBuffer(ELEVATION_SMOOTHING_FACTOR); // A buffer of the recent distance readings (m) for calculating grade - private final DoubleBuffer distanceBuffer = new DoubleBuffer(Constants.DISTANCE_SMOOTHING_FACTOR); + private final DoubleBuffer distanceBuffer = new DoubleBuffer(DISTANCE_SMOOTHING_FACTOR); // A buffer of the recent grade calculations (%) - private final DoubleBuffer gradeBuffer = new DoubleBuffer(Constants.GRADE_SMOOTHING_FACTOR); + private final DoubleBuffer gradeBuffer = new DoubleBuffer(GRADE_SMOOTHING_FACTOR); /** * Creates a new trip statistics updater. @@ -122,8 +157,7 @@ public class TripStatisticsUpdater { return; } double movingDistance = lastMovingLocation.distanceTo(location); - if (movingDistance < minRecordingDistance - && location.getSpeed() < Constants.MAX_NO_MOVEMENT_SPEED) { + if (movingDistance < minRecordingDistance && location.getSpeed() < MAX_NO_MOVEMENT_SPEED) { updateTime(location.getTime()); lastLocation = location; return; @@ -258,7 +292,7 @@ public class TripStatisticsUpdater { */ long timeDifference = time - lastLocationTime; double speedDifference = Math.abs(lastLocationSpeed - speed); - if (speedDifference > Constants.MAX_ACCELERATION * timeDifference) { + if (speedDifference > MAX_ACCELERATION * timeDifference) { return false; } @@ -272,6 +306,6 @@ public class TripStatisticsUpdater { } double average = speedBuffer.getAverage(); double diff = Math.abs(average - speed); - return (speed < average * 10) && (diff < Constants.MAX_ACCELERATION * timeDifference); + return (speed < average * 10) && (diff < MAX_ACCELERATION * timeDifference); } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/FileUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/FileUtils.java index 659552e65..f0ebbabd9 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/FileUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/FileUtils.java @@ -15,7 +15,6 @@ */ package com.google.android.apps.mytracks.util; -import com.google.android.apps.mytracks.Constants; import com.google.common.annotations.VisibleForTesting; import android.os.Environment; @@ -31,6 +30,13 @@ public class FileUtils { private FileUtils() {} + /** + * Name of the top-level directory inside the SD card where our files will be + * read from/written to. + */ + @VisibleForTesting + static final String SDCARD_TOP_DIR = "MyTracks"; + /** * The maximum FAT32 path length. See the FAT32 spec at * http://msdn.microsoft.com/en-us/windows/hardware/gg463080 @@ -88,7 +94,7 @@ public class FileUtils { StringBuilder dirNameBuilder = new StringBuilder(); dirNameBuilder.append(Environment.getExternalStorageDirectory()); dirNameBuilder.append(File.separatorChar); - dirNameBuilder.append(Constants.SDCARD_TOP_DIR); + dirNameBuilder.append(SDCARD_TOP_DIR); for (String component : components) { dirNameBuilder.append(File.separatorChar); dirNameBuilder.append(component); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java index 0195fc5b0..a2431ad6a 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java @@ -15,8 +15,6 @@ */ package com.google.android.apps.mytracks.services; -import static com.google.android.apps.mytracks.Constants.RESUME_TRACK_EXTRA_NAME; - import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.content.MyTracksProvider; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; @@ -57,13 +55,13 @@ import java.util.List; /** * Tests for the MyTracks track recording service. - * + *
+ * TODO: The original class, ServiceTestCase, has a few limitations, e.g. it's
+ * not possible to properly shutdown the service, unless tearDown() is called,
+ * which prevents from testing multiple scenarios in a single test (see
+ * runFunctionTest for more details).
+ *
* @author Bartlomiej Niechwiej
- *
- * TODO: The original class, ServiceTestCase, has a few limitations, e.g.
- * it's not possible to properly shutdown the service, unless tearDown()
- * is called, which prevents from testing multiple scenarios in a single
- * test (see runFunctionTest for more details).
*/
public class TrackRecordingServiceTest extends ServiceTestCase