Improve cards ui

This commit is contained in:
Chumva 2018-12-14 19:04:13 +02:00
parent fb704e8d97
commit c37564ea59
6 changed files with 105 additions and 73 deletions

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<stroke android:width="1dp" android:color="@color/active_buttons_and_links_dark" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<stroke android:width="1dp" android:color="@color/active_buttons_and_links_light" />
</shape>
</item>
</selector>

View file

@ -31,20 +31,21 @@
<net.osmand.plus.routepreparationmenu.FlowLayout
android:id="@+id/routes_badges"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:layout_marginBottom="4dp" />
<LinearLayout
android:id="@+id/routes_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="14dp"
android:paddingTop="8dp">
android:paddingBottom="14dp">
<net.osmand.plus.widgets.TextViewEx
<android.support.v7.widget.AppCompatTextView
android:id="@+id/from_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
tools:text="@string/route_from" />
<net.osmand.plus.widgets.TextViewEx

View file

@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:background="@drawable/transport_stop_route_bg"
android:orientation="horizontal">
@ -19,9 +19,9 @@
android:id="@+id/transport_stop_route_text"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:textAllCaps="true"
android:textColor="@color/color_white"
android:textSize="@dimen/default_sub_text_size_small"

View file

@ -10,7 +10,8 @@
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
Thx - Hardy
-->
<string name="route_way">Way:</string>
<string name="on_foot">on foot: %1$s</string>
<string name="route_way">Way: %1$s</string>
<string name="points_of_interests">Points of interests(POI)</string>
<string name="waiting_for_route_calculation">Waiting for route calculation</string>
<string name="app_mode_public_transport">Public transport</string>

View file

@ -3,12 +3,15 @@ package net.osmand.plus.routepreparationmenu.routeCards;
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;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.data.TransportRoute;
@ -18,7 +21,6 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routepreparationmenu.FlowLayout;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.transport.TransportStopType;
@ -31,16 +33,14 @@ public class PublicTransportCard extends BaseRouteCard {
private MapActivity mapActivity;
private TransportRoutePlanner.TransportRouteResult routeResult;
private final RoutingHelper routingHelper;
private final TransportRoutingHelper transportHelper;
private int routeId;
public PublicTransportCard(MapActivity mapActivity, boolean nightMode, TransportRoutePlanner.TransportRouteResult routeResult, int routeId) {
super(mapActivity.getMyApplication(), nightMode);
this.transportHelper = app.getTransportRoutingHelper();
this.mapActivity = mapActivity;
this.routeResult = routeResult;
routingHelper = mapActivity.getRoutingHelper();
this.transportHelper = routingHelper.getTransportRoutingHelper();
this.routeId = routeId;
}
@ -59,45 +59,88 @@ public class PublicTransportCard extends BaseRouteCard {
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));
// }
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));
}
}
}
}
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 wayLine = (TextView) view.findViewById(R.id.way_line);
fromLine.setText(app.getString(R.string.route_from) + " " + routeResult.getSegments().get(0).getStart().getName());
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);
wayLine.setText(app.getString(R.string.route_way) + " " + travelTime + " • walking - " + walkTime + "" + walkDistance);
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);
detailsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
transportHelper.setCurrentRoute(routeId);
}
});
applyDayNightMode();
if (isLastItem) {
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom() + AndroidUtils.dpToPx(app, 60));
}
}
private 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);
AndroidUtils.setBackground(app, detailsButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark);
@ -117,31 +160,17 @@ public class PublicTransportCard extends BaseRouteCard {
((TextView) view.findViewById(R.id.details_button_descr)).setTextColor(color);
detailsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
transportHelper.setCurrentRoute(routeId);
}
});
if (isLastItem) {
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom() + AndroidUtils.dpToPx(app, 60));
}
}
private View createRouteBadge(final Object object) {
private View createRouteBadge(TransportRoutePlanner.TransportRouteResultSegment segment) {
LinearLayout convertView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
if (object != null) {
String routeRef = "";
int bgColor = 0;
if (object instanceof TransportRoutePlanner.TransportRouteResultSegment) {
TransportRoutePlanner.TransportRouteResultSegment segment = (TransportRoutePlanner.TransportRouteResultSegment) object;
TransportRoute transportRoute = segment.route;
if (segment != null) {
TransportRoute transportRoute = segment.route;
TransportStopRoute transportStopRoute = getTransportStopRoute(transportRoute, segment.getStart());
String routeRef = getAdjustedRouteRef(segment.route.getRef());
int bgColor = transportStopRoute.getColor(app, nightMode);
TransportStopRoute transportStopRoute = getTransportStopRoute(transportRoute, segment.getStart());
routeRef = getAdjustedRouteRef(transportStopRoute.route.getRef());
bgColor = transportStopRoute.getColor(app, nightMode);
}
TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text);
ImageView transportStopRouteImageView = (ImageView) convertView.findViewById(R.id.transport_stop_route_icon);
@ -150,19 +179,12 @@ public class PublicTransportCard extends BaseRouteCard {
GradientDrawable gradientDrawableBg = (GradientDrawable) convertView.getBackground();
gradientDrawableBg.setColor(bgColor);
transportStopRouteTextView.setTextColor(UiUtilities.getContrastColor(app, bgColor, true));
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(app, object.toString(), Toast.LENGTH_LONG).show();
}
});
}
return convertView;
}
private View createWalkRouteBadge(final String walkTime) {
private View createWalkRouteBadge(String walkTime) {
LinearLayout convertView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
if (walkTime != null) {
int bgColor = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
@ -176,28 +198,18 @@ public class PublicTransportCard extends BaseRouteCard {
gradientDrawableBg.setColor(bgColor);
transportStopRouteTextView.setTextColor(bgColor);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setForeground(app, convertView, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setForeground(app, convertView, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark);
}
AndroidUtils.setBackground(app, convertView, nightMode, R.drawable.btn_border_trans_light, R.drawable.ripple_dark);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(app, walkTime, Toast.LENGTH_LONG).show();
}
});
AndroidUtils.setBackground(app, convertView, nightMode, R.drawable.btn_border_active_light, R.drawable.btn_border_active_dark);
}
return convertView;
}
private View createArrow() {
LinearLayout container = new LinearLayout(app);
ImageView arrow = new ImageView(app);
arrow.setImageDrawable(getContentIcon(R.drawable.ic_arrow_forward));
return arrow;
container.addView(arrow, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, AndroidUtils.dpToPx(app, 28)));
return container;
}
private TransportStopRoute getTransportStopRoute(TransportRoute rs, TransportStop s) {