[android] Adjust compass to transparent nav bar

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
Arnaud Vergnet 2022-09-07 15:55:30 +02:00 committed by Viktor Govako
parent 6310366643
commit 92d02e926a
2 changed files with 30 additions and 6 deletions

View file

@ -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)

View file

@ -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)