Open overview with header in track menu

This commit is contained in:
Vitaliy 2021-02-09 01:18:54 +02:00
parent 6d0f17748f
commit fba0b42119
4 changed files with 55 additions and 33 deletions

View file

@ -1,6 +1,7 @@
package net.osmand.plus.base; package net.osmand.plus.base;
import android.animation.Animator; import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
@ -884,10 +885,28 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment
updateMainViewLayout(posY); updateMainViewLayout(posY);
} }
if (animated) { if (animated) {
mainView.animate().y(posY) animateMainView(posY, needCloseMenu, previousMenuState, newMenuState);
.setDuration(ANIMATION_DURATION) } else {
.setInterpolator(new DecelerateInterpolator()) if (needCloseMenu && isHideable()) {
.setListener(new AnimatorListenerAdapter() { dismiss();
} else {
mainView.setY(posY);
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
ContextMenuFragmentListener listener = this.listener;
if (listener != null) {
listener.onContextMenuYPosChanged(this, posY, needMapAdjust, true);
}
}
return posY;
}
protected void animateMainView(final int posY, final boolean needCloseMenu, final int previousMenuState, final int newMenuState) {
animateView(mainView, posY, new AnimatorListenerAdapter() {
boolean canceled = false; boolean canceled = false;
@ -909,30 +928,14 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment
} }
} }
} }
}).start(); });
} else {
if (needCloseMenu && isHideable()) {
dismiss();
} else {
mainView.setY(posY);
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
ContextMenuFragmentListener listener = this.listener;
if (listener != null) {
listener.onContextMenuYPosChanged(this, posY, needMapAdjust, true);
}
}
return posY;
} }
public void animateView(@NonNull View view, int y) { public void animateView(@NonNull View view, int y, @Nullable AnimatorListener listener) {
view.animate().y(y) view.animate().y(y)
.setDuration(ANIMATION_DURATION) .setDuration(ANIMATION_DURATION)
.setInterpolator(new DecelerateInterpolator()) .setInterpolator(new DecelerateInterpolator())
.setListener(listener)
.start(); .start();
} }

View file

@ -133,7 +133,7 @@ public abstract class ContextMenuScrollFragment extends ContextMenuFragment impl
if (mapControlsView != null) { if (mapControlsView != null) {
int zoomY = y - getMapControlsHeight(); int zoomY = y - getMapControlsHeight();
if (animated) { if (animated) {
fragment.animateView(mapControlsView, zoomY); fragment.animateView(mapControlsView, zoomY, null);
} else { } else {
mapControlsView.setY(zoomY); mapControlsView.setY(zoomY);
} }

View file

@ -767,7 +767,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
int pagesY = y - getPagesViewHeight() + fragment.getShadowHeight() + int pagesY = y - getPagesViewHeight() + fragment.getShadowHeight() +
(Build.VERSION.SDK_INT >= 21 ? AndroidUtils.getStatusBarHeight(pagesView.getContext()) : 0); (Build.VERSION.SDK_INT >= 21 ? AndroidUtils.getStatusBarHeight(pagesView.getContext()) : 0);
if (animated) { if (animated) {
fragment.animateView(pagesView, pagesY); fragment.animateView(pagesView, pagesY, null);
} else { } else {
pagesView.setY(pagesY); pagesView.setY(pagesY);
} }
@ -780,7 +780,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
int zoomY = y - getZoomButtonsHeight() + int zoomY = y - getZoomButtonsHeight() +
(Build.VERSION.SDK_INT >= 21 ? AndroidUtils.getStatusBarHeight(zoomButtonsView.getContext()) : 0); (Build.VERSION.SDK_INT >= 21 ? AndroidUtils.getStatusBarHeight(zoomButtonsView.getContext()) : 0);
if (animated) { if (animated) {
fragment.animateView(zoomButtonsView, zoomY); fragment.animateView(zoomButtonsView, zoomY, null);
} else { } else {
zoomButtonsView.setY(zoomY); zoomButtonsView.setY(zoomY);
} }

View file

@ -155,6 +155,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
private LatLon latLon; private LatLon latLon;
private int menuTitleHeight; private int menuTitleHeight;
private int menuHeaderHeight;
private int toolbarHeightPx; private int toolbarHeightPx;
private boolean mapPositionAdjusted; private boolean mapPositionAdjusted;
@ -300,8 +301,12 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
updateHeader(); updateHeader();
setupButtons(view); setupButtons(view);
updateCardsLayout(); updateCardsLayout();
if (menuType == TrackMenuType.OVERVIEW && isPortrait()) {
calculateLayoutAndShowHeader();
} else {
calculateLayoutAndUpdateMenuState(); calculateLayoutAndUpdateMenuState();
} }
}
return view; return view;
} }
@ -484,8 +489,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
@Override @Override
protected void calculateLayout(View view, boolean initLayout) { protected void calculateLayout(View view, boolean initLayout) {
menuTitleHeight = routeMenuTopShadowAll.getHeight() menuHeaderHeight = headerContainer.getHeight();
+ bottomNav.getHeight(); menuTitleHeight = routeMenuTopShadowAll.getHeight() + bottomNav.getHeight();
super.calculateLayout(view, initLayout); super.calculateLayout(view, initLayout);
} }
@ -913,6 +918,20 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}); });
} }
private void calculateLayoutAndShowHeader() {
runLayoutListener(new Runnable() {
@Override
public void run() {
int posY = getViewHeight() - menuHeaderHeight - menuTitleHeight - getShadowHeight();
if (posY < getViewY()) {
updateMainViewLayout(posY);
}
animateMainView(posY, false, getCurrentMenuState(), getCurrentMenuState());
updateMapControlsPos(TrackMenuFragment.this, posY, true);
}
});
}
private void updateMenuState() { private void updateMenuState() {
if (menuType == TrackMenuType.OPTIONS) { if (menuType == TrackMenuType.OPTIONS) {
openMenuFullScreen(); openMenuFullScreen();