reformated code

This commit is contained in:
unknown 2014-06-11 20:30:50 +03:00
parent defb4d4ab2
commit b475a6314f

View file

@ -35,10 +35,9 @@ public class RouteStepsPlugin extends OsmandPlugin {
private List<Boolean> pointsStatus; private List<Boolean> pointsStatus;
public RouteStepsPlugin(OsmandApplication app) {
public RouteStepsPlugin(OsmandApplication app){
this.app = app; this.app = app;
this.file = new File("/storage/emulated/0/osmand/tracks/","504.gpx"); this.file = new File("/storage/emulated/0/osmand/tracks/", "504.gpx");
gpx = GPXUtilities.loadGPXFile(app, file); gpx = GPXUtilities.loadGPXFile(app, file);
loadCurrentRoute(); loadCurrentRoute();
pointsList = currentRoute.points; pointsList = currentRoute.points;
@ -46,17 +45,21 @@ public class RouteStepsPlugin extends OsmandPlugin {
getAllPointsStatus(); getAllPointsStatus();
} }
public void setGpxFile(GPXUtilities.GPXFile file){ this.gpx = file;} public void setGpxFile(GPXUtilities.GPXFile file) {
this.gpx = file;
}
public void saveGPXFile(){ GPXUtilities.writeGpxFile(file,gpx,app); } public void saveGPXFile() {
GPXUtilities.writeGpxFile(file, gpx, app);
}
public void setCurrentPoint(GPXUtilities.WptPt point){ public void setCurrentPoint(GPXUtilities.WptPt point) {
currentPoint = point; currentPoint = point;
int number = findPointPosition(point); int number = findPointPosition(point);
currentPointPos = number; currentPointPos = number;
} }
public void setCurrentPoint(int number){ public void setCurrentPoint(int number) {
currentPoint = pointsList.get(number); currentPoint = pointsList.get(number);
currentPointPos = number; currentPointPos = number;
} }
@ -84,7 +87,7 @@ public class RouteStepsPlugin extends OsmandPlugin {
@Override @Override
public void registerLayers(MapActivity activity) { public void registerLayers(MapActivity activity) {
// remove old if existing after turn // remove old if existing after turn
if(routeStepsLayer != null) { if (routeStepsLayer != null) {
activity.getMapView().removeLayer(routeStepsLayer); activity.getMapView().removeLayer(routeStepsLayer);
} }
routeStepsLayer = new RouteStepsLayer(activity, this); routeStepsLayer = new RouteStepsLayer(activity, this);
@ -92,13 +95,15 @@ public class RouteStepsPlugin extends OsmandPlugin {
//registerWidget(activity); //registerWidget(activity);
} }
public List<GPXUtilities.WptPt> getPoints() {return currentRoute.points;} public List<GPXUtilities.WptPt> getPoints() {
return currentRoute.points;
}
public boolean getPointStatus(int numberOfPoint){ public boolean getPointStatus(int numberOfPoint) {
Map<String, String> map = gpx.getExtensionsToRead(); Map<String, String> map = gpx.getExtensionsToRead();
String mapKey = routeKey + POINT_KEY + numberOfPoint + VISITED_KEY; String mapKey = routeKey + POINT_KEY + numberOfPoint + VISITED_KEY;
if (map.containsKey(mapKey)){ if (map.containsKey(mapKey)) {
String value = map.get(mapKey); String value = map.get(mapKey);
return (value.equals("true")); return (value.equals("true"));
} }
@ -107,36 +112,36 @@ public class RouteStepsPlugin extends OsmandPlugin {
} }
//saves point status value to gpx extention file //saves point status value to gpx extention file
public void setPointStatus(int numberOfPoint, boolean status){ public void setPointStatus(int numberOfPoint, boolean status) {
Map<String, String> map = gpx.getExtensionsToWrite(); Map<String, String> map = gpx.getExtensionsToWrite();
String mapKey = routeKey + POINT_KEY + numberOfPoint + VISITED_KEY; String mapKey = routeKey + POINT_KEY + numberOfPoint + VISITED_KEY;
if (status){ if (status) {
map.put(mapKey, "true"); map.put(mapKey, "true");
} else { } else {
map.put(mapKey, "false"); map.put(mapKey, "false");
} }
} }
public GPXUtilities.WptPt getNextPoint(){ public GPXUtilities.WptPt getNextPoint() {
if (pointsList.size() > currentPointPos +1){ if (pointsList.size() > currentPointPos + 1) {
return pointsList.get(currentPointPos+1); return pointsList.get(currentPointPos + 1);
} else{ } else {
return null; return null;
} }
} }
private void loadCurrentRoute() { private void loadCurrentRoute() {
if (gpx.routes.size() < 1){ if (gpx.routes.size() < 1) {
return; return;
} }
Map<String,String> map = gpx.getExtensionsToRead(); Map<String, String> map = gpx.getExtensionsToRead();
if (map.containsKey(CURRENT_ROUTE_KEY)){ if (map.containsKey(CURRENT_ROUTE_KEY)) {
String routeName = map.get(CURRENT_ROUTE_KEY); String routeName = map.get(CURRENT_ROUTE_KEY);
int i = 0; int i = 0;
for(GPXUtilities.Route route : gpx.routes){ for (GPXUtilities.Route route : gpx.routes) {
if (route.name.equals(routeName)){ if (route.name.equals(routeName)) {
currentRoute = route; currentRoute = route;
routeKey = i; routeKey = i;
return; return;
@ -164,22 +169,22 @@ public class RouteStepsPlugin extends OsmandPlugin {
} }
}; };
adapter.item(R.string.context_menu_item_show_route_points) adapter.item(R.string.context_menu_item_show_route_points)
.icons( R.drawable.ic_action_parking_dark, R.drawable.ic_action_parking_light).listen(addListener).reg(); .icons(R.drawable.ic_action_parking_dark, R.drawable.ic_action_parking_light).listen(addListener).reg();
} }
private void getAllPointsStatus(){ private void getAllPointsStatus() {
for(int i=0; i< pointsList.size(); i++){ for (int i = 0; i < pointsList.size(); i++) {
pointsStatus.add(getPointStatus(i)); pointsStatus.add(getPointStatus(i));
} }
} }
private void showStepsDialog(MapActivity mapActivity){ private void showStepsDialog(MapActivity mapActivity) {
List<String> pointNames = new ArrayList<String>(); List<String> pointNames = new ArrayList<String>();
//this array need to collect user selection during dialogue //this array need to collect user selection during dialogue
final List<Boolean> pointsIntermediateState = new ArrayList<Boolean>(pointsStatus); final List<Boolean> pointsIntermediateState = new ArrayList<Boolean>(pointsStatus);
for(GPXUtilities.WptPt point : pointsList){ for (GPXUtilities.WptPt point : pointsList) {
pointNames.add(point.name); pointNames.add(point.name);
} }
@ -189,17 +194,17 @@ public class RouteStepsPlugin extends OsmandPlugin {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i, boolean isChecked) { public void onClick(DialogInterface dialogInterface, int i, boolean isChecked) {
//saving user choice //saving user choice
pointsIntermediateState.set(i,isChecked); pointsIntermediateState.set(i, isChecked);
} }
}); });
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
for (int j=0; j< pointsIntermediateState.size(); j++){ for (int j = 0; j < pointsIntermediateState.size(); j++) {
boolean newValue = pointsIntermediateState.get(j); boolean newValue = pointsIntermediateState.get(j);
//if values is the same - there's no need to save data //if values is the same - there's no need to save data
if (newValue != pointsStatus.get(j)){ if (newValue != pointsStatus.get(j)) {
setPointStatus(j,newValue); setPointStatus(j, newValue);
} }
} }
pointsStatus = new ArrayList<Boolean>(pointsIntermediateState); pointsStatus = new ArrayList<Boolean>(pointsIntermediateState);
@ -222,10 +227,10 @@ public class RouteStepsPlugin extends OsmandPlugin {
} }
private int findPointPosition(GPXUtilities.WptPt point){ private int findPointPosition(GPXUtilities.WptPt point) {
int i = 0; int i = 0;
for (GPXUtilities.WptPt item : pointsList){ for (GPXUtilities.WptPt item : pointsList) {
if (item.equals(point)){ if (item.equals(point)) {
return i; return i;
} }
i++; i++;