Example usage for android.hardware SensorManager SENSOR_STATUS_ACCURACY_MEDIUM

List of usage examples for android.hardware SensorManager SENSOR_STATUS_ACCURACY_MEDIUM

Introduction

In this page you can find the example usage for android.hardware SensorManager SENSOR_STATUS_ACCURACY_MEDIUM.

Prototype

int SENSOR_STATUS_ACCURACY_MEDIUM

To view the source code for android.hardware SensorManager SENSOR_STATUS_ACCURACY_MEDIUM.

Click Source Link

Document

This sensor is reporting data with an average level of accuracy, calibration with the environment may improve the readings

Usage

From source file:org.apache.cordova.devicemotion.AccelListener.java

/**
 * Returns latest cached position if the sensor hasn't returned newer value.
 *
 * Called two seconds after starting the listener.
 *//*from  www. j a va 2s .  co  m*/
private void timeout() {
    if (this.status == AccelListener.STARTING && this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {
        // call win with latest cached position
        // but first check if cached position is reliable
        this.timestamp = System.currentTimeMillis();
        this.win();
    }
}

From source file:org.skt.runtime.html5apis.Accelerometer.java

/**
 * Sensor listener event.// w w  w.j a v a  2s  .co  m
 * 
 * @param SensorEvent event
 */
public void onSensorChanged(SensorEvent event) {
    // Only look at accelerometer events
    if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;
    }

    // If not running, then just return
    if (this.status == Accelerometer.STOPPED) {
        return;
    }

    this.setStatus(Accelerometer.RUNNING);

    if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {

        // Save time that event was received
        this.timestamp = System.nanoTime();
        this.x = event.values[0];
        this.y = event.values[1];
        this.z = event.values[2];

        this.win();
    }
}

From source file:org.apache.cordova.AccelListener.java

/**
 * Sensor listener event./* w  w  w . ja  v  a  2  s.  c o m*/
 *
 * @param SensorEvent event
 */
public void onSensorChanged(SensorEvent event) {
    // Only look at accelerometer events
    if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;
    }

    // If not running, then just return
    if (this.status == AccelListener.STOPPED) {
        return;
    }
    this.setStatus(AccelListener.RUNNING);

    if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {

        // Save time that event was received
        this.timestamp = System.currentTimeMillis();
        this.x = event.values[0];
        this.y = event.values[1];
        this.z = event.values[2];

        this.win();
    }
}

From source file:com.ut3.ehg.turismotepic.Augmentedreality.java

public ArchitectView.SensorAccuracyChangeListener getSensorAccuracyListener() {
    return new ArchitectView.SensorAccuracyChangeListener() {
        @Override//from w  ww .  j a v  a  2s .  c  o m
        public void onCompassAccuracyChanged(int accuracy) {
            /* UNRELIABLE = 0, LOW = 1, MEDIUM = 2, HIGH = 3 */
            if (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM && Augmentedreality.this != null
                    && !Augmentedreality.this.isFinishing() && System.currentTimeMillis()
                            - Augmentedreality.this.lastCalibrationToastShownTimeMillis > 5 * 1000) {
                //Toast.makeText( MainActivity.this, R.string.compass_accuracy_low, Toast.LENGTH_LONG ).show();
                Augmentedreality.this.lastCalibrationToastShownTimeMillis = System.currentTimeMillis();
            }
        }
    };
}

From source file:org.apache.cordova.devicemotion.LightListener.java

/**
 * Sensor listener event.//from   w  w  w  .j  a  va  2 s.co m
 *
 * @param SensorEvent event
 */
public void onSensorChanged(SensorEvent event) {
    // Only look at accelerometer events
    if (event.sensor.getType() != Sensor.TYPE_LIGHT) {
        return;
    }

    // If not running, then just return
    if (this.status == LightListener.STOPPED) {
        return;
    }
    this.setStatus(LightListener.RUNNING);

    if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {

        // Save time that event was received
        this.timestamp = System.currentTimeMillis();
        this.x = event.values[0];

        this.win();
    }
}

From source file:com.bsafe.sensors.motion.BSMotionSensorsPlugin.java

/**
 * Sensor listener event./*from   w ww. j  a v  a  2  s.  com*/
 *
 * @param SensorEvent event
 */
public void onSensorChanged(SensorEvent event) {
    // Only look at accelerometer events
    if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;
    }

    // If not running, then just return
    if (this.status == BSMotionSensorsPlugin.STOPPED) {
        return;
    }
    this.setStatus(BSMotionSensorsPlugin.RUNNING);

    if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {

        // Save time that event was received
        this.timestamp = System.currentTimeMillis();
        this.x = event.values[0];
        this.y = event.values[1];
        this.z = event.values[2];

        this.win();
    }
}

From source file:com.aps490.drdc.prototype.MainActivity.java

@Override
public SensorAccuracyChangeListener getSensorAccuracyListener() {
    return new SensorAccuracyChangeListener() {
        @Override/*w  w w .  j  a v a2s  . c om*/
        public void onCompassAccuracyChanged(int accuracy) {
            /* UNRELIABLE = 0, LOW = 1, MEDIUM = 2, HIGH = 3 */
            if (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM && MainActivity.this != null
                    && !MainActivity.this.isFinishing() && System.currentTimeMillis()
                            - MainActivity.this.lastCalibrationToastShownTimeMillis > 5 * 1000) {
                Toast.makeText(MainActivity.this, R.string.compass_accuracy_low, Toast.LENGTH_LONG).show();
                MainActivity.this.lastCalibrationToastShownTimeMillis = System.currentTimeMillis();
            }
        }
    };
}

From source file:de.htw.ar.treasurehuntar.AbstractArchitectActivity.java

public SensorAccuracyChangeListener getSensorAccuracyListener() {
    return new SensorAccuracyChangeListener() {
        @Override//  w  w w .  j a va  2s.  c  om
        public void onCompassAccuracyChanged(int accuracy) {
            /* UNRELIABLE = 0, LOW = 1, MEDIUM = 2, HIGH = 3 */
            if (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM && isFinishing()
                    && System.currentTimeMillis() - lastCalibrationToastShownTimeMillis > 5 * 1000) {
                Toast.makeText(AbstractArchitectActivity.this, R.string.compass_accuracy_low, Toast.LENGTH_LONG)
                        .show();
                lastCalibrationToastShownTimeMillis = System.currentTimeMillis();
            }
        }
    };
}

From source file:com.cellbots.logger.LoggerActivity.java

private void updateSensorUi(int sensorType, int accuracy, float[] values) {
    // IMPORTANT: DO NOT UPDATE THE CONTENTS INSIDE A DRAWER IF IT IS BEING
    // ANIMATED VIA A CALL TO animateOpen/animateClose!!!
    // Updating anything inside will stop the animation from running.
    // Note that this does not seem to affect the animation if it had been
    // triggered by dragging the drawer instead of being called
    // programatically.
    if (mDataDrawer.isMoving()) {
        return;/* w  w w.  ja  va  2  s  .c o  m*/
    }
    TextView xTextView;
    TextView yTextView;
    TextView zTextView;
    if (sensorType == Sensor.TYPE_ACCELEROMETER) {
        xTextView = mAccelXTextView;
        yTextView = mAccelYTextView;
        zTextView = mAccelZTextView;
    } else if (sensorType == Sensor.TYPE_GYROSCOPE) {
        xTextView = mGyroXTextView;
        yTextView = mGyroYTextView;
        zTextView = mGyroZTextView;
    } else if (sensorType == Sensor.TYPE_MAGNETIC_FIELD) {
        xTextView = mMagXTextView;
        yTextView = mMagYTextView;
        zTextView = mMagZTextView;
    } else {
        return;
    }

    int textColor = Color.WHITE;
    String prefix = "";
    switch (accuracy) {
    case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
        prefix = "  ";
        break;
    case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
        prefix = "  *";
        break;
    case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
        prefix = "  **";
        break;
    case SensorManager.SENSOR_STATUS_UNRELIABLE:
        prefix = "  ***";
        break;
    }

    xTextView.setTextColor(textColor);
    yTextView.setTextColor(textColor);
    zTextView.setTextColor(textColor);
    xTextView.setText(prefix + numberDisplayFormatter(values[0]));
    yTextView.setText(prefix + numberDisplayFormatter(values[1]));
    zTextView.setText(prefix + numberDisplayFormatter(values[2]));

}

From source file:com.example.sensingapp.SensingApp.java

public void onAccuracyChanged(Sensor sensor, int accuracy) {
    switch (sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        m_sSensorAccuracy = "1,"; //Accl
        break;//from ww  w  . j  a v a2 s .c  o m

    case Sensor.TYPE_LINEAR_ACCELERATION:
        m_sSensorAccuracy = "2,"; //LinearAccl
        break;

    case Sensor.TYPE_GYROSCOPE:
        m_sSensorAccuracy = "3,"; //Gyro
        break;

    case Sensor.TYPE_MAGNETIC_FIELD:
        m_sSensorAccuracy = "4,"; //Magnet
        break;

    case Sensor.TYPE_GRAVITY:
        m_sSensorAccuracy = "5,"; //Gravity      
        break;

    case Sensor.TYPE_PROXIMITY:
        m_sSensorAccuracy = "6,"; //Proxi
        break;

    case Sensor.TYPE_LIGHT:
        m_sSensorAccuracy = "7,"; //Light
        break;

    case Sensor.TYPE_PRESSURE:
        m_sSensorAccuracy = "8,"; //Barometer
        break;

    case Sensor.TYPE_RELATIVE_HUMIDITY:
        m_sSensorAccuracy = "9,"; //Humidity
        break;

    case Sensor.TYPE_AMBIENT_TEMPERATURE:
        m_sSensorAccuracy = "10,"; //Temperature
        break;

    default:
        m_sSensorAccuracy = "11,"; //Other
    }

    switch (accuracy) {
    case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
        m_sSensorAccuracy = m_sSensorAccuracy + "1,"; //H
        break;

    case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
        m_sSensorAccuracy = m_sSensorAccuracy + "2,"; //M
        break;

    case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
        m_sSensorAccuracy = m_sSensorAccuracy + "3,"; //L
        break;

    case SensorManager.SENSOR_STATUS_UNRELIABLE:
        m_sSensorAccuracy = m_sSensorAccuracy + "4,"; //U
        break;
    }
}