All Projects → dvoiss → Sensorannotations

dvoiss / Sensorannotations

Licence: apache-2.0
Android - Annotate methods to use as listeners for a sensor.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Sensorannotations

Easydeviceinfo
📱 [Android Library] Get device information in a super easy way.
Stars: ✭ 1,698 (+1338.98%)
Mutual labels:  sensor, annotations
Marginalia
📜 marginalia.el - Marginalia in the minibuffer
Stars: ✭ 111 (-5.93%)
Mutual labels:  annotations
Androidwearmotionsensors
Using the accelerometer and gyroscope on an Android Wear device
Stars: ✭ 91 (-22.88%)
Mutual labels:  sensor
Deep Learning Based Ecg Annotator
Annotation of ECG signals using deep learning, tensorflow’ Keras
Stars: ✭ 110 (-6.78%)
Mutual labels:  annotations
Remarks
Extract highlights, scribbles, and annotations from PDFs marked with the reMarkable tablet. Export to Markdown, PDF, PNG, and SVG
Stars: ✭ 94 (-20.34%)
Mutual labels:  annotations
Kripton
A Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.
Stars: ✭ 110 (-6.78%)
Mutual labels:  annotations
Retrofit Cjs
retrofit-cjs 是一个基于JavaScript装饰器(Decorator)和 axios 实现的网络请求库, 支持Vue / React / react-native 等常用框架
Stars: ✭ 87 (-26.27%)
Mutual labels:  annotations
Jupytergraffiti
Create interactive screencasts inside Jupyter Notebook that anybody can play back
Stars: ✭ 114 (-3.39%)
Mutual labels:  annotations
Esp32 Mpu Driver
ESP32 full library for all MPU6000 MPU6050 MPU6500 MPU9150 MPU9250 with SPI and I2C support and more.
Stars: ✭ 111 (-5.93%)
Mutual labels:  sensor
Mini Graph Card
Minimalistic graph card for Home Assistant Lovelace UI
Stars: ✭ 1,370 (+1061.02%)
Mutual labels:  sensor
Dataset
Crop/Weed Field Image Dataset
Stars: ✭ 98 (-16.95%)
Mutual labels:  annotations
Sensingkit Ios
An iOS framework that provides Mobile Sensing functionality to your apps.
Stars: ✭ 93 (-21.19%)
Mutual labels:  sensor
Typical
Typical: Fast, simple, & correct data-validation using Python 3 typing.
Stars: ✭ 111 (-5.93%)
Mutual labels:  annotations
Exnn
An Elixir Evolutive Neural Network framework à la G.Sher
Stars: ✭ 93 (-21.19%)
Mutual labels:  sensor
Diy projects base on rt Thread
一些基于 RT-Thread 开发的 DIY 项目
Stars: ✭ 113 (-4.24%)
Mutual labels:  sensor
No Copy
A Kotlin compiler plugin that removes the `copy` method of data classes.
Stars: ✭ 90 (-23.73%)
Mutual labels:  annotations
Laravel Aspect
aspect oriented programming Package for laravel framework
Stars: ✭ 98 (-16.95%)
Mutual labels:  annotations
Nova
NOVA is a tool for annotating and analyzing behaviours in social interactions. It supports Annotators using Machine Learning already during the coding process. Further it features both, discrete labels and continuous scores and a visuzalization of streams recorded with the SSI Framework.
Stars: ✭ 110 (-6.78%)
Mutual labels:  annotations
Tieguanyin
Activity Builder.
Stars: ✭ 113 (-4.24%)
Mutual labels:  annotations
Router
🍭灵活的组件化路由框架.
Stars: ✭ 1,502 (+1172.88%)
Mutual labels:  annotations

SensorAnnotations

Annotate methods to use as listeners for sensor events.

Build Status Download Android Arsenal Awesome Android #22

public class MyActivity extends Activity {
    /**
     * Perform actions as accelerometer data changes...
     */
    @OnSensorChanged(Sensor.TYPE_ACCELEROMETER)
    void accelerometerSensorChanged(@NonNull SensorEvent event) {
        doSomething(event.values);
    }

    /**
     * If the sensor isn't available, update UI accordingly...
     */
    @OnSensorNotAvailable(Sensor.TYPE_ACCELEROMETER)
    void testTemperatureSensorNotAvailable() {
        hideAccelerometerUi();
    }
    
    @Override protected void onResume() {
        super.onResume();
        SensorAnnotations.bind(this);
    }

    @Override protected void onPause() {
        super.onPause();
        SensorAnnotations.unbind(this); // Unbind to save the user's battery life.
    }
}

There are four possible annotations: @OnSensorChanged, @OnAccuracyChanged, @OnSensorNotAvailable, and @OnTrigger. The annotated methods must have the method signatures specified in the Sensors Overview Android docs.

@OnSensorChanged(Sensor.TYPE_HEART_RATE)
void method(@NonNull SensorEvent event) {}

// or the following syntax can be used which accepts a delay value:
@OnSensorChanged(value = Sensor.TYPE_LIGHT, delay = SensorManager.SENSOR_DELAY_NORMAL)
void method(@NonNull SensorEvent event) {}

@OnAccuracyChanged(Sensor.TYPE_MAGNETIC_FIELD)
void method(@NonNull Sensor sensor, int accuracy) {}

@OnSensorNotAvailable(Sensor.TYPE_AMBIENT_TEMPERATURE)
void method() {}

@OnTrigger
void method(@NonNull TriggerEvent event) {}

For information about sensor delays and accuracy events see the "Monitoring Sensor Events" portion of the Android docs.

Calling SensorAnnotations.bind should be done when you want to start receiving sensor events. Because this consumes battery life you need to call unbind when you are finished. The bind method needs to take a Context object. There are two variations:

SensorAnnotations.bind(context);
// Use this alternative to bind to a different target. See the example application.
SensorAnnotations.bind(this, context);

The @OnTrigger annotation is a specific annotation for sensors of TYPE_SIGNIFICANT_MOTION (introduced in 4.3). This type has a different method and parameter than the others. For more info see the Android docs on Using the Significant Motion Sensor.

View the Demo app for usage

SensorAnnotations Sample App

How does it work?

A binding class is created for each class that has annotations. In the example app, the classes MainActivity and AccelerometerManager will have two classes generated at compile time: MainActivity$$SensorBinder and AccelerometerManager$$SensorBinder. Because these classes are generated at compile time no reflection is needed.

These classes register the listener with the sensor system service. If the sensor isn't available on the device and a method has been annotated with @OnSensorNotAvailable it will be invoked. If an accuracy event occurs and a method has been annotated with @OnAccuracyChanged it will be invoked. The TYPE_SIGNIFICANT_MOTION sensor doesn't have an accuracy callback.

Use in your project

buildscript {
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

apply plugin: 'com.neenbedankt.android-apt'

dependencies {
    compile 'com.dvoiss:sensorannotations:0.1.0'
    apt 'com.dvoiss:sensorannotations-compiler:0.1.0'
}

Using Android Gradle Plugin version 2.2.0+:

dependencies {
    compile 'com.dvoiss:sensorannotations:0.1.0'
    annotationProcessor 'com.dvoiss:sensorannotations-compiler:0.1.0'
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].