diff --git a/OsmAnd/res/drawable/btn_circle_trans_flat.xml b/OsmAnd/res/drawable/btn_circle_trans_flat.xml new file mode 100644 index 0000000000..edde680885 --- /dev/null +++ b/OsmAnd/res/drawable/btn_circle_trans_flat.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/btn_circle_trans_flat_n.xml b/OsmAnd/res/drawable/btn_circle_trans_flat_n.xml new file mode 100644 index 0000000000..ecf51e7a1a --- /dev/null +++ b/OsmAnd/res/drawable/btn_circle_trans_flat_n.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/map_context_menu_fragment.xml b/OsmAnd/res/layout/map_context_menu_fragment.xml index 06a02cf77e..ebb13a5643 100644 --- a/OsmAnd/res/layout/map_context_menu_fragment.xml +++ b/OsmAnd/res/layout/map_context_menu_fragment.xml @@ -600,6 +600,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + maxVelocityY) { maxVelocityY = velocityY; } } + + updateToolbar(); + updateTopButton(); } break; case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: if (moving) { moving = false; int currentY = getViewY(); @@ -332,18 +377,35 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo slidingUp = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) < -50; slidingDown = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) > 50; - if (velocity != null) { - velocity.recycle(); - } - boolean skipScreenState = Math.abs(currentY - dyMain) > skipScreenStateLimit; changeMenuState(currentY, skipScreenState, slidingUp, slidingDown); } + recycleVelocityTracker(); + break; + case MotionEvent.ACTION_CANCEL: + moving = false; + recycleVelocityTracker(); break; } return true; } + + private void initOrResetVelocityTracker() { + if (velocityTracker == null) { + velocityTracker = VelocityTracker.obtain(); + } else { + velocityTracker.clear(); + } + } + + private void recycleVelocityTracker() { + if (velocityTracker != null) { + velocityTracker.recycle(); + velocityTracker = null; + } + } + }; View topShadowAllView = view.findViewById(R.id.context_menu_top_shadow_all); @@ -541,6 +603,43 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo return view; } + private float getToolbarAlpha(int y) { + float a = 0; + if (y < minHalfY) { + a = 1f - (y - bottomToolbarPosY) * (1f / (minHalfY - bottomToolbarPosY)); + } + if (a < 0) { + a = 0; + } else if (a > 1) { + a = 1; + } + return a; + } + + private void updateToolbar() { + float a = getToolbarAlpha(getViewY()); + toolbarContainer.setAlpha(a); + } + + private float getTopButtonAlpha(int y) { + float a = 0; + int headerTopY = getHeaderOnlyTopY(); + if (y < headerTopY) { + a = 1f - (y - minHalfY) * (1f / (headerTopY - minHalfY)); + } + if (a < 0) { + a = 0; + } else if (a > 1) { + a = 1; + } + return a; + } + + private void updateTopButton() { + float a = getTopButtonAlpha(getViewY()); + topButtonContainer.setAlpha(a); + } + private void toggleDetailsHideButton() { int menuState = menu.getCurrentMenuState(); final boolean showShowHideButton = menuState == MenuState.HALF_SCREEN || (!menu.isLandscapeLayout() && menuState == MenuState.FULL_SCREEN); @@ -582,7 +681,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } private void processScreenHeight(ViewParent parent) { - View container = (View)parent; + View container = (View) parent; screenHeight = container.getHeight() + AndroidUtils.getStatusBarHeight(getActivity()); skipScreenStateLimit = screenHeight * SKIP_HALF_SCREEN_STATE_KOEF; viewHeight = screenHeight - AndroidUtils.getStatusBarHeight(getMapActivity()); @@ -682,6 +781,18 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo updateMainViewLayout(posY); } + final float topButtonAlpha = getTopButtonAlpha(posY); + topButtonContainer.animate().alpha(topButtonAlpha) + .setDuration(200) + .setInterpolator(new DecelerateInterpolator()) + .start(); + + final float toolbarAlpha = getToolbarAlpha(posY); + toolbarContainer.animate().alpha(toolbarAlpha) + .setDuration(200) + .setInterpolator(new DecelerateInterpolator()) + .start(); + mainView.animate().y(posY) .setDuration(200) .setInterpolator(new DecelerateInterpolator()) @@ -739,7 +850,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light); button.setTextColor(buttonColorStateList); } else { - buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_disabled_bg_dark: R.drawable.context_menu_controller_disabled_bg_light); + buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_disabled_bg_dark : R.drawable.context_menu_controller_disabled_bg_light); button.setTextColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_controller_disabled_text_color_dark : R.color.ctx_menu_controller_disabled_text_color_light)); } button.setEnabled(enabled); @@ -1267,6 +1378,11 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } } + private int getHeaderOnlyTopY() { + return viewHeight - menuTitleHeight; + } + + private int getPosY() { return getPosY(CURRENT_Y_UNDEFINED, false); } @@ -1277,13 +1393,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } int destinationState; - int minHalfY; if (menu.isExtended()) { destinationState = menu.getCurrentMenuState(); - minHalfY = viewHeight - (int) (viewHeight * menu.getHalfScreenMaxHeightKoef()); } else { destinationState = MenuState.HEADER_ONLY; - minHalfY = viewHeight - (int) (viewHeight * .75f); } updateZoomButtonsVisibility(destinationState); @@ -1291,7 +1404,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo int posY = 0; switch (destinationState) { case MenuState.HEADER_ONLY: - posY = viewHeight - menuTitleHeight; + posY = getHeaderOnlyTopY(); break; case MenuState.HALF_SCREEN: posY = minHalfY; @@ -1440,7 +1553,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } private int getZoomButtonsY(int y) { - return y - zoomButtonsHeight; + return y - zoomButtonsHeight - shadowHeight - zoomPaddingTop; } private void doLayoutMenu() {