From 2c53ffd59897f81ea8b2a9ef4c78feccf14c563e Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 17 Dec 2018 14:12:03 +0200 Subject: [PATCH] Add CustomTypefaceSpan and refactor route cards --- .../java/net/osmand/data/TransportRoute.java | 20 +- OsmAnd/res/layout/transport_route_card.xml | 15 +- OsmAnd/res/values/strings.xml | 1 + .../TransportStopRouteAdapter.java | 15 +- .../MapRouteInfoMenu.java | 3 +- .../MapRouteInfoMenuFragment.java | 1 - .../routeCards/BaseRouteCard.java | 10 +- .../routeCards/PublicTransportCard.java | 205 +++++++++--------- .../routeCards/SimpleRouteCard.java | 44 ++-- .../widgets/style/CustomTypefaceSpan.java | 31 +++ 10 files changed, 191 insertions(+), 154 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/widgets/style/CustomTypefaceSpan.java diff --git a/OsmAnd-java/src/main/java/net/osmand/data/TransportRoute.java b/OsmAnd-java/src/main/java/net/osmand/data/TransportRoute.java index 70997955f5..d995c811e4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/TransportRoute.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/TransportRoute.java @@ -1,5 +1,9 @@ package net.osmand.data; +import net.osmand.osm.edit.Node; +import net.osmand.osm.edit.Way; +import net.osmand.util.MapUtils; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -8,10 +12,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import net.osmand.osm.edit.Node; -import net.osmand.osm.edit.Way; -import net.osmand.util.MapUtils; - public class TransportRoute extends MapObject { private List forwardStops = new ArrayList(); private String ref; @@ -209,4 +209,16 @@ public class TransportRoute extends MapObject { return d; } + public String getAdjustedRouteRef() { + if (ref != null) { + int charPos = ref.lastIndexOf(':'); + if (charPos != -1) { + ref = ref.substring(0, charPos); + } + if (ref.length() > 4) { + ref = ref.substring(0, 4); + } + } + return ref; + } } \ No newline at end of file diff --git a/OsmAnd/res/layout/transport_route_card.xml b/OsmAnd/res/layout/transport_route_card.xml index fb26a5e273..afd806be95 100644 --- a/OsmAnd/res/layout/transport_route_card.xml +++ b/OsmAnd/res/layout/transport_route_card.xml @@ -5,12 +5,13 @@ android:id="@+id/route_info_details_card" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical"> + android:orientation="vertical" + android:paddingBottom="10dp"> - @@ -88,6 +93,8 @@ \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index f852766a8d..6d576e1607 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -10,6 +10,7 @@ - For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience Thx - Hardy --> + transfers: %1$s on foot: %1$s Way: %1$s Points of interests(POI) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java index 727d741234..d640dda9e5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java @@ -45,7 +45,7 @@ public class TransportStopRouteAdapter extends ArrayAdapter { int bgColor = 0; if (object instanceof TransportStopRoute) { TransportStopRoute transportStopRoute = (TransportStopRoute) object; - routeRef = getAdjustedRouteRef(transportStopRoute.route.getRef()); + routeRef = transportStopRoute.route.getAdjustedRouteRef(); bgColor = transportStopRoute.getColor(app, nightMode); } else if (object instanceof String) { routeRef = (String) object; @@ -70,19 +70,6 @@ public class TransportStopRouteAdapter extends ArrayAdapter { return convertView; } - private String getAdjustedRouteRef(String ref) { - if (ref != null) { - int charPos = ref.lastIndexOf(':'); - if (charPos != -1) { - ref = ref.substring(0, charPos); - } - if (ref.length() > 4) { - ref = ref.substring(0, 4); - } - } - return ref; - } - public interface OnClickListener { void onClick(int position); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index dac4673540..8f64e8ff04 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -338,8 +338,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { public void build(LinearLayout rootView) { rootView.removeAllViews(); for (BaseRouteCard card : routeCards) { - card.bindViewHolder(); - rootView.addView(card.getView()); + rootView.addView(card.createCardView()); } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java index 9a8292a1d1..100b362122 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java @@ -120,7 +120,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { } cardsContainer = (LinearLayout) view.findViewById(R.id.route_menu_cards_container); -// cardsContainer.setBackgroundColor(getResources().getColor(nightMode ? R.color.activity_background_dark : R.color.activity_background_light)); buildBottomView(); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/BaseRouteCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/BaseRouteCard.java index b9fe680506..20a2592641 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/BaseRouteCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/BaseRouteCard.java @@ -13,20 +13,18 @@ import net.osmand.plus.R; public abstract class BaseRouteCard { protected OsmandApplication app; - protected boolean nightMode; - protected View view; + protected boolean isLastItem; + protected boolean nightMode; public BaseRouteCard(OsmandApplication app, boolean nightMode) { this.app = app; this.nightMode = nightMode; } - public abstract void bindViewHolder(); + public abstract View createCardView(); - public View getView() { - return view; - } + protected abstract void applyDayNightMode(); @ColorInt protected int getResolvedColor(@ColorRes int colorId) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/PublicTransportCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/PublicTransportCard.java index f131d8c31e..91e0496d3a 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/PublicTransportCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/PublicTransportCard.java @@ -1,11 +1,11 @@ package net.osmand.plus.routepreparationmenu.routeCards; +import android.graphics.Typeface; import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.support.v4.content.ContextCompat; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; -import android.text.style.StyleSpan; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -20,23 +20,31 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.FontCache; import net.osmand.plus.routepreparationmenu.FlowLayout; import net.osmand.plus.routing.TransportRoutingHelper; import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.transport.TransportStopType; -import net.osmand.router.TransportRoutePlanner; +import net.osmand.plus.widgets.style.CustomTypefaceSpan; +import net.osmand.router.TransportRoutePlanner.TransportRouteResult; +import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment; import java.util.Iterator; +import java.util.List; public class PublicTransportCard extends BaseRouteCard { + private static final int MIN_WALK_TIME = 120; private MapActivity mapActivity; - private TransportRoutePlanner.TransportRouteResult routeResult; - private final TransportRoutingHelper transportHelper; + private TransportRouteResult routeResult; + private TransportRoutingHelper transportHelper; + + private View view; + private int routeId; - public PublicTransportCard(MapActivity mapActivity, boolean nightMode, TransportRoutePlanner.TransportRouteResult routeResult, int routeId) { + public PublicTransportCard(MapActivity mapActivity, boolean nightMode, TransportRouteResult routeResult, int routeId) { super(mapActivity.getMyApplication(), nightMode); this.transportHelper = app.getTransportRoutingHelper(); this.mapActivity = mapActivity; @@ -45,81 +53,18 @@ public class PublicTransportCard extends BaseRouteCard { } @Override - public void bindViewHolder() { + public View createCardView() { view = mapActivity.getLayoutInflater().inflate(R.layout.transport_route_card, null); view.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light)); - int itemsSpacing = AndroidUtils.dpToPx(app, 6); - - FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges); - - Iterator iterator = routeResult.getSegments().iterator(); - - while (iterator.hasNext()) { - TransportRoutePlanner.TransportRouteResultSegment s = iterator.next(); - if (s.walkDist != 0) { - double walkTime = getWalkTime(s.walkDist, routeResult.getWalkSpeed()); - if (walkTime > 120) { - String walkTimeS = OsmAndFormatter.getFormattedDuration((int) walkTime, app); - routesBadges.addView(createWalkRouteBadge(walkTimeS), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); - routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); - } - } - routesBadges.addView(createRouteBadge(s), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); - if (iterator.hasNext()) { - routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); - } else { - double finishWalkDist = routeResult.getFinishWalkDist(); - if (finishWalkDist > 0) { - double walkTime2 = getWalkTime(finishWalkDist, routeResult.getWalkSpeed()); - if (walkTime2 > 120) { - String walkTimeS = OsmAndFormatter.getFormattedDuration((int) walkTime2, app); - routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); - routesBadges.addView(createWalkRouteBadge(walkTimeS)); - } - } - } - } + List segments = routeResult.getSegments(); + createRouteBadges(segments); TextView fromLine = (TextView) view.findViewById(R.id.from_line); TextView wayLine = (TextView) view.findViewById(R.id.way_line); - String name = routeResult.getSegments().get(0).getStart().getName(); - String firstLine = app.getString(R.string.route_from) + " " + name; - if (routeResult.getSegments().size() > 1) { - firstLine += ", transfers: " + (routeResult.getSegments().size() - 1); - } - SpannableString spannableDesc1 = new SpannableString(firstLine); - - spannableDesc1.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), - firstLine.indexOf(name), firstLine.indexOf(name) + name.length(), 0); - - fromLine.setText(spannableDesc1); - String travelTime = OsmAndFormatter.getFormattedDuration((int) routeResult.getTravelTime(), app); - String walkTime = OsmAndFormatter.getFormattedDuration((int) routeResult.getWalkTime(), app); - String walkDistance = OsmAndFormatter.getFormattedDistance((int) routeResult.getTravelDist(), app); - - String secondLine = app.getString(R.string.route_way, travelTime) + " • " + app.getString(R.string.on_foot, walkTime) + " • " + walkDistance; - - SpannableString spannableDesc = new SpannableString(secondLine); - - spannableDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), - secondLine.indexOf(travelTime), secondLine.indexOf(travelTime) + travelTime.length(), 0); - spannableDesc.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), - secondLine.indexOf(travelTime), secondLine.indexOf(travelTime) + travelTime.length(), 0); - - spannableDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), - secondLine.indexOf(walkTime), secondLine.indexOf(walkTime) + walkTime.length(), 0); - spannableDesc.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), - secondLine.indexOf(walkTime), secondLine.indexOf(walkTime) + walkTime.length(), 0); - - wayLine.setText(spannableDesc); - wayLine.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - } - }); + fromLine.setText(getFirstLineDescrSpan()); + wayLine.setText(getSecondLineDescrSpan()); FrameLayout detailsButton = view.findViewById(R.id.details_button); detailsButton.setOnClickListener(new View.OnClickListener() { @@ -133,42 +78,113 @@ public class PublicTransportCard extends BaseRouteCard { if (isLastItem) { view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom() + AndroidUtils.dpToPx(app, 60)); } + return view; } - private void applyDayNightMode() { + protected void applyDayNightMode() { TextView fromLine = (TextView) view.findViewById(R.id.from_line); TextView wayLine = (TextView) view.findViewById(R.id.way_line); AndroidUtils.setTextSecondaryColor(app, fromLine, nightMode); AndroidUtils.setTextSecondaryColor(app, wayLine, nightMode); - FrameLayout detailsButton = view.findViewById(R.id.details_button); + FrameLayout detailsButton = (FrameLayout) view.findViewById(R.id.details_button); + TextView detailsButtonDescr = (TextView) view.findViewById(R.id.details_button_descr); AndroidUtils.setBackground(app, detailsButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - AndroidUtils.setBackground(app, view.findViewById(R.id.details_button_descr), nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); + AndroidUtils.setBackground(app, detailsButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); } else { - AndroidUtils.setBackground(app, view.findViewById(R.id.details_button_descr), nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); + AndroidUtils.setBackground(app, detailsButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); } - AndroidUtils.setBackground(app, view, nightMode, R.color.activity_background_light, R.color.activity_background_dark); - AndroidUtils.setBackground(app, view.findViewById(R.id.top_divider), nightMode, - R.color.divider_light, R.color.divider_dark); - AndroidUtils.setBackground(app, view.findViewById(R.id.routes_info_container), nightMode, - R.color.route_info_bg_light, R.color.route_info_bg_dark); + AndroidUtils.setBackground(app, view.findViewById(R.id.top_divider), nightMode, R.color.divider_light, R.color.divider_dark); + AndroidUtils.setBackground(app, view.findViewById(R.id.routes_info_container), nightMode, R.color.route_info_bg_light, R.color.route_info_bg_dark); int color = ContextCompat.getColor(mapActivity, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); - - ((TextView) view.findViewById(R.id.details_button_descr)).setTextColor(color); - + detailsButtonDescr.setTextColor(color); } - private View createRouteBadge(TransportRoutePlanner.TransportRouteResultSegment segment) { + private SpannableString getFirstLineDescrSpan() { + List segments = routeResult.getSegments(); + String name = segments.get(0).getStart().getName(); + String firstLine = app.getString(R.string.route_from) + " " + name; + + if (segments.size() > 1) { + firstLine += ", " + app.getString(R.string.transfers, (segments.size() - 1)); + } + + SpannableString firstLineDesc = new SpannableString(firstLine); + Typeface typeface = FontCache.getRobotoMedium(app); + firstLineDesc.setSpan(new CustomTypefaceSpan(typeface), + firstLine.indexOf(name), firstLine.indexOf(name) + name.length(), 0); + firstLineDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), + firstLine.indexOf(name), firstLine.indexOf(name) + name.length(), 0); + + return firstLineDesc; + } + + private SpannableString getSecondLineDescrSpan() { + Typeface typeface = FontCache.getRobotoMedium(app); + String travelTime = OsmAndFormatter.getFormattedDuration((int) routeResult.getTravelTime(), app); + String walkTime = OsmAndFormatter.getFormattedDuration((int) routeResult.getWalkTime(), app); + String walkDistance = OsmAndFormatter.getFormattedDistance((int) routeResult.getTravelDist(), app); + + String secondLine = app.getString(R.string.route_way, travelTime) + " • " + app.getString(R.string.on_foot, walkTime) + " • " + walkDistance; + + SpannableString secondLineDesc = new SpannableString(secondLine); + + secondLineDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), + secondLine.indexOf(travelTime), secondLine.indexOf(travelTime) + travelTime.length(), 0); + secondLineDesc.setSpan(new CustomTypefaceSpan(typeface), + secondLine.indexOf(travelTime), secondLine.indexOf(travelTime) + travelTime.length(), 0); + + secondLineDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), + secondLine.indexOf(walkTime), secondLine.indexOf(walkTime) + walkTime.length(), 0); + secondLineDesc.setSpan(new CustomTypefaceSpan(typeface), + secondLine.indexOf(walkTime), secondLine.indexOf(walkTime) + walkTime.length(), 0); + + return secondLineDesc; + } + + private void createRouteBadges(List segments) { + int itemsSpacing = AndroidUtils.dpToPx(app, 6); + FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges); + + Iterator iterator = segments.iterator(); + while (iterator.hasNext()) { + TransportRouteResultSegment s = iterator.next(); + if (s.walkDist != 0) { + double walkTime = getWalkTime(s.walkDist, routeResult.getWalkSpeed()); + if (walkTime > MIN_WALK_TIME) { + String walkTimeS = OsmAndFormatter.getFormattedDuration((int) walkTime, app); + routesBadges.addView(createWalkRouteBadge(walkTimeS.toLowerCase()), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); + routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); + } + } + routesBadges.addView(createRouteBadge(s), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); + if (iterator.hasNext()) { + routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); + } else { + double finishWalkDist = routeResult.getFinishWalkDist(); + if (finishWalkDist > 0) { + double walkTime2 = getWalkTime(finishWalkDist, routeResult.getWalkSpeed()); + if (walkTime2 > MIN_WALK_TIME) { + String walkTimeS = OsmAndFormatter.getFormattedDuration((int) walkTime2, app); + routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); + routesBadges.addView(createWalkRouteBadge(walkTimeS.toLowerCase())); + } + } + } + } + } + + private View createRouteBadge(TransportRouteResultSegment segment) { LinearLayout convertView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false); if (segment != null) { TransportRoute transportRoute = segment.route; TransportStopRoute transportStopRoute = getTransportStopRoute(transportRoute, segment.getStart()); - String routeRef = getAdjustedRouteRef(segment.route.getRef()); + String routeRef = segment.route.getAdjustedRouteRef(); int bgColor = transportStopRoute.getColor(app, nightMode); TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text); @@ -223,20 +239,7 @@ public class PublicTransportCard extends BaseRouteCard { return r; } - private String getAdjustedRouteRef(String ref) { - if (ref != null) { - int charPos = ref.lastIndexOf(':'); - if (charPos != -1) { - ref = ref.substring(0, charPos); - } - if (ref.length() > 4) { - ref = ref.substring(0, 4); - } - } - return ref; - } - private double getWalkTime(double walkDist, double walkSpeed) { return walkDist / walkSpeed; } -} +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/SimpleRouteCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/SimpleRouteCard.java index 73bb34e556..743cc2ccb9 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/SimpleRouteCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/routeCards/SimpleRouteCard.java @@ -31,7 +31,9 @@ public class SimpleRouteCard extends BaseRouteCard { private MapActivity mapActivity; private GPXUtilities.GPXFile gpx; - private final RoutingHelper routingHelper; + private RoutingHelper routingHelper; + + private View view; public SimpleRouteCard(MapActivity mapActivity, boolean nightMode, GPXUtilities.GPXFile gpx) { super(mapActivity.getMyApplication(), nightMode); @@ -41,7 +43,7 @@ public class SimpleRouteCard extends BaseRouteCard { } @Override - public void bindViewHolder() { + public View createCardView() { view = mapActivity.getLayoutInflater().inflate(R.layout.route_info_statistic, null); view.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light)); @@ -93,7 +95,21 @@ public class SimpleRouteCard extends BaseRouteCard { AndroidUtils.setTextPrimaryColor(ctx, durationText, nightMode); AndroidUtils.setTextSecondaryColor(ctx, durationTitle, nightMode); } + applyDayNightMode(); + view.findViewById(R.id.details_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ShowRouteInfoDialogFragment.showDialog(mapActivity.getSupportFragmentManager()); + } + }); + + buildHeader(view); + + return view; + } + + protected void applyDayNightMode() { FrameLayout detailsButton = view.findViewById(R.id.details_button); AndroidUtils.setBackground(app, detailsButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); @@ -103,26 +119,12 @@ public class SimpleRouteCard extends BaseRouteCard { AndroidUtils.setBackground(app, view.findViewById(R.id.details_button_descr), nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); } int color = ContextCompat.getColor(mapActivity, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); - AndroidUtils.setBackground(ctx, view.findViewById(R.id.dividerToDropDown), nightMode, - R.color.divider_light, R.color.divider_dark); - AndroidUtils.setBackground(ctx, view.findViewById(R.id.info_divider), nightMode, - R.color.activity_background_light, R.color.route_info_cancel_button_color_dark); - - AndroidUtils.setBackground(ctx, view.findViewById(R.id.route_info_details_card), nightMode, - R.color.activity_background_light, R.color.route_info_cancel_button_color_dark); - AndroidUtils.setBackground(ctx, view.findViewById(R.id.RouteInfoControls), nightMode, - R.color.route_info_bg_light, R.color.route_info_bg_dark); + AndroidUtils.setBackground(app, view.findViewById(R.id.dividerToDropDown), nightMode, R.color.divider_light, R.color.divider_dark); + AndroidUtils.setBackground(app, view.findViewById(R.id.info_divider), nightMode, R.color.activity_background_light, R.color.route_info_cancel_button_color_dark); + AndroidUtils.setBackground(app, view.findViewById(R.id.route_info_details_card), nightMode, R.color.activity_background_light, R.color.route_info_cancel_button_color_dark); + AndroidUtils.setBackground(app, view.findViewById(R.id.RouteInfoControls), nightMode, R.color.route_info_bg_light, R.color.route_info_bg_dark); ((TextView) view.findViewById(R.id.details_button_descr)).setTextColor(color); - - detailsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - ShowRouteInfoDialogFragment.showDialog(mapActivity.getSupportFragmentManager()); - } - }); - - buildHeader(view); } private void buildHeader(View headerView) { @@ -148,8 +150,6 @@ public class SimpleRouteCard extends BaseRouteCard { mChart.setData(new LineData(dataSets)); mChart.setVisibility(View.VISIBLE); } else { - elevationDataSet = null; - slopeDataSet = null; mChart.setVisibility(View.GONE); } } diff --git a/OsmAnd/src/net/osmand/plus/widgets/style/CustomTypefaceSpan.java b/OsmAnd/src/net/osmand/plus/widgets/style/CustomTypefaceSpan.java new file mode 100644 index 0000000000..b679a320eb --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/widgets/style/CustomTypefaceSpan.java @@ -0,0 +1,31 @@ +package net.osmand.plus.widgets.style; + +import android.graphics.Typeface; +import android.text.TextPaint; +import android.text.style.MetricAffectingSpan; + +public class CustomTypefaceSpan extends MetricAffectingSpan { + + private Typeface typeface; + + public CustomTypefaceSpan(Typeface typeface) { + this.typeface = typeface; + } + + @Override + public void updateMeasureState(TextPaint p) { + update(p); + } + + @Override + public void updateDrawState(TextPaint tp) { + update(tp); + } + + private void update(TextPaint tp) { + Typeface old = tp.getTypeface(); + int oldStyle = old.getStyle(); + Typeface font = Typeface.create(typeface, oldStyle); + tp.setTypeface(font); + } +} \ No newline at end of file