Merge pull request #7753 from osmandapp/Fix_7596

Fix 7596
This commit is contained in:
max-klaus 2019-10-25 13:49:07 +03:00 committed by GitHub
commit 2388820ec1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View file

@ -388,13 +388,18 @@ public class AndroidUtils {
: ctx.getResources().getColor(R.color.text_color_secondary_light)); : ctx.getResources().getColor(R.color.text_color_secondary_light));
} }
public static int getTextWidth(float textSize, String text) { public static int getTextWidth(float textSize, String text) {
Paint paint = new Paint(); Paint paint = new Paint();
paint.setTextSize(textSize); paint.setTextSize(textSize);
return (int) paint.measureText(text); 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) { public static int dpToPx(Context ctx, float dp) {
Resources r = ctx.getResources(); Resources r = ctx.getResources();
return (int) TypedValue.applyDimension( return (int) TypedValue.applyDimension(

View file

@ -3,7 +3,6 @@ package net.osmand.plus.routepreparationmenu;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
@ -552,10 +551,10 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
if (activity != null) { if (activity != null) {
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams(); RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
if (AndroidUiHelper.isOrientationPortrait(getActivity())) { if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
layoutParams.width = AndroidUtils.getScreenWidth(activity) / 2; layoutParams.width = (int) (AndroidUtils.getScreenWidth(activity) / 2.5);
} else { } else {
// 11.5dp is the shadow width // 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); view.setLayoutParams(layoutParams);
} }
@ -585,6 +584,26 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
super(app, items); 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;
int defaultItemHeight = viewGroup.getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_selected_item_title_height);
if (defaultItemHeight < minTextHeight) {
viewHolder.itemView.setMinimumHeight(minTextHeight);
}
}
return viewHolder;
}
@Override @Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
OsmandApplication app = getApp(); OsmandApplication app = getApp();