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; ...@@ -62,6 +62,7 @@ import org.osmdroid.views.overlay.OverlayWithIWVisitor;
import org.osmdroid.views.overlay.Polygon; import org.osmdroid.views.overlay.Polygon;
import org.osmdroid.views.overlay.Polyline; import org.osmdroid.views.overlay.Polyline;
import org.osmdroid.views.overlay.compass.CompassOverlay; 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.gestures.RotationGestureOverlay;
import org.osmdroid.views.overlay.infowindow.OverlayInfoWindow; import org.osmdroid.views.overlay.infowindow.OverlayInfoWindow;
import org.osmdroid.views.overlay.mylocation.IMyLocationConsumer; import org.osmdroid.views.overlay.mylocation.IMyLocationConsumer;
...@@ -107,6 +108,7 @@ class NativeOpenStreetMapController implements MapController, MapListener { ...@@ -107,6 +108,7 @@ class NativeOpenStreetMapController implements MapController, MapListener {
private OverlayInfoWindow defaultInfoWindow = null; private OverlayInfoWindow defaultInfoWindow = null;
private boolean ready = false; private boolean ready = false;
private ZoomControlView zoomControls = null; private ZoomControlView zoomControls = null;
private float lastAzimuth = Float.NaN;
private static class AppInventorLocationSensorAdapter implements IMyLocationProvider, private static class AppInventorLocationSensorAdapter implements IMyLocationProvider,
LocationSensor.LocationSensorListener { LocationSensor.LocationSensorListener {
...@@ -383,8 +385,14 @@ class NativeOpenStreetMapController implements MapController, MapListener { ...@@ -383,8 +385,14 @@ class NativeOpenStreetMapController implements MapController, MapListener {
} }
if (compass != null) { if (compass != null) {
if (enabled) { if (enabled) {
compass.enableCompass(); if (compass.getOrientationProvider() != null) {
compass.enableCompass();
} else {
compass.enableCompass(new InternalCompassOrientationProvider(view.getContext()));
}
compass.onOrientationChanged(lastAzimuth, null);
} else { } else {
lastAzimuth = compass.getOrientation();
compass.disableCompass(); compass.disableCompass();
} }
} }
...@@ -392,7 +400,7 @@ class NativeOpenStreetMapController implements MapController, MapListener { ...@@ -392,7 +400,7 @@ class NativeOpenStreetMapController implements MapController, MapListener {
@Override @Override
public boolean isCompassEnabled() { public boolean isCompassEnabled() {
return compass != null && compass.isEnabled(); return compass != null && compass.isCompassEnabled();
} }
@Override @Override
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
package com.google.appinventor.components.runtime; 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.shadows.ShadowAsynchUtil;
import com.google.appinventor.components.runtime.util.ErrorMessages; import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.GeometryUtil; import com.google.appinventor.components.runtime.util.GeometryUtil;
...@@ -13,7 +15,9 @@ import org.easymock.EasyMock; ...@@ -13,7 +15,9 @@ import org.easymock.EasyMock;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.osmdroid.util.GeoPoint; import org.osmdroid.util.GeoPoint;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadow.api.Shadow; import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowSensorManager;
import org.robolectric.shadows.ShadowView; import org.robolectric.shadows.ShadowView;
import java.io.IOException; import java.io.IOException;
...@@ -121,6 +125,12 @@ public class MapTest extends MapTestBase { ...@@ -121,6 +125,12 @@ public class MapTest extends MapTestBase {
@Test @Test
public void testShowCompass() { 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); map.ShowCompass(true);
assertTrue(map.ShowCompass()); 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