Merge pull request #706 from Bars107/master

Added routepoints layer.
This commit is contained in:
vshcherb 2014-06-20 18:36:29 +02:00
commit ef62639d37
10 changed files with 239 additions and 57 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B

View file

@ -24,6 +24,7 @@
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
style="@style/OsmandListView"/>

View file

@ -8,6 +8,7 @@
<string name="mark_as_visited">Mark as visited</string>
<string name="mark_as_not_visited">Mark as not-visited</string>
<string name="mark_as_current">Navigate to</string>
<string name="navigate_to_next">Navigate to next point</string>
<string name="map_widget_route_points">Route points</string>
<string name="route_points_activity">Route Points</string>
<string name="navigate_dialog">Navigate dialog</string>

View file

@ -132,6 +132,7 @@ public class RoutePointsActivity extends OsmandListActivity {
super.onListItemClick(l, v, position, id);
RoutePoint rp = adapter.getItem(position);
getSherlock().startActionMode(getPointActionModeCallback(rp));
adapter.notifyDataSetChanged();
}
private class PointItemAdapter extends ArrayAdapter<RoutePoint> {
@ -262,6 +263,7 @@ public class RoutePointsActivity extends OsmandListActivity {
@Override
public void onDestroyActionMode(ActionMode actionMode) {
selectedItem = null;
adapter.notifyDataSetChanged();
}
};
}

View file

@ -0,0 +1,135 @@
package net.osmand.plus.routepointsnavigation;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.os.AsyncTask;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import java.util.List;
/**
* Created by Barsik on 20.06.2014.
*/
public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private final RoutePointsPlugin plugin;
private final MapActivity map;
public RoutePointsLayer(MapActivity map, RoutePointsPlugin plugin){
this.map = map;
this.plugin = plugin;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
}
@Override
public LatLon getObjectLocation(Object o) {
return null;
}
@Override
public String getObjectDescription(Object o) {
return null;
}
@Override
public String getObjectName(Object o) {
return null;
}
@Override
public void initLayer(OsmandMapTileView view) {
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return false;
}
@Override
public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
if (o instanceof GPXUtilities.WptPt && plugin.getCurrentRoute() != null){
final GPXUtilities.WptPt point = (GPXUtilities.WptPt) o;
ContextMenuAdapter.OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
if (itemId == R.string.mark_as_not_visited){
plugin.getCurrentRoute().markPoint(point,false);
saveGPXAsync();
} else if (itemId == R.string.mark_as_visited) {
plugin.getCurrentRoute().markPoint(point, true);
saveGPXAsync();
} else if (itemId == R.string.mark_as_current){
plugin.getCurrentRoute().markPoint(point, false);
plugin.getCurrentRoute().navigateToPoint(point);
saveGPXAsync();
} else if (itemId == R.string.navigate_to_next){
plugin.getCurrentRoute().naviateToNextPoint();
saveGPXAsync();
}
}
};
if (plugin.getCurrentRoute().getPointStatus(point)){
adapter.item(R.string.mark_as_not_visited).icons(
R.drawable.ic_action_gremove_dark, R.drawable.ic_action_gremove_light).listen(listener).reg();
} else {
adapter.item(R.string.mark_as_visited).icons(
R.drawable.ic_action_ok_dark, R.drawable.ic_action_ok_light).listen(listener).reg();
}
RoutePointsPlugin.RoutePoint routePoint = plugin.getCurrentRoute().getRoutePointFromWpt(point);
if (routePoint.isNextNavigate) {
adapter.item(R.string.navigate_to_next).icons(
R.drawable.ic_action_gnext_dark, R.drawable.ic_action_gnext_light).listen(listener).reg();
} else {
adapter.item(R.string.mark_as_current).icons(
R.drawable.ic_action_signpost_dark, R.drawable.ic_action_signpost_light).listen(listener).reg();
}
}
}
private void saveGPXAsync() {
new AsyncTask<RoutePointsPlugin.SelectedRouteGpxFile, Void, Void>() {
protected void onPreExecute() {
}
@Override
protected Void doInBackground(RoutePointsPlugin.SelectedRouteGpxFile... params) {
if(plugin.getCurrentRoute() != null) {
plugin.getCurrentRoute().saveFile();
}
return null;
}
protected void onPostExecute(Void result) {
}
}.execute(plugin.getCurrentRoute());
}
}

View file

@ -42,6 +42,8 @@ public class RoutePointsPlugin extends OsmandPlugin {
private TextInfoWidget routeStepsControl;
private SelectedRouteGpxFile currentRoute;
private RoutePointsLayer routePointsLayer;
public RoutePointsPlugin(OsmandApplication app) {
ApplicationMode.regWidget("route_steps", ApplicationMode.CAR, ApplicationMode.DEFAULT);
this.app = app;
@ -97,7 +99,7 @@ public class RoutePointsPlugin extends OsmandPlugin {
if (mapInfoLayer != null) {
routeStepsControl = createRouteStepsInfoControl(activity, mapInfoLayer.getPaintSubText(), mapInfoLayer.getPaintSubText());
mapInfoLayer.getMapInfoControls().registerSideWidget(routeStepsControl,
R.drawable.widget_target, R.string.map_widget_route_points, "route_steps", false, 8);
R.drawable.ic_signpost, R.string.map_widget_route_points, "route_steps", false, 8);
mapInfoLayer.recreateControls();
}
}
@ -105,11 +107,22 @@ public class RoutePointsPlugin extends OsmandPlugin {
@Override
public void registerLayers(MapActivity activity) {
super.registerLayers(activity);
if (routePointsLayer != null) {
activity.getMapView().removeLayer(routePointsLayer);
}
routePointsLayer = new RoutePointsLayer(activity, this);
activity.getMapView().addLayer(routePointsLayer, 5.5f);
registerWidget(activity);
}
@Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
if (routePointsLayer == null){
registerLayers(activity);
}
if (routeStepsControl == null) {
registerWidget(activity);
}
@ -143,7 +156,7 @@ public class RoutePointsPlugin extends OsmandPlugin {
}
});
routeStepsControl.setText(null, null);
routeStepsControl.setImageDrawable(map.getResources().getDrawable(R.drawable.widget_target));
routeStepsControl.setImageDrawable(map.getResources().getDrawable(R.drawable.ic_signpost));
return routeStepsControl;
}
@ -165,6 +178,7 @@ public class RoutePointsPlugin extends OsmandPlugin {
public boolean isNextNavigate() {
return isNextNavigate;
}
public boolean isVisited() {
return visitedTime != 0;
}
@ -358,6 +372,35 @@ public class RoutePointsPlugin extends OsmandPlugin {
sortPoints();
}
public boolean getPointStatus(WptPt p) {
RoutePoint point = getRoutePointFromWpt(p);
return point != null && (point.isVisited());
}
public void markPoint(WptPt point, boolean visited) {
RoutePoint routePoint = getRoutePointFromWpt(point);
if (routePoint != null) {
markPoint(routePoint, visited);
}
}
public void navigateToPoint(WptPt point) {
RoutePoint routePoint = getRoutePointFromWpt(point);
if (routePoint != null) {
navigateToPoint(routePoint);
}
}
public RoutePoint getRoutePointFromWpt(WptPt point) {
if (currentPoints != null) {
for (RoutePoint find : currentPoints) {
WptPt itemToFind = find.getWpt();
if (itemToFind.equals(point)) {
return find;
}
}
}
return null;
}
}
}