renamed plugin. Visited point is green. Not visited blue.

This commit is contained in:
unknown 2014-06-16 15:18:02 +03:00
parent c3e534195b
commit 6cb62a3a86
9 changed files with 140 additions and 139 deletions

View file

@ -114,7 +114,7 @@
<activity android:name="net.osmand.plus.activities.SettingsNavigationActivity" android:configChanges="keyboardHidden|orientation"></activity>
<activity android:name="net.osmand.plus.monitoring.SettingsMonitoringActivity" android:configChanges="keyboardHidden|orientation"></activity>
<activity android:name="net.osmand.plus.rastermaps.SettingsRasterMapsActivity" android:configChanges="keyboardHidden|orientation"></activity>
<activity android:name="net.osmand.plus.routesteps.RouteStepsActivity"/>
<activity android:name=".routepointsnavigation.RoutePointsActivity"/>
<activity android:name="net.osmand.plus.osmedit.SettingsOsmEditingActivity" android:configChanges="keyboardHidden|orientation"></activity>
<activity android:name="net.osmand.plus.development.SettingsDevelopmentActivity" android:configChanges="keyboardHidden|orientation"></activity>

View file

@ -1,37 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dip" >
android:orientation="horizontal"
android:padding="6dip"
android:weightSum="6">
<TextView android:id="@+id/index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox1"
android:layout_alignBottom="@+id/checkBox1"
android:layout_toRightOf="@+id/checkBox1"/>
android:layout_weight="5"/>
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox1"
android:layout_alignBottom="@+id/checkBox1"
android:layout_alignParentRight="true"/>
android:layout_weight="1"/>
</RelativeLayout>
</LinearLayout>

View file

@ -5,17 +5,17 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_width="fill_parent"
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/gpx_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:padding="10dp"
android:text="@string/all_route_points" android:textSize="20sp" />
<Button android:id="@+id/done"
android:layout_width="wrap_content"
android:layout_marginRight="6dp"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:text="done"/>
</RelativeLayout>
</LinearLayout>
<ListView android:id="@+id/pointsListView"

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="route_points_no_gpx">No gpx</string>
<string name="mark_as_current">Mark as current</string>
</resources>

View file

@ -1878,4 +1878,6 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="navigation_intent_invalid">Invalid format: %s</string>
<string name="route_step_menu_mark_as_next">Mark as next</string>
<string name="route_step_menu_show_on_map">Show on map</string>
<string name="mark_as_visited">Mark as visited</string>
<string name="show_on_map">Show on map</string>
</resources>

View file

