From 6d42803dd8a1bb89c56cc529fcb2a7a233b2c950 Mon Sep 17 00:00:00 2001 From: Rodrigo Damazio Date: Thu, 12 Aug 2010 19:43:27 -0300 Subject: [PATCH] Updating statistics object usage in SAX importer --- .../android/apps/mytracks/io/GpxImporter.java | 31 +++++++++---------- .../apps/mytracks/io/GpxImporterTest.java | 3 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/GpxImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/GpxImporter.java index a4240ebd1..2630c0a58 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/GpxImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/GpxImporter.java @@ -1,12 +1,12 @@ /* - * Copyright 2008 Google Inc. - * + * Copyright 2010 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 @@ -17,7 +17,7 @@ package com.google.android.apps.mytracks.io; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Track; -import com.google.android.apps.mytracks.stats.TripStatistics; +import com.google.android.apps.mytracks.stats.TripStatisticsBuilder; import com.google.android.apps.mytracks.util.MyTracksUtils; import android.location.Location; @@ -101,9 +101,9 @@ public class GpxImporter extends DefaultHandler { private Track track; /** - * Statistics object for the current track + * Statistics builder for the current track. */ - private TripStatistics stats; + private TripStatisticsBuilder statsBuilder; /** * Number of locations already processed @@ -314,7 +314,7 @@ public class GpxImporter extends DefaultHandler { if (MyTracksUtils.isValidLocation(location)) { - stats.addLocation(location, location.getTime()); + statsBuilder.addLocation(location, location.getTime()); // insert in db Uri trackPointIdUri = providerUtils.insertTrackPoint(location, track @@ -349,15 +349,14 @@ public class GpxImporter extends DefaultHandler { if (lastLocation != null) { // Calculate statistics for the imported track and update - stats.pauseAt(lastLocation.getTime()); - track.setStopTime(lastLocation.getTime()); + statsBuilder.pauseAt(lastLocation.getTime()); track.setNumberOfPoints(numberOfLocations); - stats.fillStatisticsForTrack(track); + track.setStatistics(statsBuilder.getStatistics()); providerUtils.updateTrack(track); tracksWritten.add(track.getId()); isCurrentTrackRollbackable = false; lastLocation = null; - stats = null; + statsBuilder = null; } else { @@ -390,12 +389,12 @@ public class GpxImporter extends DefaultHandler { throw new SAXException(msg); } } - + location.setTime(time); // initialize start time with time of first track point - if (stats == null) { - stats = new TripStatistics(time); - track.setStartTime(time); + if (statsBuilder == null) { + statsBuilder = new TripStatisticsBuilder(); + statsBuilder.resumeAt(time); } // We don't have a speed and bearing in GPX, make something up from diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/GpxImporterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/GpxImporterTest.java index 4b7419c2c..0db21c091 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/GpxImporterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/GpxImporterTest.java @@ -128,7 +128,8 @@ public class GpxImporterTest extends AndroidTestCase { Track track = trackParam.getValue(); assertEquals(TRACK_NAME, track.getName()); assertEquals(TRACK_DESC, track.getDescription()); - assertEquals(format.parse(TRACK_TIME_1).getTime(), track.getStartTime()); + assertEquals(format.parse(TRACK_TIME_1).getTime(), + track.getStatistics().getStartTime()); assertNotSame(-1, track.getStartId()); assertNotSame(-1, track.getStopId());