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