@ -22,7 +22,7 @@ import net.osmand.plus.osmo.OsMoPlugin;
import net.osmand.plus.osmodroid.OsMoDroidPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.routesteps.RouteStepsPlugin;
import net.osmand.plus.routepointsnavigation.RoutePointsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.OsmandMapTileView;
import org.apache.commons.logging.Log;
@ -85,7 +85,7 @@ public abstract class OsmandPlugin {
//final RouteStepsPlugin routeSteps = new RouteStepsPlugin(app);
//installPlugin(ROUTE_STEPS_PLUGIN_COMPONENT, RouteStepsPlugin.ID, app, routeSteps);
installedPlugins.add(new RouteStepsPlugin(app));
installedPlugins.add(new RoutePointsPlugin(app));
installPlugin(OSMODROID_PLUGIN_COMPONENT, OsMoDroidPlugin.ID, app, new OsMoDroidPlugin(app));
installedPlugins.add(new OsmEditingPlugin(app));

View file

@ -1,9 +1,6 @@
package net.osmand.plus.routesteps;
package net.osmand.plus.routepointsnavigation;
import alice.tuprolog.Int;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Log;
@ -15,9 +12,9 @@ import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandExpandableListActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.views.ContextMenuLayer;
import org.w3c.dom.Text;
import java.io.File;
import java.util.*;
@ -25,10 +22,9 @@ import java.util.*;
/**
* Created by Bars on 13.06.2014.
*/
public class RouteStepsActivity extends SherlockFragmentActivity {
public class RoutePointsActivity extends SherlockFragmentActivity {
private static final String VISITED_KEY = "IsVisited";
private static final String POINT_KEY = "Point";
private static final String CURRENT_ROUTE_KEY = "CurrentRoute";
private File file;
@ -45,7 +41,9 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
private List<Boolean> pointsChangedState;
private List<Boolean> pointsStartState;
private RouteStepsPlugin plugin;
private RoutePointsPlugin plugin;
private int selectedItemIndex;
@Override
@ -55,8 +53,8 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
getPlugin();
getGpx();
if (gpx != null){
preparePoints();
if (gpx != null) {
prepareView();
}
Button done = (Button) findViewById(R.id.done);
@ -64,6 +62,9 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
@Override
public void onClick(View view) {
saveStatus();
GPXUtilities.WptPt point = plugin.getCurrentPoint();
app.getSettings().setMapLocationToShow(point.lat, point.lon, app.getSettings().getMapZoomToShow());
finish();
}
});
@ -71,33 +72,37 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
}
private void getPlugin(){
private void getPlugin() {
List<OsmandPlugin> plugins = OsmandPlugin.getEnabledPlugins();
for (OsmandPlugin plugin: plugins){
if (plugin instanceof RouteStepsPlugin){
this.plugin = (RouteStepsPlugin) plugin;
for (OsmandPlugin plugin : plugins) {
if (plugin instanceof RoutePointsPlugin) {
this.plugin = (RoutePointsPlugin) plugin;
}
}
}
private void getGpx(){
if (plugin.getGpx() != null){
private void getGpx() {
if (plugin.getGpx() != null) {
this.gpx = plugin.getGpx();
} else {
GpxUiHelper.selectGPXFile(this,false,false, new CallbackWithObject<GPXUtilities.GPXFile[]>() {
GpxUiHelper.selectGPXFile(this, false, false, new CallbackWithObject<GPXUtilities.GPXFile[]>() {
@Override
public boolean processResult(GPXUtilities.GPXFile[] result) {
gpx = result[0];
preparePoints();
plugin.setGpx(gpx);
prepareView();
return false;
}
});
}
}
private void preparePoints(){
private void prepareView() {
TextView gpxName = (TextView) findViewById(R.id.gpx_name);
String fileName = gpx.path.substring(gpx.path.lastIndexOf("/") + 1,gpx.path.lastIndexOf("."));
gpxName.setText(fileName);
loadCurrentRoute();
pointsList = currentRoute.points;
sortPoints();
@ -112,7 +117,7 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
for (int i = 0; i < pointsList.size(); i++) {
String pointName = pointsList.get(i).name;
if (pointsStatus.get(i) != 0) {
String dateString= DateFormat.format("MM/dd/yyyy hh:mm:ss", new Date(pointsStatus.get(i))).toString();
String dateString = DateFormat.format("MM/dd/yyyy hh:mm:ss", new Date(pointsStatus.get(i))).toString();
pointItemsList.add(new PointItem(true, pointName, dateString));
} else {
pointItemsList.add(new PointItem(false, pointName, ""));
@ -126,26 +131,32 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
final PopupMenu menu = new PopupMenu(RouteStepsActivity.this, view);
selectedItemIndex = i;
final PopupMenu popup = new PopupMenu(RoutePointsActivity.this, view);
final Menu menu = popup.getMenu();
menu.add(getString(R.string.mark_as_current));
menu.add(getString(R.string.mark_as_visited));
menu.add(getString(R.string.show_on_map));
menu.getMenuInflater().inflate(R.menu.route_step_menu, menu.getMenu());
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
if (menuItem.getTitle().equals("Mark as next")){
if (menuItem.getTitle().equals(getResources().getString(R.string.mark_as_current))) {
plugin.setCurrentPoint(pointsList.get(selectedItemIndex));
} else if (menuItem.getTitle().equals(getResources().getString(R.string.show_on_map))) {
GPXUtilities.WptPt point = pointsList.get(selectedItemIndex);
app.getSettings().setMapLocationToShow(point.lat, point.lon, app.getSettings().getMapZoomToShow());
finish();
} else {
//AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
///int position = info.position;
//GPXUtilities.WptPt point = pointsList.get(position);
//app.getSettings().setMapLocationToShow();
}
return true;
}
});
menu.show();
popup.show();
}
});
}
@ -172,43 +183,42 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
private List<Long> getAllPointsStatus() {
List<Long> pointsStatus = new ArrayList<Long>();
for (int i = 0; i < pointsList.size(); i++) {
pointsStatus.add(getPointStatus(pointsIndex.get(i)));
pointsStatus.add(plugin.getPointStatus(pointsIndex.get(i)));
}
return pointsStatus;
}
private void saveStatus(){
private void saveStatus() {
for (int i = 0; i < pointsChangedState.size(); i++) {
boolean newValue = pointsChangedState.get(i);
//if values is the same - there's no need to save data
if (newValue != pointsStartState.get(i)) {
int indexToWrite = pointsIndex.get(i);
setPointStatus(indexToWrite, newValue);
plugin.setPointStatus(indexToWrite, newValue);
}
}
saveGPXFile();
finish();
}
private void sortPoints(){
private void sortPoints() {
List<GPXUtilities.WptPt> listToSort = new ArrayList<GPXUtilities.WptPt>();
List<Integer> indexItemsAtTheEnd = new ArrayList<Integer>();
pointsIndex = new ArrayList<Integer>();
for (int i =0; i< pointsList.size(); i++){
long status = getPointStatus(i);
if (status == 0L){
for (int i = 0; i < pointsList.size(); i++) {
long status = plugin.getPointStatus(i);
if (status == 0L) {
listToSort.add(pointsList.get(i));
pointsIndex.add(i);
} else{
} else {
indexItemsAtTheEnd.add(i);
}
}
for (int i : indexItemsAtTheEnd){
for (int i : indexItemsAtTheEnd) {
listToSort.add(pointsList.get(i));
pointsIndex.add(i);
}
@ -220,34 +230,6 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
GPXUtilities.writeGpxFile(new File(gpx.path), gpx, app);
}
private long getPointStatus(int numberOfPoint) {
Map<String, String> map = currentRoute.getExtensionsToRead();
String mapKey = POINT_KEY + numberOfPoint + VISITED_KEY;
if (map.containsKey(mapKey)) {
String value = map.get(mapKey);
return (Long.valueOf(value));
}
return 0L;
}
//saves point status value to gpx extention file
private void setPointStatus(int numberOfPoint, boolean status) {
Map<String, String> map = currentRoute.getExtensionsToWrite();
String mapKey = POINT_KEY + numberOfPoint + VISITED_KEY;
if (status) {
//value is current time
Calendar c = Calendar.getInstance();
long number = c.getTimeInMillis();
map.put(mapKey, String.valueOf(number));
} else if (map.containsKey(mapKey)) {
map.remove(mapKey);
}
}
public List<Boolean> getPointsState() {
List<Boolean> status = new ArrayList<Boolean>();
for (int i = 0; i < pointsStatus.size(); i++) {
@ -270,12 +252,12 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
}
private class PointItemAdapter extends ArrayAdapter<PointItem> {
private RouteStepsActivity ctx;
private RoutePointsActivity ctx;
private ArrayList<PointItem> pointsList;
public PointItemAdapter(Context context, int textViewResourceId, ArrayList<PointItem> pointsList) {
super(context, textViewResourceId, pointsList);
ctx = (RouteStepsActivity) context;
ctx = (RoutePointsActivity) context;
this.pointsList = new ArrayList<PointItem>();
this.pointsList.addAll(pointsList);
}
@ -284,8 +266,6 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
TextView index;
TextView name;
TextView date;
CheckBox visited;
}
@Override
@ -300,31 +280,22 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
holder.index = (TextView) convertView.findViewById(R.id.index);
holder.date = (TextView) convertView.findViewById(R.id.date);
holder.name = (TextView) convertView.findViewById(R.id.name);
holder.visited = (CheckBox) convertView.findViewById(R.id.checkBox1);
convertView.setTag(holder);
holder.visited.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CheckBox ch = (CheckBox) view;
RelativeLayout parent = (RelativeLayout) ch.getParent();
TextView text = (TextView) parent.getChildAt(0);
pointsChangedState.set(Integer.parseInt(text.getText().toString()), ch.isChecked());
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
PointItem point = pointsList.get(position);
holder.index.setText(String.valueOf(position));
holder.visited.setChecked(point.isSelected());
String pointName = point.getName();
int pos = pointName.indexOf(":");
holder.name.setText(pointName.substring(0, pos));
if (point.isSelected()){
if (point.isSelected()) {
holder.name.setTextColor(getResources().getColor(R.color.osmbug_closed));
holder.date.setText(String.valueOf(point.getTime()));
} else{
} else {
holder.name.setTextColor(getResources().getColor(R.color.color_update));
holder.date.setText("");
}
@ -333,6 +304,7 @@ public class RouteStepsActivity extends SherlockFragmentActivity {
}
//this class needed to represent route point in UI
private class PointItem {
private boolean visited;
private String name;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.routesteps;
package net.osmand.plus.routepointsnavigation;
import android.graphics.Canvas;
import android.graphics.PointF;
@ -14,12 +14,12 @@ import java.util.List;
/**
* Created by Barsik on 10.06.2014.
*/
public class RouteStepsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private final MapActivity map;
private RouteStepsPlugin plugin;
private RoutePointsPlugin plugin;
public RouteStepsLayer(MapActivity map, RouteStepsPlugin plugin){
public RoutePointsLayer(MapActivity map, RoutePointsPlugin plugin){
this.map = map;
this.plugin = plugin;
}

View file

@ -1,22 +1,16 @@
package net.osmand.plus.routesteps;
package net.osmand.plus.routepointsnavigation;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.view.View;
import net.osmand.data.LatLon;
import net.osmand.plus.*;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
@ -24,30 +18,28 @@ import java.util.Map;
/**
* Created by Barsik on 10.06.2014.
*/
public class RouteStepsPlugin extends OsmandPlugin {
public class RoutePointsPlugin extends OsmandPlugin {
public static final String ID = "osmand.route.stepsPlugin";
private static final String VISITED_KEY = "IsVisited";
private static final String POINT_KEY = "Point";
private OsmandApplication app;
private GPXUtilities.GPXFile gpx;
private File file;
private GPXUtilities.Route currentRoute;
private GPXUtilities.WptPt currentPoint;
private int currentPointPos;
private RouteStepsLayer routeStepsLayer;
private RoutePointsLayer routeStepsLayer;
private List<GPXUtilities.WptPt> pointsList;
private TextInfoWidget routeStepsControl;
private int visitedCount;
public RouteStepsPlugin(OsmandApplication app) {
public RoutePointsPlugin(OsmandApplication app) {
ApplicationMode. regWidget("route_steps", (ApplicationMode[]) null);
this.app = app;
// this.file = new File("/storage/emulated/0/osmand/tracks/", "504.gpx");
// gpx = GPXUtilities.loadGPXFile(app, file);
}
public void setGpxFile(GPXUtilities.GPXFile file) {
this.gpx = file;
}
public void setCurrentPoint(GPXUtilities.WptPt point) {
@ -85,16 +77,23 @@ public class RouteStepsPlugin extends OsmandPlugin {
return true;
}
public GPXUtilities.WptPt getCurrentPoint(){return currentPoint;}
public GPXUtilities.GPXFile getGpx(){ return gpx;}
public void setGpx(GPXUtilities.GPXFile gpx) { this.gpx = gpx;}
public void setGpx(GPXUtilities.GPXFile gpx) {
this.gpx = gpx;
currentRoute = gpx.routes.get(0);
pointsList = currentRoute.points;
refreshPointsStatus();
}
public void registerLayers(MapActivity activity) {
// remove old if existing after turn
if (routeStepsLayer != null) {
activity.getMapView().removeLayer(routeStepsLayer);
}
routeStepsLayer = new RouteStepsLayer(activity, this);
routeStepsLayer = new RoutePointsLayer(activity, this);
activity.getMapView().addLayer(routeStepsLayer, 5.5f);
registerWidget(activity);
}
@ -102,7 +101,7 @@ public class RouteStepsPlugin extends OsmandPlugin {
private void registerWidget(MapActivity activity) {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
if (mapInfoLayer != null) {
routeStepsControl = createRouteStepsInfoControl(activity, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText());
routeStepsControl = createRouteStepsInfoControl(activity, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintText());
mapInfoLayer.getMapInfoControls().registerSideWidget(routeStepsControl,
R.drawable.widget_parking, R.string.map_widget_route_steps, "route_steps", false, 8);
mapInfoLayer.recreateControls();
@ -143,13 +142,12 @@ public class RouteStepsPlugin extends OsmandPlugin {
private TextInfoWidget createRouteStepsInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) {
TextInfoWidget routeStepsControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
@Override
@Override()
public boolean updateInfo(OsmandMapLayer.DrawSettings drawSettings) {
if (gpx != null) {
OsmandMapTileView view = map.getMapView();
setText("test", "test");
setText(String.valueOf(visitedCount) + "/",String.valueOf(pointsList.size()));
} else {
setText("No gpx", "");
setText(app.getString(R.string.route_points_no_gpx), "");
}
return true;
@ -159,7 +157,7 @@ public class RouteStepsPlugin extends OsmandPlugin {
routeStepsControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(app, RouteStepsActivity.class);
Intent intent = new Intent(app, RoutePointsActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
app.startActivity(intent);
}
@ -169,5 +167,39 @@ public class RouteStepsPlugin extends OsmandPlugin {
return routeStepsControl;
}
public void refreshPointsStatus(){
visitedCount = 0;
for (int i=0; i< pointsList.size();i++){
if (getPointStatus(i) != 0){ visitedCount++;}
}
}
public long getPointStatus(int numberOfPoint) {
Map<String, String> map = currentRoute.getExtensionsToRead();
String mapKey = POINT_KEY + numberOfPoint + VISITED_KEY;
if (map.containsKey(mapKey)) {
String value = map.get(mapKey);
return (Long.valueOf(value));
}
return 0L;
}
//saves point status value to gpx extention file
public void setPointStatus(int numberOfPoint, boolean status) {
Map<String, String> map = currentRoute.getExtensionsToWrite();
String mapKey = POINT_KEY + numberOfPoint + VISITED_KEY;
if (status) {
//value is current time
Calendar c = Calendar.getInstance();
long number = c.getTimeInMillis();
map.put(mapKey, String.valueOf(number));
} else if (map.containsKey(mapKey)) {
map.remove(mapKey);
}
refreshPointsStatus();
}
}