Add CustomTypefaceSpan and refactor route cards
This commit is contained in:
parent
1f02c3e95c
commit
2c53ffd598
10 changed files with 191 additions and 154 deletions
|
@ -1,5 +1,9 @@
|
||||||
package net.osmand.data;
|
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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -8,10 +12,6 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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 {
|
public class TransportRoute extends MapObject {
|
||||||
private List<TransportStop> forwardStops = new ArrayList<TransportStop>();
|
private List<TransportStop> forwardStops = new ArrayList<TransportStop>();
|
||||||
private String ref;
|
private String ref;
|
||||||
|
@ -209,4 +209,16 @@ public class TransportRoute extends MapObject {
|
||||||
return d;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,12 +5,13 @@
|
||||||
android:id="@+id/route_info_details_card"
|
android:id="@+id/route_info_details_card"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="10dp">
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/top_divider"
|
android:id="@+id/top_divider"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="2dp"
|
android:layout_height="1dp"
|
||||||
android:focusable="false" />
|
android:focusable="false" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -41,17 +42,21 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="14dp">
|
android:paddingBottom="14dp">
|
||||||
|
|
||||||
<android.support.v7.widget.AppCompatTextView
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
android:id="@+id/from_line"
|
android:id="@+id/from_line"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="10dp"
|
android:paddingBottom="6dp"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular"
|
||||||
tools:text="@string/route_from" />
|
tools:text="@string/route_from" />
|
||||||
|
|
||||||
<net.osmand.plus.widgets.TextViewEx
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
android:id="@+id/way_line"
|
android:id="@+id/way_line"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular"
|
||||||
tools:text="@string/route_from" />
|
tools:text="@string/route_from" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -88,6 +93,8 @@
|
||||||
<include
|
<include
|
||||||
android:id="@+id/shadow"
|
android:id="@+id/shadow"
|
||||||
layout="@layout/card_bottom_divider"
|
layout="@layout/card_bottom_divider"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="2dp"
|
||||||
android:visibility="visible" />
|
android:visibility="visible" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -10,6 +10,7 @@
|
||||||
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="transfers">transfers: %1$s</string>
|
||||||
<string name="on_foot">on foot: %1$s</string>
|
<string name="on_foot">on foot: %1$s</string>
|
||||||
<string name="route_way">Way: %1$s</string>
|
<string name="route_way">Way: %1$s</string>
|
||||||
<string name="points_of_interests">Points of interests(POI)</string>
|
<string name="points_of_interests">Points of interests(POI)</string>
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class TransportStopRouteAdapter extends ArrayAdapter<Object> {
|
||||||
int bgColor = 0;
|
int bgColor = 0;
|
||||||
if (object instanceof TransportStopRoute) {
|
if (object instanceof TransportStopRoute) {
|
||||||
TransportStopRoute transportStopRoute = (TransportStopRoute) object;
|
TransportStopRoute transportStopRoute = (TransportStopRoute) object;
|
||||||
routeRef = getAdjustedRouteRef(transportStopRoute.route.getRef());
|
routeRef = transportStopRoute.route.getAdjustedRouteRef();
|
||||||
bgColor = transportStopRoute.getColor(app, nightMode);
|
bgColor = transportStopRoute.getColor(app, nightMode);
|
||||||
} else if (object instanceof String) {
|
} else if (object instanceof String) {
|
||||||
routeRef = (String) object;
|
routeRef = (String) object;
|
||||||
|
@ -70,19 +70,6 @@ public class TransportStopRouteAdapter extends ArrayAdapter<Object> {
|
||||||
return convertView;
|
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 {
|
public interface OnClickListener {
|
||||||
void onClick(int position);
|
void onClick(int position);
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,8 +338,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
||||||
public void build(LinearLayout rootView) {
|
public void build(LinearLayout rootView) {
|
||||||
rootView.removeAllViews();
|
rootView.removeAllViews();
|
||||||
for (BaseRouteCard card : routeCards) {
|
for (BaseRouteCard card : routeCards) {
|
||||||
card.bindViewHolder();
|
rootView.addView(card.createCardView());
|
||||||
rootView.addView(card.getView());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
cardsContainer = (LinearLayout) view.findViewById(R.id.route_menu_cards_container);
|
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();
|
buildBottomView();
|
||||||
|
|
||||||
|
|
|
@ -13,20 +13,18 @@ import net.osmand.plus.R;
|
||||||
public abstract class BaseRouteCard {
|
public abstract class BaseRouteCard {
|
||||||
|
|
||||||
protected OsmandApplication app;
|
protected OsmandApplication app;
|
||||||
protected boolean nightMode;
|
|
||||||
protected View view;
|
|
||||||
protected boolean isLastItem;
|
protected boolean isLastItem;
|
||||||
|
protected boolean nightMode;
|
||||||
|
|
||||||
public BaseRouteCard(OsmandApplication app, boolean nightMode) {
|
public BaseRouteCard(OsmandApplication app, boolean nightMode) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.nightMode = nightMode;
|
this.nightMode = nightMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void bindViewHolder();
|
public abstract View createCardView();
|
||||||
|
|
||||||
public View getView() {
|
protected abstract void applyDayNightMode();
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ColorInt
|
@ColorInt
|
||||||
protected int getResolvedColor(@ColorRes int colorId) {
|
protected int getResolvedColor(@ColorRes int colorId) {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package net.osmand.plus.routepreparationmenu.routeCards;
|
package net.osmand.plus.routepreparationmenu.routeCards;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.GradientDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.text.style.StyleSpan;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
@ -20,23 +20,31 @@ import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.helpers.FontCache;
|
||||||
import net.osmand.plus.routepreparationmenu.FlowLayout;
|
import net.osmand.plus.routepreparationmenu.FlowLayout;
|
||||||
import net.osmand.plus.routing.TransportRoutingHelper;
|
import net.osmand.plus.routing.TransportRoutingHelper;
|
||||||
import net.osmand.plus.transport.TransportStopRoute;
|
import net.osmand.plus.transport.TransportStopRoute;
|
||||||
import net.osmand.plus.transport.TransportStopType;
|
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.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PublicTransportCard extends BaseRouteCard {
|
public class PublicTransportCard extends BaseRouteCard {
|
||||||
|
|
||||||
|
private static final int MIN_WALK_TIME = 120;
|
||||||
|
|
||||||
private MapActivity mapActivity;
|
private MapActivity mapActivity;
|
||||||
private TransportRoutePlanner.TransportRouteResult routeResult;
|
private TransportRouteResult routeResult;
|
||||||
private final TransportRoutingHelper transportHelper;
|
private TransportRoutingHelper transportHelper;
|
||||||
|
|
||||||
|
private View view;
|
||||||
|
|
||||||
private int routeId;
|
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);
|
super(mapActivity.getMyApplication(), nightMode);
|
||||||
this.transportHelper = app.getTransportRoutingHelper();
|
this.transportHelper = app.getTransportRoutingHelper();
|
||||||
this.mapActivity = mapActivity;
|
this.mapActivity = mapActivity;
|
||||||
|
@ -45,81 +53,18 @@ public class PublicTransportCard extends BaseRouteCard {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindViewHolder() {
|
public View createCardView() {
|
||||||
view = mapActivity.getLayoutInflater().inflate(R.layout.transport_route_card, null);
|
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));
|
view.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light));
|
||||||
|
|
||||||
int itemsSpacing = AndroidUtils.dpToPx(app, 6);
|
List<TransportRouteResultSegment> segments = routeResult.getSegments();
|
||||||
|
createRouteBadges(segments);
|
||||||
FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges);
|
|
||||||
|
|
||||||
Iterator<TransportRoutePlanner.TransportRouteResultSegment> 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView fromLine = (TextView) view.findViewById(R.id.from_line);
|
TextView fromLine = (TextView) view.findViewById(R.id.from_line);
|
||||||
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
|
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
|
||||||
|
|
||||||
String name = routeResult.getSegments().get(0).getStart().getName();
|
fromLine.setText(getFirstLineDescrSpan());
|
||||||
String firstLine = app.getString(R.string.route_from) + " " + name;
|
wayLine.setText(getSecondLineDescrSpan());
|
||||||
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) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
FrameLayout detailsButton = view.findViewById(R.id.details_button);
|
FrameLayout detailsButton = view.findViewById(R.id.details_button);
|
||||||
detailsButton.setOnClickListener(new View.OnClickListener() {
|
detailsButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -133,42 +78,113 @@ public class PublicTransportCard extends BaseRouteCard {
|
||||||
if (isLastItem) {
|
if (isLastItem) {
|
||||||
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom() + AndroidUtils.dpToPx(app, 60));
|
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 fromLine = (TextView) view.findViewById(R.id.from_line);
|
||||||
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
|
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
|
||||||
AndroidUtils.setTextSecondaryColor(app, fromLine, nightMode);
|
AndroidUtils.setTextSecondaryColor(app, fromLine, nightMode);
|
||||||
AndroidUtils.setTextSecondaryColor(app, wayLine, 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);
|
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) {
|
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 {
|
} 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, nightMode, R.color.activity_background_light, R.color.activity_background_dark);
|
||||||
AndroidUtils.setBackground(app, view.findViewById(R.id.top_divider), nightMode,
|
AndroidUtils.setBackground(app, view.findViewById(R.id.top_divider), nightMode, R.color.divider_light, R.color.divider_dark);
|
||||||
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.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);
|
int color = ContextCompat.getColor(mapActivity, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
|
||||||
|
detailsButtonDescr.setTextColor(color);
|
||||||
((TextView) view.findViewById(R.id.details_button_descr)).setTextColor(color);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View createRouteBadge(TransportRoutePlanner.TransportRouteResultSegment segment) {
|
private SpannableString getFirstLineDescrSpan() {
|
||||||
|
List<TransportRouteResultSegment> 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<TransportRouteResultSegment> segments) {
|
||||||
|
int itemsSpacing = AndroidUtils.dpToPx(app, 6);
|
||||||
|
FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges);
|
||||||
|
|
||||||
|
Iterator<TransportRouteResultSegment> 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);
|
LinearLayout convertView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
|
||||||
if (segment != null) {
|
if (segment != null) {
|
||||||
TransportRoute transportRoute = segment.route;
|
TransportRoute transportRoute = segment.route;
|
||||||
TransportStopRoute transportStopRoute = getTransportStopRoute(transportRoute, segment.getStart());
|
TransportStopRoute transportStopRoute = getTransportStopRoute(transportRoute, segment.getStart());
|
||||||
|
|
||||||
String routeRef = getAdjustedRouteRef(segment.route.getRef());
|
String routeRef = segment.route.getAdjustedRouteRef();
|
||||||
int bgColor = transportStopRoute.getColor(app, nightMode);
|
int bgColor = transportStopRoute.getColor(app, nightMode);
|
||||||
|
|
||||||
TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text);
|
TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text);
|
||||||
|
@ -223,20 +239,7 @@ public class PublicTransportCard extends BaseRouteCard {
|
||||||
return r;
|
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) {
|
private double getWalkTime(double walkDist, double walkSpeed) {
|
||||||
return walkDist / walkSpeed;
|
return walkDist / walkSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,7 +31,9 @@ public class SimpleRouteCard extends BaseRouteCard {
|
||||||
|
|
||||||
private MapActivity mapActivity;
|
private MapActivity mapActivity;
|
||||||
private GPXUtilities.GPXFile gpx;
|
private GPXUtilities.GPXFile gpx;
|
||||||
private final RoutingHelper routingHelper;
|
private RoutingHelper routingHelper;
|
||||||
|
|
||||||
|
private View view;
|
||||||
|
|
||||||
public SimpleRouteCard(MapActivity mapActivity, boolean nightMode, GPXUtilities.GPXFile gpx) {
|
public SimpleRouteCard(MapActivity mapActivity, boolean nightMode, GPXUtilities.GPXFile gpx) {
|
||||||
super(mapActivity.getMyApplication(), nightMode);
|
super(mapActivity.getMyApplication(), nightMode);
|
||||||
|
@ -41,7 +43,7 @@ public class SimpleRouteCard extends BaseRouteCard {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindViewHolder() {
|
public View createCardView() {
|
||||||
view = mapActivity.getLayoutInflater().inflate(R.layout.route_info_statistic, null);
|
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));
|
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.setTextPrimaryColor(ctx, durationText, nightMode);
|
||||||
AndroidUtils.setTextSecondaryColor(ctx, durationTitle, 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);
|
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);
|
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);
|
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);
|
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,
|
AndroidUtils.setBackground(app, view.findViewById(R.id.dividerToDropDown), nightMode, R.color.divider_light, R.color.divider_dark);
|
||||||
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(ctx, view.findViewById(R.id.info_divider), nightMode,
|
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);
|
||||||
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);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
((TextView) view.findViewById(R.id.details_button_descr)).setTextColor(color);
|
((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) {
|
private void buildHeader(View headerView) {
|
||||||
|
@ -148,8 +150,6 @@ public class SimpleRouteCard extends BaseRouteCard {
|
||||||
mChart.setData(new LineData(dataSets));
|
mChart.setData(new LineData(dataSets));
|
||||||
mChart.setVisibility(View.VISIBLE);
|
mChart.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
elevationDataSet = null;
|
|
||||||
slopeDataSet = null;
|
|
||||||
mChart.setVisibility(View.GONE);
|
mChart.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue