From 818fe36d629a036c2e268b86ae2a13b24f45b5b1 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 1 Apr 2019 18:28:37 +0300 Subject: [PATCH] Fix bottom sheet height and improve route info cards ui --- OsmAnd/res/drawable/ripple_rounded_dark.xml | 2 +- OsmAnd/res/drawable/ripple_rounded_light.xml | 2 +- OsmAnd/res/layout/route_details_legend.xml | 34 +++++++++++ OsmAnd/res/layout/route_info_card.xml | 58 +++++++++++++------ OsmAnd/res/values-large/sizes.xml | 4 +- OsmAnd/res/values/sizes.xml | 4 +- .../base/MenuBottomSheetDialogFragment.java | 2 +- .../RouteDetailsFragment.java | 2 + .../cards/RouteInfoCard.java | 51 ++++++++++------ 9 files changed, 120 insertions(+), 39 deletions(-) create mode 100644 OsmAnd/res/layout/route_details_legend.xml diff --git a/OsmAnd/res/drawable/ripple_rounded_dark.xml b/OsmAnd/res/drawable/ripple_rounded_dark.xml index dc86d03171..a0b9e77bd2 100644 --- a/OsmAnd/res/drawable/ripple_rounded_dark.xml +++ b/OsmAnd/res/drawable/ripple_rounded_dark.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/OsmAnd/res/drawable/ripple_rounded_light.xml b/OsmAnd/res/drawable/ripple_rounded_light.xml index a4a056ac0c..dd575011a4 100644 --- a/OsmAnd/res/drawable/ripple_rounded_light.xml +++ b/OsmAnd/res/drawable/ripple_rounded_light.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/OsmAnd/res/layout/route_details_legend.xml b/OsmAnd/res/layout/route_details_legend.xml new file mode 100644 index 0000000000..acca375cb7 --- /dev/null +++ b/OsmAnd/res/layout/route_details_legend.xml @@ -0,0 +1,34 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/route_info_card.xml b/OsmAnd/res/layout/route_info_card.xml index a467d87c9c..bfc450e9b9 100644 --- a/OsmAnd/res/layout/route_info_card.xml +++ b/OsmAnd/res/layout/route_info_card.xml @@ -9,13 +9,12 @@ + android:layout_height="wrap_content"> - + android:layout_marginTop="@dimen/route_info_card_details_margin" + android:layout_marginBottom="@dimen/route_info_card_details_margin" + android:background="?attr/selectableItemBackground" + android:orientation="horizontal" + android:paddingStart="@dimen/bottom_sheet_content_margin_small" + android:paddingLeft="@dimen/bottom_sheet_content_margin_small" + android:paddingEnd="@dimen/content_padding" + android:paddingRight="@dimen/content_padding"> + + + + + + diff --git a/OsmAnd/res/values-large/sizes.xml b/OsmAnd/res/values-large/sizes.xml index 260cc467b3..982853a40f 100644 --- a/OsmAnd/res/values-large/sizes.xml +++ b/OsmAnd/res/values-large/sizes.xml @@ -191,9 +191,11 @@ 78dp 12dp 27dp - 78dp + 106dp 72dp 27dp + 13dp + 60dp 78dp diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 3a2b3910e6..7abb319aaf 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -284,10 +284,12 @@ 54dp 8dp 18dp - 52dp + 71dp 40dp 48dp 18dp + 9dp + 40dp 52dp diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index bc12728b5a..d5626a88e3 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -179,7 +179,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } final int screenHeight = AndroidUtils.getScreenHeight(activity); final int statusBarHeight = AndroidUtils.getStatusBarHeight(activity); - final int contentHeight = getContentHeight(screenHeight - statusBarHeight - AndroidUtils.getNavBarHeight(activity)); + final int contentHeight = getContentHeight(screenHeight - statusBarHeight); mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java index e56400ce0c..f16d1cda7a 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java @@ -363,6 +363,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT private void createRouteCard(LinearLayout cardsContainer, RouteInfoCard routeInfoCard) { OsmandApplication app = requireMyApplication(); menuCards.add(routeInfoCard); + routeInfoCard.setListener(this); cardsContainer.addView(routeInfoCard.build(app)); buildRowDivider(cardsContainer, false); } @@ -1499,6 +1500,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT @Override public void onCardLayoutNeeded(@NonNull BaseCard card) { + runLayoutListener(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/RouteInfoCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/RouteInfoCard.java index d56a602dd7..feb9b98370 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/RouteInfoCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/RouteInfoCard.java @@ -1,19 +1,20 @@ package net.osmand.plus.routepreparationmenu.cards; import android.graphics.drawable.Drawable; -import android.support.v4.content.ContextCompat; +import android.support.v7.view.ContextThemeWrapper; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.StyleSpan; -import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.github.mikephil.charting.charts.HorizontalBarChart; import com.github.mikephil.charting.data.BarData; -import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; @@ -39,6 +40,8 @@ public class RouteInfoCard extends BaseCard { private Statistics routeStatistics; private GPXUtilities.GPXTrackAnalysis analysis; + private boolean showLegend; + public RouteInfoCard(MapActivity mapActivity, Statistics routeStatistics, GPXUtilities.GPXTrackAnalysis analysis) { super(mapActivity); this.routeStatistics = routeStatistics; @@ -54,11 +57,28 @@ public class RouteInfoCard extends BaseCard { protected void updateContent() { updateHeader(); final HorizontalBarChart chart = (HorizontalBarChart) view.findViewById(R.id.chart); - GpxUiHelper.setupHorizontalGPXChart(app, chart, 5, 10, 10, true, nightMode); + GpxUiHelper.setupHorizontalGPXChart(app, chart, 5, 9, 24, true, nightMode); BarData barData = GpxUiHelper.buildStatisticChart(app, chart, routeStatistics, analysis, true, nightMode); chart.setData(barData); - LinearLayout container = view.findViewById(R.id.route_items); - attachLegend(container, routeStatistics); + final LinearLayout container = (LinearLayout) view.findViewById(R.id.route_items); + container.removeAllViews(); + if (showLegend) { + attachLegend(container, routeStatistics); + } + final ImageView iconViewCollapse = (ImageView) view.findViewById(R.id.up_down_icon); + iconViewCollapse.setImageDrawable(getCollapseIcon(!showLegend)); + view.findViewById(R.id.info_type_details_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showLegend = !showLegend; + updateContent(); + setLayoutNeeded(); + } + }); + } + + private Drawable getCollapseIcon(boolean collapsed) { + return collapsed ? getContentIcon(R.drawable.ic_action_arrow_down) : getActiveIcon(R.drawable.ic_action_arrow_up); } private void updateHeader() { @@ -85,24 +105,21 @@ public class RouteInfoCard extends BaseCard { Map> partition = routeStatistics.getPartition(); List list = new ArrayList(partition.keySet()); sortRouteSegmentAttributes(list); + ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); + LayoutInflater inflater = LayoutInflater.from(ctx); for (E key : list) { RouteSegmentAttribute segment = partition.get(key); - int color = segment.getColor(); - Drawable circle = app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, color); + View view = inflater.inflate(R.layout.route_details_legend, container, false); + Drawable circle = app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, segment.getColor()); + ImageView legendIcon = (ImageView) view.findViewById(R.id.legend_icon_color); + legendIcon.setImageDrawable(circle); String propertyName = segment.getPropertyName(); String name = SettingsNavigationActivity.getStringPropertyName(app, propertyName, propertyName.replaceAll("_", " ")); Spannable text = getSpanLegend(name, segment); - - TextView legend = new TextView(app); - legend.setTextColor(getMainFontColor()); - legend.setTextSize(15); - legend.setGravity(Gravity.CENTER_VERTICAL); - legend.setCompoundDrawablePadding(AndroidUtils.dpToPx(app, 16)); - legend.setPadding(AndroidUtils.dpToPx(app, 16), AndroidUtils.dpToPx(app, 4), AndroidUtils.dpToPx(app, 16), AndroidUtils.dpToPx(app, 4)); - legend.setCompoundDrawablesWithIntrinsicBounds(circle, null, null, null); + TextView legend = (TextView) view.findViewById(R.id.legend_text); legend.setText(text); - container.addView(legend); + container.addView(view); } }