From f5470c276ebe3ff38f86bdd89d1b52c4e9acfcd9 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 16 May 2018 14:26:39 +0300 Subject: [PATCH] refactored arrow replacing --- .../plus/mapcontextmenu/MenuBuilder.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index de3145093e..d34c61efd0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -829,20 +829,21 @@ public class MenuBuilder { titleView.setTextSize(16); titleView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark)); String desc = route.getDescription(getMapActivity().getMyApplication(), true); - + SpannableString stringWithImage = new SpannableString(desc); if (desc.contains("=>") || desc.contains(" - ")) { Drawable arrow = app.getIconsCache().getIcon(R.drawable.ic_arrow_right_16, light ? R.color.ctx_menu_route_icon_color_light : R.color.ctx_menu_route_icon_color_dark); Float ascent = titleView.getPaint().getFontMetrics().ascent; int h = (int) -ascent; - arrow.setBounds(0, 0, h, h); - SpannableString stringWithImage = new SpannableString(desc); - int i = desc.indexOf("=>"); - int d = desc.indexOf(" - "); - stringWithImage.setSpan(new ImageSpan(arrow, DynamicDrawableSpan.ALIGN_BASELINE), i == -1 ? d : i, i == -1 ? d + 3 : i + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - titleView.setText(stringWithImage); - } else { - titleView.setText(desc); + arrow.setBounds(0, 0, arrow.getIntrinsicWidth(), h); + int replaceIndex = desc.indexOf("=>"); + if (replaceIndex != -1) { + stringWithImage.setSpan(new ImageSpan(arrow, DynamicDrawableSpan.ALIGN_BASELINE), replaceIndex, replaceIndex + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } else { + replaceIndex = desc.indexOf(" - ") + 1; + stringWithImage.setSpan(new ImageSpan(arrow, DynamicDrawableSpan.ALIGN_BASELINE), replaceIndex, replaceIndex + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } } + titleView.setText(stringWithImage); infoView.addView(titleView); LinearLayout typeView = new LinearLayout(view.getContext());