Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-07-29 16:27:52 +02:00
commit 611d655faf
16 changed files with 714 additions and 38 deletions

View file

@ -42,7 +42,7 @@ public class AudioVideoNoteMenuBuilder extends MenuBuilder {
DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(view.getContext());
DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(view.getContext());
Date date = new Date(recording.getFile().lastModified());
buildRow(view, R.drawable.ic_action_data, dateFormat.format(date) + "" + timeFormat.format(date), 0, false, 0, false);
buildRow(view, R.drawable.ic_action_data, dateFormat.format(date) + "" + timeFormat.format(date), 0, false, 0, false, null);
buildPlainMenuItems(view);

View file

@ -43,12 +43,14 @@ public class MenuBuilder {
private String text;
private boolean needLinks;
private boolean url;
private OnClickListener onClickListener;
public PlainMenuItem(int iconId, String text, boolean needLinks, boolean url) {
public PlainMenuItem(int iconId, String text, boolean needLinks, boolean url, OnClickListener onClickListener) {
this.iconId = iconId;
this.text = text;
this.needLinks = needLinks;
this.url = url;
this.onClickListener = onClickListener;
}
public int getIconId() {
@ -66,6 +68,10 @@ public class MenuBuilder {
public boolean isUrl() {
return url;
}
public OnClickListener getOnClickListener() {
return onClickListener;
}
}
public MenuBuilder(OsmandApplication app) {
@ -88,7 +94,7 @@ public class MenuBuilder {
protected void buildPlainMenuItems(View view) {
for (PlainMenuItem item : plainMenuItems) {
buildRow(view, item.getIconId(), item.getText(), 0, item.isNeedLinks(), 0, item.isUrl());
buildRow(view, item.getIconId(), item.getText(), 0, item.isNeedLinks(), 0, item.isUrl(), item.getOnClickListener());
}
}
@ -111,11 +117,11 @@ public class MenuBuilder {
firstRow = false;
}
protected View buildRow(View view, int iconId, String text, int textColor, boolean needLinks, int textLinesLimit, boolean isUrl) {
return buildRow(view, getRowIcon(iconId), text, textColor, needLinks, textLinesLimit, isUrl);
protected View buildRow(View view, int iconId, String text, int textColor, boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener) {
return buildRow(view, getRowIcon(iconId), text, textColor, needLinks, textLinesLimit, isUrl, onClickListener);
}
protected View buildRow(final View view, Drawable icon, final String text, int textColor, boolean needLinks, int textLinesLimit, boolean isUrl) {
protected View buildRow(final View view, Drawable icon, final String text, int textColor, boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener) {
if (!isFirstRow()) {
buildRowDivider(view, false);
@ -183,7 +189,9 @@ public class MenuBuilder {
llText.setLayoutParams(llTextViewParams);
llText.addView(textView);
if (isUrl) {
if (onClickListener != null) {
ll.setOnClickListener(onClickListener);
} else if (isUrl) {
ll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -269,8 +277,8 @@ public class MenuBuilder {
public void buildCustomAddressLine(LinearLayout ll) {
}
public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl) {
plainMenuItems.add(new PlainMenuItem(iconId, text, needLinks, isUrl));
public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl, OnClickListener onClickListener) {
plainMenuItems.add(new PlainMenuItem(iconId, text, needLinks, isUrl, onClickListener));
}
public void clearPlainMenuItems() {

View file

@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import net.osmand.binary.RouteDataObject;
@ -12,7 +13,6 @@ import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -139,8 +139,8 @@ public abstract class MenuController extends BaseMenuController {
protected abstract void setObject(Object object);
public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl) {
builder.addPlainMenuItem(iconId, text, needLinks, isUrl);
public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl, OnClickListener onClickListener) {
builder.addPlainMenuItem(iconId, text, needLinks, isUrl, onClickListener);
}
public void clearPlainMenuItems() {
@ -153,7 +153,7 @@ public abstract class MenuController extends BaseMenuController {
protected void addMyLocationToPlainItems(LatLon latLon) {
addPlainMenuItem(R.drawable.ic_action_get_my_location, PointDescription.getLocationName(getMapActivity(),
latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", ""), false, false);
latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", ""), false, false, null);
}
public PointDescription getPointDescription() {

View file

@ -350,7 +350,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
buildRow(view, R.drawable.ic_action_get_my_location, PointDescription.getLocationName(app,
amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), true)
.replaceAll("\n", ""), 0, false, 0, false);
.replaceAll("\n", ""), 0, false, 0, false, null);
}
public void buildAmenityRow(View view, AmenityInfoRow info) {

View file

@ -25,7 +25,7 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
@Override
public void buildInternal(View view) {
if (!Algorithms.isEmpty(fav.getDescription())) {
buildRow(view, R.drawable.ic_action_note_dark, fav.getDescription(), 0, true, 0, false);
buildRow(view, R.drawable.ic_action_note_dark, fav.getDescription(), 0, true, 0, false, null);
}
buildPlainMenuItems(view);

View file

@ -34,7 +34,7 @@ public class GpxItemMenuBuilder extends MenuBuilder {
String description = GpxUiHelper.getDescription(app, item.analysis, false);
String[] lines = description.split("\n");
for (String line : lines) {
buildRow(view, R.drawable.ic_action_info_dark, line, 0, false, 0, false);
buildRow(view, R.drawable.ic_action_info_dark, line, 0, false, 0, false, null);
}
}

View file

@ -34,23 +34,23 @@ public class WptPtMenuBuilder extends MenuBuilder {
DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(view.getContext());
Date date = new Date(wpt.time);
buildRow(view, R.drawable.ic_action_data,
dateFormat.format(date) + "" + timeFormat.format(date), 0, false, 0, false);
dateFormat.format(date) + "" + timeFormat.format(date), 0, false, 0, false, null);
}
if (wpt.speed > 0) {
buildRow(view, R.drawable.ic_action_speed,
OsmAndFormatter.getFormattedSpeed((float)wpt.speed, app), 0, false, 0, false);
OsmAndFormatter.getFormattedSpeed((float)wpt.speed, app), 0, false, 0, false, null);
}
if (!Double.isNaN(wpt.ele)) {
buildRow(view, R.drawable.ic_action_altitude,
OsmAndFormatter.getFormattedDistance((float) wpt.ele, app), 0, false, 0, false);
OsmAndFormatter.getFormattedDistance((float) wpt.ele, app), 0, false, 0, false, null);
}
if (!Double.isNaN(wpt.hdop)) {
buildRow(view, R.drawable.ic_action_gps_info,
Algorithms.capitalizeFirstLetterAndLowercase(app.getString(R.string.plugin_distance_point_hdop)) + ": "
+ OsmAndFormatter.getFormattedDistance((float)wpt.hdop, app), 0, false, 0, false);
+ OsmAndFormatter.getFormattedDistance((float)wpt.hdop, app), 0, false, 0, false, null);
}
if (!Algorithms.isEmpty(wpt.desc)) {
final View row = buildRow(view, R.drawable.ic_action_note_dark, wpt.desc, 0, true, 10, false);
final View row = buildRow(view, R.drawable.ic_action_note_dark, wpt.desc, 0, true, 10, false, null);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View file

@ -97,7 +97,7 @@ public class AmenityMenuController extends MenuController {
if (resId == 0) {
resId = R.drawable.ic_action_folder_stroke;
}
addPlainMenuItem(resId, typeStr, false, false);
addPlainMenuItem(resId, typeStr, false, false, null);
}
}
}

View file

@ -226,16 +226,16 @@ public class MapDataMenuController extends MenuController {
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
if (indexItem != null) {
addPlainMenuItem(R.drawable.ic_action_info_dark, indexItem.getType().getString(getMapActivity()), false, false);
addPlainMenuItem(R.drawable.ic_action_info_dark, indexItem.getType().getString(getMapActivity()), false, false, null);
StringBuilder sizeStr = new StringBuilder();
sizeStr.append(indexItem.getSizeDescription(getMapActivity()));
if (backuped) {
sizeStr.append("").append(LocalIndexType.DEACTIVATED.getHumanString(getMapActivity()));
}
addPlainMenuItem(R.drawable.ic_action_info_dark, sizeStr.toString(), false, false);
addPlainMenuItem(R.drawable.ic_action_info_dark, sizeStr.toString(), false, false, null);
} else if (localIndexInfo != null) {
if (getDownloadActivityType() != null) {
addPlainMenuItem(R.drawable.ic_action_info_dark, getDownloadActivityType().getString(getMapActivity()), false, false);
addPlainMenuItem(R.drawable.ic_action_info_dark, getDownloadActivityType().getString(getMapActivity()), false, false, null);
}
StringBuilder sizeStr = new StringBuilder();
if (localIndexInfo.getSize() >= 0) {
@ -252,7 +252,7 @@ public class MapDataMenuController extends MenuController {
sizeStr.append(LocalIndexType.DEACTIVATED.getHumanString(getMapActivity()));
}
}
addPlainMenuItem(R.drawable.ic_action_info_dark, sizeStr.toString(), false, false);
addPlainMenuItem(R.drawable.ic_action_info_dark, sizeStr.toString(), false, false, null);
}
if (!Algorithms.isEmpty(mapObject.getWorldRegion().getParams().getWikiLink())) {
String[] items = mapObject.getWorldRegion().getParams().getWikiLink().split(":");
@ -262,7 +262,7 @@ public class MapDataMenuController extends MenuController {
} else {
url = "https://wikipedia.org/wiki/" + items[0].replace(' ', '_');
}
addPlainMenuItem(R.drawable.ic_world_globe_dark, url, false, true);
addPlainMenuItem(R.drawable.ic_world_globe_dark, url, false, true, null);
}
if (!Algorithms.isEmpty(mapObject.getWorldRegion().getParams().getPopulation())) {
String population = mapObject.getWorldRegion().getParams().getPopulation();
@ -277,13 +277,13 @@ public class MapDataMenuController extends MenuController {
k++;
}
addPlainMenuItem(R.drawable.ic_action_info_dark, getMapActivity().getResources().getString(R.string.poi_population)
+ ": " + b, false, false);
+ ": " + b, false, false, null);
}
if (indexItem != null) {
DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(getMapActivity());
addPlainMenuItem(R.drawable.ic_action_data, indexItem.getRemoteDate(dateFormat), false, false);
addPlainMenuItem(R.drawable.ic_action_data, indexItem.getRemoteDate(dateFormat), false, false, null);
} else if (localIndexInfo != null) {
addPlainMenuItem(R.drawable.ic_action_data, localIndexInfo.getDescription(), false, false);
addPlainMenuItem(R.drawable.ic_action_data, localIndexInfo.getDescription(), false, false, null);
}
}

View file

@ -114,9 +114,9 @@ public class TransportStopController extends MenuController {
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
for (TransportStopRoute r : routes) {
if (r.type == null) {
addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false);
addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false, null);
} else {
addPlainMenuItem(r.type.getResourceId(), r.desc, false, false);
addPlainMenuItem(r.type.getResourceId(), r.desc, false, false, null);
}
}
super.addPlainMenuItems(typeStr, pointDescription, latLon);

View file

@ -0,0 +1,167 @@
package net.osmand.plus.mapcontextmenu.controllers;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
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, R.drawable.mx_route_bus_ref),
FERRY(R.drawable.mx_route_ferry_ref, R.drawable.mx_route_ferry_ref),
FUNICULAR(R.drawable.mx_route_funicular_ref, R.drawable.mx_route_funicular_ref),
LIGHT_RAIL(R.drawable.mx_route_light_rail_ref, R.drawable.mx_route_light_rail_ref),
MONORAIL(R.drawable.mx_route_monorail_ref, R.drawable.mx_route_monorail_ref),
RAILWAY(R.drawable.mx_route_railway_ref, R.drawable.mx_route_railway_ref),
SHARE_TAXI(R.drawable.mx_route_share_taxi_ref, R.drawable.mx_route_share_taxi_ref),
TRAIN(R.drawable.mx_route_train_ref, R.drawable.mx_route_train_ref),
TRAM(R.drawable.mx_route_tram_ref, R.drawable.mx_railway_tram_stop),
TROLLEYBUS(R.drawable.mx_route_trolleybus_ref, R.drawable.mx_route_trolleybus_ref),
SUBWAY(R.drawable.mx_subway_station, R.drawable.mx_subway_station);
final int resId;
final int topResId;
TransportStopType(int resId, int topResId) {
this.resId = resId;
this.topResId = topResId;
}
public int getResourceId() {
return resId;
}
public int getTopResourceId() {
return topResId;
}
public boolean isTopType() {
return this == TRAM || this == SUBWAY;
}
public static TransportStopType findType(String typeName) {
String tName = typeName.toUpperCase();
for (TransportStopType t : values()) {
if (t.name().equals(tName)) {
return t;
}
}
return null;
}
}
private TransportStop transportStop;
private List<TransportStopRoute> routes = new ArrayList<>();
private TransportStopType topType;
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();
}
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
}
@Override
public int getLeftIconId() {
if (topType == null) {
return R.drawable.mx_public_transport;
} else {
return topType.getTopResourceId();
}
}
@Override
public boolean needStreetName() {
return Algorithms.isEmpty(getNameStr());
}
@Override
public boolean displayDistanceDirection() {
return true;
}
@Override
public String getTypeStr() {
return getPointDescription().getTypeName();
}
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
<<<<<<< HEAD
for (List<TransportStopRoute> l : routes) {
for (TransportStopRoute r : l) {
if (r.type == null) {
addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false, null);
} else {
addPlainMenuItem(r.type.getResourceId(), r.desc, false, false, null);
}
=======
for (TransportStopRoute r : routes) {
if (r.type == null) {
addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false);
} else {
addPlainMenuItem(r.type.getResourceId(), r.desc, false, false);
>>>>>>> 0855c6c36d1d10760efecc2dcc04c3840362ca87
}
}
super.addPlainMenuItems(typeStr, pointDescription, latLon);
}
private void processTransportStop() {
routes.clear();
List<TransportIndexRepository> reps = getMapActivity().getMyApplication()
.getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(),
transportStop.getLocation().getLongitude());
boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
for (TransportIndexRepository t : reps) {
if (t.acceptTransportStop(transportStop)) {
List<TransportRoute> rts = t.getRouteForStop(transportStop);
if (rts != null) {
for (TransportRoute rs : rts) {
TransportStopType type = TransportStopType.findType(rs.getType());
TransportStopRoute r = new TransportStopRoute();
if (topType == null && type != null && type.isTopType()) {
topType = type;
}
r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getName() : rs.getEnName(true));
r.route = rs;
this.routes.add(r);
}
}
}
}
}
private class TransportStopRoute {
public TransportStopType type;
public String desc;
public TransportRoute route;
}
}

View file

@ -0,0 +1,172 @@
package net.osmand.plus.mapcontextmenu.controllers;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
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, R.drawable.mx_route_bus_ref),
FERRY(R.drawable.mx_route_ferry_ref, R.drawable.mx_route_ferry_ref),
FUNICULAR(R.drawable.mx_route_funicular_ref, R.drawable.mx_route_funicular_ref),
LIGHT_RAIL(R.drawable.mx_route_light_rail_ref, R.drawable.mx_route_light_rail_ref),
MONORAIL(R.drawable.mx_route_monorail_ref, R.drawable.mx_route_monorail_ref),
RAILWAY(R.drawable.mx_route_railway_ref, R.drawable.mx_route_railway_ref),
SHARE_TAXI(R.drawable.mx_route_share_taxi_ref, R.drawable.mx_route_share_taxi_ref),
TRAIN(R.drawable.mx_route_train_ref, R.drawable.mx_route_train_ref),
TRAM(R.drawable.mx_route_tram_ref, R.drawable.mx_railway_tram_stop),
TROLLEYBUS(R.drawable.mx_route_trolleybus_ref, R.drawable.mx_route_trolleybus_ref),
SUBWAY(R.drawable.mx_subway_station, R.drawable.mx_subway_station);
final int resId;
final int topResId;
TransportStopType(int resId, int topResId) {
this.resId = resId;
this.topResId = topResId;
}
public int getResourceId() {
return resId;
}
public int getTopResourceId() {
return topResId;
}
public boolean isTopType() {
return this == TRAM || this == SUBWAY;
}
public static TransportStopType findType(String typeName) {
String tName = typeName.toUpperCase();
for (TransportStopType t : values()) {
if (t.name().equals(tName)) {
return t;
}
}
return null;
}
}
private TransportStop transportStop;
private List<List<TransportStopRoute>> routes = new ArrayList<>();
private TransportStopType topType;
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();
}
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
}
@Override
public int getLeftIconId() {
if (topType == null) {
return R.drawable.mx_public_transport;
} else {
return topType.getTopResourceId();
}
}
@Override
public boolean needStreetName() {
return Algorithms.isEmpty(getNameStr());
}
@Override
public boolean displayDistanceDirection() {
return true;
}
@Override
public String getTypeStr() {
return getPointDescription().getTypeName();
}
@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.getResourceId(), r.desc, false, false);
}
}
}
super.addPlainMenuItems(typeStr, pointDescription, latLon);
}
private void processTransportStop() {
routes.clear();
List<TransportIndexRepository> reps = getMapActivity().getMyApplication()
.getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(),
transportStop.getLocation().getLongitude());
boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
for (TransportIndexRepository t : reps) {
if (t.acceptTransportStop(transportStop)) {
List<String> l;
if (useEnglishNames) {
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {3}");
} else {
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {2}");
}
if (l != null) {
List<TransportStopRoute> routeList = new ArrayList<>();
for (String s : l) {
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 (topType == null && type != null && type.isTopType()) {
topType = type;
}
}
}
routes.add(routeList);
}
}
}
}
private class TransportStopRoute {
public TransportStopType type;
public String desc;
}
}

