use of android.hardware.Sensor in project AndroidSDK-RecipeBook by gabu.
the class ProximityManager method onResume.
public void onResume() {
// 近接センサーを取得
List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_PROXIMITY);
// 取得できなければ何もしない
if (list.size() < 1)
return;
// 近接センサーを取得
Sensor sensor = list.get(0);
// 近接センサーにリスナーを登録
// 第3引数で感度を指定できます。
mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
use of android.hardware.Sensor in project nmid-headline by miao1007.
the class Shake2Share method startSensor.
private void startSensor() {
mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
if (mSensorManager == null) {
throw new UnsupportedOperationException();
}
Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
if (sensor == null) {
throw new UnsupportedOperationException();
}
boolean success = mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
if (!success) {
throw new UnsupportedOperationException();
}
}
use of android.hardware.Sensor in project libgdx by libgdx.
the class AndroidInput method registerSensorListeners.
void registerSensorListeners() {
if (config.useAccelerometer) {
manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() == 0) {
accelerometerAvailable = false;
} else {
Sensor accelerometer = manager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
accelerometerListener = new SensorListener(this.nativeOrientation, this.accelerometerValues, this.magneticFieldValues, this.gyroscopeValues);
accelerometerAvailable = manager.registerListener(accelerometerListener, accelerometer, SensorManager.SENSOR_DELAY_GAME);
}
} else
accelerometerAvailable = false;
if (config.useGyroscope) {
manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
if (manager.getSensorList(Sensor.TYPE_GYROSCOPE).size() == 0) {
gyroscopeAvailable = false;
} else {
Sensor gyroscope = manager.getSensorList(Sensor.TYPE_GYROSCOPE).get(0);
gyroscopeListener = new SensorListener(this.nativeOrientation, this.gyroscopeValues, this.magneticFieldValues, this.gyroscopeValues);
gyroscopeAvailable = manager.registerListener(gyroscopeListener, gyroscope, SensorManager.SENSOR_DELAY_GAME);
}
} else
gyroscopeAvailable = false;
if (config.useCompass) {
if (manager == null)
manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
Sensor sensor = manager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
if (sensor != null) {
compassAvailable = accelerometerAvailable;
if (compassAvailable) {
compassListener = new SensorListener(this.nativeOrientation, this.accelerometerValues, this.magneticFieldValues, this.gyroscopeValues);
compassAvailable = manager.registerListener(compassListener, sensor, SensorManager.SENSOR_DELAY_GAME);
}
} else {
compassAvailable = false;
}
} else
compassAvailable = false;
Gdx.app.log("AndroidInput", "sensor listener setup");
}
use of android.hardware.Sensor in project cw-omnibus by commonsguy.
the class MainActivity method getSensorList.
@Override
public List<Sensor> getSensorList() {
List<Sensor> unfiltered = new ArrayList<Sensor>(mgr.getSensorList(Sensor.TYPE_ALL));
List<Sensor> result = new ArrayList<Sensor>();
for (Sensor s : unfiltered) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || !isTriggerSensor(s)) {
result.add(s);
}
}
Collections.sort(result, new Comparator<Sensor>() {
@Override
public int compare(final Sensor a, final Sensor b) {
return (a.toString().compareTo(b.toString()));
}
});
return (result);
}
use of android.hardware.Sensor in project jpHolo by teusink.
the class AccelListener method start.
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
//
/**
* Start listening for acceleration sensor.
*
* @return status of listener
*/
private int start() {
// If already starting or running, then just return
if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) {
return this.status;
}
this.setStatus(AccelListener.STARTING);
// Get accelerometer from sensor manager
List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
// If found, then register as listener
if ((list != null) && (list.size() > 0)) {
this.mSensor = list.get(0);
this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI);
this.setStatus(AccelListener.STARTING);
} else {
this.setStatus(AccelListener.ERROR_FAILED_TO_START);
this.fail(AccelListener.ERROR_FAILED_TO_START, "No sensors found to register accelerometer listening to.");
return this.status;
}
// Set a timeout callback on the main thread.
stopTimeout();
mainHandler = new Handler(Looper.getMainLooper());
mainHandler.postDelayed(mainRunnable, 2000);
return this.status;
}
Aggregations