From aa1e2f8738186608f91cc6eb6fb2cbe400692eae Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 19 Nov 2018 17:36:48 +0200 Subject: [PATCH] Add adjustMapPosition and remove toolbar --- OsmAnd/res/layout/plan_route_info.xml | 46 ----- .../MapRouteInfoMenu.java | 5 +- .../MapRouteInfoMenuFragment.java | 167 ++++++++---------- 3 files changed, 79 insertions(+), 139 deletions(-) diff --git a/OsmAnd/res/layout/plan_route_info.xml b/OsmAnd/res/layout/plan_route_info.xml index 1718487384..28d12fb050 100644 --- a/OsmAnd/res/layout/plan_route_info.xml +++ b/OsmAnd/res/layout/plan_route_info.xml @@ -523,52 +523,6 @@ - - - - - - - - - - - - 0 && slidingUp) { while (menu.getCurrentMenuState() != newState) { @@ -444,7 +434,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { } } } else if (slidingDown) { - if (currentMenuState == MenuController.MenuState.HEADER_ONLY) { + if (currentMenuState == MapRouteInfoMenu.MenuState.HEADER_ONLY) { needCloseMenu = true; } else { while (menu.getCurrentMenuState() != newState) { @@ -471,7 +461,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { } } int newMenuState = menu.getCurrentMenuState(); - boolean needMapAdjust = currentMenuState != newMenuState && newMenuState != MenuController.MenuState.FULL_SCREEN; + boolean needMapAdjust = currentMenuState != newMenuState && newMenuState != MapRouteInfoMenu.MenuState.FULL_SCREEN; applyPosY(currentY, needCloseMenu, needMapAdjust, currentMenuState, newMenuState, 0); } @@ -487,20 +477,20 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { int posY = 0; switch (destinationState) { - case MenuController.MenuState.HEADER_ONLY: - posY = getMenuStatePosY(MenuController.MenuState.HEADER_ONLY); + case MapRouteInfoMenu.MenuState.HEADER_ONLY: + posY = getMenuStatePosY(MapRouteInfoMenu.MenuState.HEADER_ONLY); break; - case MenuController.MenuState.HALF_SCREEN: - posY = getMenuStatePosY(MenuController.MenuState.HALF_SCREEN); + case MapRouteInfoMenu.MenuState.HALF_SCREEN: + posY = getMenuStatePosY(MapRouteInfoMenu.MenuState.HALF_SCREEN); break; - case MenuController.MenuState.FULL_SCREEN: + case MapRouteInfoMenu.MenuState.FULL_SCREEN: if (currentY != CURRENT_Y_UNDEFINED) { int maxPosY = viewHeight - menuFullHeightMax; - int minPosY = getMenuStatePosY(MenuController.MenuState.FULL_SCREEN); + int minPosY = getMenuStatePosY(MapRouteInfoMenu.MenuState.FULL_SCREEN); if (maxPosY > minPosY) { maxPosY = minPosY; } - if (currentY > minPosY || previousState != MenuController.MenuState.FULL_SCREEN) { + if (currentY > minPosY || previousState != MapRouteInfoMenu.MenuState.FULL_SCREEN) { posY = minPosY; } else if (currentY < maxPosY) { posY = maxPosY; @@ -508,7 +498,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { posY = currentY; } } else { - posY = getMenuStatePosY(MenuController.MenuState.FULL_SCREEN); + posY = getMenuStatePosY(MapRouteInfoMenu.MenuState.FULL_SCREEN); } break; default: @@ -539,21 +529,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { updateMainViewLayout(posY); } - final float toolbarAlpha = getToolbarAlpha(posY); - if (toolbarAlpha > 0) { - updateVisibility(toolbarContainer, true); - } - toolbarContainer.animate().alpha(toolbarAlpha) - .setDuration(200) - .setInterpolator(new DecelerateInterpolator()) - .setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - updateVisibility(toolbarContainer, toolbarAlpha); - } - }) - .start(); - mainView.animate().y(posY) .setDuration(200) .setInterpolator(new DecelerateInterpolator()) @@ -582,6 +557,9 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { }) .start(); + if (needMapAdjust) { + adjustMapPosition(posY); + } } } @@ -589,44 +567,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { runLayoutListener(); } - private float getToolbarAlpha(int y) { - float a = 0; - if (menu != null && portrait) { - if (y < bottomToolbarPosY) { - a = 1f - (y - topScreenPosY) * (1f / (bottomToolbarPosY - topScreenPosY)); - } - if (a < 0) { - a = 0; - } else if (a > 1) { - a = 1; - } - } - return a; - } - - private void updateToolbar() { - float a = getToolbarAlpha(getViewY()); - updateVisibility(toolbarContainer, a); - } - - private void updateVisibility(View v, float alpha) { - boolean visible = alpha > 0; - v.setAlpha(alpha); - if (visible && v.getVisibility() != View.VISIBLE) { - v.setVisibility(View.VISIBLE); - } else if (!visible && v.getVisibility() == View.VISIBLE) { - v.setVisibility(View.INVISIBLE); - } - } - - private void updateVisibility(View v, boolean visible) { - if (visible && v.getVisibility() != View.VISIBLE) { - v.setVisibility(View.VISIBLE); - } else if (!visible && v.getVisibility() == View.VISIBLE) { - v.setVisibility(View.INVISIBLE); - } - } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void runLayoutListener() { if (view != null) { @@ -677,13 +617,58 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { } public int getHeight() { - if (mainView != null) { - return mainView.getHeight(); + if (menu != null) { + int height = getMenuStatePosY(menu.getCurrentMenuState()); + return viewHeight - height - AndroidUtils.getStatusBarHeight(getMyApplication()); } else { return 0; } } + private void adjustMapPosition(int y) { + if (menu.isSelectFromMapTouch()) { + return; + } + + RoutingHelper rh = getMyApplication().getRoutingHelper(); + if (rh.isRoutePlanningMode() && getMapActivity().getMapView() != null) { + Location lt = rh.getLastProjection(); + if (lt == null) { + lt = getMyApplication().getTargetPointsHelper().getPointToStartLocation(); + } + if (lt != null) { + double left = lt.getLongitude(), right = lt.getLongitude(); + double top = lt.getLatitude(), bottom = lt.getLatitude(); + List list = rh.getCurrentCalculatedRoute(); + for (Location l : list) { + left = Math.min(left, l.getLongitude()); + right = Math.max(right, l.getLongitude()); + top = Math.max(top, l.getLatitude()); + bottom = Math.min(bottom, l.getLatitude()); + } + List targetPoints = getMyApplication().getTargetPointsHelper().getIntermediatePointsWithTarget(); + for (TargetPointsHelper.TargetPoint l : targetPoints) { + left = Math.min(left, l.getLongitude()); + right = Math.max(right, l.getLongitude()); + top = Math.max(top, l.getLatitude()); + bottom = Math.min(bottom, l.getLatitude()); + } + + RotatedTileBox tb = getMapActivity().getMapView().getCurrentRotatedTileBox().copy(); + int tileBoxWidthPx = 0; + int tileBoxHeightPx = 0; + + if (!portrait) { + tileBoxWidthPx = tb.getPixWidth() - getWidth(); + } else { + int fHeight = viewHeight - y - AndroidUtils.getStatusBarHeight(getMyApplication()); + tileBoxHeightPx = tb.getPixHeight() - fHeight; + } + getMapActivity().getMapView().fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0); + } + } + } + public int getWidth() { if (mainView != null) { return mainView.getWidth();