Example usage for android.hardware SensorManager SENSOR_STATUS_UNRELIABLE

List of usage examples for android.hardware SensorManager SENSOR_STATUS_UNRELIABLE

Introduction

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

Prototype

int SENSOR_STATUS_UNRELIABLE

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

Click Source Link

Document

The values returned by this sensor cannot be trusted, calibration is needed or the environment doesn't allow readings

Usage

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

/**
 * Stop listening to acceleration sensor.
 *///  www.  ja va 2s.  c o  m
private void stop() {
    stopTimeout();
    if (this.status != LightListener.STOPPED) {
        this.sensorManager.unregisterListener(this);
    }
    this.setStatus(LightListener.STOPPED);
    this.accuracy = SensorManager.SENSOR_STATUS_UNRELIABLE;
}

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

/**
 * Stop listening to acceleration sensor.
 *///  w  w w .  j av a  2 s  . co m
private void stop() {
    stopTimeout();
    if (this.status != BSMotionSensorsPlugin.STOPPED) {
        this.sensorManager.unregisterListener(this);
    }
    this.setStatus(BSMotionSensorsPlugin.STOPPED);
    this.accuracy = SensorManager.SENSOR_STATUS_UNRELIABLE;
}

From source file:ch.bfh.sensordataprocessor.sensor.SensorDisplayFragment.java

/**
 * @see android.hardware.SensorEventListener#onAccuracyChanged(android.hardware.Sensor, int)
 */// www .j ava  2 s.  c om
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    switch (accuracy) {
    case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
        this.accuracy.setText("SENSOR_STATUS_ACCURACY_HIGH");
        break;
    case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
        this.accuracy.setText("SENSOR_STATUS_ACCURACY_MEDIUM");
        break;
    case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
        this.accuracy.setText("SENSOR_STATUS_ACCURACY_LOW");
        break;
    case SensorManager.SENSOR_STATUS_UNRELIABLE:
        this.accuracy.setText("SENSOR_STATUS_UNRELIABLE");
        break;
    }
}

From source file:com.example.casthelloworld.MainActivity.java

@Override
public void onSensorChanged(SensorEvent sensorEvent) {

    if (sensorEvent.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
        return;/*from www . j a v a2s  .co m*/
    }

    SensorManager.getRotationMatrixFromVector(mRotationMatrix, sensorEvent.values);

    SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z,
            mRotationMatrix);

    SensorManager.getOrientation(mRotationMatrix, orientationVals);

    orientationVals[2] = (float) Math.toDegrees(orientationVals[2]);

    float Roll = orientationVals[2];

    if (Roll < -85 && Roll > -95 && lastVal != 0.0f) {
        // Log.d("Middle: ", "" + Roll);
        lastVal = 0.0f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll <= -95 && Roll > -105 && lastVal != -0.2f) {
        // Log.d("Left", "" + Roll);
        lastVal = -0.2f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll >= -85 && Roll < -75 && lastVal != 0.2f) {
        // Log.d("Right", "" + Roll);
        lastVal = 0.2f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll <= -105 && Roll > -115 && lastVal != -0.4f) {
        // Log.d("Left", "" + Roll);
        lastVal = -0.4f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll >= -75 && Roll < -65 && lastVal != 0.4f) {
        // Log.d("Right", "" + Roll);
        lastVal = 0.4f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll <= -115 && Roll > -125 && lastVal != -0.6f) {
        // Log.d("Left", "" + Roll);
        lastVal = -0.6f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll >= -65 && Roll < -55 && lastVal != 0.6f) {
        // Log.d("Right", "" + Roll);
        lastVal = 0.6f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll <= -125 && Roll > -135 && lastVal != -0.8f) {
        // Log.d("Left", "" + Roll);
        lastVal = -0.8f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll >= -55 && Roll < -45 && lastVal != 0.8f) {
        // Log.d("Right", "" + Roll);
        lastVal = 0.8f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll <= -135 && lastVal != -1.0f && lastVal != 1.0f) {
        // Log.d("Left", "" + Roll);
        lastVal = -1.0f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    } else if (Roll >= -45 && lastVal != 1.0f && lastVal != -1.0f) {
        // Log.d("Right", "" + Roll);
        lastVal = 1.0f;
        try {
            directionMessage.put("direction", (double) lastVal);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mGameManagerClient.sendGameMessage(directionMessage);
    }

}

From source file:net.line2soft.preambul.controllers.SlippyMapListener.java

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (sensor.getType() == Sensor.TYPE_ORIENTATION) {
        CompassView cp = (CompassView) activity.findViewById(R.id.compass);
        CompassView cpBig = (CompassView) activity.findViewById(R.id.compassBig);
        if (accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE
                || accuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW) {
            activity.setAccurate(false);
            activity.displayInfo(activity.getString(R.string.message_compass_not_accurate));
            cp.setVisibility(View.GONE);
            cpBig.setVisibility(View.GONE);
        } else {/* w  w w . j a  v  a2 s .co  m*/
            activity.setAccurate(true);
            if (cp.getVisibility() == View.GONE && cpBig.getVisibility() == View.GONE) {
                cp.setVisibility(View.VISIBLE);
            }
        }
    }
}

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  v  a2  s.c  om
    }
    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.dragon4.owo.ar_trace.ARCore.MixView.java

public void onAccuracyChanged(Sensor sensor, int accuracy) {
    // ? ? ?  ? /*from w  w  w  .  j ava 2 s. co m*/
    if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD && accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE
            && compassErrorDisplayed == 0) {
        for (int i = 0; i < 2; i++) {
            //  ?? . ? 
            Toast.makeText(mixContext, "Compass data unreliable. Please recalibrate compass.",
                    Toast.LENGTH_LONG).show();
        }
        compassErrorDisplayed++;
    }
}

From source file:org.mixare.MixViewActivity.java

public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD && accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE
            && getMixViewData().getCompassErrorDisplayed() == 0) {
        for (int i = 0; i < 2; i++) {
            markerRenderer.getContext().getNotificationManager()
                    .addNotification("Compass data unreliable. Please recalibrate compass.");
        }//ww w .  j a  va2 s .  c o m
        getMixViewData().setCompassErrorDisplayed(getMixViewData().getCompassErrorDisplayed() + 1);
    }
}

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;/*w w  w . ja  va  2 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;
    }
}