Added OnClickListener for context menu row
This commit is contained in:
parent
a681af7753
commit
c4e4b01fc9
12 changed files with 46 additions and 38 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,9 +114,9 @@ public class TransportStopController extends MenuController {
|
|||
for (List<TransportStopRoute> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue