Android Open Source - Sensoria Sensor Data






From Project

Back to project page Sensoria.

License

The source code is released under:

MIT License

If you think the Android project Sensoria listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.grocs.sensors.common;
/*from  w w w.  j  ava 2 s.  c  o m*/
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import android.hardware.Sensor;

class SensorData implements ISensorData {
    private final Sensor sensor;
    private final boolean isDefault;
    private final ISensorDescription description;
    private final AtomicBoolean dirty = new AtomicBoolean();;
    private final float[] fValues;
    private int accuracy;

    SensorData(final Sensor sensor, final boolean defaultSensor) {
        this.sensor = sensor;
        this.isDefault = defaultSensor;
        //
        description = SensorDescriptions.getDescription(sensor.getType());
        // use the description to find out how many values are to be expected
        fValues = new float[description.getValueDescriptions().length];
    }

    /**
     * @see com.grocs.sensors.common.ISensorData#getSensor()
     */
    @Override
    public Sensor getSensor() {
        return sensor;
    }

    /**
     * @see com.grocs.sensors.common.ISensorData#getDescription()
     */
    @Override
    public ISensorDescription getDescription() {
        return description;
    }

    /**
     * @see com.grocs.sensors.common.ISensorData#getValues()
     */
    @Override
    public float[] getValues() {
        return fValues;
    }

    /**
     * @see com.grocs.sensors.common.ISensorData#isDefault()
     */
    @Override
    public boolean isDefault() {
        return isDefault;
    }

    /**
     * clear the dirty flag
     * @return previous value of the dirty flag
     */
    boolean clearDirty() {
        return dirty.getAndSet(false);
    }

    /**
     * @param values new values
     * @return true ico changes, false in the other case
     */
    synchronized boolean update(final float[] values) {
        for (int i = 0; i < fValues.length && i < values.length; ++i) {
            if (fValues[i] != values[i]) {
                fValues[i] = values[i];
                dirty.set(true);
            }
        }
        return dirty.get();
    }

    synchronized boolean update(int accuracy) {
        if (accuracy == this.accuracy) {
            return false;
        }
        this.accuracy = accuracy;
        dirty.set(true);
        return true;
    }

    @Override
    public String toString() {
        return "SensorData [Sensor=" + sensor.getName() + ", fValues="
                + Arrays.toString(fValues) + "]";
    }
}




Java Source Code List

com.grocs.sensors.common.FloatConvertor.java
com.grocs.sensors.common.ISensorData.java
com.grocs.sensors.common.ISensorDescription.java
com.grocs.sensors.common.SensorCollector.java
com.grocs.sensors.common.SensorConstants.java
com.grocs.sensors.common.SensorDataComparator.java
com.grocs.sensors.common.SensorDataManagerListener.java
com.grocs.sensors.common.SensorDataManager.java
com.grocs.sensors.common.SensorData.java
com.grocs.sensors.common.SensorDescriptions.java
com.grocs.sensors.common.SensorFilter.java
com.grocs.sensors.common.SensorUtils.java
com.grocs.sensors.common.TestFloatConvertor.java
com.grocs.sensors.ui.ActivityDetail.java
com.grocs.sensors.ui.Activity.java
com.grocs.sensors.ui.EntryAdapter.java
com.grocs.sensors.ui.FloatFormatter.java
com.grocs.sensors.ui.SensorEntryComparator.java
com.grocs.sensors.ui.SensorEntry.java
com.grocs.sensors.ui.SensorPreferenceActivity.java
com.grocs.sensors.ui.TestFloatFormatter.java