Java Code Examples for android.hardware.Sensor#getType()
The following examples show how to use
android.hardware.Sensor#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Engine.java From 30-android-libraries-in-30-days with Apache License 2.0 | 6 votes |
@Override public void onAccuracyChanged(final Sensor pSensor, final int pAccuracy) { if(this.mRunning) { switch(pSensor.getType()) { case Sensor.TYPE_ACCELEROMETER: if(this.mAccelerationData != null) { this.mAccelerationData.setAccuracy(pAccuracy); this.mAccelerationListener.onAccelerationAccuracyChanged(this.mAccelerationData); } else if(this.mOrientationData != null) { this.mOrientationData.setAccelerationAccuracy(pAccuracy); this.mOrientationListener.onOrientationAccuracyChanged(this.mOrientationData); } break; case Sensor.TYPE_MAGNETIC_FIELD: this.mOrientationData.setMagneticFieldAccuracy(pAccuracy); this.mOrientationListener.onOrientationAccuracyChanged(this.mOrientationData); break; } } }
Example 2
Source File: SensorChange.java From VirtualSensor with GNU Lesser General Public License v3.0 | 6 votes |
public float[] handleListener(Sensor s, VirtualSensorListener listener, float[] values, int accuracy, long timestamp, float accResolution, float magResolution) { if (s.getType() == Sensor.TYPE_ACCELEROMETER) { if (Util.checkSensorResolution(this.accelerometerValues, values, accResolution)) { this.accelerometerValues = values; } if (listener.getSensor() != null || listener.isDummyGyroListener) { return this.getSensorValues(listener, timestamp); } } else if (s.getType() == Sensor.TYPE_MAGNETIC_FIELD) { if (Util.checkSensorResolution(this.magneticValues, values, magResolution)) { this.magneticValues = values; } } return null; }
Example 3
Source File: SensorUtil.java From Sensor-Disabler with MIT License | 5 votes |
public static float getMinimumValueForSensor(Sensor sensor) { float minimumValue; switch (sensor.getType()) { case Sensor.TYPE_HEART_RATE: case Sensor.TYPE_LIGHT: case Sensor.TYPE_PROXIMITY: case Sensor.TYPE_STEP_COUNTER: case Sensor.TYPE_PRESSURE: minimumValue = 0; break; default: minimumValue = -sensor.getMaximumRange(); } return minimumValue; }
Example 4
Source File: RunService.java From SEAL-Demo with MIT License | 5 votes |
@Override public void onSensorChanged(SensorEvent sensorEvent) { Sensor sensor = sensorEvent.sensor; if (sensor.getType() == TYPE_ACCELEROMETER) { mAccelerometerMatrix = sensorEvent.values; } else if (sensor.getType() == TYPE_GYROSCOPE) { mGyroscopeMatrix = sensorEvent.values; } }
Example 5
Source File: SensorsActivity.java From android-motion-detector with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { if (sensor == null) throw new NullPointerException(); if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD && accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) { Log.e(TAG, "Compass data unreliable"); } }
Example 6
Source File: StepSensor.java From react-native-google-fit with MIT License | 5 votes |
@Override public void onSensorChanged(SensorEvent sensorEvent) { Sensor mySensor = sensorEvent.sensor; Log.i(TAG, "onSensorChanged"); if (mySensor.getType() == Sensor.TYPE_STEP_COUNTER) { WritableMap map = Arguments.createMap(); long curTime = System.currentTimeMillis(); //i++; if ((curTime - lastUpdate) > delay) { final Object o = sensorEvent.values[0]; Log.i("History", "Data point:" + sensorEvent.values[0]); map.putDouble("steps", sensorEvent.values[0]); sendEvent(this.mReactContext, "StepSensorChangedEvent", map); activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(mReactContext.getApplicationContext(), "" + o, Toast.LENGTH_SHORT).show(); } }); lastUpdate = curTime; } } }
Example 7
Source File: OrientationManager.java From PTVGlass with MIT License | 5 votes |
@Override public void onAccuracyChanged(Sensor sensor, int accuracy) { if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { mHasInterference = (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_HIGH); notifyAccuracyChanged(); } }
Example 8
Source File: AccelListener.java From cordova-android-chromeview with Apache License 2.0 | 5 votes |
/** * Called when the accuracy of the sensor has changed. * * @param sensor * @param accuracy */ public void onAccuracyChanged(Sensor sensor, int accuracy) { // Only look at accelerometer events if (sensor.getType() != Sensor.TYPE_ACCELEROMETER) { return; } // If not running, then just return if (this.status == AccelListener.STOPPED) { return; } this.accuracy = accuracy; }
Example 9
Source File: LuxActivity.java From androidthings-drivers with Apache License 2.0 | 5 votes |
@Override public void onDynamicSensorConnected(Sensor sensor) { if (sensor.getType() == Sensor.TYPE_LIGHT) { Log.i(TAG, "Light sensor connected"); mSensorManager.registerListener(LuxActivity.this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } }
Example 10
Source File: MynaService.java From Myna with Apache License 2.0 | 5 votes |
private void checkAndRegisterSensor(int sensorType){ List<Sensor> sensors = mSensorManager.getSensorList(Sensor.TYPE_ALL); Sensor sensor; for (int index = 0; index < sensors.size(); ++index) { sensor = sensors.get(index); if (sensor.getType() == sensorType) { mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST); } } }
Example 11
Source File: GaugePanel.java From trekarta with GNU General Public License v3.0 | 5 votes |
@Override public void onAccuracyChanged(Sensor sensor, int accuracy) { if (sensor.getType() == Sensor.TYPE_PRESSURE) { if (accuracy == SensorManager.SENSOR_STATUS_NO_CONTACT || accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) setValue(Gauge.TYPE_ELEVATION, Float.NaN); } }
Example 12
Source File: StepDcretor.java From JkStepSensor with Apache License 2.0 | 5 votes |
public void onSensorChanged(SensorEvent event) { Sensor sensor = event.sensor; synchronized (this) { if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) { calc_step(event); } } }
Example 13
Source File: Engine.java From tilt-game-android with MIT License | 5 votes |
@Override public void onSensorChanged(final SensorEvent pEvent) { if (this.mRunning) { final Sensor sensor = pEvent.sensor; final int sensorType = sensor.getType(); switch (sensorType) { case Sensor.TYPE_ACCELEROMETER: if (this.mAccelerationData != null) { this.mAccelerationData.setDisplayRotation(this.getDisplayOrientation()); this.mAccelerationData.setValues(pEvent.values); this.mAccelerationListener.onAccelerationChanged(this.mAccelerationData); } else if (this.mOrientationData != null) { this.mOrientationData.setDisplayRotation(this.getDisplayOrientation()); this.mOrientationData.setAccelerationValues(pEvent.values); this.mOrientationListener.onOrientationChanged(this.mOrientationData); } break; case Sensor.TYPE_MAGNETIC_FIELD: this.mOrientationData.setDisplayRotation(this.getDisplayOrientation()); this.mOrientationData.setMagneticFieldValues(pEvent.values); this.mOrientationListener.onOrientationChanged(this.mOrientationData); break; default: throw new IllegalArgumentException("Unexpected " + Sensor.class.getSimpleName() + " of Type: '" + sensorType + "'."); } } }
Example 14
Source File: SensorUtil.java From Sensor-Disabler with MIT License | 5 votes |
public static String generateUniqueSensorKey(Sensor sensor) { //TODO Maybe use Sensor.toString? return sensor.getName() + SENSOR_SEPARATOR + sensor.getVendor() + SENSOR_SEPARATOR + sensor.getVersion() + SENSOR_SEPARATOR + sensor.getType(); }
Example 15
Source File: OrientationSensor.java From geopaparazzi with GNU General Public License v3.0 | 5 votes |
@Override public void onAccuracyChanged(Sensor sensor, int accuracy) { int SensorType = sensor.getType(); switch (SensorType) { case Sensor.TYPE_GRAVITY: m_GravityAccuracy = accuracy; break; case Sensor.TYPE_MAGNETIC_FIELD: m_MagneticFieldAccuracy = accuracy; break; } if (m_parent != null) m_parent.onAccuracyChanged(sensor, accuracy); }
Example 16
Source File: AllNativeSensorProvider.java From science-journal with Apache License 2.0 | 4 votes |
private List<AdvertisedSensor> buildSensors() { List<AdvertisedSensor> sensors = new ArrayList<>(); final List<Sensor> deviceSensors = getSensorManager().getSensorList(Sensor.TYPE_ALL); for (final Sensor sensor : deviceSensors) { final SensorAppearanceResources appearance = new SensorAppearanceResources(); String name = sensor.getName(); final SensorBehavior behavior = new SensorBehavior(); behavior.loggingId = name; behavior.settingsIntent = DeviceSettingsPopupActivity.getPendingIntent(AllNativeSensorProvider.this, sensor); final int sensorType = sensor.getType(); if (sensorType == Sensor.TYPE_ACCELEROMETER) { appearance.iconId = android.R.drawable.ic_media_ff; appearance.units = "ms/2"; appearance.shortDescription = "Not really a 3-axis accelerometer"; behavior.shouldShowSettingsOnConnect = true; } if (isTemperature(sensorType)) { appearance.iconId = android.R.drawable.star_on; String unitString = TemperatureSettingsPopupActivity.getUnitString(AllNativeSensorProvider.this); appearance.units = unitString; appearance.shortDescription = "Ambient temperature (settings to change units!)"; behavior.settingsIntent = TemperatureSettingsPopupActivity.getPendingIntent(AllNativeSensorProvider.this, sensor); } String sensorAddress = "" + sensorType; sensors.add( new AdvertisedSensor(sensorAddress, name) { private SensorEventListener mSensorEventListener; @Override protected SensorAppearanceResources getAppearance() { return appearance; } @Override protected SensorBehavior getBehavior() { return behavior; } @Override protected boolean connect() throws Exception { unregister(); return true; } @Override protected void streamData(final DataConsumer c) { final int index = DeviceSettingsPopupActivity.getIndexForSensorType( sensorType, AllNativeSensorProvider.this); mSensorEventListener = new HardwareEventListener(sensorType, index, c); getSensorManager() .registerListener(mSensorEventListener, sensor, SensorManager.SENSOR_DELAY_UI); } @Override protected void disconnect() { unregister(); } private void unregister() { if (mSensorEventListener != null) { getSensorManager().unregisterListener(mSensorEventListener); mSensorEventListener = null; } } }); } return sensors; }
Example 17
Source File: SensorUtil.java From Sensor-Disabler with MIT License | 4 votes |
public static String getDescription(Sensor sensor) { switch (sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), including the force of gravity."; case Sensor.TYPE_AMBIENT_TEMPERATURE: return "Measures the ambient room temperature in degrees Celsius (°C)."; case Sensor.TYPE_GRAVITY: return "Measures the force of gravity in m/s² that is applied to a device on all three physical axes (x, y, z)."; case Sensor.TYPE_GYROSCOPE: return "Measures a device's rate of rotation in rad/s around each of the three physical axes (x, y, and z)."; case Sensor.TYPE_HEART_RATE: return "Measures heart rate."; case Sensor.TYPE_LIGHT: return "Measures the ambient light level (illumination) in lx."; case Sensor.TYPE_LINEAR_ACCELERATION: return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity."; case Sensor.TYPE_MAGNETIC_FIELD: return "Measures the ambient geomagnetic field for all three physical axes (x, y, z) in μT."; case Sensor.TYPE_PRESSURE: return "Measures the ambient air pressure in hPa or mbar."; case Sensor.TYPE_PROXIMITY: return "Measures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a person's ear."; case Sensor.TYPE_RELATIVE_HUMIDITY: return "Measures the relative ambient humidity in percent (%)."; case Sensor.TYPE_ROTATION_VECTOR: return "Measures the orientation of a device by providing the three elements of the device's rotation vector."; case Sensor.TYPE_ORIENTATION: return "Measures degrees of rotation that a device makes around all three physical axes (x, y, z). "; case Sensor.TYPE_TEMPERATURE: return "Measures the temperature of the device in degrees Celsius (°C). "; default: return "Information about this sensor is unavailable."; } }
Example 18
Source File: EnvironmentalSucker.java From CameraV with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings({ "unchecked", "deprecation" }) public EnvironmentalSucker(Context context) { super(context); setSucker(this); sm = (SensorManager)context.getApplicationContext().getSystemService(Context.SENSOR_SERVICE); availableSensors = sm.getSensorList(Sensor.TYPE_ALL); for(Sensor s : availableSensors) { switch(s.getType()) { case Sensor.TYPE_AMBIENT_TEMPERATURE: sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL); break; case Sensor.TYPE_RELATIVE_HUMIDITY: sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL); break; case Sensor.TYPE_PRESSURE: sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL); break; case Sensor.TYPE_LIGHT: sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL); break; case Sensor.TYPE_TEMPERATURE: sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL); break; } } setTask(new TimerTask() { @Override public void run() { if(currentAmbientTemp != null) sendToBuffer(currentAmbientTemp); if(currentDeviceTemp != null) sendToBuffer(currentDeviceTemp); if(currentHumidity != null) sendToBuffer(currentHumidity); if(currentPressure != null) sendToBuffer(currentPressure); if(currentLight != null) sendToBuffer(currentLight); } }); getTimer().schedule(getTask(), 0, Environment.LOG_RATE); }
Example 19
Source File: SensorMetricsCollector.java From Battery-Metrics with MIT License | 4 votes |
@Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; }
Example 20
Source File: CbService.java From PressureNet-SDK with MIT License | 4 votes |
@Override public void onAccuracyChanged(Sensor sensor, int accuracy) { if (sensor.getType() == sensorId) { } }