-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from XYOracleNetwork/feature/android-location-…
…payload-raw raw location payload
- Loading branch information
Showing
9 changed files
with
201 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationPayloadRaw.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package network.xyo.client.witness.location.info | ||
|
||
import android.os.Bundle | ||
import com.squareup.moshi.JsonClass | ||
import network.xyo.client.payload.XyoPayload | ||
|
||
// Extension function for safely retrieving typed values from a Bundle | ||
private fun Bundle.getTypedValue(key: String): Any? { | ||
return when { | ||
containsKey(key) -> { | ||
when { | ||
getString(key) != null -> getString(key) | ||
getInt(key, Int.MIN_VALUE) != Int.MIN_VALUE -> getInt(key) | ||
getLong(key, Long.MIN_VALUE) != Long.MIN_VALUE -> getLong(key) | ||
getFloat(key, Float.MIN_VALUE) != Float.MIN_VALUE -> getFloat(key) | ||
getDouble(key, Double.MIN_VALUE) != Double.MIN_VALUE -> getDouble(key) | ||
getBoolean(key) -> getBoolean(key) | ||
else -> null | ||
} | ||
} | ||
else -> null | ||
} | ||
} | ||
|
||
@JsonClass(generateAdapter = true) | ||
open class XyoLocationPayloadRaw( | ||
val provider: String?, | ||
val latitude: Double, | ||
val longitude: Double, | ||
val altitude: Double, | ||
val accuracy: Float?, | ||
val bearing: Float?, | ||
val bearingAccuracyDegrees: Float?, | ||
val speed: Float?, | ||
val speedAccuracyMetersPerSecond: Float?, | ||
val verticalAccuracyMeters: Float?, | ||
val time: Long, | ||
val isMock: Boolean?, | ||
val extras: Map<String, Any?>? = null | ||
): XyoPayload() { | ||
override var schema: String | ||
get() = "network.xyo.location.android.raw" | ||
set(value) = Unit | ||
|
||
override fun hash(): String { | ||
return sha256String(this) | ||
} | ||
|
||
|
||
companion object { | ||
fun detect( | ||
provider: String?, | ||
latitude: Double, | ||
longitude: Double, | ||
altitude: Double, | ||
accuracy: Float?, | ||
bearing: Float?, | ||
bearingAccuracyDegrees: Float?, | ||
speed: Float?, | ||
speedAccuracyMetersPerSecond: Float?, | ||
verticalAccuracyMeters: Float?, | ||
time: Long, | ||
isMock: Boolean?, | ||
extras: Bundle? = null | ||
): XyoLocationPayloadRaw { | ||
val extrasMap = extras?.keySet()?.associateWith { key -> | ||
extras.getTypedValue(key) | ||
} | ||
|
||
return XyoLocationPayloadRaw( | ||
provider, | ||
latitude, | ||
longitude, | ||
altitude, | ||
accuracy, | ||
bearing, | ||
bearingAccuracyDegrees, | ||
speed, | ||
speedAccuracyMetersPerSecond, | ||
verticalAccuracyMeters, | ||
time, | ||
isMock, | ||
extrasMap | ||
) | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationPayloads.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package network.xyo.client.witness.location.info | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
|
||
class XyoLocationPayloads { | ||
companion object { | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
@SuppressLint("MissingPermission") | ||
suspend fun detect(context: Context): Pair<XyoLocationPayload, XyoLocationPayloadRaw>? { | ||
return XyoLocationCurrent.detect(context) | ||
} | ||
} | ||
} |
Oops, something went wrong.