-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into ab_game_rotation_vector_support
- Loading branch information
Showing
23 changed files
with
687 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
buildscript { | ||
val compose_version by extra("1.4.0") | ||
val wear_compose_version by extra("1.0.0") | ||
} | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
plugins { | ||
id("com.android.application") version "7.4.2" apply false | ||
id("com.android.library") version "7.4.2" apply false | ||
id("org.jetbrains.kotlin.android") version "1.8.10" apply false | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...osesensors/src/main/java/com/mutualmobile/composesensors/AmbientTemperatureSensorState.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,76 @@ | ||
package com.mutualmobile.composesensors | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
|
||
/** | ||
* Measures the ambient room temperature in degrees Celsius (°C) | ||
* @param temperature Ambient temperature as determined by sensor (in °C). | ||
* @param isAvailable Whether the current device has an ambient temperature sensor. Defaults to false. | ||
* @param accuracy Accuracy factor of the ambient temperature sensor. Defaults to 0. | ||
*/ | ||
@Immutable | ||
class AmbientTemperatureSensorState internal constructor( | ||
val temperature: Float = 0f, | ||
val isAvailable: Boolean = false, | ||
val accuracy: Int = 0 | ||
) { | ||
override fun toString(): String { | ||
return "AmbientTemperatureSensorState(temperature=$temperature, " + | ||
"isAvailable=$isAvailable, accuracy=$accuracy)" | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
other as AmbientTemperatureSensorState | ||
|
||
if (temperature != other.temperature) return false | ||
if (isAvailable != other.isAvailable) return false | ||
if (accuracy != other.accuracy) return false | ||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = temperature.hashCode() | ||
result = 31 * result + isAvailable.hashCode() | ||
result = 31 * result + accuracy | ||
return result | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Creates and [remember]s instance of [AmbientTemperatureSensorState]. | ||
* @param sensorDelay The rate at which the raw sensor data should be received. | ||
* Defaults to [SensorDelay.Normal]. | ||
* @param onError Callback invoked on every error state. | ||
*/ | ||
@Composable | ||
fun rememberAmbientTemperatureSensorState( | ||
sensorDelay: SensorDelay = SensorDelay.Normal, | ||
onError: (throwable: Throwable) -> Unit = {}, | ||
): AmbientTemperatureSensorState { | ||
val sensorState = rememberSensorState( | ||
sensorType = SensorType.AmbientTemperature, | ||
sensorDelay = sensorDelay, | ||
onError = onError, | ||
) | ||
|
||
val ambientTemperatureSensorState = remember { mutableStateOf(AmbientTemperatureSensorState()) } | ||
|
||
LaunchedEffect(key1 = sensorState, block = { | ||
val sensorStateValues = sensorState.data | ||
if (sensorStateValues.isNotEmpty()) { | ||
ambientTemperatureSensorState.value = AmbientTemperatureSensorState( | ||
temperature = sensorStateValues[0], | ||
isAvailable = sensorState.isAvailable, | ||
accuracy = sensorState.accuracy | ||
) | ||
} | ||
}) | ||
|
||
return ambientTemperatureSensorState.value | ||
} |
88 changes: 88 additions & 0 deletions
88
...ors/src/main/java/com/mutualmobile/composesensors/GeomagneticRotationVectorSensorState.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,88 @@ | ||
package com.mutualmobile.composesensors | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
|
||
/** | ||
* Measures the orientation of a device by providing the three elements of the device's rotation vector. | ||
* @param vectorX Rotation vector component along the x axis. | ||
* @param vectorY Rotation vector component along the y axis. | ||
* @param vectorZ Rotation vector component along the z axis. | ||
* @param isAvailable Whether the current device has a geomagnetic rotation vector sensor. Defaults to false. | ||
* @param accuracy Accuracy factor of the geomagnetic rotation vector sensor. Defaults to 0. | ||
*/ | ||
@Immutable | ||
class GeomagneticRotationVectorSensorState internal constructor( | ||
val vectorX: Float = 0f, | ||
val vectorY: Float = 0f, | ||
val vectorZ: Float = 0f, | ||
val isAvailable: Boolean = false, | ||
val accuracy: Int = 0 | ||
) { | ||
override fun toString(): String { | ||
return "GeomagneticRotationVectorSensorState(vectorX=$vectorX, " + | ||
"vectorY=$vectorY, vectorZ=$vectorZ, isAvailable=$isAvailable, " + | ||
"accuracy=$accuracy)" | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
other as GeomagneticRotationVectorSensorState | ||
|
||
if (vectorX != other.vectorX) return false | ||
if (vectorY != other.vectorY) return false | ||
if (vectorZ != other.vectorZ) return false | ||
if (isAvailable != other.isAvailable) return false | ||
if (accuracy != other.accuracy) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = vectorX.hashCode() | ||
result = 31 * result + vectorY.hashCode() | ||
result = 31 * result + vectorZ.hashCode() | ||
result = 31 * result + isAvailable.hashCode() | ||
result = 31 * result + accuracy | ||
return result | ||
} | ||
} | ||
|
||
/** | ||
* Creates and [remember]s instance of [GeomagneticRotationVectorSensorState]. | ||
* @param sensorDelay The rate at which the raw sensor data should be received. | ||
* Defaults to [SensorDelay.Normal]. | ||
* @param onError Callback invoked on every error state. | ||
*/ | ||
@Composable | ||
fun rememberGeomagneticRotationVectorSensorState( | ||
sensorDelay: SensorDelay = SensorDelay.Normal, | ||
onError: (throwable: Throwable) -> Unit = {}, | ||
): GeomagneticRotationVectorSensorState { | ||
val sensorState = rememberSensorState( | ||
sensorType = SensorType.GeomagneticRotationVector, | ||
sensorDelay = sensorDelay, | ||
onError = onError, | ||
) | ||
|
||
val geomagneticRotationVectorSensorState = | ||
remember { mutableStateOf(GeomagneticRotationVectorSensorState()) } | ||
|
||
LaunchedEffect(key1 = sensorState, block = { | ||
val sensorStateValues = sensorState.data | ||
if (sensorStateValues.isNotEmpty()) { | ||
geomagneticRotationVectorSensorState.value = GeomagneticRotationVectorSensorState( | ||
vectorX = sensorStateValues[0], | ||
vectorY = sensorStateValues[1], | ||
vectorZ = sensorStateValues[2], | ||
isAvailable = sensorState.isAvailable, | ||
accuracy = sensorState.accuracy | ||
) | ||
} | ||
}) | ||
|
||
return geomagneticRotationVectorSensorState.value | ||
} |
77 changes: 77 additions & 0 deletions
77
composesensors/src/main/java/com/mutualmobile/composesensors/HeartRateSensorState.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,77 @@ | ||
package com.mutualmobile.composesensors | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
|
||
/** | ||
* The HeartRate sensor provides the speed at which the current user's heart beats per minute (denoted by BPM). | ||
* @param heartRate Indicates the current heart rate (in BPM). | ||
* @param isAvailable Whether the current device has an heart rate sensor. Defaults to false. | ||
* @param accuracy Accuracy factor of the heart rate sensor. Defaults to 0. | ||
*/ | ||
@Immutable | ||
class HeartRateSensorState internal constructor( | ||
val heartRate: Float = 0f, | ||
val isAvailable: Boolean = false, | ||
val accuracy: Int = 0, | ||
) { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is HeartRateSensorState) return false | ||
|
||
if (heartRate != other.heartRate) return false | ||
if (isAvailable != other.isAvailable) return false | ||
if (accuracy != other.accuracy) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = heartRate.hashCode() | ||
result = 31 * result + isAvailable.hashCode() | ||
result = 31 * result + accuracy.hashCode() | ||
return result | ||
} | ||
|
||
override fun toString(): String { | ||
return "HeartRateSensorState(heartRate=$heartRate isAvailable=$isAvailable, accuracy=$accuracy)" | ||
} | ||
} | ||
|
||
/** | ||
* Creates and [remember]s an instance of [HeartRateSensorState]. | ||
* @param sensorDelay The rate at which the raw sensor data should be received. | ||
* Defaults to [SensorDelay.Normal]. | ||
* @param onError Callback invoked on every error state. | ||
*/ | ||
@Composable | ||
fun rememberHeartRateSensorState( | ||
sensorDelay: SensorDelay = SensorDelay.Normal, | ||
onError: (throwable: Throwable) -> Unit = {}, | ||
): HeartRateSensorState { | ||
val sensorState = rememberSensorState( | ||
sensorType = SensorType.HeartRate, | ||
sensorDelay = sensorDelay, | ||
onError = onError, | ||
) | ||
val heartRateSensorState = remember { mutableStateOf(HeartRateSensorState()) } | ||
|
||
LaunchedEffect( | ||
key1 = sensorState, | ||
block = { | ||
val sensorStateValues = sensorState.data | ||
if (sensorStateValues.isNotEmpty()) { | ||
heartRateSensorState.value = HeartRateSensorState( | ||
heartRate = sensorStateValues[0], | ||
isAvailable = sensorState.isAvailable, | ||
accuracy = sensorState.accuracy, | ||
) | ||
} | ||
}, | ||
) | ||
|
||
return heartRateSensorState.value | ||
} |
Oops, something went wrong.