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,12 +311,15 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
mainView.setLayoutParams(lp); mainView.setLayoutParams(lp);
mainView.requestLayout(); mainView.requestLayout();
if (velocity != null) {
velocity.addMovement(event); velocity.addMovement(event);
velocity.computeCurrentVelocity(1000); velocity.computeCurrentVelocity(1000);
velocityY = Math.abs(velocity.getYVelocity()); velocityY = Math.abs(velocity.getYVelocity());
if (velocityY > maxVelocityY) if (velocityY > maxVelocityY) {
maxVelocityY = velocityY; 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;
if (velocity != null) {
velocity.recycle(); 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,6 +610,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
boolean needCloseMenu = false; boolean needCloseMenu = false;
int oldMenuState = menu.getCurrentMenuState(); int oldMenuState = menu.getCurrentMenuState();
if (!menu.isLandscapeLayout()) {
if (slidingDown && !skipScreenState && oldMenuState == MenuState.FULL_SCREEN && currentY < topScreenPosY) { if (slidingDown && !skipScreenState && oldMenuState == MenuState.FULL_SCREEN && currentY < topScreenPosY) {
slidingDown = false; slidingDown = false;
} }
@ -617,6 +625,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
menu.slideDown(); menu.slideDown();
} }
} }
}
int newMenuState = menu.getCurrentMenuState(); int newMenuState = menu.getCurrentMenuState();
boolean needMapAdjust = oldMenuState != newMenuState && newMenuState != MenuState.FULL_SCREEN; boolean needMapAdjust = oldMenuState != newMenuState && newMenuState != MenuState.FULL_SCREEN;
@ -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;
} }