diff --git a/.hgignore b/.hgignore index 1c3f1f5a7..ffa8823b5 100644 --- a/.hgignore +++ b/.hgignore @@ -7,3 +7,5 @@ syntax:glob MyTracksTest/annotations.log **/*.pyc **/*.pyo +syntax: glob +MyTracksTest/hs_err_pid*.log diff --git a/MyTracks/res/values/colors.xml b/MyTracks/res/values/colors.xml index 4d08680fa..eca05f9d7 100644 --- a/MyTracks/res/values/colors.xml +++ b/MyTracks/res/values/colors.xml @@ -54,11 +54,11 @@ limitations under the License. - #f774DF00 + #F774DF00 - #f75858FA + #F75858FA - #f7DF0101 + #F7DF0101 diff --git a/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java b/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java index 46c861928..1705c481d 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java @@ -259,25 +259,8 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe // Draw the selected track: drawTrack(canvas, projection, viewRect); - // Draw the "End" marker. - if (showEndMarker) { - for (int i = getPoints().size() - 1; i >= 0; --i) { - if (getPoints().get(i).valid) { - drawElement(canvas, projection, getPoints().get(i).geoPoint, endMarker, - -markerWidth / 2, -markerHeight); - break; - } - } - } - - // Draw the "Start" marker. - for (int i = 0; i < getPoints().size(); ++i) { - if (getPoints().get(i).valid) { - drawElement(canvas, projection, getPoints().get(i).geoPoint, startMarker, - -markerWidth / 2, -markerHeight); - break; - } - } + // Draw the "Start" and "End" markers: + drawMarkers(canvas, projection); // Draw the waypoints: drawWaypoints(canvas, projection); @@ -287,6 +270,28 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe drawMyLocation(canvas, projection); } + private void drawMarkers(Canvas canvas, Projection projection) { + // Draw the "End" marker. + if (showEndMarker) { + for (int i = getPoints().size() - 1; i >= 0; --i) { + if (getPoints().get(i).valid) { + drawElement(canvas, projection, getPoints().get(i).geoPoint, endMarker, + -markerWidth / 2, -markerHeight); + break; + } + } + } + + // Draw the "Start" marker. + for (int i = 0; i < getPoints().size(); ++i) { + if (getPoints().get(i).valid) { + drawElement(canvas, projection, getPoints().get(i).geoPoint, startMarker, + -markerWidth / 2, -markerHeight); + break; + } + } + } + // Visible for testing. Projection getMapProjection(MapView mapView) { return mapView.getProjection(); @@ -306,6 +311,11 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe return new Path(); } + // Visible for testing. + public Path getLastPath() { + return trackPathPainter.getLastPath(); + } + private void drawWaypoints(Canvas canvas, Projection projection) { synchronized (waypoints) {; for (Waypoint wpt : waypoints) { diff --git a/MyTracks/src/com/google/android/apps/mytracks/SettingsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/SettingsActivity.java index 2987954a7..e6ffc58f4 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/SettingsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/SettingsActivity.java @@ -461,14 +461,15 @@ public class SettingsActivity extends PreferenceActivity { }.start(); } - /** Check if metric is unchecked and in that case convert to english to show it to the user. */ + /** Set the given edit text preference text. + If the units are not metric convert the value before displaying. */ private void viewTrackColorModeSettings(EditTextPreference preference, int id) { CheckBoxPreference metricUnitsPreference = (CheckBoxPreference) findPreference( getString(R.string.metric_units_key)); if(metricUnitsPreference.isChecked()) { return; } - //Convert miles/h to km/h + // Convert miles/h to km/h SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); String metricspeed = prefs.getString(getString(id), null); int englishspeed; @@ -480,14 +481,15 @@ public class SettingsActivity extends PreferenceActivity { preference.getEditText().setText(String.valueOf(englishspeed)); } - /** Check if metric is unchecked and in that case convert to metric to save it internaly. */ + /** Saves the given edit text preference value. + If the units are not metric convert the value before saving. */ private void validateTrackColorModeSettings(EditTextPreference preference, String newValue, int id) { CheckBoxPreference metricUnitsPreference = (CheckBoxPreference) findPreference( getString(R.string.metric_units_key)); String metricspeed; if(!metricUnitsPreference.isChecked()) { - //Convert miles/h to km/h + // Convert miles/h to km/h try { metricspeed = String.valueOf((int) (Double.parseDouble(newValue) * UnitConversions.MPH_TO_KMH) + 1); } catch (NumberFormatException e) { diff --git a/MyTracks/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathDescriptor.java b/MyTracks/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathDescriptor.java index e26cee3d3..8da7c5218 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathDescriptor.java +++ b/MyTracks/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathDescriptor.java @@ -15,16 +15,16 @@ */ package com.google.android.apps.mytracks.maps; - import com.google.android.apps.mytracks.Constants; - 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.maps.mytracks.R; - import android.content.Context; - - import android.content.SharedPreferences; - import android.content.SharedPreferences.OnSharedPreferenceChangeListener; - import android.util.Log; +import com.google.android.apps.mytracks.Constants; +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.maps.mytracks.R; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.util.Log; /** @@ -32,8 +32,8 @@ package com.google.android.apps.mytracks.maps; * * @author Vangelis S. */ -public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor, - OnSharedPreferenceChangeListener { +public class DynamicSpeedTrackPathDescriptor + implements TrackPathDescriptor, OnSharedPreferenceChangeListener { private int slowSpeed; private int normalSpeed; private int speedMargin; @@ -41,7 +41,6 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor, private final Context context; public DynamicSpeedTrackPathDescriptor(Context context){ - this.context = context; SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, 0); @@ -100,7 +99,8 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor, SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, 0); long currentTrackId = prefs.getLong(context.getString(R.string.selected_track_key), -1); if(currentTrackId == -1) { - return false; //in reality this means something went awry, additional logic to exit or so? + // in reality this means something went awry, additional logic to exit or so? + return false; } Track track = MyTracksProviderUtils.Factory.get(context).getTrack(currentTrackId); TripStatistics stats = track.getStatistics(); @@ -118,7 +118,10 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor, } else { difference = Math.abs(averageMovingSpeed - newaverageSpeed) / difference * 100; } - averageMovingSpeed = newaverageSpeed; - return difference >= 20; + if(difference >= 20) { + averageMovingSpeed = newaverageSpeed; + return true; + } + return false; } } \ No newline at end of file diff --git a/MyTracks/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathPainter.java b/MyTracks/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathPainter.java index 4a2d5b081..2234f8b8f 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathPainter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathPainter.java @@ -15,23 +15,24 @@ */ package com.google.android.apps.mytracks.maps; -import java.util.ArrayList; -import java.util.List; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Point; -import android.graphics.Rect; - import com.google.android.apps.mytracks.ColoredPath; import com.google.android.apps.mytracks.MapOverlay.CachedLocation; import com.google.android.maps.GeoPoint; import com.google.android.maps.Projection; import com.google.android.maps.mytracks.R; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.Point; +import android.graphics.Rect; + +import java.util.ArrayList; +import java.util.List; + /** - * A path painter that variates the path colors based on fixed speeds or average speed margin + * A path painter that varies the path colors based on fixed speeds or average speed margin * depending of the TrackPathDescriptor passed to its constructor. * * @author Vangelis S. @@ -126,7 +127,15 @@ public class DynamicSpeedTrackPathPainter implements TrackPathPainter { @Override public boolean needsRedraw() { - // TODO Auto-generated method stub return trackPathDescriptor.needsRedraw(); } + + @Override + public Path getLastPath() { + Path path = new Path(); + for(int i = 0; i < coloredPaths.size(); ++i) { + path.addPath(coloredPaths.get(i).getPath()); + } + return path; + } } \ No newline at end of file diff --git a/MyTracks/src/com/google/android/apps/mytracks/maps/FixedSpeedTrackPathDescriptor.java b/MyTracks/src/com/google/android/apps/mytracks/maps/FixedSpeedTrackPathDescriptor.java index 1f3764aa1..636c963c3 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/maps/FixedSpeedTrackPathDescriptor.java +++ b/MyTracks/src/com/google/android/apps/mytracks/maps/FixedSpeedTrackPathDescriptor.java @@ -37,8 +37,8 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSha public FixedSpeedTrackPathDescriptor(Context context){ this.context = context; - context.getSharedPreferences(Constants.SETTINGS_NAME, 0) - .registerOnSharedPreferenceChangeListener(this); + context.getSharedPreferences(Constants.SETTINGS_NAME, 0) + .registerOnSharedPreferenceChangeListener(this); SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, 0); if (prefs == null) { @@ -89,10 +89,10 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSha } SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, 0); if (prefs == null) { - slowSpeed = 9; - normalSpeed = 17; - return; - } + slowSpeed = 9; + normalSpeed = 17; + return; + } try { slowSpeed = Integer.parseInt(prefs.getString(context.getString( diff --git a/MyTracks/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainter.java b/MyTracks/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainter.java index 7a0dce291..b12ae2370 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainter.java @@ -15,7 +15,10 @@ */ package com.google.android.apps.mytracks.maps; -import java.util.List; +import com.google.android.apps.mytracks.MapOverlay.CachedLocation; +import com.google.android.maps.GeoPoint; +import com.google.android.maps.Projection; +import com.google.android.maps.mytracks.R; import android.content.Context; import android.graphics.Canvas; @@ -24,10 +27,7 @@ import android.graphics.Path; import android.graphics.Point; import android.graphics.Rect; -import com.google.android.apps.mytracks.MapOverlay.CachedLocation; -import com.google.android.maps.GeoPoint; -import com.google.android.maps.Projection; -import com.google.android.maps.mytracks.R; +import java.util.List; /** @@ -99,4 +99,9 @@ public class SingleColorTrackPathPainter implements TrackPathPainter { public boolean needsRedraw() { return false; } + + @Override + public Path getLastPath() { + return path; + } } \ No newline at end of file diff --git a/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathDescriptor.java b/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathDescriptor.java index 4d4de59f8..389994e6b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathDescriptor.java +++ b/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathDescriptor.java @@ -16,23 +16,23 @@ package com.google.android.apps.mytracks.maps; /** - * A path descriptor interface as template to each type of path descriptor. + * An interface for classes which describe how to draw a track path. * * @author Vangelis S. */ public interface TrackPathDescriptor { /** - * @return The speed limit considered as slow. + * @return The maximum speed which is considered slow. */ int getSlowSpeed(); /** - * @return The speed limit considered as normal. + * @return The maximum speed which is considered normal. */ int getNormalSpeed(); /** - * @return If the path needs to be updated from scratch. + * @return True if the path needs to be updated. */ boolean needsRedraw(); } \ No newline at end of file diff --git a/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathPainter.java b/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathPainter.java index 9efc9fc34..1f1d8e31d 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathPainter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathPainter.java @@ -15,47 +15,53 @@ */ package com.google.android.apps.mytracks.maps; -import java.util.List; - -import android.graphics.Canvas; -import android.graphics.Rect; - import com.google.android.apps.mytracks.MapOverlay.CachedLocation; import com.google.android.maps.Projection; +import android.graphics.Canvas; +import android.graphics.Path; +import android.graphics.Rect; + +import java.util.List; + /** - * A path painter interface as template to each type of path painter. + * An interface for classes which paint the track path. * * @author Vangelis S. */ public interface TrackPathPainter { /** - * Clears the related data + * Clears the related data. */ void clear(); /** - * Draws the path to the canvas + * Draws the path to the canvas. * @param canvas The Canvas to draw upon */ void drawTrack(Canvas canvas); /** - * Updates the path - * @param projection The Canvas to draw upon + * Updates the path. + * @param projection The Canvas to draw upon. * @param viewRect The Path to be drawn. - * @param startLocationIdx The start point from where update the path - * @param alwaysVisible Flag for alwaysvisible - * @param points The list of points used to update the path + * @param startLocationIdx The start point from where update the path. + * @param alwaysVisible Flag for alwaysvisible. + * @param points The list of points used to update the path. */ void updatePath(Projection projection, Rect viewRect, int startLocationIdx, Boolean alwaysVisible, List points); /** - * @return If the path needs to be updated from scratch. + * @return True if the path needs to be updated. */ boolean needsRedraw(); + + /** + * @return The path being used currently. + */ + Path getLastPath(); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathPainterFactory.java b/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathPainterFactory.java index 0d901f15b..88a66d238 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathPainterFactory.java +++ b/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathPainterFactory.java @@ -23,7 +23,7 @@ import android.content.SharedPreferences; import android.util.Log; /** - * A factory of TrackPathPainters. + * A factory for TrackPathPainters. * * @author Vangelis S. */ @@ -45,9 +45,9 @@ public class TrackPathPainterFactory { } String colorMode = prefs.getString(context.getString(R.string.track_color_mode_key), null); - Log.i(Constants.TAG, "Creating trackpathpainter of type: " + colorMode); + Log.i(Constants.TAG, "Creating track path painter of type: " + colorMode); - if (colorMode == null) { + if (colorMode == null || colorMode.equals(context.getString(R.string.track_color_mode_none))) { return new SingleColorTrackPathPainter(context); } else if (colorMode.equals(context.getString(R.string.track_color_mode_fixed))) { return new DynamicSpeedTrackPathPainter(context, @@ -56,6 +56,7 @@ public class TrackPathPainterFactory { return new DynamicSpeedTrackPathPainter(context, new DynamicSpeedTrackPathDescriptor(context)); } else { + Log.i(Constants.TAG, "Unknow colorMode: " + colorMode); return new SingleColorTrackPathPainter(context); } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathUtilities.java b/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathUtilities.java index 9bc804a58..c8b788352 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathUtilities.java +++ b/MyTracks/src/com/google/android/apps/mytracks/maps/TrackPathUtilities.java @@ -24,8 +24,7 @@ import android.graphics.Paint; * @author Vangelis S. */ public class TrackPathUtilities { - public static Paint getPaint(int id, Context context) - { + public static Paint getPaint(int id, Context context) { Paint paint = new Paint(); paint.setColor(context.getResources().getColor(id)); paint.setStrokeWidth(3); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/MapOverlayTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/MapOverlayTest.java index 209203b48..49a91b49b 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/MapOverlayTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/MapOverlayTest.java @@ -16,103 +16,23 @@ package com.google.android.apps.mytracks; import com.google.android.apps.mytracks.content.Waypoint; -import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; -import com.google.android.maps.Projection; -import android.content.Context; import android.graphics.Canvas; -import android.graphics.Path; -import android.graphics.Point; -import android.graphics.PointF; -import android.graphics.Rect; import android.location.Location; import android.test.AndroidTestCase; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - /** * Tests for the MyTracks map overlay. * * @author Bartlomiej Niechwiej + * @author Vangelis S. */ public class MapOverlayTest extends AndroidTestCase { private Canvas canvas; private MockMyTracksOverlay myTracksOverlay; private MapView mockView; - private Projection mockProjection; - - /** - * A mock version of {@code MapOverlay} that does not use - * {@class MapView}. - */ - private class MockMyTracksOverlay extends MapOverlay { - public MockMyTracksOverlay(Context context) { - super(context); - } - @Override - Projection getMapProjection(MapView mapView) { - return mockProjection; - } - @Override - Rect getMapViewRect(MapView mapView) { - return new Rect(0, 0, 100, 100); - } - @Override - Path newPath() { - return new MockPath(); - } - } - - /** - * A mock class that intercepts {@code Path}'s and records calls to - * {@code #moveTo()} and {@code #lineTo()}. - */ - private static class MockPath extends Path { - /** A list of disjoined path segments. */ - public final List> segments = new LinkedList>(); - /** The total number of points in this path. */ - public int totalPoints; - - private List currentSegment; - @Override - public void lineTo(float x, float y) { - super.lineTo(x, y); - assertNotNull(currentSegment); - currentSegment.add(new PointF(x, y)); - totalPoints++; - } - @Override - public void moveTo(float x, float y) { - super.moveTo(x, y); - segments.add(currentSegment = - new ArrayList(Arrays.asList(new PointF(x, y)))); - totalPoints++; - } - } - - /** - * A mock {@code Projection} that acts as the identity matrix. - */ - private static class MockProjection implements Projection { - @Override - public Point toPixels(GeoPoint in, Point out) { - return out; - } - @Override - public float metersToEquatorPixels(float meters) { - return meters; - } - @Override - public GeoPoint fromPixels(int x, int y) { - return new GeoPoint(y, x); - } - } - @Override protected void setUp() throws Exception { super.setUp(); @@ -121,9 +41,8 @@ public class MapOverlayTest extends AndroidTestCase { // Enable drawing. myTracksOverlay.setTrackDrawingEnabled(true); mockView = null; - mockProjection = new MockProjection(); } - + public void testAddLocation() throws Exception { Location location = new Location("gps"); location.setLatitude(10); @@ -137,19 +56,19 @@ public class MapOverlayTest extends AndroidTestCase { myTracksOverlay.addLocation(location); assertEquals(2, myTracksOverlay.getNumLocations()); assertEquals(0, myTracksOverlay.getNumWaypoints()); - //assertNull(myTracksOverlay.getLastPath()); + assertNull(myTracksOverlay.getLastPath()); // Draw and make sure that we don't lose any point. myTracksOverlay.draw(canvas, mockView, false); assertEquals(2, myTracksOverlay.getNumLocations()); assertEquals(0, myTracksOverlay.getNumWaypoints()); - //assertNotNull(myTracksOverlay.getLastPath()); - //assertEquals(2, ((MockPath)myTracksOverlay.getLastPath()).totalPoints); + assertNotNull(myTracksOverlay.getLastPath()); + assertEquals(2, ((MockPath)myTracksOverlay.getLastPath()).totalPoints); myTracksOverlay.draw(canvas, mockView, true); assertEquals(2, myTracksOverlay.getNumLocations()); assertEquals(0, myTracksOverlay.getNumWaypoints()); - //assertNotNull(myTracksOverlay.getLastPath()); + assertNotNull(myTracksOverlay.getLastPath()); } public void testClearPoints() throws Exception { @@ -182,7 +101,7 @@ public class MapOverlayTest extends AndroidTestCase { myTracksOverlay.addWaypoint(waypoint); assertEquals(1, myTracksOverlay.getNumWaypoints()); assertEquals(0, myTracksOverlay.getNumLocations()); - //assertNull(myTracksOverlay.getLastPath()); + assertNull(myTracksOverlay.getLastPath()); final int waypoints = 10; for (int i = 0; i < waypoints; ++i) { @@ -192,7 +111,7 @@ public class MapOverlayTest extends AndroidTestCase { } assertEquals(1 + waypoints, myTracksOverlay.getNumWaypoints()); assertEquals(0, myTracksOverlay.getNumLocations()); - //assertNull(myTracksOverlay.getLastPath()); + assertNull(myTracksOverlay.getLastPath()); } public void testClearWaypoints() throws Exception { @@ -226,18 +145,18 @@ public class MapOverlayTest extends AndroidTestCase { // Shadow. myTracksOverlay.draw(canvas, mockView, true); // We don't expect to do anything if - //assertNull(myTracksOverlay.getLastPath()); + assertNull(myTracksOverlay.getLastPath()); assertEquals(40, myTracksOverlay.getNumWaypoints()); assertEquals(100, myTracksOverlay.getNumLocations()); // No shadow. myTracksOverlay.draw(canvas, mockView, false); - //assertNotNull(myTracksOverlay.getLastPath()); - //assertTrue(myTracksOverlay.getLastPath() instanceof MockPath); - //MockPath path = (MockPath) myTracksOverlay.getLastPath(); + assertNotNull(myTracksOverlay.getLastPath()); + assertTrue(myTracksOverlay.getLastPath() instanceof MockPath); + MockPath path = (MockPath) myTracksOverlay.getLastPath(); assertEquals(40, myTracksOverlay.getNumWaypoints()); assertEquals(100, myTracksOverlay.getNumLocations()); - //assertEquals(100, path.totalPoints); + assertEquals(100, path.totalPoints); // TODO: Check the points from the path (and the segments). } } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/MockMyTracksOverlay.java b/MyTracksTest/src/com/google/android/apps/mytracks/MockMyTracksOverlay.java new file mode 100644 index 000000000..51d409067 --- /dev/null +++ b/MyTracksTest/src/com/google/android/apps/mytracks/MockMyTracksOverlay.java @@ -0,0 +1,55 @@ +/* + * 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 + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.android.apps.mytracks; + +import com.google.android.maps.MapView; +import com.google.android.maps.Projection; + +import android.content.Context; +import android.graphics.Path; +import android.graphics.Rect; + +/** + * Elements for Tests for the MyTracks map overlay. + * + * @author Bartlomiej Niechwiej + * @author Vangelis S. + */ + + /** + * A mock version of {@code MapOverlay} that does not use + * {@class MapView}. + */ + public class MockMyTracksOverlay extends MapOverlay { + + private Projection mockProjection; + public MockMyTracksOverlay(Context context) { + super(context); + mockProjection = new MockProjection(); + } + @Override + public Projection getMapProjection(MapView mapView) { + return mockProjection; + } + @Override + public Rect getMapViewRect(MapView mapView) { + return new Rect(0, 0, 100, 100); + } + @Override + public Path newPath() { + return new MockPath(); + } + } \ No newline at end of file diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/MockPath.java b/MyTracksTest/src/com/google/android/apps/mytracks/MockPath.java new file mode 100644 index 000000000..45cf515c9 --- /dev/null +++ b/MyTracksTest/src/com/google/android/apps/mytracks/MockPath.java @@ -0,0 +1,62 @@ +/* + * 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 + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.android.apps.mytracks; + +import android.graphics.Path; +import android.graphics.PointF; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import junit.framework.Assert; + +/** + * Elements for Tests for the MyTracks map overlay. + * + * @author Bartlomiej Niechwiej + * @author Vangelis S. + */ + + /** + * A mock class that intercepts {@code Path}'s and records calls to + * {@code #moveTo()} and {@code #lineTo()}. + */ + public class MockPath extends Path { + /** A list of disjoined path segments. */ + public final List> segments = new LinkedList>(); + /** The total number of points in this path. */ + public int totalPoints; + + private List currentSegment; + + @Override + public void lineTo(float x, float y) { + super.lineTo(x, y); + + Assert.assertNotNull(currentSegment); + currentSegment.add(new PointF(x, y)); + totalPoints++; + } + @Override + public void moveTo(float x, float y) { + super.moveTo(x, y); + segments.add(currentSegment = + new ArrayList(Arrays.asList(new PointF(x, y)))); + totalPoints++; + } + } \ No newline at end of file diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/MockProjection.java b/MyTracksTest/src/com/google/android/apps/mytracks/MockProjection.java new file mode 100644 index 000000000..59e82d238 --- /dev/null +++ b/MyTracksTest/src/com/google/android/apps/mytracks/MockProjection.java @@ -0,0 +1,46 @@ +/* + * 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 + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.android.apps.mytracks; + +import com.google.android.maps.GeoPoint; +import com.google.android.maps.Projection; + +import android.graphics.Point; + +/** + * Elements for Tests for the MyTracks map overlay. + * + * @author Bartlomiej Niechwiej + * @author Vangelis S. + */ + + /** + * A mock {@code Projection} that acts as the identity matrix. + */ + public class MockProjection implements Projection { + @Override + public Point toPixels(GeoPoint in, Point out) { + return out; + } + @Override + public float metersToEquatorPixels(float meters) { + return meters; + } + @Override + public GeoPoint fromPixels(int x, int y) { + return new GeoPoint(y, x); + } + } \ No newline at end of file diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathDescriptorsTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathDescriptorsTest.java new file mode 100644 index 000000000..880f1bd64 --- /dev/null +++ b/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathDescriptorsTest.java @@ -0,0 +1,108 @@ +/* + * 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 + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.android.apps.mytracks.maps; + +import com.google.android.apps.mytracks.MockMyTracksOverlay; +import com.google.android.maps.MapView; + +import android.graphics.Canvas; +import android.location.Location; +import android.test.AndroidTestCase; + +/** + * Tests for the MyTracks map overlay. + * + * @author Bartlomiej Niechwiej + * @author Vangelis S. + */ +public class TrackPathDescriptorsTest extends AndroidTestCase { + private Canvas canvas; + private MockMyTracksOverlay myTracksOverlay; + private MapView mockView; + + @Override + protected void setUp() throws Exception { + super.setUp(); + canvas = new Canvas(); + myTracksOverlay = new MockMyTracksOverlay(getContext()); + // Enable drawing. + myTracksOverlay.setTrackDrawingEnabled(true); + mockView = null; + } + + public void testSimpeColorTrackPathPainter() throws Exception { + Location location = new Location("gps"); + location.setLatitude(10); + + for (int i = 0; i < 100; ++i) { + location = new Location("gps"); + location.setLatitude(20 + i / 2); + location.setLongitude(150 - i); + myTracksOverlay.addLocation(location); + } + + TrackPathPainter painter = new SingleColorTrackPathPainter(getContext()); + int startLocationIdx = 0; + Boolean alwaysVisible = true; + + painter.updatePath(myTracksOverlay.getMapProjection(mockView), + myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible, + myTracksOverlay.getPoints()); + painter.drawTrack(canvas); + } + + public void testFixedSpeedTrackPathDescriptor() throws Exception { + Location location = new Location("gps"); + location.setLatitude(10); + + for (int i = 0; i < 100; ++i) { + location = new Location("gps"); + location.setLatitude(20 + i / 2); + location.setLongitude(150 - i); + myTracksOverlay.addLocation(location); + } + + TrackPathPainter painter = new DynamicSpeedTrackPathPainter(getContext(), new FixedSpeedTrackPathDescriptor(getContext())); + int startLocationIdx = 0; + Boolean alwaysVisible = true; + + painter.updatePath(myTracksOverlay.getMapProjection(mockView), + myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible, + myTracksOverlay.getPoints()); + painter.drawTrack(canvas); + } + + public void testDynamicSpeedTrackPathDescriptor() throws Exception { + Location location = new Location("gps"); + location.setLatitude(10); + + for (int i = 0; i < 100; ++i) { + location = new Location("gps"); + location.setLatitude(20 + i / 2); + location.setLongitude(150 - i); + myTracksOverlay.addLocation(location); + } + + TrackPathPainter painter = new DynamicSpeedTrackPathPainter(getContext(), new DynamicSpeedTrackPathDescriptor(getContext())); + int startLocationIdx = 0; + Boolean alwaysVisible = true; + + painter.updatePath(myTracksOverlay.getMapProjection(mockView), + myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible, + myTracksOverlay.getPoints()); + painter.drawTrack(canvas); + } +}