Merge pull request #8229 from osmandapp/tilt_gesture_opengl
Tilt gesture opengl
This commit is contained in:
commit
1dbcf48f89
4 changed files with 111 additions and 12 deletions
|
@ -2290,6 +2290,7 @@ public class OsmandSettings {
|
||||||
public static final String LAST_KNOWN_MAP_LAT = "last_known_map_lat"; //$NON-NLS-1$
|
public static final String LAST_KNOWN_MAP_LAT = "last_known_map_lat"; //$NON-NLS-1$
|
||||||
public static final String LAST_KNOWN_MAP_LON = "last_known_map_lon"; //$NON-NLS-1$
|
public static final String LAST_KNOWN_MAP_LON = "last_known_map_lon"; //$NON-NLS-1$
|
||||||
public static final String LAST_KNOWN_MAP_ZOOM = "last_known_map_zoom"; //$NON-NLS-1$
|
public static final String LAST_KNOWN_MAP_ZOOM = "last_known_map_zoom"; //$NON-NLS-1$
|
||||||
|
public static final String LAST_KNOWN_MAP_ELEVATION = "last_known_map_elevation"; //$NON-NLS-1$
|
||||||
|
|
||||||
public static final String MAP_LABEL_TO_SHOW = "map_label_to_show"; //$NON-NLS-1$
|
public static final String MAP_LABEL_TO_SHOW = "map_label_to_show"; //$NON-NLS-1$
|
||||||
public static final String MAP_LAT_TO_SHOW = "map_lat_to_show"; //$NON-NLS-1$
|
public static final String MAP_LAT_TO_SHOW = "map_lat_to_show"; //$NON-NLS-1$
|
||||||
|
@ -2403,6 +2404,14 @@ public class OsmandSettings {
|
||||||
settingsAPI.edit(globalPreferences).putInt(LAST_KNOWN_MAP_ZOOM, zoom).commit();
|
settingsAPI.edit(globalPreferences).putInt(LAST_KNOWN_MAP_ZOOM, zoom).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getLastKnownMapElevation() {
|
||||||
|
return settingsAPI.getFloat(globalPreferences, LAST_KNOWN_MAP_ELEVATION, 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastKnownMapElevation(float elevation) {
|
||||||
|
settingsAPI.edit(globalPreferences).putFloat(LAST_KNOWN_MAP_ELEVATION, elevation).commit();
|
||||||
|
}
|
||||||
|
|
||||||
public final static String POINT_NAVIGATE_LAT = "point_navigate_lat"; //$NON-NLS-1$
|
public final static String POINT_NAVIGATE_LAT = "point_navigate_lat"; //$NON-NLS-1$
|
||||||
public final static String POINT_NAVIGATE_LON = "point_navigate_lon"; //$NON-NLS-1$
|
public final static String POINT_NAVIGATE_LON = "point_navigate_lon"; //$NON-NLS-1$
|
||||||
public final static String POINT_NAVIGATE_ROUTE = "point_navigate_route_integer"; //$NON-NLS-1$
|
public final static String POINT_NAVIGATE_ROUTE = "point_navigate_route_integer"; //$NON-NLS-1$
|
||||||
|
|
|
@ -474,7 +474,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
OsmAndMapLayersView ml = (OsmAndMapLayersView) findViewById(R.id.MapLayersView);
|
OsmAndMapLayersView ml = (OsmAndMapLayersView) findViewById(R.id.MapLayersView);
|
||||||
ml.setVisibility(View.VISIBLE);
|
ml.setVisibility(View.VISIBLE);
|
||||||
atlasMapRendererView.setAzimuth(0);
|
atlasMapRendererView.setAzimuth(0);
|
||||||
atlasMapRendererView.setElevationAngle(90);
|
atlasMapRendererView.setElevationAngle(app.getSettings().getLastKnownMapElevation());
|
||||||
NativeCoreContext.getMapRendererContext().setMapRendererView(atlasMapRendererView);
|
NativeCoreContext.getMapRendererContext().setMapRendererView(atlasMapRendererView);
|
||||||
ml.setMapView(mapView);
|
ml.setMapView(mapView);
|
||||||
mapViewTrackingUtilities.setMapView(mapView);
|
mapViewTrackingUtilities.setMapView(mapView);
|
||||||
|
@ -488,6 +488,12 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMapElevation(float angle) {
|
||||||
|
if (atlasMapRendererView != null) {
|
||||||
|
atlasMapRendererView.setElevationAngle(angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void createProgressBarForRouting() {
|
private void createProgressBarForRouting() {
|
||||||
final ProgressBar pb = (ProgressBar) findViewById(R.id.map_horizontal_progress);
|
final ProgressBar pb = (ProgressBar) findViewById(R.id.map_horizontal_progress);
|
||||||
|
|
||||||
|
@ -1490,6 +1496,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.setLastKnownMapZoom(mapView.getZoom());
|
settings.setLastKnownMapZoom(mapView.getZoom());
|
||||||
|
settings.setLastKnownMapElevation(mapView.getElevationAngle());
|
||||||
settings.MAP_ACTIVITY_ENABLED.set(false);
|
settings.MAP_ACTIVITY_ENABLED.set(false);
|
||||||
app.getResourceManager().interruptRendering();
|
app.getResourceManager().interruptRendering();
|
||||||
OsmandPlugin.onMapActivityPause(this);
|
OsmandPlugin.onMapActivityPause(this);
|
||||||
|
|
|
@ -5,6 +5,8 @@ import android.graphics.PointF;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.views.corenative.NativeCoreContext;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -36,6 +38,10 @@ public class MultiTouchSupport {
|
||||||
public void onActionPointerUp();
|
public void onActionPointerUp();
|
||||||
|
|
||||||
public void onActionCancel();
|
public void onActionCancel();
|
||||||
|
|
||||||
|
public void onChangingViewAngle(float angle);
|
||||||
|
|
||||||
|
public void onChangeViewAngleStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean multiTouchAPISupported = false;
|
private boolean multiTouchAPISupported = false;
|
||||||
|
@ -62,6 +68,14 @@ public class MultiTouchSupport {
|
||||||
return inZoomMode;
|
return inZoomMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isInTiltMode() {
|
||||||
|
return inTiltMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTiltSupported() {
|
||||||
|
return ((OsmandApplication) ctx.getApplicationContext()).getSettings().USE_OPENGL_RENDER.get() && NativeCoreContext.isInit();
|
||||||
|
}
|
||||||
|
|
||||||
private void initMethods(){
|
private void initMethods(){
|
||||||
try {
|
try {
|
||||||
getPointerCount = MotionEvent.class.getMethod("getPointerCount"); //$NON-NLS-1$
|
getPointerCount = MotionEvent.class.getMethod("getPointerCount"); //$NON-NLS-1$
|
||||||
|
@ -76,9 +90,15 @@ public class MultiTouchSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean inZoomMode = false;
|
private boolean inZoomMode = false;
|
||||||
|
private boolean inTiltMode = false;
|
||||||
private double zoomStartedDistance = 100;
|
private double zoomStartedDistance = 100;
|
||||||
private double zoomRelative = 1;
|
private double zoomRelative = 1;
|
||||||
private PointF centerPoint = new PointF();
|
private PointF centerPoint = new PointF();
|
||||||
|
private PointF firstFingerStart = new PointF();
|
||||||
|
private PointF secondFingerStart = new PointF();
|
||||||
|
private static final int TILT_X_THRESHOLD_PX = 40;
|
||||||
|
private static final int TILT_Y_THRESHOLD_PX = 40;
|
||||||
|
private static final int TILT_DY_THRESHOLD_PX = 40;
|
||||||
|
|
||||||
public boolean onTouchEvent(MotionEvent event){
|
public boolean onTouchEvent(MotionEvent event){
|
||||||
if(!isMultiTouchSupported()){
|
if(!isMultiTouchSupported()){
|
||||||
|
@ -95,6 +115,9 @@ public class MultiTouchSupport {
|
||||||
listener.onZoomOrRotationEnded(zoomRelative, angleRelative);
|
listener.onZoomOrRotationEnded(zoomRelative, angleRelative);
|
||||||
inZoomMode = false;
|
inZoomMode = false;
|
||||||
return true;
|
return true;
|
||||||
|
} else if (inTiltMode) {
|
||||||
|
inTiltMode = false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -114,19 +137,24 @@ public class MultiTouchSupport {
|
||||||
}
|
}
|
||||||
if (actionCode == ACTION_POINTER_DOWN) {
|
if (actionCode == ACTION_POINTER_DOWN) {
|
||||||
centerPoint = new PointF((x1 + x2) / 2, (y1 + y2) / 2);
|
centerPoint = new PointF((x1 + x2) / 2, (y1 + y2) / 2);
|
||||||
|
firstFingerStart = new PointF(x1, y1);
|
||||||
|
secondFingerStart = new PointF(x2, y2);
|
||||||
listener.onGestureInit(x1, y1, x2, y2);
|
listener.onGestureInit(x1, y1, x2, y2);
|
||||||
listener.onZoomStarted(centerPoint);
|
listener.onZoomStarted(centerPoint);
|
||||||
zoomStartedDistance = distance;
|
zoomStartedDistance = distance;
|
||||||
angleStarted = angle;
|
angleStarted = angle;
|
||||||
inZoomMode = true;
|
|
||||||
return true;
|
return true;
|
||||||
} else if(actionCode == ACTION_POINTER_UP){
|
} else if(actionCode == ACTION_POINTER_UP){
|
||||||
if (inZoomMode) {
|
if (inZoomMode) {
|
||||||
listener.onZoomOrRotationEnded(zoomRelative, angleRelative);
|
listener.onZoomOrRotationEnded(zoomRelative, angleRelative);
|
||||||
inZoomMode = false;
|
inZoomMode = false;
|
||||||
|
} else if (inTiltMode) {
|
||||||
|
inTiltMode = false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if(inZoomMode && actionCode == MotionEvent.ACTION_MOVE){
|
} else if (actionCode == MotionEvent.ACTION_MOVE) {
|
||||||
|
if (inZoomMode) {
|
||||||
|
|
||||||
// Keep zoom center fixed or flexible
|
// Keep zoom center fixed or flexible
|
||||||
centerPoint = new PointF((x1 + x2) / 2, (y1 + y2) / 2);
|
centerPoint = new PointF((x1 + x2) / 2, (y1 + y2) / 2);
|
||||||
|
|
||||||
|
@ -135,6 +163,32 @@ public class MultiTouchSupport {
|
||||||
}
|
}
|
||||||
zoomRelative = distance / zoomStartedDistance;
|
zoomRelative = distance / zoomStartedDistance;
|
||||||
listener.onZoomingOrRotating(zoomRelative, angleRelative);
|
listener.onZoomingOrRotating(zoomRelative, angleRelative);
|
||||||
|
} else if (inTiltMode) {
|
||||||
|
float dy2 = secondFingerStart.y - y2;
|
||||||
|
float viewAngle = dy2 / 8f;
|
||||||
|
listener.onChangingViewAngle(viewAngle);
|
||||||
|
} else if (isTiltSupported()) {
|
||||||
|
float dx1 = Math.abs(firstFingerStart.x - x1);
|
||||||
|
float dx2 = Math.abs(secondFingerStart.x - x2);
|
||||||
|
float dy1 = Math.abs(firstFingerStart.y - y1);
|
||||||
|
float dy2 = Math.abs(secondFingerStart.y - y2);
|
||||||
|
float startDy = Math.abs(secondFingerStart.y - firstFingerStart.y);
|
||||||
|
if (dx1 < TILT_X_THRESHOLD_PX && dx2 < TILT_X_THRESHOLD_PX
|
||||||
|
&& dy1 > TILT_Y_THRESHOLD_PX && dy2 > TILT_Y_THRESHOLD_PX
|
||||||
|
&& startDy < TILT_Y_THRESHOLD_PX * 6
|
||||||
|
&& Math.abs(dy2 - dy1) < TILT_DY_THRESHOLD_PX) {
|
||||||
|
listener.onChangeViewAngleStarted();
|
||||||
|
inTiltMode = true;
|
||||||
|
} else if (dx1 > TILT_X_THRESHOLD_PX || dx2 > TILT_X_THRESHOLD_PX
|
||||||
|
|| Math.abs(dy2 - dy1) > TILT_DY_THRESHOLD_PX
|
||||||
|
|| Math.abs(dy1 - dy2) > TILT_DY_THRESHOLD_PX) {
|
||||||
|
angleRelative = 0;
|
||||||
|
zoomRelative = 0;
|
||||||
|
inZoomMode = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inZoomMode = true;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -186,6 +186,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
private long multiTouchStartTime;
|
private long multiTouchStartTime;
|
||||||
private long multiTouchEndTime;
|
private long multiTouchEndTime;
|
||||||
private boolean wasZoomInMultiTouch;
|
private boolean wasZoomInMultiTouch;
|
||||||
|
private float elevationAngle;
|
||||||
|
|
||||||
public OsmandMapTileView(MapActivity activity, int w, int h) {
|
public OsmandMapTileView(MapActivity activity, int w, int h) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
|
@ -257,6 +258,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
elevationAngle = settings.getLastKnownMapElevation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setView(View view) {
|
public void setView(View view) {
|
||||||
|
@ -439,6 +441,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
return currentViewport.getZoom();
|
return currentViewport.getZoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getElevationAngle() {
|
||||||
|
return elevationAngle;
|
||||||
|
}
|
||||||
|
|
||||||
public double getZoomFractionalPart() {
|
public double getZoomFractionalPart() {
|
||||||
return currentViewport.getZoomFloatPart();
|
return currentViewport.getZoomFloatPart();
|
||||||
}
|
}
|
||||||
|
@ -1127,6 +1133,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
private LatLon initialCenterLatLon;
|
private LatLon initialCenterLatLon;
|
||||||
private boolean startRotating = false;
|
private boolean startRotating = false;
|
||||||
private static final float ANGLE_THRESHOLD = 30;
|
private static final float ANGLE_THRESHOLD = 30;
|
||||||
|
private float initialElevation;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onZoomOrRotationEnded(double relativeToStart, float angleRelative) {
|
public void onZoomOrRotationEnded(double relativeToStart, float angleRelative) {
|
||||||
|
@ -1199,6 +1206,16 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
multiTouch = false;
|
multiTouch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChangingViewAngle(float angle) {
|
||||||
|
setElevationAngle(initialElevation - angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChangeViewAngleStarted() {
|
||||||
|
initialElevation = elevationAngle;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onZoomStarted(PointF centerPoint) {
|
public void onZoomStarted(PointF centerPoint) {
|
||||||
initialMultiTouchCenterPoint = centerPoint;
|
initialMultiTouchCenterPoint = centerPoint;
|
||||||
|
@ -1287,6 +1304,16 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setElevationAngle(float angle) {
|
||||||
|
if (angle < 35f) {
|
||||||
|
angle = 35f;
|
||||||
|
} else if (angle > 90f) {
|
||||||
|
angle = 90f;
|
||||||
|
}
|
||||||
|
this.elevationAngle = angle;
|
||||||
|
((MapActivity) activity).setMapElevation(angle);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isZoomingAllowed(int baseZoom, float dz) {
|
private boolean isZoomingAllowed(int baseZoom, float dz) {
|
||||||
if (baseZoom > getMaxZoom()) {
|
if (baseZoom > getMaxZoom()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1346,7 +1373,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||||
|
if (!multiTouchSupport.isInTiltMode()) {
|
||||||
dragToAnimate(e2.getX() + distanceX, e2.getY() + distanceY, e2.getX(), e2.getY(), true);
|
dragToAnimate(e2.getX() + distanceX, e2.getY() + distanceY, e2.getX(), e2.getY(), true);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue