[android] remove main menu bar

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
Arnaud Vergnet 2022-07-11 12:36:08 +02:00 committed by Roman Tsisyk
parent 282425e1ac
commit 59532504ff
15 changed files with 136 additions and 304 deletions

View file

@ -1,15 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<group
android:pivotX="24"
android:pivotY="24"
android:scaleX="0.50"
android:scaleY="0.50">
<path
android:fillColor="#FFF"
android:pathData="M48,18.8509c0,0.4231 -0.25,0.8846 -0.75,1.3846l-10.4712,10.2116 2.4808,14.4231c0.0192,0.1346 0.0288,0.3269 0.0288,0.5769 0,0.4038 -0.101,0.7452 -0.3029,1.024 -0.2019,0.2788 -0.4952,0.4183 -0.8798,0.4183 -0.3654,0 -0.75,-0.1154 -1.1538,-0.3462l-12.9519,-6.8077 -12.9519,6.8077c-0.4231,0.2308 -0.8077,0.3462 -1.1538,0.3462 -0.4038,0 -0.7067,-0.1394 -0.9087,-0.4183 -0.2019,-0.2788 -0.3029,-0.6202 -0.3029,-1.024 0,-0.1154 0.0192,-0.3077 0.0577,-0.5769l2.4808,-14.4231 -10.5,-10.2116c-0.4808,-0.5192 -0.7212,-0.9808 -0.7212,-1.3846 0,-0.7115 0.5385,-1.1538 1.6154,-1.3269l14.4808,-2.1058 6.4904,-13.125c0.3654,-0.7885 0.8365,-1.1827 1.4135,-1.1827 0.5769,0 1.0481,0.3942 1.4135,1.1827l6.4904,13.125 14.4808,2.1058c1.0769,0.1731 1.6154,0.6154 1.6154,1.3269Z" />
</group>
</vector>

View file

@ -1,15 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<group
android:pivotX="24"
android:pivotY="24"
android:scaleX="0.60"
android:scaleY="0.60">
<path
android:fillColor="#fff"
android:pathData="M31,28h-1.59l-0.55,-0.55c1.96,-2.27 3.14,-5.22 3.14,-8.45 0,-7.18 -5.82,-13 -13,-13 -7.18,0 -13,5.82 -13,13 0,7.18 5.82,13 13,13 3.23,0 6.18,-1.18 8.45,-3.13l0.55,0.55v1.58l10,9.98 2.98,-2.98 -9.98,-10ZM19,28c-4.97,0 -9,-4.03 -9,-9 0,-4.97 4.03,-9 9,-9 4.97,0 9,4.03 9,9 0,4.97 -4.03,9 -9,9Z" />
</group>
</vector>

View file

@ -1,15 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<group
android:pivotX="24"
android:pivotY="24"
android:scaleX="0.65"
android:scaleY="0.65">
<path
android:fillColor="#fff"
android:pathData="M36,32.17c-1.52,0 -2.89,0.59 -3.93,1.54l-14.25,-8.31c0.11,-0.45 0.18,-0.92 0.18,-1.4 0,-0.48 -0.07,-0.95 -0.18,-1.4l14.1,-8.23c1.07,1 2.5,1.62 4.08,1.62 3.31,0 6,-2.69 6,-6 0,-3.31 -2.69,-6 -6,-6 -3.31,0 -6,2.69 -6,6 0,0.48 0.07,0.95 0.18,1.4l-14.1,8.23c-1.07,-1 -2.5,-1.62 -4.08,-1.62 -3.31,0 -6,2.69 -6,6 0,3.31 2.69,6 6,6 1.58,0 3.01,-0.62 4.08,-1.62l14.25,8.31c-0.1,0.42 -0.16,0.86 -0.16,1.31 0,3.22 2.61,5.83 5.83,5.83 3.22,0 5.83,-2.61 5.83,-5.83 0,-3.22 -2.61,-5.83 -5.83,-5.83Z" />
</group>
</vector>

View file

@ -27,10 +27,8 @@
layout="@layout/layout_nav_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" />
app:layout_constraintStart_toStartOf="parent" />
<include
layout="@layout/map_navigation_buttons_zoom"
android:layout_width="wrap_content"
@ -52,6 +50,14 @@
style="@style/MwmWidget.MapButton"
android:contentDescription="@string/core_my_position"
android:tint="@null"
android:layout_marginBottom="@dimen/margin_half"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/menu_button" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/menu_button"
style="@style/MwmWidget.MapButton"
android:layout_marginBottom="@dimen/margin_half"
android:src="@drawable/ic_menu_open"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -27,10 +27,8 @@
layout="@layout/layout_nav_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" />
app:layout_constraintStart_toStartOf="parent" />
<include
layout="@layout/map_navigation_buttons_zoom"
android:layout_width="wrap_content"
@ -50,8 +48,16 @@
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/my_position"
style="@style/MwmWidget.MapButton"
android:layout_marginBottom="@dimen/margin_half"
android:contentDescription="@string/core_my_position"
android:tint="@null"
app:layout_constraintBottom_toTopOf="@+id/menu_button"
app:layout_constraintEnd_toEndOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/menu_button"
style="@style/MwmWidget.MapButton"
android:layout_marginBottom="@dimen/margin_half"
android:src="@drawable/ic_menu_open"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -5,18 +5,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?menuBackground"
android:visibility="invisible"
android:visibility="gone"
tools:visibility="visible">
<include
android:id="@+id/buttons_frame"
layout="@layout/menu_buttons_line" />
<include
android:id="@+id/routing_plan_frame"
layout="@layout/menu_route_plan_line"
tools:layout_height="@dimen/menu_line_height"
tools:layout_marginTop="60dp"
tools:layout_width="match_parent" />
<include
@ -24,7 +19,7 @@
layout="@layout/routing_action_panel"
android:visibility="gone"
tools:layout_height="wrap_content"
tools:layout_marginTop="120dp"
tools:layout_marginTop="@dimen/menu_line_height"
tools:layout_width="match_parent"
tools:visibility="visible" />
</FrameLayout>

View file

@ -1,64 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/menu_line_height"
android:paddingStart="@dimen/margin_half"
android:paddingEnd="@dimen/margin_half"
tools:background="#40FF0000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/help"
style="@style/MwmTheme.Menu.Line.Button"
android:src="@drawable/ic_question_mark"
android:tag="@string/tag_menu_collapse"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:id="@+id/search"
style="@style/MwmTheme.Menu.Line.Button"
android:src="@drawable/ic_menu_search"
android:tag="@string/tag_menu_collapse"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:id="@+id/bookmarks"
style="@style/MwmTheme.Menu.Line.Button"
android:src="@drawable/ic_menu_bookmarks"
android:tag="@string/tag_menu_collapse"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:id="@+id/toggle"
style="@style/MwmTheme.Menu.Line.Button"
android:src="@drawable/ic_menu_open"
android:tag="@string/tag_menu_collapse"/>
</LinearLayout>
<View
android:id="@+id/marker"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="end"
android:layout_marginTop="@dimen/margin_half"
android:layout_marginEnd="@dimen/margin_half"
android:background="@drawable/counter"
android:visibility="gone"
tools:visibility="visible"/>
</FrameLayout>

View file

@ -75,8 +75,7 @@
<!-- map widgets -->
<dimen name="margin_compass">32dp</dimen>
<dimen name="margin_compass_top">26dp</dimen>
<dimen name="margin_ruler_left">10dp</dimen>
<dimen name="margin_ruler_bottom">58dp</dimen>
<dimen name="margin_ruler">10dp</dimen>
<dimen name="compass_height">40dp</dimen>
<dimen name="button_big_corner_radius">20dp</dimen>
<dimen name="button_small_corner_radius">2dp</dimen>

View file

@ -63,7 +63,6 @@ public class MapFragment extends BaseMwmFragment
private boolean mSurfaceCreated;
private boolean mSurfaceAttached;
private boolean mLaunchByDeepLink;
private static boolean sWasCopyrightDisplayed;
@Nullable
private String mUiThemeOnPause;
@SuppressWarnings("NullableProblems")
@ -71,8 +70,6 @@ public class MapFragment extends BaseMwmFragment
private SurfaceView mSurfaceView;
@Nullable
private MapRenderingListener mMapRenderingListener;
@Nullable
private MapWidgetOffsetsProvider mWidgetOffsetsProvider;
private void setupWidgets(int width, int height)
{
@ -81,16 +78,7 @@ public class MapFragment extends BaseMwmFragment
Context context = requireContext();
nativeCleanWidgets();
if (!sWasCopyrightDisplayed)
{
nativeSetupWidget(WIDGET_COPYRIGHT,
UiUtils.dimen(context, R.dimen.margin_ruler_left),
mHeight - UiUtils.dimen(context, R.dimen.margin_ruler_bottom),
ANCHOR_LEFT_BOTTOM);
sWasCopyrightDisplayed = true;
}
setupWidgetOffsets();
setupBottomWidgetsOffset(0);
nativeSetupWidget(WIDGET_SCALE_FPS_LABEL,
UiUtils.dimen(context, R.dimen.margin_base),
@ -100,16 +88,6 @@ public class MapFragment extends BaseMwmFragment
setupCompass(UiUtils.getCompassYOffset(requireContext()), false);
}
private void setupWidgetOffsets()
{
int rulerOffset = 0;
if (mWidgetOffsetsProvider != null)
{
rulerOffset = mWidgetOffsetsProvider.getRulerOffsetY();
}
setupRuler(rulerOffset, false);
}
void setupCompass(int offsetY, boolean forceRedraw)
{
Context context = requireContext();
@ -124,12 +102,29 @@ public class MapFragment extends BaseMwmFragment
nativeApplyWidgets();
}
void setupBottomWidgetsOffset(int offset)
{
setupRuler(offset, true);
setupAttribution(offset, true);
}
void setupRuler(int offsetY, boolean forceRedraw)
{
Context context = requireContext();
nativeSetupWidget(WIDGET_RULER,
UiUtils.dimen(context, R.dimen.margin_ruler_left),
mHeight - UiUtils.dimen(context, R.dimen.margin_ruler_bottom) + offsetY,
UiUtils.dimen(context, R.dimen.margin_ruler),
mHeight - UiUtils.dimen(context, R.dimen.margin_ruler) - offsetY,
ANCHOR_LEFT_BOTTOM);
if (forceRedraw && mSurfaceCreated)
nativeApplyWidgets();
}
void setupAttribution(int offsetY, boolean forceRedraw)
{
Context context = requireContext();
nativeSetupWidget(WIDGET_COPYRIGHT,
UiUtils.dimen(context, R.dimen.margin_ruler),
mHeight - UiUtils.dimen(context, R.dimen.margin_ruler) - offsetY,
ANCHOR_LEFT_BOTTOM);
if (forceRedraw && mSurfaceCreated)
nativeApplyWidgets();
@ -257,7 +252,6 @@ public class MapFragment extends BaseMwmFragment
{
super.onAttach(context);
mMapRenderingListener = (MapRenderingListener) context;
mWidgetOffsetsProvider = (MapWidgetOffsetsProvider) context;
}
@Override
@ -265,7 +259,6 @@ public class MapFragment extends BaseMwmFragment
{
super.onDetach();
mMapRenderingListener = null;
mWidgetOffsetsProvider = null;
}
@Override

View file

@ -1,7 +0,0 @@
package com.mapswithme.maps;
interface MapWidgetOffsetsProvider
{
int getRulerOffsetY();
int getWaterMarkOffsetY();
}

View file

@ -9,6 +9,7 @@ import android.content.Intent;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MotionEvent;
@ -87,7 +88,6 @@ import com.mapswithme.maps.widget.placepage.PlacePageFactory;
import com.mapswithme.maps.widget.placepage.RoutingModeListener;
import com.mapswithme.util.Config;
import com.mapswithme.util.Counters;
import com.mapswithme.util.InputUtils;
import com.mapswithme.util.PermissionsUtils;
import com.mapswithme.util.SharingUtils;
import com.mapswithme.util.ThemeSwitcher;
@ -108,7 +108,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
CustomNavigateUpListener,
RoutingController.Container,
LocationHelper.UiCallback,
FloatingSearchToolbarController.VisibilityListener,
RoutingPlanInplaceController.RoutingPlanListener,
RoutingBottomMenuListener,
BookmarkManager.BookmarksLoadingListener,
@ -116,8 +115,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
PlacePageController.SlideListener,
AlertDialogCallback, RoutingModeListener,
AppBackgroundTracker.OnTransitionListener,
NoConnectionListener,
MapWidgetOffsetsProvider
NoConnectionListener
{
public static final String EXTRA_TASK = "map_task";
public static final String EXTRA_LAUNCH_BY_DEEP_LINK = "launch_by_deep_link";
@ -397,7 +395,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
mSearchController.getToolbar()
.getViewTreeObserver()
.addOnGlobalLayoutListener(new ToolbarLayoutChangeListener());
mSearchController.setVisibilityListener(this);
initBottomSheets();
@ -432,6 +429,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private ArrayList<MenuBottomSheetItem> getMainMenuItems()
{
ArrayList<MenuBottomSheetItem> items = new ArrayList<>();
items.add(new MenuBottomSheetItem(R.string.help, R.drawable.ic_question_mark, this::showHelp));
items.add(new MenuBottomSheetItem(R.string.placepage_add_place_button, R.drawable.ic_plus, this::onAddPlaceOptionSelected));
items.add(new MenuBottomSheetItem(
R.string.download_maps,
@ -608,7 +606,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
final View frame = findViewById(R.id.navigation_buttons);
mMapButtonsController = new MapButtonsController(frame, this, this::onMapButtonClick, mPlacePageController);
mMapButtonsController = new MapButtonsController(frame,
this,
this::onMapButtonClick,
(v) -> closeSearchToolbar(true, true),
mPlacePageController);
// FIXME For some reason the first onResume does not make the badge appear
new Handler().postDelayed(() -> mMapButtonsController.updateMarker(this), 100);
}
void onMapButtonClick(MapButtonsController.MapButtons button)
@ -638,6 +642,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
case navSearch:
showSearch();
break;
case menu:
closeFloatingPanels();
showMainMenuBottomSheet();
break;
}
}
@ -743,7 +751,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (stopSearch)
{
mSearchController.cancelSearchApiAndHide(clearText);
mMapButtonsController.resetNavSearch();
mMapButtonsController.resetSearch();
}
else
{
@ -792,7 +800,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void initMainMenu()
{
mMainMenu = new MainMenu(findViewById(R.id.menu_frame), this::onMenuItemClick);
mMainMenu = new MainMenu(findViewById(R.id.menu_frame), this::adjustBottomWidgets);
if (mIsTabletLayout)
{
@ -800,28 +808,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
}
private void onMenuItemClick(@NonNull MainMenu.Item item)
{
switch (item)
{
case HELP:
showHelp();
break;
case SEARCH:
RoutingController.get().cancel();
closeFloatingPanels();
showSearch(mSearchController.getQuery());
break;
case BOOKMARKS:
showBookmarks();
break;
case MENU:
closeFloatingPanels();
showMainMenuBottomSheet();
break;
}
}
private void initOnmapDownloader()
{
mOnmapDownloader = new OnmapDownloader(this);
@ -1023,7 +1009,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
super.onResume();
refreshSearchToolbar();
mMainMenu.onResume();
if (Framework.nativeIsInChoosePositionMode())
{
UiUtils.show(mPointChooser);
@ -1033,7 +1018,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
mOnmapDownloader.onResume();
mNavigationController.onActivityResumed(this);
mMapButtonsController.onResume();
mMapButtonsController.onResume(this);
mPlacePageController.onActivityResumed(this);
}
@ -1210,8 +1195,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
return;
mIsFullscreen = isFullscreen;
showMainMenu(!isFullscreen);
mMapButtonsController.showMapButtons(!isFullscreen);
}
@ -1232,7 +1215,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
if (removeCurrentFragment(true))
{
InputUtils.hideKeyboard(mMainMenu.getFrame());
refreshSearchToolbar();
}
}
@ -1249,30 +1231,12 @@ public class MwmActivity extends BaseMwmFragmentActivity
MapFragment.nativeCompassUpdated(compass.getNorth(), true);
}
private void adjustBottomWidgets(int offsetY)
public void adjustBottomWidgets(int offsetY)
{
if (mMapFragment == null || !mMapFragment.isAdded())
return;
mMapFragment.setupRuler(offsetY, false);
}
@Override
public int getRulerOffsetY()
{
return getBottomMapWidgetOffsetY();
}
private int getBottomMapWidgetOffsetY()
{
View menuView = mMainMenu.getFrame();
return UiUtils.isVisible(menuView) ? 0 : menuView.getHeight();
}
@Override
public int getWaterMarkOffsetY()
{
return getBottomMapWidgetOffsetY();
mMapFragment.setupBottomWidgetsOffset(offsetY);
}
@Override
@ -1294,10 +1258,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (!isVisible)
return;
mMapButtonsController.showButton(RoutingController.get().isPlanning()
|| RoutingController.get().isBuilt(),
MapButtonsController.MapButtons.nav);
if (RoutingController.get().isNavigating())
{
mNavigationController.show(true);
@ -1423,7 +1383,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void showMainMenu(boolean show)
{
mMainMenu.show(show);
adjustBottomWidgets(show ? 0 : getBottomMapWidgetOffsetY());
}
@Override
@ -1495,14 +1454,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
});
}
@Override
public void onSearchVisibilityChanged(boolean visible)
{
boolean show = visible && !TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery())
&& !RoutingController.get().isNavigating();
mMainMenu.show(!show);
}
private int calcFloatingViewsOffset()
{
int offset;

View file

@ -1,21 +1,29 @@
package com.mapswithme.maps.maplayer;
import android.app.Activity;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.OptIn;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.badge.BadgeDrawable;
import com.google.android.material.badge.BadgeUtils;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.mapswithme.maps.R;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.downloader.UpdateInfo;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.routing.SearchWheel;
import com.mapswithme.maps.widget.menu.MyPositionButton;
import com.mapswithme.maps.widget.placepage.PlacePageController;
import com.mapswithme.util.Config;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.log.Logger;
public class MapButtonsController
{
@ -28,6 +36,8 @@ public class MapButtonsController
@NonNull
private final View myPosition;
@NonNull
private final View mMenuButton;
@NonNull
private final View mSearchButtonFrame;
@Nullable
private final MyPositionButton mNavMyPosition;
@ -35,6 +45,9 @@ public class MapButtonsController
private final MapLayersController mToggleMapLayerController;
@NonNull
private final SearchWheel mSearchWheel;
@NonNull
private BadgeDrawable mBadgeDrawable;
private final PlacePageController mPlacePageController;
private final float mBottomMargin;
private final float mButtonWidth;
@ -42,7 +55,7 @@ public class MapButtonsController
private float mContentHeight;
private float mContentWidth;
public MapButtonsController(@NonNull View frame, AppCompatActivity activity, MapButtonClickListener mapButtonClickListener, PlacePageController placePageController)
public MapButtonsController(@NonNull View frame, AppCompatActivity activity, MapButtonClickListener mapButtonClickListener, @NonNull View.OnClickListener onSearchCanceledListener, PlacePageController placePageController)
{
mButtonsFrame = frame.findViewById(R.id.navigation_buttons_inner);
mZoomFrame = frame.findViewById(R.id.zoom_buttons_container);
@ -51,6 +64,8 @@ public class MapButtonsController
.setOnClickListener((v) -> mapButtonClickListener.onClick(MapButtons.zoomIn));
frame.findViewById(R.id.nav_zoom_out)
.setOnClickListener((v) -> mapButtonClickListener.onClick(MapButtons.zoomOut));
mMenuButton = frame.findViewById(R.id.menu_button);
mMenuButton.setOnClickListener((v) -> mapButtonClickListener.onClick(MapButtons.menu));
myPosition = frame.findViewById(R.id.my_position);
mNavMyPosition = new MyPositionButton(myPosition, (v) -> mapButtonClickListener.onClick(MapButtons.myPosition));
@ -58,8 +73,8 @@ public class MapButtonsController
mToggleMapLayerController = new MapLayersController(mLayersButton,
() -> mapButtonClickListener.onClick(MapButtons.toggleMapLayer), activity);
mSearchButtonFrame = activity.findViewById(R.id.search_button_frame);
mSearchWheel = new SearchWheel(frame, (v) -> mapButtonClickListener.onClick(MapButtons.navSearch));
mSearchButtonFrame = frame.findViewById(R.id.search_button_frame);
mSearchWheel = new SearchWheel(frame, (v) -> mapButtonClickListener.onClick(MapButtons.navSearch), onSearchCanceledListener);
mSearchButtonFrame.findViewById(R.id.btn_bookmarks)
.setOnClickListener((v) -> mapButtonClickListener.onClick(MapButtons.navBookmarks));
@ -89,11 +104,26 @@ public class MapButtonsController
mNavMyPosition.showButton(show);
break;
case nav:
UiUtils.showIf(show && isInNavigationMode(),
mSearchButtonFrame);
UiUtils.showIf(show, mSearchButtonFrame);
case menu:
UiUtils.showIf(show, mMenuButton);
}
}
@OptIn(markerClass = com.google.android.material.badge.ExperimentalBadgeUtils.class)
public void updateMarker(@NonNull Activity activity)
{
final UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
final int count = (info == null ? 0 : info.filesCount);
BadgeUtils.detachBadgeDrawable(mBadgeDrawable, mMenuButton);
mBadgeDrawable = BadgeDrawable.create(activity);
mBadgeDrawable.setHorizontalOffset(30);
mBadgeDrawable.setVerticalOffset(20);
mBadgeDrawable.setNumber(count);
mBadgeDrawable.setVisible(count > 0);
BadgeUtils.attachBadgeDrawable(mBadgeDrawable, mMenuButton);
}
private boolean isScreenWideEnough()
{
return mContentWidth > (mPlacePageController.getPlacePageWidth() + 2 * mButtonWidth);
@ -123,6 +153,7 @@ public class MapButtonsController
showButton(getViewTopOffset(translation, mSearchButtonFrame) > 0, MapButtons.nav);
showButton(getViewTopOffset(translation, mLayersButton) > 0, MapButtons.toggleMapLayer);
showButton(getViewTopOffset(translation, myPosition) > 0, MapButtons.myPosition);
showButton(getViewTopOffset(translation, mMenuButton) > 0, MapButtons.menu);
}
public void setTopLimit(float limit)
@ -163,13 +194,14 @@ public class MapButtonsController
return (int) (translation + v.getTop() - mTopLimit);
}
public void onResume()
public void onResume(@NonNull Activity activity)
{
showButton(true, MapButtons.zoom);
mSearchWheel.onResume();
updateMarker(activity);
}
public void resetNavSearch()
public void resetSearch()
{
mSearchWheel.reset();
}
@ -193,7 +225,8 @@ public class MapButtonsController
zoom,
nav,
navSearch,
navBookmarks
navBookmarks,
menu
}
public interface MapButtonClickListener

View file

@ -110,7 +110,7 @@ public class NavigationController implements Application.ActivityLifecycleCallba
public void stop(MwmActivity parent)
{
mMapButtonsController.resetNavSearch();
mMapButtonsController.resetSearch();
if (mBound)
{
@ -222,7 +222,6 @@ public class NavigationController implements Application.ActivityLifecycleCallba
else if (!show && UiUtils.isVisible(mFrame))
mNavMenu.hideNavBottomSheet();
UiUtils.showIf(show, mFrame);
mMapButtonsController.showButton(show, MapButtonsController.MapButtons.nav);
}
public boolean isNavMenuCollapsed()

View file

@ -36,7 +36,9 @@ public class SearchWheel implements View.OnClickListener
@Nullable
private SearchOption mCurrentOption;
@NonNull
private View.OnClickListener mOnSearchPressedListener;
private final View.OnClickListener mOnSearchPressedListener;
@NonNull
private final View.OnClickListener mOnSearchCanceledListener;
private static final long CLOSE_DELAY_MILLIS = 5000L;
private final Runnable mCloseRunnable = new Runnable() {
@ -102,10 +104,11 @@ public class SearchWheel implements View.OnClickListener
}
}
public SearchWheel(View frame, View.OnClickListener onSearchPressedListener)
public SearchWheel(View frame, @NonNull View.OnClickListener onSearchPressedListener, @NonNull View.OnClickListener onSearchCanceledListener)
{
mFrame = frame;
mOnSearchPressedListener = onSearchPressedListener;
mOnSearchCanceledListener = onSearchCanceledListener;
mTouchInterceptor = mFrame.findViewById(R.id.touch_interceptor);
mTouchInterceptor.setOnClickListener(this);
mSearchButton = mFrame.findViewById(R.id.btn_search);
@ -137,7 +140,6 @@ public class SearchWheel implements View.OnClickListener
{
mIsExpanded = false;
mCurrentOption = null;
SearchEngine.INSTANCE.cancelInteractiveSearch();
resetSearchButtonImage();
}
@ -222,18 +224,18 @@ public class SearchWheel implements View.OnClickListener
switch (v.getId())
{
case R.id.btn_search:
if (RoutingController.get().isPlanning())
if (!RoutingController.get().isNavigating())
{
if (TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery()))
showSearchInParent();
else
reset();
mOnSearchCanceledListener.onClick(v);
return;
}
if (mCurrentOption != null || !TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery()))
{
reset();
mOnSearchCanceledListener.onClick(v);
refreshSearchVisibility();
return;
}

