aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormax-klaus <53395422+max-klaus@users.noreply.github.com>2019-10-22 15:10:14 +0300
committerGitHub <noreply@github.com>2019-10-22 15:10:14 +0300
commit61fabcba77f59e1ab91900cace5e0c2e848d1efc (patch)
treedcc995ae7b4ae111440e29b7b7ebfa675150965c
parenta29ee0887413d9c1e9d06aeba2cb79c9c385d782 (diff)
parente35c7f5ead4b3a192a5489cf496ca205d908ce93 (diff)
downloadOsmand-61fabcba77f59e1ab91900cace5e0c2e848d1efc.tar.gz
Merge pull request #7718 from osmandapp/context_menu_description
Context menu description improvements
-rw-r--r--OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java61
-rw-r--r--OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java17
-rw-r--r--OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java94
-rw-r--r--OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java23
-rw-r--r--OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java50
-rw-r--r--OsmAnd/src/net/osmand/plus/widgets/tools/ClickableSpanTouchListener.java52
-rw-r--r--OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java49
7 files changed, 161 insertions, 185 deletions
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java
index e03b5bf31b..377df7a9dd 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java
@@ -56,8 +56,10 @@ import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.transport.TransportStopRoute;
+import net.osmand.plus.views.POIMapLayer;
import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.plus.widgets.TextViewEx;
+import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@@ -471,6 +473,7 @@ public class MenuBuilder {
}
protected void buildTopInternal(View view) {
+ buildDescription(view);
if (showLocalTransportRoutes()) {
buildRow(view, 0, null, app.getString(R.string.transport_Routes), 0, true, getCollapsableTransportStopRoutesView(view.getContext(), false, false),
false, 0, false, null, true);
@@ -483,6 +486,9 @@ public class MenuBuilder {
}
}
+ protected void buildDescription(View view){
+ }
+
protected void buildAfter(View view) {
buildRowDivider(view);
}
@@ -505,20 +511,20 @@ public class MenuBuilder {
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,
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);
}
public View buildRow(View view, int iconId, String buttonText, String text, int textColor,
boolean collapsable, final CollapsableView collapsableView,
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);
}
- 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,
- int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
+ public View buildRow(final View view, Drawable icon, final String buttonText, final String textPrefix, final String text,
+ int textColor, String secondaryText, boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
+ int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
if (!isFirstRow()) {
buildRowDivider(view);
@@ -537,7 +543,8 @@ public class MenuBuilder {
ll.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
- copyToClipboard(text, view.getContext());
+ String textToCopy = Algorithms.isEmpty(textPrefix) ? text : textPrefix + ": " + text;
+ copyToClipboard(textToCopy, view.getContext());
return true;
}
});
@@ -572,30 +579,46 @@ public class MenuBuilder {
llText.setLayoutParams(llTextViewParams);
ll.addView(llText);
+ TextViewEx textPrefixView = null;
+ if (!Algorithms.isEmpty(textPrefix)) {
+ textPrefixView = new TextViewEx(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.setTypeface(FontCache.getRobotoRegular(view.getContext()));
+ textPrefixView.setTextSize(12);
+ textPrefixView.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light: R.color.text_color_secondary_dark));
+ textPrefixView.setMinLines(1);
+ textPrefixView.setMaxLines(1);
+ textPrefixView.setText(textPrefix);
+ llText.addView(textPrefixView);
+ }
+
// Primary text
TextViewEx textView = new TextViewEx(view.getContext());
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- llTextParams.setMargins(icon != null ? 0 : dpToPx(16f), dpToPx(secondaryText != null ? 10f : 8f), 0, dpToPx(secondaryText != null ? 6f : 8f));
+ llTextParams.setMargins(icon != null ? 0 : dpToPx(16f), dpToPx(textPrefixView != null ? 2f : (secondaryText != null ? 10f : 8f)), 0, dpToPx(secondaryText != null ? 6f : 8f));
textView.setLayoutParams(llTextParams);
textView.setTypeface(FontCache.getRobotoRegular(view.getContext()));
textView.setTextSize(16);
textView.setTextColor(app.getResources().getColor(light ? R.color.text_color_primary_light : R.color.text_color_primary_dark));
+ textView.setText(text);
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);
if (isUrl || isNumber || isEmail) {
textView.setTextColor(linkTextColor);
- } else if (needLinks) {
- Linkify.addLinks(textView, Linkify.ALL);
- textView.setLinksClickable(true);
+ } else if (needLinks && Linkify.addLinks(textView, Linkify.ALL)) {
+ textView.setMovementMethod(null);
textView.setLinkTextColor(linkTextColor);
+ textView.setOnTouchListener(new ClickableSpanTouchListener());
AndroidUtils.removeLinkUnderline(textView);
}
if (textLinesLimit > 0) {
textView.setMinLines(1);
textView.setMaxLines(textLinesLimit);
+ textView.setEllipsize(TextUtils.TruncateAt.END);
}
- textView.setText(text);
if (textColor > 0) {
textView.setTextColor(view.getResources().getColor(textColor));
}
@@ -706,7 +729,21 @@ public class MenuBuilder {
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) {
final String[] items = text.split("[,;]");
final Intent intent = new Intent(actionType);
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java
index 466070f46b..eb3e9f7112 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java
@@ -1,7 +1,6 @@
package net.osmand.plus.mapcontextmenu.builders;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
@@ -9,7 +8,6 @@ import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
-import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import android.text.TextUtils;
import android.text.util.Linkify;
@@ -23,13 +21,16 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
-import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
-import net.osmand.plus.*;
+import net.osmand.plus.OsmAndFormatter;
+import net.osmand.plus.OsmandPlugin;
+import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.MetricsConstants;
+import net.osmand.plus.R;
+import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
@@ -37,11 +38,13 @@ import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.views.POIMapLayer;
import net.osmand.plus.widgets.TextViewEx;
+import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikipedia.WikipediaArticleWikiLinkFragment;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser;
+
import org.apache.commons.logging.Log;
import java.math.RoundingMode;
@@ -173,10 +176,10 @@ public class AmenityMenuBuilder extends MenuBuilder {
needLinks = false;
}
textView.setText(text);
- if (needLinks) {
- Linkify.addLinks(textView, Linkify.ALL);
- textView.setLinksClickable(true);
+ if (needLinks && Linkify.addLinks(textView, Linkify.ALL)) {
+ textView.setMovementMethod(null);
textView.setLinkTextColor(linkTextColor);
+ textView.setOnTouchListener(new ClickableSpanTouchListener());
AndroidUtils.removeLinkUnderline(textView);
}
textView.setEllipsize(TextUtils.TruncateAt.END);
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java
index 5b3d7818a7..233f9c33a6 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java
@@ -3,15 +3,9 @@ package net.osmand.plus.mapcontextmenu.builders;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
-import android.text.TextUtils;
-import android.util.Log;
-import android.view.Gravity;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.LinearLayout;
-import android.widget.TextView;
-import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader;
@@ -27,7 +21,6 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.myplaces.FavoritesActivity;
-import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.widgets.TextViewEx;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@@ -73,7 +66,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
@Override
protected void buildTopInternal(View view) {
- buildDescription(view);
super.buildTopInternal(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) {
FavoriteGroup favoriteGroup = app.getFavorites().getGroup(fav);
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) {
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
List<Amenity> amenities = app.getResourceManager().searchAmenities(
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java
index 7fae86a6dd..a54f3e11db 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java
@@ -8,10 +8,10 @@ import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.LinearLayout;
-import net.osmand.data.LatLon;
-import net.osmand.data.PointDescription;
import net.osmand.GPXUtilities;
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.SelectedGpxFile;
import net.osmand.plus.OsmAndAppCustomization;
@@ -30,6 +30,7 @@ import java.util.Date;
import java.util.List;
public class WptPtMenuBuilder extends MenuBuilder {
+
private final WptPt wpt;
public WptPtMenuBuilder(@NonNull MapActivity mapActivity, final @NonNull WptPt wpt) {
@@ -50,6 +51,13 @@ public class WptPtMenuBuilder extends MenuBuilder {
}
@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
public void buildInternal(View view) {
if (wpt.time > 0) {
DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(view.getContext());
@@ -92,16 +100,7 @@ public class WptPtMenuBuilder extends MenuBuilder {
}
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) {
diff --git a/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java
index 02afd073b4..8ad5a94578 100644
--- a/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java
@@ -8,15 +8,10 @@ import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
-import android.text.Layout;
-import android.text.Selection;
-import android.text.Spannable;
-import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
-import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
@@ -26,6 +21,7 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
+import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
@@ -72,53 +68,11 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
if (UTM_FORMAT.equals(preference.getKey())) {
TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
if (summaryView != null) {
- summaryView.setOnTouchListener(getSummaryTouchListener());
+ summaryView.setOnTouchListener(new ClickableSpanTouchListener());
}
}
}
- private View.OnTouchListener getSummaryTouchListener() {
- return new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- int action = event.getAction();
-
- if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
- TextView widget = (TextView) v;
-
- int x = (int) event.getX();
- int y = (int) event.getY();
-
- x -= widget.getTotalPaddingLeft();
- y -= widget.getTotalPaddingTop();
-
- x += widget.getScrollX();
- y += widget.getScrollY();
-
- Layout layout = widget.getLayout();
- int line = layout.getLineForVertical(y);
- int off = layout.getOffsetForHorizontal(line, x);
-
- Spannable spannable = new SpannableString(widget.getText());
- ClickableSpan[] links = spannable.getSpans(off, off, ClickableSpan.class);
-
- if (links.length != 0) {
- if (action == MotionEvent.ACTION_UP) {
- links[0].onClick(widget);
- } else {
- Selection.setSelection(spannable, spannable.getSpanStart(links[0]), spannable.getSpanEnd(links[0]));
- }
- return true;
- } else {
- Selection.removeSelection(spannable);
- }
- }
-
- return false;
- }
- };
- }
-
private CharSequence getCoordinatesFormatSummary(Location loc, int format) {
double lat = loc != null ? loc.getLatitude() : 49.41869;
double lon = loc != null ? loc.getLongitude() : 8.67339;
diff --git a/OsmAnd/src/net/osmand/plus/widgets/tools/ClickableSpanTouchListener.java b/OsmAnd/src/net/osmand/plus/widgets/tools/ClickableSpanTouchListener.java
new file mode 100644
index 0000000000..5abb6e0815
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/widgets/tools/ClickableSpanTouchListener.java
@@ -0,0 +1,52 @@
+package net.osmand.plus.widgets.tools;
+
+import android.text.Layout;
+import android.text.Selection;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.style.ClickableSpan;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.TextView;
+
+public class ClickableSpanTouchListener implements View.OnTouchListener {
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ int action = event.getAction();
+
+ if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
+ TextView widget = (TextView) v;
+
+ int x = (int) event.getX();
+ int y = (int) event.getY();
+
+ x -= widget.getTotalPaddingLeft();
+ y -= widget.getTotalPaddingTop();
+
+ x += widget.getScrollX();
+ y += widget.getScrollY();
+
+ Layout layout = widget.getLayout();
+ int line = layout.getLineForVertical(y);
+ int off = layout.getOffsetForHorizontal(line, x);
+
+ Spannable spannable = new SpannableString(widget.getText());
+ ClickableSpan[] links = spannable.getSpans(off, off, ClickableSpan.class);
+
+ if (links.length != 0) {
+ if (action == MotionEvent.ACTION_UP) {
+ links[0].onClick(widget);
+ } else {
+ Selection.setSelection(spannable, spannable.getSpanStart(links[0]), spannable.getSpanEnd(links[0]));
+ }
+ return true;
+ } else {
+ Selection.removeSelection(spannable);
+ }
+ }
+
+ return false;
+ }
+
+} \ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java
index fc5294e7be..855492be92 100644
--- a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java
+++ b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java
@@ -12,30 +12,37 @@ import net.osmand.util.Algorithms;
import java.util.HashMap;
public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
+
private final static String KEY_PHONE = "Phone: ";
private final static String KEY_EMAIL = "Email: ";
private final static String KEY_WORKING_HOURS = "Working hours: ";
private final static String KEY_PRICE = "Price: ";
private final static String KEY_DIRECTIONS = "Directions: ";
private final static String KEY_DESCRIPTION = "Description";
-
+
+ private HashMap<String, String> descTokens;
+
public WikivoyageWptPtMenuBuilder(@NonNull MapActivity mapActivity, @NonNull WptPt 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
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 emails = descTokens.get(KEY_EMAIL);
String workingHours = descTokens.get(KEY_WORKING_HOURS);
String price = descTokens.get(KEY_PRICE);
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)) {
buildRow(view, R.drawable.ic_action_call_dark,
null, phones, 0,
@@ -68,23 +75,25 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
}
}
- private HashMap<String, String> getDescriptionTokens(String desc, String ... allowedKeys) {
- String[] tokens = desc.split("\n");
+ private HashMap<String, String> getDescriptionTokens(String desc, String... allowedKeys) {
HashMap<String, String> mTokens = new HashMap<>();
- for (String token : tokens) {
- boolean matched = false;
- for (String key : allowedKeys) {
- if (token.startsWith(key)) {
- matched = true;
- String value = token.substring(key.length()).trim();
- mTokens.put(key, value);
+ if (!Algorithms.isEmpty(desc)) {
+ String[] tokens = desc.split("\n");
+ for (String token : tokens) {
+ boolean matched = false;
+ for (String key : allowedKeys) {
+ if (token.startsWith(key)) {
+ matched = true;
+ String value = token.substring(key.length()).trim();
+ mTokens.put(key, value);
+ }
+ }
+ if (!matched) {
+ String s = mTokens.get(KEY_DESCRIPTION);
+ mTokens.put(KEY_DESCRIPTION, s != null ? s + "\n" + token : token);
}
- }
- if (!matched) {
- String s = mTokens.get(KEY_DESCRIPTION);
- mTokens.put(KEY_DESCRIPTION, s != null ? s + "\n" + token : token);
}
}
return mTokens;
}
-}
+} \ No newline at end of file