Merge pull request #9559 from osmandapp/Fix_9325

Fix #9325
This commit is contained in:
vshcherb 2020-08-03 14:15:09 +02:00 committed by GitHub
commit bb6387eb57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -172,25 +172,43 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
} }
private void setQuickActionButtonMargin() { 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(); FrameLayout.LayoutParams param = (FrameLayout.LayoutParams) quickActionButton.getLayoutParams();
if (AndroidUiHelper.isOrientationPortrait(mapActivity)) { if (AndroidUiHelper.isOrientationPortrait(mapActivity)) {
Pair<Integer, Integer> fabMargin = settings.getPortraitFabMargin(); Pair<Integer, Integer> fabMargin = settings.getPortraitFabMargin();
if (fabMargin != null) { setQuickActionButtonMargin(param, fabMargin, 0, defBottomMargin);
param.rightMargin = fabMargin.first;
param.bottomMargin = fabMargin.second;
} else {
param.bottomMargin = calculateTotalSizePx(R.dimen.map_button_size, R.dimen.map_button_spacing) * 2;
}
} else { } else {
Pair<Integer, Integer> fabMargin = settings.getLandscapeFabMargin(); Pair<Integer, Integer> fabMargin = settings.getLandscapeFabMargin();
if (fabMargin != null) { setQuickActionButtonMargin(param, fabMargin, defRightMargin, 0);
param.rightMargin = fabMargin.first;
param.bottomMargin = fabMargin.second;
} else {
param.rightMargin = calculateTotalSizePx(R.dimen.map_button_size, R.dimen.map_button_spacing_land) * 2;
}
} }
quickActionButton.setLayoutParams(param); }
private void setQuickActionButtonMargin(FrameLayout.LayoutParams params,
Pair<Integer, Integer> 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) { private int calculateTotalSizePx(@DimenRes int... dimensId) {