Search in sources :

Example 51 with SensorManager

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;
}
Also used : SensorManager(android.hardware.SensorManager)

Example 52 with SensorManager

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;
}
Also used : HandlerThread(android.os.HandlerThread) SensorManager(android.hardware.SensorManager) Handler(android.os.Handler) Sensor(android.hardware.Sensor)

Example 53 with SensorManager

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);
    }
}
Also used : SensorManager(android.hardware.SensorManager)

Example 54 with SensorManager

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.");
    }
}
Also used : SensorManager(android.hardware.SensorManager)

Example 55 with SensorManager

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;
}
Also used : SensorManager(android.hardware.SensorManager) SuppressLint(android.annotation.SuppressLint) Sensor(android.hardware.Sensor)

Aggregations

SensorManager (android.hardware.SensorManager)89 Sensor (android.hardware.Sensor)29 SharedPreferences (android.content.SharedPreferences)12 Resources (android.content.res.Resources)8 PowerManager (android.os.PowerManager)6 ContentResolver (android.content.ContentResolver)5 IntentFilter (android.content.IntentFilter)5 SystemSensorManager (android.hardware.SystemSensorManager)5 IPowerManager (android.os.IPowerManager)5 RemoteException (android.os.RemoteException)5 WindowManager (android.view.WindowManager)5 DisplayManagerInternal (android.hardware.display.DisplayManagerInternal)4 BatteryManagerInternal (android.os.BatteryManagerInternal)4 DreamManagerInternal (android.service.dreams.DreamManagerInternal)4 IVrManager (android.service.vr.IVrManager)4 Display (android.view.Display)4 WindowManagerPolicy (android.view.WindowManagerPolicy)4 LightsManager (com.android.server.lights.LightsManager)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3