Merge pull request #5110 from osmandapp/FavouriteDescription

added row "Description" to Favourite in context menu
This commit is contained in:
vshcherb 2018-03-07 22:52:45 +01:00 committed by GitHub
commit 29722c269f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 87 additions and 3 deletions

View file

@ -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<Amenity> amenities = app.getResourceManager().searchAmenities(

View file

@ -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) {