[android] Added spannable for routing details(time/distance/arrival time)

This commit is contained in:
Dmitry Donskoy 2019-08-20 12:03:22 +03:00 committed by Aleksandr Zatsepin
parent 1fa9a08047
commit cb2645f992
6 changed files with 153 additions and 40 deletions

View file

@ -8,21 +8,26 @@
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="@dimen/altitude_chart_time_distance_height"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/time"
style="@style/MwmWidget.TextView.PlanDetail.Number.Time"
android:singleLine="true"
android:ellipsize="middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="33 min"/>
<TextView
style="@style/MwmWidget.TextView.PlanDetail.Number.Secondary"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="2dp"
android:visibility="gone"
android:text="•"
tools:ignore="HardcodedText"/>
<TextView
android:id="@+id/distance"
android:visibility="gone"
style="@style/MwmWidget.TextView.PlanDetail.Number"
tools:text="1024 km"/>
</LinearLayout>

View file

@ -7,7 +7,10 @@
android:layout_height="wrap_content">
<TextView
android:id="@+id/time"
style="@style/MwmWidget.TextView.PlanDetail.Number.Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="middle"
android:layout_marginBottom="4dp"
tools:text="33 min"/>
<TextView
@ -18,6 +21,7 @@
android:layout_marginTop="2dp"
android:layout_toRightOf="@id/time"
android:layout_toEndOf="@id/time"
android:visibility="gone"
android:text="•"
tools:ignore="HardcodedText"/>
<TextView
@ -25,6 +29,7 @@
style="@style/MwmWidget.TextView.PlanDetail.Number"
android:layout_toEndOf="@id/dot"
android:layout_toRightOf="@id/dot"
android:visibility="gone"
tools:text="1024 km 324"/>
<TextView
android:id="@+id/arrival"
@ -34,8 +39,8 @@
android:layout_alignLeft="@id/time"
android:layout_alignStart="@id/time"
android:layout_marginBottom="10dp"
android:visibility="gone"
tools:text="Arrival 13:03"
style="@style/MwmWidget.TextView.PlanDetail.Number.Secondary"
android:textSize="@dimen/text_size_routing_plan_detail_arrival"/>
<TextView
android:id="@+id/altitude_difference"

View file

@ -22,4 +22,4 @@
android:layout_width="@dimen/altitude_chart_image_width"
android:layout_height="@dimen/altitude_chart_image_height"
android:layout_marginBottom="8dp"/>
</LinearLayout>
</LinearLayout>

View file

@ -8,7 +8,7 @@
android:layout_height="wrap_content">
<include layout="@layout/altitude_chart_panel"
tools:visibility="gone"/>
tools:visibility="visible"/>
<include layout="@layout/routing_bottom_panel_transit"/>

View file

@ -1,31 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/numbers"
android:layout_width="match_parent"
android:layout_height="@dimen/altitude_chart_time_distance_height"
android:layout_marginBottom="@dimen/altitude_chart_time_distance_margin_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="@dimen/altitude_chart_time_distance_height"
android:orientation="horizontal">
<TextView
android:id="@+id/time"
style="@style/MwmWidget.TextView.PlanDetail.Number.Time"
tools:text="33 min"/>
<TextView
style="@style/MwmWidget.TextView.PlanDetail.Number.Secondary"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="2dp"
android:text="•"
tools:ignore="HardcodedText"/>
<TextView
android:id="@+id/distance"
style="@style/MwmWidget.TextView.PlanDetail.Number"
tools:text="1024 km"/>
</LinearLayout>
android:layout_height="wrap_content">
<TextView
android:id="@+id/altitude_difference"
android:layout_width="wrap_content"
@ -35,8 +14,45 @@
android:textColor="?colorAccent"
android:layout_gravity="end"
android:gravity="center"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:visibility="gone"
tools:text="43 m"
tools:targetApi="jelly_bean"
tools:visibility="visible"/>
</FrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
android:layout_toLeftOf="@id/altitude_difference"
android:layout_toStartOf="@id/altitude_difference">
<TextView
android:id="@+id/time"
android:layout_width="0dp"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="middle"
tools:text="33 min"
android:layout_height="wrap_content"/>
<TextView
style="@style/MwmWidget.TextView.PlanDetail.Number.Secondary"
android:layout_marginLeft="6dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="6dp"
android:layout_marginTop="2dp"
android:visibility="gone"
android:text="•"
tools:ignore="HardcodedText"/>
<TextView
android:id="@+id/distance"
android:layout_width="0dp"
android:layout_weight="1"
android:visibility="gone"
style="@style/MwmWidget.TextView.PlanDetail.Number"
tools:text="1024 km"/>
</LinearLayout>
</RelativeLayout>

