From 347d41ee1c2d87a77fd49a19a0ce9f559c7df38e Mon Sep 17 00:00:00 2001 From: Dmitry Donskoy Date: Fri, 5 Apr 2019 15:15:31 +0300 Subject: [PATCH] [android] Added correct adjusting for floating views on the MapActivity --- .../src/com/mapswithme/maps/MwmActivity.java | 40 ++++++++++++++----- .../maps/routing/RoutingPlanController.java | 5 --- .../routing/RoutingPlanInplaceController.java | 2 +- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 97b967dd6d..a0896c60ac 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -249,6 +249,10 @@ public class MwmActivity extends BaseMwmFragmentActivity @NonNull private View mDrivingOptionsBtnContainer; + @SuppressWarnings("NullableProblems") + @NonNull + private View.OnLayoutChangeListener mDriverOptionsLayoutListener; + public interface LeftAnimationTrackListener { void onTrackStarted(boolean collapsed); @@ -547,12 +551,9 @@ public class MwmActivity extends BaseMwmFragmentActivity private void initDrivingOptionsViews() { mDrivingOptionsBtnContainer = findViewById(R.id.driving_options_btn_container); - View routingPlanFrame = findViewById(R.id.routing_plan_frame); - DrivingOptionsLayoutChangeListener listener = new DrivingOptionsLayoutChangeListener(); - routingPlanFrame.addOnLayoutChangeListener(listener); View btn = mDrivingOptionsBtnContainer.findViewById(R.id.driving_options_btn); btn.setOnClickListener(v -> DrivingOptionsActivity.start(this)); - mDrivingOptionsBtnContainer.addOnLayoutChangeListener(listener); + mDriverOptionsLayoutListener = new SelfTerminatedDrivingOptionsLayoutListener(); } private void initTips() @@ -1854,10 +1855,12 @@ public class MwmActivity extends BaseMwmFragmentActivity if (mNavAnimationController == null) return; - mNavAnimationController.setTopLimit(!show ? 0 : mRoutingPlanInplaceController.getHeight()); + int totalHeight = calcFloatingViewOffset(); + + mNavAnimationController.setTopLimit(!show ? 0 : totalHeight); mNavAnimationController.setBottomLimit(!show ? 0 : getCurrentMenu().getFrame().getHeight()); adjustCompassAndTraffic(!show ? UiUtils.getStatusBarHeight(getApplicationContext()) - : mRoutingPlanInplaceController.getHeight()); + : totalHeight); } @Override @@ -1940,9 +1943,7 @@ public class MwmActivity extends BaseMwmFragmentActivity return; int toolbarHeight = mSearchController.getToolbar().getHeight(); - int offset = mRoutingPlanInplaceController != null - && mRoutingPlanInplaceController.getHeight() > 0 - ? mRoutingPlanInplaceController.getHeight() : UiUtils.getStatusBarHeight(this); + int offset = calcFloatingViewOffset(); adjustCompassAndTraffic(visible ? toolbarHeight : offset); setNavButtonsTopLimit(visible ? toolbarHeight : 0); @@ -1955,6 +1956,19 @@ public class MwmActivity extends BaseMwmFragmentActivity } } + private int calcFloatingViewOffset() + { + if (mRoutingPlanInplaceController == null + || mRoutingPlanInplaceController.getFrame().getHeight() == 0) + return UiUtils.getStatusBarHeight(this); + + int extraOppositeOffset = mDrivingOptionsBtnContainer.getVisibility() == View.VISIBLE + ? 0 + : mDrivingOptionsBtnContainer.getHeight(); + + return mRoutingPlanInplaceController.getFrame().getHeight() - extraOppositeOffset; + } + @Override public void onResultsUpdate(SearchResult[] results, long timestamp, boolean isHotel) { @@ -2074,6 +2088,7 @@ public class MwmActivity extends BaseMwmFragmentActivity private void showDrivingOptionView() { + mDrivingOptionsBtnContainer.addOnLayoutChangeListener(mDriverOptionsLayoutListener); UiUtils.show(mDrivingOptionsBtnContainer); View image = findViewById(R.id.driving_options_btn_img); UiUtils.showIf(RoutingOptions.hasAnyOptions(), image); @@ -2084,6 +2099,7 @@ public class MwmActivity extends BaseMwmFragmentActivity private void hideDrivingOptionsView() { + mDrivingOptionsBtnContainer.addOnLayoutChangeListener(mDriverOptionsLayoutListener); UiUtils.hide(mDrivingOptionsBtnContainer); } @@ -2762,7 +2778,7 @@ public class MwmActivity extends BaseMwmFragmentActivity dialog.show(this, ERROR_CALCULATE_ROUTE_FIRST_TIME_TAG); } - private class DrivingOptionsLayoutChangeListener implements View.OnLayoutChangeListener + private class SelfTerminatedDrivingOptionsLayoutListener implements View.OnLayoutChangeListener { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, @@ -2771,7 +2787,9 @@ public class MwmActivity extends BaseMwmFragmentActivity if (mRoutingPlanInplaceController == null) return; - adjustCompassAndTraffic(mRoutingPlanInplaceController.getFrame().getHeight()); + onRoutingPlanStartAnimate( + mRoutingPlanInplaceController.getFrame().getVisibility() == View.VISIBLE); + mDrivingOptionsBtnContainer.removeOnLayoutChangeListener(this); } } } diff --git a/android/src/com/mapswithme/maps/routing/RoutingPlanController.java b/android/src/com/mapswithme/maps/routing/RoutingPlanController.java index 77b272217d..82a582cec8 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingPlanController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingPlanController.java @@ -305,11 +305,6 @@ public class RoutingPlanController extends ToolbarController mRoutingBottomMenuController.restoreRoutingPanelState(state); } - public int getHeight() - { - return mFrameHeight; - } - public void showAddStartFrame() { mRoutingBottomMenuController.showAddStartFrame(); diff --git a/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java b/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java index 2f9da5b286..6c3d25ea17 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java @@ -77,7 +77,7 @@ public class RoutingPlanInplaceController extends RoutingPlanController mRoutingPlanListener.onRoutingPlanStartAnimate(show); ValueAnimator animator = - ValueAnimator.ofFloat(show ? -mFrameHeight : 0, show ? 0 : -mFrameHeight); + ValueAnimator.ofFloat(show ? -getFrame().getHeight() : 0, show ? 0 : -getFrame().getHeight()); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override