[android] improve map status bar handling and adapt its color

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
Arnaud Vergnet 2022-09-26 16:30:37 +02:00 committed by Alexander Borsuk
parent 383e0f61e3
commit f863559b50
22 changed files with 218 additions and 356 deletions

View file

@ -13,7 +13,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/margin_double"
android:clipChildren="false"
android:clipToPadding="false"
android:layoutDirection="ltr"

View file

@ -6,72 +6,58 @@
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/map_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map_ui_container">
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/map_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="@+id/onmap_downloader"
layout="@layout/onmap_downloader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
layout="@layout/onmap_downloader"/>
<include
android:id="@+id/position_chooser"
layout="@layout/position_chooser"/>
android:layout_centerInParent="true" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/map_buttons"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="@+id/position_chooser"
layout="@layout/position_chooser" />
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_with_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"
tools:visibility="visible" />
<include
layout="@layout/routing_plan"
android:visibility="invisible" />
<include
layout="@layout/menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<include
layout="@layout/layout_nav"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:paddingBottom="@dimen/margin_base"
android:visibility="invisible" />
</RelativeLayout>
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_with_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"
tools:visibility="visible" />
<include
layout="@layout/routing_plan"
android:visibility="invisible"/>
<include
layout="@layout/menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<include
layout="@layout/layout_nav"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:paddingBottom="@dimen/margin_base"
android:visibility="invisible"/>
</RelativeLayout>
<com.mapswithme.maps.widget.placepage.PlacePageView
android:id="@+id/placepage"
style="?attr/bottomSheetStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
app:layout_behavior="@string/placepage_behavior"/>
app:layout_behavior="@string/placepage_behavior" />
<FrameLayout
android:id="@+id/pp_buttons_layout"
android:layout_width="match_parent"
@ -83,8 +69,8 @@
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="@dimen/place_page_buttons_height"
android:orientation="horizontal"/>
<include layout="@layout/divider_horizontal"/>
android:orientation="horizontal" />
<include layout="@layout/divider_horizontal" />
</FrameLayout>
<include layout="@layout/elevation_profile_bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -37,7 +37,7 @@
<View
android:id="@+id/nav_bottom_sheet_nav_bar"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:background="?cardBackground"/>

View file

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_top_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layoutDirection="ltr"
tools:background="#20FF0000"
tools:showIn="@layout/layout_nav">
@ -14,6 +14,7 @@
android:layout_width="match_parent"
android:layout_height="@dimen/nav_street_height"
android:elevation="@dimen/nav_elevation"
app:layout_constraintTop_toTopOf="parent"
android:background="?cardBackground">
<TextView
android:id="@+id/street"
@ -27,16 +28,13 @@
tools:text="Sample street name.\nLong looooooooong!!!!"/>
</FrameLayout>
<include
layout="@layout/shadow_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/street_frame"/>
<RelativeLayout
android:id="@+id/nav_next_turn_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/street_frame"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="-40dp"
android:elevation="@dimen/nav_elevation">
<LinearLayout
android:id="@+id/nav_next_turn_frame"
@ -101,4 +99,4 @@
tools:src="@drawable/ic_then_left_sharp"/>
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -13,7 +13,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/margin_double"
android:clipChildren="false"
android:clipToPadding="false"
android:layoutDirection="ltr"

View file

@ -81,6 +81,7 @@
<color name="bg_menu_night">#CC2D3237</color>
<color name="bg_statusbar">#004120</color>
<color name="bg_statusbar_translucent">#66000000</color>
<color name="bg_statusbar_night">#121417</color>
<!-- Buttons -->

View file

@ -20,14 +20,12 @@
<style name="MwmTheme.MainActivity">
<item name="android:colorPrimaryDark">@android:color/black</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="MwmTheme.Night.MainActivity">
<item name="android:colorPrimaryDark">@android:color/black</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>

View file

@ -90,8 +90,6 @@ public class MapFragment extends BaseMwmFragment
UiUtils.dimen(context, R.dimen.margin_base),
ANCHOR_LEFT_TOP);
mCurrentCompassOffsetX = 0;
mCurrentCompassOffsetY = UiUtils.getCompassYOffset(requireContext());
setupCompass(mCurrentCompassOffsetY, mCurrentCompassOffsetX, false);
}
@ -287,6 +285,10 @@ public class MapFragment extends BaseMwmFragment
public void onCreate(Bundle b)
{
super.onCreate(b);
mCurrentCompassOffsetX = 0;
mCurrentCompassOffsetY = 0;
mBottomWidgetOffsetX = 0;
mBottomWidgetOffsetY = 0;
setRetainInstance(true);
Bundle args = getArguments();
if (args != null)

View file

@ -1,7 +1,5 @@
package com.mapswithme.maps;
import static com.mapswithme.maps.widget.placepage.PlacePageButtons.PLACEPAGE_MORE_MENU_ID;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
@ -13,7 +11,6 @@ import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.TextView;
@ -29,7 +26,6 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentFactory;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.mapswithme.maps.Framework.PlacePageActivationListener;
import com.mapswithme.maps.api.Const;
import com.mapswithme.maps.background.AppBackgroundTracker;
@ -101,6 +97,8 @@ import java.util.ArrayList;
import java.util.Objects;
import java.util.Stack;
import static com.mapswithme.maps.widget.placepage.PlacePageButtons.PLACEPAGE_MORE_MENU_ID;
public class MwmActivity extends BaseMwmFragmentActivity
implements PlacePageActivationListener,
View.OnTouchListener,
@ -149,6 +147,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private MapFragment mMapFragment;
private View mPointChooser;
private Toolbar mPointChooserToolbar;
enum PointChooserMode
{
NONE,
@ -189,6 +188,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
private int navBarHeight;
private WindowInsets mCurrentWindowInsets;
public interface LeftAnimationTrackListener
{
void onTrackStarted(boolean collapsed);
@ -378,6 +379,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
setContentView(R.layout.activity_map);
UiUtils.setupTransparentStatusBar(this);
mPlacePageController = PlacePageFactory.createCompositePlacePageController(
this, this);
@ -386,8 +388,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
mSearchController = new FloatingSearchToolbarController(this, this);
mSearchController.getToolbar()
.getViewTreeObserver()
.addOnGlobalLayoutListener(new ToolbarLayoutChangeListener());
.getViewTreeObserver();
boolean isLaunchByDeepLink = getIntent().getBooleanExtra(EXTRA_LAUNCH_BY_DEEP_LINK, false);
initViews(isLaunchByDeepLink);
@ -405,33 +406,34 @@ public class MwmActivity extends BaseMwmFragmentActivity
addTask(new Factory.RestoreRouteTask());
}
private void refreshLightStatusBar()
{
UiUtils.setLightStatusBar(this, !(
ThemeUtils.isNightTheme(this)
|| RoutingController.get().isPlanning()
|| Framework.nativeIsInChoosePositionMode()
));
}
private void updateViewsInsets()
{
findViewById(R.id.map_ui_container).setOnApplyWindowInsetsListener((view, windowInsets) -> {
setViewInsets(findViewById(R.id.map_ui_container), windowInsets);
setViewInsets(findViewById(R.id.pp_buttons_layout), windowInsets);
setViewInsets(findViewById(R.id.toolbar), windowInsets);
setViewInsets(findViewById(R.id.menu_frame), windowInsets);
setViewInsetsSides(findViewById(R.id.routing_plan_frame).findViewById(R.id.toolbar), windowInsets);
mPointChooser.setOnApplyWindowInsetsListener((view, windowInsets) -> {
UiUtils.setViewInsetsPaddingBottom(mPointChooser, windowInsets);
UiUtils.extendViewWithStatusBar(mPointChooserToolbar, windowInsets);
navBarHeight = windowInsets.getSystemWindowInsetBottom();
adjustCompass(-1, windowInsets.getSystemWindowInsetRight());
// For the first loading, set compass top margin to status bar size
if (mCurrentWindowInsets == null)
adjustCompass(windowInsets.getSystemWindowInsetTop(), windowInsets.getSystemWindowInsetRight());
else
adjustCompass(-1, windowInsets.getSystemWindowInsetRight());
refreshLightStatusBar();
adjustBottomWidgets(windowInsets.getSystemWindowInsetLeft());
mCurrentWindowInsets = windowInsets;
return windowInsets;
});
}
private void setViewInsets(View view, WindowInsets windowInsets)
{
view.setPadding(windowInsets.getSystemWindowInsetLeft(), view.getPaddingTop(),
windowInsets.getSystemWindowInsetRight(), windowInsets.getSystemWindowInsetBottom());
}
private void setViewInsetsSides(View view, WindowInsets windowInsets)
{
view.setPadding(windowInsets.getSystemWindowInsetLeft(), view.getPaddingTop(),
windowInsets.getSystemWindowInsetRight(), view.getPaddingBottom());
}
private int getDownloadMapsCounter()
{
UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
@ -473,10 +475,9 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (mPointChooser == null)
return;
final Toolbar toolbar = mPointChooser.findViewById(R.id.toolbar_point_chooser);
UiUtils.extendViewWithStatusBar(toolbar);
UiUtils.showHomeUpButton(toolbar);
toolbar.setNavigationOnClickListener(v -> {
mPointChooserToolbar = mPointChooser.findViewById(R.id.toolbar_point_chooser);
UiUtils.showHomeUpButton(mPointChooserToolbar);
mPointChooserToolbar.setNavigationOnClickListener(v -> {
closePositionChooser();
if (mPointChooserMode == PointChooserMode.API)
finish();
@ -562,6 +563,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
UiUtils.show(mPointChooser);
setFullscreen(true);
Framework.nativeTurnOnChoosePositionMode(isBusiness, applyPosition);
refreshLightStatusBar();
}
private void hidePositionChooser()
@ -572,6 +574,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (mPointChooserMode == PointChooserMode.API)
finish();
mPointChooserMode = PointChooserMode.NONE;
refreshLightStatusBar();
}
private void initMap(boolean isLaunchByDeepLink)
@ -1003,6 +1006,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
mNavigationController.onActivityResumed(this);
mMapButtonsController.onResume();
mPlacePageController.onActivityResumed(this);
refreshLightStatusBar();
}
@Override
@ -1390,9 +1394,14 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Override
public void onRoutingPlanStartAnimate(boolean show)
{
int totalHeight = calcFloatingViewsOffset();
adjustCompassAndTraffic(!show ? UiUtils.getStatusBarHeight(getApplicationContext())
: totalHeight);
int offset = mCurrentWindowInsets.getSystemWindowInsetTop();
if (show && mRoutingPlanInplaceController != null)
{
final int height = mRoutingPlanInplaceController.calcHeight();
if (height != 0)
offset = height;
}
adjustCompassAndTraffic(offset);
}
@Override
@ -1422,7 +1431,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
if (mIsTabletLayout)
{
adjustCompassAndTraffic(UiUtils.getStatusBarHeight(getApplicationContext()));
adjustCompassAndTraffic(mCurrentWindowInsets.getSystemWindowInsetTop());
}
else
{
@ -1451,16 +1460,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
});
}
private int calcFloatingViewsOffset()
{
int offset;
if (mRoutingPlanInplaceController == null
|| (offset = mRoutingPlanInplaceController.calcHeight()) == 0)
return UiUtils.getStatusBarHeight(this);
return offset;
}
@Override
public void showNavigation(boolean show)
{
@ -1506,6 +1505,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
mRoutingPlanInplaceController.hideDrivingOptionsView();
mNavigationController.stop(this);
initNavigationButtons(MapButtonsController.LayoutMode.regular);
refreshLightStatusBar();
}
@Override
@ -1515,6 +1515,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
ThemeSwitcher.INSTANCE.restart(isMapRendererActive());
mNavigationController.start(this);
initNavigationButtons(MapButtonsController.LayoutMode.navigation);
refreshLightStatusBar();
}
@Override
@ -1522,6 +1523,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
closeFloatingToolbarsAndPanels(true);
initNavigationButtons(MapButtonsController.LayoutMode.regular);
refreshLightStatusBar();
}
@Override
@ -1529,6 +1531,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
closeFloatingToolbarsAndPanels(true);
initNavigationButtons(MapButtonsController.LayoutMode.planning);
refreshLightStatusBar();
}
@Override
@ -1538,6 +1541,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
ThemeSwitcher.INSTANCE.restart(isMapRendererActive());
mNavigationController.stop(this);
initNavigationButtons(MapButtonsController.LayoutMode.planning);
refreshLightStatusBar();
}
@Override
@ -1750,20 +1754,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
BookmarkManager.INSTANCE.showBookmarkCategoryOnMap(categoryId);
}
private class ToolbarLayoutChangeListener implements ViewTreeObserver.OnGlobalLayoutListener
{
@Override
public void onGlobalLayout()
{
mSearchController.getToolbar().getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
adjustCompassAndTraffic(UiUtils.isVisible(mSearchController.getToolbar())
? calcFloatingViewsOffset()
: UiUtils.getStatusBarHeight(getApplicationContext()));
}
}
public void onAddPlaceOptionSelected()
{
closeFloatingPanels();

View file

@ -84,8 +84,6 @@ class PanelAnimator
for (MwmActivity.LeftAnimationTrackListener listener: mAnimationTrackListeners)
listener.onTrackStarted(true);
mAnimationTrackListeners.finishIterate();
mActivity.adjustCompass(UiUtils.getCompassYOffset(mActivity));
}
});
@ -120,8 +118,6 @@ class PanelAnimator
listener.onTrackStarted(false);
mAnimationTrackListeners.finishIterate();
mActivity.adjustCompass(UiUtils.getCompassYOffset(mActivity));
if (completionListener != null)
completionListener.run();
}

View file

@ -222,6 +222,11 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
else
MapManager.nativeDownload(mCurrentCountry.id);
}));
mFrame.setOnApplyWindowInsetsListener((view, windowInsets) -> {
UiUtils.setViewInsetsPadding(view, windowInsets);
return windowInsets;
});
}
@Override

View file

@ -120,6 +120,12 @@ public class MapButtonsController extends Fragment
mButtonsMap.put(MapButtons.menu, menuButton);
if (helpButton != null)
mButtonsMap.put(MapButtons.help, helpButton);
mFrame.setOnApplyWindowInsetsListener((view, windowInsets) -> {
UiUtils.setViewInsetsPadding(view, windowInsets);
return windowInsets;
});
return mFrame;
}

View file

@ -26,8 +26,8 @@ public class TrafficButton
mButton = trafficBtn;
mLoadingAnim = getLoadingAnim(trafficBtn);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) trafficBtn.getLayoutParams();
params.setMargins(0, UiUtils.getStatusBarHeight(trafficBtn.getContext()), 0, 0);
// RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) trafficBtn.getLayoutParams();
// params.setMargins(0, UiUtils.getStatusBarHeight(trafficBtn.getContext()), 0, 0);
}
@NonNull

View file

@ -12,7 +12,6 @@ import android.os.IBinder;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
@ -87,13 +86,6 @@ public class NavigationController implements Application.ActivityLifecycleCallba
mOnSettingsClickListener = onSettingsClickListener;
mMapButtonsController = mapButtonsController;
// Show a blank view below the navbar to hide the menu content
mFrame.findViewById(R.id.nav_bottom_sheet_nav_bar).setOnApplyWindowInsetsListener((view, windowInsets) -> {
view.getLayoutParams().height = windowInsets.getSystemWindowInsetBottom();
view.getLayoutParams().width = mFrame.findViewById(R.id.nav_bottom_sheet).getWidth();
return windowInsets;
});
// Top frame
View topFrame = mFrame.findViewById(R.id.nav_top_frame);
View turnFrame = topFrame.findViewById(R.id.nav_next_turn_frame);
@ -112,11 +104,20 @@ public class NavigationController implements Application.ActivityLifecycleCallba
mStreetFrame = topFrame.findViewById(R.id.street_frame);
mNextStreet = mStreetFrame.findViewById(R.id.street);
View shadow = topFrame.findViewById(R.id.shadow_top);
UiUtils.hide(shadow);
UiUtils.extendViewWithStatusBar(mStreetFrame);
UiUtils.extendViewMarginWithStatusBar(turnFrame);
// Show a blank view below the navbar to hide the menu content
final View navigationBarBackground = mFrame.findViewById(R.id.nav_bottom_sheet_nav_bar);
final View nextTurnContainer = mFrame.findViewById(R.id.nav_next_turn_container);
mStreetFrame.setOnApplyWindowInsetsListener((v, windowInsets) -> {
UiUtils.extendViewWithStatusBar(v, windowInsets);
nextTurnContainer.setPadding(windowInsets.getSystemWindowInsetLeft(), nextTurnContainer.getPaddingTop(),
nextTurnContainer.getPaddingRight(), nextTurnContainer.getPaddingBottom());
navigationBarBackground.getLayoutParams().height = windowInsets.getSystemWindowInsetBottom();
// The gesture navigation bar stays at the bottom in landscape
// We need to add a background only above the nav menu
navigationBarBackground.getLayoutParams().width = mFrame.findViewById(R.id.nav_bottom_sheet).getWidth();
return windowInsets;
});
final Application app = (Application) mFrame.getContext().getApplicationContext();
mSpeedCamSignalCompletionListener = new CameraWarningSignalCompletionListener(app);

View file

@ -104,6 +104,11 @@ public class RoutingPlanController extends ToolbarController
mDriverOptionsLayoutListener = new SelfTerminatedDrivingOptionsLayoutListener();
mAnimToggle = MwmApplication.from(activity.getApplicationContext())
.getResources().getInteger(R.integer.anim_default);
mFrame.setOnApplyWindowInsetsListener((view, windowInsets) -> {
UiUtils.setViewInsetsPaddingNoTop(activity.findViewById(R.id.menu_frame), windowInsets);
return windowInsets;
});
}
@NonNull

View file

@ -27,6 +27,10 @@ public class FloatingSearchToolbarController extends SearchToolbarController
mListener = listener;
// We only want to detect a click on the input and not allow editing.
disableQueryEditing();
getToolbar().setOnApplyWindowInsetsListener((view, windowInsets) -> {
UiUtils.setViewInsetsPaddingNoTop(view, windowInsets);
return windowInsets;
});
}
@Override

View file

@ -31,7 +31,12 @@ public class ToolbarController implements Detachable<Activity>
mToolbar = root.findViewById(getToolbarId());
if (useExtendedToolbar())
UiUtils.extendViewWithStatusBar(getToolbar());
{
getToolbar().setOnApplyWindowInsetsListener((view, windowInsets) -> {
UiUtils.extendViewWithStatusBar(getToolbar(), windowInsets);
return windowInsets;
});
}
UiUtils.setupNavigationIcon(mToolbar, mNavigationClickListener);
setSupportActionBar(activity, mToolbar);
}

