Add rotation to setMapLocation API

This commit is contained in:
Everton Hermann 2020-07-18 12:10:30 +02:00
parent bbc2a4c07a
commit fac63e2cb3
6 changed files with 49 additions and 4 deletions

View file

@ -10,12 +10,18 @@ public class SetMapLocationParams extends AidlParams {
private double latitude; private double latitude;
private double longitude; private double longitude;
private int zoom; private int zoom;
private float rotation;
private boolean animated; private boolean animated;
public SetMapLocationParams(double latitude, double longitude, int zoom, boolean animated) { public SetMapLocationParams(double latitude, double longitude, int zoom, boolean animated) {
this(latitude, longitude, zoom, Float.NaN, animated);
}
public SetMapLocationParams(double latitude, double longitude, int zoom, float rotation, boolean animated) {
this.latitude = latitude; this.latitude = latitude;
this.longitude = longitude; this.longitude = longitude;
this.zoom = zoom; this.zoom = zoom;
this.rotation = rotation;
this.animated = animated; this.animated = animated;
} }
@ -47,6 +53,10 @@ public class SetMapLocationParams extends AidlParams {
return zoom; return zoom;
} }
public float getRotation() {
return rotation;
}
public boolean isAnimated() { public boolean isAnimated() {
return animated; return animated;
} }
@ -56,6 +66,7 @@ public class SetMapLocationParams extends AidlParams {
bundle.putDouble("latitude", latitude); bundle.putDouble("latitude", latitude);
bundle.putDouble("longitude", longitude); bundle.putDouble("longitude", longitude);
bundle.putInt("zoom", zoom); bundle.putInt("zoom", zoom);
bundle.putFloat("rotation",rotation);
bundle.putBoolean("animated", animated); bundle.putBoolean("animated", animated);
} }
@ -64,6 +75,7 @@ public class SetMapLocationParams extends AidlParams {
latitude = bundle.getDouble("latitude"); latitude = bundle.getDouble("latitude");
longitude = bundle.getDouble("longitude"); longitude = bundle.getDouble("longitude");
zoom = bundle.getInt("zoom"); zoom = bundle.getInt("zoom");
rotation = bundle.getFloat("rotation");
animated = bundle.getBoolean("animated"); animated = bundle.getBoolean("animated");
} }
} }

View file

@ -8,12 +8,19 @@ public class SetMapLocationParams implements Parcelable {
private double latitude; private double latitude;
private double longitude; private double longitude;
private int zoom; private int zoom;
private float rotation;
private boolean animated; private boolean animated;
public SetMapLocationParams(double latitude, double longitude, int zoom, boolean animated) { public SetMapLocationParams(double latitude, double longitude, int zoom, boolean animated) {
this(latitude, longitude, zoom, Float.NaN, animated);
}
public SetMapLocationParams(double latitude, double longitude, int zoom, float rotation, boolean animated) {
this.latitude = latitude; this.latitude = latitude;
this.longitude = longitude; this.longitude = longitude;
this.zoom = zoom; this.zoom = zoom;
this.rotation = rotation;
this.animated = animated; this.animated = animated;
} }
@ -44,6 +51,10 @@ public class SetMapLocationParams implements Parcelable {
return zoom; return zoom;
} }
public float getRotation() {
return rotation;
}
public boolean isAnimated() { public boolean isAnimated() {
return animated; return animated;
} }
@ -52,6 +63,7 @@ public class SetMapLocationParams implements Parcelable {
out.writeDouble(latitude); out.writeDouble(latitude);
out.writeDouble(longitude); out.writeDouble(longitude);
out.writeInt(zoom); out.writeInt(zoom);
out.writeFloat(rotation);
out.writeByte((byte) (animated ? 1 : 0)); out.writeByte((byte) (animated ? 1 : 0));
} }
@ -59,6 +71,7 @@ public class SetMapLocationParams implements Parcelable {
latitude = in.readDouble(); latitude = in.readDouble();
longitude = in.readDouble(); longitude = in.readDouble();
zoom = in.readInt(); zoom = in.readInt();
rotation = in.readFloat();
animated = in.readByte() != 0; animated = in.readByte() != 0;
} }

View file

