- POI doesn't refresh map after delete
https://github.com/osmandapp/Osmand/issues/1281
- No delete in context menu for POI/Editing
https://github.com/osmandapp/Osmand/issues/1278
This commit is contained in:
Victor Shcherb 2015-06-02 01:14:07 +02:00
parent d7f53dca03
commit 48b1452a1d
12 changed files with 179 additions and 177 deletions

View file

@ -9,7 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="osm_edit_context_menu_delete">Delete Osm Edit</string>
<string name="rendering_value_disabled_name">Disabled</string>
<string name="rendering_value_walkingRoutesScopeOSMC_name">Coloring according to route scope</string>
<string name="rendering_value_walkingRoutesOSMC_name">Coloring according to OSMC</string>

View file

@ -1,5 +1,16 @@
package net.osmand.plus.osmedit;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import net.osmand.access.AccessibleToast;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashBaseFragment;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
@ -12,18 +23,6 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashBaseFragment;
import net.osmand.plus.myplaces.FavoritesActivity;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Denis
@ -135,17 +134,14 @@ public class DashOsmEditsFragment extends DashBaseFragment implements OsmEditsUp
getString(R.string.uploading), getString(R.string.local_openstreetmap_uploading),
ProgressDialog.STYLE_HORIZONTAL).getDialog();
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog,
DashOsmEditsFragment.this, remotepoi, remotebug, toUpload.length);
DashOsmEditsFragment.this, plugin, remotepoi, remotebug, toUpload.length);
uploadTask.execute(toUpload);
dialog.show();
}
private void getOsmPoints(ArrayList<OsmPoint> dataPoints) {
OpenstreetmapsDbHelper dbpoi = new OpenstreetmapsDbHelper(getActivity());
OsmBugsDbHelper dbbug = new OsmBugsDbHelper(getActivity());
List<OpenstreetmapPoint> l1 = dbpoi.getOpenstreetmapPoints();
List<OsmNotesPoint> l2 = dbbug.getOsmbugsPoints();
List<OpenstreetmapPoint> l1 = plugin.getDBPOI().getOpenstreetmapPoints();
List<OsmNotesPoint> l2 = plugin.getDBBug().getOsmbugsPoints();
if (l1.isEmpty()){
int i = 0;
for(OsmPoint point : l2){

View file

@ -112,10 +112,10 @@ public class EditingPOIDialogProvider implements DialogProvider {
settings = ((OsmandApplication) activity.getApplication()).getSettings();
isLocalEdit = true;
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
this.openstreetmapUtil = new OpenstreetmapLocalUtil(activity);
this.openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
this.openstreetmapUtilToLoad = openstreetmapUtil;
} else if(!settings.isInternetConnectionAvailable(true)) {
this.openstreetmapUtil = new OpenstreetmapLocalUtil(activity);
this.openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
this.openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity);
} else {
isLocalEdit = false;
@ -692,7 +692,6 @@ public class EditingPOIDialogProvider implements DialogProvider {
@Override
protected void onPostExecute(Node result) {
progress.dismiss();
plugin.collectLocalOsmEdits();
if (result != null) {
successAction.run();
}

View file

@ -15,13 +15,14 @@ import android.content.Context;
public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
private final Context ctx;
private final OpenstreetmapsDbHelper db;
public final static Log log = PlatformUtil.getLog(OpenstreetmapLocalUtil.class);
public OpenstreetmapLocalUtil(Context uiContext) {
private OsmEditingPlugin plugin;
public OpenstreetmapLocalUtil(OsmEditingPlugin plugin, Context uiContext) {
this.plugin = plugin;
this.ctx = uiContext;
this.db = new OpenstreetmapsDbHelper(ctx);
}
@Override
@ -33,16 +34,16 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
public Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment, boolean closeChangeSet){
Node newNode = n;
if (n.getId() == -1) {
newNode = new Node(n, Math.min(-2, db.getMinID() - 1)); // generate local id for the created node
newNode = new Node(n, Math.min(-2, plugin.getDBPOI().getMinID() - 1)); // generate local id for the created node
}
OpenstreetmapPoint p = new OpenstreetmapPoint();
p.setEntity(newNode);
p.setAction(action);
p.setComment(comment);
if (p.getAction() == OsmPoint.Action.DELETE && newNode.getId() < 0) { //if it is our local poi
db.deletePOI(p);
plugin.getDBPOI().deletePOI(p);
} else {
db.addOpenstreetmap(p);
plugin.getDBPOI().addOpenstreetmap(p);
}
return newNode;
}

View file

@ -12,7 +12,6 @@ import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.LinkedHashMap;
import java.util.Map;
@ -40,7 +39,6 @@ import org.xmlpull.v1.XmlSerializer;
import android.content.Context;
import android.util.Xml;
import android.view.View;
import android.widget.Toast;
public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {

View file

@ -27,7 +27,7 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper {
OPENSTREETMAP_COL_LAT + " double," + OPENSTREETMAP_COL_LON + " double," +
OPENSTREETMAP_COL_TAGS + " VARCHAR(2048)," +
OPENSTREETMAP_COL_ACTION + " TEXT, " + OPENSTREETMAP_COL_COMMENT + " TEXT);"; //$NON-NLS-1$ //$NON-NLS-2$
List<OpenstreetmapPoint> cache = null;
public OpenstreetmapsDbHelper(Context context) {
super(context, OPENSTREETMAP_DB_NAME, null, DATABASE_VERSION);
@ -47,11 +47,13 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper {
}
public List<OpenstreetmapPoint> getOpenstreetmapPoints() {
return checkOpenstreetmapPoints();
if(cache == null ) {
return checkOpenstreetmapPoints();
}
return cache;
}
public boolean addOpenstreetmap(OpenstreetmapPoint p) {
checkOpenstreetmapPoints();
SQLiteDatabase db = getWritableDatabase();
if (db != null) {
StringBuilder tags = new StringBuilder();
@ -67,6 +69,8 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper {
" (" + OPENSTREETMAP_COL_ID + ", " + OPENSTREETMAP_COL_LAT + ", " + OPENSTREETMAP_COL_LON + ", " + OPENSTREETMAP_COL_TAGS + ", " + OPENSTREETMAP_COL_ACTION + "," + OPENSTREETMAP_COL_COMMENT + ")" +
" VALUES (?, ?, ?, ?, ?, ?)",
new Object[] { p.getId(),p.getLatitude(), p.getLongitude(), tags.toString() , OsmPoint.stringAction.get(p.getAction()), p.getComment(), }); //$NON-NLS-1$ //$NON-NLS-2$
db.close();
checkOpenstreetmapPoints();
return true;
}
return false;
@ -75,11 +79,12 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper {
public boolean deletePOI(OpenstreetmapPoint p) {
checkOpenstreetmapPoints();
SQLiteDatabase db = getWritableDatabase();
if (db != null) {
db.execSQL("DELETE FROM " + OPENSTREETMAP_TABLE_NAME +
" WHERE " + OPENSTREETMAP_COL_ID + " = ?", new Object[] { p.getId() }); //$NON-NLS-1$ //$NON-NLS-2$
db.close();
checkOpenstreetmapPoints();
return true;
}
return false;
@ -87,8 +92,8 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper {
private List<OpenstreetmapPoint> checkOpenstreetmapPoints(){
SQLiteDatabase db = getWritableDatabase();
List<OpenstreetmapPoint> cachedOpenstreetmapPoints = new ArrayList<OpenstreetmapPoint>();
SQLiteDatabase db = getReadableDatabase();
List<OpenstreetmapPoint> points = new ArrayList<OpenstreetmapPoint>();
if (db != null) {
Cursor query = db.rawQuery("SELECT " + OPENSTREETMAP_COL_ID + ", " + OPENSTREETMAP_COL_LAT + "," + OPENSTREETMAP_COL_LON + "," + OPENSTREETMAP_COL_ACTION + "," + OPENSTREETMAP_COL_COMMENT + "," + OPENSTREETMAP_COL_TAGS+ " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
OPENSTREETMAP_TABLE_NAME, null);
@ -106,12 +111,13 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper {
p.setEntity(entity);
p.setAction(query.getString(3));
p.setComment(query.getString(4));
cachedOpenstreetmapPoints.add(p);
points.add(p);
} while (query.moveToNext());
}
query.close();
}
return cachedOpenstreetmapPoints;
cache = points;
return points;
}
public long getMinID() {

View file

@ -23,7 +23,7 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper {
OSMBUGS_COL_ID + " INTEGER, " + OSMBUGS_COL_TEXT + " TEXT, " + //$NON-NLS-1$ //$NON-NLS-2$
OSMBUGS_COL_LAT + " double, " + OSMBUGS_COL_LON + " double, " + //$NON-NLS-1$ //$NON-NLS-2$
OSMBUGS_COL_ACTION + " TEXT, " + OSMBUGS_COL_AUTHOR + " TEXT);"; //$NON-NLS-1$ //$NON-NLS-2$
List<OsmNotesPoint> cache = null;
public OsmBugsDbHelper(Context context) {
super(context, OSMBUGS_DB_NAME, null, DATABASE_VERSION);
}
@ -38,11 +38,13 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper {
}
public List<OsmNotesPoint> getOsmbugsPoints() {
return checkOsmbugsPoints();
if (cache == null) {
return checkOsmbugsPoints();
}
return cache;
}
public boolean addOsmbugs(OsmNotesPoint p) {
checkOsmbugsPoints();
SQLiteDatabase db = getWritableDatabase();
if (db != null) {
db.execSQL(
@ -50,24 +52,27 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper {
+ OSMBUGS_COL_LON + "," + OSMBUGS_COL_ACTION + "," + OSMBUGS_COL_AUTHOR + ")" + " VALUES (?, ?, ?, ?, ?, ?)",
new Object[] { p.getId(), p.getText(), p.getLatitude(), p.getLongitude(),
OsmPoint.stringAction.get(p.getAction()), p.getAuthor() }); //$NON-NLS-1$ //$NON-NLS-2$
db.close();
checkOsmbugsPoints();
return true;
}
return false;
}
public boolean deleteAllBugModifications(OsmNotesPoint p) {
checkOsmbugsPoints();
SQLiteDatabase db = getWritableDatabase();
if (db != null) {
db.execSQL("DELETE FROM " + OSMBUGS_TABLE_NAME +
" WHERE " + OSMBUGS_COL_ID + " = ?", new Object[] { p.getId() }); //$NON-NLS-1$ //$NON-NLS-2$
db.close();
checkOsmbugsPoints();
return true;
}
return false;
}
private List<OsmNotesPoint> checkOsmbugsPoints(){
SQLiteDatabase db = getWritableDatabase();
SQLiteDatabase db = getReadableDatabase();
List<OsmNotesPoint> cachedOsmbugsPoints = new ArrayList<OsmNotesPoint>();
if (db != null) {
Cursor query = db.rawQuery("SELECT " + OSMBUGS_COL_ID + ", " + OSMBUGS_COL_TEXT + ", " + OSMBUGS_COL_LAT + "," + OSMBUGS_COL_LON + "," + OSMBUGS_COL_ACTION + "," + OSMBUGS_COL_AUTHOR + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
@ -89,6 +94,7 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper {
query.close();
db.close();
}
cache = cachedOsmbugsPoints;
return cachedOsmbugsPoints;
}

View file

@ -1,20 +1,14 @@
package net.osmand.plus.osmedit;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Xml;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
@ -39,13 +33,20 @@ import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Xml;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Toast;
public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider, DialogProvider {
@ -220,9 +221,6 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
if(data != null) {
data.clearCache();
}
if (plugin != null){
plugin.collectLocalOsmEdits();
}
}
private static String readText(XmlPullParser parser, String key) throws XmlPullParserException, IOException {

View file

@ -1,23 +1,9 @@
package net.osmand.plus.osmedit;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.List;
import net.osmand.access.AccessibleToast;
import net.osmand.data.Amenity;
import net.osmand.data.DataTileManager;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OsmandApplication;
@ -33,21 +19,48 @@ import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.Algorithms;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class OsmEditingPlugin extends OsmandPlugin {
private static final String ID = "osm.editing";
private OsmandSettings settings;
private OsmandApplication app;
DataTileManager<OsmPoint> localOsmEditsInternal = null;
OpenstreetmapsDbHelper dbpoi ;
OsmBugsDbHelper dbbug ;
@Override
public String getId() {
return ID;
}
public OpenstreetmapsDbHelper getDBPOI() {
if(dbpoi == null) {
dbpoi = new OpenstreetmapsDbHelper(app);
}
return dbpoi;
}
public OsmBugsDbHelper getDBBug() {
if(dbbug == null) {
dbbug = new OsmBugsDbHelper(app);
}
return dbbug;
}
public OsmEditingPlugin(OsmandApplication app) {
this.app = app;
}
@ -150,9 +163,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
@Override
public void addMyPlacesTab(FavoritesActivity favoritesActivity, List<TabActivity.TabItem> mTabs, Intent intent) {
OpenstreetmapsDbHelper dbpoi = new OpenstreetmapsDbHelper(favoritesActivity);
OsmBugsDbHelper dbbug = new OsmBugsDbHelper(favoritesActivity);
if (dbpoi.getOpenstreetmapPoints().size() > 0 || dbbug.getOsmbugsPoints().size() > 0){
if (getDBPOI().getOpenstreetmapPoints().size() > 0 || getDBBug().getOsmbugsPoints().size() > 0){
mTabs.add(favoritesActivity.getTabIndicator(R.string.osm_edits, OsmEditsFragment.class));
if (intent != null && "OSM".equals(intent.getStringExtra("TAB"))) {
app.getSettings().FAVORITES_TAB.set(R.string.osm_edits);
@ -223,11 +234,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
}
}
public void onLocalItemDeleted(OsmPoint point) {
if(localOsmEditsInternal != null) {
localOsmEditsInternal.unregisterObject(point.getLatitude(), point.getLongitude(), point);
}
}
public enum UploadVisibility implements IEnumWithResource {
Public(R.string.gpxup_public),
@ -285,40 +292,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
return true;
}
public void onLocalOsmEditAdded(OsmPoint point){
if(localOsmEditsInternal != null) {
localOsmEditsInternal.registerObject(point.getLatitude(), point.getLongitude(), point);
}
}
public void collectLocalOsmEdits() {
DataTileManager<OsmPoint> res = new DataTileManager<OsmPoint>();
OpenstreetmapsDbHelper dbpoi = new OpenstreetmapsDbHelper(app);
OsmBugsDbHelper dbbug = new OsmBugsDbHelper(app);
List<OpenstreetmapPoint> l1 = dbpoi.getOpenstreetmapPoints();
List<OsmNotesPoint> l2 = dbbug.getOsmbugsPoints();
for (OsmPoint point : l1) {
res.registerObject(point.getLatitude(), point.getLongitude(), point);
}
for (OsmPoint point : l2) {
res.registerObject(point.getLatitude(), point.getLongitude(), point);
}
localOsmEditsInternal = res;
}
public DataTileManager<OsmPoint> getLocalOsmEdits(){
if(localOsmEditsInternal == null) {
collectLocalOsmEdits();
}
return localOsmEditsInternal;
}
public List<OsmPoint> getAllEdits(){
return getLocalOsmEdits().getAllObjects();
}
@Override
public String getName() {
return app.getString(R.string.osm_settings);

View file

@ -61,9 +61,6 @@ public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUplo
private boolean selectionMode = false;
private OpenstreetmapsDbHelper dbpoi;
private OsmBugsDbHelper dbbug;
private OpenstreetmapRemoteUtil remotepoi;
private OsmBugsRemoteUtil remotebug;
@ -82,8 +79,6 @@ public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUplo
plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
View view = getActivity().getLayoutInflater().inflate(R.layout.update_index, container, false);
((TextView) view.findViewById(R.id.header)).setText(R.string.your_edits);
dbpoi = new OpenstreetmapsDbHelper(getActivity());
dbbug = new OsmBugsDbHelper(getActivity());
remotepoi = new OpenstreetmapRemoteUtil(getActivity());
remotebug = new OsmBugsRemoteUtil(getMyApplication());
@ -307,13 +302,12 @@ public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUplo
while (it.hasNext()) {
OsmPoint omsPoint = it.next();
if (omsPoint.getGroup() == OsmPoint.Group.POI) {
dbpoi.deletePOI((OpenstreetmapPoint) omsPoint);
plugin.getDBPOI().deletePOI((OpenstreetmapPoint) omsPoint);
} else if (omsPoint.getGroup() == OsmPoint.Group.BUG) {
dbbug.deleteAllBugModifications((OsmNotesPoint) omsPoint);
plugin.getDBBug().deleteAllBugModifications((OsmNotesPoint) omsPoint);
}
it.remove();
listAdapter.delete(omsPoint);
plugin.onLocalItemDeleted(omsPoint);
}
listAdapter.notifyDataSetChanged();
@ -327,8 +321,8 @@ public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUplo
public void onResume() {
super.onResume();
dataPoints = new ArrayList<>();
List<OpenstreetmapPoint> l1 = dbpoi.getOpenstreetmapPoints();
List<OsmNotesPoint> l2 = dbbug.getOsmbugsPoints();
List<OpenstreetmapPoint> l1 = plugin.getDBPOI().getOpenstreetmapPoints();
List<OsmNotesPoint> l2 = plugin.getDBBug().getOsmbugsPoints();
dataPoints.addAll(l1);
dataPoints.addAll(l2);
listAdapter = new OsmEditsAdapter(dataPoints);
@ -507,7 +501,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUplo
getString(R.string.uploading),
getString(R.string.local_openstreetmap_uploading),
ProgressDialog.STYLE_HORIZONTAL).getDialog();
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog, this, remotepoi,
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog, this, plugin, remotepoi,
remotebug, toUpload.length);
uploadTask.execute(toUpload);
@ -621,7 +615,6 @@ public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUplo
@Override
public void uploadUpdated(OsmPoint point) {
plugin.onLocalItemDeleted(point);
listAdapter.delete(point);
}

View file

@ -1,24 +1,23 @@
package net.osmand.plus.osmedit;
import java.util.List;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
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 android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import net.osmand.data.DataTileManager;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
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;
import android.widget.ArrayAdapter;
/**
* Created by Denis on
@ -71,25 +70,26 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
DataTileManager<OsmPoint> points = plugin.getLocalOsmEdits();
final QuadRect latlon = tileBox.getLatLonBounds();
List<OsmPoint> objects = points.getObjects(latlon. top, latlon.left, latlon.bottom, latlon.right);
for (OsmPoint o : objects) {
int locationX = tileBox.getPixXFromLonNoRot(o.getLongitude());
int locationY = tileBox.getPixYFromLatNoRot(o.getLatitude());
canvas.rotate(-view.getRotate(), locationX, locationY);
Bitmap b;
if (o.getGroup() == OsmPoint.Group.POI) {
b = poi;
} else if (o.getGroup() == OsmPoint.Group.BUG) {
b = bug;
} else {
b = poi;
}
canvas.drawBitmap(b, locationX - b.getWidth() / 2, locationY - b.getHeight(), paintIcon);
canvas.rotate(view.getRotate(), locationX, locationY);
drawPoints(canvas, tileBox, plugin.getDBBug().getOsmbugsPoints());
drawPoints(canvas, tileBox, plugin.getDBPOI().getOpenstreetmapPoints());
}
}
private void drawPoints(Canvas canvas, RotatedTileBox tileBox, List<? extends OsmPoint> objects) {
for (OsmPoint o : objects) {
int locationX = tileBox.getPixXFromLonNoRot(o.getLongitude());
int locationY = tileBox.getPixYFromLatNoRot(o.getLatitude());
canvas.rotate(-view.getRotate(), locationX, locationY);
Bitmap b;
if (o.getGroup() == OsmPoint.Group.POI) {
b = poi;
} else if (o.getGroup() == OsmPoint.Group.BUG) {
b = bug;
} else {
b = poi;
}
canvas.drawBitmap(b, locationX - b.getWidth() / 2, locationY - b.getHeight(), paintIcon);
canvas.rotate(view.getRotate(), locationX, locationY);
}
}
@ -109,7 +109,13 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
int ey = (int) point.y;
int compare = getRadiusPoi(tileBox);
int radius = compare * 3 / 2;
for (OsmPoint n : plugin.getAllEdits()) {
compare = getFromPoint(tileBox, am, ex, ey, compare, radius, plugin.getDBBug().getOsmbugsPoints());
compare = getFromPoint(tileBox, am, ex, ey, compare, radius, plugin.getDBPOI().getOpenstreetmapPoints());
}
private int getFromPoint(RotatedTileBox tileBox, List<? super OsmPoint> am, int ex, int ey, int compare,
int radius, List<? extends OsmPoint> pnts) {
for (OsmPoint n : pnts) {
int x = (int) tileBox.getPixXFromLatLon(n.getLatitude(), n.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(n.getLatitude(), n.getLongitude());
if (calculateBelongs(ex, ey, x, y, compare)) {
@ -117,6 +123,7 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
am.add(n);
}
}
return compare;
}
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
@ -145,6 +152,28 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
}
return null;
}
@Override
public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
if (o instanceof OsmPoint) {
final OsmPoint r = (OsmPoint) o;
adapter.item(R.string.osm_edit_context_menu_delete).iconColor(R.drawable.ic_action_delete_dark
).listen(new ContextMenuAdapter.OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
if(r instanceof OsmNotesPoint) {
plugin.getDBBug().deleteAllBugModifications((OsmNotesPoint) r);
} else if(r instanceof OpenstreetmapPoint) {
plugin.getDBPOI().deletePOI((OpenstreetmapPoint) r);
}
view.refreshMap();
return true;
}
}).reg();
}
}
@Override
public String getObjectDescription(Object o) {

View file

@ -20,8 +20,6 @@ public class UploadOpenstreetmapPointAsyncTask extends AsyncTask<OsmPoint, OsmPo
private OsmBugsRemoteUtil remotebug;
private OpenstreetmapsDbHelper dbpoi;
private OsmBugsDbHelper dbbug;
private int listSize = 0;
@ -29,15 +27,18 @@ public class UploadOpenstreetmapPointAsyncTask extends AsyncTask<OsmPoint, OsmPo
private Fragment ctx;
public UploadOpenstreetmapPointAsyncTask(ProgressDialog progress,Fragment ctx, OpenstreetmapRemoteUtil remotepoi, OsmBugsRemoteUtil remotebug,
private OsmEditingPlugin plugin;
public UploadOpenstreetmapPointAsyncTask(ProgressDialog progress,Fragment ctx,
OsmEditingPlugin plugin,
OpenstreetmapRemoteUtil remotepoi, OsmBugsRemoteUtil remotebug,
int listSize) {
this.progress = progress;
this.plugin = plugin;
this.remotepoi = remotepoi;
this.remotebug = remotebug;
this.listSize = listSize;
this.ctx = ctx;
dbpoi = new OpenstreetmapsDbHelper(ctx.getActivity());
dbbug = new OsmBugsDbHelper(ctx.getActivity());
}
@Override
@ -56,7 +57,8 @@ public class UploadOpenstreetmapPointAsyncTask extends AsyncTask<OsmPoint, OsmPo
}
Node n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment(), false);
if (n != null) {
dbpoi.deletePOI(p);
plugin.getDBPOI().deletePOI(p);
publishProgress(p);
uploaded++;
}
@ -71,7 +73,7 @@ public class UploadOpenstreetmapPointAsyncTask extends AsyncTask<OsmPoint, OsmPo
success = remotebug.closingBug(p.getId(), p.getText(), p.getAuthor()) == null;
}
if (success) {
dbbug.deleteAllBugModifications(p);
plugin.getDBBug().deleteAllBugModifications(p);
uploaded++;
publishProgress(p);
}