{"id":21611088,"url":"https://github.com/ricknout/compose-sensors","last_synced_at":"2025-04-11T05:24:01.140Z","repository":{"id":159827841,"uuid":"628972474","full_name":"ricknout/compose-sensors","owner":"ricknout","description":"A thin wrapper around the Android Sensor APIs, designed to make it easier to work with them in Jetpack Compose.","archived":false,"fork":false,"pushed_at":"2023-05-25T08:26:56.000Z","size":2588,"stargazers_count":99,"open_issues_count":3,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T03:27:30.641Z","etag":null,"topics":["android","android-library","android-sensors","jetpack-compose"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ricknout.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-17T11:10:03.000Z","updated_at":"2024-10-12T04:32:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"2843b5d3-b630-43f4-b3cd-d4ccd07c10b6","html_url":"https://github.com/ricknout/compose-sensors","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricknout%2Fcompose-sensors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricknout%2Fcompose-sensors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricknout%2Fcompose-sensors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricknout%2Fcompose-sensors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ricknout","download_url":"https://codeload.github.com/ricknout/compose-sensors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248346553,"owners_count":21088474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","android-sensors","jetpack-compose"],"created_at":"2024-11-24T21:10:55.807Z","updated_at":"2025-04-11T05:24:01.124Z","avatar_url":"https://github.com/ricknout.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compose Sensors\n\nThis library is a thin wrapper around the [Android Sensor APIs](https://developer.android.com/guide/topics/sensors/sensors_overview),\ndesigned to make it easier to work with them in [Jetpack Compose](https://developer.android.com/jetpack/compose).\n\n| ![Accelerometer](art/accelerometer.gif) | ![Light](art/light.gif) | ![Proximity](art/proximity.gif) |\n|-----------------------------------------|-------------------------|---------------------------------|\n\n## Usage\n\n### Dependency\n\nIn module `build.gralde.kts` file:\n\n```kotlin\ndependencies {\n    implementation(\"dev.ricknout.composesensors:composesensors:$version\")\n}\n```\n\nThe library is available via `mavenCentral()`. Versions can be found on the [releases page](https://github.com/ricknout/compose-sensors/releases).\n\n### Core APIs\n\nThe core APIs provide composable access to the Android sensor framework classes:\n\n```kotlin\n// Get the SensorManager\nval sensorManager = getSensorManager()\n\n// Check if a certain type of sensor is available\nval available = isSensorAvailable(type = Sensor.TYPE_ACCELEROMETER)\n\n// Get a sensor\nval sensor = getSensor(type = Sensor.TYPE_ACCELEROMETER)\n\n// Remember a sensor value as State that updates as SensorEvents arrive\nval sensorValue by rememberSensorValueAsState(type = Sensor.TYPE_ACCELEROMETER) { event -\u003e\n    // Transform SensorEvents\n}\n```\n\n### Per-sensor APIs\n\nThe per-sensor APIs build on the core APIs and provide convenience by:\n* Not having to pass the sensor `type` parameter\n* Handling the transformation of `SensorEvent`s for each type of sensor, by using the `SensorValue` class\n\n```kotlin\n// Check if accelerometer sensor is available\nval available = isAccelerometerSensorAvailable()\n\n// Get accelerometer sensor\nval sensor = getAccelerometerSensor()\n\n// Remember accelerometer sensor value as State that updates as SensorEvents arrive\nval sensorValue by rememberAccelerometerSensorValueAsState()\n// Accelerometer sensor values. Also available: sensorValue.timestamp, sensorValue.accuracy\nval (x, y, z) = sensorValue.value\n```\n\nThe following sensor types are available:\n\n| Type                    | Availability                          | Sensor                        | Sensor value                                   |\n|-------------------------|---------------------------------------|-------------------------------|------------------------------------------------|\n| ⏩ Accelerometer         | `isAccelerometerSensorAvailable`      | `getAccelerometerSensor`      | `rememberAccelerometerSensorValueAsState`      |\n| 🌡️ Ambient Temperature | `isAmbientTemperatureSensorAvailable` | `getAmbientTemperatureSensor` | `rememberAmbientTemperatureSensorValueAsState` |\n| ⏬ Gravity               | `isGravitySensorAvailable`            | `getGravitySensor`            | `rememberGravitySensorValueAsState`            |\n| 🔄 Gyroscope            | `isGyroscopeSensorAvailable`          | `getGyroscopeSensor`          | `rememberGyroscopeSensorValueAsState`          |\n| 💡 Light                | `isLightSensorAvailable`              | `getLightSensor`              | `rememberLightSensorValueAsState`              |\n| ⏪ Linear Acceleration   | `isLinearAccelerationSensorAvailable` | `getLinearAccelerationSensor` | `rememberLinearAccelerationSensorValueAsState` |\n| 🧲 Magnetic field       | `isMagneticFieldSensorAvailable`      | `getMagneticFieldSensor`      | `rememberMagneticFieldSensorValueAsState`      |\n| 💨 Pressure             | `isPressureSensorAvailable`           | `getPressureSensor`           | `rememberPressureSensorValueAsState`           |\n| 🔛 Proximity            | `isProximitySensorAvailable`          | `getProximitySensor`          | `rememberProximitySensorValueAsState`          |\n| 💧 Relative Humidity    | `isRelativeHumiditySensorAvailable`   | `getRelativeHumiditySensor`   | `rememberRelativeHumiditySensorValueAsState`   |\n\nWatch this space, more types to come!\n\n## License\n\n```\nCopyright 2023 Nick Rout\n\nLicensed to the Apache Software Foundation (ASF) under one or more contributor\nlicense agreements. See the NOTICE file distributed with this work for\nadditional information regarding copyright ownership. The ASF licenses this\nfile to you under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License. You may obtain a copy of\nthe License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\nLicense for the specific language governing permissions and limitations under\nthe License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricknout%2Fcompose-sensors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fricknout%2Fcompose-sensors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricknout%2Fcompose-sensors/lists"}