Context menu - POI type and Coorsd in detais view
This commit is contained in:
parent
30bd298e93
commit
4aaf677632
5 changed files with 149 additions and 73 deletions
|
@ -1,10 +1,8 @@
|
|||
package net.osmand.plus.mapcontextmenu;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.ResultMatcher;
|
||||
|
@ -13,9 +11,9 @@ import net.osmand.data.Amenity;
|
|||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -35,7 +33,10 @@ public class MapContextMenu {
|
|||
private PointDescription pointDescription;
|
||||
private Object object;
|
||||
|
||||
private String foundStreetName;
|
||||
private int leftIconId;
|
||||
private String nameStr;
|
||||
private String typeStr;
|
||||
private String streetStr;
|
||||
|
||||
private static final String KEY_CTX_MENU_OBJECT = "key_ctx_menu_object";
|
||||
private static final String KEY_CTX_MENU_POINT_DESC = "key_ctx_menu_point_desc";
|
||||
|
@ -64,8 +65,13 @@ public class MapContextMenu {
|
|||
|
||||
this.pointDescription = pointDescription;
|
||||
this.object = object;
|
||||
foundStreetName = null;
|
||||
leftIconId = 0;
|
||||
nameStr = null;
|
||||
typeStr = null;
|
||||
streetStr = null;
|
||||
|
||||
acquireLeftIconId();
|
||||
acquireNameAndType();
|
||||
acquireStreetName(mapActivity, new LatLon(pointDescription.getLat(), pointDescription.getLon()));
|
||||
|
||||
MapContextMenuFragment.showInstance(mapActivity);
|
||||
|
@ -93,6 +99,22 @@ public class MapContextMenu {
|
|||
}
|
||||
|
||||
public int getLeftIconId() {
|
||||
return leftIconId;
|
||||
}
|
||||
|
||||
public String getTitleStr() {
|
||||
return nameStr;
|
||||
}
|
||||
|
||||
public String getLocationStr(MapActivity mapActivity) {
|
||||
if (Algorithms.isEmpty(streetStr))
|
||||
return pointDescription.getLocationName(mapActivity, true).replaceAll("\n", "");
|
||||
else
|
||||
return streetStr;
|
||||
}
|
||||
|
||||
private void acquireLeftIconId() {
|
||||
leftIconId = 0;
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
String id = null;
|
||||
|
@ -108,42 +130,45 @@ public class MapContextMenu {
|
|||
if (id != null) {
|
||||
Integer resId = RenderingIcons.getResId(id);
|
||||
if (resId != null) {
|
||||
return resId;
|
||||
leftIconId = resId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getAddressStr() {
|
||||
String res = null;
|
||||
|
||||
private void acquireNameAndType() {
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
Amenity amenity = (Amenity) object;
|
||||
res = OsmAndFormatter.getPoiStringWithoutType(amenity, settings.MAP_PREFERRED_LOCALE.get());
|
||||
|
||||
PoiCategory pc = amenity.getType();
|
||||
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
|
||||
typeStr = amenity.getSubType();
|
||||
if (pt != null) {
|
||||
typeStr = pt.getTranslation();
|
||||
} else if(typeStr != null){
|
||||
typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
|
||||
}
|
||||
nameStr = amenity.getName(settings.MAP_PREFERRED_LOCALE.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (Algorithms.isEmpty(res)) {
|
||||
String typeName = pointDescription.getTypeName();
|
||||
String name = pointDescription.getName();
|
||||
|
||||
if (!Algorithms.isEmpty(name))
|
||||
res = name;
|
||||
else if (!Algorithms.isEmpty(typeName))
|
||||
res = typeName;
|
||||
if (Algorithms.isEmpty(nameStr)) {
|
||||
nameStr = pointDescription.getName();
|
||||
}
|
||||
if (Algorithms.isEmpty(typeStr)) {
|
||||
typeStr = pointDescription.getTypeName();
|
||||
}
|
||||
|
||||
return Algorithms.isEmpty(res) ? "Address is unknown yet" : res; // todo: text constant
|
||||
if (Algorithms.isEmpty(nameStr)) {
|
||||
if (!Algorithms.isEmpty(typeStr)) {
|
||||
nameStr = typeStr;
|
||||
typeStr = null;
|
||||
} else {
|
||||
nameStr = app.getResources().getString(R.string.address_unknown);
|
||||
}
|
||||
}
|
||||
|
||||
public String getLocationStr(MapActivity mapActivity) {
|
||||
if (foundStreetName == null)
|
||||
return pointDescription.getLocationName(mapActivity, true).replaceAll("\n", "");
|
||||
else
|
||||
return foundStreetName;
|
||||
}
|
||||
|
||||
private void acquireStreetName(final MapActivity activity, final LatLon loc) {
|
||||
|
@ -154,14 +179,14 @@ public class MapContextMenu {
|
|||
|
||||
@Override
|
||||
public boolean publish(RouteDataObject object) {
|
||||
if(object != null) {
|
||||
foundStreetName = RoutingHelper.formatStreetName(object.getName(settings.MAP_PREFERRED_LOCALE.get()),
|
||||
if (object != null) {
|
||||
streetStr = RoutingHelper.formatStreetName(object.getName(settings.MAP_PREFERRED_LOCALE.get()),
|
||||
object.getRef(), object.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
|
||||
if (foundStreetName != null && foundStreetName.trim().length() == 0) {
|
||||
foundStreetName = null;
|
||||
if (streetStr != null && streetStr.trim().length() == 0) {
|
||||
streetStr = null;
|
||||
}
|
||||
|
||||
if (foundStreetName != null) {
|
||||
if (streetStr != null) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
refreshMenuTitle(activity);
|
||||
|
@ -169,7 +194,7 @@ public class MapContextMenu {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
foundStreetName = null;
|
||||
streetStr = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -186,7 +211,12 @@ public class MapContextMenu {
|
|||
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
return new AmenityInfoMenuController(app, activity, (Amenity)object);
|
||||
MenuController menuController = new AmenityInfoMenuController(app, activity, (Amenity)object);
|
||||
if (!Algorithms.isEmpty(typeStr)) {
|
||||
menuController.addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr);
|
||||
}
|
||||
menuController.addPlainMenuItem(R.drawable.map_my_location, pointDescription.getLocationName(activity, true).replaceAll("\n", ""));
|
||||
return menuController;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -213,6 +213,8 @@ public class MapContextMenuFragment extends Fragment {
|
|||
private float velocityY;
|
||||
private float maxVelocityY;
|
||||
|
||||
private boolean hasMoved;
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
|
||||
|
@ -220,6 +222,10 @@ public class MapContextMenuFragment extends Fragment {
|
|||
OsmandMapTileView mapView = getMapActivity().getMapView();
|
||||
mapView.getAnimatedDraggingThread().startMoving(getCtxMenu().getPointDescription().getLat(), getCtxMenu().getPointDescription().getLon(),
|
||||
mapView.getZoom(), true);
|
||||
|
||||
if (hasMoved) {
|
||||
applyPosY(getViewY());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -229,6 +235,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
hasMoved = false;
|
||||
dy = event.getY();
|
||||
dyMain = getViewY();
|
||||
velocity = VelocityTracker.obtain();
|
||||
|
@ -238,6 +245,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
hasMoved = true;
|
||||
float y = event.getY();
|
||||
float newY = getViewY() + (y - dy);
|
||||
setViewY((int) newY);
|
||||
|
@ -275,11 +283,18 @@ public class MapContextMenuFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
applyPosY(currentY);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void applyPosY(int currentY) {
|
||||
final int posY = getPosY();
|
||||
|
||||
if (currentY != posY) {
|
||||
|
||||
if (posY < getViewY()) {
|
||||
if (posY < currentY) {
|
||||
updateMainViewLayout(posY);
|
||||
}
|
||||
|
||||
|
@ -304,10 +319,6 @@ public class MapContextMenuFragment extends Fragment {
|
|||
updateMainViewLayout(posY);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -417,7 +428,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
private void setAddressLocation() {
|
||||
// Text line 1
|
||||
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
|
||||
line1.setText(getCtxMenu().getAddressStr());
|
||||
line1.setText(getCtxMenu().getTitleStr());
|
||||
|
||||
// Text line 2
|
||||
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
|
||||
|
|
|
@ -25,6 +25,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
|||
|
||||
public class AmenityInfoMenuBuilder extends MenuBuilder {
|
||||
|
||||
boolean firstRow;
|
||||
private final Amenity amenity;
|
||||
|
||||
public AmenityInfoMenuBuilder(OsmandApplication app, final Amenity amenity) {
|
||||
|
@ -32,11 +33,11 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
this.amenity = amenity;
|
||||
}
|
||||
|
||||
private void buildRow(View view, int iconId, String text, boolean firstRow) {
|
||||
buildRow(view, getRowIcon(iconId), text, firstRow);
|
||||
private void buildRow(View view, int iconId, String text) {
|
||||
buildRow(view, getRowIcon(iconId), text);
|
||||
}
|
||||
|
||||
private void buildRow(View view, Drawable icon, String text, boolean firstRow) {
|
||||
private void buildRow(View view, Drawable icon, String text) {
|
||||
boolean light = app.getSettings().isLightContent();
|
||||
|
||||
LinearLayout ll = new LinearLayout(view.getContext());
|
||||
|
@ -94,6 +95,8 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
horizontalLine.setBackgroundColor(app.getResources().getColor(light ? R.color.ctx_menu_info_divider_light : R.color.ctx_menu_info_divider_dark));
|
||||
|
||||
((LinearLayout) view).addView(horizontalLine);
|
||||
|
||||
firstRow = false;
|
||||
}
|
||||
|
||||
public int dpToPx(float dp) {
|
||||
|
@ -108,7 +111,11 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
@Override
|
||||
public void build(View view) {
|
||||
|
||||
boolean firstRow = true;
|
||||
firstRow = true;
|
||||
|
||||
for (PlainMenuItem item : plainMenuItems) {
|
||||
buildRow(view, item.getIconId(), item.getText());
|
||||
}
|
||||
|
||||
MapPoiTypes poiTypes = app.getPoiTypes();
|
||||
for (Map.Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
|
||||
|
@ -149,12 +156,10 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
}
|
||||
|
||||
if (icon != null) {
|
||||
buildRow(view, icon, vl, firstRow);
|
||||
buildRow(view, icon, vl);
|
||||
} else {
|
||||
buildRow(view, iconId, vl, firstRow);
|
||||
buildRow(view, iconId, vl);
|
||||
}
|
||||
|
||||
firstRow = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,19 +11,45 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public abstract class MenuBuilder {
|
||||
|
||||
public class PlainMenuItem {
|
||||
private int iconId;
|
||||
private String text;
|
||||
|
||||
public PlainMenuItem(int iconId, String text) {
|
||||
this.iconId = iconId;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public int getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public static final float SHADOW_HEIGHT_TOP_DP = 16f;
|
||||
public static final float SHADOW_HEIGHT_BOTTOM_DP = 6f;
|
||||
|
||||
protected OsmandApplication app;
|
||||
protected LinkedList<PlainMenuItem> plainMenuItems;
|
||||
|
||||
public MenuBuilder(OsmandApplication app) {
|
||||
this.app = app;
|
||||
plainMenuItems = new LinkedList<>();
|
||||
}
|
||||
|
||||
public abstract void build(View view);
|
||||
|
||||
public void addPlainMenuItem(int iconId, String text) {
|
||||
plainMenuItems.add(new PlainMenuItem(iconId, text));
|
||||
}
|
||||
|
||||
public Drawable getRowIcon(int iconId) {
|
||||
IconsCache iconsCache = app.getIconsCache();
|
||||
boolean light = app.getSettings().isLightContent();
|
||||
|
|
|
@ -30,6 +30,10 @@ public abstract class MenuController {
|
|||
builder.build(rootView);
|
||||
}
|
||||
|
||||
public void addPlainMenuItem(int iconId, String text) {
|
||||
builder.addPlainMenuItem(iconId, text);
|
||||
}
|
||||
|
||||
public int getInitialMenuState() {
|
||||
if (isLandscapeLayout()) {
|
||||
return MenuState.FULL_SCREEN;
|
||||
|
|
Loading…
Reference in a new issue