forked from upstream-mirrors/OpenTracks
Removed MapOverlay.
This commit is contained in:
-104
@@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 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.util.PreferencesUtils;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for the {@link DynamicSpeedTrackPathDescriptor}.
|
|
||||||
*
|
|
||||||
* @author Youtao Liu
|
|
||||||
*/
|
|
||||||
public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
|
||||||
|
|
||||||
private Context context;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
context = getContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the method {@link DynamicSpeedTrackPathDescriptor#getSpeedMargin()}
|
|
||||||
* with zero, normal and illegal value.
|
|
||||||
*/
|
|
||||||
public void testGetSpeedMargin() {
|
|
||||||
// The default value of speedMargin is 25.
|
|
||||||
int[] expectations = { 0, 50, 99, 25 };
|
|
||||||
// Test
|
|
||||||
for (int i = 0; i < expectations.length; i++) {
|
|
||||||
PreferencesUtils.setInt(context, R.string.track_color_mode_percentage_key, expectations[i]);
|
|
||||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
|
||||||
context);
|
|
||||||
assertEquals(expectations[i], dynamicSpeedTrackPathDescriptor.getSpeedMargin());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link DynamicSpeedTrackPathDescriptor#getSlowSpeed()}.
|
|
||||||
*/
|
|
||||||
public void testGetSlowSpeed() {
|
|
||||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
|
||||||
context);
|
|
||||||
dynamicSpeedTrackPathDescriptor.setAverageMovingSpeed(50);
|
|
||||||
dynamicSpeedTrackPathDescriptor.setSpeedMargin(10);
|
|
||||||
assertEquals(50.0, dynamicSpeedTrackPathDescriptor.getAverageMovingSpeed());
|
|
||||||
assertEquals(45.0, dynamicSpeedTrackPathDescriptor.getSlowSpeed());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link DynamicSpeedTrackPathDescriptor#getNormalSpeed()}.
|
|
||||||
*/
|
|
||||||
public void testGetNormalSpeed() {
|
|
||||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
|
||||||
context);
|
|
||||||
dynamicSpeedTrackPathDescriptor.setAverageMovingSpeed(50);
|
|
||||||
dynamicSpeedTrackPathDescriptor.setSpeedMargin(10);
|
|
||||||
assertEquals(50.0, dynamicSpeedTrackPathDescriptor.getAverageMovingSpeed());
|
|
||||||
assertEquals(55.0, dynamicSpeedTrackPathDescriptor.getNormalSpeed());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link DynamicSpeedTrackPathDescriptor#updateState(com.google.android.apps.mytracks.stats.TripStatistics)}
|
|
||||||
* by different averageMovingSpeed.
|
|
||||||
*/
|
|
||||||
public void testIsDiffereceSignificant() {
|
|
||||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
|
||||||
context);
|
|
||||||
double[] averageMovingSpeeds = { 0, 30, 30, 30 };
|
|
||||||
double[] newAverageMovingSpeed = { 20, 30,
|
|
||||||
// Difference is less than CRITICAL_DIFFERENCE_PERCENTAGE
|
|
||||||
30 * (1 + (DynamicSpeedTrackPathDescriptor.CRITICAL_DIFFERENCE_PERCENTAGE / 100) / 2),
|
|
||||||
// Difference is more than CRITICAL_DIFFERENCE_PERCENTAGE
|
|
||||||
30 * (1 + (DynamicSpeedTrackPathDescriptor.CRITICAL_DIFFERENCE_PERCENTAGE / 100.00) * 2) };
|
|
||||||
boolean[] expectedValues = { true, false, false, true };
|
|
||||||
double[] expectedAverageMovingSpeed = { 0, 30, 30, 30 };
|
|
||||||
// Test
|
|
||||||
for (int i = 0; i < newAverageMovingSpeed.length; i++) {
|
|
||||||
dynamicSpeedTrackPathDescriptor.setAverageMovingSpeed(averageMovingSpeeds[i]);
|
|
||||||
assertEquals(expectedValues[i], dynamicSpeedTrackPathDescriptor.isDifferenceSignificant(
|
|
||||||
averageMovingSpeeds[i], newAverageMovingSpeed[i]));
|
|
||||||
assertEquals(expectedAverageMovingSpeed[i],
|
|
||||||
dynamicSpeedTrackPathDescriptor.getAverageMovingSpeed());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-92
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 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.util.PreferencesUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for the {@link FixedSpeedTrackPathDescriptor}.
|
|
||||||
*
|
|
||||||
* @author Youtao Liu
|
|
||||||
*/
|
|
||||||
public class FixedSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void tearDown() throws Exception {
|
|
||||||
Context context = getContext();
|
|
||||||
PreferencesUtils.setString(
|
|
||||||
context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
|
||||||
PreferencesUtils.setInt(context, R.string.track_color_mode_slow_key,
|
|
||||||
PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT);
|
|
||||||
PreferencesUtils.setInt(context, R.string.track_color_mode_medium_key,
|
|
||||||
PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT);
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests when the slow speed and the normal speed are both zero.
|
|
||||||
*/
|
|
||||||
public void testGetSpeed_zero() {
|
|
||||||
testSpeed(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests when the slow speed and the normal speed are both one.
|
|
||||||
*/
|
|
||||||
public void testGetSpeed_one() {
|
|
||||||
testSpeed(1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests when the slow speed and the normal speed are both large number. E.g.,
|
|
||||||
* 99 and 100.
|
|
||||||
*/
|
|
||||||
public void testGetSpeed_large() {
|
|
||||||
testSpeed(99, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests when the slow speed and the normal speed are both the default value.
|
|
||||||
*/
|
|
||||||
public void testGetSpeed_default() {
|
|
||||||
testSpeed(PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT,
|
|
||||||
PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testSpeed(int slowSpeed, int normalSpeed) {
|
|
||||||
testSpeed(slowSpeed, normalSpeed, true);
|
|
||||||
testSpeed(slowSpeed, normalSpeed, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testSpeed(int slowSpeed, int normalSpeed, boolean metric) {
|
|
||||||
Context context = getContext();
|
|
||||||
PreferencesUtils.setString(context, R.string.stats_units_key,
|
|
||||||
context.getString(metric ? R.string.stats_units_metric : R.string.stats_units_imperial));
|
|
||||||
PreferencesUtils.setInt(context, R.string.track_color_mode_slow_key, slowSpeed);
|
|
||||||
PreferencesUtils.setInt(context, R.string.track_color_mode_medium_key, normalSpeed);
|
|
||||||
FixedSpeedTrackPathDescriptor fixedSpeedTrackPathDescriptor = new FixedSpeedTrackPathDescriptor(
|
|
||||||
context);
|
|
||||||
double expectedSlowSpeed = metric ? slowSpeed : slowSpeed * UnitConversions.MI_TO_KM;
|
|
||||||
double expectedNormalSpeed = metric ? normalSpeed : normalSpeed * UnitConversions.MI_TO_KM;
|
|
||||||
assertEquals(expectedSlowSpeed, fixedSpeedTrackPathDescriptor.getSlowSpeed());
|
|
||||||
assertEquals(expectedNormalSpeed, fixedSpeedTrackPathDescriptor.getNormalSpeed());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-60
@@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 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 android.content.Context;
|
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for the {@link MultiColorTrackPath}.
|
|
||||||
*
|
|
||||||
* @author Youtao Liu
|
|
||||||
*/
|
|
||||||
public class MultiColorTrackPathTest extends AndroidTestCase {
|
|
||||||
|
|
||||||
private MultiColorTrackPath multiColorTrackPath;
|
|
||||||
private Context context;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
context = getContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the {@link MultiColorTrackPath#getColor(double)} when use dynamic speed
|
|
||||||
* track path descriptor.
|
|
||||||
*/
|
|
||||||
public void testGetColor_DynamicSpeedTrackPathDescriptor() {
|
|
||||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
|
||||||
context);
|
|
||||||
dynamicSpeedTrackPathDescriptor.setAverageMovingSpeed(50);
|
|
||||||
dynamicSpeedTrackPathDescriptor.setSpeedMargin(10);
|
|
||||||
multiColorTrackPath = new MultiColorTrackPath(context, dynamicSpeedTrackPathDescriptor);
|
|
||||||
|
|
||||||
// Slow speed should be below 45 (10% of 50), and fast speed should be above
|
|
||||||
// 55 (10% of 50).
|
|
||||||
assertEquals(multiColorTrackPath.getSlowColor(), multiColorTrackPath.getColor(5));
|
|
||||||
assertEquals(multiColorTrackPath.getSlowColor(), multiColorTrackPath.getColor(44));
|
|
||||||
assertEquals(multiColorTrackPath.getNormalColor(), multiColorTrackPath.getColor(50));
|
|
||||||
assertEquals(multiColorTrackPath.getNormalColor(), multiColorTrackPath.getColor(54));
|
|
||||||
assertEquals(multiColorTrackPath.getFastColor(), multiColorTrackPath.getColor(56));
|
|
||||||
assertEquals(multiColorTrackPath.getFastColor(), multiColorTrackPath.getColor(100));
|
|
||||||
|
|
||||||
assertNotSame(multiColorTrackPath.getSlowColor(), multiColorTrackPath.getNormalColor());
|
|
||||||
assertNotSame(multiColorTrackPath.getSlowColor(), multiColorTrackPath.getFastColor());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -508,7 +508,6 @@ public class ChartView extends View {
|
|||||||
|
|
||||||
clipToGraphArea(canvas);
|
clipToGraphArea(canvas);
|
||||||
drawDataSeries(canvas);
|
drawDataSeries(canvas);
|
||||||
drawWaypoints(canvas);
|
|
||||||
drawGrid(canvas);
|
drawGrid(canvas);
|
||||||
|
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
@@ -549,38 +548,6 @@ public class ChartView extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Draws the waypoints.
|
|
||||||
*
|
|
||||||
* @param canvas the canvas
|
|
||||||
*/
|
|
||||||
private void drawWaypoints(Canvas canvas) {
|
|
||||||
synchronized (waypoints) {
|
|
||||||
for (int i = 0; i < waypoints.size(); i++) {
|
|
||||||
final Waypoint waypoint = waypoints.get(i);
|
|
||||||
if (waypoint.getLocation() == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
double xValue = getWaypointXValue(waypoint);
|
|
||||||
if (xValue > maxX) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
canvas.save();
|
|
||||||
float x = getX(getWaypointXValue(waypoint));
|
|
||||||
canvas.drawLine(
|
|
||||||
x, topBorder + spacer + markerHeight / 2, x, topBorder + effectiveHeight, markerPaint);
|
|
||||||
canvas.translate(
|
|
||||||
x - (float) (markerWidth * MapOverlay.WAYPOINT_X_ANCHOR), topBorder + spacer);
|
|
||||||
if (waypoints.get(i).getType() == WaypointType.STATISTICS) {
|
|
||||||
statisticsMarker.draw(canvas);
|
|
||||||
} else {
|
|
||||||
waypointMarker.draw(canvas);
|
|
||||||
}
|
|
||||||
canvas.restore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the grid.
|
* Draws the grid.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,302 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2008 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 static com.google.android.apps.mytracks.content.TrackDataHub.TARGET_DISPLAYED_TRACK_POINTS;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
|
||||||
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
|
||||||
import com.google.android.apps.mytracks.maps.TrackPath;
|
|
||||||
import com.google.android.apps.mytracks.maps.TrackPathFactory;
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
|
||||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
|
||||||
import com.google.android.gms.maps.GoogleMap;
|
|
||||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
|
||||||
import com.google.android.gms.maps.model.MarkerOptions;
|
|
||||||
import com.google.android.gms.maps.model.Polyline;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
|
||||||
import android.location.Location;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A map overlay that displays my location arrow, error circle, and track info.
|
|
||||||
*
|
|
||||||
* @author Leif Hendrik Wilden
|
|
||||||
*/
|
|
||||||
public class MapOverlay {
|
|
||||||
|
|
||||||
public static final float WAYPOINT_X_ANCHOR = 13f / 48f;
|
|
||||||
|
|
||||||
private static final String TAG = MapOverlay.class.getSimpleName();
|
|
||||||
|
|
||||||
private static final float WAYPOINT_Y_ANCHOR = 43f / 48f;
|
|
||||||
private static final float MARKER_X_ANCHOR = 50f / 96f;
|
|
||||||
private static final float MARKER_Y_ANCHOR = 90f / 96f;
|
|
||||||
private static final int INITIAL_LOCATIONS_SIZE = 1024;
|
|
||||||
|
|
||||||
private final OnSharedPreferenceChangeListener
|
|
||||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
||||||
if (key == null
|
|
||||||
|| key.equals(PreferencesUtils.getKey(context, R.string.track_color_mode_key))) {
|
|
||||||
trackColorMode = PreferencesUtils.getString(
|
|
||||||
context, R.string.track_color_mode_key, PreferencesUtils.TRACK_COLOR_MODE_DEFAULT);
|
|
||||||
trackPath = TrackPathFactory.getTrackPath(context, trackColorMode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
private final List<CachedLocation> locations;
|
|
||||||
private final BlockingQueue<CachedLocation> pendingLocations;
|
|
||||||
private final List<Waypoint> waypoints;
|
|
||||||
|
|
||||||
private String trackColorMode = PreferencesUtils.TRACK_COLOR_MODE_DEFAULT;
|
|
||||||
|
|
||||||
private boolean showEndMarker = true;
|
|
||||||
private TrackPath trackPath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A pre-processed {@link Location} to speed up drawing.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
public static class CachedLocation {
|
|
||||||
|
|
||||||
private final boolean valid;
|
|
||||||
private final LatLng latLng;
|
|
||||||
private final double speed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for an invalid cached location.
|
|
||||||
*/
|
|
||||||
public CachedLocation() {
|
|
||||||
this.valid = false;
|
|
||||||
this.latLng = null;
|
|
||||||
this.speed = -1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for a potentially valid cached location.
|
|
||||||
*/
|
|
||||||
public CachedLocation(Location location) {
|
|
||||||
this.valid = LocationUtils.isValidLocation(location);
|
|
||||||
this.latLng = valid ? new LatLng(location.getLatitude(), location.getLongitude()) : null;
|
|
||||||
this.speed = location.hasSpeed() ? location.getSpeed() * UnitConversions.MS_TO_KMH : -1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the location is valid.
|
|
||||||
*/
|
|
||||||
public boolean isValid() {
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the speed in kilometers per hour.
|
|
||||||
*/
|
|
||||||
public double getSpeed() {
|
|
||||||
return speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the LatLng.
|
|
||||||
*/
|
|
||||||
public LatLng getLatLng() {
|
|
||||||
return latLng;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public MapOverlay(Context context) {
|
|
||||||
this.context = context;
|
|
||||||
this.waypoints = new ArrayList<Waypoint>();
|
|
||||||
this.locations = new ArrayList<CachedLocation>(INITIAL_LOCATIONS_SIZE);
|
|
||||||
|
|
||||||
// Set the number of points to be 2x the TARGET_DISPLAYED_TRACK_POINTS
|
|
||||||
this.pendingLocations = new ArrayBlockingQueue<CachedLocation>(
|
|
||||||
2 * TARGET_DISPLAYED_TRACK_POINTS, true);
|
|
||||||
|
|
||||||
context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE)
|
|
||||||
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
|
||||||
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a location.
|
|
||||||
*
|
|
||||||
* @param location the location
|
|
||||||
*/
|
|
||||||
public void addLocation(Location location) {
|
|
||||||
// Queue up in the pendingLocations until it's merged with locations
|
|
||||||
if (!pendingLocations.offer(new CachedLocation(location))) {
|
|
||||||
Log.e(TAG, "Unable to add to pendingLocations.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a segment split.
|
|
||||||
*/
|
|
||||||
public void addSegmentSplit() {
|
|
||||||
// Queue up in the pendingLocations until it's merged with locations
|
|
||||||
if (!pendingLocations.offer(new CachedLocation())) {
|
|
||||||
Log.e(TAG, "Unable to add to pendingLocations.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the locations.
|
|
||||||
*/
|
|
||||||
public void clearPoints() {
|
|
||||||
synchronized (locations) {
|
|
||||||
locations.clear();
|
|
||||||
pendingLocations.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a waypoint.
|
|
||||||
*
|
|
||||||
* @param waypoint the waypoint
|
|
||||||
*/
|
|
||||||
public void addWaypoint(Waypoint waypoint) {
|
|
||||||
synchronized (waypoints) {
|
|
||||||
waypoints.add(waypoint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the waypoints.
|
|
||||||
*/
|
|
||||||
public void clearWaypoints() {
|
|
||||||
synchronized (waypoints) {
|
|
||||||
waypoints.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether to show the end marker.
|
|
||||||
*
|
|
||||||
* @param show true to show the end marker
|
|
||||||
*/
|
|
||||||
public void setShowEndMarker(boolean show) {
|
|
||||||
showEndMarker = show;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the track, start and end markers, and waypoints.
|
|
||||||
*
|
|
||||||
* @param googleMap the google map
|
|
||||||
* @param paths the paths
|
|
||||||
* @param tripStatistics the trip statistics
|
|
||||||
* @param reload true to reload all points
|
|
||||||
* @return true if has the start marker
|
|
||||||
*/
|
|
||||||
public boolean update(GoogleMap googleMap, ArrayList<Polyline> paths,
|
|
||||||
TripStatistics tripStatistics, boolean reload) {
|
|
||||||
synchronized (locations) {
|
|
||||||
boolean hasStartMarker = false;
|
|
||||||
// Merge pendingLocations with locations
|
|
||||||
int newLocations = pendingLocations.drainTo(locations);
|
|
||||||
// Call updateState first because we want to update its state each time
|
|
||||||
// (for dynamic coloring)
|
|
||||||
if (trackPath.updateState(tripStatistics) || reload) {
|
|
||||||
googleMap.clear();
|
|
||||||
paths.clear();
|
|
||||||
trackPath.updatePath(googleMap, paths, 0, locations);
|
|
||||||
hasStartMarker = updateStartAndEndMarkers(googleMap);
|
|
||||||
updateWaypoints(googleMap);
|
|
||||||
} else {
|
|
||||||
if (newLocations != 0) {
|
|
||||||
int numLocations = locations.size();
|
|
||||||
trackPath.updatePath(googleMap, paths, numLocations - newLocations, locations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hasStartMarker;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the start and end markers.
|
|
||||||
*
|
|
||||||
* @param googleMap the google map
|
|
||||||
* @return true if has the start marker
|
|
||||||
*/
|
|
||||||
private boolean updateStartAndEndMarkers(GoogleMap googleMap) {
|
|
||||||
// Add the end marker
|
|
||||||
if (showEndMarker) {
|
|
||||||
for (int i = locations.size() - 1; i >= 0; i--) {
|
|
||||||
CachedLocation cachedLocation = locations.get(i);
|
|
||||||
if (cachedLocation.valid) {
|
|
||||||
MarkerOptions markerOptions = new MarkerOptions().position(cachedLocation.getLatLng())
|
|
||||||
.anchor(MARKER_X_ANCHOR, MARKER_Y_ANCHOR).draggable(false).visible(true)
|
|
||||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker_red_paddle));
|
|
||||||
googleMap.addMarker(markerOptions);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the start marker
|
|
||||||
boolean hasStartMarker = false;
|
|
||||||
for (int i = 0; i < locations.size(); i++) {
|
|
||||||
CachedLocation cachedLocation = locations.get(i);
|
|
||||||
if (cachedLocation.valid) {
|
|
||||||
MarkerOptions markerOptions = new MarkerOptions().position(cachedLocation.getLatLng())
|
|
||||||
.anchor(MARKER_X_ANCHOR, MARKER_Y_ANCHOR).draggable(false).visible(true)
|
|
||||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker_green_paddle));
|
|
||||||
googleMap.addMarker(markerOptions);
|
|
||||||
hasStartMarker = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hasStartMarker;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the waypoints.
|
|
||||||
*
|
|
||||||
* @param googleMap the google map.
|
|
||||||
*/
|
|
||||||
private void updateWaypoints(GoogleMap googleMap) {
|
|
||||||
synchronized (waypoints) {
|
|
||||||
for (Waypoint waypoint : waypoints) {
|
|
||||||
Location location = waypoint.getLocation();
|
|
||||||
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
|
|
||||||
int drawableId = waypoint.getType() == WaypointType.STATISTICS
|
|
||||||
? R.drawable.ic_marker_yellow_pushpin : R.drawable.ic_marker_blue_pushpin;
|
|
||||||
MarkerOptions markerOptions = new MarkerOptions().position(latLng)
|
|
||||||
.anchor(WAYPOINT_X_ANCHOR, WAYPOINT_Y_ANCHOR).draggable(false).visible(true)
|
|
||||||
.icon(BitmapDescriptorFactory.fromResource(drawableId))
|
|
||||||
.title(String.valueOf(waypoint.getId()));
|
|
||||||
googleMap.addMarker(markerOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-142
@@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 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 android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A dynamic speed path descriptor.
|
|
||||||
*
|
|
||||||
* @author Vangelis S.
|
|
||||||
*/
|
|
||||||
public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor {
|
|
||||||
|
|
||||||
private final OnSharedPreferenceChangeListener
|
|
||||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.track_color_mode_percentage_key))) {
|
|
||||||
speedMargin = PreferencesUtils.getInt(context, R.string.track_color_mode_percentage_key,
|
|
||||||
PreferencesUtils.TRACK_COLOR_MODE_PERCENTAGE_DEFAULT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
private int speedMargin;
|
|
||||||
private double slowSpeed;
|
|
||||||
private double normalSpeed;
|
|
||||||
private double averageMovingSpeed;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int CRITICAL_DIFFERENCE_PERCENTAGE = 20;
|
|
||||||
|
|
||||||
public DynamicSpeedTrackPathDescriptor(Context context) {
|
|
||||||
this.context = context;
|
|
||||||
context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE)
|
|
||||||
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
|
||||||
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getSlowSpeed() {
|
|
||||||
slowSpeed = averageMovingSpeed - (averageMovingSpeed * speedMargin / 100.0);
|
|
||||||
return slowSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getNormalSpeed() {
|
|
||||||
normalSpeed = averageMovingSpeed + (averageMovingSpeed * speedMargin / 100.0);
|
|
||||||
return normalSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean updateState(TripStatistics tripStatistics) {
|
|
||||||
double newAverageMovingSpeed = (int) Math.floor(
|
|
||||||
tripStatistics.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH);
|
|
||||||
|
|
||||||
if (isDifferenceSignificant(averageMovingSpeed, newAverageMovingSpeed)) {
|
|
||||||
averageMovingSpeed = newAverageMovingSpeed;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the average moving speed and the new average moving speed
|
|
||||||
* are significantly different.
|
|
||||||
*
|
|
||||||
* @param oldAverageMovingSpeed
|
|
||||||
* @param newAverageMovingSpeed
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
boolean isDifferenceSignificant(double oldAverageMovingSpeed, double newAverageMovingSpeed) {
|
|
||||||
if (oldAverageMovingSpeed == 0) {
|
|
||||||
return newAverageMovingSpeed != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Here, both oldAverageMovingSpeed and newAverageMovingSpeed are not zero.
|
|
||||||
double maxValue = Math.max(oldAverageMovingSpeed, newAverageMovingSpeed);
|
|
||||||
double differencePercentage = Math.abs(oldAverageMovingSpeed - newAverageMovingSpeed) / maxValue
|
|
||||||
* 100.0;
|
|
||||||
return differencePercentage >= CRITICAL_DIFFERENCE_PERCENTAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the speed margin.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
int getSpeedMargin() {
|
|
||||||
return speedMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the speed margin.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void setSpeedMargin(int value) {
|
|
||||||
speedMargin = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the average moving speed.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
double getAverageMovingSpeed() {
|
|
||||||
return averageMovingSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the average moving speed.
|
|
||||||
*
|
|
||||||
* @param value the value
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void setAverageMovingSpeed(double value) {
|
|
||||||
averageMovingSpeed = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-101
@@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 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.Constants;
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A fixed speed path descriptor.
|
|
||||||
*
|
|
||||||
* @author Vangelis S.
|
|
||||||
*/
|
|
||||||
public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor {
|
|
||||||
|
|
||||||
private final OnSharedPreferenceChangeListener
|
|
||||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
||||||
boolean updateSlowSpeed = false;
|
|
||||||
boolean updateNormalSpeed = false;
|
|
||||||
if (key == null
|
|
||||||
|| key.equals(PreferencesUtils.getKey(context, R.string.track_color_mode_slow_key))) {
|
|
||||||
updateSlowSpeed = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (key == null || key.equals(
|
|
||||||
PreferencesUtils.getKey(context, R.string.track_color_mode_medium_key))) {
|
|
||||||
updateNormalSpeed = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (key == null
|
|
||||||
|| key.equals(PreferencesUtils.getKey(context, R.string.stats_units_key))) {
|
|
||||||
updateSlowSpeed = true;
|
|
||||||
updateNormalSpeed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateSlowSpeed) {
|
|
||||||
slowSpeed = PreferencesUtils.getInt(context, R.string.track_color_mode_slow_key,
|
|
||||||
PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT);
|
|
||||||
if (!PreferencesUtils.isMetricUnits(context)) {
|
|
||||||
slowSpeed = slowSpeed * UnitConversions.MI_TO_KM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateNormalSpeed) {
|
|
||||||
normalSpeed = PreferencesUtils.getInt(context, R.string.track_color_mode_medium_key,
|
|
||||||
PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT);
|
|
||||||
if (!PreferencesUtils.isMetricUnits(context)) {
|
|
||||||
normalSpeed = normalSpeed * UnitConversions.MI_TO_KM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
private double slowSpeed;
|
|
||||||
private double normalSpeed;
|
|
||||||
|
|
||||||
public FixedSpeedTrackPathDescriptor(Context context) {
|
|
||||||
this.context = context;
|
|
||||||
context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE)
|
|
||||||
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
|
||||||
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getSlowSpeed() {
|
|
||||||
return slowSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getNormalSpeed() {
|
|
||||||
return normalSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean updateState(TripStatistics tripStatistics) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-132
@@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 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 android.content.Context;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.MapOverlay.CachedLocation;
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
|
||||||
import com.google.android.gms.maps.GoogleMap;
|
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
|
||||||
import com.google.android.gms.maps.model.Polyline;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
public class MultiColorTrackPath implements TrackPath {
|
|
||||||
private final TrackPathDescriptor trackPathDescriptor;
|
|
||||||
private final int slowColor;
|
|
||||||
private final int normalColor;
|
|
||||||
private final int fastColor;
|
|
||||||
|
|
||||||
public MultiColorTrackPath(Context context, TrackPathDescriptor trackPathDescriptor) {
|
|
||||||
this.trackPathDescriptor = trackPathDescriptor;
|
|
||||||
slowColor = context.getResources().getColor(R.color.track_color_slow);
|
|
||||||
normalColor = context.getResources().getColor(R.color.track_color_normal);
|
|
||||||
fastColor = context.getResources().getColor(R.color.track_color_fast);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean updateState(TripStatistics tripStatistics) {
|
|
||||||
return trackPathDescriptor.updateState(tripStatistics);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updatePath(GoogleMap googleMap, ArrayList<Polyline> paths, int startIndex,
|
|
||||||
List<CachedLocation> locations) {
|
|
||||||
if (googleMap == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (startIndex >= locations.size()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean newSegment = startIndex == 0 || !locations.get(startIndex - 1).isValid();
|
|
||||||
LatLng lastLatLng = startIndex != 0 ? locations.get(startIndex -1).getLatLng() : null;
|
|
||||||
|
|
||||||
ArrayList<LatLng> lastSegmentPoints = new ArrayList<LatLng>();
|
|
||||||
int lastSegmentColor = paths.size() != 0 ? paths.get(paths.size() - 1).getColor() : slowColor;
|
|
||||||
boolean useLastPolyline = true;
|
|
||||||
|
|
||||||
for (int i = startIndex; i < locations.size(); ++i) {
|
|
||||||
CachedLocation cachedLocation = locations.get(i);
|
|
||||||
|
|
||||||
// If not valid, start a new segment
|
|
||||||
if (!cachedLocation.isValid()) {
|
|
||||||
newSegment = true;
|
|
||||||
lastLatLng = null;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
LatLng latLng = cachedLocation.getLatLng();
|
|
||||||
int color = getColor(cachedLocation.getSpeed());
|
|
||||||
|
|
||||||
// Either update point or draw a line from the last point
|
|
||||||
if (newSegment) {
|
|
||||||
TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, lastSegmentColor, useLastPolyline);
|
|
||||||
useLastPolyline = false;
|
|
||||||
lastSegmentColor = color;
|
|
||||||
newSegment = false;
|
|
||||||
}
|
|
||||||
if (lastSegmentColor == color) {
|
|
||||||
lastSegmentPoints.add(latLng);
|
|
||||||
} else {
|
|
||||||
TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, lastSegmentColor, useLastPolyline);
|
|
||||||
useLastPolyline = false;
|
|
||||||
if (lastLatLng != null) {
|
|
||||||
lastSegmentPoints.add(lastLatLng);
|
|
||||||
}
|
|
||||||
lastSegmentPoints.add(latLng);
|
|
||||||
lastSegmentColor = color;
|
|
||||||
}
|
|
||||||
lastLatLng = latLng;
|
|
||||||
}
|
|
||||||
TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, lastSegmentColor, useLastPolyline);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected int getColor(double speed) {
|
|
||||||
if (speed <= trackPathDescriptor.getSlowSpeed()) {
|
|
||||||
return slowColor;
|
|
||||||
} else if (speed <= trackPathDescriptor.getNormalSpeed()) {
|
|
||||||
return normalColor;
|
|
||||||
} else {
|
|
||||||
return fastColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected int getSlowColor() {
|
|
||||||
return slowColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected int getNormalColor() {
|
|
||||||
return normalColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected int getFastColor() {
|
|
||||||
return fastColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-79
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 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.MapOverlay.CachedLocation;
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
|
||||||
import com.google.android.gms.maps.GoogleMap;
|
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
|
||||||
import com.google.android.gms.maps.model.Polyline;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A single color track path.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
public class SingleColorTrackPath implements TrackPath {
|
|
||||||
|
|
||||||
final int color;
|
|
||||||
|
|
||||||
public SingleColorTrackPath(Context context) {
|
|
||||||
color = context.getResources().getColor(R.color.track_color_fast);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean updateState(TripStatistics tripStatistics) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updatePath(GoogleMap googleMap, ArrayList<Polyline> paths, int startIndex,
|
|
||||||
List<CachedLocation> locations) {
|
|
||||||
if (googleMap == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (startIndex >= locations.size()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean newSegment = startIndex == 0 || !locations.get(startIndex - 1).isValid();
|
|
||||||
ArrayList<LatLng> lastSegmentPoints = new ArrayList<LatLng>();
|
|
||||||
boolean useLastPolyline = true;
|
|
||||||
for (int i = startIndex; i < locations.size(); i++) {
|
|
||||||
CachedLocation cachedLocation = locations.get(i);
|
|
||||||
|
|
||||||
// If not valid, start a new segment
|
|
||||||
if (!cachedLocation.isValid()) {
|
|
||||||
newSegment = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
LatLng latLng = cachedLocation.getLatLng();
|
|
||||||
if (newSegment) {
|
|
||||||
TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, color, useLastPolyline);
|
|
||||||
useLastPolyline = false;
|
|
||||||
newSegment = false;
|
|
||||||
}
|
|
||||||
lastSegmentPoints.add(latLng);
|
|
||||||
}
|
|
||||||
TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, color, useLastPolyline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 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.MapOverlay.CachedLocation;
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
|
||||||
import com.google.android.gms.maps.GoogleMap;
|
|
||||||
import com.google.android.gms.maps.model.Polyline;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A track path.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
public interface TrackPath {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates state.
|
|
||||||
*
|
|
||||||
* @param tripStatistics the trip statistics
|
|
||||||
* @return true if the state is updated.
|
|
||||||
*/
|
|
||||||
public boolean updateState(TripStatistics tripStatistics);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the path.
|
|
||||||
*
|
|
||||||
* @param startIndex the start index
|
|
||||||
* @param points the points
|
|
||||||
*/
|
|
||||||
public void updatePath(GoogleMap googleMap, ArrayList<Polyline> paths, int startIndex,
|
|
||||||
List<CachedLocation> points);
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 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.stats.TripStatistics;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface for classes which describe how to draw a track path.
|
|
||||||
*
|
|
||||||
* @author Vangelis S.
|
|
||||||
*/
|
|
||||||
public interface TrackPathDescriptor {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the maximum speed which is considered slow.
|
|
||||||
*/
|
|
||||||
public double getSlowSpeed();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the maximum speed which is considered normal.
|
|
||||||
*/
|
|
||||||
public double getNormalSpeed();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates state.
|
|
||||||
*
|
|
||||||
* @param tripstatistics the trip statistics
|
|
||||||
* @return true if the state is updated.
|
|
||||||
*/
|
|
||||||
public boolean updateState(TripStatistics tripstatistics);
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 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.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A factory for {@link TrackPath}.
|
|
||||||
*
|
|
||||||
* @author Vangelis S.
|
|
||||||
*/
|
|
||||||
public class TrackPathFactory {
|
|
||||||
|
|
||||||
private TrackPathFactory() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a new {@link TrackPath}.
|
|
||||||
*
|
|
||||||
* @param context the context
|
|
||||||
*/
|
|
||||||
public static TrackPath getTrackPath(Context context, String trackColorMode) {
|
|
||||||
if (context.getString(R.string.settings_map_track_color_mode_dynamic_value)
|
|
||||||
.equals(trackColorMode)) {
|
|
||||||
return new MultiColorTrackPath(context, new DynamicSpeedTrackPathDescriptor(context));
|
|
||||||
} else if (context.getString(R.string.settings_map_track_color_mode_fixed_value)
|
|
||||||
.equals(trackColorMode)) {
|
|
||||||
return new MultiColorTrackPath(context, new FixedSpeedTrackPathDescriptor(context));
|
|
||||||
} else {
|
|
||||||
return new SingleColorTrackPath(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 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.gms.maps.GoogleMap;
|
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
|
||||||
import com.google.android.gms.maps.model.Polyline;
|
|
||||||
import com.google.android.gms.maps.model.PolylineOptions;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Various utility functions for track path painting.
|
|
||||||
*
|
|
||||||
* @author Vangelis S.
|
|
||||||
*/
|
|
||||||
public class TrackPathUtils {
|
|
||||||
|
|
||||||
private TrackPathUtils() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a path.
|
|
||||||
*
|
|
||||||
* @param googleMap the google map
|
|
||||||
* @param paths the existing paths
|
|
||||||
* @param points the path points
|
|
||||||
* @param color the path color
|
|
||||||
* @param append true to append to the last path
|
|
||||||
*/
|
|
||||||
public static void addPath(GoogleMap googleMap, ArrayList<Polyline> paths,
|
|
||||||
ArrayList<LatLng> points, int color, boolean append) {
|
|
||||||
if (points.size() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (append && paths.size() != 0) {
|
|
||||||
Polyline lastPolyline = paths.get(paths.size() - 1);
|
|
||||||
ArrayList<LatLng> pathPoints = new ArrayList<LatLng>();
|
|
||||||
pathPoints.addAll(lastPolyline.getPoints());
|
|
||||||
pathPoints.addAll(points);
|
|
||||||
lastPolyline.setPoints(pathPoints);
|
|
||||||
} else {
|
|
||||||
PolylineOptions polylineOptions = new PolylineOptions().addAll(points).width(5).color(color);
|
|
||||||
Polyline polyline = googleMap.addPolyline(polylineOptions);
|
|
||||||
paths.add(polyline);
|
|
||||||
}
|
|
||||||
points.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user