From 81f367eacb22d4707889291dbc5c2ce673e5cf5a Mon Sep 17 00:00:00 2001 From: cepprice Date: Tue, 16 Mar 2021 19:12:02 +0500 Subject: [PATCH] Fix ClassCastException --- .../MeasurementToolFragment.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 779dd6f2e1..c777f3bdb0 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -307,6 +307,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void onGlobalLayout() { updateCardContainerSize(); + mainView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); } @@ -676,19 +677,36 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route } private void updateCardContainerSize() { + if (portrait) { + return; + } View measureModeControls = mainView.findViewById(R.id.measure_mode_controls); int width = mainView.getWidth() - measureModeControls.getWidth(); - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, -1); int bottomMargin = measureModeControls.getHeight(); bottomMargin = progressBarVisible ? bottomMargin + mainView.findViewById(R.id.snap_to_road_progress_bar).getHeight() : bottomMargin; - params.setMargins(0, 0, 0, bottomMargin); - cardsContainer.setLayoutParams(params); + if (mainView.getParent() instanceof FrameLayout) { + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, -1); + params.setMargins(0, 0, 0, bottomMargin); + cardsContainer.setLayoutParams(params); + } else if (mainView.getParent() instanceof LinearLayout) { + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, -1); + params.setMargins(0, 0, 0, bottomMargin); + cardsContainer.setLayoutParams(params); + } } private void shiftBottomMapControls(boolean toInitialPosition) { + if (portrait) { + return; + } int leftMargin = toInitialPosition ? 0 : cardsContainer.getWidth(); - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) bottomMapControls.getLayoutParams(); - params.setMargins(leftMargin, 0, 0, 0); + if (bottomMapControls.getParent() instanceof LinearLayout) { + LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) bottomMapControls.getLayoutParams(); + params.setMargins(leftMargin, 0, 0, 0); + } else if (bottomMapControls.getParent() instanceof FrameLayout) { + FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) bottomMapControls.getLayoutParams(); + params.setMargins(leftMargin, 0, 0, 0); + } } public boolean isInEditMode() {