From 372e35c46b48855342c23d727cced436866bbe4d Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Wed, 2 Dec 2020 14:28:31 +0200 Subject: [PATCH 1/3] Bottom sheet should scroll outside the screen, bottom sheets behavior with keyboard Bottom sheet should scroll outside the screen Check keyboard doesn't show after open If the bottom sheet contains "text field" taping on it will show the keyboard, bottom sheet main buttons should be above the keyboard. --- OsmAnd/res/layout/bottom_sheet_menu_base.xml | 3 ++- OsmAnd/res/layout/send_gpx_fragment.xml | 2 ++ .../dialogs/SendGpxBottomSheetFragment.java | 24 +++++++------------ 3 files changed, 13 insertions(+), 16 deletions(-) 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"> contentHeight) { - scrollView.getLayoutParams().height = contentHeight; + if (contentHeightPrevious != contentHeight && activity != null) { + if (viewHeight + shadowHeight < contentHeight) { + AndroidUtils.setBackground(getView(), getPortraitBg(activity)); } else { - scrollView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; + AndroidUtils.setBackground(getView(), getColoredBg(activity)); } 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; } } }; From 5240191d51e8cdc6b5f04d5dee1170f2b0c54f11 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Wed, 2 Dec 2020 22:13:30 +0200 Subject: [PATCH 2/3] Update SendGpxBottomSheetFragment.java --- .../dialogs/SendGpxBottomSheetFragment.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java index 4d2a6e7e73..ca7bf3ec53 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -30,6 +30,7 @@ import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem; @@ -56,7 +57,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { private TextInputEditText tagsField; private TextInputEditText messageField; - private final int contentHeightPrevious = 0; + private int contentHeightPrevious = 0; public void setGpxInfos(GpxInfo[] gpxInfos) { this.gpxInfos = gpxInfos; @@ -139,17 +140,32 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { Activity activity = getActivity(); int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width); int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height); + boolean showTopShadow; final ScrollView scrollView = getView().findViewById(R.id.scroll_view); scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame); int viewHeight = scrollView.getHeight(); int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight; if (contentHeightPrevious != contentHeight && activity != null) { - if (viewHeight + shadowHeight < contentHeight) { - AndroidUtils.setBackground(getView(), getPortraitBg(activity)); - } else { - AndroidUtils.setBackground(getView(), getColoredBg(activity)); - } + showTopShadow = viewHeight + shadowHeight < contentHeight; scrollView.requestLayout(); + contentHeightPrevious = contentHeight; + 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)); } } }; From 60b9cbd91f7eac15d814dd58eb8032b401aa07d2 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Thu, 3 Dec 2020 12:03:23 +0200 Subject: [PATCH 3/3] Refactor --- .../base/MenuBottomSheetDialogFragment.java | 25 +++++++++----- .../dialogs/SendGpxBottomSheetFragment.java | 33 +++++-------------- .../VehicleParametersBottomSheet.java | 32 +++++------------- 3 files changed, 33 insertions(+), 57 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 84bd292aa5..71192fafe6 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -187,18 +187,27 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra // 8dp is the shadow height boolean showTopShadow = screenHeight - statusBarHeight - mainView.getHeight() >= 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 ca7bf3ec53..759f924d10 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -1,6 +1,5 @@ package net.osmand.plus.osmedit.dialogs; -import android.app.Activity; import android.graphics.Rect; import android.os.AsyncTask; import android.os.Bundle; @@ -22,7 +21,6 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.textfield.TextInputEditText; -import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -30,7 +28,6 @@ import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; -import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem; @@ -58,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; @@ -137,37 +137,20 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { @Override public void onGlobalLayout() { Rect visibleDisplayFrame = new Rect(); - Activity activity = getActivity(); - int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width); - int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height); - boolean showTopShadow; - 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 viewHeight = scrollView.getHeight(); int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight; - if (contentHeightPrevious != contentHeight && activity != null) { + if (contentHeightPrevious != contentHeight) { + boolean showTopShadow; showTopShadow = viewHeight + shadowHeight < contentHeight; scrollView.requestLayout(); contentHeightPrevious = contentHeight; 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)); - } - } }; } 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();