use of android.hardware.SensorManager in project CalendarTrigger by rparkins999.
the class MuteService method checkOrientationWait.
// return true if still waiting for correct orientation
private boolean checkOrientationWait(int classNum, boolean before) {
int wanted;
if (before) {
wanted = PrefsManager.getBeforeOrientation(this, classNum);
} else {
wanted = PrefsManager.getAfterOrientation(this, classNum);
}
if ((wanted == 0) || (wanted == PrefsManager.BEFORE_ANY_POSITION)) {
return false;
}
switch(PrefsManager.getOrientationState(this)) {
case // sensor currently not active
PrefsManager.ORIENTATION_IDLE:
SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
Sensor ams = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
if (ams == null) {
return false;
}
lock();
PrefsManager.setOrientationState(this, PrefsManager.ORIENTATION_WAITING);
sm.registerListener(this, ams, SensorManager.SENSOR_DELAY_FASTEST);
new MyLog(this, "Requested accelerometer value for class ".concat(PrefsManager.getClassName(this, classNum)));
// FALLTHRU
case // waiting for value
PrefsManager.ORIENTATION_WAITING:
return true;
case // just got a value
PrefsManager.ORIENTATION_DONE:
nextAccelTime = System.currentTimeMillis() + FIVE_MINUTES;
new MyLog(this, "accelerometerX = " + String.valueOf(accelerometerX) + ", accelerometerY = " + String.valueOf(accelerometerY) + ", accelerometerZ = " + String.valueOf(accelerometerZ));
if ((accelerometerX >= -0.3) && (accelerometerX <= 0.3) && (accelerometerY >= -0.3) && (accelerometerY <= 0.3) && (accelerometerZ >= 9.6) && (accelerometerZ <= 10.0)) {
if ((wanted & PrefsManager.BEFORE_FACE_UP) != 0) {
return false;
}
} else if ((accelerometerX >= -0.3) && (accelerometerX <= 0.3) && (accelerometerY >= -0.3) && (accelerometerY <= 0.3) && (accelerometerZ >= -10.0) && (accelerometerZ <= -9.6)) {
if ((wanted & PrefsManager.BEFORE_FACE_DOWN) != 0) {
return false;
}
} else if ((wanted & PrefsManager.BEFORE_OTHER_POSITION) != 0) {
return false;
}
nextAccelTime = System.currentTimeMillis() + FIVE_MINUTES;
PrefsManager.setOrientationState(this, PrefsManager.ORIENTATION_IDLE);
new MyLog(this, "Still waiting for orientation for class ".concat(PrefsManager.getClassName(this, classNum)));
return true;
default:
return false;
}
}
use of android.hardware.SensorManager in project CalendarTrigger by rparkins999.
the class MuteService method onSensorChanged.
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
switch(sensorEvent.sensor.getType()) {
case Sensor.TYPE_STEP_COUNTER:
{
int newCounterSteps = (int) sensorEvent.values[0];
if (newCounterSteps != PrefsManager.getStepCount(this)) {
PrefsManager.setStepCount(this, newCounterSteps);
startIfNecessary(this, "Step counter changed");
}
}
break;
case Sensor.TYPE_ACCELEROMETER:
SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
sm.unregisterListener(this);
accelerometerX = sensorEvent.values[0];
accelerometerY = sensorEvent.values[1];
accelerometerZ = sensorEvent.values[2];
PrefsManager.setOrientationState(this, PrefsManager.ORIENTATION_DONE);
startIfNecessary(this, "Accelerometer event");
break;
default:
}
}
use of android.hardware.SensorManager in project CalendarTrigger by rparkins999.
the class MuteService method StartStepCounter.
// FIXME can we use a similar power saving trick as accelerometer?
// return true if step counter is now running
private boolean StartStepCounter(int classNum) {
if (PrefsManager.getStepCount(this) == PrefsManager.STEP_COUNTER_IDLE) {
SensorManager sensorManager = (SensorManager) getSystemService(Activity.SENSOR_SERVICE);
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER, true);
if (sensor == null) {
// if we can't get a wakeup step counter, try without
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
if (sensor == null) {
// no step counter at all
return false;
}
}
if (sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL)) {
new MyLog(this, "Step counter activated for class ".concat(PrefsManager.getClassName(this, classNum)));
if (sensor.isWakeUpSensor()) {
PrefsManager.setStepCount(this, PrefsManager.STEP_COUNTER_WAKEUP);
} else {
PrefsManager.setStepCount(this, PrefsManager.STEP_COUNTER_WAKE_LOCK);
lock();
}
return true;
} else {
// could not activate step counter
return false;
}
} else {
// already starting it for another class
return true;
}
}
use of android.hardware.SensorManager in project android_packages_apps_Settings by crdroidandroid.
the class DoubleTwistPreferenceController method isGestureAvailable.
public static boolean isGestureAvailable(Context context) {
final Resources resources = context.getResources();
final String name = resources.getString(R.string.gesture_double_twist_sensor_name);
final String vendor = resources.getString(R.string.gesture_double_twist_sensor_vendor);
if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(vendor)) {
final 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.SensorManager in project QRCode by 5peak2me.
the class AmbientLightManager method stop.
void stop() {
if (lightSensor != null) {
SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
sensorManager.unregisterListener(this);
cameraManager = null;
lightSensor = null;
}
}
Aggregations