View file

@ -9,7 +9,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.mapswithme.maps.R;
import com.mapswithme.maps.location.LocationHelper;
@ -54,8 +53,8 @@ public class NavMenu
{
mActivity = activity;
mNavMenuListener = navMenuListener;
View mBottomFrame = mActivity.findViewById(R.id.nav_bottom_frame);
mHeaderFrame = mBottomFrame.findViewById(R.id.line_frame);
final View bottomFrame = mActivity.findViewById(R.id.nav_bottom_frame);
mHeaderFrame = bottomFrame.findViewById(R.id.line_frame);
mHeaderFrame.setOnClickListener(v -> toggleNavMenu());
mHeaderFrame.addOnLayoutChangeListener((view, i, i1, i2, i3, i4, i5, i6, i7) -> setPeekHeight());
mNavBottomSheetBehavior = BottomSheetBehavior.from(mActivity.findViewById(R.id.nav_bottom_sheet));
@ -86,24 +85,24 @@ public class NavMenu
});
// Bottom frame
mSpeedViewContainer = mBottomFrame.findViewById(R.id.speed_view_container);
mSpeedValue = mBottomFrame.findViewById(R.id.speed_value);
mSpeedUnits = mBottomFrame.findViewById(R.id.speed_dimen);
mTimeHourValue = mBottomFrame.findViewById(R.id.time_hour_value);
mTimeHourUnits = mBottomFrame.findViewById(R.id.time_hour_dimen);
mTimeMinuteValue = mBottomFrame.findViewById(R.id.time_minute_value);
mTimeMinuteUnits = mBottomFrame.findViewById(R.id.time_minute_dimen);
mTimeEstimate = mBottomFrame.findViewById(R.id.time_estimate);
mDistanceValue = mBottomFrame.findViewById(R.id.distance_value);
mDistanceUnits = mBottomFrame.findViewById(R.id.distance_dimen);
mRouteProgress = mBottomFrame.findViewById(R.id.navigation_progress);
mSpeedViewContainer = bottomFrame.findViewById(R.id.speed_view_container);
mSpeedValue = bottomFrame.findViewById(R.id.speed_value);
mSpeedUnits = bottomFrame.findViewById(R.id.speed_dimen);
mTimeHourValue = bottomFrame.findViewById(R.id.time_hour_value);
mTimeHourUnits = bottomFrame.findViewById(R.id.time_hour_dimen);
mTimeMinuteValue = bottomFrame.findViewById(R.id.time_minute_value);
mTimeMinuteUnits = bottomFrame.findViewById(R.id.time_minute_dimen);
mTimeEstimate = bottomFrame.findViewById(R.id.time_estimate);
mDistanceValue = bottomFrame.findViewById(R.id.distance_value);
mDistanceUnits = bottomFrame.findViewById(R.id.distance_dimen);
mRouteProgress = bottomFrame.findViewById(R.id.navigation_progress);
// Bottom frame buttons
ImageView mSettings = mBottomFrame.findViewById(R.id.settings);
ImageView mSettings = bottomFrame.findViewById(R.id.settings);
mSettings.setOnClickListener(v -> onSettingsClicked());
mTts = mBottomFrame.findViewById(R.id.tts_volume);
mTts = bottomFrame.findViewById(R.id.tts_volume);
mTts.setOnClickListener(v -> onTtsClicked());
Button stop = mBottomFrame.findViewById(R.id.stop);
Button stop = bottomFrame.findViewById(R.id.stop);
stop.setOnClickListener(v -> onStopClicked());
UiUtils.updateRedButton(stop);

