parent
b36b8e5555
commit
3c11d784b4
@ -8,18 +8,16 @@ import android.hardware.SensorEvent
|
||||
import android.hardware.SensorEventListener
|
||||
import android.hardware.SensorManager
|
||||
import android.location.Location
|
||||
import android.location.LocationListener
|
||||
import android.location.LocationManager
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.location.LocationListenerCompat
|
||||
import de.mm20.launcher2.ktx.PI
|
||||
import de.mm20.launcher2.ktx.checkPermission
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import de.mm20.launcher2.ktx.checkPermission
|
||||
import kotlinx.coroutines.flow.combine
|
||||
|
||||
class DevicePoseProvider internal constructor(
|
||||
@ -39,7 +37,7 @@ class DevicePoseProvider internal constructor(
|
||||
}
|
||||
|
||||
fun getLocation(minTimeMs: Long = 1000, minDistanceM: Float = 1f) = channelFlow {
|
||||
val locationCallback = LocationListener {
|
||||
val locationCallback = LocationListenerCompat {
|
||||
lastLocation = it
|
||||
updateDeclination(it)
|
||||
trySend(it)
|
||||
@ -54,7 +52,9 @@ class DevicePoseProvider internal constructor(
|
||||
|
||||
val location =
|
||||
(if (hasFineAccess) this@runCatching.getLastKnownLocation(LocationManager.GPS_PROVIDER) else null)
|
||||
?: if (hasCoarseAccess) this@runCatching.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) else null
|
||||
?: if (hasCoarseAccess) this@runCatching.getLastKnownLocation(
|
||||
LocationManager.NETWORK_PROVIDER
|
||||
) else null
|
||||
|
||||
if (location != null) {
|
||||
lastLocation = location
|
||||
@ -87,7 +87,8 @@ class DevicePoseProvider internal constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun getAzimuthDegrees(samplingPeriodUs: Int = SensorManager.SENSOR_DELAY_UI): Flow<Float> = callbackFlow {
|
||||
fun getAzimuthDegrees(samplingPeriodUs: Int = SensorManager.SENSOR_DELAY_UI): Flow<Float> =
|
||||
callbackFlow {
|
||||
val azimuthCallback = object : SensorEventListener {
|
||||
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {}
|
||||
override fun onSensorChanged(event: SensorEvent?) {
|
||||
@ -122,7 +123,10 @@ class DevicePoseProvider internal constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun getHeadingToDegrees(headingEastwardDegrees: Float, samplingPeriodUs: Int = SensorManager.SENSOR_DELAY_UI): Flow<Float> = combine(
|
||||
fun getHeadingToDegrees(
|
||||
headingEastwardDegrees: Float,
|
||||
samplingPeriodUs: Int = SensorManager.SENSOR_DELAY_UI
|
||||
): Flow<Float> = combine(
|
||||
getAzimuthDegrees(samplingPeriodUs),
|
||||
callbackFlow {
|
||||
val upsideDownCallback = object : SensorEventListener {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user