diff --git a/.gitignore b/.gitignore index 7535671..f29b313 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,8 @@ project.xcworkspace .settings local.properties android.iml +android/gradlew +android/gradlew.bat # Cocoapods # diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..033e24c Binary files /dev/null and b/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..62f495d --- /dev/null +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/android/src/main/java/com/compassheading/CompassHeadingModule.java b/android/src/main/java/com/compassheading/CompassHeadingModule.java index 44a173d..925d946 100644 --- a/android/src/main/java/com/compassheading/CompassHeadingModule.java +++ b/android/src/main/java/com/compassheading/CompassHeadingModule.java @@ -32,6 +32,14 @@ public class CompassHeadingModule extends ReactContextBaseJavaModule implements private int mFilter = 1; private SensorManager sensorManager; + /** + * Possible values. + * 0 -> sensorManager.SENSOR_STATUS_UNRELIABLE + * 1 -> sensorManager.SENSOR_STATUS_ACCURACY_LOW + * 2 -> sensorManager.SENSOR_STATUS_ACCURACY_MEDIUM + * 3 -> sensorManager.SENSOR_STATUS_ACCURACY_HIGH + */ + private int mAccuracy = SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM; private final float[] mGravity = new float[3]; private final float[] mGeomagnetic = new float[3]; @@ -174,7 +182,7 @@ else if(rotation == Surface.ROTATION_180){ WritableMap params = Arguments.createMap(); params.putDouble("heading", mAzimuth); - params.putDouble("accuracy", 1.0); + params.putDouble("accuracy", mAccuracy); getReactApplicationContext() .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) @@ -185,5 +193,17 @@ else if(rotation == Surface.ROTATION_180){ } @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) {} + public void onAccuracyChanged(Sensor sensor, int accuracy) { + + if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { + mAccuracy = accuracy; + WritableMap params = Arguments.createMap(); + params.putDouble("heading", mAzimuth); + params.putDouble("accuracy", mAccuracy); + + getReactApplicationContext() + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) + .emit("HeadingUpdated", params); + } + } } diff --git a/src/index.tsx b/src/index.tsx index 9b278c6..0d3b434 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -23,6 +23,18 @@ let _start = CompassHeading.start; type dataType = { heading: number; + /** + * for Android: + * 0 -> sensorManager.SENSOR_STATUS_UNRELIABLE + * 1 -> sensorManager.SENSOR_STATUS_ACCURACY_LOW + * 2 -> sensorManager.SENSOR_STATUS_ACCURACY_MEDIUM + * 3 -> sensorManager.SENSOR_STATUS_ACCURACY_HIGH + * https://developer.android.com/reference/android/hardware/SensorManager + * + * for iOS: + * in degree of the offset + * https://developer.apple.com/documentation/corelocation/clheading + */ accuracy: number; };