Commit a8f5b679 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Force draw compass on enable

Change-Id: I86ad3e3f63315d7b78765f59d1b5763b4f63104c
parent 2820e72a
......@@ -62,6 +62,7 @@ import org.osmdroid.views.overlay.OverlayWithIWVisitor;
import org.osmdroid.views.overlay.Polygon;
import org.osmdroid.views.overlay.Polyline;
import org.osmdroid.views.overlay.compass.CompassOverlay;
import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider;
import org.osmdroid.views.overlay.gestures.RotationGestureOverlay;
import org.osmdroid.views.overlay.infowindow.OverlayInfoWindow;
import org.osmdroid.views.overlay.mylocation.IMyLocationConsumer;
......@@ -107,6 +108,7 @@ class NativeOpenStreetMapController implements MapController, MapListener {
private OverlayInfoWindow defaultInfoWindow = null;
private boolean ready = false;
private ZoomControlView zoomControls = null;
private float lastAzimuth = Float.NaN;
private static class AppInventorLocationSensorAdapter implements IMyLocationProvider,
LocationSensor.LocationSensorListener {
......@@ -383,8 +385,14 @@ class NativeOpenStreetMapController implements MapController, MapListener {
}
if (compass != null) {
if (enabled) {
compass.enableCompass();
if (compass.getOrientationProvider() != null) {
compass.enableCompass();
} else {
compass.enableCompass(new InternalCompassOrientationProvider(view.getContext()));
}
compass.onOrientationChanged(lastAzimuth, null);
} else {
lastAzimuth = compass.getOrientation();
compass.disableCompass();
}
}
......@@ -392,7 +400,7 @@ class NativeOpenStreetMapController implements MapController, MapListener {
@Override
public boolean isCompassEnabled() {
return compass != null && compass.isEnabled();
return compass != null && compass.isCompassEnabled();
}
@Override
......
......@@ -5,6 +5,8 @@
package com.google.appinventor.components.runtime;
import android.content.Context;
import android.hardware.Sensor;
import com.google.appinventor.components.runtime.shadows.ShadowAsynchUtil;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.GeometryUtil;
......@@ -13,7 +15,9 @@ import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
import org.osmdroid.util.GeoPoint;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowSensorManager;
import org.robolectric.shadows.ShadowView;
import java.io.IOException;
......@@ -121,6 +125,12 @@ public class MapTest extends MapTestBase {
@Test
public void testShowCompass() {
/* We need to create a sensor for the orientation type, otherwise compass will fail to enable */
Context context = RuntimeEnvironment.application.getApplicationContext();
ShadowSensorManager sensorManager = Shadow.extract(context.getSystemService(Context.SENSOR_SERVICE));
Sensor s = Shadow.newInstanceOf(Sensor.class);
sensorManager.addSensor(Sensor.TYPE_ORIENTATION, s);
/* end setup */
map.ShowCompass(true);
assertTrue(map.ShowCompass());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment