Context menu Fix
This commit is contained in:
parent
c0be4699c8
commit
837c98825f
4 changed files with 47 additions and 87 deletions
|
@ -63,17 +63,12 @@ public class MapContextMenu {
|
|||
settings = app.getSettings();
|
||||
}
|
||||
|
||||
public void show() {
|
||||
MapContextMenuFragment.showInstance(mapActivity);
|
||||
}
|
||||
|
||||
public void show(PointDescription pointDescription, Object object) {
|
||||
|
||||
public boolean init(PointDescription pointDescription, Object object) {
|
||||
if (isMenuVisible()) {
|
||||
if (this.object == null || !this.object.equals(object)) {
|
||||
hide();
|
||||
} else {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,9 +84,19 @@ public class MapContextMenu {
|
|||
if (object != null || Algorithms.isEmpty(pointDescription.getName())) {
|
||||
acquireStreetName(new LatLon(pointDescription.getLat(), pointDescription.getLon()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
MapContextMenuFragment.showInstance(mapActivity);
|
||||
public void show() {
|
||||
if (!isMenuVisible()) {
|
||||
MapContextMenuFragment.showInstance(mapActivity);
|
||||
}
|
||||
}
|
||||
|
||||
public void show(PointDescription pointDescription, Object object) {
|
||||
if (init(pointDescription, object)) {
|
||||
MapContextMenuFragment.showInstance(mapActivity);
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
|
|
|
@ -37,11 +37,11 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
this.amenity = amenity;
|
||||
}
|
||||
|
||||
private void buildRow(View view, int iconId, String text, int textColor, boolean isDescription) {
|
||||
buildRow(view, getRowIcon(iconId), text, textColor, isDescription);
|
||||
private void buildRow(View view, int iconId, String text, int textColor, boolean isWiki) {
|
||||
buildRow(view, getRowIcon(iconId), text, textColor, isWiki);
|
||||
}
|
||||
|
||||
private void buildRow(final View view, Drawable icon, String text, int textColor, final boolean isDescription) {
|
||||
private void buildRow(final View view, Drawable icon, String text, int textColor, final boolean isWiki) {
|
||||
boolean light = app.getSettings().isLightContent();
|
||||
|
||||
LinearLayout ll = new LinearLayout(view.getContext());
|
||||
|
@ -80,7 +80,7 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
|
||||
textView.setAutoLinkMask(Linkify.ALL);
|
||||
textView.setLinksClickable(true);
|
||||
if (isDescription) {
|
||||
if (isWiki) {
|
||||
textView.setMinLines(1);
|
||||
textView.setMaxLines(5);
|
||||
}
|
||||
|
@ -88,13 +88,11 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
if (textColor > 0) {
|
||||
textView.setTextColor(view.getResources().getColor(textColor));
|
||||
}
|
||||
if (isDescription) {
|
||||
if (isWiki) {
|
||||
textView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isDescription) {
|
||||
POIMapLayer.showDescriptionDialog(view.getContext(), app, amenity);
|
||||
}
|
||||
POIMapLayer.showDescriptionDialog(view.getContext(), app, amenity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -143,7 +141,7 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
int iconId = 0;
|
||||
Drawable icon = null;
|
||||
int textColor = 0;
|
||||
boolean isDescription = false;
|
||||
boolean isWiki = false;
|
||||
String key = e.getKey();
|
||||
String vl = e.getValue();
|
||||
|
||||
|
@ -166,7 +164,7 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
vl = vl.substring(0, 300);
|
||||
}
|
||||
hasWiki = true;
|
||||
isDescription = true;
|
||||
isWiki = true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
@ -195,7 +193,6 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
} else {
|
||||
if (Amenity.DESCRIPTION.equals(key)) {
|
||||
iconId = R.drawable.ic_action_note_dark;
|
||||
isDescription = true;
|
||||
} else {
|
||||
iconId = R.drawable.ic_action_info_dark;
|
||||
}
|
||||
|
@ -217,9 +214,9 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
|||
}
|
||||
|
||||
if (icon != null) {
|
||||
buildRow(view, icon, vl, textColor, isDescription);
|
||||
buildRow(view, icon, vl, textColor, isWiki);
|
||||
} else {
|
||||
buildRow(view, iconId, vl, textColor, isDescription);
|
||||
buildRow(view, iconId, vl, textColor, isWiki);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,8 +63,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
private LatLon latLon;
|
||||
private String description;
|
||||
private Map<Object, IContextMenuProvider> selectedObjects = new ConcurrentHashMap<Object, IContextMenuProvider>();
|
||||
private Object selectedObj;
|
||||
private IContextMenuProvider contextObject;
|
||||
|
||||
private TextView textView;
|
||||
private ImageView closeButton;
|
||||
|
@ -212,8 +210,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
public void showMapContextMenuMarker(LatLon latLon) {
|
||||
activity.getContextMenu().hide();
|
||||
this.latLon = latLon;
|
||||
selectedObj = null;
|
||||
contextObject = null;
|
||||
showMapContextMenuMarker();
|
||||
}
|
||||
|
||||
|
@ -296,9 +292,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
if (latLon != null) {
|
||||
if (selectedObjects.size() == 1) {
|
||||
setLocation(null, "");
|
||||
selectedObj = selectedObjects.keySet().iterator().next();
|
||||
contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(latLon);
|
||||
Object selectedObj = selectedObjects.keySet().iterator().next();
|
||||
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(latLon, selectedObj, contextObject);
|
||||
return true;
|
||||
} else if (selectedObjects.size() > 1) {
|
||||
showContextMenuForSelectedObjects(latLon);
|
||||
|
@ -308,8 +304,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
setLocation(null, "");
|
||||
final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y);
|
||||
final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y);
|
||||
selectedObj = null;
|
||||
contextObject = null;
|
||||
showMapContextMenu(new LatLon(lat, lon));
|
||||
return true;
|
||||
}
|
||||
|
@ -460,9 +454,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
if(selectOnMap != null) {
|
||||
LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y);
|
||||
CallbackWithObject<LatLon> cb = selectOnMap;
|
||||
selectOnMap = null;
|
||||
cb.processResult(latlon);
|
||||
showMapContextMenuMarker(latlon);
|
||||
showMapContextMenu(latlon);
|
||||
selectOnMap = null;
|
||||
return true;
|
||||
}
|
||||
if (val == 2) {
|
||||
|
@ -503,16 +497,16 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
builder.setItems(d, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
selectedObj = s.get(which);
|
||||
contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(l);
|
||||
Object selectedObj = s.get(which);
|
||||
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(l, selectedObj, contextObject);
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
} else {
|
||||
selectedObj = selectedObjects.keySet().iterator().next();
|
||||
contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(l);
|
||||
Object selectedObj = selectedObjects.keySet().iterator().next();
|
||||
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(l, selectedObj, contextObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -525,6 +519,14 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
}
|
||||
|
||||
public void showMapContextMenu(LatLon latLon, String title) {
|
||||
showMapContextMenu(latLon, title, null, null);
|
||||
}
|
||||
|
||||
public void showMapContextMenu(LatLon latLon, Object selectedObj, IContextMenuProvider contextObject) {
|
||||
showMapContextMenu(latLon, null, selectedObj, contextObject);
|
||||
}
|
||||
|
||||
public void showMapContextMenu(LatLon latLon, String title, Object selectedObj, IContextMenuProvider contextObject) {
|
||||
PointDescription pointDescription;
|
||||
if (selectedObj != null && contextObject != null) {
|
||||
pointDescription = contextObject.getObjectName(selectedObj);
|
||||
|
@ -540,7 +542,11 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
this.latLon = new LatLon(pointDescription.getLat(), pointDescription.getLon());
|
||||
|
||||
showMapContextMenuMarker();
|
||||
activity.getContextMenu().show(pointDescription, selectedObj);
|
||||
if (selectOnMap != null) {
|
||||
activity.getContextMenu().init(pointDescription, selectedObj);
|
||||
} else {
|
||||
activity.getContextMenu().show(pointDescription, selectedObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -335,54 +335,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
|
||||
if (o instanceof Amenity) {
|
||||
final Amenity a = (Amenity) o;
|
||||
OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
if (itemId == R.string.poi_context_menu_call) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse("tel:" + a.getPhone())); //$NON-NLS-1$
|
||||
view.getContext().startActivity(intent);
|
||||
} catch (RuntimeException e) {
|
||||
log.error("Failed to invoke call", e); //$NON-NLS-1$
|
||||
AccessibleToast.makeText(view.getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if (itemId == R.string.poi_context_menu_website) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(a.getSite()));
|
||||
view.getContext().startActivity(intent);
|
||||
} catch (RuntimeException e) {
|
||||
log.error("Failed to invoke call", e); //$NON-NLS-1$
|
||||
AccessibleToast.makeText(view.getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if (itemId == R.string.poi_context_menu_showdescription) {
|
||||
showDescriptionDialog(view.getContext(), app, a);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
if (OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a, false).length() > 0 ||
|
||||
a.getType().isWiki()) {
|
||||
adapter.item(R.string.poi_context_menu_showdescription)
|
||||
.iconColor(R.drawable.ic_action_note_dark).listen(listener).reg();
|
||||
}
|
||||
if (a.getPhone() != null) {
|
||||
adapter.item(R.string.poi_context_menu_call)
|
||||
.iconColor(R.drawable.ic_action_call_dark).listen(listener).reg();
|
||||
}
|
||||
if (a.getSite() != null) {
|
||||
adapter.item(R.string.poi_context_menu_website)
|
||||
.iconColor(R.drawable.ic_world_globe_dark).listen(listener)
|
||||
.reg();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void showDescriptionDialog(Context ctx, OsmandApplication app, Amenity a) {
|
||||
String lang = app.getSettings().MAP_PREFERRED_LOCALE.get();
|
||||
if (a.getType().isWiki()) {
|
||||
|
|
Loading…
Reference in a new issue