mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-05 11:03:06 +02:00
Suggested corrections made (Pending corrections in halt until getting response from the last revision comments i made)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+19
-16
@@ -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;
|
||||
}
|
||||
}
|
||||
+20
-11
@@ -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;
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -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(
|
||||
|
||||
+10
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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<CachedLocation> 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user