Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-03-10 19:50:15 +01:00
commit 33360db55d
23 changed files with 286 additions and 134 deletions

View file

@ -1,25 +1,19 @@
package net.osmand.access;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import android.graphics.PointF;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import android.graphics.PointF;
import android.os.Build;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import java.util.List;
import java.util.Map;
// Provide touch exploration mode for map view
// when scrolling it by gestures is disabled.
@ -91,6 +85,11 @@ public class MapExplorer extends SimpleOnGestureListener implements IContextMenu
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects) {
int radius = (int)(VICINITY_RADIUS * tileBox.getDensity());

View file

@ -90,14 +90,18 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
final QuadRect latlon = tileBox.getLatLonBounds();
List<Recording> objects = recs.getObjects(latlon.top, latlon.left, latlon.bottom, latlon.right);
List<Recording> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
for (Recording o : objects) {
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
} else {
fullObjects.add(o);
fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
}
}
for (Recording o : fullObjects) {
@ -113,6 +117,8 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
}
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
@ -156,6 +162,11 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return o instanceof Recording;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects) {
getRecordingsFromPoint(point, tileBox, objects);

View file

@ -587,6 +587,11 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
return distanceMeasurementMode == 1;
}
@Override
public boolean isObjectClickable(Object o) {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getMPointsFromPoint(tileBox, point, o);

View file

@ -737,6 +737,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
}
}
public boolean supportZoomIn() {
return menuController == null || menuController.supportZoomIn();
}
public boolean fabVisible() {
return menuController == null || menuController.fabVisible();
}

View file

@ -231,14 +231,14 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
moving = false;
int posY = getViewY();
if (!centered) {
if (!zoomIn) {
if (!zoomIn && menu.supportZoomIn()) {
LatLon centerLatLon = map.getCurrentRotatedTileBox().getCenterLatLon();
if (centerLatLon.equals(menu.getLatLon())) {
zoomIn = true;
}
}
centerMarkerLocation();
} else if (!zoomIn) {
} else if (!zoomIn && menu.supportZoomIn()) {
int fZoom = getZoom();
zoomIn = true;
if (fZoom < ZOOM_IN_STANDARD) {

View file

@ -236,6 +236,10 @@ public abstract class MenuController extends BaseMenuController {
return titleProgressController;
}
public boolean supportZoomIn() {
return true;
}
public boolean fabVisible() {
return true;
}

View file

@ -8,6 +8,7 @@ import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.widget.Toast;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
@ -22,6 +23,7 @@ import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject;
@ -41,17 +43,23 @@ public class MapDataMenuController extends MenuController {
private List<IndexItem> otherIndexItems;
private boolean srtmDisabled;
private boolean srtmNeedsInstallation;
boolean downloaded;
private DownloadIndexesThread downloadThread;
private ResourceManager rm;
public MapDataMenuController(OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, final DownloadMapObject mapObject) {
super(new MenuBuilder(app), pointDescription, mapActivity);
this.mapObject = mapObject;
rm = app.getResourceManager();
indexItem = mapObject.getIndexItem();
downloadThread = app.getDownloadThread();
if (indexItem != null) {
downloaded = indexItem.isDownloaded();
otherIndexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(mapObject.getWorldRegion()));
otherIndexItems.remove(indexItem);
} else {
downloaded = checkIfObjectDownloaded(rm.getOsmandRegions().getDownloadName(mapObject.getDataObject()));
}
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
@ -93,6 +101,14 @@ public class MapDataMenuController extends MenuController {
public void buttonPressed() {
if (indexItem != null) {
deleteItem();
} else if (downloaded) {
/*
File f = new File(info.getPathToData());
boolean successfull = Algorithms.removeAllFiles(f);
if (successfull) {
getMapActivity().getMyApplication().getResourceManager().closeFile(info.getFileName());
}
*/
}
}
};
@ -215,6 +231,11 @@ public class MapDataMenuController extends MenuController {
}
}
@Override
public boolean supportZoomIn() {
return false;
}
@Override
public boolean fabVisible() {
return false;
@ -254,7 +275,7 @@ public class MapDataMenuController extends MenuController {
}
}
rightTitleButtonController.visible = indexItem != null && indexItem.isDownloaded();
rightTitleButtonController.visible = downloaded;
topRightTitleButtonController.visible = otherIndexItems.size() > 0;
boolean downloadIndexes = getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable()
@ -332,4 +353,12 @@ public class MapDataMenuController extends MenuController {
confirm.show();
}
}
private boolean checkIfObjectDownloaded(String downloadName) {
final String regionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_MAP_INDEX_EXT;
final String roadsRegionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + ".road"
+ IndexConstants.BINARY_MAP_INDEX_EXT;
return rm.getIndexFileNames().containsKey(regionName) || rm.getIndexFileNames().containsKey(roadsRegionName);
}
}

View file

@ -133,6 +133,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
float iconSize = resolvedNote.getWidth() * 3 / 2.5f;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
List<OpenStreetNote> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
for (OpenStreetNote o : objects) {
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
@ -145,8 +147,10 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
b = resolvedNoteSmall;
}
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
} else {
fullObjects.add(o);
fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
}
}
for (OpenStreetNote o : fullObjects) {
@ -160,6 +164,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
}
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
}
@ -519,6 +525,11 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return o instanceof OpenStreetNote;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
getBugFromPoint(tileBox, point, res);

View file

@ -15,6 +15,7 @@ import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import java.util.ArrayList;
import java.util.List;
/**
@ -61,6 +62,7 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
}
private void drawPoints(Canvas canvas, RotatedTileBox tileBox, List<? extends OsmPoint> objects) {
List<LatLon> fullObjectsLatLon = new ArrayList<>();
for (OsmPoint o : objects) {
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
@ -73,7 +75,9 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
b = poi;
}
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
}
this.fullObjectsLatLon = fullObjectsLatLon;
}
@Override
@ -133,6 +137,11 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return o instanceof OsmPoint;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getOsmEditsFromPoint(point, tileBox, o);

View file

@ -208,6 +208,11 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return o instanceof OsMoDevice;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getOsmoFromPoint(tileBox, point, o);

View file

@ -113,6 +113,11 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return o == getParkingPoint();
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getParkingFromPoint(tileBox, point, o);

View file

@ -40,6 +40,11 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {

View file

@ -14,20 +14,14 @@ import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import net.osmand.CallbackWithObject;
import net.osmand.data.Amenity;
import net.osmand.data.FavouritePoint;
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.audionotes.AudioVideoNotesPlugin.Recording;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
import net.osmand.plus.osmedit.OsmBugsLayer.OpenStreetNote;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import java.util.ArrayList;
import java.util.HashMap;
@ -49,6 +43,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
boolean disableSingleTap();
boolean disableLongPressOnMap();
boolean isObjectClickable(Object o);
}
public interface IContextMenuProviderSelection {
@ -70,7 +66,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
private ImageView contextMarker;
private Paint paint;
private Bitmap pressedBitmap;
private LatLon pressedLatLon;
private Bitmap pressedBitmapSmall;
private List<LatLon> pressedLatLonFull = new ArrayList<>();
private List<LatLon> pressedLatLonSmall = new ArrayList<>();
private GestureDetector movementListener;
@ -99,6 +97,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
paint = new Paint();
pressedBitmap = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_shield_tap);
pressedBitmapSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_shield_tap_small);
}
public boolean isVisible() {
@ -107,9 +106,14 @@ public class ContextMenuLayer extends OsmandMapLayer {
@Override
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
if (pressedLatLon != null) {
int x = (int) box.getPixXFromLatLon(pressedLatLon.getLatitude(), pressedLatLon.getLongitude());
int y = (int) box.getPixYFromLatLon(pressedLatLon.getLatitude(), pressedLatLon.getLongitude());
for (LatLon latLon : pressedLatLonSmall) {
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
canvas.drawBitmap(pressedBitmapSmall, x - pressedBitmapSmall.getWidth() / 2, y - pressedBitmapSmall.getHeight() / 2, paint);
}
for (LatLon latLon : pressedLatLonFull) {
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
canvas.drawBitmap(pressedBitmap, x - pressedBitmap.getWidth() / 2, y - pressedBitmap.getHeight() / 2, paint);
}
@ -162,7 +166,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point);
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false);
if (selectedObjects.size() == 1) {
Object selectedObj = selectedObjects.keySet().iterator().next();
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
@ -229,7 +233,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
return res;
}
private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point) {
private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox,
PointF point, boolean acquireObjLatLon) {
List<LatLon> pressedLatLonFull = new ArrayList<>();
List<LatLon> pressedLatLonSmall = new ArrayList<>();
Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>();
List<Object> s = new ArrayList<>();
for (OsmandMapLayer lt : view.getLayers()) {
@ -239,9 +246,21 @@ public class ContextMenuLayer extends OsmandMapLayer {
l.collectObjectsFromPoint(point, tileBox, s);
for (Object o : s) {
selectedObjects.put(o, l);
if (acquireObjLatLon && l.isObjectClickable(o)) {
LatLon latLon = l.getObjectLocation(o);
if (lt.isPresentInFullObjects(latLon) && !pressedLatLonFull.contains(latLon)) {
pressedLatLonFull.add(latLon);
} else if (lt.isPresentInSmallObjects(latLon) && !pressedLatLonSmall.contains(latLon)) {
pressedLatLonSmall.add(latLon);
}
}
}
}
}
if (acquireObjLatLon) {
this.pressedLatLonFull = pressedLatLonFull;
this.pressedLatLonSmall = pressedLatLonSmall;
}
return selectedObjects;
}
@ -316,29 +335,15 @@ public class ContextMenuLayer extends OsmandMapLayer {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
PointF point = new PointF(event.getX(), event.getY());
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point);
if (selectedObjects.size() == 1) {
Object selectedObj = selectedObjects.keySet().iterator().next();
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
LatLon latLon = null;
PointDescription pointDescription = null;
if (contextObject != null) {
latLon = contextObject.getObjectLocation(selectedObj);
pointDescription = contextObject.getObjectName(selectedObj);
}
if (latLon == null) {
latLon = getLatLon(point, tileBox);
}
if (isObjectClickable(selectedObj, pointDescription)) {
pressedLatLon = latLon;
view.refreshMap();
}
selectObjectsForContextMenu(tileBox, new PointF(event.getX(), event.getY()), true);
if (pressedLatLonFull.size() > 0 || pressedLatLonSmall.size() > 0) {
view.refreshMap();
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
pressedLatLon = null;
pressedLatLonFull.clear();
pressedLatLonSmall.clear();
view.refreshMap();
break;
}
@ -346,30 +351,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
return false;
}
private boolean isObjectClickable(Object object, PointDescription pointDescription) {
boolean res;
if (pointDescription != null) {
res = pointDescription.isParking()
|| pointDescription.isFavorite()
|| pointDescription.isAudioNote()
|| pointDescription.isPhotoNote()
|| pointDescription.isVideoNote()
|| pointDescription.isPoi()
|| object instanceof OsmPoint
|| object instanceof FavouritePoint
|| object instanceof OsMoDevice
|| object instanceof OpenStreetNote;
} else {
res = object instanceof Amenity
|| object instanceof Recording
|| object instanceof OsmPoint
|| object instanceof FavouritePoint
|| object instanceof OsMoDevice
|| object instanceof OpenStreetNote;
}
return res;
}
private class MenuLayerOnGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override

View file

@ -2,7 +2,6 @@ package net.osmand.plus.views;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Join;
@ -495,6 +494,11 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return false;
}
private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List<? super DownloadMapObject> dataObjects) {
int zoom = tb.getZoom();
if (zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION

View file

@ -101,6 +101,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
// request to load
final QuadRect latLonBounds = tileBox.getLatLonBounds();
List<LocationPoint> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
for (LocationPoint o : getPoints()) {
if (!o.isVisible()) {
continue;
@ -112,13 +114,17 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
int col = o.getColor() == 0 || o.getColor() == Color.BLACK ? defaultColor : o.getColor();
paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY));
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
} else {
fullObjects.add(o);
fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
}
}
for (LocationPoint o : fullObjects) {
drawPoint(canvas, tileBox, latLonBounds, o);
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
if(textLayer.isVisible()) {
@ -196,6 +202,11 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return o instanceof LocationPoint;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
if (this.settings.SHOW_FAVORITES.get() && tileBox.getZoom() >= startZoom) {

View file

@ -13,7 +13,6 @@ import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.support.annotation.NonNull;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
@ -286,6 +285,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
for (SelectedGpxFile g : selectedGPXFiles) {
List<WptPt> pts = getListStarPoints(g);
List<WptPt> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
int fcolor = g.getColor() == 0 ? defPointColor : g.getColor();
for (WptPt o : pts) {
if (o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top
@ -299,8 +300,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
int col = visit ? visitedColor : o.getColor(fcolor);
paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY));
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
smallObjectsLatLon.add(new LatLon(o.lat, o.lon));
} else {
fullObjects.add(o);
fullObjectsLatLon.add(new LatLon(o.lat, o.lon));
}
}
}
@ -312,6 +315,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), pointColor, true);
fid.drawBitmapInCenter(canvas, x, y);
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
}
@ -470,6 +475,11 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return o instanceof WptPt;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
getWptFromPoint(tileBox, point, res);

View file

@ -10,7 +10,6 @@ import android.widget.ArrayAdapter;
import net.osmand.Location;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
@ -111,6 +110,11 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements ContextMenuL
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
int ex = (int) point.x;

View file

@ -385,6 +385,11 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();

View file

@ -1,10 +1,11 @@
package net.osmand.plus.views;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.view.MotionEvent;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
@ -12,52 +13,73 @@ import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.util.MapAlgorithms;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.MotionEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import gnu.trove.list.array.TIntArrayList;
public abstract class OsmandMapLayer {
protected List<LatLon> fullObjectsLatLon;
protected List<LatLon> smallObjectsLatLon;
public abstract void initLayer(OsmandMapTileView view);
public abstract void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings);
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}
public abstract void destroyLayer();
public void onRetainNonConfigurationInstance(Map<String, Object> map) {}
public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter) {}
public abstract void destroyLayer();
public void onRetainNonConfigurationInstance(Map<String, Object> map) {
}
public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter) {
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
return false;
}
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
return false;
}
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { return false;}
public <Params> void executeTaskInBackground(AsyncTask<Params, ?, ?> task, Params... params){
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
return false;
}
public <Params> void executeTaskInBackground(AsyncTask<Params, ?, ?> task, Params... params) {
task.execute(params);
}
public boolean isPresentInFullObjects(LatLon latLon) {
if (fullObjectsLatLon == null) {
return true;
} else if (latLon != null) {
return fullObjectsLatLon.contains(latLon);
}
return false;
}
public boolean isPresentInSmallObjects(LatLon latLon) {
if (smallObjectsLatLon != null && latLon != null) {
return smallObjectsLatLon.contains(latLon);
}
return false;
}
/**
* This method returns whether canvas should be rotated as
* This method returns whether canvas should be rotated as
* map rotated before {@link #onDraw(android.graphics.Canvas, net.osmand.data.RotatedTileBox, net.osmand.plus.views.OsmandMapLayer.DrawSettings)}.
* If the layer draws simply layer over screen (not over map)
* it should return true.
*/
public abstract boolean drawInScreenPixels();
public static class DrawSettings {
private final boolean nightMode;
private final boolean updateVectorRendering;
@ -70,23 +92,23 @@ public abstract class OsmandMapLayer {
this.nightMode = nightMode;
this.updateVectorRendering = updateVectorRendering;
}
public boolean isUpdateVectorRendering() {
return updateVectorRendering;
}
public boolean isNightMode() {
return nightMode;
}
}
private boolean isIn(int x, int y, int lx, int ty, int rx, int by) {
return x >= lx && x <= rx && y >= ty && y <= by;
}
public int calculateSplitPaths(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys,
TIntArrayList results) {
TIntArrayList results) {
int px = xs.get(0);
int py = ys.get(0);
int h = tb.getPixHeight();
@ -94,12 +116,12 @@ public abstract class OsmandMapLayer {
int cnt = 0;
boolean pin = isIn(px, py, 0, 0, w, h);
Path path = null;
for(int i = 1; i < xs.size(); i++) {
for (int i = 1; i < xs.size(); i++) {
int x = xs.get(i);
int y = ys.get(i);
boolean in = isIn(x, y, 0, 0, w, h);
boolean draw = false;
if(pin && in) {
if (pin && in) {
draw = true;
} else {
long intersection = MapAlgorithms.calculateIntersection(x, y,
@ -121,7 +143,7 @@ public abstract class OsmandMapLayer {
}
return cnt;
}
public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path) {
boolean start = false;
int px = xs.get(0);
@ -130,12 +152,12 @@ public abstract class OsmandMapLayer {
int w = tb.getPixWidth();
int cnt = 0;
boolean pin = isIn(px, py, 0, 0, w, h);
for(int i = 1; i < xs.size(); i++) {
for (int i = 1; i < xs.size(); i++) {
int x = xs.get(i);
int y = ys.get(i);
boolean in = isIn(x, y, 0, 0, w, h);
boolean draw = false;
if(pin && in) {
if (pin && in) {
draw = true;
} else {
long intersection = MapAlgorithms.calculateIntersection(x, y,
@ -153,7 +175,7 @@ public abstract class OsmandMapLayer {
}
path.lineTo(x, y);
start = true;
} else{
} else {
start = false;
}
pin = in;
@ -166,7 +188,7 @@ public abstract class OsmandMapLayer {
@NonNull
public QuadTree<QuadRect> initBoundIntersections(RotatedTileBox tileBox) {
QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight());
bounds.inset(-bounds.width()/4, -bounds.height()/4);
bounds.inset(-bounds.width() / 4, -bounds.height() / 4);
return new QuadTree<>(bounds, 4, 0.6f);
}
@ -200,23 +222,23 @@ public abstract class OsmandMapLayer {
protected T results;
protected Task currentTask;
protected Task pendingTask;
public RotatedTileBox getQueriedBox() {
return queriedBox;
}
public T getResults() {
return results;
}
public boolean queriedBoxContains(final RotatedTileBox queriedData, final RotatedTileBox newBox) {
return queriedData != null && queriedData.containsTileBox(newBox) && Math.abs(queriedData.getZoom() - newBox.getZoom()) <= ZOOM_THRESHOLD;
}
public void queryNewData(RotatedTileBox tileBox) {
if (!queriedBoxContains(queriedBox, tileBox) ) {
if (!queriedBoxContains(queriedBox, tileBox)) {
Task ct = currentTask;
if(ct == null || !queriedBoxContains(ct.getDataBox(), tileBox)) {
if (ct == null || !queriedBoxContains(ct.getDataBox(), tileBox)) {
RotatedTileBox original = tileBox.copy();
RotatedTileBox extended = original.copy();
extended.increasePixelDimensions(tileBox.getPixWidth() / 2, tileBox.getPixHeight() / 2);
@ -225,41 +247,41 @@ public abstract class OsmandMapLayer {
executeTaskInBackground(task);
} else {
pendingTask = task;
}
}
}
}
}
public void layerOnPostExecute() {
}
public boolean isInterrupted() {
return pendingTask != null;
}
protected abstract T calculateResult(RotatedTileBox tileBox);
public class Task extends AsyncTask<Object, Object, T> {
private RotatedTileBox dataBox;
private RotatedTileBox requestedBox;
public Task(RotatedTileBox requestedBox, RotatedTileBox dataBox) {
this.requestedBox = requestedBox;
this.dataBox = dataBox;
}
public RotatedTileBox getOriginalBox() {
return requestedBox;
}
public RotatedTileBox getDataBox() {
return dataBox;
}
@Override
protected T doInBackground(Object... params) {
if (queriedBoxContains(queriedBox, dataBox) ) {
if (queriedBoxContains(queriedBox, dataBox)) {
return null;
}
return calculateResult(dataBox);
@ -289,9 +311,9 @@ public abstract class OsmandMapLayer {
public void clearCache() {
results = null;
queriedBox = null;
}
}
}

View file

@ -232,6 +232,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
List<Amenity> objects = Collections.emptyList();
List<Amenity> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
if (filter != null) {
if (tileBox.getZoom() >= startZoom) {
data.queryNewData(tileBox);
@ -248,8 +250,12 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(poiBackgroundSmall, x - poiBackgroundSmall.getWidth() / 2, y - poiBackgroundSmall.getHeight() / 2, paintIconBackground);
smallObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(),
o.getLocation().getLongitude()));
} else {
fullObjects.add(o);
fullObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(),
o.getLocation().getLongitude()));
}
}
for (Amenity o : fullObjects) {
@ -274,6 +280,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
}
}
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
}
@ -510,6 +518,11 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
return null;
}
@Override
public boolean isObjectClickable(Object o) {
return o instanceof Amenity;
}
@Override
public LatLon getTextLocation(Amenity o) {
return o.getLocation();

View file

@ -194,6 +194,11 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return false;
}
private LatLon getMyLocation() {
Location location = locationProvider.getLastKnownLocation();
if (location != null) {

View file

@ -172,7 +172,12 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
public boolean disableLongPressOnMap() {
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
TargetPointsHelper tg = map.getMyApplication().getTargetPointsHelper();

View file

@ -198,6 +198,11 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
getFromPoint(tileBox, point, res);