use of android.hardware.SensorEventListener in project android_frameworks_base by crdroidandroid.
the class PowerManagerService method runPostProximityCheck.
private void runPostProximityCheck(final Runnable r) {
if (mSensorManager == null) {
r.run();
return;
}
synchronized (mProximityWakeLock) {
mProximityWakeLock.acquire();
mProximityListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
cleanupProximityLocked();
if (!mHandler.hasMessages(MSG_WAKE_UP)) {
Slog.w(TAG, "Proximity sensor took too long, wake event already triggered!");
return;
}
mHandler.removeMessages(MSG_WAKE_UP);
final float distance = event.values[0];
if (distance >= PROXIMITY_NEAR_THRESHOLD || distance >= mProximitySensor.getMaximumRange()) {
r.run();
} else {
Slog.w(TAG, "Not waking up. Proximity sensor is blocked.");
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do nothing
}
};
mSensorManager.registerListener(mProximityListener, mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
}
}
use of android.hardware.SensorEventListener in project robolectric by robolectric.
the class ShadowSensorManagerTest method shouldReturnHasNoListenerAfterUnregisterListener.
@Test
public void shouldReturnHasNoListenerAfterUnregisterListener() {
SensorEventListener listener = registerListener();
sensorManager.unregisterListener(listener, sensorManager.getDefaultSensor(SensorManager.SENSOR_ACCELEROMETER));
assertThat(shadow.hasListener(listener)).isFalse();
}
use of android.hardware.SensorEventListener in project robolectric by robolectric.
the class ShadowSensorManagerTest method shouldReturnHasNoListenerAfterUnregisterListenerWithoutSpecificSensor.
@Test
public void shouldReturnHasNoListenerAfterUnregisterListenerWithoutSpecificSensor() {
SensorEventListener listener = registerListener();
sensorManager.unregisterListener(listener);
assertThat(shadow.hasListener(listener)).isFalse();
}
use of android.hardware.SensorEventListener in project android_frameworks_base by DirtyUnicorns.
the class PowerManagerService method runPostProximityCheck.
private void runPostProximityCheck(final Runnable r) {
if (mSensorManager == null) {
r.run();
return;
}
synchronized (mProximityWakeLock) {
mProximityWakeLock.acquire();
mProximityListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
cleanupProximityLocked();
if (!mHandler.hasMessages(MSG_WAKE_UP)) {
Slog.w(TAG, "Proximity sensor took too long, wake event already triggered!");
return;
}
mHandler.removeMessages(MSG_WAKE_UP);
final float distance = event.values[0];
if (distance >= PROXIMITY_NEAR_THRESHOLD || distance >= mProximitySensor.getMaximumRange()) {
r.run();
} else {
Slog.w(TAG, "Not waking up. Proximity sensor is blocked.");
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do nothing
}
};
mSensorManager.registerListener(mProximityListener, mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
}
}
Aggregations