From faa2c0f2efdb93bbae935f417833a0279ab64bfb Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 21 Oct 2019 19:01:14 +0300 Subject: [PATCH] Unify context menu description row --- .../plus/mapcontextmenu/MenuBuilder.java | 58 +++++++++--- .../builders/FavouritePointMenuBuilder.java | 94 ++----------------- .../builders/WptPtMenuBuilder.java | 23 +++-- .../menu/WikivoyageWptPtMenuBuilder.java | 23 +++-- 4 files changed, 81 insertions(+), 117 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index e03b5bf31b..23c666de58 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -56,6 +56,7 @@ 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.util.Algorithms; @@ -471,6 +472,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 +485,9 @@ public class MenuBuilder { } } + protected void buildDescription(View view){ + } + protected void buildAfter(View 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, 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 +542,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,6 +578,21 @@ public class MenuBuilder { llText.setLayoutParams(llTextViewParams); 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 TextViewEx textView = new TextViewEx(view.getContext()); 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.setTextSize(16); 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); @@ -595,10 +621,6 @@ public class MenuBuilder { textView.setMinLines(1); textView.setMaxLines(textLinesLimit); } - textView.setText(text); - if (textColor > 0) { - textView.setTextColor(view.getResources().getColor(textColor)); - } llText.addView(textView); // Secondary text @@ -706,7 +728,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/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 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 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) { @@ -49,6 +50,13 @@ public class WptPtMenuBuilder extends MenuBuilder { 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 public void buildInternal(View view) { if (wpt.time > 0) { @@ -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/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuBuilder.java index fc5294e7be..8c274c9497 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 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 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,7 +75,7 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder { } } - private HashMap getDescriptionTokens(String desc, String ... allowedKeys) { + private HashMap getDescriptionTokens(String desc, String... allowedKeys) { String[] tokens = desc.split("\n"); HashMap mTokens = new HashMap<>(); for (String token : tokens) { @@ -87,4 +94,4 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder { } return mTokens; } -} +} \ No newline at end of file