From 110e52a73e4706ed2a17dd1f32b6cabf21a59d17 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 7 Mar 2018 19:08:12 +0200 Subject: [PATCH] added row "Description" to favourite in context menu --- .../builders/FavouritePointMenuBuilder.java | 87 +++++++++++++++++++ .../FavouritePointMenuController.java | 3 - 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 98600e0e05..4616d5696f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -4,9 +4,14 @@ import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.support.annotation.NonNull; +import android.text.TextUtils; +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.ResultMatcher; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.Amenity; @@ -23,6 +28,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.widgets.TextViewEx; +import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.util.List; @@ -64,6 +70,7 @@ public class FavouritePointMenuBuilder extends MenuBuilder { @Override protected void buildTopInternal(View view) { + buildDescription(view); super.buildTopInternal(view); buildGroupFavouritesView(view); } @@ -92,6 +99,86 @@ 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 = null; + 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.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.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_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, 5, 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/controllers/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java index 509d1312d2..94349ab4ee 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java @@ -137,9 +137,6 @@ public class FavouritePointMenuController extends MenuController { @Override public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { - if (!Algorithms.isEmpty(fav.getDescription())) { - addPlainMenuItem(R.drawable.ic_action_note_dark, null, fav.getDescription(), true, false, null); - } Object originObject = getBuilder().getOriginObject(); if (originObject != null) { if (originObject instanceof Amenity) {