View file

@ -2,8 +2,10 @@ package com.mapswithme.maps.routing;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.IdRes;
@ -14,7 +16,14 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@ -359,18 +368,96 @@ final class RoutingBottomMenuController implements View.OnClickListener
return;
}
Spanned spanned = makeSpannedRoutingDetails(mContext, rinfo);
TextView numbersTime = (TextView) mNumbersFrame.findViewById(R.id.time);
TextView numbersDistance = (TextView) mNumbersFrame.findViewById(R.id.distance);
TextView numbersArrival = (TextView) mNumbersFrame.findViewById(R.id.arrival);
numbersTime.setText(RoutingController.formatRoutingTime(mContext, rinfo.totalTimeInSeconds,
R.dimen.text_size_routing_number));
numbersDistance.setText(rinfo.distToTarget + " " + rinfo.targetUnits);
numbersTime.setText(spanned, TextView.BufferType.SPANNABLE);
}
if (numbersArrival != null)
{
String arrivalTime = RoutingController.formatArrivalTime(rinfo.totalTimeInSeconds);
numbersArrival.setText(arrivalTime);
}
@NonNull
private static Spanned makeSpannedRoutingDetails(@NonNull Context context, @NonNull RoutingInfo routingInfo)
{
CharSequence time = RoutingController.formatRoutingTime(context,
routingInfo.totalTimeInSeconds,
R.dimen.text_size_routing_number);
SpannableStringBuilder builder = new SpannableStringBuilder();
initTimeBuilderSequence(context, time, builder);
String dot = "";
initDotBuilderSequence(context, dot, builder);
String dist = routingInfo.distToTarget + " " + routingInfo.targetUnits;
dist = "asdasdasdasdasdasdasdasdasdadqweqweqweqweqweqweqweqweqweqwe";
initTailBuilderSequence(context, dist, builder, android.R.attr.textColorPrimary);
String arrivalTime = RoutingController.formatArrivalTime(routingInfo.totalTimeInSeconds);
initTailBuilderSequence(context, arrivalTime, builder.append(" "), R.attr.secondary);
return builder;
}
private static void initTimeBuilderSequence(@NonNull Context context, @NonNull CharSequence time,
@NonNull SpannableStringBuilder builder)
{
builder.append(time);
builder.setSpan(new TypefaceSpan(context.getResources().getString(R.string.robotoMedium)),
0,
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new AbsoluteSizeSpan(context.getResources().getDimensionPixelSize(R.dimen.text_size_routing_number)),
0,
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new StyleSpan(Typeface.BOLD),
0,
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new ForegroundColorSpan(ThemeUtils.getColor(context, android.R.attr.textColorPrimary)),
0,
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
private static void initDotBuilderSequence(@NonNull Context context, String dot, SpannableStringBuilder builder)
{
builder.append(dot);
builder.setSpan(new TypefaceSpan(context.getResources().getString(R.string.robotoMedium)),
builder.length() - dot.length(),
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new AbsoluteSizeSpan(context.getResources().getDimensionPixelSize(R.dimen.text_size_routing_number)),
builder.length() - dot.length(),
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new ForegroundColorSpan(ThemeUtils.getColor(context, R.attr.secondary)),
builder.length() - dot.length(),
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
private static void initTailBuilderSequence(@NonNull Context context, @NonNull String arrivalTime,
@NonNull SpannableStringBuilder builder, int textColor)
{
builder.append(arrivalTime);
builder.setSpan(new TypefaceSpan(context.getResources().getString(R.string.robotoMedium)),
builder.length() - arrivalTime.length(),
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new AbsoluteSizeSpan(context.getResources()
.getDimensionPixelSize(R.dimen.text_size_routing_number)),
builder.length() - arrivalTime.length(),
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new StyleSpan(Typeface.NORMAL),
builder.length() - arrivalTime.length(),
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new ForegroundColorSpan(ThemeUtils.getColor(context, textColor)),
builder.length() - arrivalTime.length(),
builder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
@Override