From c4e4b01fc96ee0e54dbaeecb49e14728c3fb70ea Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 29 Jul 2016 17:24:24 +0300 Subject: [PATCH] Added OnClickListener for context menu row --- .../audionotes/AudioVideoNoteMenuBuilder.java | 2 +- .../plus/mapcontextmenu/MenuBuilder.java | 24 ++++++++++++------- .../plus/mapcontextmenu/MenuController.java | 8 +++---- .../builders/AmenityMenuBuilder.java | 2 +- .../builders/FavouritePointMenuBuilder.java | 2 +- .../builders/GpxItemMenuBuilder.java | 2 +- .../builders/WptPtMenuBuilder.java | 10 ++++---- .../controllers/AmenityMenuController.java | 2 +- .../controllers/MapDataMenuController.java | 16 ++++++------- .../controllers/TransportStopController.java | 4 ++-- .../plus/osmedit/EditPOIMenuBuilder.java | 10 ++++---- .../plus/osmedit/OsmBugMenuController.java | 2 +- 12 files changed, 46 insertions(+), 38 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java index ec55f83bd7..1e929adfb1 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuBuilder.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 5ba508ab7b..3c244f5a4d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -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() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 659588a889..0c7afb307b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -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() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 5c8e9d33f2..f1b3822734 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 7316c5a256..da871965d4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java index bec6206b23..fd2dc096fe 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java @@ -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); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java index a49671dd82..074a70b875 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 38de0908c1..36fce992df 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -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); } } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java index e8393f2646..708f9e9358 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java @@ -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); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 731cde125c..a4f80da7fa 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -114,9 +114,9 @@ public class TransportStopController extends MenuController { for (List l : routes) { for (TransportStopRoute r : l) { 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); } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuBuilder.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuBuilder.java index 100175bb4b..67596a9cdc 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuBuilder.java @@ -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); } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java index f4aa25a93e..a7fd05407a 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java @@ -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); } }