View file

@ -2,78 +2,25 @@ package com.mapswithme.maps.widget.menu;
import android.view.View;
import com.mapswithme.maps.R;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.downloader.UpdateInfo;
import com.mapswithme.util.UiUtils;
public class MainMenu
{
private final View mFrame;
private final View mButtonsFrame;
private final View mRoutePlanFrame;
private final View mNewsMarker;
private final ItemClickListener mItemClickListener;
private final OnMenuSizeChangeListener mOnMenuSizeChangeListener;
private int mMenuHeight;
public MainMenu(View frame, ItemClickListener itemClickListener)
public MainMenu(View frame, OnMenuSizeChangeListener onMenuSizeChangeListener)
{
mFrame = frame;
mItemClickListener = itemClickListener;
mButtonsFrame = mFrame.findViewById(R.id.buttons_frame);
mRoutePlanFrame = mFrame.findViewById(R.id.routing_plan_frame);
mNewsMarker = mButtonsFrame.findViewById(R.id.marker);
init();
}
void mapItem(Item item, int viewId)
{
View res = mButtonsFrame.findViewById(viewId);
if (res != null)
res.setOnClickListener(v -> mItemClickListener.onItemClick(item));
}
public void onResume()
{
updateMarker();
}
public void updateMarker()
{
final UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
final int count = (info == null ? 0 : info.filesCount);
final boolean show = count > 0;
UiUtils.showIf(show, mNewsMarker);
}
private void init()
{
mapItem(Item.HELP, R.id.help);
mapItem(Item.SEARCH, R.id.search);
mapItem(Item.BOOKMARKS, R.id.bookmarks);
mapItem(Item.MENU, R.id.toggle);
mOnMenuSizeChangeListener = onMenuSizeChangeListener;
mFrame.addOnLayoutChangeListener(new MainMenu.FrameLayoutChangeListener());
setState(State.MENU, false);
}
public void setState(State state, boolean isFullScreen)
{
if (state != State.NAVIGATION)
{
boolean isRouting = state == State.ROUTE_PREPARE;
if (mRoutePlanFrame == null)
UiUtils.show(mButtonsFrame);
else
{
UiUtils.showIf(state == State.MENU, mButtonsFrame);
UiUtils.showIf(isRouting, mRoutePlanFrame);
}
}
show(state != State.NAVIGATION && !isFullScreen);
UiUtils.showIf(state == State.MENU, mButtonsFrame);
UiUtils.showIf(state == State.ROUTE_PREPARE, mRoutePlanFrame);
show(state == State.ROUTE_PREPARE && !isFullScreen);
}
public void show(boolean show)
@ -82,6 +29,12 @@ public class MainMenu
return;
UiUtils.showIf(show, mFrame);
notifyHeight();
}
private void notifyHeight()
{
mOnMenuSizeChangeListener.OnMenuSizeChange(UiUtils.isVisible(mFrame) ? mMenuHeight : 0);
}
public View getFrame()
@ -104,8 +57,19 @@ public class MainMenu
BOOKMARKS
}
public interface ItemClickListener
public interface OnMenuSizeChangeListener
{
void onItemClick(Item item);
void OnMenuSizeChange(int newHeight);
}
private class FrameLayoutChangeListener implements View.OnLayoutChangeListener
{
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
int oldTop, int oldRight, int oldBottom)
{
mMenuHeight = bottom - top;
notifyHeight();
}
}
}