Unify context menu description row
This commit is contained in:
parent
9520101321
commit
faa2c0f2ef
4 changed files with 81 additions and 117 deletions
|
@ -56,6 +56,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
|
||||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
|
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
|
||||||
import net.osmand.plus.render.RenderingIcons;
|
import net.osmand.plus.render.RenderingIcons;
|
||||||
import net.osmand.plus.transport.TransportStopRoute;
|
import net.osmand.plus.transport.TransportStopRoute;
|
||||||
|
import net.osmand.plus.views.POIMapLayer;
|
||||||
import net.osmand.plus.views.TransportStopsLayer;
|
import net.osmand.plus.views.TransportStopsLayer;
|
||||||
import net.osmand.plus.widgets.TextViewEx;
|
import net.osmand.plus.widgets.TextViewEx;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
@ -471,6 +472,7 @@ public class MenuBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void buildTopInternal(View view) {
|
protected void buildTopInternal(View view) {
|
||||||
|
buildDescription(view);
|
||||||
if (showLocalTransportRoutes()) {
|
if (showLocalTransportRoutes()) {
|
||||||
buildRow(view, 0, null, app.getString(R.string.transport_Routes), 0, true, getCollapsableTransportStopRoutesView(view.getContext(), false, false),
|
buildRow(view, 0, null, app.getString(R.string.transport_Routes), 0, true, getCollapsableTransportStopRoutesView(view.getContext(), false, false),
|
||||||
false, 0, false, null, true);
|
false, 0, false, null, true);
|
||||||
|
@ -483,6 +485,9 @@ public class MenuBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void buildDescription(View view){
|
||||||
|
}
|
||||||
|
|
||||||
protected void buildAfter(View view) {
|
protected void buildAfter(View view) {
|
||||||
buildRowDivider(view);
|
buildRowDivider(view);
|
||||||
}
|
}
|
||||||
|
@ -505,20 +510,20 @@ public class MenuBuilder {
|
||||||
public View buildRow(final View view, Drawable icon, final String buttonText, final String text, int textColor, String secondaryText,
|
public View buildRow(final View view, Drawable icon, final String buttonText, final String text, int textColor, String secondaryText,
|
||||||
boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
|
boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
|
||||||
int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
|
int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||||
return buildRow(view, icon, buttonText, text, textColor, secondaryText, collapsable, collapsableView,
|
return buildRow(view, icon, buttonText, null, text, textColor, secondaryText, collapsable, collapsableView,
|
||||||
needLinks, textLinesLimit, isUrl, false, false, onClickListener, matchWidthDivider);
|
needLinks, textLinesLimit, isUrl, false, false, onClickListener, matchWidthDivider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public View buildRow(View view, int iconId, String buttonText, String text, int textColor,
|
public View buildRow(View view, int iconId, String buttonText, String text, int textColor,
|
||||||
boolean collapsable, final CollapsableView collapsableView,
|
boolean collapsable, final CollapsableView collapsableView,
|
||||||
boolean needLinks, int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
|
boolean needLinks, int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||||
return buildRow(view, iconId == 0 ? null : getRowIcon(iconId), buttonText, text, textColor, null, collapsable, collapsableView,
|
return buildRow(view, iconId == 0 ? null : getRowIcon(iconId), buttonText, null, text, textColor, null, collapsable, collapsableView,
|
||||||
needLinks, textLinesLimit, isUrl, isNumber, isEmail, onClickListener, matchWidthDivider);
|
needLinks, textLinesLimit, isUrl, isNumber, isEmail, onClickListener, matchWidthDivider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public View buildRow(final View view, Drawable icon, final String buttonText, final String text, int textColor, String secondaryText,
|
public View buildRow(final View view, Drawable icon, final String buttonText, final String textPrefix, final String text,
|
||||||
boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
|
int textColor, String secondaryText, boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
|
||||||
int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
|
int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||||
|
|
||||||
if (!isFirstRow()) {
|
if (!isFirstRow()) {
|
||||||
buildRowDivider(view);
|
buildRowDivider(view);
|
||||||
|
@ -537,7 +542,8 @@ public class MenuBuilder {
|
||||||
ll.setOnLongClickListener(new View.OnLongClickListener() {
|
ll.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
copyToClipboard(text, view.getContext());
|
String textToCopy = Algorithms.isEmpty(textPrefix) ? text : textPrefix + ": " + text;
|
||||||
|
copyToClipboard(textToCopy, view.getContext());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -572,6 +578,21 @@ public class MenuBuilder {
|
||||||
llText.setLayoutParams(llTextViewParams);
|
llText.setLayoutParams(llTextViewParams);
|
||||||
ll.addView(llText);
|
ll.addView(llText);
|
||||||
|
|
||||||
|
// Text prefix
|
||||||
|
if (!Algorithms.isEmpty(textPrefix)) {
|
||||||
|
TextView textPrefixView = new TextView(view.getContext());
|
||||||
|
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, dpToPx(8f), 0, 0);
|
||||||
|
textPrefixView.setLayoutParams(llTextParams);
|
||||||
|
textPrefixView.setTextSize(12);
|
||||||
|
textPrefixView.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light: R.color.text_color_secondary_dark));
|
||||||
|
textPrefixView.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
textPrefixView.setMinLines(1);
|
||||||
|
textPrefixView.setMaxLines(1);
|
||||||
|
textPrefixView.setText(textPrefix);
|
||||||
|
llText.addView(textPrefixView);
|
||||||
|
}
|
||||||
|
|
||||||
// Primary text
|
// Primary text
|
||||||
TextViewEx textView = new TextViewEx(view.getContext());
|
TextViewEx textView = new TextViewEx(view.getContext());
|
||||||
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
@ -580,6 +601,11 @@ public class MenuBuilder {
|
||||||
textView.setTypeface(FontCache.getRobotoRegular(view.getContext()));
|
textView.setTypeface(FontCache.getRobotoRegular(view.getContext()));
|
||||||
textView.setTextSize(16);
|
textView.setTextSize(16);
|
||||||
textView.setTextColor(app.getResources().getColor(light ? R.color.text_color_primary_light : R.color.text_color_primary_dark));
|
textView.setTextColor(app.getResources().getColor(light ? R.color.text_color_primary_light : R.color.text_color_primary_dark));
|
||||||
|
textView.setText(text);
|
||||||
|
|
||||||
|
if (textColor > 0) {
|
||||||
|
textView.setTextColor(view.getResources().getColor(textColor));
|
||||||
|
}
|
||||||
|
|
||||||
int linkTextColor = ContextCompat.getColor(view.getContext(), light ? R.color.ctx_menu_bottom_view_url_color_light : R.color.ctx_menu_bottom_view_url_color_dark);
|
int linkTextColor = ContextCompat.getColor(view.getContext(), light ? R.color.ctx_menu_bottom_view_url_color_light : R.color.ctx_menu_bottom_view_url_color_dark);
|
||||||
|
|
||||||
|
@ -595,10 +621,6 @@ public class MenuBuilder {
|
||||||
textView.setMinLines(1);
|
textView.setMinLines(1);
|
||||||
textView.setMaxLines(textLinesLimit);
|
textView.setMaxLines(textLinesLimit);
|
||||||
}
|
}
|
||||||
textView.setText(text);
|
|
||||||
if (textColor > 0) {
|
|
||||||
textView.setTextColor(view.getResources().getColor(textColor));
|
|
||||||
}
|
|
||||||
llText.addView(textView);
|
llText.addView(textView);
|
||||||
|
|
||||||
// Secondary text
|
// Secondary text
|
||||||
|
@ -706,7 +728,21 @@ public class MenuBuilder {
|
||||||
|
|
||||||
return ll;
|
return ll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public View buildDescriptionRow(final View view, final String textPrefix, final String description, int textColor,
|
||||||
|
int textLinesLimit, boolean matchWidthDivider) {
|
||||||
|
OnClickListener clickListener = new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
POIMapLayer.showDescriptionDialog(view.getContext(), app, description, textPrefix);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return buildRow(view, null, null, textPrefix, description, textColor,
|
||||||
|
null, false, null, true, textLinesLimit,
|
||||||
|
false, false, false, clickListener, matchWidthDivider);
|
||||||
|
}
|
||||||
|
|
||||||
protected void showDialog(String text, final String actionType, final String dataPrefix, final View v) {
|
protected void showDialog(String text, final String actionType, final String dataPrefix, final View v) {
|
||||||
final String[] items = text.split("[,;]");
|
final String[] items = text.split("[,;]");
|
||||||
final Intent intent = new Intent(actionType);
|
final Intent intent = new Intent(actionType);
|
||||||
|
|
|
@ -3,15 +3,9 @@ package net.osmand.plus.mapcontextmenu.builders;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
|
@ -27,7 +21,6 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||||
import net.osmand.plus.routing.TransportRoutingHelper;
|
|
||||||
import net.osmand.plus.widgets.TextViewEx;
|
import net.osmand.plus.widgets.TextViewEx;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
@ -73,7 +66,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void buildTopInternal(View view) {
|
protected void buildTopInternal(View view) {
|
||||||
buildDescription(view);
|
|
||||||
super.buildTopInternal(view);
|
super.buildTopInternal(view);
|
||||||
buildGroupFavouritesView(view);
|
buildGroupFavouritesView(view);
|
||||||
}
|
}
|
||||||
|
@ -88,6 +80,14 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void buildDescription(View view) {
|
||||||
|
String desc = fav.getDescription();
|
||||||
|
if (!Algorithms.isEmpty(desc)) {
|
||||||
|
buildDescriptionRow(view, app.getString(R.string.shared_string_description), desc, 0, 10, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void buildGroupFavouritesView(View view) {
|
private void buildGroupFavouritesView(View view) {
|
||||||
FavoriteGroup favoriteGroup = app.getFavorites().getGroup(fav);
|
FavoriteGroup favoriteGroup = app.getFavorites().getGroup(fav);
|
||||||
List<FavouritePoint> groupFavourites = favoriteGroup.points;
|
List<FavouritePoint> groupFavourites = favoriteGroup.points;
|
||||||
|
@ -102,84 +102,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildDescriptionRow(final View view, final String description, int textColor,
|
|
||||||
int textLinesLimit, boolean matchWidthDivider) {
|
|
||||||
if (!isFirstRow()) {
|
|
||||||
buildRowDivider(view);
|
|
||||||
}
|
|
||||||
LinearLayout baseView = new LinearLayout(view.getContext());
|
|
||||||
baseView.setOrientation(LinearLayout.VERTICAL);
|
|
||||||
LinearLayout.LayoutParams llBaseViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
baseView.setLayoutParams(llBaseViewParams);
|
|
||||||
|
|
||||||
LinearLayout ll = new LinearLayout(view.getContext());
|
|
||||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
|
||||||
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
ll.setLayoutParams(llParams);
|
|
||||||
ll.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
|
|
||||||
ll.setOnLongClickListener(new View.OnLongClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onLongClick(View v) {
|
|
||||||
copyToClipboard(description, view.getContext());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
baseView.addView(ll);
|
|
||||||
|
|
||||||
// Text
|
|
||||||
LinearLayout llText = new LinearLayout(view.getContext());
|
|
||||||
llText.setOrientation(LinearLayout.VERTICAL);
|
|
||||||
ll.addView(llText);
|
|
||||||
|
|
||||||
TextView textPrefixView = new TextView(view.getContext());
|
|
||||||
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
llTextParams.setMargins(dpToPx(16f), dpToPx(8f), 0, 0);
|
|
||||||
textPrefixView.setLayoutParams(llTextParams);
|
|
||||||
textPrefixView.setTextSize(12);
|
|
||||||
textPrefixView.setTextColor(app.getResources().getColor(R.color.ctx_menu_buttons_text_color));
|
|
||||||
textPrefixView.setEllipsize(TextUtils.TruncateAt.END);
|
|
||||||
textPrefixView.setMinLines(1);
|
|
||||||
textPrefixView.setMaxLines(1);
|
|
||||||
textPrefixView.setText(app.getResources().getString(R.string.shared_string_description));
|
|
||||||
llText.addView(textPrefixView);
|
|
||||||
|
|
||||||
TextView textView = new TextView(view.getContext());
|
|
||||||
LinearLayout.LayoutParams llTextParams2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
llTextParams2.setMargins(dpToPx(16f), dpToPx(2f), 0, dpToPx(8f));
|
|
||||||
textView.setLayoutParams(llTextParams2);
|
|
||||||
textView.setTextSize(16);
|
|
||||||
textView.setTextColor(app.getResources().getColor(light ? R.color.text_color_primary_light : R.color.text_color_primary_dark));
|
|
||||||
textView.setText(description);
|
|
||||||
|
|
||||||
textView.setEllipsize(TextUtils.TruncateAt.END);
|
|
||||||
if (textLinesLimit > 0) {
|
|
||||||
textView.setMinLines(1);
|
|
||||||
textView.setMaxLines(textLinesLimit);
|
|
||||||
}
|
|
||||||
if (textColor > 0) {
|
|
||||||
textView.setTextColor(view.getResources().getColor(textColor));
|
|
||||||
}
|
|
||||||
llText.addView(textView);
|
|
||||||
|
|
||||||
LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
llTextViewParams.weight = 1f;
|
|
||||||
llTextViewParams.setMargins(0, 0, dpToPx(10f), 0);
|
|
||||||
llTextViewParams.gravity = Gravity.CENTER_VERTICAL;
|
|
||||||
llText.setLayoutParams(llTextViewParams);
|
|
||||||
|
|
||||||
((LinearLayout) view).addView(baseView);
|
|
||||||
rowBuilt();
|
|
||||||
setDividerWidth(matchWidthDivider);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildDescription(View view) {
|
|
||||||
String desc = fav.getDescription();
|
|
||||||
if (!Algorithms.isEmpty(desc)) {
|
|
||||||
buildDescriptionRow(view, desc, 0, 0, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Amenity findAmenity(String nameStringEn, double lat, double lon) {
|
private Amenity findAmenity(String nameStringEn, double lat, double lon) {
|
||||||
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
|
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
|
||||||
List<Amenity> amenities = app.getResourceManager().searchAmenities(
|
List<Amenity> amenities = app.getResourceManager().searchAmenities(
|
||||||
|
|
|
@ -8,10 +8,10 @@ import android.support.v4.content.ContextCompat;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import net.osmand.data.LatLon;
|
|
||||||
import net.osmand.data.PointDescription;
|
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.GpxSelectionHelper;
|
import net.osmand.plus.GpxSelectionHelper;
|
||||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||||
import net.osmand.plus.OsmAndAppCustomization;
|
import net.osmand.plus.OsmAndAppCustomization;
|
||||||
|
@ -30,6 +30,7 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class WptPtMenuBuilder extends MenuBuilder {
|
public class WptPtMenuBuilder extends MenuBuilder {
|
||||||
|
|
||||||
private final WptPt wpt;
|
private final WptPt wpt;
|
||||||
|
|
||||||
public WptPtMenuBuilder(@NonNull MapActivity mapActivity, final @NonNull WptPt wpt) {
|
public WptPtMenuBuilder(@NonNull MapActivity mapActivity, final @NonNull WptPt wpt) {
|
||||||
|
@ -49,6 +50,13 @@ public class WptPtMenuBuilder extends MenuBuilder {
|
||||||
buildWaypointsView(view);
|
buildWaypointsView(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void buildDescription(View view) {
|
||||||
|
if (!Algorithms.isEmpty(wpt.desc)) {
|
||||||
|
buildDescriptionRow(view, app.getString(R.string.shared_string_description), wpt.desc, 0, 10, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildInternal(View view) {
|
public void buildInternal(View view) {
|
||||||
if (wpt.time > 0) {
|
if (wpt.time > 0) {
|
||||||
|
@ -92,16 +100,7 @@ public class WptPtMenuBuilder extends MenuBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void prepareDescription(final WptPt wpt, View view) {
|
protected void prepareDescription(final WptPt wpt, View view) {
|
||||||
if (!Algorithms.isEmpty(wpt.desc)) {
|
|
||||||
final View row = buildRow(view, R.drawable.ic_action_note_dark, null, wpt.desc, 0, false, null, true, 10, false, null, false);
|
|
||||||
row.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
POIMapLayer.showDescriptionDialog(row.getContext(), app, wpt.desc,
|
|
||||||
row.getResources().getString(R.string.shared_string_description));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildWaypointsView(View view) {
|
private void buildWaypointsView(View view) {
|
||||||
|
|
|
@ -12,30 +12,37 @@ import net.osmand.util.Algorithms;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
|
public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
|
||||||
|
|
||||||
private final static String KEY_PHONE = "Phone: ";
|
private final static String KEY_PHONE = "Phone: ";
|
||||||
private final static String KEY_EMAIL = "Email: ";
|
private final static String KEY_EMAIL = "Email: ";
|
||||||
private final static String KEY_WORKING_HOURS = "Working hours: ";
|
private final static String KEY_WORKING_HOURS = "Working hours: ";
|
||||||
private final static String KEY_PRICE = "Price: ";
|
private final static String KEY_PRICE = "Price: ";
|
||||||
private final static String KEY_DIRECTIONS = "Directions: ";
|
private final static String KEY_DIRECTIONS = "Directions: ";
|
||||||
private final static String KEY_DESCRIPTION = "Description";
|
private final static String KEY_DESCRIPTION = "Description";
|
||||||
|
|
||||||
|
private HashMap<String, String> descTokens;
|
||||||
|
|
||||||
public WikivoyageWptPtMenuBuilder(@NonNull MapActivity mapActivity, @NonNull WptPt wpt) {
|
public WikivoyageWptPtMenuBuilder(@NonNull MapActivity mapActivity, @NonNull WptPt wpt) {
|
||||||
super(mapActivity, wpt);
|
super(mapActivity, wpt);
|
||||||
|
descTokens = getDescriptionTokens(wpt.desc, KEY_PHONE, KEY_EMAIL, KEY_WORKING_HOURS, KEY_PRICE, KEY_DIRECTIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void buildDescription(View view) {
|
||||||
|
final String desc = descTokens.get(KEY_DESCRIPTION);
|
||||||
|
if (!Algorithms.isEmpty(desc)) {
|
||||||
|
buildDescriptionRow(view, app.getString(R.string.shared_string_description), desc, 0, 10, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepareDescription(final WptPt wpt, View view) {
|
protected void prepareDescription(final WptPt wpt, View view) {
|
||||||
HashMap<String, String> descTokens = getDescriptionTokens(wpt.desc, KEY_PHONE, KEY_EMAIL, KEY_WORKING_HOURS, KEY_PRICE, KEY_DIRECTIONS);
|
|
||||||
String phones = descTokens.get(KEY_PHONE);
|
String phones = descTokens.get(KEY_PHONE);
|
||||||
String emails = descTokens.get(KEY_EMAIL);
|
String emails = descTokens.get(KEY_EMAIL);
|
||||||
String workingHours = descTokens.get(KEY_WORKING_HOURS);
|
String workingHours = descTokens.get(KEY_WORKING_HOURS);
|
||||||
String price = descTokens.get(KEY_PRICE);
|
String price = descTokens.get(KEY_PRICE);
|
||||||
String direction = descTokens.get(KEY_DIRECTIONS);
|
String direction = descTokens.get(KEY_DIRECTIONS);
|
||||||
|
|
||||||
final String desc = descTokens.get(KEY_DESCRIPTION);
|
|
||||||
if (!Algorithms.isEmpty(desc)) {
|
|
||||||
buildRow(view, R.drawable.ic_action_note_dark, null, desc, 0, false, null, true, 10, false, null, false);
|
|
||||||
}
|
|
||||||
if (!Algorithms.isEmpty(phones)) {
|
if (!Algorithms.isEmpty(phones)) {
|
||||||
buildRow(view, R.drawable.ic_action_call_dark,
|
buildRow(view, R.drawable.ic_action_call_dark,
|
||||||
null, phones, 0,
|
null, phones, 0,
|
||||||
|
@ -68,7 +75,7 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, String> getDescriptionTokens(String desc, String ... allowedKeys) {
|
private HashMap<String, String> getDescriptionTokens(String desc, String... allowedKeys) {
|
||||||
String[] tokens = desc.split("\n");
|
String[] tokens = desc.split("\n");
|
||||||
HashMap<String, String> mTokens = new HashMap<>();
|
HashMap<String, String> mTokens = new HashMap<>();
|
||||||
for (String token : tokens) {
|
for (String token : tokens) {
|
||||||
|
@ -87,4 +94,4 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
|
||||||
}
|
}
|
||||||
return mTokens;
|
return mTokens;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue