Fix - single tap

This commit is contained in:
Alexey Kulish 2015-08-27 13:28:25 +03:00
parent 593d01de94
commit 13c88acfd6
16 changed files with 204 additions and 185 deletions

View file

@ -134,6 +134,16 @@ public class MapExplorer implements OnGestureListener, IContextMenuProvider {
// IContextMenuProvider interface implementation.
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects) {
int radius = (int)(VICINITY_RADIUS * tileBox.getDensity());

View file

@ -291,7 +291,7 @@ public class MapActivityLayers {
private void addFilterToList(final ContextMenuAdapter adapter, final List<PoiUIFilter> list, PoiUIFilter f) {
list.add(f);
Item it = adapter.item(f.getName());
Item it = adapter.item(f.getName()).selected(0);
if (RenderingIcons.containsBigIcon(f.getSimplifiedId())) {
it.icon(RenderingIcons.getBigIconResourceId(f.getSimplifiedId()));
} else {

View file

@ -180,6 +180,16 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
return null;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects) {
getRecordingsFromPoint(point, tileBox, objects);
@ -203,21 +213,6 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ;
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
ArrayList<Recording> o = new ArrayList<Recording>();
getRecordingsFromPoint(point, tileBox, o);
if(o.size() > 0){
StringBuilder b = new StringBuilder();
for(Recording r : o) {
b.append(getObjectDescription(r)).append('\n');
}
AccessibleToast.makeText(activity, b.toString().trim(), Toast.LENGTH_LONG).show();
return true;
}
return false;
}
@Override
public LatLon getObjectLocation(Object o) {

View file

@ -74,7 +74,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
private GPXFile originalGPX;
private String distance = null;
private int distanceMeasurementMode = 0;
private int distanceMeasurementMode = 0;
public DistanceCalculatorPlugin(OsmandApplication app) {
this.app = app;
@ -491,7 +491,11 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
@Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
if (distanceMeasurementMode == 1 && measurementPoints.size() > 0) {
List<Object> s = new ArrayList<>();
collectObjectsFromPoint(point, tileBox, s);
if (s.size() == 0 && distanceMeasurementMode == 1 && measurementPoints.size() > 0) {
LinkedList<WptPt> lt = measurementPoints.get(measurementPoints.size() - 1);
if (lt.size() > 0) {
lt.removeLast();
@ -564,6 +568,16 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
return false;
}
@Override
public boolean disableSingleTap() {
return distanceMeasurementMode == 1;
}
@Override
public boolean disableLongPressOnMap() {
return distanceMeasurementMode == 1;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getMPointsFromPoint(tileBox, point, o);

View file

@ -198,25 +198,6 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
ArrayList<OpenStreetNote> list = new ArrayList<OpenStreetNote>();
getBugFromPoint(tileBox, point, list);
if(!list.isEmpty()){
StringBuilder res = new StringBuilder();
int i = 0;
for(OpenStreetNote o : list) {
if (i++ > 0) {
res.append("\n\n");
}
res.append(activity.getString(R.string.osb_bug_name)+ " : " + o.getCommentDescription()); //$NON-NLS-1$
}
AccessibleToast.makeText(activity, res.toString(), Toast.LENGTH_LONG).show();
return true;
}
return false;
}
public void clearCache() {
if(data != null) {
data.clearCache();
@ -345,7 +326,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
builder.setNegativeButton(R.string.shared_string_cancel, null);
((EditText)openBug.findViewById(R.id.passwordEditText)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
((EditText)openBug.findViewById(R.id.userNameEditText)).setText(getUserName());
AndroidUtils.softKeyboardDelayed((EditText)openBug.findViewById(R.id.messageEditText));
AndroidUtils.softKeyboardDelayed((EditText) openBug.findViewById(R.id.messageEditText));
builder.setPositiveButton(R.string.shared_string_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@ -554,6 +535,16 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
return null;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
getBugFromPoint(tileBox, point, res);

View file

@ -140,6 +140,16 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
return (int) (r * tb.getDensity());
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getOsmEditsFromPoint(point, tileBox, o);

View file

@ -190,21 +190,6 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
}
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
List<OsMoDevice> pos = new ArrayList<OsMoDevice>();
getOsmoFromPoint(tileBox, point, pos);
if (!pos.isEmpty()) {
StringBuilder res = new StringBuilder();
for (OsMoDevice d : pos) {
res.append(getObjectDescription(d)).append("\n");
}
AccessibleToast.makeText(view.getContext(), res.toString().trim(), Toast.LENGTH_LONG).show();
return true;
}
return false;
}
@Override
public void destroyLayer() {
@ -215,6 +200,16 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
return false;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getOsmoFromPoint(tileBox, point, o);

View file

@ -97,19 +97,6 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
List <LatLon> parkPos = new ArrayList<LatLon>();
getParkingFromPoint(tileBox, point, parkPos);
if(!parkPos.isEmpty()){
StringBuilder res = new StringBuilder();
res.append(view.getContext().getString(R.string.osmand_parking_position_description));
AccessibleToast.makeText(view.getContext(), getObjectDescription(getParkingPoint()), Toast.LENGTH_LONG).show();
return true;
}
return false;
}
@Override
public void destroyLayer() {
}
@ -119,6 +106,16 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
return false;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getParkingFromPoint(tileBox, point, o);

View file

@ -30,6 +30,16 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye
this.plugin = plugin;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {

View file

@ -33,7 +33,7 @@ import android.widget.TextView;
public class ContextMenuLayer extends OsmandMapLayer {
public interface IContextMenuProvider {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o);
public LatLon getObjectLocation(Object o);
@ -41,8 +41,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
public String getObjectDescription(Object o);
public PointDescription getObjectName(Object o);
public boolean disableSingleTap();
public boolean disableLongPressOnMap();
}
public interface IContextMenuProviderSelection {
@ -226,16 +227,53 @@ public class ContextMenuLayer extends OsmandMapLayer {
view.refreshMap();
return true;
}
LatLon latLon = selectObjectsForContextMenu(tileBox, point);
String description = getSelectedObjectDescription();
setLocation(latLon, description);
if (disableLongPressOnMap()) {
LatLon latLon = selectObjectsForContextMenu(tileBox, point);
if (latLon != null) {
String description = getSelectedObjectDescription();
setLocation(latLon, description);
view.refreshMap();
return true;
} else {
return false;
}
}
final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y);
final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y);
setLocation(new LatLon(lat, lon), null);
view.refreshMap();
return true;
}
public boolean disableSingleTap() {
boolean res = false;
for(OsmandMapLayer lt : view.getLayers()){
if(lt instanceof ContextMenuLayer.IContextMenuProvider) {
if (((IContextMenuProvider) lt).disableSingleTap()) {
res = true;
break;
}
}
}
return res;
}
public boolean disableLongPressOnMap() {
boolean res = false;
for(OsmandMapLayer lt : view.getLayers()){
if(lt instanceof ContextMenuLayer.IContextMenuProvider) {
if (((IContextMenuProvider) lt).disableLongPressOnMap()) {
res = true;
break;
}
}
}
return res;
}
public LatLon selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point) {
final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y);
final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y);
clearSelectedObjects();
List<Object> s = new ArrayList<Object>();
LatLon latLon = null;
@ -250,17 +288,14 @@ public class ContextMenuLayer extends OsmandMapLayer {
((IContextMenuProviderSelection) l).setSelectedObject(o);
}
if(latLon == null) {
latLon = ((ContextMenuLayer.IContextMenuProvider) l).getObjectLocation(o);
latLon = l.getObjectLocation(o);
}
}
}
}
if(latLon == null) {
latLon = new LatLon(lat, lon);
}
return latLon;
}
@Override
public boolean drawInScreenPixels() {
return true;
@ -355,6 +390,14 @@ public class ContextMenuLayer extends OsmandMapLayer {
activity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude());
}
return true;
} else if (!disableSingleTap()) {
LatLon latLon = selectObjectsForContextMenu(tileBox, point);
if (latLon != null) {
String description = getSelectedObjectDescription();
setLocation(latLon, description);
view.refreshMap();
return true;
}
}
return false;
}

View file

@ -290,11 +290,6 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
return false;
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
return false;
}
@Override

View file

@ -152,26 +152,6 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
List<LocationPoint> favs = new ArrayList<LocationPoint>();
getFavoriteFromPoint(tileBox, point, favs);
if(!favs.isEmpty() && (tileBox.getZoom() > 14 || favs.size() < 6)){
StringBuilder res = new StringBuilder();
int i = 0;
for(LocationPoint fav : favs) {
if (i++ > 0) {
res.append("\n");
}
res.append(PointDescription.getSimpleName(fav, view.getContext())); //$NON-NLS-1$
}
AccessibleToast.makeText(view.getContext(), res.toString(), Toast.LENGTH_LONG).show();
return true;
}
return false;
}
@Override
public String getObjectDescription(Object o) {
Class<? extends LocationPoint> fcl = getFavoriteClass();
@ -191,6 +171,16 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
return null;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
getFavoriteFromPoint(tileBox, point, res);

View file

@ -425,26 +425,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
List<WptPt> gpxPoints = new ArrayList<WptPt>();
getWptFromPoint(tileBox, point, gpxPoints);
if(!gpxPoints.isEmpty() && (tileBox.getZoom() > 14 || gpxPoints.size() < 6)){
StringBuilder res = new StringBuilder();
int i = 0;
for(WptPt fav : gpxPoints) {
if (i++ > 0) {
res.append("\n\n");
}
res.append(view.getContext().getString(R.string.gpx_wpt) + " : " + fav.name); //$NON-NLS-1$
}
AccessibleToast.makeText(view.getContext(), res.toString(), Toast.LENGTH_LONG).show();
return true;
}
return false;
}
@Override
public String getObjectDescription(Object o) {
if(o instanceof WptPt){
@ -461,6 +441,16 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
return null;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
getWptFromPoint(tileBox, point, res);

View file

@ -48,7 +48,6 @@ import android.graphics.Paint.Style;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v4.view.MenuItemCompat;
@ -181,25 +180,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
List<Amenity> am = new ArrayList<Amenity>();
getAmenityFromPoint(tileBox, 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\n");
}
buildPoiInformation(res, n);
}
AccessibleToast.makeText(view.getContext(), res.toString(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
private StringBuilder buildPoiInformation(StringBuilder res, Amenity n) {
String format = OsmAndFormatter.getPoiStringWithoutType(n,
view.getSettings().MAP_PREFERRED_LOCALE.get());
@ -212,9 +192,10 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
this.view = view;
paintIcon = new Paint();
paintIcon.setStrokeWidth(1);
paintIcon.setStyle(Style.STROKE);
paintIcon.setColor(Color.BLUE);
//paintIcon.setStrokeWidth(1);
//paintIcon.setStyle(Style.STROKE);
//paintIcon.setColor(Color.BLUE);
paintIcon.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
paintIconBackground = new Paint();
poiBackground = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield);
poiBackgroundSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield_small);
@ -241,13 +222,13 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
return (int) (r * tb.getDensity());
}
private RectF calculateRect(int x, int y, int width, int height) {
RectF rf;
float left = x - width / 2;
float top = y - height / 2;
float right = left + width;
float bottom = top + height;
rf = new RectF(left, top, right, bottom);
private QuadRect calculateRect(int x, int y, int width, int height) {
QuadRect rf;
double left = x - width / 2;
double top = y - height / 2;
double right = left + width;
double bottom = top + height;
rf = new QuadRect(left, top, right, bottom);
return rf;
}
@ -265,17 +246,17 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
}
List<Amenity> objects = Collections.emptyList();
List<Amenity> fullObjects = new ArrayList<>();
if (filter != null) {
if (tileBox.getZoom() >= startZoom) {
data.queryNewData(tileBox);
objects = data.getResults();
if (objects != null) {
int iconSize = poiBackground.getWidth() * 3 / 2;
List<Amenity> fullObjects = new ArrayList<>();
QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight());
//bounds.inset(-bounds.width()/4, -bounds.height()/4);
QuadTree<RectF> boundIntersections = new QuadTree<RectF>(bounds, 4, 0.6f);
List<RectF> result = new ArrayList<RectF>();
bounds.inset(-bounds.width()/4, -bounds.height()/4);
QuadTree<QuadRect> boundIntersections = new QuadTree<>(bounds, 4, 0.6f);
List<QuadRect> result = new ArrayList<>();
for (Amenity o : objects) {
int x = (int) tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation()
@ -283,12 +264,12 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
int y = (int) tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation()
.getLongitude());
boolean intersects =false;
RectF visibleRect = calculateRect(x, y, iconSize, iconSize);
QuadRect visibleRect = calculateRect(x, y, iconSize, iconSize);
//canvas.drawRect(visibleRect, paintIcon);
boundIntersections.queryInBox(new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom), result);
for (RectF r : result) {
if (r.intersects(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom)) {
for (QuadRect r : result) {
if (QuadRect.intersects(r, visibleRect)) {
intersects = true;
break;
}
@ -320,7 +301,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
if (id != null) {
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id, false);
if (bmp != null) {
paintIcon.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon);
}
}
@ -553,6 +533,16 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
return null;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects) {
getAmenityFromPoint(tileBox, point, objects);

View file

@ -143,16 +143,15 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
}
@Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
public boolean disableSingleTap() {
return false;
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
TargetPointsHelper tg = map.getMyApplication().getTargetPointsHelper();

View file

@ -73,26 +73,6 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
ArrayList<TransportStop> stops = new ArrayList<TransportStop >();
getFromPoint(tileBox, point, stops);
if(!stops.isEmpty()){
StringBuilder res = new StringBuilder();
int i = 0;
for (TransportStop n : stops) {
if (i++ > 0) {
res.append("\n\n");
}
res.append(getStopDescription(n, true));
}
AccessibleToast.makeText(view.getContext(), res.toString(), Toast.LENGTH_LONG).show();
return true;
}
return false;
}
private String getStopDescription(TransportStop n, boolean useName) {
StringBuilder text = new StringBuilder(250);
@ -199,6 +179,16 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
return null;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
getFromPoint(tileBox, point, res);