use of android.hardware.SensorManager in project collect by opendatakit.
the class BearingWidget method checkForRequiredSensors.
private boolean checkForRequiredSensors() {
boolean isAccelerometerSensorAvailable = false;
boolean isMagneticFieldSensorAvailable = false;
SensorManager sensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
isAccelerometerSensorAvailable = true;
}
if (sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null) {
isMagneticFieldSensorAvailable = true;
}
if (!isAccelerometerSensorAvailable || !isMagneticFieldSensorAvailable) {
return false;
}
return true;
}
use of android.hardware.SensorManager in project TrekAdvisor by peterLaurence.
the class OrientationEventManager method start.
public void start() {
/* If no listener, no need to go further */
if (mOrientationListener == null)
return;
mOrientationThread = new HandlerThread("Orientation calculation thread", Thread.MIN_PRIORITY);
mOrientationThread.start();
/* Create a handler on the ui thread */
Handler handler = new Handler(Looper.getMainLooper());
/* This runnable will be executed on ui thread after each distance calculation */
UpdateOrientationListenerRunnable updateUiRunnable = new UpdateOrientationListenerRunnable(mOrientationListener);
/* The task to be executed on the dedicated thread */
OrientationCalculationRunnable runnable = new OrientationCalculationRunnable(mActivity, handler, updateUiRunnable);
mHandler = new LimitedHandler(mOrientationThread.getLooper(), runnable);
/* Subscribe to orientation events */
SensorManager sensorManager = (SensorManager) mActivity.getSystemService(Context.SENSOR_SERVICE);
Sensor mSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
sensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_UI);
/* Then update the listener (view) */
if (mOrientationListener != null) {
mOrientationListener.onOrientationEnable();
}
mStarted = true;
}
use of android.hardware.SensorManager in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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 Osmand by osmandapp.
the class DashLocationFragment method getScreenOrientation.
public static int getScreenOrientation(Activity a) {
int screenOrientation = ((WindowManager) a.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
switch(screenOrientation) {
case // Device default (normally portrait)
ORIENTATION_0:
screenOrientation = 0;
break;
case // Landscape right
ORIENTATION_90:
screenOrientation = 90;
break;
case // Landscape left
ORIENTATION_270:
screenOrientation = 270;
break;
case // Upside down
ORIENTATION_180:
screenOrientation = 180;
break;
}
// Looks like screenOrientation correction must not be applied for devices without compass?
Sensor compass = ((SensorManager) a.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
if (compass == null) {
screenOrientation = 0;
}
return screenOrientation;
}
Aggregations