From 92d02e926a815b697fe7cfa087ccc17343ab1e51 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Wed, 7 Sep 2022 15:55:30 +0200 Subject: [PATCH] [android] Adjust compass to transparent nav bar Signed-off-by: Arnaud Vergnet --- .../src/com/mapswithme/maps/MapFragment.java | 24 +++++++++++++++---- .../src/com/mapswithme/maps/MwmActivity.java | 12 ++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/android/src/com/mapswithme/maps/MapFragment.java b/android/src/com/mapswithme/maps/MapFragment.java index a7f51bce9f..9225ceaf9e 100644 --- a/android/src/com/mapswithme/maps/MapFragment.java +++ b/android/src/com/mapswithme/maps/MapFragment.java @@ -57,6 +57,9 @@ public class MapFragment extends BaseMwmFragment private static final int INVALID_POINTER_MASK = 0xFF; private static final int INVALID_TOUCH_ID = -1; + private int mCurrentCompassOffsetX; + private int mCurrentCompassOffsetY; + private int mHeight; private int mWidth; private int mBottomWidgetOffset; @@ -86,21 +89,34 @@ public class MapFragment extends BaseMwmFragment UiUtils.dimen(context, R.dimen.margin_base), ANCHOR_LEFT_TOP); - setupCompass(UiUtils.getCompassYOffset(requireContext()), false); + mCurrentCompassOffsetX = 0; + mCurrentCompassOffsetY = UiUtils.getCompassYOffset(requireContext()); + setupCompass(mCurrentCompassOffsetY, mCurrentCompassOffsetX, false); } - void setupCompass(int offsetY, boolean forceRedraw) + /** + * Moves the map compass using the given offsets. + * + * @param offsetY Pixel offset from the top. -1 to keep the previous value. + * @param offsetX Pixel offset from the right. -1 to keep the previous value. + * @param forceRedraw True to force the compass to redraw + */ + void setupCompass(int offsetY, int offsetX, boolean forceRedraw) { Context context = requireContext(); + int x = offsetX < 0 ? mCurrentCompassOffsetX : offsetX; + int y = offsetY < 0 ? mCurrentCompassOffsetY : offsetY; int navPadding = UiUtils.dimen(context, R.dimen.nav_frame_padding); int marginX = UiUtils.dimen(context, R.dimen.margin_compass) + navPadding; int marginY = UiUtils.dimen(context, R.dimen.margin_compass_top) + navPadding; nativeSetupWidget(WIDGET_COMPASS, - mWidth - marginX, - offsetY + marginY, + mWidth - x - marginX, + y + marginY, ANCHOR_CENTER); if (forceRedraw && mSurfaceCreated) nativeApplyWidgets(); + mCurrentCompassOffsetX = x; + mCurrentCompassOffsetY = y; } void setupBottomWidgetsOffset(int offset) diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index e3e9f4b389..5b551a673a 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -433,7 +433,10 @@ public class MwmActivity extends BaseMwmFragmentActivity findViewById(R.id.routing_plan_frame).findViewById(R.id.toolbar) .setOnApplyWindowInsetsListener(this::setViewInsetsSides); - + findViewById(R.id.map_fragment_container).setOnApplyWindowInsetsListener((view, windowInsets) -> { + adjustCompass(-1, windowInsets.getSystemWindowInsetRight()); + return windowInsets; + }); } private WindowInsets setViewInsets(View view, WindowInsets windowInsets) @@ -1275,11 +1278,16 @@ public class MwmActivity extends BaseMwmFragmentActivity } void adjustCompass(int offsetY) + { + adjustCompass(offsetY, -1); + } + + void adjustCompass(int offsetY, int offsetX) { if (mMapFragment == null || !mMapFragment.isAdded()) return; - mMapFragment.setupCompass(offsetY, true); + mMapFragment.setupCompass(offsetY, offsetX, true); CompassData compass = LocationHelper.INSTANCE.getCompassData(); if (compass != null)