Update MyTracksProviderUtils api to make it clear

the valid values that can be used.
This commit is contained in:
Jimmy Shih
2012-12-18 15:02:50 -08:00
parent f94d27acca
commit 11ca9cc450
15 changed files with 72 additions and 48 deletions
+1 -1
View File
@@ -2,8 +2,8 @@
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="con" path="com.google.gdt.eclipse.managedapis.MANAGED_API_CONTAINER/drive-v2r30lv1.12.0-beta"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.google.gdt.eclipse.managedapis.MANAGED_API_CONTAINER/drive-v2r30lv1.12.0-beta"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
@@ -565,7 +565,7 @@ public class TrackDataHub implements DataSourceListener {
Cursor cursor = null;
try {
cursor = myTracksProviderUtils.getWaypointCursor(
selectedTrackId, 0L, MAX_DISPLAYED_WAYPOINTS_POINTS);
selectedTrackId, -1L, MAX_DISPLAYED_WAYPOINTS_POINTS);
if (cursor != null && cursor.moveToFirst()) {
do {
Waypoint waypoint = myTracksProviderUtils.createWaypoint(cursor);
@@ -242,7 +242,7 @@ class TrackWriterImpl implements TrackWriter {
// problem because we don't try to load them into objects all at the
// same time.
Cursor cursor = null;
cursor = providerUtils.getWaypointCursor(trackId, 0,
cursor = providerUtils.getWaypointCursor(trackId, -1L,
Constants.MAX_LOADED_WAYPOINTS_POINTS);
boolean hasWaypoints = false;
if (cursor != null) {
@@ -311,7 +311,7 @@ class TrackWriterImpl implements TrackWriter {
};
TrackWriterLocationFactory locationFactory = new TrackWriterLocationFactory();
LocationIterator it = providerUtils.getTrackPointLocationIterator(track.getId(), 0, false,
LocationIterator it = providerUtils.getTrackPointLocationIterator(track.getId(), -1L, false,
locationFactory);
try {
int pointNumber = 0;
@@ -210,7 +210,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
private boolean uploadAllTrackPoints(Track track) {
Cursor cursor = null;
try {
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, 0, -1, false);
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, -1L, -1, false);
if (cursor == null) {
Log.d(TAG, "Location cursor is null");
return false;
@@ -329,7 +329,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
Cursor cursor = null;
try {
cursor = myTracksProviderUtils.getWaypointCursor(
trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS);
trackId, -1L, Constants.MAX_LOADED_WAYPOINTS_POINTS);
if (cursor != null && cursor.moveToFirst()) {
// This will skip the first waypoint (it carries the stats for the
// track).
@@ -253,7 +253,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
boolean uploadAllTrackPoints(Track track) {
Cursor cursor = null;
try {
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, 0, -1, false);
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, -1L, -1, false);
if (cursor == null) {
Log.d(TAG, "Location cursor is null");
return false;
@@ -437,7 +437,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
Cursor cursor = null;
try {
cursor = myTracksProviderUtils.getWaypointCursor(
trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS);
trackId, -1L, Constants.MAX_LOADED_WAYPOINTS_POINTS);
if (cursor != null && cursor.moveToFirst()) {
// This will skip the first waypoint (it carries the stats for the
// track).
@@ -604,7 +604,7 @@ public class TrackRecordingService extends Service {
try {
// TODO: how to handle very long track.
cursor = myTracksProviderUtils.getTrackPointCursor(
recordingTrackId, -1, Constants.MAX_LOADED_TRACK_POINTS, true);
recordingTrackId, -1L, Constants.MAX_LOADED_TRACK_POINTS, true);
if (cursor == null) {
Log.e(TAG, "Cursor is null.");
} else {
@@ -27,6 +27,7 @@ import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -96,7 +97,31 @@ public class StringUtils {
* @param time the time in milliseconds
*/
public static String formatElapsedTime(long time) {
return DateUtils.formatElapsedTime(time / 1000);
/*
* Temporary workaround for DateUtils.formatElapsedTime(time / 1000). In API
* level 17, it returns strings like "1:0:00" instead of "1:00:00", which
* breaks several unit tests.
*/
long elapsedSeconds = time / 1000;
long hours = 0;
long minutes = 0;
long seconds = 0;
if (elapsedSeconds >= 3600) {
hours = elapsedSeconds / 3600;
elapsedSeconds -= hours * 3600;
}
if (elapsedSeconds >= 60) {
minutes = elapsedSeconds / 60;
elapsedSeconds -= minutes * 60;
}
seconds = elapsedSeconds;
if (hours > 0) {
return String.format(Locale.US, "%d:%02d:%02d", hours, minutes, seconds);
} else {
return String.format(Locale.US, "%02d:%02d", minutes, seconds);
}
}
/**
@@ -82,9 +82,9 @@ public interface MyTracksProviderUtils {
* Gets a track cursor. The caller owns the returned cursor and is responsible
* for closing it.
*
* @param selection the selection
* @param selectionArgs the selection arguments
* @param sortOrder the sort order
* @param selection the selection. Can be null
* @param selectionArgs the selection arguments. Can be null
* @param sortOrder the sort order. Can be null
*/
public Cursor getTrackCursor(String selection, String[] selectionArgs, String sortOrder);
@@ -120,7 +120,7 @@ public interface MyTracksProviderUtils {
* deletion. The generator is used to update the next statistics waypoint.
*
* @param waypointId the waypoint id
* @param descriptionGenerator the description generator
* @param descriptionGenerator the description generator. Can be null for waypoint marker
*/
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator);
@@ -160,10 +160,10 @@ public interface MyTracksProviderUtils {
* Gets a waypoint cursor. The caller owns the returned cursor and is
* responsible for closing it.
*
* @param selection the selection
* @param selectionArgs the selection arguments
* @param sortOrder the sort order
* @param maxWaypoints the maximum number of waypoints to return
* @param selection the selection. Can be null
* @param selectionArgs the selection arguments. Can be null
* @param sortOrder the sort order. Can be null
* @param maxWaypoints the maximum number of waypoints to return. -1 for no limit
*/
public Cursor getWaypointCursor(
String selection, String[] selectionArgs, String sortOrder, int maxWaypoints);
@@ -173,8 +173,8 @@ public interface MyTracksProviderUtils {
* is responsible for closing it.
*
* @param trackId the track id
* @param minWaypointId the minimum waypoint id
* @param maxWaypoints the maximum number of waypoints to return
* @param minWaypointId the minimum waypoint id. -1L to ignore
* @param maxWaypoints the maximum number of waypoints to return. -1 for no limit
*/
public Cursor getWaypointCursor(long trackId, long minWaypointId, int maxWaypoints);
@@ -242,8 +242,8 @@ public interface MyTracksProviderUtils {
* responsible for closing it.
*
* @param trackId the track id
* @param startTrackPointId the starting track point id
* @param maxLocations maximum number of locations to return
* @param startTrackPointId the starting track point id. -1L to ignore
* @param maxLocations maximum number of locations to return. -1 for no limit
* @param descending true to sort the result in descending order (latest
* location first)
*/
@@ -262,8 +262,7 @@ public interface MyTracksProviderUtils {
* iteration, {@link LocationIterator#close()} must be called.
*
* @param trackId the track id
* @param startTrackPointId the start track point id or -1L to start from the
* first point
* @param startTrackPointId the starting track point id. -1L to ignore
* @param descending true to sort the result in descending order (latest
* location first)
* @param locationFactory the location factory
@@ -439,7 +439,8 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
@Override
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator) {
final Waypoint waypoint = getWaypoint(waypointId);
if (waypoint != null && waypoint.getType() == Waypoint.TYPE_STATISTICS) {
if (waypoint != null && waypoint.getType() == Waypoint.TYPE_STATISTICS
&& descriptionGenerator != null) {
final Waypoint nextWaypoint = getNextStatisticsWaypointAfter(waypoint);
if (nextWaypoint == null) {
Log.d(TAG, "Unable to find the next statistics marker after deleting one.");
@@ -510,7 +511,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
String selection = WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns.TYPE + "=?";
int type = statistics ? Waypoint.TYPE_STATISTICS : Waypoint.TYPE_WAYPOINT;
String[] selectionArgs = new String[] { Long.toString(trackId), Integer.toString(type) };
cursor = getWaypointCursor(projection, selection, selectionArgs, WaypointsColumns._ID, 0);
cursor = getWaypointCursor(projection, selection, selectionArgs, WaypointsColumns._ID, -1);
if (cursor != null) {
int count = cursor.getCount();
/*
@@ -535,7 +536,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
Cursor cursor = null;
try {
cursor = getWaypointCursor(null, WaypointsColumns._ID + "=?",
new String[] { Long.toString(waypointId) }, WaypointsColumns._ID, 0);
new String[] { Long.toString(waypointId) }, WaypointsColumns._ID, 1);
if (cursor != null && cursor.moveToFirst()) {
return createWaypoint(cursor);
}
@@ -672,7 +673,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
if (sortOrder == null) {
sortOrder = WaypointsColumns._ID;
}
if (maxWaypoints > 0) {
if (maxWaypoints >= 0) {
sortOrder += " LIMIT " + maxWaypoints;
}
return contentResolver.query(
@@ -789,7 +790,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
if (descending) {
sortOrder += " DESC";
}
if (maxLocations > 0) {
if (maxLocations >= 0) {
sortOrder += " LIMIT " + maxLocations;
}
return getTrackPointCursor(null, selection, selectionArgs, sortOrder);
@@ -1,4 +1,3 @@
#Tue Jul 17 10:23:26 PDT 2012
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+1 -1
View File
@@ -29,7 +29,7 @@ limitations under the License.
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
android:targetSdkVersion="17" />
<application
android:label="My Tracks Tests" >
@@ -128,7 +128,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
((MyTracksProviderUtilsImpl) providerUtils).setDefaultCursorBatchSize(batchSize);
List<Location> locations = new ArrayList<Location>(numPoints);
LocationIterator it = providerUtils.getTrackPointLocationIterator(
trackId, -1, descending, locationFactory);
trackId, -1L, descending, locationFactory);
try {
while (it.hasNext()) {
Location loc = it.next();
@@ -168,7 +168,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
// Load all inserted locations.
long lastPointId = -1;
int counter = 0;
LocationIterator it = providerUtils.getTrackPointLocationIterator(id, -1, false,
LocationIterator it = providerUtils.getTrackPointLocationIterator(id, -1L, false,
MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
try {
while (it.hasNext()) {
@@ -645,9 +645,9 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
insertTrackWithLocations(track);
providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), -1, trackId);
assertEquals(20, providerUtils.getTrackPointCursor(trackId, 0, 1000, false).getCount());
assertEquals(20, providerUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), 8, trackId);
assertEquals(28, providerUtils.getTrackPointCursor(trackId, 0, 1000, false).getCount());
assertEquals(28, providerUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
}
/**
@@ -728,7 +728,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
insertTrackWithLocations(track);
providerUtils.insertTrackPoint(createLocation(22), trackId);
assertEquals(11, providerUtils.getTrackPointCursor(trackId, 0, 1000, false).getCount());
assertEquals(11, providerUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
}
/**
@@ -204,7 +204,7 @@ public class TrackDataHubTest extends AndroidTestCase {
// Register two listeners
Capture<ContentObserver> contentObserverCapture = new Capture<ContentObserver>();
expect(myTracksProviderUtils.getWaypointCursor(
eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
eq(TRACK_ID), AndroidMock.leq(-1L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
.andStubAnswer(new FixedSizeCursorAnswer(2));
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class)))
.andReturn(waypoint1).andReturn(waypoint2).andReturn(waypoint1).andReturn(waypoint2);
@@ -231,7 +231,7 @@ public class TrackDataHubTest extends AndroidTestCase {
// Cause waypoints table update
ContentObserver contentObserver = contentObserverCapture.getValue();
expect(myTracksProviderUtils.getWaypointCursor(
eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
eq(TRACK_ID), AndroidMock.leq(-1L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
.andStubAnswer(new FixedSizeCursorAnswer(3));
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class)))
.andReturn(waypoint1).andReturn(waypoint2).andReturn(waypoint3);
@@ -252,7 +252,7 @@ public class TrackDataHubTest extends AndroidTestCase {
// Unregister one listener
expect(myTracksProviderUtils.getWaypointCursor(
eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
eq(TRACK_ID), AndroidMock.leq(-1L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
.andStubAnswer(new FixedSizeCursorAnswer(4));
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class)))
.andReturn(waypoint1).andReturn(waypoint2).andReturn(waypoint3).andReturn(waypoint4);
@@ -144,7 +144,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
*/
public void testUploadAllTrackPoints_nullCursor() {
Track track = TrackStubUtils.createTrack(1);
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, -1L, -1, false))
.andReturn(null);
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
@@ -166,7 +166,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
cursorMock.close();
AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock)).andReturn(
new Location("1"));
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, -1L, -1, false))
.andReturn(cursorMock);
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
@@ -193,7 +193,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
cursorMock.close();
AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock))
.andReturn(new Location("1")).times(2);
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, -1L, -1, false))
.andReturn(cursorMock);
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
@@ -223,7 +223,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
cursorMock.close();
AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock))
.andReturn(new Location("1")).times(2);
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, -1L, -1, false))
.andReturn(cursorMock);
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
@@ -252,7 +252,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
cursorMock.close();
AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock))
.andReturn(new Location("1")).times(2);
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, -1L, -1, false))
.andReturn(cursorMock);
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
@@ -274,7 +274,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
@UsesMocks(Cursor.class)
public void testUploadWaypoints_nullCursor() {
AndroidMock.expect(
myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, 0,
myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, -1L,
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(null);
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
@@ -296,7 +296,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
cursorMock.close();
AndroidMock.expect(
myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, 0,
myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, -1L,
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(cursorMock);
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
@@ -323,7 +323,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
cursorMock.close();
AndroidMock.expect(
myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, 0,
myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, -1L,
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(cursorMock);
Waypoint waypoint = new Waypoint();
waypoint.setLocation(TrackStubUtils.createMyTracksLocation());
@@ -787,6 +787,6 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
location.setTime(System.currentTimeMillis());
location.setBearing(3.0f);
trackRecordingService.insertTrackPoint(location);
Thread.sleep(100);
Thread.sleep(200);
}
}