(Re-)Enabled SaveActivity.

This commit is contained in:
Dennis Guse
2019-07-21 20:36:33 +02:00
parent 601c2fe9fa
commit 58135607e8
50 changed files with 491 additions and 538 deletions
@@ -18,9 +18,10 @@ package com.google.android.apps.mytracks;
import android.location.Location; import android.location.Location;
import com.google.android.apps.mytracks.content.MyTracksLocation; import com.google.android.apps.mytracks.content.SensorDataSetLocation;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.sensor.Sensor.SensorDataSet; import com.google.android.apps.mytracks.content.sensor.Sensor.SensorDataSet;
import com.google.android.apps.mytracks.content.sensor.SensorDataSet;
/** /**
* Commons utilities for creating stubs of track, location. The class will be * Commons utilities for creating stubs of track, location. The class will be
@@ -31,8 +32,8 @@ import com.google.android.apps.mytracks.content.sensor.Sensor.SensorDataSet;
public class TrackStubUtils { public class TrackStubUtils {
static final String LOCATION_PROVIDER = "gps"; static final String LOCATION_PROVIDER = "gps";
public static final double INITIAL_LATITUDE = 22; static final double INITIAL_LATITUDE = 22;
public static final double INITIAL_LONGITUDE = 22; static final double INITIAL_LONGITUDE = 22;
public static final double INITIAL_ALTITUDE = 22; public static final double INITIAL_ALTITUDE = 22;
static final float INITIAL_ACCURACY = 5; static final float INITIAL_ACCURACY = 5;
static final float INITIAL_SPEED = 10; static final float INITIAL_SPEED = 10;
@@ -50,7 +51,7 @@ public class TrackStubUtils {
public static Track createTrack(int numberOfLocations) { public static Track createTrack(int numberOfLocations) {
Track track = new Track(); Track track = new Track();
for (int i = 0; i < numberOfLocations; i++) { for (int i = 0; i < numberOfLocations; i++) {
track.addLocation(createMyTracksLocation(INITIAL_LATITUDE + i * DIFFERENCE, INITIAL_LONGITUDE track.addLocation(createSensorDataSetLocation(INITIAL_LATITUDE + i * DIFFERENCE, INITIAL_LONGITUDE
+ i * DIFFERENCE, INITIAL_ALTITUDE + i * DIFFERENCE)); + i * DIFFERENCE, INITIAL_ALTITUDE + i * DIFFERENCE));
} }
@@ -62,17 +63,17 @@ public class TrackStubUtils {
* *
* @return a track stub. * @return a track stub.
*/ */
public static MyTracksLocation createMyTracksLocation() { public static SensorDataSetLocation createSensorDataSetLocation() {
return createMyTracksLocation(INITIAL_LATITUDE, INITIAL_LONGITUDE, INITIAL_ALTITUDE); return createSensorDataSetLocation(INITIAL_LATITUDE, INITIAL_LONGITUDE, INITIAL_ALTITUDE);
} }
/** /**
* Creates a {@link MyTracksLocation} stub with specified values. * Creates a {@link SensorDataSetLocation} stub with specified values.
* *
* @return a MyTracksLocation stub. * @return a SensorDataSetLocation stub.
*/ */
public static MyTracksLocation createMyTracksLocation(double latitude, double longitude, public static SensorDataSetLocation createSensorDataSetLocation(double latitude, double longitude,
double altitude) { double altitude) {
// Initial Location // Initial Location
Location loc = new Location(LOCATION_PROVIDER); Location loc = new Location(LOCATION_PROVIDER);
loc.setLatitude(latitude); loc.setLatitude(latitude);
@@ -82,9 +83,9 @@ public class TrackStubUtils {
loc.setSpeed(INITIAL_SPEED); loc.setSpeed(INITIAL_SPEED);
loc.setTime(INITIAL_TIME); loc.setTime(INITIAL_TIME);
loc.setBearing(INITIAL_BEARING); loc.setBearing(INITIAL_BEARING);
SensorDataSet sd = SensorDataSet.newBuilder().build(); SensorDataSet sd = new SensorDataSet(100, 100);
return new MyTracksLocation(loc, sd); return new SensorDataSetLocation(loc, sd);
} }
} }
@@ -22,34 +22,34 @@ import android.net.Uri;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.platform.app.InstrumentationRegistry;
import com.google.android.apps.mytracks.content.MyTracksProvider.DatabaseHelper; import com.google.android.apps.mytracks.content.CustomContentProvider.DatabaseHelper;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
* Tests {@link MyTracksProvider}. * Tests {@link CustomContentProvider}.
* *
* @author Youtao Liu * @author Youtao Liu
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class MyTracksProviderTest { public class CustomContentProviderTest {
private static final String DATABASE_NAME = "mytrackstest.db"; private static final String DATABASE_NAME = "mytrackstest.db";
private SQLiteDatabase db; private SQLiteDatabase db;
private MyTracksProvider myTracksProvider; private CustomContentProvider myTracksProvider;
@Before @Before
protected void setUp() { protected void setUp() {
InstrumentationRegistry.getInstrumentation().getContext().deleteDatabase(DATABASE_NAME); InstrumentationRegistry.getInstrumentation().getContext().deleteDatabase(DATABASE_NAME);
db = (new DatabaseHelper(InstrumentationRegistry.getInstrumentation().getContext(), DATABASE_NAME)).getWritableDatabase(); db = (new DatabaseHelper(InstrumentationRegistry.getInstrumentation().getContext(), DATABASE_NAME)).getWritableDatabase();
myTracksProvider = new MyTracksProvider(); myTracksProvider = new CustomContentProvider();
} }
/** /**
* Tests {@link MyTracksProvider.DatabaseHelper#onCreate(SQLiteDatabase)}. * Tests {@link CustomContentProvider.DatabaseHelper#onCreate(SQLiteDatabase)}.
*/ */
public void testDatabaseHelper_OnCreate() { public void testDatabaseHelper_OnCreate() {
Assert.assertTrue(hasTable(TracksColumns.TABLE_NAME)); Assert.assertTrue(hasTable(TracksColumns.TABLE_NAME));
@@ -58,14 +58,14 @@ public class MyTracksProviderTest {
} }
/** /**
* Tests {@link MyTracksProvider#onCreate(android.content.Context)}. * Tests {@link CustomContentProvider#onCreate(android.content.Context)}.
*/ */
public void testOnCreate() { public void testOnCreate() {
Assert.assertTrue(myTracksProvider.onCreate(InstrumentationRegistry.getInstrumentation().getContext())); Assert.assertTrue(myTracksProvider.onCreate(InstrumentationRegistry.getInstrumentation().getContext()));
} }
/** /**
* Tests {@link MyTracksProvider#getType(Uri)}. * Tests {@link CustomContentProvider#getType(Uri)}.
*/ */
public void testGetType() { public void testGetType() {
Assert.assertEquals(TracksColumns.CONTENT_TYPE, myTracksProvider.getType(TracksColumns.CONTENT_URI)); Assert.assertEquals(TracksColumns.CONTENT_TYPE, myTracksProvider.getType(TracksColumns.CONTENT_URI));
@@ -138,6 +138,6 @@ public class MyTracksProviderTest {
createTable(WaypointsColumns.TABLE_NAME); createTable(WaypointsColumns.TABLE_NAME);
DatabaseHelper databaseHelper = new DatabaseHelper(InstrumentationRegistry.getInstrumentation().getContext()); DatabaseHelper databaseHelper = new DatabaseHelper(InstrumentationRegistry.getInstrumentation().getContext());
databaseHelper.onUpgrade(db, oldVersion, MyTracksProvider.DATABASE_VERSION); databaseHelper.onUpgrade(db, oldVersion, CustomContentProvider.DATABASE_VERSION);
} }
} }
@@ -25,8 +25,8 @@ import android.test.mock.MockContentResolver;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationFactory; import com.google.android.apps.mytracks.content.ContentProviderUtils.LocationFactory;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.content.ContentProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import com.google.android.apps.mytracks.services.TrackRecordingServiceTest.MockContext; import com.google.android.apps.mytracks.services.TrackRecordingServiceTest.MockContext;
import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatistics;
@@ -43,15 +43,15 @@ import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
* A unit test for {@link MyTracksProviderUtilsImpl}. * A unit test for {@link ContentProviderUtilsImpl}.
* *
* @author Bartlomiej Niechwiej * @author Bartlomiej Niechwiej
* @author Youtao Liu * @author Youtao Liu
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class MyTracksProviderUtilsImplTest { public class CustomContentProviderUtilsImplTest {
private Context context; private Context context;
private MyTracksProviderUtils providerUtils; private ContentProviderUtils providerUtils;
private static final String NAME_PREFIX = "test name"; private static final String NAME_PREFIX = "test name";
private static final String MOCK_DESC = "Mock Next Waypoint Desc!"; private static final String MOCK_DESC = "Mock Next Waypoint Desc!";
@@ -67,17 +67,17 @@ public class MyTracksProviderUtilsImplTest {
RenamingDelegatingContext targetContext = new RenamingDelegatingContext( RenamingDelegatingContext targetContext = new RenamingDelegatingContext(
getContext(), getContext(), "test."); getContext(), getContext(), "test.");
context = new MockContext(mockContentResolver, targetContext); context = new MockContext(mockContentResolver, targetContext);
MyTracksProvider provider = new MyTracksProvider(); CustomContentProvider provider = new CustomContentProvider();
provider.attachInfo(context, null); provider.attachInfo(context, null);
mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, provider); mockContentResolver.addProvider(ContentProviderUtils.AUTHORITY, provider);
setContext(context); setContext(context);
providerUtils = MyTracksProviderUtils.Factory.get(context); providerUtils = ContentProviderUtils.Factory.get(context);
providerUtils.deleteAllTracks(context); providerUtils.deleteAllTracks(context);
} }
public void testLocationIterator_noPoints() { public void testLocationIterator_noPoints() {
testIterator(1, 0, 1, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(1, 0, 1, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
} }
public void testLocationIterator_customFactory() { public void testLocationIterator_customFactory() {
@@ -104,33 +104,33 @@ public class MyTracksProviderUtilsImplTest {
} }
public void testLocationIterator_noBatchAscending() { public void testLocationIterator_noBatchAscending() {
testIterator(1, 50, 100, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(1, 50, 100, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
testIterator(2, 50, 50, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(2, 50, 50, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
} }
public void testLocationIterator_noBatchDescending() { public void testLocationIterator_noBatchDescending() {
testIterator(1, 50, 100, true, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(1, 50, 100, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
testIterator(2, 50, 50, true, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(2, 50, 50, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
} }
public void testLocationIterator_batchAscending() { public void testLocationIterator_batchAscending() {
testIterator(1, 50, 11, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(1, 50, 11, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
testIterator(2, 50, 25, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(2, 50, 25, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
} }
public void testLocationIterator_batchDescending() { public void testLocationIterator_batchDescending() {
testIterator(1, 50, 11, true, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(1, 50, 11, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
testIterator(2, 50, 25, true, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(2, 50, 25, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
} }
public void testLocationIterator_largeTrack() { public void testLocationIterator_largeTrack() {
testIterator(1, 20000, 2000, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); testIterator(1, 20000, 2000, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
} }
private List<Location> testIterator(long trackId, int numPoints, int batchSize, private List<Location> testIterator(long trackId, int numPoints, int batchSize,
boolean descending, LocationFactory locationFactory) { boolean descending, LocationFactory locationFactory) {
long lastPointId = initializeTrack(trackId, numPoints); long lastPointId = initializeTrack(trackId, numPoints);
((MyTracksProviderUtilsImpl) providerUtils).setDefaultCursorBatchSize(batchSize); ((ContentProviderUtilsImpl) providerUtils).setDefaultCursorBatchSize(batchSize);
List<Location> locations = new ArrayList<Location>(numPoints); List<Location> locations = new ArrayList<Location>(numPoints);
LocationIterator it = providerUtils.getTrackPointLocationIterator( LocationIterator it = providerUtils.getTrackPointLocationIterator(
trackId, -1L, descending, locationFactory); trackId, -1L, descending, locationFactory);
@@ -174,7 +174,7 @@ public class MyTracksProviderUtilsImplTest {
long lastPointId = -1; long lastPointId = -1;
int counter = 0; int counter = 0;
LocationIterator it = providerUtils.getTrackPointLocationIterator(id, -1L, false, LocationIterator it = providerUtils.getTrackPointLocationIterator(id, -1L, false,
MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
try { try {
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
@@ -193,7 +193,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#createTrack(Cursor)}. * Tests the method {@link ContentProviderUtilsImpl#createTrack(Cursor)}.
*/ */
@UsesMocks(Cursor.class) @UsesMocks(Cursor.class)
public void testCreateTrack() { public void testCreateTrack() {
@@ -224,7 +224,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#deleteAllTracks(Context)} * Tests the method {@link ContentProviderUtilsImpl#deleteAllTracks(Context)}
*/ */
public void testDeleteAllTracks() { public void testDeleteAllTracks() {
// Insert track, points and waypoint at first. // Insert track, points and waypoint at first.
@@ -258,7 +258,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#deleteTrack(Context, long)}. * Tests the method {@link ContentProviderUtilsImpl#deleteTrack(Context, long)}.
*/ */
public void testDeleteTrack() { public void testDeleteTrack() {
// Insert three tracks, points of two tracks and way point of one track. // Insert three tracks, points of two tracks and way point of one track.
@@ -298,7 +298,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#getAllTracks()} * Tests the method {@link ContentProviderUtilsImpl#getAllTracks()}
*/ */
public void testGetAllTracks() { public void testGetAllTracks() {
int initialTrackNumber = providerUtils.getAllTracks().size(); int initialTrackNumber = providerUtils.getAllTracks().size();
@@ -310,7 +310,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#getLastTrack()} * Tests the method {@link ContentProviderUtilsImpl#getLastTrack()}
*/ */
public void testGetLastTrack() { public void testGetLastTrack() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
@@ -319,7 +319,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#getTrack(long)} * Tests the method {@link ContentProviderUtilsImpl#getTrack(long)}
*/ */
public void testGetTrack() { public void testGetTrack() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
@@ -328,7 +328,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#updateTrack(Track)} * Tests the method {@link ContentProviderUtilsImpl#updateTrack(Track)}
*/ */
public void testUpdateTrack() { public void testUpdateTrack() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
@@ -344,7 +344,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#createContentValues(Waypoint)}. * Tests the method {@link ContentProviderUtilsImpl#createContentValues(Waypoint)}.
*/ */
public void testCreateContentValues_waypoint() { public void testCreateContentValues_waypoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
@@ -381,7 +381,7 @@ public class MyTracksProviderUtilsImplTest {
waypoint.setLocation(loc); waypoint.setLocation(loc);
providerUtils.insertWaypoint(waypoint); providerUtils.insertWaypoint(waypoint);
MyTracksProviderUtilsImpl myTracksProviderUtilsImpl = new MyTracksProviderUtilsImpl( ContentProviderUtilsImpl myTracksProviderUtilsImpl = new ContentProviderUtilsImpl(
new MockContentResolver()); new MockContentResolver());
long waypointId = System.currentTimeMillis(); long waypointId = System.currentTimeMillis();
@@ -395,7 +395,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#createWaypoint(Cursor)}. * Tests the method {@link ContentProviderUtilsImpl#createWaypoint(Cursor)}.
*/ */
@UsesMocks(Cursor.class) @UsesMocks(Cursor.class)
public void testCreateWaypoint() { public void testCreateWaypoint() {
@@ -435,7 +435,7 @@ public class MyTracksProviderUtilsImplTest {
/** /**
* Tests the method * Tests the method
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)} * {@link ContentProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)}
* when there is only one waypoint in the track. * when there is only one waypoint in the track.
*/ */
public void testDeleteWaypoint_onlyOneWayPoint() { public void testDeleteWaypoint_onlyOneWayPoint() {
@@ -455,7 +455,7 @@ public class MyTracksProviderUtilsImplTest {
@Override @Override
public String generateWaypointDescription(TripStatistics tripStatistics) { public String generateWaypointDescription(TripStatistics tripStatistics) {
return MyTracksProviderUtilsImplTest.MOCK_DESC; return CustomContentProviderUtilsImplTest.MOCK_DESC;
} }
@Override @Override
@@ -471,7 +471,7 @@ public class MyTracksProviderUtilsImplTest {
/** /**
* Tests the method * Tests the method
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)} * {@link ContentProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)}
* when there is more than one waypoint in the track. * when there is more than one waypoint in the track.
*/ */
public void testDeleteWaypoint_hasNextWayPoint() { public void testDeleteWaypoint_hasNextWayPoint() {
@@ -510,7 +510,7 @@ public class MyTracksProviderUtilsImplTest {
DescriptionGenerator descriptionGenerator = new DescriptionGenerator() { DescriptionGenerator descriptionGenerator = new DescriptionGenerator() {
@Override @Override
public String generateWaypointDescription(TripStatistics tripStatistics) { public String generateWaypointDescription(TripStatistics tripStatistics) {
return MyTracksProviderUtilsImplTest.MOCK_DESC; return CustomContentProviderUtilsImplTest.MOCK_DESC;
} }
@Override @Override
@@ -522,12 +522,12 @@ public class MyTracksProviderUtilsImplTest {
providerUtils.deleteWaypoint(context, 1, descriptionGenerator); providerUtils.deleteWaypoint(context, 1, descriptionGenerator);
Assert.assertNull(providerUtils.getWaypoint(1)); Assert.assertNull(providerUtils.getWaypoint(1));
Assert.assertEquals(MyTracksProviderUtilsImplTest.MOCK_DESC, providerUtils.getWaypoint(2) Assert.assertEquals(CustomContentProviderUtilsImplTest.MOCK_DESC, providerUtils.getWaypoint(2)
.getDescription()); .getDescription());
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#getFirstWaypointId(long)}. * Tests the method {@link ContentProviderUtilsImpl#getFirstWaypointId(long)}.
*/ */
public void testGetFirstWaypointId() { public void testGetFirstWaypointId() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
@@ -546,7 +546,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#getNextWaypointNumber(long, WaypointType)}. * Tests the method {@link ContentProviderUtilsImpl#getNextWaypointNumber(long, WaypointType)}.
*/ */
public void testGetNextWaypointNumber() { public void testGetNextWaypointNumber() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
@@ -576,7 +576,7 @@ public class MyTracksProviderUtilsImplTest {
/** /**
* Tests the method * Tests the method
* {@link MyTracksProviderUtils#getLastWaypoint(long, WaypointType)}. * {@link ContentProviderUtils#getLastWaypoint(long, WaypointType)}.
*/ */
public void testGetLastStatisticsWaypoint() { public void testGetLastStatisticsWaypoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
@@ -603,8 +603,8 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#insertWaypoint(Waypoint)} and * Tests the method {@link ContentProviderUtilsImpl#insertWaypoint(Waypoint)} and
* {@link MyTracksProviderUtilsImpl#getWaypoint(long)}. * {@link ContentProviderUtilsImpl#getWaypoint(long)}.
*/ */
public void testInsertAndGetWaypoint() { public void testInsertAndGetWaypoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
@@ -620,7 +620,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#updateWaypoint(Waypoint)}. * Tests the method {@link ContentProviderUtilsImpl#updateWaypoint(Waypoint)}.
*/ */
public void testUpdateWaypoint() { public void testUpdateWaypoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
@@ -640,7 +640,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#bulkInsertTrackPoint(Location[], * Tests the method {@link ContentProviderUtilsImpl#bulkInsertTrackPoint(Location[],
* int, long)}. * int, long)}.
*/ */
public void testBulkInsertTrackPoint() { public void testBulkInsertTrackPoint() {
@@ -656,7 +656,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#createTrackPoint(Cursor)}. * Tests the method {@link ContentProviderUtilsImpl#createTrackPoint(Cursor)}.
*/ */
@UsesMocks(Cursor.class) @UsesMocks(Cursor.class)
public void testCreateTrackPoint() { public void testCreateTrackPoint() {
@@ -724,7 +724,7 @@ public class MyTracksProviderUtilsImplTest {
/** /**
* Tests the method * Tests the method
* {@link MyTracksProviderUtilsImpl#insertTrackPoint(Location, long)}. * {@link ContentProviderUtilsImpl#insertTrackPoint(Location, long)}.
*/ */
public void testInsertTrackPoint() { public void testInsertTrackPoint() {
// Insert track, point at first. // Insert track, point at first.
@@ -737,7 +737,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#getFirstTrackPointId(long)}. * Tests the method {@link ContentProviderUtilsImpl#getFirstTrackPointId(long)}.
*/ */
public void testGetFirstTrackPointId() { public void testGetFirstTrackPointId() {
// Insert track, point at first. // Insert track, point at first.
@@ -749,7 +749,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#getLastTrackPointId(long)}. * Tests the method {@link ContentProviderUtilsImpl#getLastTrackPointId(long)}.
*/ */
public void testGetLastTrackPointId() { public void testGetLastTrackPointId() {
// Insert track, point at first. // Insert track, point at first.
@@ -761,7 +761,7 @@ public class MyTracksProviderUtilsImplTest {
} }
/** /**
* Tests the method {@link MyTracksProviderUtilsImpl#getLastValidTrackPoint(long)}. * Tests the method {@link ContentProviderUtilsImpl#getLastValidTrackPoint(long)}.
*/ */
public void testGetLastValidTrackPoint() { public void testGetLastValidTrackPoint() {
// Insert track, points at first. // Insert track, points at first.
@@ -775,7 +775,7 @@ public class MyTracksProviderUtilsImplTest {
/** /**
* Tests the method * Tests the method
* {@link MyTracksProviderUtilsImpl#getTrackPointCursor(long, long, int, boolean)} * {@link ContentProviderUtilsImpl#getTrackPointCursor(long, long, int, boolean)}
* in descending. * in descending.
*/ */
public void testGetTrackPointCursor_desc() { public void testGetTrackPointCursor_desc() {
@@ -790,7 +790,7 @@ public class MyTracksProviderUtilsImplTest {
/** /**
* Tests the method * Tests the method
* {@link MyTracksProviderUtilsImpl#getTrackPointCursor(long, long, int, boolean)} * {@link ContentProviderUtilsImpl#getTrackPointCursor(long, long, int, boolean)}
* in ascending. * in ascending.
*/ */
public void testGetTrackPointCursor_asc() { public void testGetTrackPointCursor_asc() {
@@ -805,7 +805,7 @@ public class MyTracksProviderUtilsImplTest {
/** /**
* Tests the method * Tests the method
* {@link MyTracksProviderUtilsImpl#getTrackPointLocationIterator(long, long, boolean, LocationFactory)} * {@link ContentProviderUtilsImpl#getTrackPointLocationIterator(long, long, boolean, LocationFactory)}
* in descending. * in descending.
*/ */
public void testGetTrackPointLocationIterator_desc() { public void testGetTrackPointLocationIterator_desc() {
@@ -817,7 +817,7 @@ public class MyTracksProviderUtilsImplTest {
long startTrackPointId = 2L; long startTrackPointId = 2L;
LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId,
startTrackPointId, true, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); startTrackPointId, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
for (int i = 1; i >= 0; i--) { for (int i = 1; i >= 0; i--) {
Assert.assertTrue(locationIterator.hasNext()); Assert.assertTrue(locationIterator.hasNext());
Location location = locationIterator.next(); Location location = locationIterator.next();
@@ -829,7 +829,7 @@ public class MyTracksProviderUtilsImplTest {
/** /**
* Tests the method * Tests the method
* {@link MyTracksProviderUtilsImpl#getTrackPointLocationIterator(long, long, boolean, LocationFactory)} * {@link ContentProviderUtilsImpl#getTrackPointLocationIterator(long, long, boolean, LocationFactory)}
* in ascending. * in ascending.
*/ */
public void testGetTrackPointLocationIterator_asc() { public void testGetTrackPointLocationIterator_asc() {
@@ -841,7 +841,7 @@ public class MyTracksProviderUtilsImplTest {
long startTrackPointId = 2L; long startTrackPointId = 2L;
LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId,
startTrackPointId, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); startTrackPointId, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
for (int i = 1; i < 10; i++) { for (int i = 1; i < 10; i++) {
Assert.assertTrue(locationIterator.hasNext()); Assert.assertTrue(locationIterator.hasNext());
@@ -889,7 +889,7 @@ public class MyTracksProviderUtilsImplTest {
* Checks the value of a location. * Checks the value of a location.
* *
* @param i the index of this location which created in the method * @param i the index of this location which created in the method
* {@link MyTracksProviderUtilsImplTest#getTrack(long, int)} * {@link CustomContentProviderUtilsImplTest#getTrack(long, int)}
* @param location the location to be checked * @param location the location to be checked
*/ */
private void checkLocation(int i, Location location) { private void checkLocation(int i, Location location) {
@@ -50,7 +50,7 @@ public class SearchEngineTest {
private static final Location HERE = new Location("gps"); private static final Location HERE = new Location("gps");
private static final long NOW = 1234567890000L; // After OLDEST_ALLOWED_TIMESTAMP private static final long NOW = 1234567890000L; // After OLDEST_ALLOWED_TIMESTAMP
private MyTracksProviderUtils providerUtils; private ContentProviderUtils providerUtils;
private SearchEngine engine; private SearchEngine engine;
@Before @Before
@@ -59,12 +59,12 @@ public class SearchEngineTest {
RenamingDelegatingContext targetContext = new RenamingDelegatingContext( RenamingDelegatingContext targetContext = new RenamingDelegatingContext(
getContext(), getContext(), "test."); getContext(), getContext(), "test.");
MockContext context = new MockContext(mockContentResolver, targetContext); MockContext context = new MockContext(mockContentResolver, targetContext);
MyTracksProvider provider = new MyTracksProvider(); CustomContentProvider provider = new CustomContentProvider();
provider.attachInfo(context, null); provider.attachInfo(context, null);
mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, provider); mockContentResolver.addProvider(ContentProviderUtils.AUTHORITY, provider);
setContext(context); setContext(context);
providerUtils = MyTracksProviderUtils.Factory.get(context); providerUtils = ContentProviderUtils.Factory.get(context);
engine = new SearchEngine(providerUtils); engine = new SearchEngine(providerUtils);
} }
@@ -30,8 +30,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.TrackStubUtils; import com.google.android.apps.mytracks.TrackStubUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationFactory; import com.google.android.apps.mytracks.content.ContentProviderUtils.LocationFactory;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.content.ContentProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.services.TrackRecordingServiceTest.MockContext; import com.google.android.apps.mytracks.services.TrackRecordingServiceTest.MockContext;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
@@ -65,7 +65,7 @@ public class TrackDataHubTest {
private MockContext context; private MockContext context;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private MyTracksProviderUtils myTracksProviderUtils; private ContentProviderUtils contentProviderUtils;
private DataSource dataSource; private DataSource dataSource;
private TrackDataManager trackDataManager; private TrackDataManager trackDataManager;
private TrackDataHub trackDataHub; private TrackDataHub trackDataHub;
@@ -75,17 +75,17 @@ public class TrackDataHubTest {
SharedPreferences.OnSharedPreferenceChangeListener>(); SharedPreferences.OnSharedPreferenceChangeListener>();
@Before @Before
@UsesMocks({ MyTracksProviderUtils.class, DataSource.class, TrackDataListener.class }) @UsesMocks({ ContentProviderUtils.class, DataSource.class, TrackDataListener.class })
@Override @Override
protected void setUp() { protected void setUp() {
context = new MockContext(new MockContentResolver(), new RenamingDelegatingContext( context = new MockContext(new MockContentResolver(), new RenamingDelegatingContext(
getContext(), getContext(), "test.")); getContext(), getContext(), "test."));
sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
myTracksProviderUtils = AndroidMock.createMock(MyTracksProviderUtils.class); contentProviderUtils = AndroidMock.createMock(ContentProviderUtils.class);
dataSource = AndroidMock.createMock(DataSource.class, context); dataSource = AndroidMock.createMock(DataSource.class, context);
trackDataManager = new TrackDataManager(); trackDataManager = new TrackDataManager();
trackDataHub = new TrackDataHub( trackDataHub = new TrackDataHub(
context, trackDataManager, myTracksProviderUtils, TARGET_POINTS) { context, trackDataManager, contentProviderUtils, TARGET_POINTS) {
@Override @Override
protected DataSource newDataSource() { protected DataSource newDataSource() {
return dataSource; return dataSource;
@@ -129,7 +129,7 @@ public class TrackDataHubTest {
// Register two listeners // Register two listeners
Capture<ContentObserver> contentObserverCapture = new Capture<ContentObserver>(); Capture<ContentObserver> contentObserverCapture = new Capture<ContentObserver>();
Track track = new Track(); Track track = new Track();
expect(myTracksProviderUtils.getTrack(TRACK_ID)).andStubReturn(track); expect(contentProviderUtils.getTrack(TRACK_ID)).andStubReturn(track);
dataSource.registerContentObserver( dataSource.registerContentObserver(
eq(TracksColumns.CONTENT_URI), capture(contentObserverCapture)); eq(TracksColumns.CONTENT_URI), capture(contentObserverCapture));
trackDataListener1.onTrackUpdated(track); trackDataListener1.onTrackUpdated(track);
@@ -146,7 +146,7 @@ public class TrackDataHubTest {
// Causes tracks table update // Causes tracks table update
ContentObserver contentObserver = contentObserverCapture.getValue(); ContentObserver contentObserver = contentObserverCapture.getValue();
expect(myTracksProviderUtils.getTrack(TRACK_ID)).andStubReturn(track); expect(contentProviderUtils.getTrack(TRACK_ID)).andStubReturn(track);
trackDataListener1.onTrackUpdated(track); trackDataListener1.onTrackUpdated(track);
trackDataListener2.onTrackUpdated(track); trackDataListener2.onTrackUpdated(track);
replay(); replay();
@@ -155,7 +155,7 @@ public class TrackDataHubTest {
verifyAndReset(); verifyAndReset();
// Unregister one listener // Unregister one listener
expect(myTracksProviderUtils.getTrack(TRACK_ID)).andStubReturn(track); expect(contentProviderUtils.getTrack(TRACK_ID)).andStubReturn(track);
trackDataListener2.onTrackUpdated(track); trackDataListener2.onTrackUpdated(track);
replay(); replay();
@@ -190,10 +190,10 @@ public class TrackDataHubTest {
// Register two listeners // Register two listeners
Capture<ContentObserver> contentObserverCapture = new Capture<ContentObserver>(); Capture<ContentObserver> contentObserverCapture = new Capture<ContentObserver>();
expect(myTracksProviderUtils.getWaypointCursor( expect(contentProviderUtils.getWaypointCursor(
eq(TRACK_ID), AndroidMock.leq(-1L), eq(TrackDataHub.MAX_DISPLAYED_WAYPOINTS))) eq(TRACK_ID), AndroidMock.leq(-1L), eq(TrackDataHub.MAX_DISPLAYED_WAYPOINTS)))
.andStubAnswer(new FixedSizeCursorAnswer(2)); .andStubAnswer(new FixedSizeCursorAnswer(2));
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class))) expect(contentProviderUtils.createWaypoint(isA(Cursor.class)))
.andReturn(waypoint1).andReturn(waypoint2).andReturn(waypoint1).andReturn(waypoint2); .andReturn(waypoint1).andReturn(waypoint2).andReturn(waypoint1).andReturn(waypoint2);
dataSource.registerContentObserver( dataSource.registerContentObserver(
eq(WaypointsColumns.CONTENT_URI), capture(contentObserverCapture)); eq(WaypointsColumns.CONTENT_URI), capture(contentObserverCapture));
@@ -217,10 +217,10 @@ public class TrackDataHubTest {
// Cause waypoints table update // Cause waypoints table update
ContentObserver contentObserver = contentObserverCapture.getValue(); ContentObserver contentObserver = contentObserverCapture.getValue();
expect(myTracksProviderUtils.getWaypointCursor( expect(contentProviderUtils.getWaypointCursor(
eq(TRACK_ID), AndroidMock.leq(-1L), eq(TrackDataHub.MAX_DISPLAYED_WAYPOINTS))) eq(TRACK_ID), AndroidMock.leq(-1L), eq(TrackDataHub.MAX_DISPLAYED_WAYPOINTS)))
.andStubAnswer(new FixedSizeCursorAnswer(3)); .andStubAnswer(new FixedSizeCursorAnswer(3));
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class))) expect(contentProviderUtils.createWaypoint(isA(Cursor.class)))
.andReturn(waypoint1).andReturn(waypoint2).andReturn(waypoint3); .andReturn(waypoint1).andReturn(waypoint2).andReturn(waypoint3);
trackDataListener1.clearWaypoints(); trackDataListener1.clearWaypoints();
trackDataListener2.clearWaypoints(); trackDataListener2.clearWaypoints();
@@ -238,10 +238,10 @@ public class TrackDataHubTest {
verifyAndReset(); verifyAndReset();
// Unregister one listener // Unregister one listener
expect(myTracksProviderUtils.getWaypointCursor( expect(contentProviderUtils.getWaypointCursor(
eq(TRACK_ID), AndroidMock.leq(-1L), eq(TrackDataHub.MAX_DISPLAYED_WAYPOINTS))) eq(TRACK_ID), AndroidMock.leq(-1L), eq(TrackDataHub.MAX_DISPLAYED_WAYPOINTS)))
.andStubAnswer(new FixedSizeCursorAnswer(4)); .andStubAnswer(new FixedSizeCursorAnswer(4));
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class))) expect(contentProviderUtils.createWaypoint(isA(Cursor.class)))
.andReturn(waypoint1).andReturn(waypoint2).andReturn(waypoint3).andReturn(waypoint4); .andReturn(waypoint1).andReturn(waypoint2).andReturn(waypoint3).andReturn(waypoint4);
trackDataListener2.clearWaypoints(); trackDataListener2.clearWaypoints();
trackDataListener2.onNewWaypoint(waypoint1); trackDataListener2.onNewWaypoint(waypoint1);
@@ -274,9 +274,9 @@ public class TrackDataHubTest {
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture)); eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5); FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
trackDataListener1.clearTrackPoints(); trackDataListener1.clearTrackPoints();
locationIterator.expectLocationsDelivered(trackDataListener1); locationIterator.expectLocationsDelivered(trackDataListener1);
trackDataListener1.onNewTrackPointsDone(); trackDataListener1.onNewTrackPointsDone();
@@ -290,9 +290,9 @@ public class TrackDataHubTest {
// Register a second listener // Register a second listener
locationIterator = new FixedSizeLocationIterator(1, 10, 5); locationIterator = new FixedSizeLocationIterator(1, 10, 5);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
trackDataListener2.clearTrackPoints(); trackDataListener2.clearTrackPoints();
locationIterator.expectLocationsDelivered(trackDataListener2); locationIterator.expectLocationsDelivered(trackDataListener2);
trackDataListener2.onNewTrackPointsDone(); trackDataListener2.onNewTrackPointsDone();
@@ -305,9 +305,9 @@ public class TrackDataHubTest {
// Deliver more points - should go to both listeners without clearing // Deliver more points - should go to both listeners without clearing
ContentObserver contentObserver = contentObserverCapture.getValue(); ContentObserver contentObserver = contentObserverCapture.getValue();
locationIterator = new FixedSizeLocationIterator(11, 10, 1); locationIterator = new FixedSizeLocationIterator(11, 10, 1);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(11L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); eq(TRACK_ID), eq(11L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(20L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(20L);
locationIterator.expectLocationsDelivered(trackDataListener1); locationIterator.expectLocationsDelivered(trackDataListener1);
locationIterator.expectLocationsDelivered(trackDataListener2); locationIterator.expectLocationsDelivered(trackDataListener2);
trackDataListener1.onNewTrackPointsDone(); trackDataListener1.onNewTrackPointsDone();
@@ -319,10 +319,10 @@ public class TrackDataHubTest {
// Unregister one listener and change track // Unregister one listener and change track
locationIterator = new FixedSizeLocationIterator(101, 10); locationIterator = new FixedSizeLocationIterator(101, 10);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class))) eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
.andReturn(locationIterator); .andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID + 1)).andReturn(110L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID + 1)).andReturn(110L);
trackDataListener2.clearTrackPoints(); trackDataListener2.clearTrackPoints();
locationIterator.expectLocationsDelivered(trackDataListener2); locationIterator.expectLocationsDelivered(trackDataListener2);
trackDataListener2.onNewTrackPointsDone(); trackDataListener2.onNewTrackPointsDone();
@@ -344,9 +344,9 @@ public class TrackDataHubTest {
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture)); eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5); FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
trackDataListener1.clearTrackPoints(); trackDataListener1.clearTrackPoints();
locationIterator.expectLocationsDelivered(trackDataListener1); locationIterator.expectLocationsDelivered(trackDataListener1);
@@ -371,9 +371,9 @@ public class TrackDataHubTest {
dataSource.registerContentObserver( dataSource.registerContentObserver(
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture)); eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
locationIterator = new FixedSizeLocationIterator(1, 10, 5); locationIterator = new FixedSizeLocationIterator(1, 10, 5);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
trackDataListener1.clearTrackPoints(); trackDataListener1.clearTrackPoints();
locationIterator.expectLocationsDelivered(trackDataListener1); locationIterator.expectLocationsDelivered(trackDataListener1);
trackDataListener1.onNewTrackPointsDone(); trackDataListener1.onNewTrackPointsDone();
@@ -395,9 +395,9 @@ public class TrackDataHubTest {
eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture)); eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture));
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5); FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
trackDataListener1.clearTrackPoints(); trackDataListener1.clearTrackPoints();
locationIterator.expectLocationsDelivered(trackDataListener1); locationIterator.expectLocationsDelivered(trackDataListener1);
trackDataListener1.onNewTrackPointsDone(); trackDataListener1.onNewTrackPointsDone();
@@ -421,10 +421,10 @@ public class TrackDataHubTest {
dataSource.registerContentObserver( dataSource.registerContentObserver(
eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture)); eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture));
locationIterator = new FixedSizeLocationIterator(1, 10); locationIterator = new FixedSizeLocationIterator(1, 10);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class))) eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
.andReturn(locationIterator); .andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID + 1)).andReturn(10L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID + 1)).andReturn(10L);
trackDataListener1.clearTrackPoints(); trackDataListener1.clearTrackPoints();
locationIterator.expectLocationsDelivered(trackDataListener1); locationIterator.expectLocationsDelivered(trackDataListener1);
trackDataListener1.onNewTrackPointsDone(); trackDataListener1.onNewTrackPointsDone();
@@ -444,15 +444,15 @@ public class TrackDataHubTest {
dataSource.registerContentObserver( dataSource.registerContentObserver(
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture)); eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(200L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(200L);
AndroidMock.expectLastCall().anyTimes(); AndroidMock.expectLastCall().anyTimes();
FixedSizeLocationIterator locationIterator1 = new FixedSizeLocationIterator( FixedSizeLocationIterator locationIterator1 = new FixedSizeLocationIterator(
1, 200, 4, 25, 71, 120); 1, 200, 4, 25, 71, 120);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator1); eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator1);
FixedSizeLocationIterator locationIterator2 = new FixedSizeLocationIterator( FixedSizeLocationIterator locationIterator2 = new FixedSizeLocationIterator(
1, 200, 4, 25, 71, 120); 1, 200, 4, 25, 71, 120);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator2); eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator2);
trackDataListener1.clearTrackPoints(); trackDataListener1.clearTrackPoints();
@@ -482,9 +482,9 @@ public class TrackDataHubTest {
// Deliver 30 points (no sampling happens) // Deliver 30 points (no sampling happens)
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 30, 5); FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 30, 5);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(30L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(30L);
trackDataListener1.clearTrackPoints(); trackDataListener1.clearTrackPoints();
locationIterator.expectLocationsDelivered(trackDataListener1); locationIterator.expectLocationsDelivered(trackDataListener1);
@@ -500,9 +500,9 @@ public class TrackDataHubTest {
// Now deliver 30 more (incrementally sampled) // Now deliver 30 more (incrementally sampled)
ContentObserver observer = observerCapture.getValue(); ContentObserver observer = observerCapture.getValue();
locationIterator = new FixedSizeLocationIterator(31, 30); locationIterator = new FixedSizeLocationIterator(31, 30);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(31L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); eq(TRACK_ID), eq(31L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(60L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(60L);
locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false); locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false);
trackDataListener1.onNewTrackPointsDone(); trackDataListener1.onNewTrackPointsDone();
replay(); replay();
@@ -512,9 +512,9 @@ public class TrackDataHubTest {
// Now another 30 (triggers resampling) // Now another 30 (triggers resampling)
locationIterator = new FixedSizeLocationIterator(1, 90); locationIterator = new FixedSizeLocationIterator(1, 90);
expect(myTracksProviderUtils.getTrackPointLocationIterator( expect(contentProviderUtils.getTrackPointLocationIterator(
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(90L); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(90L);
trackDataListener1.clearTrackPoints(); trackDataListener1.clearTrackPoints();
locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false); locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false);
trackDataListener1.onNewTrackPointsDone(); trackDataListener1.onNewTrackPointsDone();
@@ -594,15 +594,15 @@ public class TrackDataHubTest {
* Replays mocks. * Replays mocks.
*/ */
private void replay() { private void replay() {
AndroidMock.replay(myTracksProviderUtils, dataSource, trackDataListener1, trackDataListener2); AndroidMock.replay(contentProviderUtils, dataSource, trackDataListener1, trackDataListener2);
} }
/** /**
* Verifies and resets mocks. * Verifies and resets mocks.
*/ */
private void verifyAndReset() { private void verifyAndReset() {
AndroidMock.verify(myTracksProviderUtils, dataSource, trackDataListener1, trackDataListener2); AndroidMock.verify(contentProviderUtils, dataSource, trackDataListener1, trackDataListener2);
AndroidMock.reset(myTracksProviderUtils, dataSource, trackDataListener1, trackDataListener2); AndroidMock.reset(contentProviderUtils, dataSource, trackDataListener1, trackDataListener2);
} }
/** /**
@@ -725,7 +725,7 @@ public class TrackDataHubTest {
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>(); Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
dataSource.registerContentObserver(eq(TracksColumns.CONTENT_URI), capture(observerCapture)); dataSource.registerContentObserver(eq(TracksColumns.CONTENT_URI), capture(observerCapture));
Track track = TrackStubUtils.createTrack(1); Track track = TrackStubUtils.createTrack(1);
expect(myTracksProviderUtils.getTrack(capture(new Capture<Long>()))).andReturn(track); expect(contentProviderUtils.getTrack(capture(new Capture<Long>()))).andReturn(track);
// Make the track id is unique. // Make the track id is unique.
PreferencesUtils.setLong(context, R.string.recording_track_id_key, System.currentTimeMillis()); PreferencesUtils.setLong(context, R.string.recording_track_id_key, System.currentTimeMillis());
trackDataListener1.onTrackUpdated(track); trackDataListener1.onTrackUpdated(track);
@@ -742,7 +742,7 @@ public class TrackDataHubTest {
public void testRegisterWaypointsTableListener() { public void testRegisterWaypointsTableListener() {
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>(); Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
dataSource.registerContentObserver(eq(WaypointsColumns.CONTENT_URI), capture(observerCapture)); dataSource.registerContentObserver(eq(WaypointsColumns.CONTENT_URI), capture(observerCapture));
expect(myTracksProviderUtils.getWaypointCursor( expect(contentProviderUtils.getWaypointCursor(
capture(new Capture<Long>()), capture(new Capture<Long>()), capture(new Capture<Long>()), capture(new Capture<Long>()),
capture(new Capture<Integer>()))).andReturn(null); capture(new Capture<Integer>()))).andReturn(null);
trackDataListener1.clearWaypoints(); trackDataListener1.clearWaypoints();
@@ -23,7 +23,7 @@ import androidx.test.platform.app.InstrumentationRegistry;
import com.google.android.apps.mytracks.ChartView; import com.google.android.apps.mytracks.ChartView;
import com.google.android.apps.mytracks.TrackStubUtils; import com.google.android.apps.mytracks.TrackStubUtils;
import com.google.android.apps.mytracks.content.MyTracksLocation; import com.google.android.apps.mytracks.content.SensorDataSetLocation;
import com.google.android.apps.mytracks.content.sensor.Sensor; import com.google.android.apps.mytracks.content.sensor.Sensor;
import com.google.android.apps.mytracks.content.sensor.Sensor.SensorDataSet; import com.google.android.apps.mytracks.content.sensor.Sensor.SensorDataSet;
import com.google.android.apps.mytracks.util.UnitConversions; import com.google.android.apps.mytracks.util.UnitConversions;
@@ -56,10 +56,10 @@ public class ChartFragmentTest {
* double[])} * double[])}
*/ */
public void testFillDataPoint_sensorIncorrect() { public void testFillDataPoint_sensorIncorrect() {
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
// No input. // No input.
double[] point = fillDataPointTestHelper(myTracksLocation); double[] point = fillDataPointTestHelper(sensorDataSetLocation);
Assert.assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1]); Assert.assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1]);
Assert.assertEquals(Double.NaN, point[ChartView.CADENCE_SERIES + 1]); Assert.assertEquals(Double.NaN, point[ChartView.CADENCE_SERIES + 1]);
Assert.assertEquals(Double.NaN, point[ChartView.POWER_SERIES + 1]); Assert.assertEquals(Double.NaN, point[ChartView.POWER_SERIES + 1]);
@@ -74,12 +74,12 @@ public class ChartFragmentTest {
.setValue(102).setState(Sensor.SensorState.NONE); .setValue(102).setState(Sensor.SensorState.NONE);
// Creates SensorDataSet. // Creates SensorDataSet.
SensorDataSet sensorDataSet = myTracksLocation.getSensorDataSet(); SensorDataSet sensorDataSet = sensorDataSetLocation.getSensorDataSet();
sensorDataSet = sensorDataSet.toBuilder() sensorDataSet = sensorDataSet.toBuilder()
.setHeartRate(heartRateData).setCadence(cadenceData).setPower(powerData).build(); .setHeartRate(heartRateData).setCadence(cadenceData).setPower(powerData).build();
myTracksLocation.setSensorDataSet(sensorDataSet); sensorDataSetLocation.setSensorDataSet(sensorDataSet);
// Test. // Test.
point = fillDataPointTestHelper(myTracksLocation); point = fillDataPointTestHelper(sensorDataSetLocation);
Assert.assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1]); Assert.assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1]);
Assert.assertEquals(Double.NaN, point[ChartView.CADENCE_SERIES + 1]); Assert.assertEquals(Double.NaN, point[ChartView.CADENCE_SERIES + 1]);
Assert.assertEquals(Double.NaN, point[ChartView.POWER_SERIES + 1]); Assert.assertEquals(Double.NaN, point[ChartView.POWER_SERIES + 1]);
@@ -90,9 +90,9 @@ public class ChartFragmentTest {
* double[])}. * double[])}.
*/ */
public void testFillDataPoint_sensorCorrect() { public void testFillDataPoint_sensorCorrect() {
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
// No input. // No input.
double[] point = fillDataPointTestHelper(myTracksLocation); double[] point = fillDataPointTestHelper(sensorDataSetLocation);
Assert.assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1]); Assert.assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1]);
Assert.assertEquals(Double.NaN, point[ChartView.CADENCE_SERIES + 1]); Assert.assertEquals(Double.NaN, point[ChartView.CADENCE_SERIES + 1]);
Assert.assertEquals(Double.NaN, point[ChartView.POWER_SERIES + 1]); Assert.assertEquals(Double.NaN, point[ChartView.POWER_SERIES + 1]);
@@ -106,12 +106,12 @@ public class ChartFragmentTest {
.setValue(102).setState(Sensor.SensorState.SENDING); .setValue(102).setState(Sensor.SensorState.SENDING);
// Creates SensorDataSet. // Creates SensorDataSet.
SensorDataSet sensorDataSet = myTracksLocation.getSensorDataSet(); SensorDataSet sensorDataSet = sensorDataSetLocation.getSensorDataSet();
sensorDataSet = sensorDataSet.toBuilder() sensorDataSet = sensorDataSet.toBuilder()
.setHeartRate(heartRateData).setCadence(cadenceData).setPower(powerData).build(); .setHeartRate(heartRateData).setCadence(cadenceData).setPower(powerData).build();
myTracksLocation.setSensorDataSet(sensorDataSet); sensorDataSetLocation.setSensorDataSet(sensorDataSet);
// Test. // Test.
point = fillDataPointTestHelper(myTracksLocation); point = fillDataPointTestHelper(sensorDataSetLocation);
Assert.assertEquals(100.0, point[ChartView.HEART_RATE_SERIES + 1]); Assert.assertEquals(100.0, point[ChartView.HEART_RATE_SERIES + 1]);
Assert.assertEquals(101.0, point[ChartView.CADENCE_SERIES + 1]); Assert.assertEquals(101.0, point[ChartView.CADENCE_SERIES + 1]);
Assert.assertEquals(102.0, point[ChartView.POWER_SERIES + 1]); Assert.assertEquals(102.0, point[ChartView.POWER_SERIES + 1]);
@@ -125,35 +125,35 @@ public class ChartFragmentTest {
// By distance. // By distance.
chartFragment.setChartByDistance(true); chartFragment.setChartByDistance(true);
// Resets last location and writes first location. // Resets last location and writes first location.
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
double[] point = fillDataPointTestHelper(myTracksLocation1); double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
Assert.assertEquals(0.0, point[0]); Assert.assertEquals(0.0, point[0]);
// The second is a same location, just different time. // The second is a same location, just different time.
MyTracksLocation myTracksLocation2 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
point = fillDataPointTestHelper(myTracksLocation2); point = fillDataPointTestHelper(sensorDataSetLocation2);
Assert.assertEquals(0.0, point[0]); Assert.assertEquals(0.0, point[0]);
// The third location is a new location, and use metric. // The third location is a new location, and use metric.
MyTracksLocation myTracksLocation3 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation3 = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation3.setLatitude(23); sensorDataSetLocation3.setLatitude(23);
point = fillDataPointTestHelper(myTracksLocation3); point = fillDataPointTestHelper(sensorDataSetLocation3);
// Computes the distance between Latitude 22 and 23. // Computes the distance between Latitude 22 and 23.
float[] results = new float[4]; float[] results = new float[4];
Location.distanceBetween(myTracksLocation2.getLatitude(), myTracksLocation2.getLongitude(), Location.distanceBetween(sensorDataSetLocation2.getLatitude(), sensorDataSetLocation2.getLongitude(),
myTracksLocation3.getLatitude(), myTracksLocation3.getLongitude(), results); sensorDataSetLocation3.getLatitude(), sensorDataSetLocation3.getLongitude(), results);
double distance1 = results[0] * UnitConversions.M_TO_KM; double distance1 = results[0] * UnitConversions.M_TO_KM;
Assert.assertEquals(distance1, point[0]); Assert.assertEquals(distance1, point[0]);
// The fourth location is a new location, and use metric. // The fourth location is a new location, and use metric.
MyTracksLocation myTracksLocation4 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation4 = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation4.setLatitude(24); sensorDataSetLocation4.setLatitude(24);
point = fillDataPointTestHelper(myTracksLocation4); point = fillDataPointTestHelper(sensorDataSetLocation4);
// Computes the distance between Latitude 23 and 24. // Computes the distance between Latitude 23 and 24.
Location.distanceBetween(myTracksLocation3.getLatitude(), myTracksLocation3.getLongitude(), Location.distanceBetween(sensorDataSetLocation3.getLatitude(), sensorDataSetLocation3.getLongitude(),
myTracksLocation4.getLatitude(), myTracksLocation4.getLongitude(), results); sensorDataSetLocation4.getLatitude(), sensorDataSetLocation4.getLongitude(), results);
double distance2 = results[0] * UnitConversions.M_TO_KM; double distance2 = results[0] * UnitConversions.M_TO_KM;
Assert.assertEquals((distance1 + distance2), point[0]); Assert.assertEquals((distance1 + distance2), point[0]);
} }
@@ -169,36 +169,36 @@ public class ChartFragmentTest {
chartFragment.setMetricUnits(false); chartFragment.setMetricUnits(false);
// The first is a same location, just different time. // The first is a same location, just different time.
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
double[] point = fillDataPointTestHelper(myTracksLocation1); double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
Assert.assertEquals(0.0, point[0]); Assert.assertEquals(0.0, point[0]);
// The second location is a new location, and use imperial. // The second location is a new location, and use imperial.
MyTracksLocation myTracksLocation2 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation2.setLatitude(23); sensorDataSetLocation2.setLatitude(23);
point = fillDataPointTestHelper(myTracksLocation2); point = fillDataPointTestHelper(sensorDataSetLocation2);
/* /*
* Computes the distance between Latitude 22 and 23. And for we set using * Computes the distance between Latitude 22 and 23. And for we set using
* imperial, the distance should be multiplied by UnitConversions.KM_TO_MI. * imperial, the distance should be multiplied by UnitConversions.KM_TO_MI.
*/ */
float[] results = new float[4]; float[] results = new float[4];
Location.distanceBetween(myTracksLocation1.getLatitude(), myTracksLocation1.getLongitude(), Location.distanceBetween(sensorDataSetLocation1.getLatitude(), sensorDataSetLocation1.getLongitude(),
myTracksLocation2.getLatitude(), myTracksLocation2.getLongitude(), results); sensorDataSetLocation2.getLatitude(), sensorDataSetLocation2.getLongitude(), results);
double distance1 = results[0] * UnitConversions.M_TO_KM * UnitConversions.KM_TO_MI; double distance1 = results[0] * UnitConversions.M_TO_KM * UnitConversions.KM_TO_MI;
Assert.assertEquals(distance1, point[0]); Assert.assertEquals(distance1, point[0]);
// The third location is a new location, and use imperial. // The third location is a new location, and use imperial.
MyTracksLocation myTracksLocation3 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation3 = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation3.setLatitude(24); sensorDataSetLocation3.setLatitude(24);
point = fillDataPointTestHelper(myTracksLocation3); point = fillDataPointTestHelper(sensorDataSetLocation3);
/* /*
* Computes the distance between Latitude 23 and 24. And for we set using * Computes the distance between Latitude 23 and 24. And for we set using
* imperial, the distance should be multiplied by UnitConversions.KM_TO_MI. * imperial, the distance should be multiplied by UnitConversions.KM_TO_MI.
*/ */
Location.distanceBetween(myTracksLocation2.getLatitude(), myTracksLocation2.getLongitude(), Location.distanceBetween(sensorDataSetLocation2.getLatitude(), sensorDataSetLocation2.getLongitude(),
myTracksLocation3.getLatitude(), myTracksLocation3.getLongitude(), results); sensorDataSetLocation3.getLatitude(), sensorDataSetLocation3.getLongitude(), results);
double distance2 = results[0] * UnitConversions.M_TO_KM * UnitConversions.KM_TO_MI; double distance2 = results[0] * UnitConversions.M_TO_KM * UnitConversions.KM_TO_MI;
Assert.assertEquals(distance1 + distance2, point[0]); Assert.assertEquals(distance1 + distance2, point[0]);
} }
@@ -210,13 +210,13 @@ public class ChartFragmentTest {
public void testFillDataPoint_time() { public void testFillDataPoint_time() {
// By time // By time
chartFragment.setChartByDistance(false); chartFragment.setChartByDistance(false);
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
double[] point = fillDataPointTestHelper(myTracksLocation1); double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
Assert.assertEquals(0.0, point[0]); Assert.assertEquals(0.0, point[0]);
long timeSpan = 222; long timeSpan = 222;
MyTracksLocation myTracksLocation2 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation2.setTime(myTracksLocation1.getTime() + timeSpan); sensorDataSetLocation2.setTime(sensorDataSetLocation1.getTime() + timeSpan);
point = fillDataPointTestHelper(myTracksLocation2); point = fillDataPointTestHelper(sensorDataSetLocation2);
Assert.assertEquals((double) timeSpan, point[0]); Assert.assertEquals((double) timeSpan, point[0]);
} }
@@ -225,22 +225,22 @@ public class ChartFragmentTest {
* double[])} by one and two points. * double[])} by one and two points.
*/ */
public void testFillDataPoint_elevation() { public void testFillDataPoint_elevation() {
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
/* /*
* At first, clear old points of elevation, so give true to the second * At first, clear old points of elevation, so give true to the second
* parameter. Then only one value INITIALLONGTITUDE in buffer. * parameter. Then only one value INITIALLONGTITUDE in buffer.
*/ */
double[] point = fillDataPointTestHelper(myTracksLocation1); double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
Assert.assertEquals(TrackStubUtils.INITIAL_ALTITUDE, point[ChartView.ELEVATION_SERIES + 1]); Assert.assertEquals(TrackStubUtils.INITIAL_ALTITUDE, point[ChartView.ELEVATION_SERIES + 1]);
/* /*
* Send another value to buffer, now there are two values, INITIALALTITUDE * Send another value to buffer, now there are two values, INITIALALTITUDE
* and INITIALALTITUDE * 2. * and INITIALALTITUDE * 2.
*/ */
MyTracksLocation myTracksLocation2 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation2.setAltitude(TrackStubUtils.INITIAL_ALTITUDE * 2); sensorDataSetLocation2.setAltitude(TrackStubUtils.INITIAL_ALTITUDE * 2);
point = fillDataPointTestHelper(myTracksLocation2); point = fillDataPointTestHelper(sensorDataSetLocation2);
Assert.assertEquals((TrackStubUtils.INITIAL_ALTITUDE + TrackStubUtils.INITIAL_ALTITUDE * 2) / 2.0, Assert.assertEquals((TrackStubUtils.INITIAL_ALTITUDE + TrackStubUtils.INITIAL_ALTITUDE * 2) / 2.0,
point[ChartView.ELEVATION_SERIES + 1]); point[ChartView.ELEVATION_SERIES + 1]);
} }
@@ -256,24 +256,24 @@ public class ChartFragmentTest {
* At first, clear old points of speed, so give true to the second * At first, clear old points of speed, so give true to the second
* parameter. It will not be filled in to the speed buffer. * parameter. It will not be filled in to the speed buffer.
*/ */
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation1.setSpeed(128.5f); sensorDataSetLocation1.setSpeed(128.5f);
double[] point = fillDataPointTestHelper(myTracksLocation1); double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1]); Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1]);
/* /*
* Tests the logic when both metricUnits and reportSpeed are true.This * Tests the logic when both metricUnits and reportSpeed are true.This
* location will be filled into speed buffer. * location will be filled into speed buffer.
*/ */
MyTracksLocation myTracksLocation2 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
/* /*
* Add a time span here to make sure the second point is valid, the value * Add a time span here to make sure the second point is valid, the value
* 222 here is doesn't matter. * 222 here is doesn't matter.
*/ */
myTracksLocation2.setTime(myTracksLocation1.getTime() + 222); sensorDataSetLocation2.setTime(sensorDataSetLocation1.getTime() + 222);
myTracksLocation2.setSpeed(130); sensorDataSetLocation2.setSpeed(130);
point = fillDataPointTestHelper(myTracksLocation2); point = fillDataPointTestHelper(sensorDataSetLocation2);
Assert.assertEquals(130.0 * UnitConversions.MS_TO_KMH, point[ChartView.SPEED_SERIES + 1]); Assert.assertEquals(130.0 * UnitConversions.MS_TO_KMH, point[ChartView.SPEED_SERIES + 1]);
} }
@@ -285,21 +285,21 @@ public class ChartFragmentTest {
chartFragment.setMetricUnits(false); chartFragment.setMetricUnits(false);
// First data point is not added to the speed buffer // First data point is not added to the speed buffer
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation1.setSpeed(100.0f); sensorDataSetLocation1.setSpeed(100.0f);
double[] point = fillDataPointTestHelper(myTracksLocation1); double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1]); Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1]);
MyTracksLocation myTracksLocation2 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
/* /*
* Add a time span here to make sure the second point is valid and the speed * Add a time span here to make sure the second point is valid and the speed
* is valid. Speed is valid if: speedDifference > Constants.MAX_ACCELERATION * is valid. Speed is valid if: speedDifference > Constants.MAX_ACCELERATION
* * timeDifference speedDifference = 102 -100 timeDifference = 222 * * timeDifference speedDifference = 102 -100 timeDifference = 222
*/ */
myTracksLocation2.setTime(myTracksLocation2.getTime() + 222); sensorDataSetLocation2.setTime(sensorDataSetLocation2.getTime() + 222);
myTracksLocation2.setSpeed(102); sensorDataSetLocation2.setSpeed(102);
point = fillDataPointTestHelper(myTracksLocation2); point = fillDataPointTestHelper(sensorDataSetLocation2);
Assert.assertEquals(102.0 * UnitConversions.MS_TO_KMH * UnitConversions.KM_TO_MI, point[ChartView.SPEED_SERIES + 1]); Assert.assertEquals(102.0 * UnitConversions.MS_TO_KMH * UnitConversions.KM_TO_MI, point[ChartView.SPEED_SERIES + 1]);
} }
@@ -311,21 +311,21 @@ public class ChartFragmentTest {
chartFragment.setReportSpeed(false); chartFragment.setReportSpeed(false);
// First data point is not added to the speed buffer // First data point is not added to the speed buffer
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation1.setSpeed(100.0f); sensorDataSetLocation1.setSpeed(100.0f);
double[] point = fillDataPointTestHelper(myTracksLocation1); double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1]); Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1]);
MyTracksLocation myTracksLocation2 = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
/* /*
* Add a time span here to make sure the second point is valid and the speed * Add a time span here to make sure the second point is valid and the speed
* is valid. Speed is valid if: speedDifference > Constants.MAX_ACCELERATION * is valid. Speed is valid if: speedDifference > Constants.MAX_ACCELERATION
* * timeDifference speedDifference = 102 -100 timeDifference = 222 * * timeDifference speedDifference = 102 -100 timeDifference = 222
*/ */
myTracksLocation2.setTime(myTracksLocation2.getTime() + 222); sensorDataSetLocation2.setTime(sensorDataSetLocation2.getTime() + 222);
myTracksLocation2.setSpeed(102); sensorDataSetLocation2.setSpeed(102);
point = fillDataPointTestHelper(myTracksLocation2); point = fillDataPointTestHelper(sensorDataSetLocation2);
Assert.assertEquals(HOURS_PER_UNIT / (102.0 * UnitConversions.MS_TO_KMH), point[ChartView.PACE_SERIES + 1]); Assert.assertEquals(HOURS_PER_UNIT / (102.0 * UnitConversions.MS_TO_KMH), point[ChartView.PACE_SERIES + 1]);
} }
@@ -336,9 +336,9 @@ public class ChartFragmentTest {
public void testFillDataPoint_pace_zeroSpeed() { public void testFillDataPoint_pace_zeroSpeed() {
// Setups reportSpeed to false. // Setups reportSpeed to false.
chartFragment.setReportSpeed(false); chartFragment.setReportSpeed(false);
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation(); SensorDataSetLocation sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
myTracksLocation.setSpeed(0); sensorDataSetLocation.setSpeed(0);
double[] point = fillDataPointTestHelper(myTracksLocation); double[] point = fillDataPointTestHelper(sensorDataSetLocation);
Assert.assertEquals(0.0, point[ChartView.PACE_SERIES + 1]); Assert.assertEquals(0.0, point[ChartView.PACE_SERIES + 1]);
} }
@@ -19,8 +19,8 @@ package com.google.android.apps.mytracks.io.file.importer;
import static com.google.android.testing.mocking.AndroidMock.eq; import static com.google.android.testing.mocking.AndroidMock.eq;
import static com.google.android.testing.mocking.AndroidMock.expect; import static com.google.android.testing.mocking.AndroidMock.expect;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.Factory; import com.google.android.apps.mytracks.content.ContentProviderUtils.Factory;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
@@ -92,17 +92,17 @@ public class AbstractTestFileTrackImporter extends AndroidTestCase {
protected static final Uri WAYPOINT_ID_O_URI = ContentUris.appendId( protected static final Uri WAYPOINT_ID_O_URI = ContentUris.appendId(
WaypointsColumns.CONTENT_URI.buildUpon(), WAYPOINT_ID_0).build(); WaypointsColumns.CONTENT_URI.buildUpon(), WAYPOINT_ID_0).build();
protected MyTracksProviderUtils myTracksProviderUtils; protected ContentProviderUtils contentProviderUtils;
private Factory oldMyTracksProviderUtilsFactory; private Factory oldMyTracksProviderUtilsFactory;
@UsesMocks(MyTracksProviderUtils.class) @UsesMocks(ContentProviderUtils.class)
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
myTracksProviderUtils = AndroidMock.createMock(MyTracksProviderUtils.class); contentProviderUtils = AndroidMock.createMock(ContentProviderUtils.class);
oldMyTracksProviderUtilsFactory = TestingProviderUtilsFactory.installWithInstance( oldMyTracksProviderUtilsFactory = TestingProviderUtilsFactory.installWithInstance(
myTracksProviderUtils); contentProviderUtils);
} }
@Override @Override
@@ -128,11 +128,11 @@ public class AbstractTestFileTrackImporter extends AndroidTestCase {
* @param trackPointId the track point id * @param trackPointId the track point id
*/ */
protected void expectFirstTrackPoint(Location location, long trackId, long trackPointId) { protected void expectFirstTrackPoint(Location location, long trackId, long trackPointId) {
expect(myTracksProviderUtils.bulkInsertTrackPoint( expect(contentProviderUtils.bulkInsertTrackPoint(
location != null ? LocationsMatcher.eqLoc(location) : (Location[]) AndroidMock.anyObject(), location != null ? LocationsMatcher.eqLoc(location) : (Location[]) AndroidMock.anyObject(),
eq(1), eq(trackId))).andReturn(1); eq(1), eq(trackId))).andReturn(1);
expect(myTracksProviderUtils.getFirstTrackPointId(trackId)).andReturn(trackPointId); expect(contentProviderUtils.getFirstTrackPointId(trackId)).andReturn(trackPointId);
expect(myTracksProviderUtils.getLastTrackPointId(trackId)).andReturn(trackPointId); expect(contentProviderUtils.getLastTrackPointId(trackId)).andReturn(trackPointId);
} }
/** /**
@@ -143,12 +143,12 @@ public class AbstractTestFileTrackImporter extends AndroidTestCase {
* @param trackId the track id * @param trackId the track id
*/ */
protected void expectUpdateTrack(Capture<Track> track, boolean lastTrack, long trackId) { protected void expectUpdateTrack(Capture<Track> track, boolean lastTrack, long trackId) {
myTracksProviderUtils.updateTrack(AndroidMock.capture(track)); contentProviderUtils.updateTrack(AndroidMock.capture(track));
expect(myTracksProviderUtils.insertWaypoint((Waypoint) AndroidMock.anyObject())) expect(contentProviderUtils.insertWaypoint((Waypoint) AndroidMock.anyObject()))
.andReturn(WAYPOINT_ID_O_URI); .andReturn(WAYPOINT_ID_O_URI);
if (lastTrack) { if (lastTrack) {
// Return null to not add waypoints // Return null to not add waypoints
expect(myTracksProviderUtils.getTrack(trackId)).andReturn(null); expect(contentProviderUtils.getTrack(trackId)).andReturn(null);
} }
} }
@@ -90,30 +90,30 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime()); Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime()); Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
expect(myTracksProviderUtils.insertTrack((Track) AndroidMock.anyObject())) expect(contentProviderUtils.insertTrack((Track) AndroidMock.anyObject()))
.andReturn(TRACK_ID_0_URI); .andReturn(TRACK_ID_0_URI);
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0); expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
// A flush happens at the end // A flush happens at the end
expect(myTracksProviderUtils.bulkInsertTrackPoint( expect(contentProviderUtils.bulkInsertTrackPoint(
LocationsMatcher.eqLoc(location1), eq(1), eq(TRACK_ID_0))).andReturn(1); LocationsMatcher.eqLoc(location1), eq(1), eq(TRACK_ID_0))).andReturn(1);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_1); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_1);
expect( expect(
myTracksProviderUtils.getTrack(PreferencesUtils.getLong(getContext(), contentProviderUtils.getTrack(PreferencesUtils.getLong(getContext(),
R.string.recording_track_id_key))).andStubReturn(null); R.string.recording_track_id_key))).andStubReturn(null);
expectUpdateTrack(track, true, TRACK_ID_0); expectUpdateTrack(track, true, TRACK_ID_0);
AndroidMock.replay(myTracksProviderUtils); AndroidMock.replay(contentProviderUtils);
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes()); InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter( GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
getContext(), myTracksProviderUtils); getContext(), contentProviderUtils);
long trackId = gpxFileTrackImporter.importFile(inputStream); long trackId = gpxFileTrackImporter.importFile(inputStream);
assertEquals(TRACK_ID_0, trackId); assertEquals(TRACK_ID_0, trackId);
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime(); long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
long time1 = DATE_FORMAT_1.parse(TRACK_TIME_1).getTime(); long time1 = DATE_FORMAT_1.parse(TRACK_TIME_1).getTime();
assertEquals(time1 - time0, track.getValue().getTripStatistics().getTotalTime()); assertEquals(time1 - time0, track.getValue().getTripStatistics().getTotalTime());
AndroidMock.verify(myTracksProviderUtils); AndroidMock.verify(contentProviderUtils);
verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, time0); verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, time0);
} }
@@ -125,22 +125,22 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime()); Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
expect(myTracksProviderUtils.insertTrack((Track) AndroidMock.anyObject())) expect(contentProviderUtils.insertTrack((Track) AndroidMock.anyObject()))
.andReturn(TRACK_ID_0_URI); .andReturn(TRACK_ID_0_URI);
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0); expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
// A flush happens at the end // A flush happens at the end
expect(myTracksProviderUtils.bulkInsertTrackPoint( expect(contentProviderUtils.bulkInsertTrackPoint(
(Location[]) AndroidMock.anyObject(), eq(5), eq(TRACK_ID_0))).andStubReturn(5); (Location[]) AndroidMock.anyObject(), eq(5), eq(TRACK_ID_0))).andStubReturn(5);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_3); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_3);
expect( expect(
myTracksProviderUtils.getTrack(PreferencesUtils.getLong(getContext(), contentProviderUtils.getTrack(PreferencesUtils.getLong(getContext(),
R.string.recording_track_id_key))).andStubReturn(null); R.string.recording_track_id_key))).andStubReturn(null);
expectUpdateTrack(track, true, TRACK_ID_0); expectUpdateTrack(track, true, TRACK_ID_0);
AndroidMock.replay(myTracksProviderUtils); AndroidMock.replay(contentProviderUtils);
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes()); InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter( GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
getContext(), myTracksProviderUtils); getContext(), contentProviderUtils);
long trackId = gpxFileTrackImporter.importFile(inputStream); long trackId = gpxFileTrackImporter.importFile(inputStream);
assertEquals(TRACK_ID_0, trackId); assertEquals(TRACK_ID_0, trackId);
@@ -151,7 +151,7 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
assertEquals( assertEquals(
time1 - time0 + time3 - time2, track.getValue().getTripStatistics().getTotalTime()); time1 - time0 + time3 - time2, track.getValue().getTripStatistics().getTotalTime());
AndroidMock.verify(myTracksProviderUtils); AndroidMock.verify(contentProviderUtils);
verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0,
DATE_FORMAT_0.parse(TRACK_TIME_0).getTime()); DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
} }
@@ -162,29 +162,29 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
public void testOneTrackTwoSegmentsNoTime() throws Exception { public void testOneTrackTwoSegmentsNoTime() throws Exception {
Capture<Track> track = new Capture<Track>(); Capture<Track> track = new Capture<Track>();
expect(myTracksProviderUtils.insertTrack((Track) AndroidMock.anyObject())) expect(contentProviderUtils.insertTrack((Track) AndroidMock.anyObject()))
.andReturn(TRACK_ID_0_URI); .andReturn(TRACK_ID_0_URI);
expectFirstTrackPoint(null, TRACK_ID_0, TRACK_POINT_ID_0); expectFirstTrackPoint(null, TRACK_ID_0, TRACK_POINT_ID_0);
// A flush happens at the end // A flush happens at the end
expect(myTracksProviderUtils.bulkInsertTrackPoint( expect(contentProviderUtils.bulkInsertTrackPoint(
(Location[]) AndroidMock.anyObject(), eq(5), eq(TRACK_ID_0))).andStubReturn(5); (Location[]) AndroidMock.anyObject(), eq(5), eq(TRACK_ID_0))).andStubReturn(5);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_3); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_3);
expect( expect(
myTracksProviderUtils.getTrack(PreferencesUtils.getLong(getContext(), contentProviderUtils.getTrack(PreferencesUtils.getLong(getContext(),
R.string.recording_track_id_key))).andStubReturn(null); R.string.recording_track_id_key))).andStubReturn(null);
expectUpdateTrack(track, true, TRACK_ID_0); expectUpdateTrack(track, true, TRACK_ID_0);
AndroidMock.replay(myTracksProviderUtils); AndroidMock.replay(contentProviderUtils);
InputStream inputStream = new ByteArrayInputStream( InputStream inputStream = new ByteArrayInputStream(
VALID_ONE_TRACK_TWO_SEGMENTS_NO_TIME_GPX.getBytes()); VALID_ONE_TRACK_TWO_SEGMENTS_NO_TIME_GPX.getBytes());
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter( GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
getContext(), myTracksProviderUtils); getContext(), contentProviderUtils);
long trackId = gpxFileTrackImporter.importFile(inputStream); long trackId = gpxFileTrackImporter.importFile(inputStream);
assertEquals(TRACK_ID_0, trackId); assertEquals(TRACK_ID_0, trackId);
assertEquals(0, track.getValue().getTripStatistics().getTotalTime()); assertEquals(0, track.getValue().getTripStatistics().getTotalTime());
AndroidMock.verify(myTracksProviderUtils); AndroidMock.verify(contentProviderUtils);
verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, -1L); verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, -1L);
} }
@@ -231,27 +231,27 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
} }
private void testInvalidGpx(String xml) throws Exception { private void testInvalidGpx(String xml) throws Exception {
expect(myTracksProviderUtils.insertTrack((Track) AndroidMock.anyObject())) expect(contentProviderUtils.insertTrack((Track) AndroidMock.anyObject()))
.andReturn(TRACK_ID_0_URI); .andReturn(TRACK_ID_0_URI);
// For the following, use StubReturn since we don't care whether they are // For the following, use StubReturn since we don't care whether they are
// invoked or not. // invoked or not.
expect(myTracksProviderUtils.bulkInsertTrackPoint( expect(contentProviderUtils.bulkInsertTrackPoint(
(Location[]) AndroidMock.anyObject(), AndroidMock.anyInt(), AndroidMock.anyLong())) (Location[]) AndroidMock.anyObject(), AndroidMock.anyInt(), AndroidMock.anyLong()))
.andStubReturn(1); .andStubReturn(1);
expect(myTracksProviderUtils.getFirstTrackPointId(TRACK_ID_0)).andStubReturn(TRACK_POINT_ID_0); expect(contentProviderUtils.getFirstTrackPointId(TRACK_ID_0)).andStubReturn(TRACK_POINT_ID_0);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID_0)).andStubReturn(TRACK_POINT_ID_0); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).andStubReturn(TRACK_POINT_ID_0);
expect( expect(
myTracksProviderUtils.getTrack(PreferencesUtils.getLong(getContext(), contentProviderUtils.getTrack(PreferencesUtils.getLong(getContext(),
R.string.recording_track_id_key))).andStubReturn(null); R.string.recording_track_id_key))).andStubReturn(null);
myTracksProviderUtils.deleteTrack(getContext(), TRACK_ID_0); contentProviderUtils.deleteTrack(getContext(), TRACK_ID_0);
AndroidMock.replay(myTracksProviderUtils); AndroidMock.replay(contentProviderUtils);
InputStream inputStream = new ByteArrayInputStream(xml.getBytes()); InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter( GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
getContext(), myTracksProviderUtils); getContext(), contentProviderUtils);
long trackId = gpxFileTrackImporter.importFile(inputStream); long trackId = gpxFileTrackImporter.importFile(inputStream);
assertEquals(-1L, trackId); assertEquals(-1L, trackId);
AndroidMock.verify(myTracksProviderUtils); AndroidMock.verify(contentProviderUtils);
} }
} }
@@ -74,29 +74,29 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime()); Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime()); Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
myTracksProviderUtils.clearTrack(getContext(), TRACK_ID_0); contentProviderUtils.clearTrack(getContext(), TRACK_ID_0);
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0); expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
// A flush happens at the end // A flush happens at the end
expect(myTracksProviderUtils.bulkInsertTrackPoint( expect(contentProviderUtils.bulkInsertTrackPoint(
LocationsMatcher.eqLoc(location1), eq(1), eq(TRACK_ID_0))).andReturn(1); LocationsMatcher.eqLoc(location1), eq(1), eq(TRACK_ID_0))).andReturn(1);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_1); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_1);
expect( expect(
myTracksProviderUtils.getTrack(PreferencesUtils.getLong(getContext(), contentProviderUtils.getTrack(PreferencesUtils.getLong(getContext(),
R.string.recording_track_id_key))).andStubReturn(null); R.string.recording_track_id_key))).andStubReturn(null);
expectUpdateTrack(track, true, TRACK_ID_0); expectUpdateTrack(track, true, TRACK_ID_0);
AndroidMock.replay(myTracksProviderUtils); AndroidMock.replay(contentProviderUtils);
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes()); InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter( KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(
getContext(), TRACK_ID_0, myTracksProviderUtils); getContext(), TRACK_ID_0, contentProviderUtils);
long trackId = kmlFileTrackImporter.importFile(inputStream); long trackId = kmlFileTrackImporter.importFile(inputStream);
assertEquals(TRACK_ID_0, trackId); assertEquals(TRACK_ID_0, trackId);
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime(); long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
long time1 = DATE_FORMAT_1.parse(TRACK_TIME_1).getTime(); long time1 = DATE_FORMAT_1.parse(TRACK_TIME_1).getTime();
assertEquals(time1 - time0, track.getValue().getTripStatistics().getTotalTime()); assertEquals(time1 - time0, track.getValue().getTripStatistics().getTotalTime());
AndroidMock.verify(myTracksProviderUtils); AndroidMock.verify(contentProviderUtils);
verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, time0); verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, time0);
} }
@@ -108,22 +108,22 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime()); Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
myTracksProviderUtils.clearTrack(getContext(), TRACK_ID_0); contentProviderUtils.clearTrack(getContext(), TRACK_ID_0);
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0); expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
// A flush happens at the end // A flush happens at the end
expect(myTracksProviderUtils.bulkInsertTrackPoint( expect(contentProviderUtils.bulkInsertTrackPoint(
(Location[]) AndroidMock.anyObject(), eq(5), eq(TRACK_ID_0))).andStubReturn(5); (Location[]) AndroidMock.anyObject(), eq(5), eq(TRACK_ID_0))).andStubReturn(5);
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_3); expect(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_3);
expect( expect(
myTracksProviderUtils.getTrack(PreferencesUtils.getLong(getContext(), contentProviderUtils.getTrack(PreferencesUtils.getLong(getContext(),
R.string.recording_track_id_key))).andStubReturn(null); R.string.recording_track_id_key))).andStubReturn(null);
expectUpdateTrack(track, true, TRACK_ID_0); expectUpdateTrack(track, true, TRACK_ID_0);
AndroidMock.replay(myTracksProviderUtils); AndroidMock.replay(contentProviderUtils);
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes()); InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter( KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(
getContext(), TRACK_ID_0, myTracksProviderUtils); getContext(), TRACK_ID_0, contentProviderUtils);
long trackId = kmlFileTrackImporter.importFile(inputStream); long trackId = kmlFileTrackImporter.importFile(inputStream);
assertEquals(TRACK_ID_0, trackId); assertEquals(TRACK_ID_0, trackId);
@@ -134,7 +134,7 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
assertEquals( assertEquals(
time1 - time0 + time3 - time2, track.getValue().getTripStatistics().getTotalTime()); time1 - time0 + time3 - time2, track.getValue().getTripStatistics().getTotalTime());
AndroidMock.verify(myTracksProviderUtils); AndroidMock.verify(contentProviderUtils);
verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, verifyTrack(track.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0,
DATE_FORMAT_0.parse(TRACK_TIME_0).getTime()); DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
} }
@@ -38,8 +38,8 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log; import android.util.Log;
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.CustomContentProvider;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
@@ -64,7 +64,7 @@ import java.util.List;
public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingService> { public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingService> {
private Context context; private Context context;
private MyTracksProviderUtils providerUtils; private ContentProviderUtils providerUtils;
/* /*
* In order to support starting and binding to the service in the same unit * In order to support starting and binding to the service in the same unit
@@ -135,9 +135,9 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
context = new MockContext(mockContentResolver, renamingDelegatingContext); context = new MockContext(mockContentResolver, renamingDelegatingContext);
// Set up the mock content resolver // Set up the mock content resolver
MyTracksProvider myTracksProvider = new MyTracksProvider(); CustomContentProvider myTracksProvider = new CustomContentProvider();
myTracksProvider.attachInfo(context, null); myTracksProvider.attachInfo(context, null);
mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, myTracksProvider); mockContentResolver.addProvider(ContentProviderUtils.AUTHORITY, myTracksProvider);
MockContentProvider settingsProvider = new MockContentProvider(context) { MockContentProvider settingsProvider = new MockContentProvider(context) {
@Override @Override
@@ -156,7 +156,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
// Set the context // Set the context
setContext(context); setContext(context);
providerUtils = MyTracksProviderUtils.Factory.get(context); providerUtils = ContentProviderUtils.Factory.get(context);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
// Let's use default values. // Let's use default values.
+3 -2
View File
@@ -162,9 +162,10 @@ limitations under the License.
android:name="android.app.default_searchable" android:name="android.app.default_searchable"
android:value="com.google.android.apps.mytracks.SearchListActivity" /> android:value="com.google.android.apps.mytracks.SearchListActivity" />
</activity> </activity>
<activity android:name="com.google.android.apps.mytracks.io.file.exporter.SaveActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.AdvancedSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.AdvancedSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.RecordingSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.RecordingSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SensorSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.SensorSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.SettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.StatsSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.StatsSettingsActivity" />
@@ -210,7 +211,7 @@ limitations under the License.
android:authorities="com.google.android.maps.mytracks" android:authorities="com.google.android.maps.mytracks"
android:exported="false" android:exported="false"
android:grantUriPermissions="true" android:grantUriPermissions="true"
android:name="com.google.android.apps.mytracks.content.MyTracksProvider" android:name="com.google.android.apps.mytracks.content.CustomContentProvider"
android:readPermission="com.google.android.apps.mytracks.READ_TRACK_DATA" android:readPermission="com.google.android.apps.mytracks.READ_TRACK_DATA"
android:writePermission="com.google.android.apps.mytracks.WRITE_TRACK_DATA" /> android:writePermission="com.google.android.apps.mytracks.WRITE_TRACK_DATA" />
<!-- Search suggestion provider --> <!-- Search suggestion provider -->
@@ -16,7 +16,7 @@
package com.google.android.apps.mytracks; package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.util.StatsUtils; import com.google.android.apps.mytracks.util.StatsUtils;
@@ -50,7 +50,7 @@ public class AggregatedStatsActivity extends AbstractActivity {
* there is no track. * there is no track.
*/ */
private TripStatistics getTripStatistics() { private TripStatistics getTripStatistics() {
List<Track> tracks = MyTracksProviderUtils.Factory.get(this).getAllTracks(); List<Track> tracks = ContentProviderUtils.Factory.get(this).getAllTracks();
TripStatistics tripStatistics = null; TripStatistics tripStatistics = null;
if (!tracks.isEmpty()) { if (!tracks.isEmpty()) {
tripStatistics = new TripStatistics(tracks.iterator().next().getTripStatistics()); tripStatistics = new TripStatistics(tracks.iterator().next().getTripStatistics());
@@ -19,7 +19,7 @@ package com.google.android.apps.mytracks;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
/** /**
* Async Task to delete tracks. * Async Task to delete tracks.
@@ -70,16 +70,16 @@ public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
@Override @Override
protected Boolean doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(context);
if (trackIds.length == 1 && trackIds[0] == -1L) { if (trackIds.length == 1 && trackIds[0] == -1L) {
myTracksProviderUtils.deleteAllTracks(context); contentProviderUtils.deleteAllTracks(context);
} else { } else {
for (long id : trackIds) { for (long id : trackIds) {
if (isCancelled()) { if (isCancelled()) {
return false; return false;
} }
myTracksProviderUtils.deleteTrack(context, id); contentProviderUtils.deleteTrack(context, id);
} }
} }
return true; return true;
@@ -25,7 +25,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller; import com.google.android.apps.mytracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
import com.google.android.apps.mytracks.fragments.MarkerDetailFragment; import com.google.android.apps.mytracks.fragments.MarkerDetailFragment;
@@ -56,20 +56,20 @@ public class MarkerDetailActivity extends AbstractActivity implements DeleteMark
return; return;
} }
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(this);
Waypoint waypoint = myTracksProviderUtils.getWaypoint(markerId); Waypoint waypoint = contentProviderUtils.getWaypoint(markerId);
markerIds = new ArrayList<>(); markerIds = new ArrayList<>();
int markerIndex = -1; int markerIndex = -1;
try (Cursor cursor = myTracksProviderUtils.getWaypointCursor(waypoint.getTrackId(), -1L, -1)) { try (Cursor cursor = contentProviderUtils.getWaypointCursor(waypoint.getTrackId(), -1L, -1)) {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
/* /*
* Yes, this will skip the first waypoint and that is intentional as the * Yes, this will skip the first waypoint and that is intentional as the
* first waypoint holds the stats for the track. * first waypoint holds the stats for the track.
*/ */
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
Waypoint current = myTracksProviderUtils.createWaypoint(cursor); Waypoint current = contentProviderUtils.createWaypoint(cursor);
markerIds.add(current.getId()); markerIds.add(current.getId());
if (current.getId() == markerId) { if (current.getId() == markerId) {
@@ -16,7 +16,7 @@
package com.google.android.apps.mytracks; package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import com.google.android.apps.mytracks.content.WaypointCreationRequest; import com.google.android.apps.mytracks.content.WaypointCreationRequest;
@@ -130,7 +130,7 @@ public class MarkerEditActivity extends AbstractActivity {
statisticsSection.setVisibility(View.GONE); statisticsSection.setVisibility(View.GONE);
waypointSection.setVisibility(View.VISIBLE); waypointSection.setVisibility(View.VISIBLE);
int nextWaypointNumber = trackId == -1L ? -1 int nextWaypointNumber = trackId == -1L ? -1
: MyTracksProviderUtils.Factory.get(this).getNextWaypointNumber(trackId, WaypointType.WAYPOINT); : ContentProviderUtils.Factory.get(this).getNextWaypointNumber(trackId, WaypointType.WAYPOINT);
if (nextWaypointNumber == -1) { if (nextWaypointNumber == -1) {
nextWaypointNumber = 0; nextWaypointNumber = 0;
} }
@@ -139,7 +139,7 @@ public class MarkerEditActivity extends AbstractActivity {
waypointMarkerType.setText(""); waypointMarkerType.setText("");
waypointDescription.setText(""); waypointDescription.setText("");
} else { } else {
waypoint = MyTracksProviderUtils.Factory.get(this).getWaypoint(markerId); waypoint = ContentProviderUtils.Factory.get(this).getWaypoint(markerId);
if (waypoint == null) { if (waypoint == null) {
Log.d(TAG, "waypoint is null"); Log.d(TAG, "waypoint is null");
finish(); finish();
@@ -186,6 +186,6 @@ public class MarkerEditActivity extends AbstractActivity {
waypoint.setCategory(waypointMarkerType.getText().toString()); waypoint.setCategory(waypointMarkerType.getText().toString());
waypoint.setDescription(waypointDescription.getText().toString()); waypoint.setDescription(waypointDescription.getText().toString());
} }
MyTracksProviderUtils.Factory.get(this).updateWaypoint(waypoint); ContentProviderUtils.Factory.get(this).updateWaypoint(waypoint);
} }
} }
@@ -40,7 +40,7 @@ import androidx.loader.app.LoaderManager.LoaderCallbacks;
import androidx.loader.content.CursorLoader; import androidx.loader.content.CursorLoader;
import androidx.loader.content.Loader; import androidx.loader.content.Loader;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import com.google.android.apps.mytracks.content.WaypointsColumns; import com.google.android.apps.mytracks.content.WaypointsColumns;
@@ -116,7 +116,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
} }
}; };
private MyTracksProviderUtils myTracksProviderUtils; private ContentProviderUtils contentProviderUtils;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
@@ -134,12 +134,12 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); contentProviderUtils = ContentProviderUtils.Factory.get(this);
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L); long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
track = trackId != -1L ? myTracksProviderUtils.getTrack(trackId) : null; track = trackId != -1L ? contentProviderUtils.getTrack(trackId) : null;
final long trackFirstWaypointId = trackId != -1 ? myTracksProviderUtils.getFirstWaypointId(trackId) : -1; final long trackFirstWaypointId = trackId != -1 ? contentProviderUtils.getFirstWaypointId(trackId) : -1;
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
@@ -38,7 +38,7 @@ import android.widget.ListView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.SearchEngine; import com.google.android.apps.mytracks.content.SearchEngine;
import com.google.android.apps.mytracks.content.SearchEngine.ScoredResult; import com.google.android.apps.mytracks.content.SearchEngine.ScoredResult;
import com.google.android.apps.mytracks.content.SearchEngine.SearchQuery; import com.google.android.apps.mytracks.content.SearchEngine.SearchQuery;
@@ -133,7 +133,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
if (isSingleSelection) { if (isSingleSelection) {
Map<String, Object> item = arrayAdapter.getItem(positions[0]); Map<String, Object> item = arrayAdapter.getItem(positions[0]);
Long trackId = (Long) item.get(TRACK_ID_FIELD); Long trackId = (Long) item.get(TRACK_ID_FIELD);
Track track = myTracksProviderUtils.getTrack(trackId); Track track = contentProviderUtils.getTrack(trackId);
isSingleSelectionTrack = item.get(MARKER_ID_FIELD) == null; isSingleSelectionTrack = item.get(MARKER_ID_FIELD) == null;
} else { } else {
@@ -154,7 +154,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
} }
}; };
private MyTracksProviderUtils myTracksProviderUtils; private ContentProviderUtils contentProviderUtils;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private TrackRecordingServiceConnection trackRecordingServiceConnection; private TrackRecordingServiceConnection trackRecordingServiceConnection;
private SearchEngine searchEngine; private SearchEngine searchEngine;
@@ -170,10 +170,10 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); contentProviderUtils = ContentProviderUtils.Factory.get(this);
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null); trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
searchEngine = new SearchEngine(myTracksProviderUtils); searchEngine = new SearchEngine(contentProviderUtils);
searchRecentSuggestions = SearchEngineProvider.newHelper(this); searchRecentSuggestions = SearchEngineProvider.newHelper(this);
arrayAdapter = new ArrayAdapter<Map<String, Object>>(this, R.layout.list_item, R.id.list_item_name) { arrayAdapter = new ArrayAdapter<Map<String, Object>>(this, R.layout.list_item, R.id.list_item_name) {
@@ -430,7 +430,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
String trackName = null; String trackName = null;
long trackId = waypoint.getTrackId(); long trackId = waypoint.getTrackId();
if (trackId != -1L) { if (trackId != -1L) {
Track track = myTracksProviderUtils.getTrack(trackId); Track track = contentProviderUtils.getTrack(trackId);
if (track != null) { if (track != null) {
trackName = track.getName(); trackName = track.getName();
} }
@@ -477,7 +477,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
resultMap.put(NAME_FIELD, track.getName()); resultMap.put(NAME_FIELD, track.getName());
resultMap.put(TOTAL_TIME_FIELD, StringUtils.formatElapsedTime(tripStatitics.getTotalTime())); resultMap.put(TOTAL_TIME_FIELD, StringUtils.formatElapsedTime(tripStatitics.getTotalTime()));
resultMap.put(TOTAL_DISTANCE_FIELD, StringUtils.formatDistance(this, tripStatitics.getTotalDistance(), metricUnits)); resultMap.put(TOTAL_DISTANCE_FIELD, StringUtils.formatDistance(this, tripStatitics.getTotalDistance(), metricUnits));
resultMap.put(MARKER_COUNT_FIELD, myTracksProviderUtils.getWaypointCount(track.getId())); resultMap.put(MARKER_COUNT_FIELD, contentProviderUtils.getWaypointCount(track.getId()));
resultMap.put(START_TIME_FIELD, tripStatitics.getStartTime()); resultMap.put(START_TIME_FIELD, tripStatitics.getStartTime());
resultMap.put(CATEGORY_FIELD, category); resultMap.put(CATEGORY_FIELD, category);
resultMap.put(DESCRIPTION_FIELD, track.getDescription()); resultMap.put(DESCRIPTION_FIELD, track.getDescription());
@@ -41,7 +41,7 @@ import androidx.core.app.TaskStackBuilder;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TrackDataHub; import com.google.android.apps.mytracks.content.TrackDataHub;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
@@ -93,7 +93,7 @@ public class TrackDetailActivity extends AbstractTrackActivity implements Choose
private boolean hasCamera; private boolean hasCamera;
private Uri photoUri; private Uri photoUri;
private boolean hasPhoto; private boolean hasPhoto;
private MyTracksProviderUtils myTracksProviderUtils; private ContentProviderUtils contentProviderUtils;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private TrackRecordingServiceConnection trackRecordingServiceConnection; private TrackRecordingServiceConnection trackRecordingServiceConnection;
private TrackDataHub trackDataHub; private TrackDataHub trackDataHub;
@@ -197,7 +197,7 @@ public class TrackDetailActivity extends AbstractTrackActivity implements Choose
photoUri = savedInstanceState != null ? (Uri) savedInstanceState.getParcelable(PHOTO_URI_KEY) : null; photoUri = savedInstanceState != null ? (Uri) savedInstanceState.getParcelable(PHOTO_URI_KEY) : null;
hasPhoto = savedInstanceState != null && savedInstanceState.getBoolean(HAS_PHOTO_KEY, false); hasPhoto = savedInstanceState != null && savedInstanceState.getBoolean(HAS_PHOTO_KEY, false);
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); contentProviderUtils = ContentProviderUtils.Factory.get(this);
handleIntent(getIntent()); handleIntent(getIntent());
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
@@ -458,7 +458,7 @@ public class TrackDetailActivity extends AbstractTrackActivity implements Choose
long markerId = intent.getLongExtra(EXTRA_MARKER_ID, -1L); long markerId = intent.getLongExtra(EXTRA_MARKER_ID, -1L);
if (markerId != -1L) { if (markerId != -1L) {
// Use the trackId from the marker // Use the trackId from the marker
Waypoint waypoint = myTracksProviderUtils.getWaypoint(markerId); Waypoint waypoint = contentProviderUtils.getWaypoint(markerId);
if (waypoint == null) { if (waypoint == null) {
finish(); finish();
return; return;
@@ -469,11 +469,11 @@ public class TrackDetailActivity extends AbstractTrackActivity implements Choose
finish(); finish();
return; return;
} }
Track track = myTracksProviderUtils.getTrack(trackId); Track track = contentProviderUtils.getTrack(trackId);
if (track == null) { if (track == null) {
// Use the last track if markerId is not set // Use the last track if markerId is not set
if (markerId == -1L) { if (markerId == -1L) {
track = myTracksProviderUtils.getLastTrack(); track = contentProviderUtils.getLastTrack();
if (track != null) { if (track != null) {
trackId = track.getId(); trackId = track.getId();
return; return;
@@ -497,7 +497,7 @@ public class TrackDetailActivity extends AbstractTrackActivity implements Choose
if (isRecording()) { if (isRecording()) {
title = getString(isPaused ? R.string.generic_paused : R.string.generic_recording); title = getString(isPaused ? R.string.generic_paused : R.string.generic_recording);
} else { } else {
Track track = myTracksProviderUtils.getTrack(trackId); Track track = contentProviderUtils.getTrack(trackId);
title = track != null ? track.getName() : ""; title = track != null ? track.getName() : "";
} }
setTitle(title); setTitle(title);
@@ -509,9 +509,9 @@ public class TrackDetailActivity extends AbstractTrackActivity implements Choose
@Override @Override
public void onChooseActivityTypeDone(String iconValue) { public void onChooseActivityTypeDone(String iconValue) {
Track track = myTracksProviderUtils.getTrack(trackId); Track track = contentProviderUtils.getTrack(trackId);
String category = getString(TrackIconUtils.getIconActivityType(iconValue)); String category = getString(TrackIconUtils.getIconActivityType(iconValue));
TrackUtils.updateTrack(this, track, null, category, null, myTracksProviderUtils); TrackUtils.updateTrack(this, track, null, category, null, contentProviderUtils);
} }
private boolean isRecording() { private boolean isRecording() {
@@ -28,7 +28,7 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment; import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment;
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller; import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller;
@@ -53,7 +53,7 @@ public class TrackEditActivity extends AbstractActivity implements ChooseActivit
private static final String ICON_VALUE_KEY = "icon_value_key"; private static final String ICON_VALUE_KEY = "icon_value_key";
private TrackRecordingServiceConnection trackRecordingServiceConnection; private TrackRecordingServiceConnection trackRecordingServiceConnection;
private MyTracksProviderUtils myTracksProviderUtils; private ContentProviderUtils contentProviderUtils;
private Track track; private Track track;
private String iconValue; private String iconValue;
@@ -74,8 +74,8 @@ public class TrackEditActivity extends AbstractActivity implements ChooseActivit
return; return;
} }
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); contentProviderUtils = ContentProviderUtils.Factory.get(this);
track = myTracksProviderUtils.getTrack(trackId); track = contentProviderUtils.getTrack(trackId);
if (track == null) { if (track == null) {
Log.e(TAG, "No track for " + trackId); Log.e(TAG, "No track for " + trackId);
finish(); finish();
@@ -150,7 +150,7 @@ public class TrackEditActivity extends AbstractActivity implements ChooseActivit
public void onClick(View v) { public void onClick(View v) {
TrackUtils.updateTrack(TrackEditActivity.this, track, name.getText().toString(), TrackUtils.updateTrack(TrackEditActivity.this, track, name.getText().toString(),
activityType.getText().toString(), description.getText().toString(), activityType.getText().toString(), description.getText().toString(),
myTracksProviderUtils); contentProviderUtils);
finish(); finish();
} }
}); });
@@ -53,7 +53,7 @@ import androidx.loader.app.LoaderManager.LoaderCallbacks;
import androidx.loader.content.CursorLoader; import androidx.loader.content.CursorLoader;
import androidx.loader.content.Loader; import androidx.loader.content.Loader;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment; import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
import com.google.android.apps.mytracks.fragments.FileTypeDialogFragment; import com.google.android.apps.mytracks.fragments.FileTypeDialogFragment;
@@ -242,7 +242,7 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
}; };
// The following are set in onCreate // The following are set in onCreate
private MyTracksProviderUtils myTracksProviderUtils; private ContentProviderUtils contentProviderUtils;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private TrackRecordingServiceConnection trackRecordingServiceConnection; private TrackRecordingServiceConnection trackRecordingServiceConnection;
private TrackController trackController; private TrackController trackController;
@@ -281,7 +281,7 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
.build()); .build());
} }
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); contentProviderUtils = ContentProviderUtils.Factory.get(this);
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback); trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
@@ -326,7 +326,7 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
String name = cursor.getString(nameIndex); String name = cursor.getString(nameIndex);
String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex)); String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
String totalDistance = StringUtils.formatDistance(TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits); String totalDistance = StringUtils.formatDistance(TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits);
int markerCount = myTracksProviderUtils.getWaypointCount(trackId); int markerCount = contentProviderUtils.getWaypointCount(trackId);
long startTime = cursor.getLong(startTimeIndex); long startTime = cursor.getLong(startTimeIndex);
String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex); String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex);
String description = cursor.getString(descriptionIndex); String description = cursor.getString(descriptionIndex);
@@ -32,7 +32,7 @@ import java.util.List;
* *
* @author Rodrigo Damazio * @author Rodrigo Damazio
*/ */
public interface MyTracksProviderUtils { public interface ContentProviderUtils {
/** /**
* The authority (the first part of the URI) for the My Tracks content * The authority (the first part of the URI) for the My Tracks content
@@ -350,12 +350,12 @@ public interface MyTracksProviderUtils {
LocationFactory DEFAULT_LOCATION_FACTORY = new LocationFactory() { LocationFactory DEFAULT_LOCATION_FACTORY = new LocationFactory() {
@Override @Override
public Location createLocation() { public Location createLocation() {
return new MyTracksLocation(LocationManager.GPS_PROVIDER); return new SensorDataSetLocation(LocationManager.GPS_PROVIDER);
} }
}; };
/** /**
* A factory which can produce instances of {@link MyTracksProviderUtils}, and * A factory which can produce instances of {@link ContentProviderUtils}, and
* can be overridden for testing. * can be overridden for testing.
*/ */
class Factory { class Factory {
@@ -363,11 +363,11 @@ public interface MyTracksProviderUtils {
private static Factory instance = new Factory(); private static Factory instance = new Factory();
/** /**
* Creates an instance of {@link MyTracksProviderUtils}. * Creates an instance of {@link ContentProviderUtils}.
* *
* @param context the context * @param context the context
*/ */
public static MyTracksProviderUtils get(Context context) { public static ContentProviderUtils get(Context context) {
return instance.newForContext(context); return instance.newForContext(context);
} }
@@ -389,13 +389,13 @@ public interface MyTracksProviderUtils {
} }
/** /**
* Creates an instance of {@link MyTracksProviderUtils}. Allows subclasses * Creates an instance of {@link ContentProviderUtils}. Allows subclasses
* to override for testing. * to override for testing.
* *
* @param context the context * @param context the context
*/ */
protected MyTracksProviderUtils newForContext(Context context) { protected ContentProviderUtils newForContext(Context context) {
return new MyTracksProviderUtilsImpl(context.getContentResolver()); return new ContentProviderUtilsImpl(context.getContentResolver());
} }
} }
} }
@@ -35,20 +35,20 @@ import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
/** /**
* {@link MyTracksProviderUtils} implementation. * {@link ContentProviderUtils} implementation.
* *
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
*/ */
public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { public class ContentProviderUtilsImpl implements ContentProviderUtils {
private static final String TAG = MyTracksProviderUtilsImpl.class.getSimpleName(); private static final String TAG = ContentProviderUtilsImpl.class.getSimpleName();
private static final int MAX_LATITUDE = 90000000; private static final int MAX_LATITUDE = 90000000;
private final ContentResolver contentResolver; private final ContentResolver contentResolver;
private int defaultCursorBatchSize = 2000; private int defaultCursorBatchSize = 2000;
public MyTracksProviderUtilsImpl(ContentResolver contentResolver) { public ContentProviderUtilsImpl(ContentResolver contentResolver) {
this.contentResolver = contentResolver; this.contentResolver = contentResolver;
} }
@@ -734,7 +734,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
@Override @Override
public Location createTrackPoint(Cursor cursor) { public Location createTrackPoint(Cursor cursor) {
Location location = new MyTracksLocation(""); Location location = new SensorDataSetLocation("");
fillTrackPoint(cursor, new CachedTrackPointsIndexes(cursor), location); fillTrackPoint(cursor, new CachedTrackPointsIndexes(cursor), location);
return location; return location;
} }
@@ -999,17 +999,17 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
} }
//SensorData //SensorData
if (location instanceof MyTracksLocation) { if (location instanceof SensorDataSetLocation) {
MyTracksLocation myTracksLocation = (MyTracksLocation) location; SensorDataSetLocation sensorDataSetLocation = (SensorDataSetLocation) location;
SensorDataSet sensorDataSet = myTracksLocation.getSensorDataSet(); SensorDataSet sensorDataSet = sensorDataSetLocation.getSensorDataSet();
if (sensorDataSet != null && sensorDataSet.hasHeartRate()) { if (sensorDataSet != null && sensorDataSet.hasHeartRate()) {
values.put(TrackPointsColumns.SENSOR_HEARTRATE, myTracksLocation.getSensorDataSet().getHeartRate()); values.put(TrackPointsColumns.SENSOR_HEARTRATE, sensorDataSetLocation.getSensorDataSet().getHeartRate());
} }
if (sensorDataSet != null && sensorDataSet.hasCadence()) { if (sensorDataSet != null && sensorDataSet.hasCadence()) {
values.put(TrackPointsColumns.SENSOR_CADENCE, myTracksLocation.getSensorDataSet().getCadence()); values.put(TrackPointsColumns.SENSOR_CADENCE, sensorDataSetLocation.getSensorDataSet().getCadence());
} }
if (sensorDataSet != null && sensorDataSet.hasPower()) { if (sensorDataSet != null && sensorDataSet.hasPower()) {
values.put(TrackPointsColumns.SENSOR_POWER, myTracksLocation.getSensorDataSet().getPower()); values.put(TrackPointsColumns.SENSOR_POWER, sensorDataSetLocation.getSensorDataSet().getPower());
} }
} }
return values; return values;
@@ -1046,14 +1046,14 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
if (!cursor.isNull(indexes.bearingIndex)) { if (!cursor.isNull(indexes.bearingIndex)) {
location.setBearing(cursor.getFloat(indexes.bearingIndex)); location.setBearing(cursor.getFloat(indexes.bearingIndex));
} }
if (location instanceof MyTracksLocation) { if (location instanceof SensorDataSetLocation) {
MyTracksLocation myTracksLocation = (MyTracksLocation) location; SensorDataSetLocation sensorDataSetLocation = (SensorDataSetLocation) location;
float heartRate = cursor.isNull(indexes.sensorHeartRateIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorHeartRateIndex); float heartRate = cursor.isNull(indexes.sensorHeartRateIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorHeartRateIndex);
float cadence = cursor.isNull(indexes.sensorCadenceIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorCadenceIndex); float cadence = cursor.isNull(indexes.sensorCadenceIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorCadenceIndex);
float power = cursor.isNull(indexes.sensorPowerIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorPowerIndex); float power = cursor.isNull(indexes.sensorPowerIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorPowerIndex);
myTracksLocation.setSensorDataSet(new SensorDataSet(heartRate, cadence, power, SensorDataSet.DATA_UNAVAILABLE, location.getTime())); sensorDataSetLocation.setSensorDataSet(new SensorDataSet(heartRate, cadence, power, SensorDataSet.DATA_UNAVAILABLE, location.getTime()));
} }
} }
@@ -47,9 +47,9 @@ import java.io.FileNotFoundException;
* *
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
*/ */
public class MyTracksProvider extends ContentProvider { public class CustomContentProvider extends ContentProvider {
private static final String TAG = MyTracksProvider.class.getSimpleName(); private static final String TAG = CustomContentProvider.class.getSimpleName();
@VisibleForTesting @VisibleForTesting
static final int DATABASE_VERSION = 23; static final int DATABASE_VERSION = 23;
@@ -97,14 +97,14 @@ public class MyTracksProvider extends ContentProvider {
private final UriMatcher uriMatcher; private final UriMatcher uriMatcher;
private SQLiteDatabase db; private SQLiteDatabase db;
public MyTracksProvider() { public CustomContentProvider() {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME, UrlType.TRACKPOINTS.ordinal()); uriMatcher.addURI(ContentProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME, UrlType.TRACKPOINTS.ordinal());
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME + "/#", UrlType.TRACKPOINTS_ID.ordinal()); uriMatcher.addURI(ContentProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME + "/#", UrlType.TRACKPOINTS_ID.ordinal());
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME, UrlType.TRACKS.ordinal()); uriMatcher.addURI(ContentProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME, UrlType.TRACKS.ordinal());
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME + "/#", UrlType.TRACKS_ID.ordinal()); uriMatcher.addURI(ContentProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME + "/#", UrlType.TRACKS_ID.ordinal());
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME, UrlType.WAYPOINTS.ordinal()); uriMatcher.addURI(ContentProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME, UrlType.WAYPOINTS.ordinal());
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME + "/#", UrlType.WAYPOINTS_ID.ordinal()); uriMatcher.addURI(ContentProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME + "/#", UrlType.WAYPOINTS_ID.ordinal());
} }
@Override @Override
@@ -151,9 +151,9 @@ public class SearchEngine {
} }
}; };
private final MyTracksProviderUtils providerUtils; private final ContentProviderUtils providerUtils;
public SearchEngine(MyTracksProviderUtils providerUtils) { public SearchEngine(ContentProviderUtils providerUtils) {
this.providerUtils = providerUtils; this.providerUtils = providerUtils;
} }
@@ -24,7 +24,7 @@ import com.google.android.apps.mytracks.content.sensor.SensorDataSet;
* *
* @author Sandor Dornbush * @author Sandor Dornbush
*/ */
public class MyTracksLocation extends Location { public class SensorDataSetLocation extends Location {
private SensorDataSet sensorDataSet = null; private SensorDataSet sensorDataSet = null;
@@ -33,12 +33,12 @@ public class MyTracksLocation extends Location {
*/ */
private int id = -1; private int id = -1;
public MyTracksLocation(Location location, SensorDataSet sensorDataSet) { public SensorDataSetLocation(Location location, SensorDataSet sensorDataSet) {
super(location); super(location);
this.sensorDataSet = sensorDataSet; this.sensorDataSet = sensorDataSet;
} }
public MyTracksLocation(String provider) { public SensorDataSetLocation(String provider) {
super(provider); super(provider);
} }
@@ -25,7 +25,7 @@ import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.content.ContentProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
@@ -58,7 +58,7 @@ public class TrackDataHub implements DataSourceListener {
private final Context context; private final Context context;
private final TrackDataManager trackDataManager; private final TrackDataManager trackDataManager;
private final MyTracksProviderUtils myTracksProviderUtils; private final ContentProviderUtils contentProviderUtils;
private final int targetNumPoints; private final int targetNumPoints;
private boolean started; private boolean started;
@@ -85,7 +85,7 @@ public class TrackDataHub implements DataSourceListener {
* Creates a new instance. * Creates a new instance.
*/ */
public synchronized static TrackDataHub newInstance(Context context) { public synchronized static TrackDataHub newInstance(Context context) {
return new TrackDataHub(context, new TrackDataManager(), MyTracksProviderUtils.Factory.get( return new TrackDataHub(context, new TrackDataManager(), ContentProviderUtils.Factory.get(
context), TARGET_DISPLAYED_TRACK_POINTS); context), TARGET_DISPLAYED_TRACK_POINTS);
} }
@@ -94,15 +94,15 @@ public class TrackDataHub implements DataSourceListener {
* *
* @param context the context * @param context the context
* @param trackDataManager the track data manager * @param trackDataManager the track data manager
* @param myTracksProviderUtils the my tracks provider utils * @param contentProviderUtils the my tracks provider utils
* @param targetNumPoints the target number of points * @param targetNumPoints the target number of points
*/ */
@VisibleForTesting @VisibleForTesting
TrackDataHub(Context context, TrackDataManager trackDataManager, TrackDataHub(Context context, TrackDataManager trackDataManager,
MyTracksProviderUtils myTracksProviderUtils, int targetNumPoints) { ContentProviderUtils contentProviderUtils, int targetNumPoints) {
this.context = context; this.context = context;
this.trackDataManager = trackDataManager; this.trackDataManager = trackDataManager;
this.myTracksProviderUtils = myTracksProviderUtils; this.contentProviderUtils = contentProviderUtils;
this.targetNumPoints = targetNumPoints; this.targetNumPoints = targetNumPoints;
resetSamplingState(); resetSamplingState();
} }
@@ -408,7 +408,7 @@ public class TrackDataHub implements DataSourceListener {
if (trackDataListeners.isEmpty()) { if (trackDataListeners.isEmpty()) {
return; return;
} }
Track track = myTracksProviderUtils.getTrack(selectedTrackId); Track track = contentProviderUtils.getTrack(selectedTrackId);
for (TrackDataListener trackDataListener : trackDataListeners) { for (TrackDataListener trackDataListener : trackDataListeners) {
trackDataListener.onTrackUpdated(track); trackDataListener.onTrackUpdated(track);
} }
@@ -430,11 +430,11 @@ public class TrackDataHub implements DataSourceListener {
trackDataListener.clearWaypoints(); trackDataListener.clearWaypoints();
} }
try (Cursor cursor = myTracksProviderUtils.getWaypointCursor( try (Cursor cursor = contentProviderUtils.getWaypointCursor(
selectedTrackId, -1L, MAX_DISPLAYED_WAYPOINTS)) { selectedTrackId, -1L, MAX_DISPLAYED_WAYPOINTS)) {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
do { do {
Waypoint waypoint = myTracksProviderUtils.createWaypoint(cursor); Waypoint waypoint = contentProviderUtils.createWaypoint(cursor);
if (!LocationUtils.isValidLocation(waypoint.getLocation())) { if (!LocationUtils.isValidLocation(waypoint.getLocation())) {
continue; continue;
} }
@@ -477,14 +477,14 @@ public class TrackDataHub implements DataSourceListener {
long localLastSeenLocationId = updateSamplingState ? lastSeenLocationId : -1L; long localLastSeenLocationId = updateSamplingState ? lastSeenLocationId : -1L;
long maxPointId = updateSamplingState ? -1L : lastSeenLocationId; long maxPointId = updateSamplingState ? -1L : lastSeenLocationId;
long lastTrackPointId = myTracksProviderUtils.getLastTrackPointId(selectedTrackId); long lastTrackPointId = contentProviderUtils.getLastTrackPointId(selectedTrackId);
int samplingFrequency = -1; int samplingFrequency = -1;
boolean includeNextPoint = false; boolean includeNextPoint = false;
LocationIterator locationIterator = null; LocationIterator locationIterator = null;
try { try {
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(selectedTrackId, locationIterator = contentProviderUtils.getTrackPointLocationIterator(selectedTrackId,
localLastSeenLocationId + 1, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); localLastSeenLocationId + 1, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
while (locationIterator.hasNext()) { while (locationIterator.hasNext()) {
Location location = locationIterator.next(); Location location = locationIterator.next();
@@ -1,2 +0,0 @@
package com.google.android.apps.mytracks.content;
parcelable WaypointCreationRequest;
@@ -29,7 +29,7 @@ import androidx.fragment.app.DialogFragment;
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public abstract class AbstractMyTracksDialogFragment extends DialogFragment { public abstract class AbstractDialogFragment extends DialogFragment {
@NonNull @NonNull
@Override @Override
@@ -31,7 +31,7 @@ import androidx.fragment.app.FragmentActivity;
import com.google.android.apps.mytracks.ChartView; import com.google.android.apps.mytracks.ChartView;
import com.google.android.apps.mytracks.TrackDetailActivity; import com.google.android.apps.mytracks.TrackDetailActivity;
import com.google.android.apps.mytracks.content.MyTracksLocation; import com.google.android.apps.mytracks.content.SensorDataSetLocation;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TrackDataHub; import com.google.android.apps.mytracks.content.TrackDataHub;
import com.google.android.apps.mytracks.content.TrackDataListener; import com.google.android.apps.mytracks.content.TrackDataListener;
@@ -470,8 +470,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
} }
pace = speed == 0 ? 0.0 : 60.0 / speed; pace = speed == 0 ? 0.0 : 60.0 / speed;
} }
if (location instanceof MyTracksLocation && ((MyTracksLocation) location).getSensorDataSet() != null) { if (location instanceof SensorDataSetLocation && ((SensorDataSetLocation) location).getSensorDataSet() != null) {
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet(); SensorDataSet sensorDataSet = ((SensorDataSetLocation) location).getSensorDataSet();
if (sensorDataSet.hasHeartRate()) { if (sensorDataSet.hasHeartRate()) {
heartRate = sensorDataSet.getHeartRate(); heartRate = sensorDataSet.getHeartRate();
} }
@@ -29,7 +29,7 @@ import com.google.android.maps.mytracks.R;
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class ConfirmDeleteDialogFragment extends AbstractMyTracksDialogFragment { public class ConfirmDeleteDialogFragment extends AbstractDialogFragment {
/** /**
* Interface for caller of this dialog fragment. * Interface for caller of this dialog fragment.
@@ -24,7 +24,7 @@ import android.os.Bundle;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.util.DialogUtils; import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
@@ -33,7 +33,7 @@ import com.google.android.maps.mytracks.R;
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class DeleteMarkerDialogFragment extends AbstractMyTracksDialogFragment { public class DeleteMarkerDialogFragment extends AbstractDialogFragment {
/** /**
* Interface for caller of this dialog fragment. * Interface for caller of this dialog fragment.
@@ -94,10 +94,10 @@ public class DeleteMarkerDialogFragment extends AbstractMyTracksDialogFragment {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get( ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(
fragmentActivity); fragmentActivity);
for (long markerId : markerIds) { for (long markerId : markerIds) {
myTracksProviderUtils.deleteWaypoint(fragmentActivity, contentProviderUtils.deleteWaypoint(fragmentActivity,
markerId, new DescriptionGeneratorImpl(fragmentActivity)); markerId, new DescriptionGeneratorImpl(fragmentActivity));
} }
caller.onDeleteMarkerDone(); caller.onDeleteMarkerDone();
@@ -32,7 +32,7 @@ import com.google.android.maps.mytracks.R;
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class FileTypeDialogFragment extends AbstractMyTracksDialogFragment { public class FileTypeDialogFragment extends AbstractDialogFragment {
/** /**
* Interface for caller of this dialog fragment. * Interface for caller of this dialog fragment.
@@ -31,7 +31,7 @@ import androidx.fragment.app.FragmentActivity;
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class FrequencyDialogFragment extends AbstractMyTracksDialogFragment { public class FrequencyDialogFragment extends AbstractDialogFragment {
public static final String FREQUENCY_DIALOG_TAG = "frequencyDialog"; public static final String FREQUENCY_DIALOG_TAG = "frequencyDialog";
@@ -39,7 +39,7 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.google.android.apps.mytracks.MarkerEditActivity; import com.google.android.apps.mytracks.MarkerEditActivity;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
@@ -72,7 +72,7 @@ public class MarkerDetailFragment extends Fragment {
private static final String KEY_TITLE = "title"; private static final String KEY_TITLE = "title";
private static final long HIDE_TEXT_DELAY = 4000L; // 4 seconds private static final long HIDE_TEXT_DELAY = 4000L; // 4 seconds
private MyTracksProviderUtils myTracksProviderUtils; private ContentProviderUtils contentProviderUtils;
private Handler handler; private Handler handler;
private ImageView photo; private ImageView photo;
private ImageView textGradient; private ImageView textGradient;
@@ -112,7 +112,7 @@ public class MarkerDetailFragment extends Fragment {
getFragmentManager().popBackStack(); getFragmentManager().popBackStack();
return; return;
} }
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(getActivity()); contentProviderUtils = ContentProviderUtils.Factory.get(getActivity());
handler = new Handler(); handler = new Handler();
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@@ -214,7 +214,7 @@ public class MarkerDetailFragment extends Fragment {
*/ */
private void updateWaypoint(boolean refresh) { private void updateWaypoint(boolean refresh) {
if (refresh || waypoint == null) { if (refresh || waypoint == null) {
waypoint = myTracksProviderUtils.getWaypoint(getArguments().getLong(KEY_MARKER_ID)); waypoint = contentProviderUtils.getWaypoint(getArguments().getLong(KEY_MARKER_ID));
if (waypoint == null) { if (waypoint == null) {
Log.d(TAG, "waypoint is null"); Log.d(TAG, "waypoint is null");
getFragmentManager().popBackStack(); getFragmentManager().popBackStack();
@@ -259,7 +259,7 @@ public class MarkerDetailFragment extends Fragment {
setLocation(R.id.marker_detail_statistics_location, false); setLocation(R.id.marker_detail_statistics_location, false);
Track track = myTracksProviderUtils.getTrack(waypoint.getTrackId()); Track track = contentProviderUtils.getTrack(waypoint.getTrackId());
StatsUtils.setTripStatisticsValues(getActivity(), null, getView(), waypoint.getTripStatistics(), null); StatsUtils.setTripStatisticsValues(getActivity(), null, getView(), waypoint.getTripStatistics(), null);
StatsUtils.setLocationValues(getActivity(), null, getView(), waypoint.getLocation(), false); StatsUtils.setLocationValues(getActivity(), null, getView(), waypoint.getLocation(), false);
} }
@@ -17,9 +17,9 @@
package com.google.android.apps.mytracks.io.file.exporter; package com.google.android.apps.mytracks.io.file.exporter;
import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.MyTracksLocation; import com.google.android.apps.mytracks.content.SensorDataSetLocation;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.content.ContentProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.LocationUtils;
@@ -40,7 +40,7 @@ public class FileTrackExporter implements TrackExporter {
private static final String TAG = FileTrackExporter.class.getSimpleName(); private static final String TAG = FileTrackExporter.class.getSimpleName();
private final MyTracksProviderUtils myTracksProviderUtils; private final ContentProviderUtils contentProviderUtils;
private final Track[] tracks; private final Track[] tracks;
private final TrackWriter trackWriter; private final TrackWriter trackWriter;
private final TrackExporterListener trackExporterListener; private final TrackExporterListener trackExporterListener;
@@ -48,14 +48,14 @@ public class FileTrackExporter implements TrackExporter {
/** /**
* Constructor. * Constructor.
* *
* @param myTracksProviderUtils the my tracks provider utils * @param contentProviderUtils the my tracks provider utils
* @param tracks the tracks * @param tracks the tracks
* @param trackWriter the track writer * @param trackWriter the track writer
* @param trackExporterListener the track export listener * @param trackExporterListener the track export listener
*/ */
public FileTrackExporter(MyTracksProviderUtils myTracksProviderUtils, Track[] tracks, public FileTrackExporter(ContentProviderUtils contentProviderUtils, Track[] tracks,
TrackWriter trackWriter, TrackExporterListener trackExporterListener) { TrackWriter trackWriter, TrackExporterListener trackExporterListener) {
this.myTracksProviderUtils = myTracksProviderUtils; this.contentProviderUtils = contentProviderUtils;
this.tracks = tracks; this.tracks = tracks;
this.trackWriter = trackWriter; this.trackWriter = trackWriter;
this.trackExporterListener = trackExporterListener; this.trackExporterListener = trackExporterListener;
@@ -95,7 +95,7 @@ public class FileTrackExporter implements TrackExporter {
* load them into objects all at the same time. * load them into objects all at the same time.
*/ */
boolean hasWaypoints = false; boolean hasWaypoints = false;
try (Cursor cursor = myTracksProviderUtils.getWaypointCursor( try (Cursor cursor = contentProviderUtils.getWaypointCursor(
track.getId(), -1L, Constants.MAX_LOADED_WAYPOINTS_POINTS)) { track.getId(), -1L, Constants.MAX_LOADED_WAYPOINTS_POINTS)) {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
/* /*
@@ -110,7 +110,7 @@ public class FileTrackExporter implements TrackExporter {
trackWriter.writeBeginWaypoints(track); trackWriter.writeBeginWaypoints(track);
hasWaypoints = true; hasWaypoints = true;
} }
Waypoint waypoint = myTracksProviderUtils.createWaypoint(cursor); Waypoint waypoint = contentProviderUtils.createWaypoint(cursor);
trackWriter.writeWaypoint(waypoint); trackWriter.writeWaypoint(waypoint);
} }
} }
@@ -132,7 +132,7 @@ public class FileTrackExporter implements TrackExporter {
LocationIterator locationIterator = null; LocationIterator locationIterator = null;
try { try {
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator( locationIterator = contentProviderUtils.getTrackPointLocationIterator(
track.getId(), -1L, false, locationFactory); track.getId(), -1L, false, locationFactory);
while (locationIterator.hasNext()) { while (locationIterator.hasNext()) {
@@ -178,7 +178,7 @@ public class FileTrackExporter implements TrackExporter {
} }
if (wroteTrack) { if (wroteTrack) {
Location lastValidTrackPoint = myTracksProviderUtils.getLastValidTrackPoint(track.getId()); Location lastValidTrackPoint = contentProviderUtils.getLastValidTrackPoint(track.getId());
setLocationTime(lastValidTrackPoint, offset); setLocationTime(lastValidTrackPoint, offset);
trackWriter.writeEndTrack(track, lastValidTrackPoint); trackWriter.writeEndTrack(track, lastValidTrackPoint);
} else { } else {
@@ -210,14 +210,14 @@ public class FileTrackExporter implements TrackExporter {
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
private class TrackWriterLocationFactory implements MyTracksProviderUtils.LocationFactory { private class TrackWriterLocationFactory implements ContentProviderUtils.LocationFactory {
Location currentLocation; Location currentLocation;
Location lastLocation; Location lastLocation;
@Override @Override
public Location createLocation() { public Location createLocation() {
if (currentLocation == null) { if (currentLocation == null) {
currentLocation = new MyTracksLocation(""); currentLocation = new SensorDataSetLocation("");
} }
return currentLocation; return currentLocation;
} }
@@ -24,8 +24,8 @@ import androidx.annotation.VisibleForTesting;
import com.google.android.apps.mytracks.content.DescriptionGenerator; import com.google.android.apps.mytracks.content.DescriptionGenerator;
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
import com.google.android.apps.mytracks.content.MyTracksLocation; import com.google.android.apps.mytracks.content.SensorDataSetLocation;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
@@ -71,7 +71,7 @@ public class KmlTrackWriter implements TrackWriter {
private final boolean multiple; private final boolean multiple;
private final boolean playTrack; private final boolean playTrack;
private final DescriptionGenerator descriptionGenerator; private final DescriptionGenerator descriptionGenerator;
private final MyTracksProviderUtils myTracksProviderUtils; private final ContentProviderUtils contentProviderUtils;
private PrintWriter printWriter; private PrintWriter printWriter;
private ArrayList<Float> powerList = new ArrayList<>(); private ArrayList<Float> powerList = new ArrayList<>();
@@ -91,7 +91,7 @@ public class KmlTrackWriter implements TrackWriter {
this.multiple = multiple; this.multiple = multiple;
this.playTrack = playTrack; this.playTrack = playTrack;
this.descriptionGenerator = descriptionGenerator; this.descriptionGenerator = descriptionGenerator;
this.myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); this.contentProviderUtils = ContentProviderUtils.Factory.get(context);
} }
@Override @Override
@@ -261,8 +261,8 @@ public class KmlTrackWriter implements TrackWriter {
printWriter.println( printWriter.println(
"<when>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</when>"); "<when>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</when>");
printWriter.println("<gx:coord>" + getCoordinates(location, " ") + "</gx:coord>"); printWriter.println("<gx:coord>" + getCoordinates(location, " ") + "</gx:coord>");
if (location instanceof MyTracksLocation) { if (location instanceof SensorDataSetLocation) {
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet(); SensorDataSet sensorDataSet = ((SensorDataSetLocation) location).getSensorDataSet();
if (sensorDataSet != null) { if (sensorDataSet != null) {
if (sensorDataSet.hasHeartRate()) { if (sensorDataSet.hasHeartRate()) {
heartRateList.add(sensorDataSet.getHeartRate()); heartRateList.add(sensorDataSet.getHeartRate());
@@ -377,17 +377,17 @@ public class KmlTrackWriter implements TrackWriter {
* @param location the location * @param location the location
*/ */
private float getHeading(long trackId, Location location) { private float getHeading(long trackId, Location location) {
long trackPointId = myTracksProviderUtils.getTrackPointId(trackId, location); long trackPointId = contentProviderUtils.getTrackPointId(trackId, location);
if (trackPointId == -1L) { if (trackPointId == -1L) {
return location.getBearing(); return location.getBearing();
} }
Location viewLocation; Location viewLocation;
try (Cursor cursor = myTracksProviderUtils.getTrackPointCursor(trackId, trackPointId, 10, true)) { try (Cursor cursor = contentProviderUtils.getTrackPointCursor(trackId, trackPointId, 10, true)) {
if (cursor == null || cursor.getCount() == 0) { if (cursor == null || cursor.getCount() == 0) {
return location.getBearing(); return location.getBearing();
} }
cursor.moveToPosition(cursor.getCount() - 1); cursor.moveToPosition(cursor.getCount() - 1);
viewLocation = myTracksProviderUtils.createTrackPoint(cursor); viewLocation = contentProviderUtils.createTrackPoint(cursor);
} }
return viewLocation.bearingTo(location); return viewLocation.bearingTo(location);
} }
@@ -16,7 +16,7 @@
package com.google.android.apps.mytracks.io.file.exporter; package com.google.android.apps.mytracks.io.file.exporter;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
@@ -50,7 +50,7 @@ public class KmzTrackExporter implements TrackExporter {
private static final String TAG = KmzTrackExporter.class.getSimpleName(); private static final String TAG = KmzTrackExporter.class.getSimpleName();
private static final int BUFFER_SIZE = 4096; private static final int BUFFER_SIZE = 4096;
private final MyTracksProviderUtils myTracksProviderUtils; private final ContentProviderUtils contentProviderUtils;
private final FileTrackExporter fileTrackExporter; private final FileTrackExporter fileTrackExporter;
private final Track[] tracks; private final Track[] tracks;
private final long photoSize; private final long photoSize;
@@ -58,14 +58,14 @@ public class KmzTrackExporter implements TrackExporter {
/** /**
* Constructor. * Constructor.
* *
* @param myTracksProviderUtils the my tracks provider utils * @param contentProviderUtils the my tracks provider utils
* @param fileTrackExporter the file track exporter * @param fileTrackExporter the file track exporter
* @param tracks the tracks to export * @param tracks the tracks to export
* @param context the context * @param context the context
*/ */
public KmzTrackExporter(MyTracksProviderUtils myTracksProviderUtils, public KmzTrackExporter(ContentProviderUtils contentProviderUtils,
FileTrackExporter fileTrackExporter, Track[] tracks, Context context) { FileTrackExporter fileTrackExporter, Track[] tracks, Context context) {
this.myTracksProviderUtils = myTracksProviderUtils; this.contentProviderUtils = contentProviderUtils;
this.fileTrackExporter = fileTrackExporter; this.fileTrackExporter = fileTrackExporter;
this.tracks = tracks; this.tracks = tracks;
this.photoSize = PreferencesUtils.getInt( this.photoSize = PreferencesUtils.getInt(
@@ -111,7 +111,7 @@ public class KmzTrackExporter implements TrackExporter {
private void addImages(ZipOutputStream zipOutputStream) throws InterruptedException, IOException { private void addImages(ZipOutputStream zipOutputStream) throws InterruptedException, IOException {
for (Track track : tracks) { for (Track track : tracks) {
try (Cursor cursor = myTracksProviderUtils.getWaypointCursor(track.getId(), -1L, -1)) { try (Cursor cursor = contentProviderUtils.getWaypointCursor(track.getId(), -1L, -1)) {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
/* /*
* Yes, this will skip the first waypoint and that is intentional as * Yes, this will skip the first waypoint and that is intentional as
@@ -121,7 +121,7 @@ public class KmzTrackExporter implements TrackExporter {
if (Thread.interrupted()) { if (Thread.interrupted()) {
throw new InterruptedException(); throw new InterruptedException();
} }
Waypoint waypoint = myTracksProviderUtils.createWaypoint(cursor); Waypoint waypoint = contentProviderUtils.createWaypoint(cursor);
if (waypoint.hasPhoto()) { if (waypoint.hasPhoto()) {
addImage(zipOutputStream, waypoint.getPhotoUrl()); addImage(zipOutputStream, waypoint.getPhotoUrl());
} }
@@ -22,7 +22,7 @@ import android.os.AsyncTask;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.util.Log; import android.util.Log;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.io.file.TrackFileFormat; import com.google.android.apps.mytracks.io.file.TrackFileFormat;
@@ -52,7 +52,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
private final boolean playTrack; private final boolean playTrack;
private final File directory; private final File directory;
private final Context context; private final Context context;
private final MyTracksProviderUtils myTracksProviderUtils; private final ContentProviderUtils contentProviderUtils;
private WakeLock wakeLock; private WakeLock wakeLock;
@@ -85,7 +85,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
this.playTrack = playTrack; this.playTrack = playTrack;
this.directory = directory; this.directory = directory;
context = saveActivity.getApplicationContext(); context = saveActivity.getApplicationContext();
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); contentProviderUtils = ContentProviderUtils.Factory.get(context);
completed = false; completed = false;
successCount = 0; successCount = 0;
@@ -128,7 +128,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
totalCount = 1; totalCount = 1;
Track[] tracks = new Track[trackIds.length]; Track[] tracks = new Track[trackIds.length];
for (int i = 0; i < trackIds.length; i++) { for (int i = 0; i < trackIds.length; i++) {
tracks[i] = myTracksProviderUtils.getTrack(trackIds[i]); tracks[i] = contentProviderUtils.getTrack(trackIds[i]);
if (tracks[i] == null) { if (tracks[i] == null) {
Log.d(TAG, "No track for " + trackIds[i]); Log.d(TAG, "No track for " + trackIds[i]);
return false; return false;
@@ -184,7 +184,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
Track track = tracks[0]; Track track = tracks[0];
boolean useKmz = trackFileFormat == TrackFileFormat.KML && !playTrack; boolean useKmz = trackFileFormat == TrackFileFormat.KML && !playTrack;
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : trackFileFormat.getExtension(); String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : trackFileFormat.getExtension();
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks, FileTrackExporter fileTrackExporter = new FileTrackExporter(contentProviderUtils, tracks,
trackFileFormat.newTrackWriter(context, tracks.length > 1, playTrack), trackFileFormat.newTrackWriter(context, tracks.length > 1, playTrack),
new TrackExporterListener() { new TrackExporterListener() {
@@ -200,7 +200,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
} }
}); });
TrackExporter trackExporter = useKmz ? new KmzTrackExporter(myTracksProviderUtils, fileTrackExporter, tracks, context) : fileTrackExporter; TrackExporter trackExporter = useKmz ? new KmzTrackExporter(contentProviderUtils, fileTrackExporter, tracks, context) : fileTrackExporter;
String fileName = FileUtils.buildUniqueFileName(directory, track.getName(), extension); String fileName = FileUtils.buildUniqueFileName(directory, track.getName(), extension);
File file = new File(directory, fileName); File file = new File(directory, fileName);
@@ -235,7 +235,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
* Saves all the tracks. * Saves all the tracks.
*/ */
private Boolean saveAllTracks() { private Boolean saveAllTracks() {
try (Cursor cursor = myTracksProviderUtils.getTrackCursor(null, null, TracksColumns._ID)) { try (Cursor cursor = contentProviderUtils.getTrackCursor(null, null, TracksColumns._ID)) {
if (cursor == null) { if (cursor == null) {
return false; return false;
} }
@@ -245,7 +245,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
return false; return false;
} }
cursor.moveToPosition(i); cursor.moveToPosition(i);
Track track = myTracksProviderUtils.createTrack(cursor); Track track = contentProviderUtils.createTrack(cursor);
if (track != null && saveTracks(new Track[]{track})) { if (track != null && saveTracks(new Track[]{track})) {
successCount++; successCount++;
} }
@@ -23,8 +23,8 @@ import android.net.Uri;
import android.util.Log; import android.util.Log;
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.content.ContentProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
@@ -104,7 +104,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
private final Context context; private final Context context;
private final long importTrackId; private final long importTrackId;
private final MyTracksProviderUtils myTracksProviderUtils; private final ContentProviderUtils contentProviderUtils;
private final int recordingDistanceInterval; private final int recordingDistanceInterval;
private final List<Long> trackIds; private final List<Long> trackIds;
private final List<Waypoint> waypoints; private final List<Waypoint> waypoints;
@@ -136,10 +136,10 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
* track. * track.
*/ */
AbstractFileTrackImporter( AbstractFileTrackImporter(
Context context, long importTrackId, MyTracksProviderUtils myTracksProviderUtils) { Context context, long importTrackId, ContentProviderUtils contentProviderUtils) {
this.context = context; this.context = context;
this.importTrackId = importTrackId; this.importTrackId = importTrackId;
this.myTracksProviderUtils = myTracksProviderUtils; this.contentProviderUtils = contentProviderUtils;
this.recordingDistanceInterval = PreferencesUtils.getInt(context, this.recordingDistanceInterval = PreferencesUtils.getInt(context,
R.string.recording_distance_interval_key, R.string.recording_distance_interval_key,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT); PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
@@ -206,7 +206,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
return; return;
} }
long trackId = trackIds.get(size - 1); long trackId = trackIds.get(size - 1);
Track track = myTracksProviderUtils.getTrack(trackId); Track track = contentProviderUtils.getTrack(trackId);
if (track == null) { if (track == null) {
return; return;
} }
@@ -221,8 +221,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
LocationIterator locationIterator = null; LocationIterator locationIterator = null;
try { try {
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator( locationIterator = contentProviderUtils.getTrackPointLocationIterator(
track.getId(), -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); track.getId(), -1L, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
while (true) { while (true) {
if (waypoint == null) { if (waypoint == null) {
@@ -283,7 +283,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
Waypoint newWaypoint = new Waypoint(waypoint.getName(), waypointDescription, Waypoint newWaypoint = new Waypoint(waypoint.getName(), waypointDescription,
waypoint.getCategory(), icon, track.getId(), waypoint.getType(), length, duration, waypoint.getCategory(), icon, track.getId(), waypoint.getType(), length, duration,
-1L, -1L, location, tripStatistics, waypoint.getPhotoUrl()); -1L, -1L, location, tripStatistics, waypoint.getPhotoUrl());
myTracksProviderUtils.insertWaypoint(newWaypoint); contentProviderUtils.insertWaypoint(newWaypoint);
} }
// Load the next waypoint // Load the next waypoint
@@ -304,7 +304,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
trackData = new TrackData(); trackData = new TrackData();
long trackId; long trackId;
if (importTrackId == -1L) { if (importTrackId == -1L) {
Uri uri = myTracksProviderUtils.insertTrack(trackData.track); Uri uri = contentProviderUtils.insertTrack(trackData.track);
trackId = Long.parseLong(uri.getLastPathSegment()); trackId = Long.parseLong(uri.getLastPathSegment());
} else { } else {
if (trackIds.size() > 0) { if (trackIds.size() > 0) {
@@ -312,7 +312,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
"Cannot import more than one track to an existing track " + importTrackId)); "Cannot import more than one track to an existing track " + importTrackId));
} }
trackId = importTrackId; trackId = importTrackId;
myTracksProviderUtils.clearTrack(context, trackId); contentProviderUtils.clearTrack(context, trackId);
} }
trackIds.add(trackId); trackIds.add(trackId);
trackData.track.setId(trackId); trackData.track.setId(trackId);
@@ -339,7 +339,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
} }
trackData.track.setTripStatistics(trackData.tripStatisticsUpdater.getTripStatistics()); trackData.track.setTripStatistics(trackData.tripStatisticsUpdater.getTripStatistics());
trackData.track.setNumberOfPoints(trackData.numberOfLocations); trackData.track.setNumberOfPoints(trackData.numberOfLocations);
myTracksProviderUtils.updateTrack(trackData.track); contentProviderUtils.updateTrack(trackData.track);
insertFirstWaypoint(trackData.track); insertFirstWaypoint(trackData.track);
} }
@@ -574,13 +574,13 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
if (data.numBufferedLocations <= 0) { if (data.numBufferedLocations <= 0) {
return; return;
} }
myTracksProviderUtils.bulkInsertTrackPoint( contentProviderUtils.bulkInsertTrackPoint(
data.bufferedLocations, data.numBufferedLocations, data.track.getId()); data.bufferedLocations, data.numBufferedLocations, data.track.getId());
data.numBufferedLocations = 0; data.numBufferedLocations = 0;
if (data.track.getStartId() == -1L) { if (data.track.getStartId() == -1L) {
data.track.setStartId(myTracksProviderUtils.getFirstTrackPointId(data.track.getId())); data.track.setStartId(contentProviderUtils.getFirstTrackPointId(data.track.getId()));
} }
data.track.setStopId(myTracksProviderUtils.getLastTrackPointId(data.track.getId())); data.track.setStopId(contentProviderUtils.getLastTrackPointId(data.track.getId()));
} }
/** /**
@@ -605,7 +605,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
Waypoint waypoint = new Waypoint(waypointName, waypointDescription, waypointCategory, icon, Waypoint waypoint = new Waypoint(waypointName, waypointDescription, waypointCategory, icon,
track.getId(), WaypointType.STATISTICS, length, duration, -1L, -1L, waypointLocation, track.getId(), WaypointType.STATISTICS, length, duration, -1L, -1L, waypointLocation,
tripStatistics, ""); tripStatistics, "");
myTracksProviderUtils.insertWaypoint(waypoint); contentProviderUtils.insertWaypoint(waypoint);
} }
/** /**
@@ -613,7 +613,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
*/ */
private void cleanImport() { private void cleanImport() {
for (long trackId : trackIds) { for (long trackId : trackIds) {
myTracksProviderUtils.deleteTrack(context, trackId); contentProviderUtils.deleteTrack(context, trackId);
} }
} }
} }
@@ -20,7 +20,7 @@ import android.content.Context;
import android.location.Location; import android.location.Location;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@@ -54,12 +54,12 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
* @param context the context * @param context the context
*/ */
public GpxFileTrackImporter(Context context) { public GpxFileTrackImporter(Context context) {
this(context, MyTracksProviderUtils.Factory.get(context)); this(context, ContentProviderUtils.Factory.get(context));
} }
@VisibleForTesting @VisibleForTesting
GpxFileTrackImporter(Context context, MyTracksProviderUtils myTracksProviderUtils) { GpxFileTrackImporter(Context context, ContentProviderUtils contentProviderUtils) {
super(context, -1L, myTracksProviderUtils); super(context, -1L, contentProviderUtils);
} }
@Override @Override
@@ -16,7 +16,7 @@
package com.google.android.apps.mytracks.io.file.importer; package com.google.android.apps.mytracks.io.file.importer;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.io.file.TrackFileFormat; import com.google.android.apps.mytracks.io.file.TrackFileFormat;
import com.google.android.apps.mytracks.io.file.exporter.KmzTrackExporter; import com.google.android.apps.mytracks.io.file.exporter.KmzTrackExporter;
@@ -182,8 +182,8 @@ public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
if (TrackFileFormat.KML.getExtension().equals(extension)) { if (TrackFileFormat.KML.getExtension().equals(extension)) {
trackImporter = new KmlFileTrackImporter(context, -1L); trackImporter = new KmlFileTrackImporter(context, -1L);
} else { } else {
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(context);
Uri uri = myTracksProviderUtils.insertTrack(new Track()); Uri uri = contentProviderUtils.insertTrack(new Track());
long newId = Long.parseLong(uri.getLastPathSegment()); long newId = Long.parseLong(uri.getLastPathSegment());
trackImporter = new KmzTrackImporter(context, newId); trackImporter = new KmzTrackImporter(context, newId);
@@ -22,8 +22,8 @@ import android.net.Uri;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.google.android.apps.mytracks.content.MyTracksLocation; import com.google.android.apps.mytracks.content.SensorDataSetLocation;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import com.google.android.apps.mytracks.content.sensor.SensorDataSet; import com.google.android.apps.mytracks.content.sensor.SensorDataSet;
@@ -78,13 +78,13 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
* @param importTrackId track id to import to. -1L to import to a new track. * @param importTrackId track id to import to. -1L to import to a new track.
*/ */
public KmlFileTrackImporter(Context context, long importTrackId) { public KmlFileTrackImporter(Context context, long importTrackId) {
this(context, importTrackId, MyTracksProviderUtils.Factory.get(context)); this(context, importTrackId, ContentProviderUtils.Factory.get(context));
} }
@VisibleForTesting @VisibleForTesting
KmlFileTrackImporter( KmlFileTrackImporter(
Context context, long importTrackId, MyTracksProviderUtils myTracksProviderUtils) { Context context, long importTrackId, ContentProviderUtils contentProviderUtils) {
super(context, importTrackId, myTracksProviderUtils); super(context, importTrackId, contentProviderUtils);
} }
@Override @Override
@@ -246,8 +246,8 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
float cadence = hasHeartRate ? cadenceList.get(i) : SensorDataSet.DATA_UNAVAILABLE; float cadence = hasHeartRate ? cadenceList.get(i) : SensorDataSet.DATA_UNAVAILABLE;
float power = hasHeartRate ? powerList.get(i) : SensorDataSet.DATA_UNAVAILABLE; float power = hasHeartRate ? powerList.get(i) : SensorDataSet.DATA_UNAVAILABLE;
MyTracksLocation myTracksLocation = new MyTracksLocation(location, new SensorDataSet(heartrate, cadence, power, SensorDataSet.DATA_UNAVAILABLE, location.getTime())); SensorDataSetLocation sensorDataSetLocation = new SensorDataSetLocation(location, new SensorDataSet(heartrate, cadence, power, SensorDataSet.DATA_UNAVAILABLE, location.getTime()));
insertTrackPoint(myTracksLocation); insertTrackPoint(sensorDataSetLocation);
} }
} }
} }
@@ -16,7 +16,7 @@
package com.google.android.apps.mytracks.io.file.importer; package com.google.android.apps.mytracks.io.file.importer;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.io.file.exporter.KmzTrackExporter; import com.google.android.apps.mytracks.io.file.exporter.KmzTrackExporter;
import com.google.android.apps.mytracks.util.FileUtils; import com.google.android.apps.mytracks.util.FileUtils;
@@ -111,8 +111,8 @@ public class KmzTrackImporter implements TrackImporter {
*/ */
private void cleanImport(long trackId) { private void cleanImport(long trackId) {
if (trackId != -1L) { if (trackId != -1L) {
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(context);
myTracksProviderUtils.deleteTrack(context, trackId); contentProviderUtils.deleteTrack(context, trackId);
} }
if (importTrackId != -1L) { if (importTrackId != -1L) {
@@ -24,12 +24,11 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
/** /**
* My Tracks Location Manager. Applies Google location settings before allowing * Handles connection to {@link LocationManager}.
* access to {@link LocationManager}.
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class MyTracksLocationManager { public class LocationManagerConnector {
private final Handler handler; private final Handler handler;
private final LocationManager locationManager; private final LocationManager locationManager;
@@ -38,7 +37,7 @@ public class MyTracksLocationManager {
private float requestLocationUpdatesDistance; private float requestLocationUpdatesDistance;
private long requestLocationUpdatesTime; private long requestLocationUpdatesTime;
public MyTracksLocationManager(Context context, Looper looper) { public LocationManagerConnector(Context context, Looper looper) {
this.handler = new Handler(looper); this.handler = new Handler(looper);
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
@@ -45,10 +45,10 @@ 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.TrackListActivity; import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
import com.google.android.apps.mytracks.content.MyTracksLocation; import com.google.android.apps.mytracks.content.SensorDataSetLocation;
import com.google.android.apps.mytracks.content.MyTracksProvider; import com.google.android.apps.mytracks.content.CustomContentProvider;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.content.ContentProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
@@ -76,7 +76,7 @@ import java.util.concurrent.Executors;
/** /**
* A background service that registers a location listener and records track * A background service that registers a location listener and records track
* points. Track points are saved to the {@link MyTracksProvider}. * points. Track points are saved to the {@link CustomContentProvider}.
* *
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
*/ */
@@ -107,9 +107,9 @@ public class TrackRecordingService extends Service {
// The following variables are set in onCreate: // The following variables are set in onCreate:
private ExecutorService executorService; private ExecutorService executorService;
private Context context; private Context context;
private MyTracksProviderUtils myTracksProviderUtils; private ContentProviderUtils contentProviderUtils;
private Handler handler; private Handler handler;
private MyTracksLocationManager myTracksLocationManager; private LocationManagerConnector locationManagerConnector;
private PeriodicTaskExecutor voiceExecutor; private PeriodicTaskExecutor voiceExecutor;
private PeriodicTaskExecutor splitExecutor; private PeriodicTaskExecutor splitExecutor;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
@@ -198,7 +198,7 @@ public class TrackRecordingService extends Service {
@Override @Override
public void onLocationChanged(final Location location) { public void onLocationChanged(final Location location) {
if (myTracksLocationManager == null if (locationManagerConnector == null
|| executorService == null || executorService == null
|| executorService.isShutdown() || executorService.isShutdown()
|| executorService.isTerminated()) { || executorService.isTerminated()) {
@@ -250,9 +250,9 @@ public class TrackRecordingService extends Service {
super.onCreate(); super.onCreate();
executorService = Executors.newSingleThreadExecutor(); executorService = Executors.newSingleThreadExecutor();
context = this; context = this;
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); contentProviderUtils = ContentProviderUtils.Factory.get(this);
handler = new Handler(); handler = new Handler();
myTracksLocationManager = new MyTracksLocationManager(this, handler.getLooper()); locationManagerConnector = new LocationManagerConnector(this, handler.getLooper());
voiceExecutor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory()); voiceExecutor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory());
splitExecutor = new PeriodicTaskExecutor(this, new SplitPeriodicTaskFactory()); splitExecutor = new PeriodicTaskExecutor(this, new SplitPeriodicTaskFactory());
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
@@ -270,7 +270,7 @@ public class TrackRecordingService extends Service {
* Try to restart the previous recording track in case the service has been * Try to restart the previous recording track in case the service has been
* restarted by the system, which can sometimes happen. * restarted by the system, which can sometimes happen.
*/ */
Track track = myTracksProviderUtils.getTrack(recordingTrackId); Track track = contentProviderUtils.getTrack(recordingTrackId);
if (track != null) { if (track != null) {
restartTrack(track); restartTrack(track);
} else { } else {
@@ -328,8 +328,8 @@ public class TrackRecordingService extends Service {
voiceExecutor = null; voiceExecutor = null;
} }
myTracksLocationManager = null; locationManagerConnector = null;
myTracksProviderUtils = null; contentProviderUtils = null;
binder.detachFromService(); binder.detachFromService();
binder = null; binder = null;
@@ -388,7 +388,7 @@ public class TrackRecordingService extends Service {
if (waypointCreationRequest.getName() != null) { if (waypointCreationRequest.getName() != null) {
name = waypointCreationRequest.getName(); name = waypointCreationRequest.getName();
} else { } else {
int nextWaypointNumber = myTracksProviderUtils.getNextWaypointNumber(recordingTrackId, waypointType); int nextWaypointNumber = contentProviderUtils.getNextWaypointNumber(recordingTrackId, waypointType);
if (nextWaypointNumber == -1) { if (nextWaypointNumber == -1) {
nextWaypointNumber = 0; nextWaypointNumber = 0;
} }
@@ -440,7 +440,7 @@ public class TrackRecordingService extends Service {
// Insert waypoint // Insert waypoint
Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, waypointType, length, duration, -1L, -1L, location, tripStatistics, photoUrl); Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, waypointType, length, duration, -1L, -1L, location, tripStatistics, photoUrl);
Uri uri = myTracksProviderUtils.insertWaypoint(waypoint); Uri uri = contentProviderUtils.insertWaypoint(waypoint);
return Long.parseLong(uri.getLastPathSegment()); return Long.parseLong(uri.getLastPathSegment());
} }
@@ -496,7 +496,7 @@ public class TrackRecordingService extends Service {
* Returns true if should resume. * Returns true if should resume.
*/ */
private boolean shouldResumeTrack() { private boolean shouldResumeTrack() {
Track track = myTracksProviderUtils.getTrack(recordingTrackId); Track track = contentProviderUtils.getTrack(recordingTrackId);
if (track == null) { if (track == null) {
Log.d(TAG, "Not resuming. Track is null."); Log.d(TAG, "Not resuming. Track is null.");
@@ -541,7 +541,7 @@ public class TrackRecordingService extends Service {
// Insert a track // Insert a track
Track track = new Track(); Track track = new Track();
Uri uri = myTracksProviderUtils.insertTrack(track); Uri uri = contentProviderUtils.insertTrack(track);
long trackId = Long.parseLong(uri.getLastPathSegment()); long trackId = Long.parseLong(uri.getLastPathSegment());
// Update shared preferences // Update shared preferences
@@ -557,7 +557,7 @@ public class TrackRecordingService extends Service {
track.setCategory(category); track.setCategory(category);
track.setIcon(TrackIconUtils.getIconValue(this, category)); track.setIcon(TrackIconUtils.getIconValue(this, category));
track.setTripStatistics(trackTripStatisticsUpdater.getTripStatistics()); track.setTripStatistics(trackTripStatisticsUpdater.getTripStatistics());
myTracksProviderUtils.updateTrack(track); contentProviderUtils.updateTrack(track);
insertWaypoint(WaypointCreationRequest.DEFAULT_START_TRACK); insertWaypoint(WaypointCreationRequest.DEFAULT_START_TRACK);
startRecording(true); startRecording(true);
@@ -576,7 +576,7 @@ public class TrackRecordingService extends Service {
trackTripStatisticsUpdater = new TripStatisticsUpdater(tripStatistics.getStartTime()); trackTripStatisticsUpdater = new TripStatisticsUpdater(tripStatistics.getStartTime());
long markerStartTime; long markerStartTime;
Waypoint waypoint = myTracksProviderUtils.getLastWaypoint(recordingTrackId, WaypointType.STATISTICS); Waypoint waypoint = contentProviderUtils.getLastWaypoint(recordingTrackId, WaypointType.STATISTICS);
if (waypoint != null && waypoint.getTripStatistics() != null) { if (waypoint != null && waypoint.getTripStatistics() != null) {
markerStartTime = waypoint.getTripStatistics().getStopTime(); markerStartTime = waypoint.getTripStatistics().getStopTime();
} else { } else {
@@ -586,7 +586,7 @@ public class TrackRecordingService extends Service {
LocationIterator locationIterator = null; LocationIterator locationIterator = null;
try { try {
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); locationIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
while (locationIterator.hasNext()) { while (locationIterator.hasNext()) {
Location location = locationIterator.next(); Location location = locationIterator.next();
@@ -619,7 +619,7 @@ public class TrackRecordingService extends Service {
PreferencesUtils.setBoolean(this, R.string.recording_track_paused_key, false); PreferencesUtils.setBoolean(this, R.string.recording_track_paused_key, false);
// Update database // Update database
Track track = myTracksProviderUtils.getTrack(recordingTrackId); Track track = contentProviderUtils.getTrack(recordingTrackId);
if (track != null) { if (track != null) {
Location resume = new Location(LocationManager.GPS_PROVIDER); Location resume = new Location(LocationManager.GPS_PROVIDER);
resume.setLongitude(0); resume.setLongitude(0);
@@ -678,20 +678,20 @@ public class TrackRecordingService extends Service {
updateRecordingState(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, true); updateRecordingState(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, true);
// Update database // Update database
Track track = myTracksProviderUtils.getTrack(trackId); Track track = contentProviderUtils.getTrack(trackId);
if (track != null) { if (track != null) {
// If not paused, add the last location // If not paused, add the last location
if (!paused) { if (!paused) {
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(trackId)); insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(trackId));
// Update the recording track time // Update the recording track time
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false); updateRecordingTrack(track, contentProviderUtils.getLastTrackPointId(trackId), false);
} }
String trackName = TrackNameUtils.getTrackName(this, trackId, track.getTripStatistics().getStartTime(), myTracksProviderUtils.getFirstValidTrackPoint(trackId)); String trackName = TrackNameUtils.getTrackName(this, trackId, track.getTripStatistics().getStartTime(), contentProviderUtils.getFirstValidTrackPoint(trackId));
if (trackName != null && !trackName.equals(track.getName())) { if (trackName != null && !trackName.equals(track.getName())) {
track.setName(trackName); track.setName(trackName);
myTracksProviderUtils.updateTrack(track); contentProviderUtils.updateTrack(track);
} }
} }
endRecording(true, trackId); endRecording(true, trackId);
@@ -711,7 +711,7 @@ public class TrackRecordingService extends Service {
PreferencesUtils.setBoolean(this, R.string.recording_track_paused_key, true); PreferencesUtils.setBoolean(this, R.string.recording_track_paused_key, true);
// Update database // Update database
Track track = myTracksProviderUtils.getTrack(recordingTrackId); Track track = contentProviderUtils.getTrack(recordingTrackId);
if (track != null) { if (track != null) {
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(track.getId())); insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(track.getId()));
@@ -771,7 +771,7 @@ public class TrackRecordingService extends Service {
if (!currentSegmentHasLocation) { if (!currentSegmentHasLocation) {
return null; return null;
} }
return myTracksProviderUtils.getLastValidTrackPoint(trackId); return contentProviderUtils.getLastValidTrackPoint(trackId);
} }
/** /**
@@ -799,7 +799,7 @@ public class TrackRecordingService extends Service {
return; return;
} }
Track track = myTracksProviderUtils.getTrack(recordingTrackId); Track track = contentProviderUtils.getTrack(recordingTrackId);
if (track == null) { if (track == null) {
Log.w(TAG, "Ignore onLocationChangedAsync. No track."); Log.w(TAG, "Ignore onLocationChangedAsync. No track.");
return; return;
@@ -833,7 +833,7 @@ public class TrackRecordingService extends Service {
SensorDataSet sensorDataSet = getSensorDataSet(); SensorDataSet sensorDataSet = getSensorDataSet();
if (sensorDataSet != null) { if (sensorDataSet != null) {
location = new MyTracksLocation(location, sensorDataSet); location = new SensorDataSetLocation(location, sensorDataSet);
} }
// Always insert the first segment location // Always insert the first segment location
@@ -910,7 +910,7 @@ public class TrackRecordingService extends Service {
} }
try { try {
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId()); Uri uri = contentProviderUtils.insertTrackPoint(location, track.getId());
long trackPointId = Long.parseLong(uri.getLastPathSegment()); long trackPointId = Long.parseLong(uri.getLastPathSegment());
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval); trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval); markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
@@ -949,7 +949,7 @@ public class TrackRecordingService extends Service {
trackTripStatisticsUpdater.updateTime(System.currentTimeMillis()); trackTripStatisticsUpdater.updateTime(System.currentTimeMillis());
track.setTripStatistics(trackTripStatisticsUpdater.getTripStatistics()); track.setTripStatistics(trackTripStatisticsUpdater.getTripStatistics());
myTracksProviderUtils.updateTrack(track); contentProviderUtils.updateTrack(track);
} }
private SensorDataSet getSensorDataSet() { private SensorDataSet getSensorDataSet() {
@@ -963,13 +963,13 @@ public class TrackRecordingService extends Service {
* Registers the location listener. * Registers the location listener.
*/ */
private void registerLocationListener() { private void registerLocationListener() {
if (myTracksLocationManager == null) { if (locationManagerConnector == null) {
Log.e(TAG, "locationManager is null."); Log.e(TAG, "locationManager is null.");
return; return;
} }
try { try {
long interval = locationListenerPolicy.getDesiredPollingInterval(); long interval = locationListenerPolicy.getDesiredPollingInterval();
myTracksLocationManager.requestLocationUpdates(interval, locationListenerPolicy.getMinDistance(), locationListener); locationManagerConnector.requestLocationUpdates(interval, locationListenerPolicy.getMinDistance(), locationListener);
currentRecordingInterval = interval; currentRecordingInterval = interval;
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.e(TAG, "Could not register location listener.", e); Log.e(TAG, "Could not register location listener.", e);
@@ -980,11 +980,11 @@ public class TrackRecordingService extends Service {
* Unregisters the location manager. * Unregisters the location manager.
*/ */
private void unregisterLocationListener() { private void unregisterLocationListener() {
if (myTracksLocationManager == null) { if (locationManagerConnector == null) {
Log.e(TAG, "locationManager is null."); Log.e(TAG, "locationManager is null.");
return; return;
} }
myTracksLocationManager.removeLocationUpdates(locationListener); locationManagerConnector.removeLocationUpdates(locationListener);
} }
/** /**
@@ -1,46 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.settings;
import com.google.android.apps.mytracks.util.DialogUtils;
import android.content.Context;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.util.AttributeSet;
/**
* My Tracks edit text preference.
*
* @author Jimmy Shih
*/
public class MyTracksEditTextPreference extends EditTextPreference {
public MyTracksEditTextPreference(Context context) {
super(context);
}
public MyTracksEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
DialogUtils.setDialogTitleDivider(getContext(), getDialog());
}
}
@@ -21,7 +21,7 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.io.file.TrackFileFormat; import com.google.android.apps.mytracks.io.file.TrackFileFormat;
@@ -60,7 +60,7 @@ public class IntentUtils {
* @param trackFileFormat the track file format * @param trackFileFormat the track file format
*/ */
public static Intent newShareFileIntent(Context context, long trackId, String filePath, TrackFileFormat trackFileFormat) { public static Intent newShareFileIntent(Context context, long trackId, String filePath, TrackFileFormat trackFileFormat) {
Track track = MyTracksProviderUtils.Factory.get(context).getTrack(trackId); Track track = ContentProviderUtils.Factory.get(context).getTrack(trackId);
String trackDescription = track == null ? "" : new DescriptionGeneratorImpl(context).generateTrackDescription(track, null, null, false); String trackDescription = track == null ? "" : new DescriptionGeneratorImpl(context).generateTrackDescription(track, null, null, false);
return new Intent(Intent.ACTION_SEND) return new Intent(Intent.ACTION_SEND)
@@ -41,7 +41,7 @@ public class SystemUtils {
* *
* @return the version, or an empty string in case of failure. * @return the version, or an empty string in case of failure.
*/ */
public static String getMyTracksVersion(Context context) { public static String getAppVersion(Context context) {
try { try {
PackageInfo pi = context.getPackageManager() PackageInfo pi = context.getPackageManager()
.getPackageInfo("com.google.android.maps.mytracks", PackageManager.GET_META_DATA); .getPackageInfo("com.google.android.maps.mytracks", PackageManager.GET_META_DATA);
@@ -16,7 +16,7 @@
package com.google.android.apps.mytracks.util; package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.TracksColumns;
@@ -33,7 +33,7 @@ public class TrackUtils {
public static String TRACK_SORT_ORDER = TracksColumns.STARTTIME + " DESC"; public static String TRACK_SORT_ORDER = TracksColumns.STARTTIME + " DESC";
public static void updateTrack(Context context, Track track, String name, String category, String description, MyTracksProviderUtils myTracksProviderUtils) { public static void updateTrack(Context context, Track track, String name, String category, String description, ContentProviderUtils contentProviderUtils) {
if (name != null) { if (name != null) {
track.setName(name); track.setName(name);
} }
@@ -46,6 +46,6 @@ public class TrackUtils {
track.setDescription(description); track.setDescription(description);
} }
track.setModifiedTime(System.currentTimeMillis()); track.setModifiedTime(System.currentTimeMillis());
myTracksProviderUtils.updateTrack(track); contentProviderUtils.updateTrack(track);
} }
} }
@@ -18,7 +18,7 @@ package com.google.android.apps.mytracks.widgets;
import com.google.android.apps.mytracks.TrackDetailActivity; import com.google.android.apps.mytracks.TrackDetailActivity;
import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.ContentProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.services.ControlRecordingService; import com.google.android.apps.mytracks.services.ControlRecordingService;
import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatistics;
@@ -207,12 +207,12 @@ public class TrackWidgetProvider extends AppWidgetProvider {
context, R.string.track_widget_item2, PreferencesUtils.TRACK_WIDGET_ITEM2_DEFAULT); context, R.string.track_widget_item2, PreferencesUtils.TRACK_WIDGET_ITEM2_DEFAULT);
// Get track and trip statistics // Get track and trip statistics
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(context);
if (trackId == -1L) { if (trackId == -1L) {
trackId = recordingTrackId; trackId = recordingTrackId;
} }
Track track = trackId != -1L ? myTracksProviderUtils.getTrack(trackId) Track track = trackId != -1L ? contentProviderUtils.getTrack(trackId)
: myTracksProviderUtils.getLastTrack(); : contentProviderUtils.getLastTrack();
TripStatistics tripStatistics = track == null ? null : track.getTripStatistics(); TripStatistics tripStatistics = track == null ? null : track.getTripStatistics();
updateStatisticsContainer(context, remoteViews, track); updateStatisticsContainer(context, remoteViews, track);