From 0a138db9a691b36d792786d22fde6e04d1aff8a3 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 15 Dec 2017 17:34:01 +0200 Subject: [PATCH] Change wikipedia in bottom view --- OsmAnd/res/values/strings.xml | 1 + .../plus/mapcontextmenu/MenuBuilder.java | 6 +- .../builders/AmenityMenuBuilder.java | 87 ++++++++++++------- 3 files changed, 60 insertions(+), 34 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index e8500adb27..5672053b25 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Read full article Read article All points of group Opened from diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index e48dfd4ee1..49fbd60af8 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -79,7 +79,7 @@ public class MenuBuilder { protected OsmandApplication app; protected LinkedList plainMenuItems; private boolean firstRow; - private boolean matchWidthDivider; + protected boolean matchWidthDivider; protected boolean light; private long objectId; private LatLon latLon; @@ -933,7 +933,7 @@ public class MenuBuilder { protected TextViewEx buildButtonInCollapsableView(Context context, boolean selected, boolean showAll) { TextViewEx button = new TextViewEx(new ContextThemeWrapper(context, light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme)); - LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) context.getResources().getDimension(R.dimen.context_menu_controller_height)); + LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(36f)); llWikiButtonParams.setMargins(0, 0, 0, dpToPx(8f)); button.setLayoutParams(llWikiButtonParams); button.setTypeface(FontCache.getRobotoRegular(context)); @@ -947,7 +947,7 @@ public class MenuBuilder { } button.setBackgroundResource(bg); button.setTextSize(14); - int paddingSides = (int) context.getResources().getDimension(R.dimen.context_menu_button_padding_x); + int paddingSides = dpToPx(10f); button.setPadding(paddingSides, 0, paddingSides, 0); if (!selected) { ColorStateList buttonColorStateList = new ColorStateList( diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 5b0d2d1b99..8e42c71832 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -2,11 +2,11 @@ package net.osmand.plus.mapcontextmenu.builders; import android.content.DialogInterface; import android.content.Intent; -import android.graphics.Color; +import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.net.Uri; import android.support.v7.app.AlertDialog; -import android.support.v7.widget.AppCompatButton; +import android.support.v7.view.ContextThemeWrapper; import android.text.Html; import android.text.SpannableString; import android.text.TextUtils; @@ -29,9 +29,11 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.FontCache; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.views.POIMapLayer; +import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; import net.osmand.util.OpeningHoursParser; @@ -61,7 +63,7 @@ public class AmenityMenuBuilder extends MenuBuilder { boolean collapsable, final CollapsableView collapsableView, int textColor, boolean isWiki, boolean isText, boolean needLinks, boolean isPhoneNumber, boolean isUrl) { - buildRow(view, getRowIcon(iconId), text, textPrefix, collapsable, collapsableView, textColor, + buildRow(view, iconId == 0 ? null : getRowIcon(iconId), text, textPrefix, collapsable, collapsableView, textColor, isWiki, isText, needLinks, isPhoneNumber, isUrl); } @@ -102,20 +104,22 @@ public class AmenityMenuBuilder extends MenuBuilder { baseView.addView(ll); // Icon - LinearLayout llIcon = new LinearLayout(view.getContext()); - llIcon.setOrientation(LinearLayout.HORIZONTAL); - llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(64f), dpToPx(48f))); - llIcon.setGravity(Gravity.CENTER_VERTICAL); - ll.addView(llIcon); + if (icon != null) { + LinearLayout llIcon = new LinearLayout(view.getContext()); + llIcon.setOrientation(LinearLayout.HORIZONTAL); + llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(64f), dpToPx(48f))); + llIcon.setGravity(Gravity.CENTER_VERTICAL); + ll.addView(llIcon); - ImageView iconView = new ImageView(view.getContext()); - LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f)); - llIconParams.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f)); - llIconParams.gravity = Gravity.CENTER_VERTICAL; - iconView.setLayoutParams(llIconParams); - iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); - iconView.setImageDrawable(icon); - llIcon.addView(iconView); + ImageView iconView = new ImageView(view.getContext()); + LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f)); + llIconParams.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f)); + llIconParams.gravity = Gravity.CENTER_VERTICAL; + iconView.setLayoutParams(llIconParams); + iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); + iconView.setImageDrawable(icon); + llIcon.addView(iconView); + } // Text LinearLayout llText = new LinearLayout(view.getContext()); @@ -124,7 +128,7 @@ public class AmenityMenuBuilder extends MenuBuilder { TextView textView = new TextView(view.getContext()); LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llTextParams.setMargins(0, collapsable ? dpToPx(13f) : dpToPx(8f), 0, collapsable ? dpToPx(13f) : dpToPx(8f)); + llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, collapsable ? dpToPx(13f) : dpToPx(8f), 0, collapsable ? dpToPx(13f) : dpToPx(8f)); textView.setLayoutParams(llTextParams); textView.setTextSize(16); textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark)); @@ -204,21 +208,43 @@ public class AmenityMenuBuilder extends MenuBuilder { } if (isWiki) { - AppCompatButton wikiButton = new AppCompatButton(view.getContext()); - LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llWikiButtonParams.setMargins(0, dpToPx(10f), dpToPx(2f), dpToPx(10f)); - wikiButton.setLayoutParams(llWikiButtonParams); - wikiButton.setPadding(dpToPx(14f), 0, dpToPx(14f), 0); - wikiButton.setBackgroundResource(R.drawable.blue_button_drawable); - wikiButton.setTextColor(Color.WHITE); - wikiButton.setText(app.getString(R.string.read_more)); - wikiButton.setOnClickListener(new View.OnClickListener() { + 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)); + llWikiButtonParams.setMargins(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 = new ColorStateList( + new int[][] { + new int[]{android.R.attr.state_pressed}, + new int[]{} + }, + new int[] { + view.getResources().getColor(light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p), + view.getResources().getColor(light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n) + } + ); + button.setTextColor(buttonColorStateList); + button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); + button.setSingleLine(true); + button.setEllipsize(TextUtils.TruncateAt.END); + button.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { + public void onClick(View view) { POIMapLayer.showWikipediaDialog(view.getContext(), app, amenity); } }); - llText.addView(wikiButton); + button.setAllCaps(true); + button.setText(R.string.context_menu_read_full_article); + Drawable compoundDrawable = app.getIconsCache().getIcon(R.drawable.ic_action_note_dark, light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n); + button.setCompoundDrawablesWithIntrinsicBounds(compoundDrawable, null, null, null); + button.setCompoundDrawablePadding(dpToPx(8f)); + llText.addView(button); + + matchWidthDivider = true; } ((LinearLayout) view).addView(baseView); @@ -284,7 +310,7 @@ public class AmenityMenuBuilder extends MenuBuilder { List descriptions = new LinkedList<>(); for (Map.Entry e : amenity.getAdditionalInfo().entrySet()) { - int iconId; + int iconId = 0; Drawable icon = null; int textColor = 0; String key = e.getKey(); @@ -322,7 +348,6 @@ public class AmenityMenuBuilder extends MenuBuilder { if (amenity.getType().isWiki()) { if (!hasWiki) { - iconId = R.drawable.ic_action_note_dark; String lng = amenity.getContentLanguage("content", preferredLang, "en"); if (Algorithms.isEmpty(lng)) { lng = "en"; @@ -507,7 +532,7 @@ public class AmenityMenuBuilder extends MenuBuilder { if (info.icon != null) { buildRow(view, info.icon, info.text, info.textPrefix, info.collapsable, info.collapsableView, info.textColor, info.isWiki, info.isText, info.needLinks, info.isPhoneNumber, info.isUrl); - } else if (info.iconId != 0) { + } else { buildRow(view, info.iconId, info.text, info.textPrefix, info.collapsable, info.collapsableView, info.textColor, info.isWiki, info.isText, info.needLinks, info.isPhoneNumber, info.isUrl); }