View file

@ -104,7 +104,10 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
private void initToolbar(View view)
{
Toolbar toolbar = view.findViewById(R.id.toolbar);
UiUtils.extendViewWithStatusBar(toolbar);
toolbar.setOnApplyWindowInsetsListener((v, windowInsets) -> {
UiUtils.extendViewWithStatusBar(v, windowInsets);
return windowInsets;
});
final TextView textView = toolbar.findViewById(R.id.tv__save);
textView.setOnClickListener(new View.OnClickListener()
{

View file

@ -1,131 +0,0 @@
package com.mapswithme.maps.widget.placepage;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmDialogFragment;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.UiUtils;
import java.lang.ref.WeakReference;
public class EditDescriptionFragment extends BaseMwmDialogFragment
{
public static final String EXTRA_BOOKMARK = "bookmark";
private EditText mEtDescription;
private Bookmark mBookmark;
public interface OnDescriptionSavedListener
{
void onSaved(Bookmark bookmark);
}
private WeakReference<OnDescriptionSavedListener> mListener;
public EditDescriptionFragment() {}
@Override
protected int getCustomTheme()
{
return getFullscreenTheme();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_edit_description, container, false);
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState)
{
mBookmark = getArguments().getParcelable(EXTRA_BOOKMARK);
String description = null;
if (mBookmark != null)
description = mBookmark.getBookmarkDescription();
if (description != null && StringUtils.nativeIsHtml(description))
{
final String descriptionNoSimpleTags = StringUtils.removeEditTextHtmlTags(description);
if (!StringUtils.nativeIsHtml(descriptionNoSimpleTags))
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
description = Html.fromHtml(description, Html.FROM_HTML_MODE_LEGACY).toString();
else
description = Html.fromHtml(description).toString();
}
}
mEtDescription = view.findViewById(R.id.et__description);
mEtDescription.setText(description);
initToolbar(view);
mEtDescription.requestFocus();
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
public void setSaveDescriptionListener(OnDescriptionSavedListener listener)
{
mListener = new WeakReference<>(listener);
}
private void initToolbar(View view)
{
Toolbar toolbar = view.findViewById(R.id.toolbar);
UiUtils.extendViewWithStatusBar(toolbar);
final TextView textView = toolbar.findViewById(R.id.tv__save);
textView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
saveDescription();
}
});
UiUtils.showHomeUpButton(toolbar);
toolbar.setTitle(R.string.description);
toolbar.setNavigationOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
dismiss();
}
});
}
private void saveDescription()
{
mBookmark.setParams(mBookmark.getTitle(), null, mEtDescription.getText().toString());
if (mListener != null)
{
OnDescriptionSavedListener listener = mListener.get();
if (listener != null)
listener.onSaved(mBookmark);
}
dismiss();
}
@Override
public void onDetach()
{
super.onDetach();
mListener = null;
}
}

