Fix url in map context menu. Fix marker under context menu after returning from fav/wpt edit mode

This commit is contained in:
Alexey Kulish 2015-12-22 10:20:43 +03:00
parent 45e4083611
commit 23106903a4
12 changed files with 55 additions and 31 deletions

View file

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

View file

@ -1057,6 +1057,9 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
public void setFragmentVisibility(boolean visible) { public void setFragmentVisibility(boolean visible) {
if (visible) { if (visible) {
view.setVisibility(View.VISIBLE); view.setVisibility(View.VISIBLE);
if (mapCenter != null) {
map.setLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
}
adjustMapPosition(getPosY(), true, false); adjustMapPosition(getPosY(), true, false);
} else { } else {
view.setVisibility(View.GONE); view.setVisibility(View.GONE);

View file

@ -2,9 +2,11 @@ package net.osmand.plus.mapcontextmenu;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.ClipboardManager; import android.text.ClipboardManager;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.TypedValue; import android.util.TypedValue;
@ -40,11 +42,13 @@ public class MenuBuilder {
private int iconId; private int iconId;
private String text; private String text;
private boolean needLinks; private boolean needLinks;
private boolean url;
public PlainMenuItem(int iconId, String text, boolean needLinks) { public PlainMenuItem(int iconId, String text, boolean needLinks, boolean url) {
this.iconId = iconId; this.iconId = iconId;
this.text = text; this.text = text;
this.needLinks = needLinks; this.needLinks = needLinks;
this.url = url;
} }
public int getIconId() { public int getIconId() {
@ -58,6 +62,10 @@ public class MenuBuilder {
public boolean isNeedLinks() { public boolean isNeedLinks() {
return needLinks; return needLinks;
} }
public boolean isUrl() {
return url;
}
} }
public MenuBuilder(OsmandApplication app) { public MenuBuilder(OsmandApplication app) {
@ -80,7 +88,7 @@ public class MenuBuilder {
protected void buildPlainMenuItems(View view) { protected void buildPlainMenuItems(View view) {
for (PlainMenuItem item : plainMenuItems) { for (PlainMenuItem item : plainMenuItems) {
buildRow(view, item.getIconId(), item.getText(), 0, item.isNeedLinks(), 0); buildRow(view, item.getIconId(), item.getText(), 0, item.isNeedLinks(), 0, item.isUrl());
} }
} }
@ -103,11 +111,11 @@ public class MenuBuilder {
firstRow = false; firstRow = false;
} }
protected View buildRow(View view, int iconId, String text, int textColor, boolean needLinks, int textLinesLimit) { 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); return buildRow(view, getRowIcon(iconId), text, textColor, needLinks, textLinesLimit, isUrl);
} }
protected View buildRow(final View view, Drawable icon, final String text, int textColor, boolean needLinks, int textLinesLimit) { protected View buildRow(final View view, Drawable icon, final String text, int textColor, boolean needLinks, int textLinesLimit, boolean isUrl) {
if (!isFirstRow()) { if (!isFirstRow()) {
buildRowDivider(view, false); buildRowDivider(view, false);
@ -154,7 +162,9 @@ public class MenuBuilder {
textView.setTextSize(16); textView.setTextSize(16);
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark)); textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
if (needLinks) { if (isUrl) {
textView.setTextColor(textView.getLinkTextColors());
} else if (needLinks) {
textView.setAutoLinkMask(Linkify.ALL); textView.setAutoLinkMask(Linkify.ALL);
textView.setLinksClickable(true); textView.setLinksClickable(true);
} }
@ -173,6 +183,17 @@ public class MenuBuilder {
llText.setLayoutParams(llTextViewParams); llText.setLayoutParams(llTextViewParams);
llText.addView(textView); llText.addView(textView);
if (isUrl) {
ll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(text));
v.getContext().startActivity(intent);
}
});
}
((LinearLayout) view).addView(ll); ((LinearLayout) view).addView(ll);
rowBuilt(); rowBuilt();
@ -248,8 +269,8 @@ public class MenuBuilder {
public void buildCustomAddressLine(LinearLayout ll) { public void buildCustomAddressLine(LinearLayout ll) {
} }
public void addPlainMenuItem(int iconId, String text, boolean needLinks) { public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl) {
plainMenuItems.add(new PlainMenuItem(iconId, text, needLinks)); plainMenuItems.add(new PlainMenuItem(iconId, text, needLinks, isUrl));
} }
public void clearPlainMenuItems() { public void clearPlainMenuItems() {

View file

@ -125,8 +125,8 @@ public abstract class MenuController extends BaseMenuController {
protected abstract void setObject(Object object); protected abstract void setObject(Object object);
public void addPlainMenuItem(int iconId, String text, boolean needLinks) { public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl) {
builder.addPlainMenuItem(iconId, text, needLinks); builder.addPlainMenuItem(iconId, text, needLinks, isUrl);
} }
public void clearPlainMenuItems() { public void clearPlainMenuItems() {
@ -139,7 +139,7 @@ public abstract class MenuController extends BaseMenuController {
protected void addMyLocationToPlainItems(LatLon latLon) { protected void addMyLocationToPlainItems(LatLon latLon) {
addPlainMenuItem(R.drawable.ic_action_get_my_location, PointDescription.getLocationName(getMapActivity(), addPlainMenuItem(R.drawable.ic_action_get_my_location, PointDescription.getLocationName(getMapActivity(),
latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", ""), false); latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", ""), false, false);
} }
public PointDescription getPointDescription() { public PointDescription getPointDescription() {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -184,8 +184,8 @@ public class MapDataMenuController extends MenuController {
@Override @Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
if (indexItem != null) { if (indexItem != null) {
addPlainMenuItem(R.drawable.ic_action_info_dark, indexItem.getType().getString(getMapActivity()), false); addPlainMenuItem(R.drawable.ic_action_info_dark, indexItem.getType().getString(getMapActivity()), false, false);
addPlainMenuItem(R.drawable.ic_action_info_dark, indexItem.getSizeDescription(getMapActivity()), false); addPlainMenuItem(R.drawable.ic_action_info_dark, indexItem.getSizeDescription(getMapActivity()), false, false);
} }
if (!Algorithms.isEmpty(mapObject.getWorldRegion().getParams().getWikiLink())) { if (!Algorithms.isEmpty(mapObject.getWorldRegion().getParams().getWikiLink())) {
String[] items = mapObject.getWorldRegion().getParams().getWikiLink().split(":"); String[] items = mapObject.getWorldRegion().getParams().getWikiLink().split(":");
@ -195,11 +195,11 @@ public class MapDataMenuController extends MenuController {
} else { } else {
url = "https://wikipedia.org/wiki/" + items[0].replace(' ', '_'); url = "https://wikipedia.org/wiki/" + items[0].replace(' ', '_');
} }
addPlainMenuItem(R.drawable.ic_world_globe_dark, url, true); addPlainMenuItem(R.drawable.ic_world_globe_dark, url, false, true);
} }
if (indexItem != null) { if (indexItem != null) {
DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(getMapActivity()); DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(getMapActivity());
addPlainMenuItem(R.drawable.ic_action_data, indexItem.getRemoteDate(dateFormat), false); addPlainMenuItem(R.drawable.ic_action_data, indexItem.getRemoteDate(dateFormat), false, false);
} }
} }

View file

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

View file

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