View file

@ -0,0 +1,172 @@
package net.osmand.plus.mapcontextmenu.controllers;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
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, R.drawable.mx_route_bus_ref),
FERRY(R.drawable.mx_route_ferry_ref, R.drawable.mx_route_ferry_ref),
FUNICULAR(R.drawable.mx_route_funicular_ref, R.drawable.mx_route_funicular_ref),
LIGHT_RAIL(R.drawable.mx_route_light_rail_ref, R.drawable.mx_route_light_rail_ref),
MONORAIL(R.drawable.mx_route_monorail_ref, R.drawable.mx_route_monorail_ref),
RAILWAY(R.drawable.mx_route_railway_ref, R.drawable.mx_route_railway_ref),
SHARE_TAXI(R.drawable.mx_route_share_taxi_ref, R.drawable.mx_route_share_taxi_ref),
TRAIN(R.drawable.mx_route_train_ref, R.drawable.mx_route_train_ref),
TRAM(R.drawable.mx_route_tram_ref, R.drawable.mx_railway_tram_stop),
TROLLEYBUS(R.drawable.mx_route_trolleybus_ref, R.drawable.mx_route_trolleybus_ref),
SUBWAY(R.drawable.mx_subway_station, R.drawable.mx_subway_station);
final int resId;
final int topResId;
TransportStopType(int resId, int topResId) {
this.resId = resId;
this.topResId = topResId;
}
public int getResourceId() {
return resId;
}
public int getTopResourceId() {
return topResId;
}
public boolean isTopType() {
return this == TRAM || this == SUBWAY;
}
public static TransportStopType findType(String typeName) {
String tName = typeName.toUpperCase();
for (TransportStopType t : values()) {
if (t.name().equals(tName)) {
return t;
}
}
return null;
}
}
private TransportStop transportStop;
private List<List<TransportStopRoute>> routes = new ArrayList<>();
private TransportStopType topType;
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();
}
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
}
@Override
public int getLeftIconId() {
if (topType == null) {
return R.drawable.mx_public_transport;
} else {
return topType.getTopResourceId();
}
}
@Override
public boolean needStreetName() {
return Algorithms.isEmpty(getNameStr());
}
@Override
public boolean displayDistanceDirection() {
return true;
}
@Override
public String getTypeStr() {
return getPointDescription().getTypeName();
}
@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, null);
} else {
addPlainMenuItem(r.type.getResourceId(), r.desc, false, false, null);
}
}
}
super.addPlainMenuItems(typeStr, pointDescription, latLon);
}
private void processTransportStop() {
routes.clear();
List<TransportIndexRepository> reps = getMapActivity().getMyApplication()
.getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(),
transportStop.getLocation().getLongitude());
boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
for (TransportIndexRepository t : reps) {
if (t.acceptTransportStop(transportStop)) {
List<String> l;
if (useEnglishNames) {
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {3}");
} else {
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {2}");
}
if (l != null) {
List<TransportStopRoute> routeList = new ArrayList<>();
for (String s : l) {
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 (topType == null && type != null && type.isTopType()) {
topType = type;
}
}
}
routes.add(routeList);
}
}
}
}
private class TransportStopRoute {
public TransportStopType type;
public String desc;
}
}

