From a92f33aee1ef8de75fe54429279d2e90a67c76b4 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 9 Jan 2012 01:14:43 +0100 Subject: [PATCH] Implement multi objects context menu. Add wiki scripts --- .../net/osmand/data/index/WikiIndexer.java | 2 +- .../osmand/plus/views/ContextMenuLayer.java | 60 ++++++++++++++----- .../net/osmand/plus/views/FavoritesLayer.java | 32 +++++----- .../net/osmand/plus/views/OsmBugsLayer.java | 28 +++++---- .../net/osmand/plus/views/POIMapLayer.java | 50 +++++++++------- .../plus/views/TransportStopsLayer.java | 27 +++++---- build-scripts/wiki/download.sh | 31 ++++------ build-scripts/wiki/download_coord.sh | 33 ++++++++++ 8 files changed, 172 insertions(+), 91 deletions(-) create mode 100644 build-scripts/wiki/download_coord.sh diff --git a/DataExtractionOSM/src/net/osmand/data/index/WikiIndexer.java b/DataExtractionOSM/src/net/osmand/data/index/WikiIndexer.java index e945c4c257..29757052a8 100644 --- a/DataExtractionOSM/src/net/osmand/data/index/WikiIndexer.java +++ b/DataExtractionOSM/src/net/osmand/data/index/WikiIndexer.java @@ -299,7 +299,7 @@ public class WikiIndexer { } } else if (name.equals("text")) { if(parseText) { - if(id % 50 == 0) { + if(id % 100 == 0) { log.debug("Article accepted " + cid + " " + title.toString()); } analyzeTextForGeoInfoNew(); diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 719abc88ef..8d844f5660 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -6,6 +6,8 @@ import java.util.List; import net.osmand.osm.LatLon; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; @@ -28,7 +30,7 @@ public class ContextMenuLayer extends OsmandMapLayer { public interface IContextMenuProvider { - public Object getPointObject(PointF point); + public void collectObjectsFromPoint(PointF point, List o); public LatLon getObjectLocation(Object o); @@ -42,7 +44,7 @@ public class ContextMenuLayer extends OsmandMapLayer { private LatLon latLon; private IContextMenuProvider selectedContextProvider; - private Object selectedObject; + private List selectedObjects = new ArrayList(); private TextView textView; private DisplayMetrics dm; @@ -157,11 +159,11 @@ public class ContextMenuLayer extends OsmandMapLayer { } selectedContextProvider = null; - selectedObject = null; + selectedObjects.clear(); for(OsmandMapLayer l : view.getLayers()){ if(l instanceof ContextMenuLayer.IContextMenuProvider){ - selectedObject = ((ContextMenuLayer.IContextMenuProvider) l).getPointObject(point); - if(selectedObject != null){ + ((ContextMenuLayer.IContextMenuProvider) l).collectObjectsFromPoint(point, selectedObjects); + if(!selectedObjects.isEmpty()){ selectedContextProvider = (IContextMenuProvider) l; break; } @@ -169,16 +171,18 @@ public class ContextMenuLayer extends OsmandMapLayer { } LatLon latLon = view.getLatLonFromScreenPoint(point.x, point.y); - String description = ""; + StringBuilder description = new StringBuilder(); - if(selectedObject != null){ - description = selectedContextProvider.getObjectDescription(selectedObject); - LatLon l = selectedContextProvider.getObjectLocation(selectedObject); + if(!selectedObjects.isEmpty()){ + for(Object o : selectedObjects) { + description.append(selectedContextProvider.getObjectDescription(o)); + } + LatLon l = selectedContextProvider.getObjectLocation(selectedObjects.get(0)); if(l != null){ latLon = l; } } - setLocation(latLon, description); + setLocation(latLon, description.toString()); view.refreshMap(); return true; } @@ -203,8 +207,8 @@ public class ContextMenuLayer extends OsmandMapLayer { } public String getSelectedObjectName(){ - if(selectedObject != null && selectedContextProvider != null){ - return selectedContextProvider.getObjectName(selectedObject); + if(!selectedObjects.isEmpty() && selectedContextProvider != null){ + return selectedContextProvider.getObjectName(selectedObjects); } return null; } @@ -212,10 +216,8 @@ public class ContextMenuLayer extends OsmandMapLayer { @Override public boolean onSingleTap(PointF point) { if (pressedInTextView(point.x, point.y)) { - if (selectedObject != null) { - ArrayList l = new ArrayList(); - OnClickListener listener = selectedContextProvider.getActionListener(l, selectedObject); - activity.contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), l, listener); + if (!selectedObjects.isEmpty()) { + showContextMenuForSelectedObjects(); } else { activity.contextMenuPoint(latLon.getLatitude(), latLon.getLongitude()); } @@ -224,6 +226,32 @@ public class ContextMenuLayer extends OsmandMapLayer { return false; } + private void showContextMenuForSelectedObjects() { + if(selectedObjects.size() > 1){ + Builder builder = new AlertDialog.Builder(view.getContext()); + String[] d = new String[selectedObjects.size()]; + int i =0; + for(Object o : selectedObjects) { + d[i++] = selectedContextProvider.getObjectDescription(o); + } + builder.setItems(d, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // single selection at 0 + selectedObjects.set(0, selectedObjects.get(which)); + ArrayList l = new ArrayList(); + OnClickListener listener = selectedContextProvider.getActionListener(l, selectedObjects.get(0)); + activity.contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), l, listener); + } + }); + builder.show(); + } else { + ArrayList l = new ArrayList(); + OnClickListener listener = selectedContextProvider.getActionListener(l, selectedObjects.get(0)); + activity.contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), l, listener); + } + } + @Override public boolean onTouchEvent(MotionEvent event) { diff --git a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java index 103b9d73e0..63d1baecbf 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java @@ -1,5 +1,6 @@ package net.osmand.plus.views; +import java.util.ArrayList; import java.util.List; import net.osmand.FavouritePoint; @@ -21,7 +22,6 @@ import android.widget.Toast; public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider { private static final int startZoom = 6; - private static final int radius = 15; private OsmandMapTileView view; private Paint paint; @@ -86,9 +86,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I return false; } - public FavouritePoint getFavoriteFromPoint(PointF point) { - FavouritePoint result = null; - float r = 100; + public void getFavoriteFromPoint(PointF point, List res) { + float r = 80; int ex = (int) point.x; int ey = (int) point.y; int w = favoriteIcon.getWidth() / 2; @@ -98,21 +97,26 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I int y = view.getRotatedMapYForPoint(n.getLatitude(), n.getLongitude()); if (Math.abs(x - ex) <= w && y - ey <= h && y - ey >= 0) { float newr = Math.max(Math.abs(x - ex), Math.abs(y - ey)); - if(newr < r){ - r = newr; - result = n; + if (newr < r) { + res.add(n); } } } - return result; } @Override public boolean onSingleTap(PointF point) { - FavouritePoint fav = getFavoriteFromPoint(point); - if(fav != null){ - String format = view.getContext().getString(R.string.favorite) + " : " + fav.getName(); //$NON-NLS-1$ - Toast.makeText(view.getContext(), format, Toast.LENGTH_LONG).show(); + List favs = new ArrayList(); + getFavoriteFromPoint(point, favs); + if(!favs.isEmpty()){ + StringBuilder res = new StringBuilder(); + for(FavouritePoint fav : favs) { + if(favs.size() > 1) { + res.append("\n"); + } + res.append(view.getContext().getString(R.string.favorite) + " : " + fav.getName()); //$NON-NLS-1$ + } + Toast.makeText(view.getContext(), res.toString(), Toast.LENGTH_LONG).show(); return true; } return false; @@ -142,8 +146,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I } @Override - public Object getPointObject(PointF point) { - return getFavoriteFromPoint(point); + public void collectObjectsFromPoint(PointF point, List res) { + getFavoriteFromPoint(point, res); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java index aa608dc739..d2e7c4be35 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java @@ -197,35 +197,41 @@ public class OsmBugsLayer extends OsmandMapLayer implements ContextMenuLayer.ICo return false; } - public OpenStreetBug getBugFromPoint(PointF point){ - OpenStreetBug result = null; + public void getBugFromPoint(PointF point, List res){ if (objects != null && view != null) { int ex = (int) point.x; int ey = (int) point.y; int radius = getRadiusBug(view.getZoom()) * 3 / 2; + int small = getRadiusBug(view.getZoom()) * 3 / 4; try { for (int i = 0; i < objects.size(); i++) { OpenStreetBug n = objects.get(i); int x = view.getRotatedMapXForPoint(n.getLatitude(), n.getLongitude()); int y = view.getRotatedMapYForPoint(n.getLatitude(), n.getLongitude()); if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) { - radius = Math.max(Math.abs(x - ex), Math.abs(y - ey)); - result = n; + radius = small; + res.add(n); } } } catch (IndexOutOfBoundsException e) { // that's really rare case, but is much efficient than introduce synchronized block } } - return result; } @Override public boolean onSingleTap(PointF point) { - OpenStreetBug bug = getBugFromPoint(point); - if(bug != null){ - String format = activity.getString(R.string.osb_bug_name)+ " : " + bug.getName(); //$NON-NLS-1$ - Toast.makeText(activity, format, Toast.LENGTH_LONG).show(); + ArrayList list = new ArrayList(); + getBugFromPoint(point, list); + if(!list.isEmpty()){ + StringBuilder res = new StringBuilder(); + for(OpenStreetBug o : list) { + if(list.size() > 1) { + res.append("\n"); + } + res.append(activity.getString(R.string.osb_bug_name)+ " : " + o.getName()); //$NON-NLS-1$ + } + Toast.makeText(activity, res.toString(), Toast.LENGTH_LONG).show(); return true; } return false; @@ -475,8 +481,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements ContextMenuLayer.ICo } @Override - public Object getPointObject(PointF point) { - return getBugFromPoint(point); + public void collectObjectsFromPoint(PointF point, List res) { + getBugFromPoint(point, res); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index a85f8c24d4..f2525dce2a 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -47,6 +47,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon private Paint point; private OsmandMapTileView view; private List objects = new ArrayList(); + private final static int MAXIMUM_SHOW_AMENITIES = 5; private ResourceManager resourceManager; private PoiFilter filter; @@ -66,46 +67,53 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon this.filter = filter; } - public Amenity getAmenityFromPoint(PointF point){ - Amenity result = null; + public void getAmenityFromPoint(PointF point, List am){ if (objects != null) { int ex = (int) point.x; int ey = (int) point.y; + int compare = getRadiusPoi(view.getZoom()); int radius = getRadiusPoi(view.getZoom()) * 3 / 2; try { for (int i = 0; i < objects.size(); i++) { Amenity n = objects.get(i); int x = view.getRotatedMapXForPoint(n.getLocation().getLatitude(), n.getLocation().getLongitude()); int y = view.getRotatedMapYForPoint(n.getLocation().getLatitude(), n.getLocation().getLongitude()); - if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) { - radius = Math.max(Math.abs(x - ex), Math.abs(y - ey)); - result = n; + if (Math.abs(x - ex) <= compare && Math.abs(y - ey) <= compare) { + compare = radius; + am.add(n); } } } catch (IndexOutOfBoundsException e) { // that's really rare case, but is much efficient than introduce synchronized block } } - return result; } @Override public boolean onSingleTap(PointF point) { - Amenity n = getAmenityFromPoint(point); - if(n != null){ - String format = OsmAndFormatter.getPoiSimpleFormat(n, view.getContext(), - view.getSettings().USE_ENGLISH_NAMES.get()); - if(n.getOpeningHours() != null){ - format += "\n" + view.getContext().getString(R.string.opening_hours) +" : "+ n.getOpeningHours(); //$NON-NLS-1$ //$NON-NLS-2$ + List am = new ArrayList(); + getAmenityFromPoint(point, am); + if(!am.isEmpty()){ + StringBuilder res = new StringBuilder(); + for (int i = 0; i < MAXIMUM_SHOW_AMENITIES && i < am.size(); i++) { + Amenity n = am.get(i); + if (i > 0) { + res.append("\n "); + } + String format = OsmAndFormatter.getPoiSimpleFormat(n, view.getContext(), view.getSettings().USE_ENGLISH_NAMES.get()); + res.append(" " + format); + if (n.getOpeningHours() != null) { + res.append("\n").append(view.getContext().getString(R.string.opening_hours)).append(" : ").append(n.getOpeningHours()); //$NON-NLS-1$ //$NON-NLS-2$ + } + if (n.getPhone() != null) { + res.append("\n").append(view.getContext().getString(R.string.phone)).append(" : ").append(n.getPhone()); //$NON-NLS-1$ //$NON-NLS-2$ + } + if (n.getSite() != null) { + res.append("\n").append(view.getContext().getString(R.string.website)).append(" : ").append(n.getSite()); //$NON-NLS-1$ //$NON-NLS-2$ + } } - if(n.getPhone() != null){ - format += "\n" + view.getContext().getString(R.string.phone) +" : "+ n.getPhone(); //$NON-NLS-1$ //$NON-NLS-2$ - } - if(n.getSite() != null){ - format += "\n" + view.getContext().getString(R.string.website) +" : "+ n.getSite(); //$NON-NLS-1$ //$NON-NLS-2$ - } - Toast.makeText(view.getContext(), format, Toast.LENGTH_SHORT).show(); + Toast.makeText(view.getContext(), res.toString(), Toast.LENGTH_SHORT).show(); return true; } return false; @@ -364,8 +372,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } @Override - public Object getPointObject(PointF point) { - return getAmenityFromPoint(point); + public void collectObjectsFromPoint(PointF point, List objects) { + getAmenityFromPoint(point, objects); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java index 5408353f0c..a71eb3fe30 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java @@ -40,27 +40,26 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa pointAltUI.setAntiAlias(true); } - public TransportStop getFromPoint(PointF point){ - TransportStop result = null; + public void getFromPoint(PointF point, List res) { if (objects != null) { int ex = (int) point.x; int ey = (int) point.y; int radius = getRadiusPoi(view.getZoom()) * 3 / 2; + int small = getRadiusPoi(view.getZoom()); try { for (int i = 0; i < objects.size(); i++) { TransportStop n = objects.get(i); int x = view.getRotatedMapXForPoint(n.getLocation().getLatitude(), n.getLocation().getLongitude()); int y = view.getRotatedMapYForPoint(n.getLocation().getLatitude(), n.getLocation().getLongitude()); if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) { - radius = Math.max(Math.abs(x - ex), Math.abs(y - ey)); - result = n; + radius = small; + res.add(n); } } } catch (IndexOutOfBoundsException e) { // that's really rare case, but is much efficient than introduce synchronized block } } - return result; } @@ -69,9 +68,17 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa @Override public boolean onSingleTap(PointF point) { - TransportStop n = getFromPoint(point); - if(n != null){ - Toast.makeText(view.getContext(), getStopDescription(n, true), Toast.LENGTH_LONG).show(); + ArrayList stops = new ArrayList(); + getFromPoint(point, stops); + if(stops.isEmpty()){ + StringBuilder res = new StringBuilder(); + for (TransportStop n : stops) { + if(stops.size() > 1) { + res.append("\n"); + } + res.append(getStopDescription(n, true)); + } + Toast.makeText(view.getContext(), res.toString(), Toast.LENGTH_LONG).show(); return true; } return false; @@ -172,8 +179,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa } @Override - public Object getPointObject(PointF point) { - return getFromPoint(point); + public void collectObjectsFromPoint(PointF point, List res) { + getFromPoint(point, res); } @Override diff --git a/build-scripts/wiki/download.sh b/build-scripts/wiki/download.sh index 5805c4d69d..6aa53395a7 100644 --- a/build-scripts/wiki/download.sh +++ b/build-scripts/wiki/download.sh @@ -1,20 +1,15 @@ -#!/bin/sh +#!/bin/bash function download { - wget -o download.log http://dumps.wikimedia.org/"$1"wiki/latest/"$1"wiki-latest-pages-articles.xml.bz2 + echo "Start download $2"; + wget --quiet --output-document="$2"_wiki_1."$1".xml.bz2 http://dumps.wikimedia.org/"$1"wiki/latest/"$1"wiki-latest-pages-articles.xml.bz2 } -# Arabic -download ar -# English -download en -# Spanish -download es -# Portuguese -download pt -# French -download fr -# German -download de -# Russian -download ru - - +cd src; +download en English; +download de Deutch; +download nl Netherlands; +download fr French; +download ru Russian; +download es Spanish; +download it Italian; +download pt Portuguese; +download ja Japanese; diff --git a/build-scripts/wiki/download_coord.sh b/build-scripts/wiki/download_coord.sh new file mode 100644 index 0000000000..31a33961f7 --- /dev/null +++ b/build-scripts/wiki/download_coord.sh @@ -0,0 +1,33 @@ +#!/bin/bash +function download_coord { + + echo "Start download $1" + wget --quiet --output-document="$1"wiki.sql.gz http://toolserver.org/~dispenser/dumps/coord_"$1"wiki.sql.gz + echo "Start import $1"; + gunzip -c "$1"wiki.sql.gz | mysql wiki; +} + +cd src_sql; +download_coord en; +download_coord de; +download_coord nl; +download_coord fr; +download_coord ru; +download_coord es; +download_coord pl; +download_coord it; +download_coord ca; +download_coord pt; +download_coord uk; +download_coord ja; +download_coord vo; +download_coord vi; +download_coord eu; +download_coord no; +download_coord da; +download_coord sv; +download_coord sr; +download_coord eo; +download_coord ro; +download_coord lt; +