Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-02-29 14:51:41 +01:00
commit b371e06c7a
2 changed files with 140 additions and 20 deletions

View file

@ -9,23 +9,67 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.resources.TransportIndexRepository;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
public class TransportStopController extends MenuController {
public enum TransportStopType {
BUS(R.drawable.mx_route_bus_ref),
FERRY(R.drawable.mx_route_ferry_ref),
FUNICULAR(R.drawable.mx_route_funicular_ref),
LIGHT_RAIL(R.drawable.mx_route_light_rail_ref),
MONORAIL(R.drawable.mx_route_monorail_ref),
RAILWAY(R.drawable.mx_route_railway_ref),
SHARE_TAXI(R.drawable.mx_route_share_taxi_ref),
TRAIN(R.drawable.mx_route_train_ref),
TRAM(R.drawable.mx_route_tram_ref),
TROLLEYBUS(R.drawable.mx_route_trolleybus_ref),
SUBWAY(R.drawable.mx_subway_station);
final static TransportStopType[] ALL_TYPES = new TransportStopType[]
{BUS, FERRY, FUNICULAR, LIGHT_RAIL, MONORAIL, RAILWAY, SHARE_TAXI, TRAIN, TRAM, TROLLEYBUS, SUBWAY};
final int resId;
TransportStopType(int resId) {
this.resId = resId;
}
public int getResourceId() {
return resId;
}
public static TransportStopType findType(String typeName) {
String tName = typeName.toUpperCase();
for (TransportStopType t : ALL_TYPES) {
if (t.name().equals(tName)) {
return t;
}
}
return null;
}
}
private TransportStop transportStop;
private List<List<TransportStopRoute>> routes = new ArrayList<>();
private boolean hasTramRoute;
public TransportStopController(OsmandApplication app, MapActivity mapActivity,
PointDescription pointDescription, TransportStop transportStop) {
super(new MenuBuilder(app), pointDescription, mapActivity);
this.transportStop = transportStop;
processTransportStop();
}
@Override
protected void setObject(Object object) {
if (object instanceof TransportStop) {
this.transportStop = (TransportStop) object;
processTransportStop();
}
}
@ -36,7 +80,16 @@ public class TransportStopController extends MenuController {
@Override
public int getLeftIconId() {
return R.drawable.mx_public_transport_stop_position;
if (!hasTramRoute) {
return R.drawable.mx_public_transport;
} else {
return R.drawable.mx_railway_tram_stop;
}
}
@Override
public boolean needStreetName() {
return Algorithms.isEmpty(getNameStr());
}
@Override
@ -51,7 +104,19 @@ public class TransportStopController extends MenuController {
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
for (List<TransportStopRoute> l : routes) {
for (TransportStopRoute r : l) {
if (r.type == null) {
addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false);
} else {
addPlainMenuItem(r.type.resId, r.desc, false, false);
}
}
}
}
private void processTransportStop() {
routes.clear();
List<TransportIndexRepository> reps = getMapActivity().getMyApplication()
.getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(),
transportStop.getLocation().getLongitude());
@ -67,11 +132,33 @@ public class TransportStopController extends MenuController {
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {2}");
}
if (l != null) {
List<TransportStopRoute> routeList = new ArrayList<>();
for (String s : l) {
addPlainMenuItem(R.drawable.ic_action_polygom_dark, s, false, false);
int firstSpaceIndex = s.indexOf(' ');
if (firstSpaceIndex != -1) {
String typeName = s.substring(0, firstSpaceIndex);
TransportStopType type = TransportStopType.findType(typeName);
TransportStopRoute r = new TransportStopRoute();
r.type = type;
if (type == null) {
r.desc = s;
} else {
r.desc = s.substring(firstSpaceIndex + 1);
}
routeList.add(r);
if (!hasTramRoute && type != null && type == TransportStopType.TRAM) {
hasTramRoute = true;
}
}
}
routes.add(routeList);
}
}
}
}
private class TransportStopRoute {
public TransportStopType type;
public String desc;
}
}

View file

@ -1,6 +1,8 @@
package net.osmand.plus.views;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
@ -10,6 +12,7 @@ import android.view.WindowManager;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop;
import net.osmand.plus.R;
@ -21,22 +24,27 @@ import java.util.List;
public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private static final int startZoom = 12;
private Paint pointAltUI;
private OsmandMapTileView view;
private List<TransportStop> objects = new ArrayList<TransportStop>();
private DisplayMetrics dm;
private List<TransportStop> objects = new ArrayList<>();
private Paint paintIcon;
private Bitmap stopBus;
private Bitmap stopTram;
private Bitmap stopSmall;
@SuppressWarnings("deprecation")
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
dm = new DisplayMetrics();
DisplayMetrics dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
pointAltUI = new Paint();
pointAltUI.setColor(view.getResources().getColor(R.color.transport_stop));
pointAltUI.setAntiAlias(true);
paintIcon = new Paint();
stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus);
stopTram = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_tram);
stopSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_small);
}
public void getFromPoint(RotatedTileBox tb,PointF point, List<? super TransportStop> res) {
@ -45,7 +53,6 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
int ey = (int) point.y;
final int rp = getRadiusPoi(tb);
int radius = rp * 3 / 2;
int small = rp;
try {
for (int i = 0; i < objects.size(); i++) {
TransportStop n = objects.get(i);
@ -55,7 +62,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
int x = (int) tb.getPixXFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
int y = (int) tb.getPixYFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) {
radius = small;
radius = rp;
res.add(n);
}
}
@ -115,19 +122,45 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb,
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox,
DrawSettings settings) {
if (tb.getZoom() >= startZoom) {
if (tileBox.getZoom() >= startZoom) {
objects.clear();
final QuadRect latLonBounds = tb.getLatLonBounds();
/*
view.getApplication().getResourceManager().searchTransportAsync(latLonBounds.top, latLonBounds.left,
latLonBounds.bottom, latLonBounds.right, tb.getZoom(), objects);
int r = 3 * getRadiusPoi(tb) / 4;
latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), objects);
int r = 3 * getRadiusPoi(tileBox) / 4;
for (TransportStop o : objects) {
int x = tb.getPixXFromLonNoRot(o.getLocation().getLongitude());
int y = tb.getPixYFromLatNoRot(o.getLocation().getLatitude());
int x = tileBox.getPixXFromLonNoRot(o.getLocation().getLongitude());
int y = tileBox.getPixYFromLatNoRot(o.getLocation().getLatitude());
canvas.drawRect(x - r, y - r, x + r, y + r, pointAltUI);
}
*/
float iconSize = stopBus.getWidth() * 3 / 2.5f;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
final QuadRect latLonBounds = tileBox.getLatLonBounds();
view.getApplication().getResourceManager().searchTransportAsync(latLonBounds.top, latLonBounds.left,
latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), objects);
List<TransportStop> fullObjects = new ArrayList<>();
for (TransportStop o : objects) {
float x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(stopSmall, x - stopSmall.getWidth() / 2, y - stopSmall.getHeight() / 2, paintIcon);
} else {
fullObjects.add(o);
}
}
for (TransportStop o : fullObjects) {
float x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
Bitmap b = stopBus;
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
}
}
}