Merge pull request #720 from Bars107/master
RoutePointsPlugin: added functionality to package as delivered/not delivered.
This commit is contained in:
commit
9485a92039
6 changed files with 154 additions and 48 deletions
25
OsmAnd/res/layout/package_delivered.xml
Normal file
25
OsmAnd/res/layout/package_delivered.xml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/color_black">
|
||||||
|
<TextView android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:text="@string/package_delivered"/>
|
||||||
|
<Button android:id="@+id/delivered_yes"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:text="@string/default_buttons_yes"/>
|
||||||
|
<Button android:id="@+id/delivered_no"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:text="@string/default_buttons_no"/>
|
||||||
|
</LinearLayout>
|
|
@ -12,4 +12,5 @@
|
||||||
<string name="map_widget_route_points">Route points</string>
|
<string name="map_widget_route_points">Route points</string>
|
||||||
<string name="route_points_activity">Route Points</string>
|
<string name="route_points_activity">Route Points</string>
|
||||||
<string name="navigate_dialog">Navigate dialog</string>
|
<string name="navigate_dialog">Navigate dialog</string>
|
||||||
|
<string name="package_delivered">Was the package delivered?</string>
|
||||||
</resources>
|
</resources>
|
|
@ -711,4 +711,8 @@ public class MapActivity extends AccessibleActivity {
|
||||||
public void refreshMap() {
|
public void refreshMap() {
|
||||||
getMapView().refreshMap();
|
getMapView().refreshMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public View getLayout() {
|
||||||
|
return getWindow().getDecorView().findViewById(android.R.id.content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,11 @@ public class RoutePointsActivity extends OsmandListActivity {
|
||||||
|
|
||||||
if (point.isVisited()) {
|
if (point.isVisited()) {
|
||||||
holder.image.setImageResource(R.drawable.ic_action_ok_dark);
|
holder.image.setImageResource(R.drawable.ic_action_ok_dark);
|
||||||
|
if (point.isDelivered()){
|
||||||
holder.name.setTextColor(getResources().getColor(R.color.osmbug_closed));
|
holder.name.setTextColor(getResources().getColor(R.color.osmbug_closed));
|
||||||
|
} else {
|
||||||
|
holder.name.setTextColor(getResources().getColor(R.color.color_invalid));
|
||||||
|
}
|
||||||
holder.dateOrDistance.setTextColor(getResources().getColor(R.color.color_unknown));
|
holder.dateOrDistance.setTextColor(getResources().getColor(R.color.color_unknown));
|
||||||
holder.dateOrDistance.setText(point.getTime());
|
holder.dateOrDistance.setText(point.getTime());
|
||||||
holder.dateOrDistance.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
holder.dateOrDistance.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
||||||
|
@ -273,7 +277,13 @@ public class RoutePointsActivity extends OsmandListActivity {
|
||||||
finish();
|
finish();
|
||||||
} else if (menuItem.getItemId() == AS_VISITED_ID) {
|
} else if (menuItem.getItemId() == AS_VISITED_ID) {
|
||||||
// inverts selection state of item
|
// inverts selection state of item
|
||||||
|
if (!rp.isVisited()){
|
||||||
|
rp.setDelivered(true);
|
||||||
|
} else if (rp.isDelivered()){
|
||||||
|
rp.setDelivered(false);
|
||||||
|
}
|
||||||
plugin.getCurrentRoute().markPoint(rp, !rp.isVisited());
|
plugin.getCurrentRoute().markPoint(rp, !rp.isVisited());
|
||||||
|
|
||||||
saveGPXAsync();
|
saveGPXAsync();
|
||||||
prepareView();
|
prepareView();
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,17 +78,17 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye
|
||||||
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
if (itemId == R.string.mark_as_not_visited){
|
if (itemId == R.string.mark_as_not_visited){
|
||||||
plugin.getCurrentRoute().markPoint(point,false);
|
plugin.getCurrentRoute().markPoint(point,false);
|
||||||
plugin.saveGPXAsync();
|
plugin.saveCurrentRoute();
|
||||||
} else if (itemId == R.string.mark_as_visited) {
|
} else if (itemId == R.string.mark_as_visited) {
|
||||||
plugin.getCurrentRoute().markPoint(point, true);
|
plugin.getCurrentRoute().markPoint(point, true);
|
||||||
plugin.saveGPXAsync();
|
plugin.saveCurrentRoute();
|
||||||
} else if (itemId == R.string.mark_as_current){
|
} else if (itemId == R.string.mark_as_current){
|
||||||
plugin.getCurrentRoute().markPoint(point, false);
|
plugin.getCurrentRoute().markPoint(point, false);
|
||||||
plugin.getCurrentRoute().navigateToPoint(point);
|
plugin.getCurrentRoute().navigateToPoint(point);
|
||||||
plugin.saveGPXAsync();
|
plugin.saveCurrentRoute();
|
||||||
} else if (itemId == R.string.navigate_to_next){
|
} else if (itemId == R.string.navigate_to_next){
|
||||||
plugin.getCurrentRoute().navigateToNextPoint();
|
plugin.getCurrentRoute().navigateToNextPoint();
|
||||||
plugin.saveGPXAsync();
|
plugin.saveCurrentRoute();
|
||||||
}
|
}
|
||||||
map.refreshMap();
|
map.refreshMap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package net.osmand.plus.routepointsnavigation;
|
package net.osmand.plus.routepointsnavigation;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
import android.app.ActionBar;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
|
@ -38,11 +40,15 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
public static final String ID = "osmand.route.stepsPlugin";
|
public static final String ID = "osmand.route.stepsPlugin";
|
||||||
|
|
||||||
private static final String VISITED_KEY = "VISITED_KEY";
|
private static final String VISITED_KEY = "VISITED_KEY";
|
||||||
|
private static final String DELIVERED_KEY = "DELIVERED_KEY";
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private TextInfoWidget routeStepsControl;
|
private TextInfoWidget routeStepsControl;
|
||||||
private SelectedRouteGpxFile currentRoute;
|
private SelectedRouteGpxFile currentRoute;
|
||||||
|
|
||||||
|
private View deliveredView;
|
||||||
|
private MapActivity mapActivity;
|
||||||
|
|
||||||
private RoutePointsLayer routePointsLayer;
|
private RoutePointsLayer routePointsLayer;
|
||||||
|
|
||||||
public RoutePointsPlugin(OsmandApplication app) {
|
public RoutePointsPlugin(OsmandApplication app) {
|
||||||
|
@ -63,16 +69,43 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void prepareDeliveredView() {
|
||||||
|
LayoutInflater vi = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
deliveredView = vi.inflate(R.layout.package_delivered, null);
|
||||||
|
|
||||||
|
Button btnY = (Button) deliveredView.findViewById(R.id.delivered_yes);
|
||||||
|
|
||||||
|
btnY.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
currentRoute.navigateToNextPoint(true);
|
||||||
|
FrameLayout layout = (FrameLayout) mapActivity.getLayout();
|
||||||
|
layout.removeView(deliveredView);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Button btnN = (Button) deliveredView.findViewById(R.id.delivered_no);
|
||||||
|
|
||||||
|
btnN.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
currentRoute.navigateToNextPoint(false);
|
||||||
|
FrameLayout layout = (FrameLayout) mapActivity.getLayout();
|
||||||
|
layout.removeView(deliveredView);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean destinationReached() {
|
public boolean destinationReached() {
|
||||||
if (currentRoute != null) {
|
if (currentRoute != null) {
|
||||||
boolean naviateToNextPoint = currentRoute.navigateToNextPoint();
|
FrameLayout layout = (FrameLayout) mapActivity.getLayout();
|
||||||
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
||||||
|
layout.addView(deliveredView, params);
|
||||||
|
}
|
||||||
|
|
||||||
if (naviateToNextPoint) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +142,8 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void registerLayers(MapActivity activity) {
|
public void registerLayers(MapActivity activity) {
|
||||||
super.registerLayers(activity);
|
super.registerLayers(activity);
|
||||||
|
mapActivity = activity;
|
||||||
|
prepareDeliveredView();
|
||||||
if (routePointsLayer != null) {
|
if (routePointsLayer != null) {
|
||||||
activity.getMapView().removeLayer(routePointsLayer);
|
activity.getMapView().removeLayer(routePointsLayer);
|
||||||
}
|
}
|
||||||
|
@ -139,6 +173,12 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveCurrentRoute(){
|
||||||
|
if (currentRoute != null){
|
||||||
|
currentRoute.saveGPXAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private TextInfoWidget createRouteStepsInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) {
|
private TextInfoWidget createRouteStepsInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) {
|
||||||
TextInfoWidget routeStepsControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
|
TextInfoWidget routeStepsControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
|
||||||
|
|
||||||
|
@ -172,6 +212,7 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
int gpxOrder;
|
int gpxOrder;
|
||||||
long visitedTime; // 0 not visited
|
long visitedTime; // 0 not visited
|
||||||
WptPt wpt;
|
WptPt wpt;
|
||||||
|
boolean delivered;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return wpt.name;
|
return wpt.name;
|
||||||
|
@ -189,6 +230,8 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
return visitedTime != 0;
|
return visitedTime != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDelivered() { return delivered;}
|
||||||
|
|
||||||
public int getGpxOrder() {
|
public int getGpxOrder() {
|
||||||
return gpxOrder;
|
return gpxOrder;
|
||||||
}
|
}
|
||||||
|
@ -216,6 +259,11 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
return new LatLon(wpt.lat, wpt.lon);
|
return new LatLon(wpt.lat, wpt.lon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDelivered(boolean d) {
|
||||||
|
wpt.getExtensionsToWrite().put(DELIVERED_KEY, String.valueOf(d));
|
||||||
|
this.delivered = d;
|
||||||
|
}
|
||||||
|
|
||||||
public void setVisitedTime(long currentTimeMillis) {
|
public void setVisitedTime(long currentTimeMillis) {
|
||||||
visitedTime = currentTimeMillis;
|
visitedTime = currentTimeMillis;
|
||||||
wpt.getExtensionsToWrite().put(VISITED_KEY, visitedTime + "");
|
wpt.getExtensionsToWrite().put(VISITED_KEY, visitedTime + "");
|
||||||
|
@ -227,7 +275,6 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
private GPXUtilities.GPXFile gpx;
|
private GPXUtilities.GPXFile gpx;
|
||||||
private List<RoutePoint> currentPoints = new ArrayList<RoutePointsPlugin.RoutePoint>();
|
private List<RoutePoint> currentPoints = new ArrayList<RoutePointsPlugin.RoutePoint>();
|
||||||
|
|
||||||
|
|
||||||
public SelectedRouteGpxFile(GPXUtilities.GPXFile gpx) {
|
public SelectedRouteGpxFile(GPXUtilities.GPXFile gpx) {
|
||||||
this.gpx = gpx;
|
this.gpx = gpx;
|
||||||
parseGPXFile(gpx);
|
parseGPXFile(gpx);
|
||||||
|
@ -276,13 +323,17 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean navigateToNextPoint() {
|
public boolean navigateToNextPoint() {
|
||||||
if (!currentPoints.isEmpty()) {
|
if (currentPoints.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
RoutePoint rp = currentPoints.get(0);
|
RoutePoint rp = currentPoints.get(0);
|
||||||
if (rp.isNextNavigate) {
|
if (rp.isNextNavigate) {
|
||||||
rp.setVisitedTime(System.currentTimeMillis());
|
rp.setVisitedTime(System.currentTimeMillis());
|
||||||
rp.isNextNavigate = false;
|
rp.isNextNavigate = false;
|
||||||
sortPoints();
|
sortPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
RoutePoint first = currentPoints.get(0);
|
RoutePoint first = currentPoints.get(0);
|
||||||
if (!first.isVisited()) {
|
if (!first.isVisited()) {
|
||||||
app.getTargetPointsHelper().navigateToPoint(first.getPoint(), true, -1, first.getName());
|
app.getTargetPointsHelper().navigateToPoint(first.getPoint(), true, -1, first.getName());
|
||||||
|
@ -291,8 +342,8 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
} else {
|
} else {
|
||||||
app.getTargetPointsHelper().clearPointToNavigate(true);
|
app.getTargetPointsHelper().clearPointToNavigate(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sortPoints() {
|
private void sortPoints() {
|
||||||
|
@ -334,6 +385,9 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
RoutePoint rtp = new RoutePoint();
|
RoutePoint rtp = new RoutePoint();
|
||||||
rtp.gpxOrder = i;
|
rtp.gpxOrder = i;
|
||||||
rtp.wpt = wptPt;
|
rtp.wpt = wptPt;
|
||||||
|
String delivered = wptPt.getExtensionsToRead().get(DELIVERED_KEY);
|
||||||
|
rtp.delivered = Boolean.parseBoolean(delivered);
|
||||||
|
|
||||||
String time = wptPt.getExtensionsToRead().get(VISITED_KEY);
|
String time = wptPt.getExtensionsToRead().get(VISITED_KEY);
|
||||||
try {
|
try {
|
||||||
rtp.visitedTime = Long.parseLong(time);
|
rtp.visitedTime = Long.parseLong(time);
|
||||||
|
@ -408,6 +462,19 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean navigateToNextPoint(boolean delivered) {
|
||||||
|
if (currentPoints.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoutePoint rp = currentPoints.get(0);
|
||||||
|
if (rp.isNextNavigate) {
|
||||||
|
rp.setDelivered(delivered);
|
||||||
|
return navigateToNextPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveGPXAsync() {
|
public void saveGPXAsync() {
|
||||||
|
@ -418,9 +485,7 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(RoutePointsPlugin.SelectedRouteGpxFile... params) {
|
protected Void doInBackground(RoutePointsPlugin.SelectedRouteGpxFile... params) {
|
||||||
if(getCurrentRoute() != null) {
|
saveFile();
|
||||||
getCurrentRoute().saveFile();
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,3 +494,4 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
||||||
}.execute(getCurrentRoute());
|
}.execute(getCurrentRoute());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue