From c6bddc22d1ff230b80239fccbef57892d797a6c0 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Mon, 3 Aug 2020 14:20:20 +0300 Subject: [PATCH] Fix #9325 --- .../plus/views/MapQuickActionLayer.java | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index 97e9f64f2d..67fad90019 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -172,25 +172,43 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe } private void setQuickActionButtonMargin() { + int defRightMargin = calculateTotalSizePx(R.dimen.map_button_size, R.dimen.map_button_spacing_land) * 2; + int defBottomMargin = calculateTotalSizePx(R.dimen.map_button_size, R.dimen.map_button_spacing) * 2; FrameLayout.LayoutParams param = (FrameLayout.LayoutParams) quickActionButton.getLayoutParams(); if (AndroidUiHelper.isOrientationPortrait(mapActivity)) { Pair fabMargin = settings.getPortraitFabMargin(); - if (fabMargin != null) { - param.rightMargin = fabMargin.first; - param.bottomMargin = fabMargin.second; - } else { - param.bottomMargin = calculateTotalSizePx(R.dimen.map_button_size, R.dimen.map_button_spacing) * 2; - } + setQuickActionButtonMargin(param, fabMargin, 0, defBottomMargin); } else { Pair fabMargin = settings.getLandscapeFabMargin(); - if (fabMargin != null) { - param.rightMargin = fabMargin.first; - param.bottomMargin = fabMargin.second; - } else { - param.rightMargin = calculateTotalSizePx(R.dimen.map_button_size, R.dimen.map_button_spacing_land) * 2; - } + setQuickActionButtonMargin(param, fabMargin, defRightMargin, 0); } - quickActionButton.setLayoutParams(param); + } + + private void setQuickActionButtonMargin(FrameLayout.LayoutParams params, + Pair fabMargin, + int defRightMargin, int defBottomMargin) { + int screenHeight = AndroidUtils.getScreenHeight(mapActivity); + int screenWidth = AndroidUtils.getScreenWidth(mapActivity); + int btnHeight = quickActionButton.getHeight(); + int btnWidth = quickActionButton.getWidth(); + int rightMargin; + int bottomMargin; + if (fabMargin != null) { + rightMargin = fabMargin.first; + bottomMargin = fabMargin.second; + if (rightMargin < 0 || rightMargin > screenWidth - btnWidth) { + rightMargin = defRightMargin; + } + if (bottomMargin < 0 || bottomMargin > screenHeight - btnHeight) { + bottomMargin = defBottomMargin; + } + } else { + rightMargin = defRightMargin; + bottomMargin = defBottomMargin; + } + params.rightMargin = rightMargin; + params.bottomMargin = bottomMargin; + quickActionButton.setLayoutParams(params); } private int calculateTotalSizePx(@DimenRes int... dimensId) {