From c2264c3838f5ed0a4a17ea0bc12508f972cfd849 Mon Sep 17 00:00:00 2001 From: sergosm Date: Wed, 30 Sep 2020 14:48:07 +0300 Subject: [PATCH 1/3] Bottom sheets: buttons types and behaviors --- OsmAnd/res/layout/bottom_buttons_vertical.xml | 51 ++++++ OsmAnd/res/layout/bottom_sheet_menu_base.xml | 8 +- .../base/MenuBottomSheetDialogFragment.java | 172 ++++++++++++++---- .../ExitBottomSheetDialogFragment.java | 69 +++---- 4 files changed, 223 insertions(+), 77 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_buttons_vertical.xml diff --git a/OsmAnd/res/layout/bottom_buttons_vertical.xml b/OsmAnd/res/layout/bottom_buttons_vertical.xml new file mode 100644 index 0000000000..5ea2d4954c --- /dev/null +++ b/OsmAnd/res/layout/bottom_buttons_vertical.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_menu_base.xml b/OsmAnd/res/layout/bottom_sheet_menu_base.xml index 5110455a7c..d265ba938c 100644 --- a/OsmAnd/res/layout/bottom_sheet_menu_base.xml +++ b/OsmAnd/res/layout/bottom_sheet_menu_base.xml @@ -35,10 +35,8 @@ android:layout_width="match_parent" android:layout_height="10dp" android:layout_gravity="bottom" - android:visibility="gone" - android:background="@drawable/bg_contextmenu_shadow_top_light" /> + android:background="@drawable/bg_contextmenu_shadow_top_light" + android:visibility="gone" /> - - - + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 7625e5de20..57378848f5 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -8,11 +8,11 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.os.Build; import android.os.Bundle; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; +import android.view.ViewTreeObserver.OnScrollChangedListener; import android.view.Window; import android.view.WindowManager; import android.widget.LinearLayout; @@ -50,8 +50,11 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra protected int themeRes; protected View dismissButton; protected View rightButton; + protected View thirdButton; private LinearLayout itemsContainer; + private LinearLayout buttonsContainer; + protected View buttonsShadow; @StringRes protected int dismissButtonStringRes = R.string.shared_string_cancel; @@ -74,45 +77,21 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { createMenuItems(savedInstanceState); - Context ctx = requireContext(); - View mainView = View.inflate(new ContextThemeWrapper(ctx, themeRes), R.layout.bottom_sheet_menu_base, null); + Activity activity = requireActivity(); + LayoutInflater themedInflater = UiUtilities.getInflater(activity, nightMode); + View mainView = themedInflater.inflate(R.layout.bottom_sheet_menu_base, null); if (useScrollableItemsContainer()) { - itemsContainer = (LinearLayout) mainView.findViewById(R.id.scrollable_items_container); + itemsContainer = mainView.findViewById(R.id.scrollable_items_container); } else { mainView.findViewById(R.id.scroll_view).setVisibility(View.GONE); - itemsContainer = (LinearLayout) mainView.findViewById(R.id.non_scrollable_items_container); + itemsContainer = mainView.findViewById(R.id.non_scrollable_items_container); itemsContainer.setVisibility(View.VISIBLE); } + buttonsShadow = mainView.findViewById(R.id.buttons_shadow); inflateMenuItems(); - - dismissButton = mainView.findViewById(R.id.dismiss_button); - UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId()); - dismissButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onDismissButtonClickAction(); - dismiss(); - } - }); - if (hideButtonsContainer()) { - mainView.findViewById(R.id.buttons_container).setVisibility(View.GONE); - } else { - int rightBottomButtonTextId = getRightBottomButtonTextId(); - if (rightBottomButtonTextId != DEFAULT_VALUE) { - mainView.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE); - rightButton = mainView.findViewById(R.id.right_bottom_button); - UiUtilities.setupDialogButton(nightMode, rightButton, getRightBottomButtonType(), rightBottomButtonTextId); - rightButton.setVisibility(View.VISIBLE); - rightButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onRightBottomButtonClick(); - } - }); - } - } - updateBottomButtons(); + setupScrollShadow(mainView); + setupBottomButtons((ViewGroup) mainView); setupHeightAndBackground(mainView); return mainView; } @@ -183,7 +162,6 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } final int screenHeight = AndroidUtils.getScreenHeight(activity); final int statusBarHeight = AndroidUtils.getStatusBarHeight(activity); - final int contentHeight = getContentHeight(screenHeight - statusBarHeight); mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override @@ -194,12 +172,13 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } else { obs.removeGlobalOnLayoutListener(this); } + final int contentHeight = getContentHeight(screenHeight - statusBarHeight); final View contentView = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer; if (contentView.getHeight() > contentHeight) { if (useScrollableItemsContainer() || useExpandableList()) { contentView.getLayoutParams().height = contentHeight; - mainView.findViewById(R.id.buttons_shadow).setVisibility(View.VISIBLE); + buttonsShadow.setVisibility(View.VISIBLE); } else { contentView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; } @@ -222,7 +201,13 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra private int getContentHeight(int availableScreenHeight) { int customHeight = getCustomHeight(); - int maxHeight = availableScreenHeight - getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height); + int buttonsHeight = 0; + if (useVerticalButtons()) { + buttonsHeight = AndroidUtils.dpToPx(getContext(), 112); + } else { + buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height); + } + int maxHeight = availableScreenHeight - buttonsHeight; if (customHeight != DEFAULT_VALUE && customHeight <= maxHeight) { return customHeight; } @@ -280,6 +265,18 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } + protected int getThirdBottomButtonTextId() { + return DEFAULT_VALUE; + } + + protected DialogButtonType getThirdBottomButtonType() { + return DialogButtonType.PRIMARY; + } + + protected void onThirdBottomButtonClick() { + + } + protected boolean isDismissButtonEnabled() { return true; } @@ -288,6 +285,40 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra return true; } + protected void setupBottomButtons(ViewGroup view) { + Activity activity = requireActivity(); + LayoutInflater themedInflater = UiUtilities.getInflater(activity, nightMode); + if (!hideButtonsContainer()) { + if (useVerticalButtons()) { + buttonsContainer = (LinearLayout) themedInflater.inflate(R.layout.bottom_buttons_vertical, view); + setupThirdButton(); + } else { + buttonsContainer = (LinearLayout) themedInflater.inflate(R.layout.bottom_buttons, view); + } + setupRightButton(); + setupDismissButton(); + updateBottomButtons(); + } + } + + boolean useVerticalButtons() { + Activity activity = requireActivity(); + int rightBottomButtonTextId = getRightBottomButtonTextId(); + if (getDismissButtonTextId() != DEFAULT_VALUE && rightBottomButtonTextId != DEFAULT_VALUE) { + if (getThirdBottomButtonTextId() != DEFAULT_VALUE) { + return true; + } + String rightButtonText = getString(rightBottomButtonTextId); + boolean portrait = AndroidUiHelper.isOrientationPortrait(activity); + int dialogWidth = portrait ? AndroidUtils.getScreenWidth(activity) : getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width); + int measuredTextWidth = AndroidUtils.getTextWidth(getResources().getDimensionPixelSize(R.dimen.default_desc_text_size), rightButtonText); + int availableTextWidth = (dialogWidth - AndroidUtils.dpToPx(activity, 96)) / 2; + + return measuredTextWidth > availableTextWidth; + } + return false; + } + protected void updateBottomButtons() { if (dismissButton != null) { boolean enabled = isDismissButtonEnabled(); @@ -301,6 +332,54 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } } + private void setupDismissButton() { + dismissButton = buttonsContainer.findViewById(R.id.dismiss_button); + int buttonTextId = getDismissButtonTextId(); + if (buttonTextId != DEFAULT_VALUE) { + UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), buttonTextId); + dismissButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onDismissButtonClickAction(); + dismiss(); + } + }); + } + AndroidUiHelper.updateVisibility(dismissButton, buttonTextId != DEFAULT_VALUE); + } + + private void setupRightButton() { + rightButton = buttonsContainer.findViewById(R.id.right_bottom_button); + int buttonTextId = getRightBottomButtonTextId(); + if (buttonTextId != DEFAULT_VALUE) { + UiUtilities.setupDialogButton(nightMode, rightButton, getRightBottomButtonType(), buttonTextId); + rightButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onRightBottomButtonClick(); + } + }); + } + AndroidUiHelper.updateVisibility(rightButton, buttonTextId != DEFAULT_VALUE); + AndroidUiHelper.updateVisibility(buttonsContainer.findViewById(R.id.buttons_divider), buttonTextId != DEFAULT_VALUE); + } + + private void setupThirdButton() { + thirdButton = buttonsContainer.findViewById(R.id.third_button); + int buttonTextId = getThirdBottomButtonTextId(); + if (buttonTextId != DEFAULT_VALUE) { + UiUtilities.setupDialogButton(nightMode, thirdButton, getThirdBottomButtonType(), buttonTextId); + thirdButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onThirdBottomButtonClick(); + } + }); + } + AndroidUiHelper.updateVisibility(thirdButton, buttonTextId != DEFAULT_VALUE); + AndroidUiHelper.updateVisibility(buttonsContainer.findViewById(R.id.buttons_divider_top), buttonTextId != DEFAULT_VALUE); + } + @ColorRes protected int getBgColorId() { return nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light; @@ -325,7 +404,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra private LayerDrawable createBackgroundDrawable(@NonNull Context ctx, @DrawableRes int shadowDrawableResId) { Drawable shadowDrawable = ContextCompat.getDrawable(ctx, shadowDrawableResId); - Drawable[] layers = new Drawable[]{shadowDrawable, getColoredBg(ctx)}; + Drawable[] layers = new Drawable[] {shadowDrawable, getColoredBg(ctx)}; return new LayerDrawable(layers); } @@ -335,4 +414,21 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } return !app.getSettings().isLightContent(); } -} + + private void setupScrollShadow(View view) { + final View scrollView; + if (useScrollableItemsContainer()) { + scrollView = view.findViewById(R.id.scroll_view); + } else { + scrollView = itemsContainer; + } + scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() { + + @Override + public void onScrollChanged() { + boolean scrollToBottomAvailable = scrollView.canScrollVertically(1); + AndroidUiHelper.updateVisibility(buttonsShadow, scrollToBottomAvailable); + } + }); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java index df7b4ae9b7..94b5b16e46 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java @@ -28,46 +28,14 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment items.add(new ShortDescriptionItem.Builder() .setDescription(getString(R.string.plan_route_exit_dialog_descr)) - .setTitle(getString(R.string.exit_without_saving)) + .setTitle(getString(R.string. + exit_without_saving)) .setLayoutId(R.layout.bottom_sheet_item_list_title_with_descr) .create()); items.add(new DividerSpaceItem(getContext(), getResources().getDimensionPixelSize(R.dimen.bottom_sheet_exit_button_margin))); - items.add(new BottomSheetItemButton.Builder() - .setButtonType(UiUtilities.DialogButtonType.SECONDARY) - .setTitle(getString(R.string.shared_string_exit)) - .setLayoutId(R.layout.bottom_sheet_button) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Fragment targetFragment = getTargetFragment(); - if (targetFragment != null) { - targetFragment.onActivityResult(REQUEST_CODE, EXIT_RESULT_CODE, null); - } - dismiss(); - } - }) - .create()); - - items.add(new DividerSpaceItem(getContext(), - getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin))); - - items.add(new BottomSheetItemButton.Builder() - .setTitle(getString(R.string.shared_string_save)) - .setLayoutId(R.layout.bottom_sheet_button) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Fragment targetFragment = getTargetFragment(); - if (targetFragment != null) { - targetFragment.onActivityResult(REQUEST_CODE, SAVE_RESULT_CODE, null); - } - dismiss(); - } - }) - .create()); } @Override @@ -75,6 +43,39 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment return R.string.shared_string_cancel; } + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_save; + } + + @Override + protected int getThirdBottomButtonTextId() { + return R.string.shared_string_exit; + } + + @Override + protected void onRightBottomButtonClick() { + Fragment targetFragment = getTargetFragment(); + if (targetFragment != null) { + targetFragment.onActivityResult(REQUEST_CODE, SAVE_RESULT_CODE, null); + } + dismiss(); + } + + @Override + protected void onThirdBottomButtonClick() { + Fragment targetFragment = getTargetFragment(); + if (targetFragment != null) { + targetFragment.onActivityResult(REQUEST_CODE, EXIT_RESULT_CODE, null); + } + dismiss(); + } + + @Override + protected UiUtilities.DialogButtonType getThirdBottomButtonType() { + return (UiUtilities.DialogButtonType.SECONDARY); + } + public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment) { if (!fragmentManager.isStateSaved()) { ExitBottomSheetDialogFragment fragment = new ExitBottomSheetDialogFragment(); From 7ab1dcd7fb8f919dcc599818602d0d3382ce7a8a Mon Sep 17 00:00:00 2001 From: sergosm Date: Thu, 1 Oct 2020 22:26:32 +0300 Subject: [PATCH 2/3] Ability to divide Add support for 3-row buttons, with the ability to divide one of the buttons, to make it visually divided. --- .../plus/base/MenuBottomSheetDialogFragment.java | 16 ++++++++++++++-- .../ExitBottomSheetDialogFragment.java | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 57378848f5..0d86993502 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -360,8 +360,14 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } }); } + View divider = buttonsContainer.findViewById(R.id.buttons_divider); + divider.getLayoutParams().height = getFirstDividerHeight(); AndroidUiHelper.updateVisibility(rightButton, buttonTextId != DEFAULT_VALUE); - AndroidUiHelper.updateVisibility(buttonsContainer.findViewById(R.id.buttons_divider), buttonTextId != DEFAULT_VALUE); + AndroidUiHelper.updateVisibility(divider, buttonTextId != DEFAULT_VALUE); + } + + protected int getFirstDividerHeight(){ + return getResources().getDimensionPixelSize(R.dimen.content_padding); } private void setupThirdButton() { @@ -376,8 +382,14 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } }); } + View divider = buttonsContainer.findViewById(R.id.buttons_divider_top); + divider.getLayoutParams().height = getSecondDividerHeight(); AndroidUiHelper.updateVisibility(thirdButton, buttonTextId != DEFAULT_VALUE); - AndroidUiHelper.updateVisibility(buttonsContainer.findViewById(R.id.buttons_divider_top), buttonTextId != DEFAULT_VALUE); + AndroidUiHelper.updateVisibility(divider, buttonTextId != DEFAULT_VALUE); + } + + protected int getSecondDividerHeight(){ + return getResources().getDimensionPixelSize(R.dimen.content_padding); } @ColorRes diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java index 94b5b16e46..7d88767964 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java @@ -14,6 +14,7 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemButton; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; +import net.osmand.plus.helpers.AndroidUiHelper; public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -53,6 +54,11 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment return R.string.shared_string_exit; } + @Override + public int getSecondDividerHeight() { + return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large); + } + @Override protected void onRightBottomButtonClick() { Fragment targetFragment = getTargetFragment(); From 447259b80b3b90081f451a4e39da1d7be6aff4b4 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 5 Oct 2020 12:13:21 +0300 Subject: [PATCH 3/3] Small pr fixes --- OsmAnd/res/layout/bottom_buttons_vertical.xml | 85 ++++++++++--------- .../base/MenuBottomSheetDialogFragment.java | 23 +++-- .../ExitBottomSheetDialogFragment.java | 16 ++-- 3 files changed, 64 insertions(+), 60 deletions(-) diff --git a/OsmAnd/res/layout/bottom_buttons_vertical.xml b/OsmAnd/res/layout/bottom_buttons_vertical.xml index 5ea2d4954c..0de7d48389 100644 --- a/OsmAnd/res/layout/bottom_buttons_vertical.xml +++ b/OsmAnd/res/layout/bottom_buttons_vertical.xml @@ -1,51 +1,52 @@ + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/buttons_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:gravity="center" + android:orientation="vertical" + android:paddingStart="@dimen/content_padding" + android:paddingLeft="@dimen/content_padding" + android:paddingTop="@dimen/content_padding_small" + android:paddingEnd="@dimen/content_padding" + android:paddingRight="@dimen/content_padding" + android:paddingBottom="@dimen/content_padding_small"> - + - + - + - + - + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 0d86993502..307cfb3bbe 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -52,9 +52,9 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra protected View rightButton; protected View thirdButton; + private View buttonsShadow; private LinearLayout itemsContainer; private LinearLayout buttonsContainer; - protected View buttonsShadow; @StringRes protected int dismissButtonStringRes = R.string.shared_string_cancel; @@ -162,6 +162,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } final int screenHeight = AndroidUtils.getScreenHeight(activity); final int statusBarHeight = AndroidUtils.getStatusBarHeight(activity); + final int contentHeight = getContentHeight(screenHeight - statusBarHeight); mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override @@ -172,7 +173,6 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } else { obs.removeGlobalOnLayoutListener(this); } - final int contentHeight = getContentHeight(screenHeight - statusBarHeight); final View contentView = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer; if (contentView.getHeight() > contentHeight) { @@ -201,9 +201,14 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra private int getContentHeight(int availableScreenHeight) { int customHeight = getCustomHeight(); - int buttonsHeight = 0; + int buttonsHeight; if (useVerticalButtons()) { - buttonsHeight = AndroidUtils.dpToPx(getContext(), 112); + int padding = getResources().getDimensionPixelSize(R.dimen.content_padding_small); + int buttonHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_height); + buttonsHeight = (buttonHeight + padding) * 2 + getFirstDividerHeight(); + if (getThirdBottomButtonTextId() != DEFAULT_VALUE) { + buttonsHeight += buttonHeight + getSecondDividerHeight(); + } } else { buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height); } @@ -310,10 +315,12 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } String rightButtonText = getString(rightBottomButtonTextId); boolean portrait = AndroidUiHelper.isOrientationPortrait(activity); + int outerPadding = getResources().getDimensionPixelSize(R.dimen.content_padding); + int innerPadding = getResources().getDimensionPixelSize(R.dimen.content_padding_small); int dialogWidth = portrait ? AndroidUtils.getScreenWidth(activity) : getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width); - int measuredTextWidth = AndroidUtils.getTextWidth(getResources().getDimensionPixelSize(R.dimen.default_desc_text_size), rightButtonText); - int availableTextWidth = (dialogWidth - AndroidUtils.dpToPx(activity, 96)) / 2; + int availableTextWidth = (dialogWidth - (outerPadding * 3 + innerPadding * 4)) / 2; + int measuredTextWidth = AndroidUtils.getTextWidth(getResources().getDimensionPixelSize(R.dimen.default_desc_text_size), rightButtonText); return measuredTextWidth > availableTextWidth; } return false; @@ -366,7 +373,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra AndroidUiHelper.updateVisibility(divider, buttonTextId != DEFAULT_VALUE); } - protected int getFirstDividerHeight(){ + protected int getFirstDividerHeight() { return getResources().getDimensionPixelSize(R.dimen.content_padding); } @@ -388,7 +395,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra AndroidUiHelper.updateVisibility(divider, buttonTextId != DEFAULT_VALUE); } - protected int getSecondDividerHeight(){ + protected int getSecondDividerHeight() { return getResources().getDimensionPixelSize(R.dimen.content_padding); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java index 7d88767964..1bdd3ffdf2 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.measurementtool; import android.os.Bundle; -import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -9,12 +8,10 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import net.osmand.plus.R; -import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.base.MenuBottomSheetDialogFragment; -import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemButton; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; -import net.osmand.plus.helpers.AndroidUiHelper; public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -29,8 +26,7 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment items.add(new ShortDescriptionItem.Builder() .setDescription(getString(R.string.plan_route_exit_dialog_descr)) - .setTitle(getString(R.string. - exit_without_saving)) + .setTitle(getString(R.string.exit_without_saving)) .setLayoutId(R.layout.bottom_sheet_item_list_title_with_descr) .create()); @@ -56,7 +52,7 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment @Override public int getSecondDividerHeight() { - return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large); + return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin); } @Override @@ -78,8 +74,8 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment } @Override - protected UiUtilities.DialogButtonType getThirdBottomButtonType() { - return (UiUtilities.DialogButtonType.SECONDARY); + protected DialogButtonType getThirdBottomButtonType() { + return (DialogButtonType.SECONDARY); } public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment) { @@ -89,4 +85,4 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment fragment.show(fragmentManager, TAG); } } -} +} \ No newline at end of file