diff --git a/OsmAnd/res/layout/bottom_sheet_menu_base.xml b/OsmAnd/res/layout/bottom_sheet_menu_base.xml index cb4716cf00..4d62622dd6 100644 --- a/OsmAnd/res/layout/bottom_sheet_menu_base.xml +++ b/OsmAnd/res/layout/bottom_sheet_menu_base.xml @@ -8,7 +8,8 @@ + android:layout_height="0dp" + android:layout_weight="1"> = AndroidUtils.dpToPx(activity, 8); - if (AndroidUiHelper.isOrientationPortrait(activity)) { - AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity)); - if (!showTopShadow) { - mainView.setPadding(0, 0, 0, 0); - } - } else { - AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity)); - } + drawTopShadow(showTopShadow); } }); } + protected void drawTopShadow(boolean showTopShadow) { + final Activity activity = getActivity(); + View mainView = getView(); + if (activity == null || mainView == null) { + return; + } + if (AndroidUiHelper.isOrientationPortrait(activity)) { + AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity)); + if (!showTopShadow) { + mainView.setPadding(0, 0, 0, 0); + } + } else { + AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity)); + } + } + private int getContentHeight(int availableScreenHeight) { int customHeight = getCustomHeight(); int buttonsHeight; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java index ecf089c0b1..759f924d10 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -2,12 +2,10 @@ 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; @@ -57,6 +55,9 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { private TextInputEditText tagsField; private TextInputEditText messageField; private int contentHeightPrevious = 0; + private int buttonsHeight; + private int shadowHeight; + private ScrollView scrollView; public void setGpxInfos(GpxInfo[] gpxInfos) { this.gpxInfos = gpxInfos; @@ -136,26 +137,18 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { @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); + buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width); + shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height); + scrollView = getView().findViewById(R.id.scroll_view); scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame); - int height = scrollView.getHeight(); + int viewHeight = 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; - } + if (contentHeightPrevious != contentHeight) { + boolean showTopShadow; + showTopShadow = viewHeight + shadowHeight < contentHeight; 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; + drawTopShadow(showTopShadow); } } }; diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java index b3f160f910..8f4b4b4181 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java @@ -1,7 +1,6 @@ package net.osmand.plus.settings.bottomsheets; import android.annotation.SuppressLint; -import android.app.Activity; import android.graphics.Rect; import android.os.Build; import android.os.Bundle; @@ -23,13 +22,11 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; -import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; -import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.fragments.ApplyQueryType; @@ -52,6 +49,9 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet { private float currentValue; private int contentHeightPrevious = 0; private EditText text; + private int buttonsHeight; + private int shadowHeight; + private ScrollView scrollView; @Override public void createMenuItems(Bundle savedInstanceState) { @@ -164,13 +164,13 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet { @Override public void onGlobalLayout() { Rect visibleDisplayFrame = new Rect(); - int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height); - int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height); - final ScrollView scrollView = getView().findViewById(R.id.scroll_view); + buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height); + shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height); + scrollView = getView().findViewById(R.id.scroll_view); scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame); - boolean showTopShadow; int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight; if (contentHeightPrevious != contentHeight) { + boolean showTopShadow; if (scrollView.getHeight() + shadowHeight > contentHeight) { scrollView.getLayoutParams().height = contentHeight; showTopShadow = false; @@ -189,22 +189,6 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet { drawTopShadow(showTopShadow); } } - - private void drawTopShadow(boolean showTopShadow) { - final Activity activity = getActivity(); - View mainView = getView(); - if (activity == null || mainView == null) { - return; - } - if (AndroidUiHelper.isOrientationPortrait(activity)) { - AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity)); - if (!showTopShadow) { - mainView.setPadding(0, 0, 0, 0); - } - } else { - AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity)); - } - } }; } @@ -225,7 +209,7 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet { } public static void showInstance(@NonNull FragmentManager fm, String key, Fragment target, - boolean usedOnMap, @Nullable ApplicationMode appMode) { + boolean usedOnMap, @Nullable ApplicationMode appMode) { try { if (!fm.isStateSaved()) { Bundle args = new Bundle();