From b6fecef8215232af518394ddc48b6e9b51348c2c Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Fri, 4 Feb 2022 16:49:14 +0200 Subject: [PATCH 1/2] Improve api-check scripts to show more granular breaking changes. (#1119) * Improve api-check scripts to show more granular breaking changes. * Ignore api-check re directory. * Add comment to execute assembleRelease before running the script. --- .gitignore | 3 ++- Makefile | 3 +++ scripts/java-api-check-all.sh | 11 +++++++++-- scripts/java-api-check.sh | 7 ++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 92c0fdd571..1176d892aa 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,5 @@ android-docs-repo examples.zip release-docs/ release-docs.zip -/tmp/checksum.txt \ No newline at end of file +/tmp/checksum.txt +api_compat_report/ diff --git a/Makefile b/Makefile index 8cd6055b1f..832a3cf2be 100755 --- a/Makefile +++ b/Makefile @@ -28,12 +28,14 @@ build: ./gradlew plugin-lifecycle:assembleRelease; # Use `make checkApi TAG=ReleaseTag` to check the release tag or `make checkApi` to check current branch while running locally. +# Note: if run locally, execute `mbx env` and `./gradlew assembleRelease` first. .PHONY: checkApi checkApi: unset GITHUB_TOKEN; \ echo "$(shell mbx-ci github reader token)" > gh_token.txt;\ sh scripts/java-api-check-all.sh "$(TAG)" +# Note: if run locally, execute `mbx env` first. .PHONY: checkChangelog checkChangelog: unset GITHUB_TOKEN; \ @@ -77,6 +79,7 @@ generate-changelog: # Use `make update-android-docs TAG=YourReleaseTag` while running locally. # Run `make prepare-release-doc` first in the internal repository, +# Note: if run locally, execute `mbx env` first. .PHONY: update-android-docs update-android-docs: unset GITHUB_TOKEN; \ diff --git a/scripts/java-api-check-all.sh b/scripts/java-api-check-all.sh index c1d0979df5..c71cc58f64 100755 --- a/scripts/java-api-check-all.sh +++ b/scripts/java-api-check-all.sh @@ -1,11 +1,14 @@ #!/usr/bin/env bash -set -Eeuxo pipefail +set -Eeuo pipefail # Usage: # ./java-api-check-all.sh # +# Note: if run locally, execute `mbx env` and `./gradlew assembleRelease` first. +# CURRENT_DIR=$(dirname "$0") MAJOR_CHANGE_FILE=${CURRENT_DIR}/../api_compat_report/major.txt +[ -e $MAJOR_CHANGE_FILE ] && rm $MAJOR_CHANGE_FILE REVAPI=`mktemp -d` mkdir -p "${REVAPI}" @@ -44,7 +47,11 @@ rm -rf "${REVAPI}" # Fail the job when there is major changes. if [[ -f "$MAJOR_CHANGE_FILE" ]]; then - echo "Potential major level breaking change found:" + echo "" + echo "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***" + echo "*** *** *** *** Potential major level breaking change found *** *** *** ***" + echo "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***" + echo "" cat "$MAJOR_CHANGE_FILE" exit 1 fi \ No newline at end of file diff --git a/scripts/java-api-check.sh b/scripts/java-api-check.sh index 1d405e5b89..ec4ad0ff8f 100755 --- a/scripts/java-api-check.sh +++ b/scripts/java-api-check.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -Eeuxo pipefail +set -Eeuo pipefail # Usage: # ./java-api-check.sh @@ -140,7 +140,7 @@ compare_aars() { -D revapi.java.non-public-part-of-api.report-unchanged=false \ -D revapi.reporter.json.minSeverity=EQUIVALENT \ -D revapi.reporter.json.output="${json_report}" \ - -D revapi.reporter.text.minSeverity=NON_BREAKING \ + -D revapi.reporter.text.minSeverity=BREAKING \ -D revapi.reporter.text.output="${REPORT_DIR}/api_compat.txt" \ -c ${CURRENT_DIR}/java-api-check.json \ >&2 @@ -163,7 +163,8 @@ rm -rf "${TMPDIR}" echo "Compare result: $api_compat" if [[ $api_compat == major ]]; then - echo "${MODULE_NAME} " >> "${MAJOR_CHANGE_FILE}" + echo "======================== ${MODULE_NAME} ========================" >> "${MAJOR_CHANGE_FILE}" + cat ${REPORT_DIR}/api_compat.txt >> "${MAJOR_CHANGE_FILE}" fi "${CURRENT_DIR}"/semver-check.sh "${TAGGED_RELEASE_VERSION}" "${LAST_VERSION}" "${api_compat}" \ No newline at end of file From d8a1b27a4ea593e79e1ee114130384a99b484588 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Fri, 4 Feb 2022 17:40:59 +0200 Subject: [PATCH 2/2] Revert "Add LocationCompassEngine for location component (#970)" (#1115) This reverts commit 90f5a73a1c3e6a01582d06af061fb5c3512bff7a. --- ...omponentAttributeParserDefaultValueTest.kt | 6 - .../LocationComponentAttributeParserTest.kt | 6 - .../examples/LocationComponentActivity.kt | 11 - .../layout/activity_location_component.xml | 1 - .../generated_test_locationcomponent.xml | 1 - .../main/res/menu/menu_location_component.xml | 15 - app/src/main/res/values/strings.xml | 4 - .../LocationCompassEngine.kt | 305 ------------------ .../LocationComponentPluginImpl.kt | 7 +- .../locationcomponent/LocationProviderImpl.kt | 42 +-- .../LocationComponentAttributeParser.kt | 5 - .../src/main/res-public/values/public.xml | 3 - .../src/main/res/values/attrs.xml | 7 - .../LocationCompassEngineTest.kt | 95 ------ .../LocationComponentPluginImplTest.kt | 7 +- .../LocationProviderImplTest.kt | 43 +-- .../LocationComponentAttributeParserTest.kt | 7 - .../mapbox/maps/plugin/ConfigProperties.kt | 16 - .../generated/LocationComponentSettings.kt | 6 - .../LocationComponentSettingsBase.kt | 13 - .../LocationComponentSettingsInterface.kt | 6 - 21 files changed, 10 insertions(+), 596 deletions(-) delete mode 100644 plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationCompassEngine.kt delete mode 100644 plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationCompassEngineTest.kt diff --git a/app/src/androidTest/java/com/mapbox/maps/testapp/locationcomponent/generated/LocationComponentAttributeParserDefaultValueTest.kt b/app/src/androidTest/java/com/mapbox/maps/testapp/locationcomponent/generated/LocationComponentAttributeParserDefaultValueTest.kt index ebe62c2250..b3cffdf268 100644 --- a/app/src/androidTest/java/com/mapbox/maps/testapp/locationcomponent/generated/LocationComponentAttributeParserDefaultValueTest.kt +++ b/app/src/androidTest/java/com/mapbox/maps/testapp/locationcomponent/generated/LocationComponentAttributeParserDefaultValueTest.kt @@ -5,7 +5,6 @@ package com.mapbox.maps.testapp.locationcomponent.generated import android.graphics.Color import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest -import com.mapbox.maps.plugin.PuckBearingSource import com.mapbox.maps.plugin.locationcomponent.location import com.mapbox.maps.testapp.BaseMapTest import org.junit.Assert.assertEquals @@ -52,11 +51,6 @@ class LocationComponentAttributeParserDefaultValueTest : BaseMapTest() { null, mapView.location.getSettings().layerBelow ) - assertEquals( - "puckBearingSource test failed..", - PuckBearingSource.HEADING, - mapView.location.getSettings().puckBearingSource - ) } } diff --git a/app/src/androidTest/java/com/mapbox/maps/testapp/locationcomponent/generated/LocationComponentAttributeParserTest.kt b/app/src/androidTest/java/com/mapbox/maps/testapp/locationcomponent/generated/LocationComponentAttributeParserTest.kt index 22f0105e2c..58d107570c 100644 --- a/app/src/androidTest/java/com/mapbox/maps/testapp/locationcomponent/generated/LocationComponentAttributeParserTest.kt +++ b/app/src/androidTest/java/com/mapbox/maps/testapp/locationcomponent/generated/LocationComponentAttributeParserTest.kt @@ -6,7 +6,6 @@ import android.graphics.Color import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import com.mapbox.maps.R -import com.mapbox.maps.plugin.PuckBearingSource import com.mapbox.maps.plugin.locationcomponent.location import com.mapbox.maps.testapp.BaseMapTest import org.junit.Assert.assertEquals @@ -62,11 +61,6 @@ class LocationComponentAttributeParserTest : BaseMapTest() { "testString", mapView.location.getSettings().layerBelow ) - assertEquals( - "puckBearingSource test failed..", - PuckBearingSource.HEADING, - mapView.location.getSettings().puckBearingSource - ) // TODO, test for location puck. } } diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/LocationComponentActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/LocationComponentActivity.kt index ecb15f4be8..be6b4ac328 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/LocationComponentActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/LocationComponentActivity.kt @@ -11,7 +11,6 @@ import com.mapbox.maps.Style import com.mapbox.maps.extension.style.expressions.dsl.generated.interpolate import com.mapbox.maps.plugin.LocationPuck2D import com.mapbox.maps.plugin.LocationPuck3D -import com.mapbox.maps.plugin.PuckBearingSource import com.mapbox.maps.plugin.gestures.gestures import com.mapbox.maps.plugin.locationcomponent.* import com.mapbox.maps.testapp.R @@ -101,16 +100,6 @@ class LocationComponentActivity : AppCompatActivity() { } return true } - R.id.heading -> { - binding.mapView.location.updateSettings { puckBearingSource = PuckBearingSource.HEADING } - item.isChecked = true - return true - } - R.id.course -> { - binding.mapView.location.updateSettings { puckBearingSource = PuckBearingSource.COURSE } - item.isChecked = true - return true - } else -> return super.onOptionsItemSelected(item) } } diff --git a/app/src/main/res/layout/activity_location_component.xml b/app/src/main/res/layout/activity_location_component.xml index c95fec4e9c..e6528db6db 100644 --- a/app/src/main/res/layout/activity_location_component.xml +++ b/app/src/main/res/layout/activity_location_component.xml @@ -6,5 +6,4 @@ android:layout_width="match_parent" android:layout_height="match_parent" mapbox:mapbox_locationComponentEnabled = "true" - mapbox:mapbox_locationComponentPuckBearingSource = "heading" tools:context=".examples.LocationComponentActivity" /> \ No newline at end of file diff --git a/app/src/main/res/layout/generated_test_locationcomponent.xml b/app/src/main/res/layout/generated_test_locationcomponent.xml index fefd6d0028..01b1d953b5 100644 --- a/app/src/main/res/layout/generated_test_locationcomponent.xml +++ b/app/src/main/res/layout/generated_test_locationcomponent.xml @@ -9,7 +9,6 @@ mapbox:mapbox_locationComponentPulsingMaxRadius = "10dp" mapbox:mapbox_locationComponentLayerAbove = "testString" mapbox:mapbox_locationComponentLayerBelow = "testString" - mapbox:mapbox_locationComponentPuckBearingSource = "heading" android:layout_width="match_parent" android:layout_height="match_parent" /> \ No newline at end of file diff --git a/app/src/main/res/menu/menu_location_component.xml b/app/src/main/res/menu/menu_location_component.xml index 0f8d3617eb..13489d359a 100644 --- a/app/src/main/res/menu/menu_location_component.xml +++ b/app/src/main/res/menu/menu_location_component.xml @@ -16,7 +16,6 @@ - @@ -24,18 +23,4 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83a512c3fd..595b452a3d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -121,10 +121,6 @@ Make sure that the device\'s default language is not English Map localized to selected language Map localized to device language - - - Bearing source: Heading - Bearing source: Course English Spanish French diff --git a/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationCompassEngine.kt b/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationCompassEngine.kt deleted file mode 100644 index 368b49647f..0000000000 --- a/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationCompassEngine.kt +++ /dev/null @@ -1,305 +0,0 @@ -package com.mapbox.maps.plugin.locationcomponent - -import android.content.Context -import android.hardware.Sensor -import android.hardware.SensorEvent -import android.hardware.SensorEventListener -import android.hardware.SensorManager -import android.os.SystemClock -import android.view.Surface -import android.view.WindowManager -import com.mapbox.common.Logger - -/** - * This class handles compass events and tracking the current device heading. - */ -internal class LocationCompassEngine(context: Context) : SensorEventListener { - private val windowManager: WindowManager = - context.getSystemService(Context.WINDOW_SERVICE) as WindowManager - private val sensorManager: SensorManager = - context.getSystemService(Context.SENSOR_SERVICE) as SensorManager - private val compassListeners = mutableSetOf() - - // Not all devices have a compassSensor - private var compassSensor: Sensor? = null - private var gravitySensor: Sensor? = null - private var magneticFieldSensor: Sensor? = null - - private val rotationMatrix = FloatArray(9) - private var rotationVectorValue: FloatArray? = null - private var compassUpdateNextTimestamp: Long = 0 - private var gravityValues = FloatArray(3) - private var magneticValues = FloatArray(3) - private val orientation = FloatArray(3) - - init { - compassSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR) - if (compassSensor == null) { - Logger.w( - TAG, - "Rotation vector sensor not supported on device, falling back to accelerometer and magnetic field." - ) - gravitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) - magneticFieldSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) - } - } - - fun addCompassListener(compassListener: CompassListener) { - if (compassListeners.isEmpty()) { - registerSensorListeners() - } - compassListeners.add(compassListener) - } - - fun removeCompassListener(compassListener: CompassListener) { - compassListeners.remove(compassListener) - if (compassListeners.isEmpty()) { - unregisterSensorListeners() - } - } - - override fun onSensorChanged(event: SensorEvent) { - when (event.sensor.type) { - Sensor.TYPE_ROTATION_VECTOR -> { - rotationVectorValue = event.values - } - Sensor.TYPE_ACCELEROMETER -> { - gravityValues = lowPassFilter(event.values, gravityValues) - } - Sensor.TYPE_MAGNETIC_FIELD -> { - magneticValues = lowPassFilter(event.values, magneticValues) - } - } - updateOrientation() - } - - override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) { - // no need - } - - private fun updateOrientation() { - // check when the last time the compass was updated, return if too soon. - val currentTime = SystemClock.elapsedRealtime() - if (currentTime < compassUpdateNextTimestamp) { - return - } - if (rotationVectorValue != null) { - SensorManager.getRotationMatrixFromVector(rotationMatrix, rotationVectorValue) - } else { - // Get rotation matrix given the gravity and geomagnetic matrices - SensorManager.getRotationMatrix(rotationMatrix, null, gravityValues, magneticValues) - } - val (worldAxisForDeviceAxisX, worldAxisForDeviceAxisY) = getWorldAxisFromRotation() - val adjustedRotationMatrix = FloatArray(9) - SensorManager.remapCoordinateSystem( - rotationMatrix, worldAxisForDeviceAxisX, - worldAxisForDeviceAxisY, adjustedRotationMatrix - ) - - // Transform rotation matrix into azimuth/pitch/roll - SensorManager.getOrientation(adjustedRotationMatrix, orientation) - val (adjustedWorldAxisForDeviceAxisX, adjustedWorldAxisForDeviceAxisY) = adjustWorldAxis( - orientation, - worldAxisForDeviceAxisX, - worldAxisForDeviceAxisY - ) - SensorManager.remapCoordinateSystem( - rotationMatrix, adjustedWorldAxisForDeviceAxisX, - adjustedWorldAxisForDeviceAxisY, adjustedRotationMatrix - ) - - // Transform rotation matrix into azimuth/pitch/roll - SensorManager.getOrientation(adjustedRotationMatrix, orientation) - - // The x-axis is all we care about here. - notifyCompassChangeListeners(Math.toDegrees(orientation[0].toDouble()).toFloat()) - - // Update the compassUpdateNextTimestamp - compassUpdateNextTimestamp = currentTime + LocationComponentConstants.COMPASS_UPDATE_RATE_MS - } - - private fun adjustWorldAxis( - orientation: FloatArray, - worldAxisForDeviceAxisX: Int, - worldAxisForDeviceAxisY: Int - ): Pair { - var worldAxisForDeviceAxisX1 = worldAxisForDeviceAxisX - var worldAxisForDeviceAxisY1 = worldAxisForDeviceAxisY - when { - orientation[1] < -Math.PI / 4 -> { - // The pitch is less than -45 degrees. - // Remap the axes as if the device screen was the instrument panel. - when (windowManager.defaultDisplay.rotation) { - Surface.ROTATION_90 -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_Z - worldAxisForDeviceAxisY1 = SensorManager.AXIS_MINUS_X - } - Surface.ROTATION_180 -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_MINUS_X - worldAxisForDeviceAxisY1 = SensorManager.AXIS_MINUS_Z - } - Surface.ROTATION_270 -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_MINUS_Z - worldAxisForDeviceAxisY1 = SensorManager.AXIS_X - } - else -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_X - worldAxisForDeviceAxisY1 = SensorManager.AXIS_Z - } - } - } - orientation[1] > Math.PI / 4 -> { - // The pitch is larger than 45 degrees. - // Remap the axes as if the device screen was upside down and facing back. - when (windowManager.defaultDisplay.rotation) { - Surface.ROTATION_90 -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_MINUS_Z - worldAxisForDeviceAxisY1 = SensorManager.AXIS_MINUS_X - } - Surface.ROTATION_180 -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_MINUS_X - worldAxisForDeviceAxisY1 = SensorManager.AXIS_Z - } - Surface.ROTATION_270 -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_Z - worldAxisForDeviceAxisY1 = SensorManager.AXIS_X - } - else -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_X - worldAxisForDeviceAxisY1 = SensorManager.AXIS_MINUS_Z - } - } - } - Math.abs(orientation[2]) > Math.PI / 2 -> { - // The roll is less than -90 degrees, or is larger than 90 degrees. - // Remap the axes as if the device screen was face down. - when (windowManager.defaultDisplay.rotation) { - Surface.ROTATION_90 -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_MINUS_Y - worldAxisForDeviceAxisY1 = SensorManager.AXIS_MINUS_X - } - Surface.ROTATION_180 -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_MINUS_X - worldAxisForDeviceAxisY1 = SensorManager.AXIS_Y - } - Surface.ROTATION_270 -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_Y - worldAxisForDeviceAxisY1 = SensorManager.AXIS_X - } - else -> { - worldAxisForDeviceAxisX1 = SensorManager.AXIS_X - worldAxisForDeviceAxisY1 = SensorManager.AXIS_MINUS_Y - } - } - } - } - return worldAxisForDeviceAxisX1 to worldAxisForDeviceAxisY1 - } - - private fun getWorldAxisFromRotation(): Pair { - var worldAxisForDeviceAxisX: Int - var worldAxisForDeviceAxisY: Int - when (windowManager.defaultDisplay.rotation) { - Surface.ROTATION_90 -> { - worldAxisForDeviceAxisX = SensorManager.AXIS_Y - worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_X - } - Surface.ROTATION_180 -> { - worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_X - worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_Y - } - Surface.ROTATION_270 -> { - worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_Y - worldAxisForDeviceAxisY = SensorManager.AXIS_X - } - else -> { - worldAxisForDeviceAxisX = SensorManager.AXIS_X - worldAxisForDeviceAxisY = SensorManager.AXIS_Y - } - } - return worldAxisForDeviceAxisX to worldAxisForDeviceAxisY - } - - private fun notifyCompassChangeListeners(heading: Float) { - for (compassListener in compassListeners) { - compassListener.onCompassChanged(heading) - } - } - - private fun registerSensorListeners() { - if (isCompassSensorAvailable()) { - // Does nothing if the sensors already registered. - sensorManager.registerListener( - this, - compassSensor, - SENSOR_DELAY_MICROS - ) - } else { - sensorManager.registerListener( - this, - gravitySensor, - SENSOR_DELAY_MICROS - ) - sensorManager.registerListener( - this, - magneticFieldSensor, - SENSOR_DELAY_MICROS - ) - } - } - - private fun unregisterSensorListeners() { - if (isCompassSensorAvailable()) { - sensorManager.unregisterListener(this, compassSensor) - } else { - sensorManager.unregisterListener(this, gravitySensor) - sensorManager.unregisterListener(this, magneticFieldSensor) - } - } - - private fun isCompassSensorAvailable() = compassSensor != null - - /** - * Helper function, that filters newValues, considering previous values - * - * @param newValues array of float, that contains new data - * @param smoothedValues array of float, that contains previous state - * @return float filtered array of float - */ - private fun lowPassFilter(newValues: FloatArray, smoothedValues: FloatArray?): FloatArray { - if (smoothedValues == null) { - return newValues - } - for (i in newValues.indices) { - smoothedValues[i] = - smoothedValues[i] + ALPHA * (newValues[i] - smoothedValues[i]) - } - return smoothedValues - } - - /** - * Callback to receive compass update event - */ - fun interface CompassListener { - /** - * Callback's invoked when a new compass update occurs. - * - * @param userHeading the new compass heading - */ - fun onCompassChanged(userHeading: Float) - } - - private companion object { - private const val TAG = "LocationCompassProvider" - - // The rate sensor events will be delivered at. As the Android documentation states, this is only - // a hint to the system and the events might actually be received faster or slower then this - // specified rate. Since the minimum Android API levels about 9, we are able to set this value - // ourselves rather than using one of the provided constants which deliver updates too quickly for - // our use case. The default is set to 100ms - private const val SENSOR_DELAY_MICROS = 100 * 1000 - - // Filtering coefficient 0 < ALPHA < 1 - private const val ALPHA = 0.45f - } -} \ No newline at end of file diff --git a/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationComponentPluginImpl.kt b/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationComponentPluginImpl.kt index 070efc1c5f..47e96fda76 100644 --- a/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationComponentPluginImpl.kt +++ b/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationComponentPluginImpl.kt @@ -216,7 +216,7 @@ class LocationComponentPluginImpl : LocationComponentPlugin, LocationConsumer, internalSettings = LocationComponentAttributeParser.parseLocationComponentSettings(context, attrs, pixelRatio) if (internalSettings.enabled && locationProvider == null) { - locationProvider = LocationProviderImpl(context, internalSettings) + locationProvider = LocationProviderImpl(context) } } @@ -298,15 +298,12 @@ class LocationComponentPluginImpl : LocationComponentPlugin, LocationConsumer, if (internalSettings.enabled && !isLocationComponentActivated) { context.get()?.let { if (locationProvider == null) { - locationProvider = LocationProviderImpl(it, internalSettings) + locationProvider = LocationProviderImpl(it) } activateLocationComponent() } } if (internalSettings.enabled) { - if (locationProvider is LocationProviderImpl) { - (locationProvider as LocationProviderImpl).updateSettings(internalSettings) - } locationPuckManager?.updateSettings(internalSettings) } else { deactivateLocationComponent() diff --git a/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationProviderImpl.kt b/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationProviderImpl.kt index 29f30662c2..b22358d039 100644 --- a/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationProviderImpl.kt +++ b/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LocationProviderImpl.kt @@ -12,21 +12,17 @@ import com.mapbox.android.core.location.LocationEngineResult import com.mapbox.android.core.permissions.PermissionsManager import com.mapbox.common.Logger import com.mapbox.geojson.Point -import com.mapbox.maps.plugin.PuckBearingSource -import com.mapbox.maps.plugin.locationcomponent.generated.LocationComponentSettings import java.lang.ref.WeakReference import java.util.concurrent.CopyOnWriteArrayList /** * Default Location Provider implementation, it can be overwritten by users. */ -internal class LocationProviderImpl(context: Context, var settings: LocationComponentSettings) : - LocationProvider, - LocationEngineCallback, - LocationCompassEngine.CompassListener { +internal class LocationProviderImpl(context: Context) : + LocationProvider, LocationEngineCallback { private val contextWeekRef: WeakReference = WeakReference(context) private val locationEngine = LocationEngineProvider.getBestLocationEngine(context) - private val locationCompassEngine = LocationCompassEngine(context) + private val locationEngineRequest = LocationEngineRequest.Builder(LocationComponentConstants.DEFAULT_INTERVAL_MILLIS) .setFastestInterval(LocationComponentConstants.DEFAULT_FASTEST_INTERVAL_MILLIS) @@ -34,15 +30,11 @@ internal class LocationProviderImpl(context: Context, var settings: LocationComp .build() private val locationConsumers = CopyOnWriteArrayList() - private var currentPuckBearingSource: PuckBearingSource = PuckBearingSource.COURSE + private var handler: Handler? = null private lateinit var runnable: Runnable private var updateDelay = INIT_UPDATE_DELAY - init { - updateCompass() - } - @SuppressLint("MissingPermission") private fun requestLocationUpdates() { if (PermissionsManager.areLocationPermissionsGranted(contextWeekRef.get())) { @@ -70,31 +62,7 @@ internal class LocationProviderImpl(context: Context, var settings: LocationComp private fun notifyLocationUpdates(location: Location) { locationConsumers.forEach { consumer -> consumer.onLocationUpdated(Point.fromLngLat(location.longitude, location.latitude)) - if (currentPuckBearingSource == PuckBearingSource.COURSE) { - consumer.onBearingUpdated(location.bearing.toDouble()) - } - } - } - - fun updateSettings(settings: LocationComponentSettings) { - this.settings = settings - updateCompass() - } - - private fun updateCompass() { - if (settings.puckBearingSource == currentPuckBearingSource) { - return - } - when (settings.puckBearingSource) { - PuckBearingSource.HEADING -> locationCompassEngine.addCompassListener(this) - PuckBearingSource.COURSE -> locationCompassEngine.removeCompassListener(this) - } - currentPuckBearingSource = settings.puckBearingSource - } - - override fun onCompassChanged(userHeading: Float) { - locationConsumers.forEach { consumer -> - consumer.onBearingUpdated(userHeading.toDouble()) + consumer.onBearingUpdated(location.bearing.toDouble()) } } diff --git a/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentAttributeParser.kt b/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentAttributeParser.kt index 03b8552922..a22ee87a45 100644 --- a/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentAttributeParser.kt +++ b/plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentAttributeParser.kt @@ -8,7 +8,6 @@ import android.util.AttributeSet import androidx.core.content.res.ResourcesCompat import com.mapbox.maps.plugin.LocationPuck2D import com.mapbox.maps.plugin.LocationPuck3D -import com.mapbox.maps.plugin.PuckBearingSource import com.mapbox.maps.plugin.locationcomponent.R /** @@ -31,10 +30,6 @@ internal object LocationComponentAttributeParser { pulsingMaxRadius = typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_locationComponentPulsingMaxRadius, 10f * pixelRatio), layerAbove = typedArray.getString(R.styleable.mapbox_MapView_mapbox_locationComponentLayerAbove), layerBelow = typedArray.getString(R.styleable.mapbox_MapView_mapbox_locationComponentLayerBelow), - puckBearingSource = when (typedArray.getInt(R.styleable.mapbox_MapView_mapbox_locationComponentPuckBearingSource, 0)) { - 1 -> PuckBearingSource.COURSE - else -> PuckBearingSource.HEADING - }, locationPuck = when (typedArray.getInt(R.styleable.mapbox_MapView_mapbox_locationComponentLocationPuck, -1)) { 0 -> LocationPuck2D( topImage = typedArray.getDrawable(R.styleable.mapbox_MapView_mapbox_locationComponentLocationPuckLocationPuck2DTopImage), diff --git a/plugin-locationcomponent/src/main/res-public/values/public.xml b/plugin-locationcomponent/src/main/res-public/values/public.xml index 3c530a4c9d..e3d15ca281 100644 --- a/plugin-locationcomponent/src/main/res-public/values/public.xml +++ b/plugin-locationcomponent/src/main/res-public/values/public.xml @@ -20,9 +20,6 @@ - - - diff --git a/plugin-locationcomponent/src/main/res/values/attrs.xml b/plugin-locationcomponent/src/main/res/values/attrs.xml index 42c599f4d2..91a0c64f71 100644 --- a/plugin-locationcomponent/src/main/res/values/attrs.xml +++ b/plugin-locationcomponent/src/main/res/values/attrs.xml @@ -14,13 +14,6 @@ - - - - - - - diff --git a/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationCompassEngineTest.kt b/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationCompassEngineTest.kt deleted file mode 100644 index 703ad8307f..0000000000 --- a/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationCompassEngineTest.kt +++ /dev/null @@ -1,95 +0,0 @@ -package com.mapbox.maps.plugin.locationcomponent - -import android.content.Context -import android.hardware.Sensor -import android.hardware.SensorManager -import android.view.WindowManager -import com.mapbox.common.ShadowLogger -import io.mockk.every -import io.mockk.mockk -import io.mockk.verify -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - -@RunWith(RobolectricTestRunner::class) -@Config(shadows = [ShadowLogger::class]) -class LocationCompassEngineTest { - private val windowManager = mockk() - private val sensorManager = mockk(relaxed = true) - private val context = mockk() - private val compassSensor = mockk() - private val gravitySensor = mockk() - private val magneticFieldSensor = mockk() - private val compassListener = mockk() - private lateinit var locationCompassEngine: LocationCompassEngine - - @Before - fun setUp() { - every { sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR) } returns compassSensor - every { sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) } returns gravitySensor - every { sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) } returns magneticFieldSensor - every { context.getSystemService(Context.WINDOW_SERVICE) } returns windowManager - every { context.getSystemService(Context.SENSOR_SERVICE) } returns sensorManager - } - - @Test - fun supportRotationVectorSensor() { - locationCompassEngine = LocationCompassEngine(context) - verify(exactly = 1) { sensorManager.getDefaultSensor(any()) } - verify(exactly = 0) { sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) } - verify(exactly = 0) { sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) } - } - - @Test - fun notSupportRotationVectorSensor() { - every { sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR) } returns null - locationCompassEngine = LocationCompassEngine(context) - verify(exactly = 1) { sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) } - verify(exactly = 1) { sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) } - } - - @Test - fun addListenerWhileSupportRotationVectorSensor() { - locationCompassEngine = LocationCompassEngine(context) - locationCompassEngine.addCompassListener(compassListener) - verify(exactly = 1) { sensorManager.registerListener(any(), compassSensor, any()) } - verify(exactly = 0) { sensorManager.registerListener(any(), gravitySensor, any()) } - verify(exactly = 0) { sensorManager.registerListener(any(), magneticFieldSensor, any()) } - } - - @Test - fun removeListenerWhileSupportRotationVectorSensor() { - locationCompassEngine = LocationCompassEngine(context) - locationCompassEngine.addCompassListener(compassListener) - locationCompassEngine.addCompassListener(compassListener) - locationCompassEngine.addCompassListener(compassListener) - locationCompassEngine.removeCompassListener(compassListener) - verify(exactly = 1) { sensorManager.unregisterListener(any(), compassSensor) } - verify(exactly = 0) { sensorManager.unregisterListener(any(), gravitySensor) } - verify(exactly = 0) { sensorManager.unregisterListener(any(), magneticFieldSensor) } - } - - @Test - fun addListenerWhileNotSupportRotationVectorSensor() { - every { sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR) } returns null - locationCompassEngine = LocationCompassEngine(context) - locationCompassEngine.addCompassListener(compassListener) - verify(exactly = 0) { sensorManager.registerListener(any(), compassSensor, any()) } - verify(exactly = 1) { sensorManager.registerListener(any(), gravitySensor, any()) } - verify(exactly = 1) { sensorManager.registerListener(any(), magneticFieldSensor, any()) } - } - - @Test - fun removeListenerWhileNotSupportRotationVectorSensor() { - every { sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR) } returns null - locationCompassEngine = LocationCompassEngine(context) - locationCompassEngine.addCompassListener(compassListener) - locationCompassEngine.removeCompassListener(compassListener) - verify(exactly = 0) { sensorManager.unregisterListener(any(), compassSensor) } - verify(exactly = 1) { sensorManager.unregisterListener(any(), gravitySensor) } - verify(exactly = 1) { sensorManager.unregisterListener(any(), magneticFieldSensor) } - } -} \ No newline at end of file diff --git a/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationComponentPluginImplTest.kt b/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationComponentPluginImplTest.kt index 14dcf0edae..38ba811417 100644 --- a/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationComponentPluginImplTest.kt +++ b/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationComponentPluginImplTest.kt @@ -5,9 +5,7 @@ import android.content.Context import android.content.res.TypedArray import android.graphics.Color import android.graphics.drawable.Drawable -import android.hardware.SensorManager import android.util.AttributeSet -import android.view.WindowManager import com.mapbox.android.core.location.LocationEngine import com.mapbox.android.core.location.LocationEngineProvider import com.mapbox.bindgen.ExpectedFactory @@ -41,8 +39,7 @@ class LocationComponentPluginImplTest { private val typedArray = mockk(relaxed = true) private val pack = "com.mapbox.maps" private val drawable = mockk(relaxed = true) - private val windowManager = mockk(relaxed = true) - private val sensorManager = mockk(relaxed = true) + private val locationEngine = mockk(relaxed = true) private val styleCallbackSlot = slot<(StyleInterface) -> Unit>() @@ -56,8 +53,6 @@ class LocationComponentPluginImplTest { every { context.obtainStyledAttributes(any(), any(), 0, 0) } returns typedArray every { context.packageName } returns pack - every { context.getSystemService(Context.WINDOW_SERVICE) } returns windowManager - every { context.getSystemService(Context.SENSOR_SERVICE) } returns sensorManager every { typedArray.getString(any()) } returns "pk.token" every { typedArray.getInt(any(), any()) } returns -1 every { typedArray.getBoolean(any(), any()) } returns true diff --git a/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationProviderImplTest.kt b/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationProviderImplTest.kt index e7759af70e..7f15fec8b5 100644 --- a/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationProviderImplTest.kt +++ b/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LocationProviderImplTest.kt @@ -1,15 +1,11 @@ package com.mapbox.maps.plugin.locationcomponent import android.content.Context -import android.hardware.SensorManager import android.location.Location -import android.view.WindowManager import com.mapbox.android.core.location.* import com.mapbox.android.core.permissions.PermissionsManager import com.mapbox.common.ShadowLogger import com.mapbox.geojson.Point -import com.mapbox.maps.plugin.PuckBearingSource -import com.mapbox.maps.plugin.locationcomponent.generated.LocationComponentSettings import io.mockk.* import org.junit.Assert.assertEquals import org.junit.Before @@ -22,12 +18,10 @@ import org.robolectric.annotation.Config @Config(shadows = [ShadowLogger::class]) class LocationProviderImplTest { private val context = mockk(relaxed = true) - private val windowManager = mockk(relaxed = true) - private val sensorManager = mockk(relaxed = true) private val locationEngine = mockk(relaxed = true) private val locationConsumer1 = mockk(relaxed = true) private val locationConsumer2 = mockk(relaxed = true) - private val locationComponentSettings = LocationComponentSettings(locationPuck = mockk()) + private val locationEngineRequestSlot = CapturingSlot() private val locationEngineCallbackSlot = CapturingSlot>() @@ -37,11 +31,8 @@ class LocationProviderImplTest { @Before fun setup() { mockkStatic(LocationEngineProvider::class) - every { context.getSystemService(Context.WINDOW_SERVICE) } returns windowManager - every { context.getSystemService(Context.SENSOR_SERVICE) } returns sensorManager every { LocationEngineProvider.getBestLocationEngine(context) } returns locationEngine - locationComponentSettings.puckBearingSource = PuckBearingSource.COURSE - locationProviderImpl = LocationProviderImpl(context, locationComponentSettings) + locationProviderImpl = LocationProviderImpl(context) } @Test @@ -165,34 +156,4 @@ class LocationProviderImplTest { verify { locationConsumer2.onLocationUpdated(Point.fromLngLat(12.0, 34.0)) } verify { locationConsumer2.onBearingUpdated(90.0) } } - - @Test - fun testLocationUpdateWithCompass() { - locationComponentSettings.puckBearingSource = PuckBearingSource.HEADING - locationProviderImpl = LocationProviderImpl(context, locationComponentSettings) - val locationEngineResult = mockk(relaxed = true) - val location = mockk(relaxed = true) - every { locationEngineResult.lastLocation } returns location - every { location.longitude } returns 12.0 - every { location.latitude } returns 34.0 - every { location.bearing } returns 90.0f - - locationProviderImpl.registerLocationConsumer(locationConsumer1) - locationProviderImpl.registerLocationConsumer(locationConsumer2) - verify(exactly = 1) { - locationEngine.requestLocationUpdates( - any(), - capture(locationEngineCallbackSlot), - any() - ) - } - locationEngineCallbackSlot.captured.onSuccess(locationEngineResult) - verify { locationConsumer1.onLocationUpdated(Point.fromLngLat(12.0, 34.0)) } - verify(exactly = 0) { locationConsumer1.onBearingUpdated(90.0) } - verify { locationConsumer2.onLocationUpdated(Point.fromLngLat(12.0, 34.0)) } - verify(exactly = 0) { locationConsumer2.onBearingUpdated(90.0) } - locationProviderImpl.onCompassChanged(90.0f) - verify { locationConsumer1.onBearingUpdated(90.0) } - verify { locationConsumer2.onBearingUpdated(90.0) } - } } \ No newline at end of file diff --git a/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentAttributeParserTest.kt b/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentAttributeParserTest.kt index 5717747220..6db55ead76 100644 --- a/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentAttributeParserTest.kt +++ b/plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentAttributeParserTest.kt @@ -7,7 +7,6 @@ import android.content.res.TypedArray import android.graphics.Color import android.graphics.drawable.Drawable import android.util.AttributeSet -import com.mapbox.maps.plugin.PuckBearingSource import io.mockk.Runs import io.mockk.clearAllMocks import io.mockk.every @@ -124,12 +123,6 @@ class LocationComponentAttributeParserTest { val settings = LocationComponentAttributeParser.parseLocationComponentSettings(context, attrs, 1.2f) assertEquals(null, settings.layerBelow) } - @Test - fun puckBearingSourceTest() { - every { typedArray.getInt(any(), any()) } returns PuckBearingSource.HEADING.ordinal - val settings = LocationComponentAttributeParser.parseLocationComponentSettings(context, attrs, 1.2f) - assertEquals(PuckBearingSource.HEADING, settings.puckBearingSource) - } } // End of generated file. \ No newline at end of file diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/ConfigProperties.kt b/sdk-base/src/main/java/com/mapbox/maps/plugin/ConfigProperties.kt index 3ef6c912f5..3191f28216 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/ConfigProperties.kt +++ b/sdk-base/src/main/java/com/mapbox/maps/plugin/ConfigProperties.kt @@ -24,22 +24,6 @@ enum class ScrollMode(val value: String) { HORIZONTAL_AND_VERTICAL("horizontal-and-vertical"), } -/** - * The enum controls how the puck is oriented - * - * @param value String value of this property - */ -enum class PuckBearingSource(val value: String) { - /** - * Orients the puck to match the direction in which the device is facing. - */ - HEADING("heading"), - /** - * Orients the puck to match the direction in which the device is moving. - */ - COURSE("course"), -} - /** * Sealed class representing a location-puck. */ diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettings.kt b/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettings.kt index 2cfd4f138b..f73f535c86 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettings.kt +++ b/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettings.kt @@ -4,7 +4,6 @@ package com.mapbox.maps.plugin.locationcomponent.generated import android.graphics.Color import com.mapbox.maps.plugin.LocationPuck -import com.mapbox.maps.plugin.PuckBearingSource /** * Shows a location puck on the map. */ @@ -40,11 +39,6 @@ data class LocationComponentSettings @JvmOverloads constructor( */ var layerBelow: String? = null, - /** - * The enum controls how the puck is oriented - */ - var puckBearingSource: PuckBearingSource = PuckBearingSource.HEADING, - /** * Defines what the customised look of the location puck. */ diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettingsBase.kt b/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettingsBase.kt index 1686ed46dd..2b97584450 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettingsBase.kt +++ b/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettingsBase.kt @@ -3,7 +3,6 @@ package com.mapbox.maps.plugin.locationcomponent.generated import com.mapbox.maps.plugin.LocationPuck -import com.mapbox.maps.plugin.PuckBearingSource /** * Abstract settings class for LocationComponentPlugin. @@ -112,18 +111,6 @@ abstract class LocationComponentSettingsBase : LocationComponentSettingsInterfac applySettings() } - /** - * The enum controls how the puck is oriented - */ - override var puckBearingSource: PuckBearingSource - get() { - return this.internalSettings.puckBearingSource - } - set(value) { - this.internalSettings.puckBearingSource = value - applySettings() - } - /** * Defines what the customised look of the location puck. */ diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettingsInterface.kt b/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettingsInterface.kt index ab8d10f980..ac4228007b 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettingsInterface.kt +++ b/sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettingsInterface.kt @@ -3,7 +3,6 @@ package com.mapbox.maps.plugin.locationcomponent.generated import com.mapbox.maps.plugin.LocationPuck -import com.mapbox.maps.plugin.PuckBearingSource /** * Interface that defines the public settings interface for LocationComponentPlugin. @@ -53,11 +52,6 @@ interface LocationComponentSettingsInterface { */ var layerBelow: String? - /** - * The enum controls how the puck is oriented - */ - var puckBearingSource: PuckBearingSource - /** * Defines what the customised look of the location puck. */