Fix context menu landscape mode

This commit is contained in:
Alexey Kulish 2018-01-30 17:31:36 +03:00
parent 45b54e765b
commit 2fa410947d
2 changed files with 63 additions and 25 deletions

View file

@ -126,7 +126,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
markerPaddingPx = dpToPx(MARKER_PADDING_DP); markerPaddingPx = dpToPx(MARKER_PADDING_DP);
markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP); markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP);
topScreenPosY = -dpToPx(SHADOW_HEIGHT_TOP_DP); topScreenPosY = addStatusBarHeightIfNeeded(-dpToPx(SHADOW_HEIGHT_TOP_DP));
menu = getMapActivity().getContextMenu(); menu = getMapActivity().getContextMenu();
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false); view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
@ -272,11 +272,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
openMenuHalfScreen(); openMenuHalfScreen();
return true; return true;
} }
}
if (menu.isLandscapeLayout()) { if (menu.isLandscapeLayout()) {
if (swipeDetector.onTouchEvent(event)) { if (swipeDetector.onTouchEvent(event)) {
menu.close(); menu.close();
}
return true; return true;
} }
} }
@ -301,6 +300,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
hasMoved = true; hasMoved = true;
float y = event.getY(); float y = event.getY();
float newY = getViewY() + (y - dy); float newY = getViewY() + (y - dy);
if (menu.isLandscapeLayout() && newY > 0) {
newY = 0;
}
setViewY((int) newY, false, false); setViewY((int) newY, false, false);
menuFullHeight = view.getHeight() - (int) newY + 10; menuFullHeight = view.getHeight() - (int) newY + 10;
@ -309,11 +311,14 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
mainView.setLayoutParams(lp); mainView.setLayoutParams(lp);
mainView.requestLayout(); mainView.requestLayout();
velocity.addMovement(event); if (velocity != null) {
velocity.computeCurrentVelocity(1000); velocity.addMovement(event);
velocityY = Math.abs(velocity.getYVelocity()); velocity.computeCurrentVelocity(1000);
if (velocityY > maxVelocityY) velocityY = Math.abs(velocity.getYVelocity());
maxVelocityY = velocityY; if (velocityY > maxVelocityY) {
maxVelocityY = velocityY;
}
}
} }
break; break;
@ -327,7 +332,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
slidingUp = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) < -50; slidingUp = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) < -50;
slidingDown = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) > 50; slidingDown = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) > 50;
velocity.recycle(); if (velocity != null) {
velocity.recycle();
}
boolean skipScreenState = Math.abs(currentY - dyMain) > skipScreenStateLimit; boolean skipScreenState = Math.abs(currentY - dyMain) > skipScreenStateLimit;
changeMenuState(currentY, skipScreenState, slidingUp, slidingDown); changeMenuState(currentY, skipScreenState, slidingUp, slidingDown);
@ -603,18 +610,20 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
boolean needCloseMenu = false; boolean needCloseMenu = false;
int oldMenuState = menu.getCurrentMenuState(); int oldMenuState = menu.getCurrentMenuState();
if (slidingDown && !skipScreenState && oldMenuState == MenuState.FULL_SCREEN && currentY < topScreenPosY) { if (!menu.isLandscapeLayout()) {
slidingDown = false; if (slidingDown && !skipScreenState && oldMenuState == MenuState.FULL_SCREEN && currentY < topScreenPosY) {
} slidingDown = false;
if (menuBottomViewHeight > 0 && slidingUp) {
menu.slideUp();
if (skipScreenState) {
menu.slideUp();
} }
} else if (slidingDown) { if (menuBottomViewHeight > 0 && slidingUp) {
needCloseMenu = !menu.slideDown(); menu.slideUp();
if (!needCloseMenu && skipScreenState) { if (skipScreenState) {
menu.slideDown(); menu.slideUp();
}
} else if (slidingDown) {
needCloseMenu = !menu.slideDown();
if (!needCloseMenu && skipScreenState) {
menu.slideDown();
}
} }
} }
int newMenuState = menu.getCurrentMenuState(); int newMenuState = menu.getCurrentMenuState();
@ -1290,7 +1299,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
case MenuState.FULL_SCREEN: case MenuState.FULL_SCREEN:
if (currentY != CURRENT_Y_UNDEFINED) { if (currentY != CURRENT_Y_UNDEFINED) {
int maxPosY = viewHeight - menuFullHeightMax; int maxPosY = viewHeight - menuFullHeightMax;
int minPosY = addStatusBarHeightIfNeeded(topScreenPosY); int minPosY = topScreenPosY;
if (maxPosY > minPosY) { if (maxPosY > minPosY) {
maxPosY = minPosY; maxPosY = minPosY;
} }
@ -1302,7 +1311,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
posY = currentY; posY = currentY;
} }
} else { } else {
posY = addStatusBarHeightIfNeeded(topScreenPosY); posY = topScreenPosY;
} }
break; break;
default: default:

View file

@ -130,6 +130,34 @@ public abstract class MenuController extends BaseMenuController implements Colla
this.builder.setLight(isLight()); this.builder.setLight(isLight());
} }
public void onCreated() {
/*
toolbarController = new ContextMenuToolbarController(this);
toolbarController.setTitle(getNameStr());
toolbarController.setOnBackButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mapContextMenu != null) {
mapContextMenu.backToolbarAction(MenuController.this);
}
}
});
toolbarController.setOnTitleClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
toolbarController.setOnCloseButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mapContextMenu != null) {
mapContextMenu.close();
}
}
});
*/
}
@Override @Override
public void onCollapseExpand(boolean collapsed) { public void onCollapseExpand(boolean collapsed) {
if (mapContextMenu != null) { if (mapContextMenu != null) {
@ -217,6 +245,7 @@ public abstract class MenuController extends BaseMenuController implements Colla
} }
menuController.menuType = menuType; menuController.menuType = menuType;
menuController.setLatLon(latLon); menuController.setLatLon(latLon);
menuController.onCreated();
return menuController; return menuController;
} }