use of android.hardware.SensorManager in project NotificationPeekPort by lzanita09.
the class SensorHelper method checkSensorStatus.
/**
* Check if the given sensor is presented in the device and/or the user choose to use it.
*
* @param context Context instance.
* @param sensor Sensor type, can be {@link SensorHelper#SENSOR_GYRO}
* or {@link SensorHelper#SENSOR_PROXIMITY_LIGHT}
* @param combinePreference Boolean value for whether we need to check the preference or not.
* @return
*/
public static boolean checkSensorStatus(Context context, int sensor, boolean combinePreference) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
switch(sensor) {
case SENSOR_PROXIMITY_LIGHT:
Sensor proxSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) != null ? sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) : sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
return proxSensor != null && (preferences.getBoolean(PreferenceKeys.PREF_PROX_LIGHT_SENSOR, true) || !combinePreference);
case SENSOR_GYRO:
Sensor gyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
return gyroSensor != null && (preferences.getBoolean(PreferenceKeys.PREF_GYRO_SENSOR, true) || !combinePreference);
default:
return false;
}
}
use of android.hardware.SensorManager in project android_frameworks_base by DirtyUnicorns.
the class GestureLauncherService method registerCameraLaunchGesture.
/**
* Registers for the camera launch gesture.
*/
private void registerCameraLaunchGesture(Resources resources) {
if (mRegistered) {
return;
}
mCameraGestureOnTimeMs = SystemClock.elapsedRealtime();
mCameraGestureLastEventTime = mCameraGestureOnTimeMs;
SensorManager sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
int cameraLaunchGestureId = resources.getInteger(com.android.internal.R.integer.config_cameraLaunchGestureSensorType);
if (cameraLaunchGestureId != -1) {
mRegistered = false;
String sensorName = resources.getString(com.android.internal.R.string.config_cameraLaunchGestureSensorStringType);
mCameraLaunchSensor = sensorManager.getDefaultSensor(cameraLaunchGestureId, true);
// makes the code more robust.
if (mCameraLaunchSensor != null) {
if (sensorName.equals(mCameraLaunchSensor.getStringType())) {
mRegistered = sensorManager.registerListener(mGestureListener, mCameraLaunchSensor, 0);
} else {
String message = String.format("Wrong configuration. Sensor type and sensor " + "string type don't match: %s in resources, %s in the sensor.", sensorName, mCameraLaunchSensor.getStringType());
throw new RuntimeException(message);
}
}
if (DBG)
Slog.d(TAG, "Camera launch sensor registered: " + mRegistered);
} else {
if (DBG)
Slog.d(TAG, "Camera launch sensor is not specified.");
}
}
use of android.hardware.SensorManager in project weex-example by KalicyZhou.
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;
}
}
use of android.hardware.SensorManager in project android_frameworks_base by ResurrectionRemix.
the class GestureLauncherService method unregisterCameraLaunchGesture.
private void unregisterCameraLaunchGesture() {
if (mRegistered) {
mRegistered = false;
mCameraGestureOnTimeMs = 0L;
mCameraGestureLastEventTime = 0L;
mCameraGestureSensor1LastOnTimeMs = 0;
mCameraGestureSensor2LastOnTimeMs = 0;
mCameraLaunchLastEventExtra = 0;
SensorManager sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
sensorManager.unregisterListener(mGestureListener);
}
}
use of android.hardware.SensorManager in project android_frameworks_base by ResurrectionRemix.
the class GestureLauncherService method registerCameraLaunchGesture.
/**
* Registers for the camera launch gesture.
*/
private void registerCameraLaunchGesture(Resources resources) {
if (mRegistered) {
return;
}
mCameraGestureOnTimeMs = SystemClock.elapsedRealtime();
mCameraGestureLastEventTime = mCameraGestureOnTimeMs;
SensorManager sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
int cameraLaunchGestureId = resources.getInteger(com.android.internal.R.integer.config_cameraLaunchGestureSensorType);
if (cameraLaunchGestureId != -1) {
mRegistered = false;
String sensorName = resources.getString(com.android.internal.R.string.config_cameraLaunchGestureSensorStringType);
mCameraLaunchSensor = sensorManager.getDefaultSensor(cameraLaunchGestureId, true);
// makes the code more robust.
if (mCameraLaunchSensor != null) {
if (sensorName.equals(mCameraLaunchSensor.getStringType())) {
mRegistered = sensorManager.registerListener(mGestureListener, mCameraLaunchSensor, 0);
} else {
String message = String.format("Wrong configuration. Sensor type and sensor " + "string type don't match: %s in resources, %s in the sensor.", sensorName, mCameraLaunchSensor.getStringType());
throw new RuntimeException(message);
}
}
if (DBG)
Slog.d(TAG, "Camera launch sensor registered: " + mRegistered);
} else {
if (DBG)
Slog.d(TAG, "Camera launch sensor is not specified.");
}
}
Aggregations