@ -138,6 +138,8 @@ public class OsmandAidlApi {
private static final String AIDL_LATITUDE = "aidl_latitude"; private static final String AIDL_LATITUDE = "aidl_latitude";
private static final String AIDL_LONGITUDE = "aidl_longitude"; private static final String AIDL_LONGITUDE = "aidl_longitude";
private static final String AIDL_ZOOM = "aidl_zoom"; private static final String AIDL_ZOOM = "aidl_zoom";
private static final String AIDL_ROTATION = "aidl_rotation";
private static final String AIDL_ANIMATED = "aidl_animated"; private static final String AIDL_ANIMATED = "aidl_animated";
private static final String AIDL_START_NAME = "aidl_start_name"; private static final String AIDL_START_NAME = "aidl_start_name";
@ -292,6 +294,8 @@ public class OsmandAidlApi {
double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN); double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN);
int zoom = intent.getIntExtra(AIDL_ZOOM, 0); int zoom = intent.getIntExtra(AIDL_ZOOM, 0);
boolean animated = intent.getBooleanExtra(AIDL_ANIMATED, false); boolean animated = intent.getBooleanExtra(AIDL_ANIMATED, false);
float rotation = intent.getFloatExtra(AIDL_ROTATION, Float.NaN);
if (!Double.isNaN(lat) && !Double.isNaN(lon)) { if (!Double.isNaN(lat) && !Double.isNaN(lon)) {
OsmandMapTileView mapView = mapActivity.getMapView(); OsmandMapTileView mapView = mapActivity.getMapView();
if (zoom == 0) { if (zoom == 0) {
@ -300,6 +304,9 @@ public class OsmandAidlApi {
zoom = zoom > mapView.getMaxZoom() ? mapView.getMaxZoom() : zoom; zoom = zoom > mapView.getMaxZoom() ? mapView.getMaxZoom() : zoom;
zoom = zoom < mapView.getMinZoom() ? mapView.getMinZoom() : zoom; zoom = zoom < mapView.getMinZoom() ? mapView.getMinZoom() : zoom;
} }
if(rotation != Float.NaN) {
mapView.setRotate(rotation,false);
}
if (animated) { if (animated) {
mapView.getAnimatedDraggingThread().startMoving(lat, lon, zoom, true); mapView.getAnimatedDraggingThread().startMoving(lat, lon, zoom, true);
} else { } else {
@ -1548,12 +1555,13 @@ public class OsmandAidlApi {
return false; return false;
} }
boolean setMapLocation(double latitude, double longitude, int zoom, boolean animated) { boolean setMapLocation(double latitude, double longitude, int zoom, float rotation, boolean animated) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(AIDL_SET_MAP_LOCATION); intent.setAction(AIDL_SET_MAP_LOCATION);
intent.putExtra(AIDL_LATITUDE, latitude); intent.putExtra(AIDL_LATITUDE, latitude);
intent.putExtra(AIDL_LONGITUDE, longitude); intent.putExtra(AIDL_LONGITUDE, longitude);
intent.putExtra(AIDL_ZOOM, zoom); intent.putExtra(AIDL_ZOOM, zoom);
intent.putExtra(AIDL_ROTATION, rotation);
intent.putExtra(AIDL_ANIMATED, animated); intent.putExtra(AIDL_ANIMATED, animated);
app.sendBroadcast(intent); app.sendBroadcast(intent);
return true; return true;

View file

@ -597,7 +597,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
if (params != null) { if (params != null) {
OsmandAidlApi api = getApi("setMapLocation"); OsmandAidlApi api = getApi("setMapLocation");
return api != null && api.setMapLocation(params.getLatitude(), params.getLongitude(), return api != null && api.setMapLocation(params.getLatitude(), params.getLongitude(),
params.getZoom(), params.isAnimated()); params.getZoom(), params.getRotation(), params.isAnimated());
} }
return false; return false;
} catch (Exception e) { } catch (Exception e) {

View file

@ -597,7 +597,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
if (params != null) { if (params != null) {
OsmandAidlApi api = getApi("setMapLocation"); OsmandAidlApi api = getApi("setMapLocation");
return api != null && api.setMapLocation(params.getLatitude(), params.getLongitude(), return api != null && api.setMapLocation(params.getLatitude(), params.getLongitude(),
params.getZoom(), params.isAnimated()); params.getZoom(), params.getRotation(), params.isAnimated());
} }
return false; return false;
} catch (Exception e) { } catch (Exception e) {

View file

@ -8,12 +8,18 @@ public class SetMapLocationParams implements Parcelable {
private double latitude; private double latitude;
private double longitude; private double longitude;
private int zoom; private int zoom;
private float rotation;
private boolean animated; private boolean animated;
public SetMapLocationParams(double latitude, double longitude, int zoom, boolean animated) { public SetMapLocationParams(double latitude, double longitude, int zoom, boolean animated) {
this(latitude, longitude, zoom, Float.NaN, animated);
}
public SetMapLocationParams(double latitude, double longitude, int zoom, float rotation, boolean animated) {
this.latitude = latitude; this.latitude = latitude;
this.longitude = longitude; this.longitude = longitude;
this.zoom = zoom; this.zoom = zoom;
this.rotation = rotation;
this.animated = animated; this.animated = animated;
} }
@ -44,6 +50,10 @@ public class SetMapLocationParams implements Parcelable {
return zoom; return zoom;
} }
public float getRotation() {
return rotation;
}
public boolean isAnimated() { public boolean isAnimated() {
return animated; return animated;
} }
@ -52,6 +62,7 @@ public class SetMapLocationParams implements Parcelable {
out.writeDouble(latitude); out.writeDouble(latitude);
out.writeDouble(longitude); out.writeDouble(longitude);
out.writeInt(zoom); out.writeInt(zoom);
out.writeFloat(rotation);
out.writeByte((byte) (animated ? 1 : 0)); out.writeByte((byte) (animated ? 1 : 0));
} }
@ -59,6 +70,7 @@ public class SetMapLocationParams implements Parcelable {
latitude = in.readDouble(); latitude = in.readDouble();
longitude = in.readDouble(); longitude = in.readDouble();
zoom = in.readInt(); zoom = in.readInt();
rotation = in.readFloat();
animated = in.readByte() != 0; animated = in.readByte() != 0;
} }