From ff0d6a535c11d832f0f2c584b63020673c5dffd4 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 3 Feb 2021 21:28:22 +0500 Subject: [PATCH 1/3] Add HTML support --- .../builders/FavouritePointMenuBuilder.java | 22 ++++++-- .../osmand/plus/views/layers/POIMapLayer.java | 53 +++++++++++++------ .../menu/WikivoyageWptPtMenuBuilder.java | 20 +++++-- 3 files changed, 73 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index ca404569b1..48b8478e5a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -22,7 +22,9 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.CollapsableView; import net.osmand.plus.myplaces.FavoritesActivity; +import net.osmand.plus.views.layers.POIMapLayer; import net.osmand.plus.widgets.TextViewEx; +import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -82,11 +84,23 @@ 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); + protected void buildDescription(final View view) { + final String desc = fav.getDescription(); + if (Algorithms.isEmpty(desc)) { + return; } + + final String textPrefix = app.getString(R.string.shared_string_description); + View.OnClickListener clickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + POIMapLayer.showHtmlDescriptionDialog(view.getContext(), app, desc, textPrefix); + } + }; + + buildRow(view, null, null, textPrefix, WikiArticleHelper.getPartialContent(desc), 0, + null, false, null, true, 10, + false, false, false, clickListener, true); } private void buildGroupFavouritesView(View view) { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index 13352a81ee..dc2d6b794c 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -3,9 +3,11 @@ package net.osmand.plus.views.layers; import android.app.Dialog; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.PointF; import android.graphics.drawable.Drawable; import android.text.util.Linkify; +import android.util.Base64; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; @@ -41,6 +43,7 @@ import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.layers.MapTextLayer.MapTextProvider; +import net.osmand.plus.widgets.WebViewEx; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -272,7 +275,39 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } public static void showDescriptionDialog(Context ctx, OsmandApplication app, String text, String title) { - showText(ctx, app, text, title); + final TextView textView = new TextView(ctx); + LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + int textMargin = dpToPx(app, 10f); + boolean light = app.getSettings().isLightContent(); + textView.setLayoutParams(llTextParams); + textView.setPadding(textMargin, textMargin, textMargin, textMargin); + textView.setTextSize(16); + textView.setTextColor(ContextCompat.getColor(app, light ? R.color.text_color_primary_light : R.color.text_color_primary_dark)); + textView.setAutoLinkMask(Linkify.ALL); + textView.setLinksClickable(true); + textView.setText(text); + + showText(ctx, app, textView, title); + } + + public static void showHtmlDescriptionDialog(Context ctx, OsmandApplication app, String html, String title) { + final WebViewEx webView = new WebViewEx(ctx); + LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + webView.setLayoutParams(llTextParams); + int margin = dpToPx(app, 10f); + webView.setPadding(margin, margin, margin, margin); + webView.setScrollbarFadingEnabled(true); + webView.setVerticalScrollBarEnabled(false); + webView.setBackgroundColor(Color.TRANSPARENT); + webView.getSettings().setTextZoom((int) (app.getResources().getConfiguration().fontScale * 100f)); + boolean light = app.getSettings().isLightContent(); + int textColor = ContextCompat.getColor(app, light ? R.color.text_color_primary_light : R.color.text_color_primary_dark); + String rgbHex = Integer.toHexString(textColor).substring(2, 8); + html = "" + html + ""; + String encoded = Base64.encodeToString(html.getBytes(), Base64.NO_PADDING); + webView.loadData(encoded, "text/html", "base64"); + + showText(ctx, app, webView, title); } static int getResIdFromAttribute(final Context ctx, final int attr) { @@ -284,7 +319,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon return typedvalueattr.resourceId; } - private static void showText(final Context ctx, final OsmandApplication app, final String text, String title) { + private static void showText(final Context ctx, final OsmandApplication app, final View view, String title) { final Dialog dialog = new Dialog(ctx, app.getSettings().isLightContent() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); @@ -306,24 +341,12 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } }); - final TextView textView = new TextView(ctx); - LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - int textMargin = dpToPx(app, 10f); - boolean light = app.getSettings().isLightContent(); - textView.setLayoutParams(llTextParams); - textView.setPadding(textMargin, textMargin, textMargin, textMargin); - textView.setTextSize(16); - textView.setTextColor(ContextCompat.getColor(app, light ? R.color.text_color_primary_light : R.color.text_color_primary_dark)); - textView.setAutoLinkMask(Linkify.ALL); - textView.setLinksClickable(true); - textView.setText(text); - ScrollView scrollView = new ScrollView(ctx); ll.addView(topBar); LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0); lp.weight = 1; ll.addView(scrollView, lp); - scrollView.addView(textView); + scrollView.addView(view); dialog.setContentView(ll); dialog.setCancelable(true); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java index 9bc991422d..387fbfeb85 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java @@ -8,6 +8,8 @@ import net.osmand.GPXUtilities.WptPt; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.builders.WptPtMenuBuilder; +import net.osmand.plus.views.layers.POIMapLayer; +import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.util.Algorithms; import java.util.HashMap; @@ -29,11 +31,23 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder { } @Override - protected void buildDescription(View view) { + protected void buildDescription(final 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); + if (Algorithms.isEmpty(desc)) { + return; } + + final String textPrefix = app.getString(R.string.shared_string_description); + View.OnClickListener clickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + POIMapLayer.showHtmlDescriptionDialog(view.getContext(), app, desc, textPrefix); + } + }; + + buildRow(view, null, null, textPrefix, WikiArticleHelper.getPartialContent(desc), 0, + null, false, null, true, 10, + false, false, false, clickListener, true); } @Override From 7a089f367de1ab69264186b08f75d9d5cf8246da Mon Sep 17 00:00:00 2001 From: cepprice Date: Thu, 4 Feb 2021 13:16:00 +0500 Subject: [PATCH 2/3] Add 'Read Full' button to description in menu --- .../plus/mapcontextmenu/MenuBuilder.java | 141 ++++++++++++++++-- .../builders/AmenityMenuBuilder.java | 38 +---- .../builders/FavouritePointMenuBuilder.java | 28 +--- .../builders/WptPtMenuBuilder.java | 26 +++- .../menu/WikivoyageWptPtMenuBuilder.java | 27 +--- 5 files changed, 164 insertions(+), 96 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 2ad2bb6ee4..269f0e822a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -28,13 +28,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.view.ContextThemeWrapper; -import androidx.core.content.ContextCompat; -import androidx.core.graphics.drawable.DrawableCompat; - import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.data.Amenity; @@ -74,6 +67,7 @@ import net.osmand.plus.views.layers.POIMapLayer; import net.osmand.plus.views.layers.TransportStopsLayer; import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.tools.ClickableSpanTouchListener; +import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -89,6 +83,13 @@ import java.util.List; import java.util.Map; import java.util.Set; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.view.ContextThemeWrapper; +import androidx.core.content.ContextCompat; +import androidx.core.graphics.drawable.DrawableCompat; + import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener; public class MenuBuilder { @@ -801,18 +802,98 @@ 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() { + public View buildDescriptionRow(final View view, final String description) { + + final String descriptionLabel = app.getString(R.string.shared_string_description); + View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View v) { - POIMapLayer.showDescriptionDialog(view.getContext(), app, description, textPrefix); + POIMapLayer.showHtmlDescriptionDialog(view.getContext(), app, description, descriptionLabel); } }; - return buildRow(view, null, null, textPrefix, description, textColor, - null, false, null, true, textLinesLimit, - false, false, false, clickListener, 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); + LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT); + llTextViewParams.weight = 1f; + AndroidUtils.setMargins(llTextViewParams, 0, 0, dpToPx(10f), 0); + llTextViewParams.gravity = Gravity.CENTER_VERTICAL; + llText.setLayoutParams(llTextViewParams); + ll.addView(llText); + + // Description label + TextViewEx textPrefixView = new TextViewEx(view.getContext()); + LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + AndroidUtils.setMargins(llTextParams, dpToPx(16f), 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(descriptionLabel); + llText.addView(textPrefixView); + + // Description + TextViewEx textView = new TextViewEx(view.getContext()); + LinearLayout.LayoutParams llDescriptionParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + AndroidUtils.setMargins(llDescriptionParams, dpToPx(16f), dpToPx(2f), 0, dpToPx(8f)); + textView.setLayoutParams(llDescriptionParams); + 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(WikiArticleHelper.getPartialContent(description)); + + if (Linkify.addLinks(textView, Linkify.ALL)) { + textView.setMovementMethod(null); + 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); + textView.setLinkTextColor(linkTextColor); + textView.setOnTouchListener(new ClickableSpanTouchListener()); + AndroidUtils.removeLinkUnderline(textView); + } + textView.setMinLines(1); + textView.setMaxLines(10); + textView.setEllipsize(TextUtils.TruncateAt.END); + llText.addView(textView); + + // Read Full button + buildReadFullButton(llText, app.getString(R.string.context_menu_read_full), onClickListener); + + if (onClickListener != null) { + ll.setOnClickListener(onClickListener); + } + ((LinearLayout) view).addView(baseView); + + rowBuilt(); + setDividerWidth(true); + + return ll; } protected void showDialog(String text, final String actionType, final String dataPrefix, final View v) { @@ -908,6 +989,38 @@ public class MenuBuilder { ((LinearLayout) view).addView(horizontalLine); } + protected void buildReadFullButton(LinearLayout container, String btnText, View.OnClickListener onClickListener) { + Context ctx = container.getContext(); + + TextViewEx button = new TextViewEx(new ContextThemeWrapper(ctx, light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme)); + LinearLayout.LayoutParams llButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dpToPx(36f)); + AndroidUtils.setMargins(llButtonParams, dpToPx(16f), 0, 0, dpToPx(16f)); + button.setLayoutParams(llButtonParams); + button.setTypeface(FontCache.getRobotoMedium(app)); + button.setBackgroundResource(light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); + button.setTextSize(14); + int paddingSides = dpToPx(10f); + button.setPadding(paddingSides, 0, paddingSides, 0); + ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(ctx, !light, + R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, + R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p); + button.setTextColor(buttonColorStateList); + button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); + button.setSingleLine(true); + button.setEllipsize(TextUtils.TruncateAt.END); + button.setOnClickListener(onClickListener); + button.setAllCaps(true); + button.setText(btnText); + Drawable normal = app.getUIUtilities().getIcon(R.drawable.ic_action_read_text, + light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n); + Drawable pressed = app.getUIUtilities().getIcon(R.drawable.ic_action_read_text, + light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(button, Build.VERSION.SDK_INT >= 21 + ? AndroidUtils.createPressedStateListDrawable(normal, pressed) : normal, null, null, null); + button.setCompoundDrawablePadding(dpToPx(8f)); + container.addView(button); + } + public boolean hasCustomAddressLine() { return false; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 54e04071fa..846c2cdd0e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -2,10 +2,8 @@ package net.osmand.plus.mapcontextmenu.builders; import android.content.Context; import android.content.Intent; -import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.net.Uri; -import android.os.Build; import android.text.TextUtils; import android.text.util.Linkify; import android.view.Gravity; @@ -15,10 +13,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.appcompat.view.ContextThemeWrapper; -import androidx.core.content.ContextCompat; - import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.data.Amenity; @@ -31,7 +25,6 @@ import net.osmand.plus.OsmandPlugin; 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.helpers.enums.MetricsConstants; import net.osmand.plus.mapcontextmenu.CollapsableView; import net.osmand.plus.mapcontextmenu.MenuBuilder; @@ -67,6 +60,9 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; + public class AmenityMenuBuilder extends MenuBuilder { private static final String WIKI_LINK = ".wikipedia.org/w"; @@ -259,38 +255,12 @@ public class AmenityMenuBuilder extends MenuBuilder { } if (isWiki) { - TextViewEx button = new TextViewEx(new ContextThemeWrapper(view.getContext(), light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme)); - LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dpToPx(36f)); - AndroidUtils.setMargins(llWikiButtonParams, dpToPx(16f), 0, 0, dpToPx(16f)); - button.setLayoutParams(llWikiButtonParams); - button.setTypeface(FontCache.getRobotoMedium(app)); - button.setBackgroundResource(light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); - button.setTextSize(14); - int paddingSides = dpToPx(10f); - button.setPadding(paddingSides, 0, paddingSides, 0); - ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(view.getContext(), !light, - R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, - R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p); - button.setTextColor(buttonColorStateList); - button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); - button.setSingleLine(true); - button.setEllipsize(TextUtils.TruncateAt.END); - button.setOnClickListener(new View.OnClickListener() { + buildReadFullButton(llText, app.getString(R.string.context_menu_read_full_article), new View.OnClickListener() { @Override public void onClick(View view) { WikipediaDialogFragment.showInstance(mapActivity, amenity); } }); - button.setAllCaps(true); - button.setText(R.string.context_menu_read_full_article); - Drawable normal = app.getUIUtilities().getIcon(R.drawable.ic_action_read_text, - light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n); - Drawable pressed = app.getUIUtilities().getIcon(R.drawable.ic_action_read_text, - light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p); - AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(button, Build.VERSION.SDK_INT >= 21 - ? AndroidUtils.createPressedStateListDrawable(normal, pressed) : normal, null, null, null); - button.setCompoundDrawablePadding(dpToPx(8f)); - llText.addView(button); } ((LinearLayout) view).addView(baseView); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 48b8478e5a..113ff5c12e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -4,8 +4,6 @@ import android.content.Context; import android.view.View; import android.widget.LinearLayout; -import androidx.annotation.NonNull; - import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapIndexReader; @@ -19,18 +17,18 @@ import net.osmand.osm.PoiCategory; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.CollapsableView; +import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.myplaces.FavoritesActivity; -import net.osmand.plus.views.layers.POIMapLayer; import net.osmand.plus.widgets.TextViewEx; -import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.io.IOException; import java.util.List; +import androidx.annotation.NonNull; + public class FavouritePointMenuBuilder extends MenuBuilder { private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(FavouritePointMenuBuilder.class); @@ -84,23 +82,11 @@ public class FavouritePointMenuBuilder extends MenuBuilder { } @Override - protected void buildDescription(final View view) { - final String desc = fav.getDescription(); - if (Algorithms.isEmpty(desc)) { - return; + protected void buildDescription(View view) { + String desc = fav.getDescription(); + if (!Algorithms.isEmpty(desc)) { + buildDescriptionRow(view, desc); } - - final String textPrefix = app.getString(R.string.shared_string_description); - View.OnClickListener clickListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - POIMapLayer.showHtmlDescriptionDialog(view.getContext(), app, desc, textPrefix); - } - }; - - buildRow(view, null, null, textPrefix, WikiArticleHelper.getPartialContent(desc), 0, - null, false, null, true, 10, - false, false, false, clickListener, true); } private void buildGroupFavouritesView(View view) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java index c6a287f86b..278e0cd432 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java @@ -4,10 +4,6 @@ import android.content.Context; import android.view.View; import android.widget.LinearLayout; -import androidx.annotation.ColorInt; -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; - import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.WptPt; import net.osmand.IndexConstants; @@ -30,6 +26,10 @@ import java.text.DateFormat; import java.util.Date; import java.util.List; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; + public class WptPtMenuBuilder extends MenuBuilder { private final WptPt wpt; @@ -52,10 +52,22 @@ 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); + protected void buildDescription(final View view) { + if (Algorithms.isEmpty(wpt.desc)) { + return; } + + final String textPrefix = app.getString(R.string.shared_string_description); + View.OnClickListener clickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + POIMapLayer.showDescriptionDialog(view.getContext(), app, wpt.desc, textPrefix); + } + }; + + buildRow(view, null, null, textPrefix, wpt.desc, 0, + null, false, null, true, 10, + false, false, false, clickListener, matchWidthDivider); } @Override diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java index 387fbfeb85..bca5943212 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java @@ -2,18 +2,16 @@ package net.osmand.plus.wikivoyage.menu; import android.view.View; -import androidx.annotation.NonNull; - import net.osmand.GPXUtilities.WptPt; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.builders.WptPtMenuBuilder; -import net.osmand.plus.views.layers.POIMapLayer; -import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.util.Algorithms; import java.util.HashMap; +import androidx.annotation.NonNull; + public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder { private final static String KEY_PHONE = "Phone: "; @@ -31,25 +29,14 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder { } @Override - protected void buildDescription(final View view) { - final String desc = descTokens.get(KEY_DESCRIPTION); - if (Algorithms.isEmpty(desc)) { - return; + protected void buildDescription(View view) { + String desc = descTokens.get(KEY_DESCRIPTION); + if (!Algorithms.isEmpty(desc)) { + buildDescriptionRow(view, desc); } - - final String textPrefix = app.getString(R.string.shared_string_description); - View.OnClickListener clickListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - POIMapLayer.showHtmlDescriptionDialog(view.getContext(), app, desc, textPrefix); - } - }; - - buildRow(view, null, null, textPrefix, WikiArticleHelper.getPartialContent(desc), 0, - null, false, null, true, 10, - false, false, false, clickListener, true); } + @Override protected void prepareDescription(final WptPt wpt, View view) { String phones = descTokens.get(KEY_PHONE); From efac53555ac025950b1b0a391cce0219e049e2f8 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 8 Feb 2021 01:04:55 +0200 Subject: [PATCH 3/3] Small fixes --- .../osmand/plus/mapcontextmenu/MenuBuilder.java | 14 +++++++------- .../net/osmand/plus/views/layers/POIMapLayer.java | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 269f0e822a..a761b508f2 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -28,6 +28,13 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.view.ContextThemeWrapper; +import androidx.core.content.ContextCompat; +import androidx.core.graphics.drawable.DrawableCompat; + import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.data.Amenity; @@ -83,13 +90,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.view.ContextThemeWrapper; -import androidx.core.content.ContextCompat; -import androidx.core.graphics.drawable.DrawableCompat; - import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener; public class MenuBuilder { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index dc2d6b794c..758588228f 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -302,8 +302,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon webView.getSettings().setTextZoom((int) (app.getResources().getConfiguration().fontScale * 100f)); boolean light = app.getSettings().isLightContent(); int textColor = ContextCompat.getColor(app, light ? R.color.text_color_primary_light : R.color.text_color_primary_dark); - String rgbHex = Integer.toHexString(textColor).substring(2, 8); - html = "" + html + ""; + String rgbHex = Algorithms.colorToString(textColor); + html = "" + html + ""; String encoded = Base64.encodeToString(html.getBytes(), Base64.NO_PADDING); webView.loadData(encoded, "text/html", "base64");