Clean up Constants.java

This commit is contained in:
Jimmy Shih
2013-05-15 16:26:44 -07:00
parent 5ace0242b4
commit 18eff91510
9 changed files with 188 additions and 195 deletions
@@ -16,7 +16,6 @@
package com.google.android.apps.mytracks; package com.google.android.apps.mytracks;
import static android.content.Intent.ACTION_BOOT_COMPLETED; 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 static com.google.android.apps.mytracks.Constants.TAG;
import com.google.android.apps.mytracks.services.RemoveTempFilesService; import com.google.android.apps.mytracks.services.RemoveTempFilesService;
@@ -49,7 +48,7 @@ public class BootReceiver extends BroadcastReceiver {
Log.d(TAG, "BootReceiver.onReceive: " + intent.getAction()); Log.d(TAG, "BootReceiver.onReceive: " + intent.getAction());
if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) { if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent startIntent = new Intent(context, TrackRecordingService.class) Intent startIntent = new Intent(context, TrackRecordingService.class)
.putExtra(RESUME_TRACK_EXTRA_NAME, true); .putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
context.startService(startIntent); context.startService(startIntent);
Intent removeTempFilesIntent = new Intent(context, RemoveTempFilesService.class); Intent removeTempFilesIntent = new Intent(context, RemoveTempFilesService.class);
@@ -13,118 +13,58 @@
* License for the specific language governing permissions and limitations under * License for the specific language governing permissions and limitations under
* the License. * the License.
*/ */
package com.google.android.apps.mytracks; package com.google.android.apps.mytracks;
/** /**
* Constants used by the MyTracks application. * Common constants.
* *
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
*/ */
public abstract class Constants { public class Constants {
private Constants() {}
/** /**
* Should be used by all log statements * The google account type.
*/
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.
*/ */
public static final String ACCOUNT_TYPE = "com.google"; public static final String ACCOUNT_TYPE = "com.google";
/** /**
* The name of extra intent property to indicate whether we want to resume * Maximum number of track points displayed by the map overlay. Set to 2X of
* a previously recorded track. * {@link Constants#TARGET_DISPLAYED_TRACK_POINTS}
*/ */
public static final String public static final int MAX_DISPLAYED_TRACK_POINTS = 10000;
RESUME_TRACK_EXTRA_NAME = "com.google.android.apps.mytracks.RESUME_TRACK";
/**
* 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"; 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;
} }
@@ -17,7 +17,6 @@
package com.google.android.apps.mytracks.content; 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_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 static com.google.android.apps.mytracks.Constants.TARGET_DISPLAYED_TRACK_POINTS;
import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.Constants;
@@ -53,6 +52,11 @@ public class TrackDataHub implements DataSourceListener {
private static final String TAG = TrackDataHub.class.getSimpleName(); 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 Context context;
private final TrackDataManager trackDataManager; private final TrackDataManager trackDataManager;
private final MyTracksProviderUtils myTracksProviderUtils; private final MyTracksProviderUtils myTracksProviderUtils;
@@ -16,8 +16,6 @@
package com.google.android.apps.mytracks.services; 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.Constants;
import com.google.android.apps.mytracks.TrackDetailActivity; import com.google.android.apps.mytracks.TrackDetailActivity;
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
@@ -82,6 +80,14 @@ import java.util.concurrent.Executors;
public class TrackRecordingService extends Service { public class TrackRecordingService extends Service {
private static final String TAG = TrackRecordingService.class.getSimpleName(); 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 PAUSE_LATITUDE = 100.0;
public static final double RESUME_LATITUDE = 200.0; public static final double RESUME_LATITUDE = 200.0;
@@ -18,7 +18,6 @@ package com.google.android.apps.mytracks.stats;
import static com.google.android.apps.mytracks.Constants.TAG; 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.services.TrackRecordingService;
import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@@ -36,6 +35,43 @@ import android.util.Log;
*/ */
public class TripStatisticsUpdater { 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 // The track's trip statistics
private final TripStatistics tripStatistics; private final TripStatistics tripStatistics;
@@ -49,17 +85,16 @@ public class TripStatisticsUpdater {
private Location lastMovingLocation; private Location lastMovingLocation;
// A buffer of the recent speed readings (m/s) for calculating max speed // 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) // A buffer of the recent elevation readings (m)
private final DoubleBuffer elevationBuffer = new DoubleBuffer( private final DoubleBuffer elevationBuffer = new DoubleBuffer(ELEVATION_SMOOTHING_FACTOR);
Constants.ELEVATION_SMOOTHING_FACTOR);
// A buffer of the recent distance readings (m) for calculating grade // 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 (%) // 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. * Creates a new trip statistics updater.
@@ -122,8 +157,7 @@ public class TripStatisticsUpdater {
return; return;
} }
double movingDistance = lastMovingLocation.distanceTo(location); double movingDistance = lastMovingLocation.distanceTo(location);
if (movingDistance < minRecordingDistance if (movingDistance < minRecordingDistance && location.getSpeed() < MAX_NO_MOVEMENT_SPEED) {
&& location.getSpeed() < Constants.MAX_NO_MOVEMENT_SPEED) {
updateTime(location.getTime()); updateTime(location.getTime());
lastLocation = location; lastLocation = location;
return; return;
@@ -258,7 +292,7 @@ public class TripStatisticsUpdater {
*/ */
long timeDifference = time - lastLocationTime; long timeDifference = time - lastLocationTime;
double speedDifference = Math.abs(lastLocationSpeed - speed); double speedDifference = Math.abs(lastLocationSpeed - speed);
if (speedDifference > Constants.MAX_ACCELERATION * timeDifference) { if (speedDifference > MAX_ACCELERATION * timeDifference) {
return false; return false;
} }
@@ -272,6 +306,6 @@ public class TripStatisticsUpdater {
} }
double average = speedBuffer.getAverage(); double average = speedBuffer.getAverage();
double diff = Math.abs(average - speed); double diff = Math.abs(average - speed);
return (speed < average * 10) && (diff < Constants.MAX_ACCELERATION * timeDifference); return (speed < average * 10) && (diff < MAX_ACCELERATION * timeDifference);
} }
} }
@@ -15,7 +15,6 @@
*/ */
package com.google.android.apps.mytracks.util; package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.Constants;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import android.os.Environment; import android.os.Environment;
@@ -31,6 +30,13 @@ public class FileUtils {
private 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 * The maximum FAT32 path length. See the FAT32 spec at
* http://msdn.microsoft.com/en-us/windows/hardware/gg463080 * http://msdn.microsoft.com/en-us/windows/hardware/gg463080
@@ -88,7 +94,7 @@ public class FileUtils {
StringBuilder dirNameBuilder = new StringBuilder(); StringBuilder dirNameBuilder = new StringBuilder();
dirNameBuilder.append(Environment.getExternalStorageDirectory()); dirNameBuilder.append(Environment.getExternalStorageDirectory());
dirNameBuilder.append(File.separatorChar); dirNameBuilder.append(File.separatorChar);
dirNameBuilder.append(Constants.SDCARD_TOP_DIR); dirNameBuilder.append(SDCARD_TOP_DIR);
for (String component : components) { for (String component : components) {
dirNameBuilder.append(File.separatorChar); dirNameBuilder.append(File.separatorChar);
dirNameBuilder.append(component); dirNameBuilder.append(component);
@@ -15,8 +15,6 @@
*/ */
package com.google.android.apps.mytracks.services; 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.Constants;
import com.google.android.apps.mytracks.content.MyTracksProvider; import com.google.android.apps.mytracks.content.MyTracksProvider;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
@@ -57,13 +55,13 @@ import java.util.List;
/** /**
* Tests for the MyTracks track recording service. * Tests for the MyTracks track recording service.
* <p>
* 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 * @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<TestRecordingService> { public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingService> {
@@ -71,9 +69,9 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
private MyTracksProviderUtils providerUtils; private MyTracksProviderUtils providerUtils;
/* /*
* In order to support starting and binding to the service in the same * In order to support starting and binding to the service in the same unit
* unit test, we provide a workaround, as the original class doesn't allow * test, we provide a workaround, as the original class doesn't allow to bind
* to bind after the service has been previously started. * after the service has been previously started.
*/ */
private boolean bound; private boolean bound;
@@ -84,9 +82,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
} }
/** /**
* A context wrapper with the user provided {@link ContentResolver}. * A context wrapper with the user provided {@link ContentResolver}. TODO:
* * Move to test utils package.
* TODO: Move to test utils package.
*/ */
public static class MockContext extends ContextWrapper { public static class MockContext extends ContextWrapper {
private final ContentResolver contentResolver; private final ContentResolver contentResolver;
@@ -106,8 +103,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
protected IBinder bindService(Intent intent) { protected IBinder bindService(Intent intent) {
if (getService() != null) { if (getService() != null) {
if (bound) { if (bound) {
throw new IllegalStateException( throw new IllegalStateException("Service: " + getService() + " is already bound");
"Service: " + getService() + " is already bound");
} }
bound = true; bound = true;
serviceIntent = intent.cloneFilter(); serviceIntent = intent.cloneFilter();
@@ -150,6 +146,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
public Bundle call(String method, String arg, Bundle extras) { public Bundle call(String method, String arg, Bundle extras) {
return null; return null;
} }
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) { String sortOrder) {
@@ -163,6 +160,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
public Bundle call(String method, String arg, Bundle extras) { public Bundle call(String method, String arg, Bundle extras) {
return null; return null;
} }
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) { String sortOrder) {
@@ -171,14 +169,17 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
public int getCount() { public int getCount() {
return 1; return 1;
} }
@Override @Override
public boolean moveToNext() { public boolean moveToNext() {
return true; return true;
} }
@Override @Override
public String getString(int columnIndex) { public String getString(int columnIndex) {
return MyTracksLocationManager.USE_LOCATION_FOR_SERVICES_ON; return MyTracksLocationManager.USE_LOCATION_FOR_SERVICES_ON;
} }
@Override @Override
public void close() {} public void close() {}
}; };
@@ -227,7 +228,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
// Start the service in "resume" mode (simulates the on-reboot action). // Start the service in "resume" mode (simulates the on-reboot action).
Intent startIntent = createStartIntent(); Intent startIntent = createStartIntent();
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true); startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
startService(startIntent); startService(startIntent);
assertNotNull(getService()); assertNotNull(getService());
@@ -237,12 +238,13 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
assertEquals(123L, service.getRecordingTrackId()); assertEquals(123L, service.getRecordingTrackId());
} }
// TODO: shutdownService() has a bug and doesn't set mServiceCreated /*
// to false, thus preventing from a second call to onCreate(). * TODO: shutdownService() has a bug and doesn't set mServiceCreated to false,
// Report the bug to Android team. Until then, the following tests * thus preventing from a second call to onCreate(). Report the bug to Android
// and checks must be commented out. * team. Until then, the following tests and checks must be commented out.
// *
// TODO: If fixed, remove "disabled" prefix from the test name. * TODO: If fixed, remove "disabled" prefix from the test name.
*/
@MediumTest @MediumTest
public void disabledTestResumeAfterReboot_simulateReboot() throws Exception { public void disabledTestResumeAfterReboot_simulateReboot() throws Exception {
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT, updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
@@ -259,7 +261,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
// Start the service in "resume" mode (simulates the on-reboot action). // Start the service in "resume" mode (simulates the on-reboot action).
Intent startIntent = createStartIntent(); Intent startIntent = createStartIntent();
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true); startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
startService(startIntent); startService(startIntent);
assertNotNull(getService()); assertNotNull(getService());
@@ -277,7 +279,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
// Start the service in "resume" mode (simulates the on-reboot action). // Start the service in "resume" mode (simulates the on-reboot action).
Intent startIntent = createStartIntent(); Intent startIntent = createStartIntent();
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true); startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
startService(startIntent); startService(startIntent);
assertNotNull(getService()); assertNotNull(getService());
@@ -298,7 +300,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
// Start the service in "resume" mode (simulates the on-reboot action). // Start the service in "resume" mode (simulates the on-reboot action).
Intent startIntent = createStartIntent(); Intent startIntent = createStartIntent();
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true); startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
startService(startIntent); startService(startIntent);
assertNotNull(getService()); assertNotNull(getService());
@@ -319,7 +321,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
// Start the service in "resume" mode (simulates the on-reboot action). // Start the service in "resume" mode (simulates the on-reboot action).
Intent startIntent = createStartIntent(); Intent startIntent = createStartIntent();
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true); startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
startService(startIntent); startService(startIntent);
assertNotNull(getService()); assertNotNull(getService());
@@ -437,8 +439,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
assertEquals(1, receivedIntents.size()); assertEquals(1, receivedIntents.size());
Intent broadcastIntent = receivedIntents.get(0); Intent broadcastIntent = receivedIntents.get(0);
assertEquals(startAction, broadcastIntent.getAction()); assertEquals(startAction, broadcastIntent.getAction());
assertEquals(id, broadcastIntent.getLongExtra( assertEquals(id,
context.getString(R.string.track_id_broadcast_extra), -1L)); broadcastIntent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L));
context.unregisterReceiver(startReceiver); context.unregisterReceiver(startReceiver);
} }
@@ -483,8 +485,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
assertEquals(1, receivedIntents.size()); assertEquals(1, receivedIntents.size());
Intent broadcastIntent = receivedIntents.get(0); Intent broadcastIntent = receivedIntents.get(0);
assertEquals(stopAction, broadcastIntent.getAction()); assertEquals(stopAction, broadcastIntent.getAction());
assertEquals(123L, broadcastIntent.getLongExtra( assertEquals(123L,
context.getString(R.string.track_id_broadcast_extra), -1L)); broadcastIntent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L));
context.unregisterReceiver(stopReceiver); context.unregisterReceiver(stopReceiver);
} }
@@ -494,7 +496,10 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
ITrackRecordingService service = bindAndGetService(createStartIntent()); ITrackRecordingService service = bindAndGetService(createStartIntent());
assertFalse(service.isRecording()); assertFalse(service.isRecording());
// Ending the current track when there is no recording should not result in any error. /*
* Ending the current track when there is no recording should not result in
* any error.
*/
service.endCurrentTrack(); service.endCurrentTrack();
assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT,
@@ -562,8 +567,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
assertEquals(1, service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT)); assertEquals(1, service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT));
Waypoint wpt = providerUtils.getWaypoint(1); Waypoint wpt = providerUtils.getWaypoint(1);
assertEquals(getContext().getString(R.string.marker_waypoint_icon_url), assertEquals(getContext().getString(R.string.marker_waypoint_icon_url), wpt.getIcon());
wpt.getIcon());
assertEquals(getContext().getString(R.string.marker_name_format, 1), wpt.getName()); assertEquals(getContext().getString(R.string.marker_name_format, 1), wpt.getName());
assertEquals(WaypointType.WAYPOINT, wpt.getType()); assertEquals(WaypointType.WAYPOINT, wpt.getType());
assertEquals(123L, wpt.getTrackId()); assertEquals(123L, wpt.getTrackId());
@@ -574,8 +578,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
@MediumTest @MediumTest
public void testWithProperties_voiceFrequencyDefault() throws Exception { public void testWithProperties_voiceFrequencyDefault() throws Exception {
PreferencesUtils.setInt(context, R.string.voice_frequency_key, PreferencesUtils.setInt(
PreferencesUtils.VOICE_FREQUENCY_DEFAULT); context, R.string.voice_frequency_key, PreferencesUtils.VOICE_FREQUENCY_DEFAULT);
fullRecordingSession(); fullRecordingSession();
} }
@@ -619,8 +623,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
@MediumTest @MediumTest
public void testWithProperties_splitFrequencyDefault() throws Exception { public void testWithProperties_splitFrequencyDefault() throws Exception {
PreferencesUtils.setInt(context, R.string.split_frequency_key, PreferencesUtils.setInt(
PreferencesUtils.SPLIT_FREQUENCY_DEFAULT); context, R.string.split_frequency_key, PreferencesUtils.SPLIT_FREQUENCY_DEFAULT);
fullRecordingSession(); fullRecordingSession();
} }
@@ -690,8 +694,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
} }
private ITrackRecordingService bindAndGetService(Intent intent) { private ITrackRecordingService bindAndGetService(Intent intent) {
ITrackRecordingService service = ITrackRecordingService.Stub.asInterface( ITrackRecordingService service = ITrackRecordingService.Stub.asInterface(bindService(intent));
bindService(intent));
assertNotNull(service); assertNotNull(service);
return service; return service;
} }
@@ -722,8 +725,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
assertTrue(track.getId() >= 0); assertTrue(track.getId() >= 0);
providerUtils.insertTrack(track); providerUtils.insertTrack(track);
assertEquals(track.getId(), providerUtils.getTrack(track.getId()).getId()); assertEquals(track.getId(), providerUtils.getTrack(track.getId()).getId());
PreferencesUtils.setLong(context, R.string.recording_track_id_key, isRecording ? track.getId() PreferencesUtils.setLong(context, R.string.recording_track_id_key,
: PreferencesUtils.RECORDING_TRACK_ID_DEFAULT); isRecording ? track.getId() : PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, !isRecording); PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, !isRecording);
} }
@@ -760,7 +763,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
} }
} }
// Stop the track. Validate if it has correct data. // Stop the track. Validate if it has correct data.
service.endCurrentTrack(); service.endCurrentTrack();
assertFalse(service.isRecording()); assertFalse(service.isRecording());
assertEquals(-1L, service.getRecordingTrackId()); assertEquals(-1L, service.getRecordingTrackId());
@@ -2,7 +2,6 @@
package com.google.android.apps.mytracks.stats; package com.google.android.apps.mytracks.stats;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
import android.location.Location; import android.location.Location;
@@ -103,21 +102,22 @@ public class TripStatisticsUpdaterTest extends TestCase {
public void testElevationGain() throws Exception { public void testElevationGain() throws Exception {
for (double i = 0; i < 1000; i++) { for (double i = 0; i < 1000; i++) {
double expectedGain; double expectedGain;
if (i < Constants.ELEVATION_SMOOTHING_FACTOR - 1) { if (i < TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR - 1) {
expectedGain = 0; expectedGain = 0;
} else if (i < Constants.ELEVATION_SMOOTHING_FACTOR) { } else if (i < TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
expectedGain = 0.5; expectedGain = 0.5;
} else { } else {
expectedGain = 1.0; expectedGain = 1.0;
} }
assertEquals(expectedGain, tripStatisticsUpdater.updateElevation(i)); assertEquals(expectedGain, tripStatisticsUpdater.updateElevation(i));
assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(), assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(),
Constants.ELEVATION_SMOOTHING_FACTOR / 2); TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
TripStatistics data = tripStatisticsUpdater.getTripStatistics(); TripStatistics data = tripStatisticsUpdater.getTripStatistics();
assertEquals(0.0, data.getMinElevation()); assertEquals(0.0, data.getMinElevation());
assertEquals(i, data.getMaxElevation(), Constants.ELEVATION_SMOOTHING_FACTOR / 2); assertEquals(i, data.getMaxElevation(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
assertEquals(i, data.getTotalElevationGain(), Constants.ELEVATION_SMOOTHING_FACTOR); assertEquals(
i, data.getTotalElevationGain(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
} }
} }
@@ -133,7 +133,8 @@ public class TripStatisticsUpdaterTest extends TestCase {
*/ */
tripStatisticsUpdater.updateElevation(i); tripStatisticsUpdater.updateElevation(i);
tripStatisticsUpdater.updateGrade(100, 100); tripStatisticsUpdater.updateGrade(100, 100);
if (i >= Constants.GRADE_SMOOTHING_FACTOR && i >= Constants.ELEVATION_SMOOTHING_FACTOR) { if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR
&& i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade()); assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade()); assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
} }
@@ -145,7 +146,8 @@ public class TripStatisticsUpdaterTest extends TestCase {
*/ */
tripStatisticsUpdater.updateElevation(i); tripStatisticsUpdater.updateElevation(i);
tripStatisticsUpdater.updateGrade(100, -100); tripStatisticsUpdater.updateGrade(100, -100);
if (i >= Constants.GRADE_SMOOTHING_FACTOR && i >= Constants.ELEVATION_SMOOTHING_FACTOR) { if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR
&& i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade()); assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
assertEquals(-1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade()); assertEquals(-1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
} }
@@ -164,10 +166,10 @@ public class TripStatisticsUpdaterTest extends TestCase {
*/ */
tripStatisticsUpdater.updateElevation(i); tripStatisticsUpdater.updateElevation(i);
tripStatisticsUpdater.updateGrade(1, 100); tripStatisticsUpdater.updateGrade(1, 100);
assertEquals(Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics() assertEquals(
.getMaxGrade()); Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
assertEquals(Double.POSITIVE_INFINITY, tripStatisticsUpdater.getTripStatistics() assertEquals(
.getMinGrade()); Double.POSITIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMinGrade());
} }
} }
@@ -210,7 +212,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
double speed = 4.0; double speed = 4.0;
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
tripStatisticsUpdater.updateSpeed(i + ONE_SECOND, speed, i, speed); tripStatisticsUpdater.updateSpeed(i + ONE_SECOND, speed, i, speed);
if (i >= Constants.SPEED_SMOOTHING_FACTOR) { if (i >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
assertEquals(speed, tripStatisticsUpdater.getTripStatistics().getMaxSpeed()); assertEquals(speed, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
} }
} }
@@ -231,28 +233,29 @@ public class TripStatisticsUpdaterTest extends TestCase {
// Going up by 1 meter each time. // Going up by 1 meter each time.
// Moving by .001 degree latitude (111 meters). // Moving by .001 degree latitude (111 meters).
// Each time slice is 10 seconds. // Each time slice is 10 seconds.
Location location = getLocation(i + locationOffset, (i + locationOffset) * .001, Location location = getLocation(i + locationOffset, (i + locationOffset) * .001, MOVING_SPEED,
MOVING_SPEED, startTime + (timeOffset + i) * TEN_SECONDS); startTime + (timeOffset + i) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT); tripStatisticsUpdater.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
tripStatistics = tripStatisticsUpdater.getTripStatistics(); tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime()); assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime());
assertEquals((locationOffset + i) * TEN_SECONDS, tripStatistics.getMovingTime()); assertEquals((locationOffset + i) * TEN_SECONDS, tripStatistics.getMovingTime());
assertEquals(i + locationOffset, tripStatisticsUpdater.getSmoothedElevation(), assertEquals(i + locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
Constants.ELEVATION_SMOOTHING_FACTOR / 2); TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
assertEquals(0.0, tripStatistics.getMinElevation()); assertEquals(0.0, tripStatistics.getMinElevation());
assertEquals(i + locationOffset, tripStatistics.getMaxElevation(), assertEquals(i + locationOffset, tripStatistics.getMaxElevation(),
Constants.ELEVATION_SMOOTHING_FACTOR / 2); TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
assertEquals(i + locationOffset, tripStatistics.getTotalElevationGain(), assertEquals(i + locationOffset, tripStatistics.getTotalElevationGain(),
Constants.ELEVATION_SMOOTHING_FACTOR); TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
if (i + locationOffset >= Constants.SPEED_SMOOTHING_FACTOR) { if (i + locationOffset >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1); assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
} }
// If there are only moving locations in the track. // If there are only moving locations in the track.
if (locationOffset == 0 && (i + locationOffset) >= Constants.DISTANCE_SMOOTHING_FACTOR if (locationOffset == 0
&& (i + locationOffset) >= Constants.ELEVATION_SMOOTHING_FACTOR) { && (i + locationOffset) >= TripStatisticsUpdater.DISTANCE_SMOOTHING_FACTOR
&& (i + locationOffset) >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
// 1 m / 111 m = .009 // 1 m / 111 m = .009
assertEquals(0.009, tripStatistics.getMinGrade(), 0.0001); assertEquals(0.009, tripStatistics.getMinGrade(), 0.0001);
assertEquals(0.009, tripStatistics.getMaxGrade(), 0.0001); assertEquals(0.009, tripStatistics.getMaxGrade(), 0.0001);
@@ -274,26 +277,26 @@ public class TripStatisticsUpdaterTest extends TestCase {
private void addWaitLocations(int points, long startTime, TripStatistics tripStatistics, private void addWaitLocations(int points, long startTime, TripStatistics tripStatistics,
int timeOffset, int locationOffset) { int timeOffset, int locationOffset) {
for (int i = 0; i < points; i++) { for (int i = 0; i < points; i++) {
Location location = getLocation(locationOffset, locationOffset * .001, 0, startTime Location location = getLocation(
+ (i + timeOffset) * TEN_SECONDS); locationOffset, locationOffset * .001, 0, startTime + (i + timeOffset) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT); tripStatisticsUpdater.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
tripStatistics = tripStatisticsUpdater.getTripStatistics(); tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime()); assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime());
assertEquals((locationOffset) * TEN_SECONDS, tripStatistics.getMovingTime()); assertEquals((locationOffset) * TEN_SECONDS, tripStatistics.getMovingTime());
assertEquals(locationOffset, tripStatisticsUpdater.getSmoothedElevation(), assertEquals(locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
Constants.ELEVATION_SMOOTHING_FACTOR / 2); TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
assertEquals(0.0, tripStatistics.getMinElevation()); assertEquals(0.0, tripStatistics.getMinElevation());
assertEquals(locationOffset, tripStatistics.getMaxElevation(), assertEquals(locationOffset, tripStatistics.getMaxElevation(),
Constants.ELEVATION_SMOOTHING_FACTOR / 2); TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
assertEquals(locationOffset, tripStatistics.getTotalElevationGain(), assertEquals(locationOffset, tripStatistics.getTotalElevationGain(),
Constants.ELEVATION_SMOOTHING_FACTOR); TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
if (locationOffset >= Constants.SPEED_SMOOTHING_FACTOR) { if (locationOffset >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1); assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
} }
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1); assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
assertEquals(locationOffset * 111.0, tripStatistics.getTotalDistance(), assertEquals(
locationOffset * 111.0 * 0.01); locationOffset * 111.0, tripStatistics.getTotalDistance(), locationOffset * 111.0 * 0.01);
} }
} }
@@ -15,8 +15,6 @@
*/ */
package com.google.android.apps.mytracks.util; package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.Constants;
import android.os.Environment; import android.os.Environment;
import java.io.File; import java.io.File;
@@ -35,7 +33,7 @@ public class FileUtilsTest extends TestCase {
*/ */
public void testBuildExternalDirectoryPath() { public void testBuildExternalDirectoryPath() {
String expectedName = Environment.getExternalStorageDirectory() + File.separator String expectedName = Environment.getExternalStorageDirectory() + File.separator
+ Constants.SDCARD_TOP_DIR + File.separator + "a" + File.separator + "b" + File.separator + FileUtils.SDCARD_TOP_DIR + File.separator + "a" + File.separator + "b" + File.separator
+ "c"; + "c";
String dirName = FileUtils.buildExternalDirectoryPath("a", "b", "c"); String dirName = FileUtils.buildExternalDirectoryPath("a", "b", "c");
assertEquals(expectedName, dirName); assertEquals(expectedName, dirName);