Implement multi objects context menu. Add wiki scripts

This commit is contained in:
Victor Shcherb 2012-01-09 01:14:43 +01:00
parent 77f9064258
commit a92f33aee1
8 changed files with 172 additions and 91 deletions

View file

@ -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();

View file

@ -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<Object> 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<Object> selectedObjects = new ArrayList<Object>();
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<String> l = new ArrayList<String>();
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<String> l = new ArrayList<String>();
OnClickListener listener = selectedContextProvider.getActionListener(l, selectedObjects.get(0));
activity.contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), l, listener);
}
});
builder.show();
} else {
ArrayList<String> l = new ArrayList<String>();
OnClickListener listener = selectedContextProvider.getActionListener(l, selectedObjects.get(0));
activity.contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), l, listener);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {

View file

@ -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<? super FavouritePoint> 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<FavouritePoint> favs = new ArrayList<FavouritePoint>();
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<Object> res) {
getFavoriteFromPoint(point, res);
}
@Override

View file

@ -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<? super OpenStreetBug> 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<OpenStreetBug> list = new ArrayList<OpenStreetBug>();
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<Object> res) {
getBugFromPoint(point, res);
}
@Override

View file

@ -47,6 +47,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
private Paint point;
private OsmandMapTileView view;
private List<Amenity> objects = new ArrayList<Amenity>();
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<? super Amenity> 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<Amenity> am = new ArrayList<Amenity>();
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<Object> objects) {
getAmenityFromPoint(point, objects);
}
@Override

View file

@ -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<? super TransportStop> 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<TransportStop> stops = new ArrayList<TransportStop >();
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<Object> res) {
getFromPoint(point, res);
}
@Override

View file

@ -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;

View file

@ -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;