View file

@ -7,6 +7,7 @@ import android.location.Location;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -132,6 +133,12 @@ public class RichPlacePageController implements PlacePageController, LocationLis
mPlacePage.initButtons(buttons);
UiUtils.bringViewToFrontOf(mButtonsLayout, mPlacePage);
LocationHelper.INSTANCE.addListener(this);
mButtonsLayout.setOnApplyWindowInsetsListener((view, windowInsets) -> {
UiUtils.setViewInsetsPaddingNoTop(mButtonsLayout, windowInsets);
return windowInsets;
});
mPlacePage.requestApplyInsets();
}
public int getPlacePageWidth()

View file

@ -11,6 +11,7 @@ import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
@ -22,28 +23,29 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowInsets;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.AnyRes;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DimenRes;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.textfield.TextInputLayout;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import java.util.Objects;
public final class UiUtils
{
private static final int DEFAULT_TINT_COLOR = Color.parseColor("#20000000");
@ -53,12 +55,6 @@ public final class UiUtils
public static final String WIDE_PHRASE_SEPARATOR = "";
public static final String APPROXIMATE_SYMBOL = "~";
public static void addStatusBarOffset(@NonNull View view)
{
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
params.setMargins(0, UiUtils.getStatusBarHeight(view.getContext()), 0, 0);
}
public static void bringViewToFrontOf(@NonNull View frontView, @NonNull View backView)
{
frontView.setZ(backView.getZ() + 1);
@ -364,75 +360,73 @@ public final class UiUtils
return viewRect.contains(x, y);
}
public static int getStatusBarHeight(@NonNull Context context)
public static void setupTransparentStatusBar(@NonNull Activity activity)
{
int result = 0;
Resources res = context.getResources();
// TODO: find a better way of getting system status bar height
// https://github.com/organicmaps/organicmaps/issues/3611
@SuppressLint({"DiscouragedApi", "InternalInsetResource"})
int resourceId = res.getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0)
result = res.getDimensionPixelSize(resourceId);
return result;
final Window window = activity.getWindow();
window.getDecorView().setFitsSystemWindows(false);
window.setStatusBarColor(Color.TRANSPARENT);
}
public static void extendViewWithStatusBar(@NonNull View view)
public static void setLightStatusBar(@NonNull Activity activity, boolean isLight)
{
int statusBarHeight = getStatusBarHeight(view.getContext());
ViewGroup.LayoutParams lp = view.getLayoutParams();
if (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT)
final Window window = activity.getWindow();
final View decorView = window.getDecorView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
extendViewPaddingTop(view, statusBarHeight);
return;
WindowInsetsControllerCompat wic = WindowCompat.getInsetsController(window, decorView);
// It should not be possible for Window insets controller to be null
Objects.requireNonNull(wic).setAppearanceLightStatusBars(isLight);
}
else
{
@ColorInt final int color = isLight
? ResourcesCompat.getColor(activity.getResources(), R.color.bg_statusbar_translucent, null)
: Color.TRANSPARENT;
window.setStatusBarColor(color);
}
lp.height += statusBarHeight;
view.setLayoutParams(lp);
extendViewPaddingTop(view, statusBarHeight);
}
public static void extendViewPaddingWithStatusBar(@NonNull View view)
public static void extendViewWithStatusBar(@NonNull View view, WindowInsets windowInsets)
{
int statusBarHeight = getStatusBarHeight(view.getContext());
extendViewPaddingTop(view, statusBarHeight);
final int height = windowInsets.getSystemWindowInsetTop();
final ViewGroup.LayoutParams lp = view.getLayoutParams();
// Extend the height only when necessary
if (lp.height != ViewGroup.LayoutParams.WRAP_CONTENT && view.getPaddingTop() < height)
{
lp.height += height;
view.setLayoutParams(lp);
}
setViewInsetsPaddingNoBottom(view, windowInsets);
}
private static void extendViewPaddingTop(@NonNull View view, int statusBarHeight)
public static void setViewInsetsPadding(View view, WindowInsets windowInsets)
{
view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + statusBarHeight,
view.getPaddingRight(), view.getPaddingBottom());
view.setPadding(windowInsets.getSystemWindowInsetLeft(), windowInsets.getSystemWindowInsetTop(),
windowInsets.getSystemWindowInsetRight(), windowInsets.getSystemWindowInsetBottom());
}
public static void extendViewMarginWithStatusBar(@NonNull View view)
public static void setViewInsetsPaddingNoTop(View view, WindowInsets windowInsets)
{
int statusBarHeight = getStatusBarHeight(view.getContext());
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
int margin = lp.getMarginStart();
lp.setMargins(margin, margin + statusBarHeight, margin, margin);
view.setLayoutParams(lp);
view.setPadding(windowInsets.getSystemWindowInsetLeft(), view.getPaddingTop(),
windowInsets.getSystemWindowInsetRight(), windowInsets.getSystemWindowInsetBottom());
}
public static void setupStatusBar(@NonNull Activity activity)
public static void setViewInsetsPaddingSides(View view, WindowInsets windowInsets)
{
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
View statusBarTintView = new View(activity);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
params.gravity = Gravity.TOP;
statusBarTintView.setLayoutParams(params);
statusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
statusBarTintView.setVisibility(View.VISIBLE);
ViewGroup decorViewGroup = (ViewGroup) activity.getWindow().getDecorView();
decorViewGroup.addView(statusBarTintView);
view.setPadding(windowInsets.getSystemWindowInsetLeft(), view.getPaddingTop(),
windowInsets.getSystemWindowInsetRight(), view.getPaddingBottom());
}
public static void setupColorStatusBar(@NonNull Activity activity, @ColorRes int statusBarColor)
public static void setViewInsetsPaddingBottom(View view, WindowInsets windowInsets)
{
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(activity, statusBarColor));
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(),
view.getPaddingRight(), windowInsets.getSystemWindowInsetBottom());
}
public static void setViewInsetsPaddingNoBottom(View view, WindowInsets windowInsets)
{
view.setPadding(windowInsets.getSystemWindowInsetLeft(), windowInsets.getSystemWindowInsetTop(),
windowInsets.getSystemWindowInsetRight(), view.getPaddingBottom());
}
public static void setupNavigationIcon(@NonNull Toolbar toolbar,
@ -462,11 +456,6 @@ public final class UiUtils
toolbar.setNavigationOnClickListener(null);
}
public static int getCompassYOffset(@NonNull Context context)
{
return getStatusBarHeight(context);
}
@AnyRes
public static int getStyledResourceId(@NonNull Context context, @AttrRes int res)
{