View file

@ -0,0 +1,157 @@
package net.osmand.plus.mapcontextmenu.controllers;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
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, R.drawable.mx_route_bus_ref),
FERRY(R.drawable.mx_route_ferry_ref, R.drawable.mx_route_ferry_ref),
FUNICULAR(R.drawable.mx_route_funicular_ref, R.drawable.mx_route_funicular_ref),
LIGHT_RAIL(R.drawable.mx_route_light_rail_ref, R.drawable.mx_route_light_rail_ref),
MONORAIL(R.drawable.mx_route_monorail_ref, R.drawable.mx_route_monorail_ref),
RAILWAY(R.drawable.mx_route_railway_ref, R.drawable.mx_route_railway_ref),
SHARE_TAXI(R.drawable.mx_route_share_taxi_ref, R.drawable.mx_route_share_taxi_ref),
TRAIN(R.drawable.mx_route_train_ref, R.drawable.mx_route_train_ref),
TRAM(R.drawable.mx_route_tram_ref, R.drawable.mx_railway_tram_stop),
TROLLEYBUS(R.drawable.mx_route_trolleybus_ref, R.drawable.mx_route_trolleybus_ref),
SUBWAY(R.drawable.mx_subway_station, R.drawable.mx_subway_station);
final int resId;
final int topResId;
TransportStopType(int resId, int topResId) {
this.resId = resId;
this.topResId = topResId;
}
public int getResourceId() {
return resId;
}
public int getTopResourceId() {
return topResId;
}
public boolean isTopType() {
return this == TRAM || this == SUBWAY;
}
public static TransportStopType findType(String typeName) {
String tName = typeName.toUpperCase();
for (TransportStopType t : values()) {
if (t.name().equals(tName)) {
return t;
}
}
return null;
}
}
private TransportStop transportStop;
private List<TransportStopRoute> routes = new ArrayList<>();
private TransportStopType topType;
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();
}
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
}
@Override
public int getLeftIconId() {
if (topType == null) {
return R.drawable.mx_public_transport;
} else {
return topType.getTopResourceId();
}
}
@Override
public boolean needStreetName() {
return Algorithms.isEmpty(getNameStr());
}
@Override
public boolean displayDistanceDirection() {
return true;
}
@Override
public String getTypeStr() {
return getPointDescription().getTypeName();
}
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
for (TransportStopRoute r : routes) {
if (r.type == null) {
addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false);
} else {
addPlainMenuItem(r.type.getResourceId(), r.desc, false, false);
}
}
super.addPlainMenuItems(typeStr, pointDescription, latLon);
}
private void processTransportStop() {
routes.clear();
List<TransportIndexRepository> reps = getMapActivity().getMyApplication()
.getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(),
transportStop.getLocation().getLongitude());
boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
for (TransportIndexRepository t : reps) {
if (t.acceptTransportStop(transportStop)) {
List<TransportRoute> rts = t.getRouteForStop(transportStop);
if (rts != null) {
for (TransportRoute rs : rts) {
TransportStopType type = TransportStopType.findType(rs.getType());
TransportStopRoute r = new TransportStopRoute();
if (topType == null && type != null && type.isTopType()) {
topType = type;
}
r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getName() : rs.getEnName(true));
r.route = rs;
this.routes.add(r);
}
}
}
}
}
private class TransportStopRoute {
public TransportStopType type;
public String desc;
public TransportRoute route;
}
}

