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;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.app.Activity;
@ -884,32 +885,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment
updateMainViewLayout(posY);
}
if (animated) {
mainView.animate().y(posY)
.setDuration(ANIMATION_DURATION)
.setInterpolator(new DecelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
boolean canceled = false;
@Override
public void onAnimationCancel(Animator animation) {
canceled = true;
}
@Override
public void onAnimationEnd(Animator animation) {
if (!canceled) {
if (needCloseMenu && isHideable()) {
dismiss();
} else {
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
}
}).start();
animateMainView(posY, needCloseMenu, previousMenuState, newMenuState);
} else {
if (needCloseMenu && isHideable()) {
dismiss();
@ -929,10 +905,37 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment
return posY;
}
public void animateView(@NonNull View view, int y) {
protected void animateMainView(final int posY, final boolean needCloseMenu, final int previousMenuState, final int newMenuState) {
animateView(mainView, posY, new AnimatorListenerAdapter() {
boolean canceled = false;
@Override
public void onAnimationCancel(Animator animation) {
canceled = true;
}
@Override
public void onAnimationEnd(Animator animation) {
if (!canceled) {
if (needCloseMenu && isHideable()) {
dismiss();
} else {
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
}
});
}
public void animateView(@NonNull View view, int y, @Nullable AnimatorListener listener) {
view.animate().y(y)
.setDuration(ANIMATION_DURATION)
.setInterpolator(new DecelerateInterpolator())
.setListener(listener)
.start();
}

View file

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

View file

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

View file

@ -155,6 +155,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
private LatLon latLon;
private int menuTitleHeight;
private int menuHeaderHeight;
private int toolbarHeightPx;
private boolean mapPositionAdjusted;
@ -300,7 +301,11 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
updateHeader();
setupButtons(view);
updateCardsLayout();
calculateLayoutAndUpdateMenuState();
if (menuType == TrackMenuType.OVERVIEW && isPortrait()) {
calculateLayoutAndShowHeader();
} else {
calculateLayoutAndUpdateMenuState();
}
}
return view;
}
@ -484,8 +489,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
@Override
protected void calculateLayout(View view, boolean initLayout) {
menuTitleHeight = routeMenuTopShadowAll.getHeight()
+ bottomNav.getHeight();
menuHeaderHeight = headerContainer.getHeight();
menuTitleHeight = routeMenuTopShadowAll.getHeight() + bottomNav.getHeight();
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() {
if (menuType == TrackMenuType.OPTIONS) {
openMenuFullScreen();