diff --git a/OsmAnd/res/anim/slide_in_left.xml b/OsmAnd/res/anim/slide_in_left.xml new file mode 100644 index 0000000000..a78b2a3d3b --- /dev/null +++ b/OsmAnd/res/anim/slide_in_left.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/anim/slide_out_left.xml b/OsmAnd/res/anim/slide_out_left.xml new file mode 100644 index 0000000000..d0d53a67b2 --- /dev/null +++ b/OsmAnd/res/anim/slide_out_left.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 4cc8c2d2db..1f696ba148 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -1,10 +1,9 @@ package net.osmand.plus.mapcontextmenu; +import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.util.Log; -import android.widget.Toast; import net.osmand.binary.RouteDataObject; import net.osmand.data.Amenity; @@ -16,7 +15,6 @@ import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.sections.AmenityInfoMenuController; import net.osmand.plus.mapcontextmenu.sections.MenuController; @@ -184,11 +182,11 @@ public class MapContextMenu { }.execute(loc); } - public MenuController getMenuController() { + public MenuController getMenuController(Activity activity) { if (object != null) { if (object instanceof Amenity) { - return new AmenityInfoMenuController(app, (Amenity)object); + return new AmenityInfoMenuController(app, activity, (Amenity)object); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 39109275f6..a9713e8042 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -21,6 +21,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.animation.DecelerateInterpolator; +import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; @@ -147,6 +148,12 @@ public class MapContextMenuFragment extends Fragment { getCtxMenu().restoreMenuState(savedInstanceState); view = inflater.inflate(R.layout.map_context_menu_fragment, container, false); + mainView = view.findViewById(R.id.context_menu_main); + + menuController = getCtxMenu().getMenuController(getActivity()); + if (menuController != null && menuController.isLandscapeLayout()) { + mainView.setLayoutParams(new FrameLayout.LayoutParams(dpToPx(menuController.getLandscapeWidthDp()), ViewGroup.LayoutParams.MATCH_PARENT)); + } ViewTreeObserver vto = view.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @@ -196,8 +203,6 @@ public class MapContextMenuFragment extends Fragment { } }); - mainView = view.findViewById(R.id.context_menu_main); - final View.OnTouchListener slideTouchListener = new View.OnTouchListener() { private float dy; private float dyMain; @@ -205,41 +210,28 @@ public class MapContextMenuFragment extends Fragment { private boolean slidingUp; private boolean slidingDown; - private float velocityX; private float velocityY; private float maxVelocityY; - private float startX; - private float startY; - private long lastTouchDown; - private final int CLICK_ACTION_THRESHHOLD = 200; - - private boolean isClick(float endX, float endY) { - float differenceX = Math.abs(startX - endX); - float differenceY = Math.abs(startY - endY); - if (differenceX > 1 || - differenceY > 1 || - Math.abs(velocityX) > 10 || - Math.abs(velocityY) > 10 || - System.currentTimeMillis() - lastTouchDown > CLICK_ACTION_THRESHHOLD) { - return false; - } - return true; - } - @Override public boolean onTouch(View v, MotionEvent event) { + if (singleTapDetector.onTouchEvent(event)) { + OsmandMapTileView mapView = getMapActivity().getMapView(); + mapView.getAnimatedDraggingThread().startMoving(getCtxMenu().getPointDescription().getLat(), getCtxMenu().getPointDescription().getLon(), + mapView.getZoom(), true); + return true; + } + + if (menuController != null && menuController.isLandscapeLayout()) { + return true; + } + switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - startX = event.getX(); - startY = event.getY(); - lastTouchDown = System.currentTimeMillis(); - dy = event.getY(); dyMain = getViewY(); velocity = VelocityTracker.obtain(); - velocityX = 0; velocityY = 0; maxVelocityY = 0; velocity.addMovement(event); @@ -260,7 +252,6 @@ public class MapContextMenuFragment extends Fragment { velocity.addMovement(event); velocity.computeCurrentVelocity(1000); - velocityX = Math.abs(velocity.getXVelocity()); velocityY = Math.abs(velocity.getYVelocity()); if (velocityY > maxVelocityY) maxVelocityY = velocityY; @@ -269,9 +260,6 @@ public class MapContextMenuFragment extends Fragment { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: - float endX = event.getX(); - float endY = event.getY(); - int currentY = getViewY(); slidingUp = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) < -50; @@ -316,14 +304,6 @@ public class MapContextMenuFragment extends Fragment { updateMainViewLayout(posY); } } - - // OnClick event - if (isClick(endX, endY)) { - OsmandMapTileView mapView = getMapActivity().getMapView(); - mapView.getAnimatedDraggingThread().startMoving(getCtxMenu().getPointDescription().getLat(), getCtxMenu().getPointDescription().getLon(), - mapView.getZoom(), true); - } - break; } @@ -417,7 +397,6 @@ public class MapContextMenuFragment extends Fragment { }); // Menu controller - menuController = getCtxMenu().getMenuController(); bottomView = view.findViewById(R.id.context_menu_bottom_view); if (menuController != null) { bottomView.setOnTouchListener(new View.OnTouchListener() { @@ -529,9 +508,19 @@ public class MapContextMenuFragment extends Fragment { } public static void showInstance(final MapActivity mapActivity) { + + int slideInAnim = R.anim.slide_in_bottom; + int slideOutAnim = R.anim.slide_out_bottom; + + MenuController menuController = mapActivity.getContextMenu().getMenuController(mapActivity); + if (menuController != null) { + slideInAnim = menuController.getSlideInAnimation(); + slideOutAnim = menuController.getSlideOutAnimation(); + } + MapContextMenuFragment fragment = new MapContextMenuFragment(); mapActivity.getSupportFragmentManager().beginTransaction() - .setCustomAnimations(R.anim.slide_in_bottom, R.anim.slide_out_bottom, R.anim.slide_in_bottom, R.anim.slide_out_bottom) + .setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim) .add(R.id.fragmentContainer, fragment, "MapContextMenuFragment") .addToBackStack(null).commit(); } @@ -551,6 +540,12 @@ public class MapContextMenuFragment extends Fragment { return dm.heightPixels; } + private int getScreenWidth() { + DisplayMetrics dm = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); + return dm.widthPixels; + } + private int dpToPx(float dp) { Resources r = getActivity().getResources(); return (int) TypedValue.applyDimension( diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/sections/AmenityInfoMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/sections/AmenityInfoMenuController.java index 6c29cbc601..461665c879 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/sections/AmenityInfoMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/sections/AmenityInfoMenuController.java @@ -1,21 +1,23 @@ package net.osmand.plus.mapcontextmenu.sections; +import android.app.Activity; + import net.osmand.data.Amenity; import net.osmand.plus.OsmandApplication; public class AmenityInfoMenuController extends MenuController { - public AmenityInfoMenuController(OsmandApplication app, final Amenity amenity) { - super(new AmenityInfoMenuBuilder(app, amenity)); + public AmenityInfoMenuController(OsmandApplication app, Activity activity, final Amenity amenity) { + super(new AmenityInfoMenuBuilder(app, amenity), activity); } @Override - public int getInitialMenuState() { + protected int getInitialMenuStatePortrait() { return MenuState.HEADER_ONLY; } @Override - public int getSupportedMenuStates() { + protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/sections/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/sections/MenuController.java index c2e01c5e3f..42300fa32e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/sections/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/sections/MenuController.java @@ -1,7 +1,11 @@ package net.osmand.plus.mapcontextmenu.sections; +import android.app.Activity; import android.view.View; +import net.osmand.plus.R; +import net.osmand.plus.helpers.AndroidUiHelper; + public abstract class MenuController { public class MenuState { @@ -12,9 +16,13 @@ public abstract class MenuController { private MenuBuilder builder; private int currentMenuState; + private boolean portraitMode; + private boolean largeDevice; - public MenuController(MenuBuilder builder) { + public MenuController(MenuBuilder builder, Activity activity) { this.builder = builder; + portraitMode = AndroidUiHelper.isOrientationPortrait(activity); + largeDevice = AndroidUiHelper.isXLargeDevice(activity); this.currentMenuState = getInitialMenuState(); } @@ -23,10 +31,50 @@ public abstract class MenuController { } public int getInitialMenuState() { - return MenuState.HEADER_ONLY; + if (isLandscapeLayout()) { + return MenuState.FULL_SCREEN; + } else { + return getInitialMenuStatePortrait(); + } + } + + public boolean isLandscapeLayout() { + return !portraitMode && !largeDevice; + } + + public float getLandscapeWidthDp() { + return 350f; } public int getSupportedMenuStates() { + if (isLandscapeLayout()) { + return MenuState.FULL_SCREEN; + } else { + return getSupportedMenuStatesPortrait(); + } + } + + public int getSlideInAnimation() { + if (isLandscapeLayout()) { + return R.anim.slide_in_left; + } else { + return R.anim.slide_in_bottom; + } + } + + public int getSlideOutAnimation() { + if (isLandscapeLayout()) { + return R.anim.slide_out_left; + } else { + return R.anim.slide_out_bottom; + } + } + + protected int getInitialMenuStatePortrait() { + return MenuState.HEADER_ONLY; + } + + protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; }