diff --git a/android/res/drawable/ic_menu_bookmarks.xml b/android/res/drawable/ic_menu_bookmarks.xml deleted file mode 100644 index 14e3bdb725..0000000000 --- a/android/res/drawable/ic_menu_bookmarks.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/android/res/drawable/ic_menu_search.xml b/android/res/drawable/ic_menu_search.xml deleted file mode 100644 index b0504a6f7a..0000000000 --- a/android/res/drawable/ic_menu_search.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/android/res/drawable/ic_menu_share.xml b/android/res/drawable/ic_menu_share.xml deleted file mode 100644 index 5c36e6ea4d..0000000000 --- a/android/res/drawable/ic_menu_share.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/android/res/layout-land/map_navigation_buttons.xml b/android/res/layout-land/map_navigation_buttons.xml index f39dbb27cc..981fc2b1d6 100644 --- a/android/res/layout-land/map_navigation_buttons.xml +++ b/android/res/layout-land/map_navigation_buttons.xml @@ -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" /> + diff --git a/android/res/layout/map_navigation_buttons.xml b/android/res/layout/map_navigation_buttons.xml index 944c89a5b9..fdf4ccf8bc 100644 --- a/android/res/layout/map_navigation_buttons.xml +++ b/android/res/layout/map_navigation_buttons.xml @@ -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" /> + diff --git a/android/res/layout/menu.xml b/android/res/layout/menu.xml index b2d745e286..1c23173cd1 100644 --- a/android/res/layout/menu.xml +++ b/android/res/layout/menu.xml @@ -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"> - - diff --git a/android/res/layout/menu_buttons_line.xml b/android/res/layout/menu_buttons_line.xml deleted file mode 100644 index b26aec09c0..0000000000 --- a/android/res/layout/menu_buttons_line.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/android/res/values/dimens.xml b/android/res/values/dimens.xml index 32764bdb35..3b42e73549 100644 --- a/android/res/values/dimens.xml +++ b/android/res/values/dimens.xml @@ -75,8 +75,7 @@ 32dp 26dp - 10dp - 58dp + 10dp 40dp 20dp 2dp diff --git a/android/src/com/mapswithme/maps/MapFragment.java b/android/src/com/mapswithme/maps/MapFragment.java index cdb82b005a..1bd5235ea3 100644 --- a/android/src/com/mapswithme/maps/MapFragment.java +++ b/android/src/com/mapswithme/maps/MapFragment.java @@ -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 diff --git a/android/src/com/mapswithme/maps/MapWidgetOffsetsProvider.java b/android/src/com/mapswithme/maps/MapWidgetOffsetsProvider.java deleted file mode 100644 index 35d42a055d..0000000000 --- a/android/src/com/mapswithme/maps/MapWidgetOffsetsProvider.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.mapswithme.maps; - -interface MapWidgetOffsetsProvider -{ - int getRulerOffsetY(); - int getWaterMarkOffsetY(); -} diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index f963b28520..8a5cf5841a 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -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 getMainMenuItems() { ArrayList 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; diff --git a/android/src/com/mapswithme/maps/maplayer/MapButtonsController.java b/android/src/com/mapswithme/maps/maplayer/MapButtonsController.java index ab36314af2..514d7c09cd 100644 --- a/android/src/com/mapswithme/maps/maplayer/MapButtonsController.java +++ b/android/src/com/mapswithme/maps/maplayer/MapButtonsController.java @@ -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 diff --git a/android/src/com/mapswithme/maps/routing/NavigationController.java b/android/src/com/mapswithme/maps/routing/NavigationController.java index 7dd32e7eec..e9a7ededef 100644 --- a/android/src/com/mapswithme/maps/routing/NavigationController.java +++ b/android/src/com/mapswithme/maps/routing/NavigationController.java @@ -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() diff --git a/android/src/com/mapswithme/maps/routing/SearchWheel.java b/android/src/com/mapswithme/maps/routing/SearchWheel.java index 0cd697a75a..30a9deaf89 100644 --- a/android/src/com/mapswithme/maps/routing/SearchWheel.java +++ b/android/src/com/mapswithme/maps/routing/SearchWheel.java @@ -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; } diff --git a/android/src/com/mapswithme/maps/widget/menu/MainMenu.java b/android/src/com/mapswithme/maps/widget/menu/MainMenu.java index 51cc75b2ce..819b0c2cb2 100644 --- a/android/src/com/mapswithme/maps/widget/menu/MainMenu.java +++ b/android/src/com/mapswithme/maps/widget/menu/MainMenu.java @@ -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(); + } } }