forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
@@ -228,8 +228,9 @@ public class TrackListActivity extends FragmentActivity {
|
||||
}
|
||||
};
|
||||
listView.setAdapter(adapter);
|
||||
ApiAdapterFactory.getApiAdapter().configureContextualMenu(this, listView,
|
||||
R.menu.track_list_context_menu, R.id.track_list_item_name, contextualActionModeCallback);
|
||||
ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(
|
||||
this, listView, R.menu.track_list_context_menu, R.id.track_list_item_name,
|
||||
contextualActionModeCallback);
|
||||
|
||||
getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() {
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ 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 com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
@@ -138,4 +139,14 @@ public class DynamicSpeedTrackPathPainter implements TrackPathPainter {
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns coloredPaths.
|
||||
*
|
||||
* @return coloredPaths
|
||||
*/
|
||||
@VisibleForTesting
|
||||
List<ColoredPath> getColoredPaths() {
|
||||
return coloredPaths;
|
||||
}
|
||||
}
|
||||
+35
-20
@@ -19,6 +19,7 @@ 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 com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
@@ -29,16 +30,15 @@ import android.graphics.Rect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* A path painter that not variates the path colors.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*/
|
||||
public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
private final Paint selectedTrackPaint;
|
||||
private Path path;
|
||||
|
||||
|
||||
public SingleColorTrackPathPainter(Context context) {
|
||||
selectedTrackPaint = TrackPathUtilities.getPaint(R.color.red, context);
|
||||
}
|
||||
@@ -47,49 +47,64 @@ public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
public void drawTrack(Canvas canvas) {
|
||||
canvas.drawPath(path, selectedTrackPaint);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updatePath(Projection projection, Rect viewRect, int startLocationIdx,
|
||||
Boolean alwaysVisible, List<CachedLocation> points) {
|
||||
path = new Path();
|
||||
updatePath(projection, viewRect, startLocationIdx, alwaysVisible, points, path);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 always visible.
|
||||
* @param points The list of points used to update the path.
|
||||
* @param pathToUpdate The path to be created.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void updatePath(Projection projection, Rect viewRect, int startLocationIdx,
|
||||
Boolean alwaysVisible, List<CachedLocation> points, Path pathToUpdate) {
|
||||
pathToUpdate.incReserve(points.size());
|
||||
// Whether to start a new segment on new valid and visible point.
|
||||
boolean newSegment = startLocationIdx <= 0 || !points.get(startLocationIdx - 1).valid;
|
||||
boolean newSegment = startLocationIdx <= 0 || !points.get(startLocationIdx - 1).valid;
|
||||
boolean lastVisible = !newSegment;
|
||||
final Point pt = new Point();
|
||||
// Loop over track points.
|
||||
int numPoints = points.size();
|
||||
path = newPath();
|
||||
path.incReserve(numPoints);
|
||||
|
||||
for (int i = startLocationIdx; i < numPoints ; ++i) {
|
||||
for (int i = startLocationIdx; i < points.size(); ++i) {
|
||||
CachedLocation loc = points.get(i);
|
||||
|
||||
|
||||
// Check if valid, if not then indicate a new segment.
|
||||
if (!loc.valid) {
|
||||
newSegment = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
final GeoPoint geoPoint = loc.geoPoint;
|
||||
// Check if this breaks the existing segment.
|
||||
boolean visible = alwaysVisible
|
||||
boolean visible = alwaysVisible
|
||||
|| viewRect.contains(geoPoint.getLongitudeE6(), geoPoint.getLatitudeE6());
|
||||
if (!visible && !lastVisible) {
|
||||
// This is a point outside view not connected to a visible one.
|
||||
newSegment = true;
|
||||
}
|
||||
lastVisible = visible;
|
||||
|
||||
|
||||
// Either move to beginning of a new segment or continue the old one.
|
||||
projection.toPixels(geoPoint, pt);
|
||||
if (newSegment) {
|
||||
path.moveTo(pt.x, pt.y);
|
||||
pathToUpdate.moveTo(pt.x, pt.y);
|
||||
newSegment = false;
|
||||
} else {
|
||||
path.lineTo(pt.x, pt.y);
|
||||
pathToUpdate.lineTo(pt.x, pt.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
path = null;
|
||||
@@ -99,12 +114,12 @@ public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
public boolean needsRedraw() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Path getLastPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// Visible for testing
|
||||
public Path newPath() {
|
||||
return new Path();
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Api11Adapter extends Api10Adapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureContextualMenu(final Activity activity, ListView listView, final int menuId,
|
||||
public void configureListViewContextualMenu(final Activity activity, ListView listView, final int menuId,
|
||||
final int actionModeTitleId,
|
||||
final ContextualActionModeCallback contextualActionModeCallback) {
|
||||
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
|
||||
|
||||
@@ -116,7 +116,7 @@ public class Api7Adapter implements ApiAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureContextualMenu(Activity activity, ListView listView, int menuId,
|
||||
public void configureListViewContextualMenu(Activity activity, ListView listView, int menuId,
|
||||
int actionModeTitleId, ContextualActionModeCallback contextualActionModeCallback) {
|
||||
activity.registerForContextMenu(listView);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public interface ApiAdapter {
|
||||
public void configureActionBarHomeAsUp(Activity activity);
|
||||
|
||||
/**
|
||||
* Configures the context menu.
|
||||
* Configures the list view context menu.
|
||||
* <p>
|
||||
* Due to changes in API level 11.
|
||||
*
|
||||
@@ -138,7 +138,7 @@ public interface ApiAdapter {
|
||||
* @param contextualActionModeCallback the callback when an item is selected
|
||||
* in the contextual action mode
|
||||
*/
|
||||
public void configureContextualMenu(Activity activity, ListView listView, int menuId,
|
||||
public void configureListViewContextualMenu(Activity activity, ListView listView, int menuId,
|
||||
int actionModeTitleId, ContextualActionModeCallback contextualActionModeCallback);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user