From 1b64dd1569307647ab14a5760e510cabde722b6a Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 24 Oct 2019 17:39:04 +0300 Subject: [PATCH 1/4] Make scroll items more evident --- .../plus/routepreparationmenu/AddPointBottomSheetDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 3fc913b8c2..f143c26163 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -552,10 +552,10 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { if (activity != null) { RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams(); if (AndroidUiHelper.isOrientationPortrait(getActivity())) { - layoutParams.width = AndroidUtils.getScreenWidth(activity) / 2; + layoutParams.width = (int) (AndroidUtils.getScreenWidth(activity) / 2.5); } else { // 11.5dp is the shadow width - layoutParams.width = (getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width) / 2) - AndroidUtils.dpToPx(activity, 11.5f); + layoutParams.width = (int) ((getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width) / 2.5) - AndroidUtils.dpToPx(activity, 11.5f)); } view.setLayoutParams(layoutParams); } From 459bd143705b37684ac5b2064f627148f9163ca1 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 25 Oct 2019 13:17:42 +0300 Subject: [PATCH 2/4] Fix #7596 --- OsmAnd/src/net/osmand/AndroidUtils.java | 9 +++++++-- .../AddPointBottomSheetDialog.java | 10 +++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index f41b67710f..e27d316644 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -388,13 +388,18 @@ public class AndroidUtils { : ctx.getResources().getColor(R.color.text_color_secondary_light)); } - public static int getTextWidth(float textSize, String text) { Paint paint = new Paint(); paint.setTextSize(textSize); return (int) paint.measureText(text); } - + + public static int getTextHeight(Paint paint) { + Paint.FontMetrics fm = paint.getFontMetrics(); + float height = fm.bottom - fm.top; + return (int) height; + } + public static int dpToPx(Context ctx, float dp) { Resources r = ctx.getResources(); return (int) TypedValue.applyDimension( diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index f143c26163..0ede9b6514 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -3,7 +3,6 @@ package net.osmand.plus.routepreparationmenu; import android.Manifest; import android.app.Activity; import android.content.Intent; -import android.content.pm.PackageManager; import android.graphics.Color; import android.graphics.Typeface; import android.os.Bundle; @@ -550,6 +549,15 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { view.setOnClickListener(listener); Activity activity = getActivity(); if (activity != null) { + TextView title = view.findViewById(R.id.title); + TextView description = view.findViewById(R.id.description); + + int titleHeight = AndroidUtils.getTextHeight(title.getPaint()); + int descriptionHeight = AndroidUtils.getTextHeight(description.getPaint()); + int minTextHeight = titleHeight + descriptionHeight * 2; + if (view.getHeight() < minTextHeight) { + view.setMinimumHeight(minTextHeight); + } RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams(); if (AndroidUiHelper.isOrientationPortrait(getActivity())) { layoutParams.width = (int) (AndroidUtils.getScreenWidth(activity) / 2.5); From 766858012ea2aa8fe9001db85eb9e01ca73fc580 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 25 Oct 2019 13:32:10 +0300 Subject: [PATCH 3/4] Fix scroll items height only for favorites --- .../AddPointBottomSheetDialog.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 0ede9b6514..a48c02c9b1 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -549,15 +549,6 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { view.setOnClickListener(listener); Activity activity = getActivity(); if (activity != null) { - TextView title = view.findViewById(R.id.title); - TextView description = view.findViewById(R.id.description); - - int titleHeight = AndroidUtils.getTextHeight(title.getPaint()); - int descriptionHeight = AndroidUtils.getTextHeight(description.getPaint()); - int minTextHeight = titleHeight + descriptionHeight * 2; - if (view.getHeight() < minTextHeight) { - view.setMinimumHeight(minTextHeight); - } RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams(); if (AndroidUiHelper.isOrientationPortrait(getActivity())) { layoutParams.width = (int) (AndroidUtils.getScreenWidth(activity) / 2.5); @@ -593,6 +584,25 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { super(app, items); } + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { + RecyclerView.ViewHolder viewHolder = super.onCreateViewHolder(viewGroup, viewType); + + TextView title = viewHolder.itemView.findViewById(R.id.title); + TextView description = viewHolder.itemView.findViewById(R.id.description); + if (title != null && description != null) { + int titleHeight = AndroidUtils.getTextHeight(title.getPaint()); + int descriptionHeight = AndroidUtils.getTextHeight(description.getPaint()); + int minTextHeight = titleHeight + descriptionHeight * 2; + if (viewHolder.itemView.getHeight() < minTextHeight) { + viewHolder.itemView.setMinimumHeight(minTextHeight); + } + } + + return viewHolder; + } + @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { OsmandApplication app = getApp(); From 4c94cfa131aada4e0aaa63481ee21eda1b37eedb Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 25 Oct 2019 13:46:55 +0300 Subject: [PATCH 4/4] Fix defaultItemHeight --- .../plus/routepreparationmenu/AddPointBottomSheetDialog.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index a48c02c9b1..ad6be46339 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -595,7 +595,8 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { int titleHeight = AndroidUtils.getTextHeight(title.getPaint()); int descriptionHeight = AndroidUtils.getTextHeight(description.getPaint()); int minTextHeight = titleHeight + descriptionHeight * 2; - if (viewHolder.itemView.getHeight() < minTextHeight) { + int defaultItemHeight = viewGroup.getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_selected_item_title_height); + if (defaultItemHeight < minTextHeight) { viewHolder.itemView.setMinimumHeight(minTextHeight); } }