use of android.hardware.Sensor in project cordova-android-chromeview by thedracle.
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.
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
public void run() {
AccelListener.this.timeout();
}
}, 2000);
return this.status;
}
use of android.hardware.Sensor 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);
}
}
use of android.hardware.Sensor in project robolectric by robolectric.
the class ShadowSensorManagerTest method getSensor_shouldBeConfigurable.
@Test
public void getSensor_shouldBeConfigurable() {
Sensor sensor = Shadow.newInstanceOf(Sensor.class);
shadowOf(sensorManager).addSensor(Sensor.TYPE_ACCELEROMETER, sensor);
assertThat(sensor).isSameAs(sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
}
use of android.hardware.Sensor in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class GestureSettings method hasSensor.
private static boolean hasSensor(Context context, int nameResId, int vendorResId) {
Resources resources = context.getResources();
String name = resources.getString(nameResId);
String vendor = resources.getString(vendorResId);
if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(vendor)) {
SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
for (Sensor s : sensorManager.getSensorList(Sensor.TYPE_ALL)) {
if (name.equals(s.getName()) && vendor.equals(s.getVendor())) {
return true;
}
}
}
return false;
}
use of android.hardware.Sensor in project android_frameworks_base by crdroidandroid.
the class SensorPowerCalculator method calculateApp.
@Override
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs, long rawUptimeUs, int statsType) {
// Process Sensor usage
final SparseArray<? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats();
final int NSE = sensorStats.size();
for (int ise = 0; ise < NSE; ise++) {
final BatteryStats.Uid.Sensor sensor = sensorStats.valueAt(ise);
final int sensorHandle = sensorStats.keyAt(ise);
final BatteryStats.Timer timer = sensor.getSensorTime();
final long sensorTime = timer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000;
switch(sensorHandle) {
case BatteryStats.Uid.Sensor.GPS:
app.gpsTimeMs = sensorTime;
app.gpsPowerMah = (app.gpsTimeMs * mGpsPowerOn) / (1000 * 60 * 60);
break;
default:
final int sensorsCount = mSensors.size();
for (int i = 0; i < sensorsCount; i++) {
final Sensor s = mSensors.get(i);
if (s.getHandle() == sensorHandle) {
app.sensorPowerMah += (sensorTime * s.getPower()) / (1000 * 60 * 60);
break;
}
}
break;
}
}
}
Aggregations