From 2316cd8ae1c4a57214dd74f445c22e0b3bfad9bc Mon Sep 17 00:00:00 2001 From: crimean Date: Sat, 23 Mar 2019 18:17:22 +0300 Subject: [PATCH] Fix landscape mode for route details --- OsmAnd/res/layout/route_info_layout.xml | 1 - .../osmand/plus/activities/MapActivity.java | 22 ++++++++--- .../osmand/plus/base/ContextMenuFragment.java | 38 ++++++++----------- .../ChooseRouteFragment.java | 26 ++++++++++--- .../MapRouteInfoMenu.java | 5 +++ .../RouteDetailsFragment.java | 5 +++ .../osmand/plus/views/MapControlsLayer.java | 2 +- .../plus/views/MapQuickActionLayer.java | 4 ++ 8 files changed, 67 insertions(+), 36 deletions(-) diff --git a/OsmAnd/res/layout/route_info_layout.xml b/OsmAnd/res/layout/route_info_layout.xml index 121013f7a5..7c41af6dae 100644 --- a/OsmAnd/res/layout/route_info_layout.xml +++ b/OsmAnd/res/layout/route_info_layout.xml @@ -1,6 +1,5 @@ diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 83b30dbfd3..125ecc3fde 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -106,6 +106,7 @@ import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; +import net.osmand.plus.routepreparationmenu.ChooseRouteFragment; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenuFragment; import net.osmand.plus.routing.IRouteInformationListener; @@ -592,14 +593,21 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return; } } - if (getPlanRouteFragment() != null) { - if (getPlanRouteFragment().quit(true)) { + PlanRouteFragment planRouteFragment = getPlanRouteFragment(); + if (planRouteFragment != null) { + if (planRouteFragment.quit(true)) { MapMarkersDialogFragment.showInstance(this); } return; } - if (getMeasurementToolFragment() != null) { - getMeasurementToolFragment().quit(true); + MeasurementToolFragment measurementToolFragment = getMeasurementToolFragment(); + if (measurementToolFragment != null) { + measurementToolFragment.quit(true); + return; + } + ChooseRouteFragment chooseRouteFragment = getChooseRouteFragment(); + if (chooseRouteFragment != null) { + chooseRouteFragment.dismiss(); return; } if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) { @@ -629,7 +637,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return; super.onBackPressed(); - } private void quitAddGpxPointMode() { @@ -2007,6 +2014,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (MeasurementToolFragment) fragment : null; } + public ChooseRouteFragment getChooseRouteFragment() { + Fragment fragment = getSupportFragmentManager().findFragmentByTag(ChooseRouteFragment.TAG); + return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (ChooseRouteFragment) fragment : null; + } + public boolean isTopToolbarActive() { MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer(); return mapInfoLayer.hasTopToolbar(); diff --git a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java index d45e559bba..0b833c89ed 100644 --- a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java @@ -17,7 +17,6 @@ import android.support.v7.view.ContextThemeWrapper; import android.text.ClipboardManager; import android.util.TypedValue; import android.view.GestureDetector; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.VelocityTracker; @@ -74,6 +73,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { private int minHalfY; private int topScreenPosY; + private int topPadding; private int menuFullHeightMax; private int menuBottomViewHeight; private int menuFullHeight; @@ -82,7 +82,6 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { private int topShadowMargin; private int currentMenuState; private int shadowHeight; - private int toolbarHeight; private int statusBarHeight; private String preferredMapLang; @@ -107,6 +106,8 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { public abstract int getHeaderViewHeight(); + public abstract int getToolbarHeight(); + public boolean isSingleFragment() { return true; } @@ -192,31 +193,26 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { shadowHeight = AndroidUtils.dpToPx(mapActivity, SHADOW_HEIGHT_TOP_DP); topScreenPosY = addStatusBarHeightIfNeeded(-shadowHeight); - toolbarHeight = app.getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar); - mainView = view.findViewById(getMainViewId()); nightMode = app.getDaynightHelper().isNightModeForMapControls(); - processScreenHeight(container); - - minHalfY = viewHeight - (int) (viewHeight * .75f); - LockableScrollView bottomScrollView = (LockableScrollView) view.findViewById(getBottomScrollViewId()); bottomScrollView.setScrollingEnabled(false); AndroidUtils.setBackground(app, bottomScrollView, nightMode, R.color.route_info_bg_light, R.color.route_info_bg_dark); - AndroidUtils.setBackground(app, mainView, nightMode, R.drawable.bg_map_context_menu_light, R.drawable.bg_map_context_menu_dark); if (!portrait) { + topPadding = getToolbarHeight() - topScreenPosY; + bottomScrollView.setPadding(0, topPadding, 0, 0); final TypedValue typedValueAttr = new TypedValue(); mapActivity.getTheme().resolveAttribute(R.attr.left_menu_view_bg, typedValueAttr, true); mainView.setBackgroundResource(typedValueAttr.resourceId); mainView.setLayoutParams(new FrameLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.dashboard_land_width), ViewGroup.LayoutParams.MATCH_PARENT)); - - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(AndroidUtils.dpToPx(mapActivity, 345f), ViewGroup.LayoutParams.WRAP_CONTENT); - params.gravity = Gravity.BOTTOM; } + processScreenHeight(container); + minHalfY = viewHeight - (int) (viewHeight * .75f); + final GestureDetector swipeDetector = new GestureDetector(app, new HorizontalSwipeConfirm(true)); final OnTouchListener slideTouchListener = new OnTouchListener() { @@ -293,16 +289,14 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { if (moving) { moving = false; int currentY = getViewY(); - + int fullScreenTopPosY = getMenuStatePosY(MenuState.FULL_SCREEN); final VelocityTracker velocityTracker = this.velocityTracker; velocityTracker.computeCurrentVelocity(1000, maximumVelocity); int initialVelocity = (int) velocityTracker.getYVelocity(); - - if ((Math.abs(initialVelocity) > minimumVelocity)) { - + if ((Math.abs(initialVelocity) > minimumVelocity) && currentY != fullScreenTopPosY) { scroller.abortAnimation(); scroller.fling(0, currentY, 0, initialVelocity, 0, 0, - Math.min(viewHeight - menuFullHeightMax, getFullScreenTopPosY()), + Math.min(viewHeight - menuFullHeightMax, fullScreenTopPosY), screenHeight, 0, 0); currentY = scroller.getFinalY(); @@ -480,7 +474,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { screenHeight = container.getHeight() + statusBarHeight; - viewHeight = screenHeight - statusBarHeight; + viewHeight = screenHeight - statusBarHeight - topPadding; minHalfY = viewHeight - (int) (viewHeight * .75f); } } @@ -488,7 +482,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { private int getFullScreenTopPosY() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - int res = topShadowMargin + toolbarHeight; + int res = topShadowMargin + getToolbarHeight(); if (Build.VERSION.SDK_INT >= 21 && !isSingleFragment()) { res -= statusBarHeight; } @@ -833,15 +827,13 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy(); int tileBoxWidthPx = 0; int tileBoxHeightPx = 0; - - boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); if (!portrait) { tileBoxWidthPx = tb.getPixWidth() - view.getWidth(); } else { tileBoxHeightPx = getHeaderOnlyTopY(); } - if (tileBoxHeightPx > 0) { - int topMarginPx = toolbarHeight; + if (tileBoxHeightPx > 0 || tileBoxWidthPx > 0) { + int topMarginPx = getToolbarHeight(); mapActivity.getMapView().fitRectToMap(rect.left, rect.right, rect.top, rect.bottom, tileBoxWidthPx, tileBoxHeightPx, topMarginPx); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index 4436f20e28..14276b1f41 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -21,6 +21,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.ImageButton; import net.osmand.AndroidUtils; @@ -109,10 +110,16 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); View view = LayoutInflater.from(context).inflate(R.layout.fragment_show_all_routes, null); AndroidUtils.addStatusBarPadding21v(mapActivity, view); - solidToolbarView = view.findViewById(R.id.toolbar_layout); + View solidToolbarView = view.findViewById(R.id.toolbar_layout); + this.solidToolbarView = solidToolbarView; solidToolbarHeight = getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar); LockableViewPager viewPager = view.findViewById(R.id.pager); this.viewPager = viewPager; + if (!portrait) { + initialMenuState = MenuState.FULL_SCREEN; + solidToolbarView.setLayoutParams(new FrameLayout.LayoutParams(AndroidUtils.dpToPx(mapActivity, 345f), ViewGroup.LayoutParams.WRAP_CONTENT)); + view.setLayoutParams(new FrameLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.dashboard_land_width), ViewGroup.LayoutParams.MATCH_PARENT)); + } viewPager.setClipToPadding(false); //viewPager.setPageMargin(-60); final RoutesPagerAdapter pagerAdapter = new RoutesPagerAdapter(getChildFragmentManager(), publicTransportMode ? routes.size() : 1, initialMenuState); @@ -168,7 +175,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe if (!wasDrawerDisabled) { mapActivity.disableDrawer(); } - updateControlsVisibility(false); + updateControlsVisibility(false, false); } } @@ -180,7 +187,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe if (!wasDrawerDisabled) { mapActivity.enableDrawer(); } - updateControlsVisibility(true); + updateControlsVisibility(true, routeInfoMenuState != -1); } } @@ -213,7 +220,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color); } - private void dismiss() { + public void dismiss() { try { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { @@ -422,6 +429,8 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe if (publicTransportMode) { view.findViewById(R.id.toolbar_options).setVisibility(View.GONE); + } + if (publicTransportMode || !portrait) { view.findViewById(R.id.toolbar_options_flow).setVisibility(View.GONE); view.findViewById(R.id.toolbar_options_flow_bg).setVisibility(View.GONE); } @@ -622,13 +631,18 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe } } - public void updateControlsVisibility(boolean visible) { + public void updateControlsVisibility(boolean visible, boolean openingRouteInfo) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { int visibility = visible ? View.VISIBLE : View.GONE; mapActivity.findViewById(R.id.map_center_info).setVisibility(visibility); mapActivity.findViewById(R.id.map_left_widgets_panel).setVisibility(visibility); - mapActivity.findViewById(R.id.map_right_widgets_panel).setVisibility(visibility); + if (!openingRouteInfo) { + mapActivity.findViewById(R.id.map_right_widgets_panel).setVisibility(visibility); + if (!portrait) { + mapActivity.getMapView().setMapPositionX(visible ? 0 : 1); + } + } mapActivity.findViewById(R.id.bottom_controls_container).setVisibility(visibility); mapActivity.refreshMap(); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 226689ce29..a811ccb9fd 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -1902,6 +1902,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener boolean refreshMap = !switched; boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); if (!portrait) { + currentMenuState = MenuState.FULL_SCREEN; mapActivity.getMapView().setMapPositionX(1); refreshMap = true; } @@ -1934,6 +1935,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener removeTargetPointListener(); } + public boolean needShowMenu() { + return showMenu; + } + public void setShowMenu(int menuState) { showMenu = true; showMenuState = menuState; diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java index babb4d75b9..7d6338fbca 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java @@ -125,6 +125,11 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT return !menuCards.isEmpty() ? menuCards.get(0).getViewHeight() : 0; } + @Override + public int getToolbarHeight() { + return getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar); + } + @Override public boolean isSingleFragment() { return false; diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index e536fcd56e..80748f800c 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -747,11 +747,11 @@ public class MapControlsLayer extends OsmandMapLayer { routePlanningMode = true; } boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode(); - boolean routeDialogOpened = mapRouteInfoMenu.isVisible(); boolean trackDialogOpened = TrackDetailsMenu.isVisible(); boolean contextMenuOpened = !mapActivity.getContextMenu().shouldShowTopControls(); boolean showRouteCalculationControls = routePlanningMode || ((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode); + boolean routeDialogOpened = mapRouteInfoMenu.isVisible() || (showRouteCalculationControls && mapRouteInfoMenu.needShowMenu()); updateMyLocation(rh, routeDialogOpened || trackDialogOpened || contextMenuOpened); boolean showButtons = (showRouteCalculationControls || !routeFollowingMode) && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened && !isInChoosingRoutesMode(); diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index 5e28f1d5b9..4aa003cac7 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -40,6 +40,7 @@ import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickActionFactory; import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionsWidget; +import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -388,6 +389,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe private void setupQuickActionBtnVisibility() { MapContextMenu contextMenu = mapActivity.getContextMenu(); + MapRouteInfoMenu mapRouteInfoMenu = mapActivity.getMapRouteInfoMenu(); MapMultiSelectionMenu multiSelectionMenu = contextMenu.getMultiSelectionMenu(); WeakReference contextMenuMenuFragmentRef = contextMenu.findMenuFragment(); MapContextMenuFragment contextMenuMenuFragment = contextMenuMenuFragmentRef != null ? contextMenuMenuFragmentRef.get() : null; @@ -397,6 +399,8 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe contextMenuLayer.isInGpxDetailsMode() || measurementToolLayer.isInMeasurementMode() || mapMarkersLayer.isInPlanRouteMode() || + mapRouteInfoMenu.isVisible() || + MapRouteInfoMenu.chooseRoutesVisible || contextMenu.isVisible() && contextMenuMenuFragment != null && !contextMenuMenuFragment.isRemoving() || contextMenu.isVisible() && contextMenuMenuFragment != null && contextMenuMenuFragment.isAdded() || multiSelectionMenu.isVisible() && multiMenuFragment != null && multiMenuFragment.isAdded() ||