fix vertical arrow alignment;

fix blocks within width 60dp-120dp
This commit is contained in:
Skalii 2021-02-13 05:57:28 +02:00
parent e5bf00162e
commit 63351ebf66
4 changed files with 23 additions and 12 deletions

View file

@ -93,6 +93,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginTop="1sp"
android:contentDescription="@string/show_view_angle" android:contentDescription="@string/show_view_angle"
osmand:srcCompat="@drawable/ic_direction_arrow" /> osmand:srcCompat="@drawable/ic_direction_arrow" />

View file

@ -38,21 +38,23 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding" android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding" android:layout_marginLeft="@dimen/content_padding"
android:gravity="center" android:layout_marginTop="@dimen/dash_margin"
android:orientation="horizontal" android:layout_marginBottom="@dimen/dash_margin"
android:paddingTop="@dimen/dash_margin" android:orientation="horizontal">
android:paddingBottom="@dimen/dash_margin">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/direction" android:id="@+id/direction"
android:layout_width="@dimen/context_menu_transport_icon_size" android:layout_width="@dimen/context_menu_transport_icon_size"
android:layout_height="@dimen/context_menu_transport_icon_size" android:layout_height="@dimen/context_menu_transport_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginTop="1sp"
osmand:srcCompat="@drawable/ic_direction_arrow" /> osmand:srcCompat="@drawable/ic_direction_arrow" />
<TextView <TextView
android:id="@+id/distance" android:id="@+id/distance"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/content_padding_small_half" android:layout_marginStart="@dimen/content_padding_small_half"
android:layout_marginLeft="@dimen/content_padding_small_half" android:layout_marginLeft="@dimen/content_padding_small_half"
android:maxLines="1" android:maxLines="1"

View file

@ -6,7 +6,7 @@
android:layout_height="@dimen/list_header_height" android:layout_height="@dimen/list_header_height"
android:layout_marginStart="@dimen/content_padding" android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding" android:layout_marginLeft="@dimen/content_padding"
android:gravity="center_vertical" android:gravity="start|center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<LinearLayout <LinearLayout
@ -14,14 +14,13 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="@dimen/content_padding" android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding" android:layout_marginRight="@dimen/content_padding"
android:gravity="center_vertical" android:gravity="start|center_vertical"
android:maxWidth="@dimen/grid_menu_item_width"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="start|center_vertical"
android:orientation="horizontal" android:orientation="horizontal"
android:weightSum="2"> android:weightSum="2">
@ -61,8 +60,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@null" android:background="@null"
android:ellipsize="end" android:ellipsize="end"
android:gravity="start|center_vertical"
android:lines="1" android:lines="1"
android:maxWidth="@dimen/grid_menu_item_width" android:maxWidth="@dimen/grid_menu_item_width"
android:minWidth="@dimen/map_route_buttons_width"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
tools:text="@string/distance" /> tools:text="@string/distance" />

View file

@ -32,6 +32,7 @@ import net.osmand.plus.widgets.TextViewEx;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class GpxBlockStatisticsBuilder { public class GpxBlockStatisticsBuilder {
@ -232,12 +233,10 @@ public class GpxBlockStatisticsBuilder {
public void onBindViewHolder(BlockStatisticsViewHolder holder, int position) { public void onBindViewHolder(BlockStatisticsViewHolder holder, int position) {
final StatBlock item = items.get(position); final StatBlock item = items.get(position);
holder.valueText.setText(item.value); holder.valueText.setText(item.value);
holder.titleText.setText(item.title);
if (updateRunning) {
holder.titleText.setWidth(app.getResources().getDimensionPixelSize(R.dimen.map_route_buttons_width));
}
holder.valueText.setTextColor(activeColor); holder.valueText.setTextColor(activeColor);
holder.titleText.setText(item.title);
holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light)); holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light));
holder.titleText.setWidth(calculateWidthWithin(item.title, item.value));
holder.itemView.setOnClickListener(new View.OnClickListener() { holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -271,6 +270,14 @@ public class GpxBlockStatisticsBuilder {
} }
} }
public int calculateWidthWithin(String... texts) {
int textSize = app.getResources().getDimensionPixelSize(R.dimen.default_desc_text_size);
int textWidth = AndroidUtils.getTextMaxWidth(textSize, Arrays.asList(texts));
int minWidth = AndroidUtils.dpToPx(app, 60);
int maxWidth = AndroidUtils.dpToPx(app, 120);
return Math.min(maxWidth, Math.max(minWidth, textWidth));
}
private class BlockStatisticsViewHolder extends RecyclerView.ViewHolder { private class BlockStatisticsViewHolder extends RecyclerView.ViewHolder {
private final TextViewEx valueText; private final TextViewEx valueText;