Example usage for android.hardware Sensor getType

List of usage examples for android.hardware Sensor getType

Introduction

In this page you can find the example usage for android.hardware Sensor getType.

Prototype

public int getType() 

Source Link

Usage

From source file:Main.java

public static boolean isSensorCompatible(Sensor sensor) {
    return sensor.getType() == Sensor.TYPE_STEP_COUNTER || sensor.getType() == Sensor.TYPE_STEP_DETECTOR
            || sensor.getType() == Sensor.TYPE_LIGHT || sensor.getType() == Sensor.TYPE_PRESSURE
            || sensor.getType() == Sensor.TYPE_RELATIVE_HUMIDITY
            || sensor.getType() == Sensor.TYPE_SIGNIFICANT_MOTION || sensor.getType() == Sensor.TYPE_GRAVITY;
}

From source file:altermarkive.uploader.Report.java

@SuppressWarnings("unused")
public static String probe(Context context) throws JSONException {
    SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> list = manager.getSensorList(Sensor.TYPE_ALL);
    int[] types = new int[list.size()];
    String[] vendors = new String[list.size()];
    String[] names = new String[list.size()];
    float[] resolutions = new float[list.size()];
    int[] delays = new int[list.size()];
    float[] ranges = new float[list.size()];
    float[] powers = new float[list.size()];
    int i = 0;/*from   w ww  .j av  a  2  s  .com*/
    for (Sensor sensor : list) {
        types[i] = sensor.getType();
        vendors[i] = sensor.getVendor();
        names[i] = sensor.getName();
        resolutions[i] = sensor.getResolution();
        delays[i] = sensor.getMinDelay();
        ranges[i] = sensor.getMaximumRange();
        powers[i] = sensor.getPower();
        i++;
    }
    return report(context, types, vendors, names, resolutions, delays, ranges, powers);
}

From source file:com.commonsware.android.sensor.monitor.MainActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private boolean isXYZ(Sensor s) {
    switch (s.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
    case Sensor.TYPE_GRAVITY:
    case Sensor.TYPE_GYROSCOPE:
    case Sensor.TYPE_LINEAR_ACCELERATION:
    case Sensor.TYPE_MAGNETIC_FIELD:
    case Sensor.TYPE_ROTATION_VECTOR:
        return (true);
    }/*from w ww .  j a  va2  s.  c  om*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (s.getType() == Sensor.TYPE_GAME_ROTATION_VECTOR || s.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED
                || s.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
            return (true);
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (s.getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR) {
            return (true);
        }
    }

    return (false);
}

From source file:org.wso2.carbon.iot.android.sense.event.streams.speed.SpeedDataReader.java

@Override
public void onSensorChanged(SensorEvent event) {

    Sensor devSensor = event.sensor;

    if (devSensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        x = event.values[0];/*w w  w . j  ava 2  s . c  o m*/
        y = event.values[1];
        z = event.values[2];

    }
}

From source file:org.jitsi.android.gui.fragment.ProximitySensorFragment.java

/**
 * {@inheritDoc}//from w w  w .j  a v  a  2  s. c o m
 */
@Override
public void onResume() {
    super.onResume();

    // Skips if the sensor has been already attached
    if (proximitySensor != null)
        return;

    SensorManager manager = JitsiApplication.getSensorManager();

    List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL);
    logger.trace("Device has " + sensors.size() + " sensors");
    for (Sensor s : sensors) {
        logger.trace("Sensor " + s.getName() + " type: " + s.getType());
    }

    this.proximitySensor = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    if (proximitySensor == null) {
        return;
    }

    logger.info("Using proximity sensor: " + proximitySensor.getName());
    sensorDisabled = false;
    manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI);
}

From source file:com.fallahpoor.infocenter.fragments.SensorsFragment.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public ArrayList<String> getSubItemsArrayList() {

    HashMap<Integer, String> sensorsHashMap = new HashMap<>();
    ArrayList<String> subItems = new ArrayList<>();
    Iterator<Integer> iterator;
    String supported = getString(R.string.supported);
    String unsupported = getString(R.string.unsupported);
    ArrayList<Integer> sensorTypes = new ArrayList<>(Arrays.asList(new Integer[] { Sensor.TYPE_ACCELEROMETER,
            Sensor.TYPE_AMBIENT_TEMPERATURE, Sensor.TYPE_GRAVITY, Sensor.TYPE_GYROSCOPE, Sensor.TYPE_LIGHT,
            Sensor.TYPE_LINEAR_ACCELERATION, Sensor.TYPE_MAGNETIC_FIELD, Sensor.TYPE_PRESSURE,
            Sensor.TYPE_PROXIMITY, Sensor.TYPE_RELATIVE_HUMIDITY, Sensor.TYPE_ROTATION_VECTOR }));

    if (mIsApiAtLeast18) {
        sensorTypes.add(Sensor.TYPE_GAME_ROTATION_VECTOR);
        sensorTypes.add(Sensor.TYPE_SIGNIFICANT_MOTION);
    }/*from ww  w. j  a  v a  2  s .c  om*/

    if (mIsApiAtLeast19) {
        sensorTypes.add(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR);
        sensorTypes.add(Sensor.TYPE_STEP_COUNTER);
        sensorTypes.add(Sensor.TYPE_STEP_DETECTOR);
    }

    SensorManager sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    // Get the list of all available sensors of the device
    List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);

    iterator = sensorTypes.iterator();

    // Assume all sensor types are unsupported
    while (iterator.hasNext()) {
        sensorsHashMap.put(iterator.next(), unsupported);
    }

    /*
     * For each sensor type that is in sensors change its status from
     * "unsupported" to "supported".
     */
    for (Sensor sensor : sensors) {
        sensorsHashMap.put(sensor.getType(), supported);
    }

    iterator = sensorTypes.iterator();

    while (iterator.hasNext()) {
        subItems.add(sensorsHashMap.get(iterator.next()));
    }

    return subItems;

}

From source file:com.commonsware.android.sensor.monitor.MainActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private boolean isTriggerSensor(Sensor s) {
    int[] triggers = { Sensor.TYPE_SIGNIFICANT_MOTION, Sensor.TYPE_STEP_DETECTOR, Sensor.TYPE_STEP_COUNTER };

    return (Arrays.binarySearch(triggers, s.getType()) >= 0);
}

From source file:com.polyvi.xface.extension.XAccelerometerExt.java

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    // Only look at accelerometer events
    if (sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;//from   w  ww.ja v a2 s  .co m
    }

    // If not running, then just return
    if (mStatus == STOPPED) {
        return;
    }
    mAccuracy = accuracy;
}

From source file:org.jitsi.android.gui.call.ProximitySensorFragment.java

/**
 * {@inheritDoc}/*from  w w w  .  j  ava2  s  . co  m*/
 */
@Override
public void onResume() {
    super.onResume();

    SensorManager manager = JitsiApplication.getSensorManager();

    // Skips if the sensor has been already attached
    if (proximitySensor != null) {
        // Re-registers the listener as it might have been
        // unregistered in onPause()
        manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI);
        return;
    }

    List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL);
    logger.trace("Device has " + sensors.size() + " sensors");
    for (Sensor s : sensors) {
        logger.trace("Sensor " + s.getName() + " type: " + s.getType());
    }

    this.proximitySensor = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    if (proximitySensor == null) {
        return;
    }

    logger.info("Using proximity sensor: " + proximitySensor.getName());
    sensorDisabled = false;
    manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI);
}