diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java index ed982747b0..ecf089c0b1 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -1,11 +1,16 @@ package net.osmand.plus.osmedit.dialogs; +import android.graphics.Rect; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.text.Editable; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.LinearLayout; +import android.widget.ScrollView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -51,6 +56,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { private TextInputEditText tagsField; private TextInputEditText messageField; + private int contentHeightPrevious = 0; public void setGpxInfos(GpxInfo[] gpxInfos) { this.gpxInfos = gpxInfos; @@ -63,6 +69,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode); View sendOsmPoiView = themedInflater.inflate(R.layout.send_gpx_fragment, null); + sendOsmPoiView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener()); tagsField = sendOsmPoiView.findViewById(R.id.tags_field); messageField = sendOsmPoiView.findViewById(R.id.message_field); @@ -124,6 +131,36 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { items.add(titleItem); } + private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() { + return new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + Rect visibleDisplayFrame = new Rect(); + int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width); + int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height); + final ScrollView scrollView = getView().findViewById(R.id.scroll_view); + scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame); + int height = scrollView.getHeight(); + int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight; + if (contentHeightPrevious != contentHeight || contentHeight < height) { + if (scrollView.getHeight() + shadowHeight > contentHeight) { + scrollView.getLayoutParams().height = contentHeight; + } else { + scrollView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; + } + scrollView.requestLayout(); + int delay = Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP ? 300 : 1000; + scrollView.postDelayed(new Runnable() { + public void run() { + scrollView.scrollTo(0, scrollView.getHeight()); + } + }, delay); + contentHeightPrevious = contentHeight; + } + } + }; + } + protected static void showOpenStreetMapScreen(@NonNull FragmentActivity activity) { if (activity instanceof MapActivity) { BaseSettingsFragment.showInstance(activity, OPEN_STREET_MAP_EDITING);