diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/AbstractImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/AbstractFileTrackImporter.java similarity index 98% rename from MyTracks/src/com/google/android/apps/mytracks/io/file/AbstractImporter.java rename to MyTracks/src/com/google/android/apps/mytracks/io/file/AbstractFileTrackImporter.java index 5879a18ae..f665e278a 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/AbstractImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/AbstractFileTrackImporter.java @@ -54,12 +54,12 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; /** - * Abstract class for various importers like {@link GpxImporter} and - * {@link KmlImporter}. + * Abstract class for various file track importers like {@link GpxFileTrackImporter} and + * {@link KmlFileTrackImporter}. * * @author Jimmy Shih */ -abstract class AbstractImporter extends DefaultHandler { +abstract class AbstractFileTrackImporter extends DefaultHandler implements TrackImporter { /** * Data for the current track. @@ -131,12 +131,12 @@ abstract class AbstractImporter extends DefaultHandler { * @param importTrackId the track id to import to. -1L to import to a new * track. */ - protected AbstractImporter(Context context, long importTrackId) { + protected AbstractFileTrackImporter(Context context, long importTrackId) { this(context, importTrackId, MyTracksProviderUtils.Factory.get(context)); } @VisibleForTesting - protected AbstractImporter( + protected AbstractFileTrackImporter( Context context, long importTrackId, MyTracksProviderUtils myTracksProviderUtils) { this.context = context; this.importTrackId = importTrackId; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxFileTrackImporter.java similarity index 95% rename from MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java rename to MyTracks/src/com/google/android/apps/mytracks/io/file/GpxFileTrackImporter.java index d4b97697b..bbbe122bc 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxFileTrackImporter.java @@ -31,7 +31,7 @@ import org.xml.sax.SAXException; * * @author Jimmy Shih */ -public class GpxImporter extends AbstractImporter { +public class GpxFileTrackImporter extends AbstractFileTrackImporter { private static final String TAG_DESCRIPTION = "desc"; private static final String TAG_COMMENT = "cmt"; @@ -54,12 +54,12 @@ public class GpxImporter extends AbstractImporter { * @param context the context * @param importTrackId track id to import to. -1L to import to a new track. */ - public GpxImporter(Context context, long importTrackId) { + public GpxFileTrackImporter(Context context, long importTrackId) { super(context, importTrackId); } @VisibleForTesting - public GpxImporter(Context context, MyTracksProviderUtils myTracksProviderUtils) { + public GpxFileTrackImporter(Context context, MyTracksProviderUtils myTracksProviderUtils) { super(context, -1L, myTracksProviderUtils); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/ImportAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/ImportAsyncTask.java index 281b1b887..20f38f37b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/ImportAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/ImportAsyncTask.java @@ -158,10 +158,10 @@ public class ImportAsyncTask extends AsyncTask { */ private boolean importFile(final File file) { try { - AbstractImporter importer = trackFileFormat == TrackFileFormat.KML ? new KmlImporter( + TrackImporter trackImporter = trackFileFormat == TrackFileFormat.KML ? new KmlFileTrackImporter( context, -1L) - : new GpxImporter(context, -1L); - long trackIds[] = importer.importFile(new FileInputStream(file)); + : new GpxFileTrackImporter(context, -1L); + long trackIds[] = trackImporter.importFile(new FileInputStream(file)); int length = trackIds.length; if (length > 0) { trackId = trackIds[length - 1]; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/KmlImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/KmlFileTrackImporter.java similarity index 97% rename from MyTracks/src/com/google/android/apps/mytracks/io/file/KmlImporter.java rename to MyTracks/src/com/google/android/apps/mytracks/io/file/KmlFileTrackImporter.java index 6a792baf9..76762acb9 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/KmlImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/KmlFileTrackImporter.java @@ -36,7 +36,7 @@ import org.xml.sax.SAXException; * * @author Jimmy Shih */ -public class KmlImporter extends AbstractImporter { +public class KmlFileTrackImporter extends AbstractFileTrackImporter { private static final String CADENCE = "cadence"; private static final String HEART_RATE = "heart_rate"; @@ -74,12 +74,12 @@ public class KmlImporter extends AbstractImporter { * @param context the context * @param importTrackId track id to import to. -1L to import to a new track. */ - public KmlImporter(Context context, long importTrackId) { + public KmlFileTrackImporter(Context context, long importTrackId) { super(context, importTrackId); } @VisibleForTesting - public KmlImporter(Context context, MyTracksProviderUtils myTracksProviderUtils) { + public KmlFileTrackImporter(Context context, MyTracksProviderUtils myTracksProviderUtils) { super(context, -1L, myTracksProviderUtils); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackImporter.java new file mode 100644 index 000000000..11620e71d --- /dev/null +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackImporter.java @@ -0,0 +1,34 @@ +/* + * 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.io.file; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.ParserConfigurationException; + +import org.xml.sax.SAXException; + +/** + * Interface for a track importer. + * + * @author Jimmy Shih + */ +public interface TrackImporter { + + public long[] importFile(InputStream inputStream) + throws SAXException, IOException, ParserConfigurationException; +} diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java index eace3dd56..9d5855175 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java @@ -18,7 +18,7 @@ package com.google.android.apps.mytracks.io.sync; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Track; -import com.google.android.apps.mytracks.io.file.KmlImporter; +import com.google.android.apps.mytracks.io.file.KmlFileTrackImporter; import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.gms.auth.GoogleAuthException; @@ -348,9 +348,9 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter { if (driveFile != null) { InputStream inputStream = downloadDriveFile(driveFile, true); if (inputStream != null) { - KmlImporter kmlImporter = new KmlImporter(context, -1L); + KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(context, -1L); try { - long[] trackIds = kmlImporter.importFile(inputStream); + long[] trackIds = kmlFileTrackImporter.importFile(inputStream); if (trackIds.length == 1) { Track track = myTracksProviderUtils.getTrack(trackIds[0]); if (track == null) { @@ -494,9 +494,9 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter { Log.e(TAG, "Unable to update track. Input stream is null for track " + track.getName()); return false; } - KmlImporter kmlImporter = new KmlImporter(context, track.getId()); + KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(context, track.getId()); try { - long[] trackIds = kmlImporter.importFile(inputStream); + long[] trackIds = kmlFileTrackImporter.importFile(inputStream); if (trackIds.length == 1) { Track newTrack = myTracksProviderUtils.getTrack(trackIds[0]); if (newTrack == null) { diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/AbstractTestImporter.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/AbstractTestFileTrackImporter.java similarity index 98% rename from MyTracksTest/src/com/google/android/apps/mytracks/io/file/AbstractTestImporter.java rename to MyTracksTest/src/com/google/android/apps/mytracks/io/file/AbstractTestFileTrackImporter.java index 55059418e..2334dfc66 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/AbstractTestImporter.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/AbstractTestFileTrackImporter.java @@ -42,11 +42,11 @@ import java.util.SimpleTimeZone; import org.easymock.Capture; /** - * Abstract class for testing importer. + * Abstract class for testing file track importers. * * @author Jimmy Shih. */ -public class AbstractTestImporter extends AndroidTestCase { +public class AbstractTestFileTrackImporter extends AndroidTestCase { protected static final String TRACK_NAME_0 = "blablub"; protected static final String TRACK_DESCRIPTION_0 = "s'Laebe isch koi Schlotzer"; diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxFileTrackImporterTest.java similarity index 91% rename from MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java rename to MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxFileTrackImporterTest.java index 48ed37630..f9999ca87 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxFileTrackImporterTest.java @@ -31,11 +31,11 @@ import org.easymock.Capture; import org.xml.sax.SAXException; /** - * Tests for {@link GpxImporter}. + * Tests for {@link GpxFileTrackImporter}. * * @author Steffen Horlacher */ -public class GpxImporterTest extends AbstractTestImporter { +public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter { private static String getNameAndDescription(String name, String description) { return "" + ""; @@ -107,8 +107,9 @@ public class GpxImporterTest extends AbstractTestImporter { AndroidMock.replay(myTracksProviderUtils); InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes()); - GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils); - long[] trackIds = gpxImporter.importFile(inputStream); + GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter( + getContext(), myTracksProviderUtils); + long[] trackIds = gpxFileTrackImporter.importFile(inputStream); assertEquals(1, trackIds.length); assertEquals(TRACK_ID_0, trackIds[0]); @@ -140,8 +141,9 @@ public class GpxImporterTest extends AbstractTestImporter { AndroidMock.replay(myTracksProviderUtils); InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes()); - GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils); - long[] trackIds = gpxImporter.importFile(inputStream); + GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter( + getContext(), myTracksProviderUtils); + long[] trackIds = gpxFileTrackImporter.importFile(inputStream); assertEquals(1, trackIds.length); assertEquals(TRACK_ID_0, trackIds[0]); @@ -177,8 +179,9 @@ public class GpxImporterTest extends AbstractTestImporter { InputStream inputStream = new ByteArrayInputStream( VALID_ONE_TRACK_TWO_SEGMENTS_NO_TIME_GPX.getBytes()); - GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils); - long[] trackIds = gpxImporter.importFile(inputStream); + GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter( + getContext(), myTracksProviderUtils); + long[] trackIds = gpxFileTrackImporter.importFile(inputStream); assertEquals(1, trackIds.length); assertEquals(TRACK_ID_0, trackIds[0]); @@ -212,8 +215,9 @@ public class GpxImporterTest extends AbstractTestImporter { AndroidMock.replay(myTracksProviderUtils); InputStream inputStream = new ByteArrayInputStream(VALID_TWO_TRACKS_GPX.getBytes()); - GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils); - long[] trackIds = gpxImporter.importFile(inputStream); + GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter( + getContext(), myTracksProviderUtils); + long[] trackIds = gpxFileTrackImporter.importFile(inputStream); assertEquals(2, trackIds.length); assertEquals(TRACK_ID_0, trackIds[0]); assertEquals(TRACK_ID_1, trackIds[1]); @@ -279,8 +283,9 @@ public class GpxImporterTest extends AbstractTestImporter { InputStream inputStream = new ByteArrayInputStream(xml.getBytes()); try { - GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils); - gpxImporter.importFile(inputStream); + GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter( + getContext(), myTracksProviderUtils); + gpxFileTrackImporter.importFile(inputStream); } catch (SAXException e) { // expected } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/KmlImporterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/KmlFileTrackImporterTest.java similarity index 91% rename from MyTracksTest/src/com/google/android/apps/mytracks/io/file/KmlImporterTest.java rename to MyTracksTest/src/com/google/android/apps/mytracks/io/file/KmlFileTrackImporterTest.java index 3184ce575..391b44423 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/KmlImporterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/KmlFileTrackImporterTest.java @@ -30,11 +30,11 @@ import java.io.InputStream; import org.easymock.Capture; /** - * Tests for {@link KmlImporter}. + * Tests for {@link KmlFileTrackImporter}. * * @author Jimmy Shih */ -public class KmlImporterTest extends AbstractTestImporter { +public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter { private static String getNameAndDescription(String name, String description) { return "