View file

@ -31,8 +31,8 @@ public class EditPOIMenuBuilder extends MenuBuilder {
if (osmPoint instanceof OsmNotesPoint) {
OsmNotesPoint notes = (OsmNotesPoint) osmPoint;
buildRow(view, R.drawable.ic_action_note_dark, notes.getText(), 0, false, 0, false);
buildRow(view, R.drawable.ic_group, notes.getAuthor(), 0, false, 0, false);
buildRow(view, R.drawable.ic_action_note_dark, notes.getText(), 0, false, 0, false, null);
buildRow(view, R.drawable.ic_group, notes.getAuthor(), 0, false, 0, false, null);
} else if (osmPoint instanceof OpenstreetmapPoint) {
OpenstreetmapPoint point = (OpenstreetmapPoint) osmPoint;
@ -57,7 +57,7 @@ public class EditPOIMenuBuilder extends MenuBuilder {
if (resId == 0) {
resId = R.drawable.ic_action_folder_stroke;
}
buildRow(view, resId, poiTranslation, 0, false, 0, false);
buildRow(view, resId, poiTranslation, 0, false, 0, false, null);
break;
}
}
@ -67,12 +67,12 @@ public class EditPOIMenuBuilder extends MenuBuilder {
continue;
}
String text = e.getKey() + "=" + e.getValue();
buildRow(view, R.drawable.ic_action_info_dark, text, 0, false, 0, false);
buildRow(view, R.drawable.ic_action_info_dark, text, 0, false, 0, false, null);
}
}
buildRow(view, R.drawable.ic_action_get_my_location, PointDescription.getLocationName(app,
osmPoint.getLatitude(), osmPoint.getLongitude(), true)
.replaceAll("\n", ""), 0, false, 0, false);
.replaceAll("\n", ""), 0, false, 0, false, null);
}
}

View file

@ -96,7 +96,7 @@ public class OsmBugMenuController extends MenuController {
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
super.addPlainMenuItems(typeStr, pointDescription, latLon);
for (String description : bug.getCommentDescriptionList()) {
addPlainMenuItem(R.drawable.ic_action_note_dark, description, true, false);
addPlainMenuItem(R.drawable.ic_action_note_dark, description, true, false, null);
}
}