Search in sources :

Example 66 with SensorManager

use of android.hardware.SensorManager in project QRCode by 5peak2me.

the class AmbientLightManager method start.

void start(CameraManager cameraManager) {
    this.cameraManager = cameraManager;
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
        SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
        if (lightSensor != null) {
            sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
        }
    }
}
Also used : SensorManager(android.hardware.SensorManager) SharedPreferences(android.content.SharedPreferences)

Example 67 with SensorManager

use of android.hardware.SensorManager in project zxing-android-embedded by journeyapps.

the class AmbientLightManager method start.

public void start() {
    if (cameraSettings.isAutoTorchEnabled()) {
        SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
        if (lightSensor != null) {
            sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
        }
    }
}
Also used : SensorManager(android.hardware.SensorManager)

Example 68 with SensorManager

use of android.hardware.SensorManager in project zxing-android-embedded by journeyapps.

the class AmbientLightManager method stop.

public void stop() {
    if (lightSensor != null) {
        SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        sensorManager.unregisterListener(this);
        lightSensor = null;
    }
}
Also used : SensorManager(android.hardware.SensorManager)

Example 69 with SensorManager

use of android.hardware.SensorManager in project zxingfragmentlib by mitoyarzun.

the class AmbientLightManager method stop.

public void stop() {
    if (lightSensor != null) {
        SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        sensorManager.unregisterListener(this);
        cameraManager = null;
        lightSensor = null;
    }
}
Also used : SensorManager(android.hardware.SensorManager)

Example 70 with SensorManager

use of android.hardware.SensorManager in project aware-client by denzilferreira.

the class Aware method sensorDiff.

/**
 * This function returns a list of sensors to enable and one to disable because of server side configuration changes
 *
 * @param server
 * @param local
 * @return
 * @throws JSONException
 */
private static ArrayList<JSONArray> sensorDiff(Context context, JSONArray server, JSONArray local) throws JSONException {
    SensorManager manager = (SensorManager) context.getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL);
    Hashtable<Integer, Boolean> listSensorType = new Hashtable<>();
    for (int i = 0; i < sensors.size(); i++) {
        listSensorType.put(sensors.get(i).getType(), true);
    }
    Hashtable<String, Integer> optionalSensors = new Hashtable<>();
    optionalSensors.put(Aware_Preferences.STATUS_ACCELEROMETER, Sensor.TYPE_ACCELEROMETER);
    optionalSensors.put(Aware_Preferences.STATUS_SIGNIFICANT_MOTION, Sensor.TYPE_ACCELEROMETER);
    optionalSensors.put(Aware_Preferences.STATUS_BAROMETER, Sensor.TYPE_PRESSURE);
    optionalSensors.put(Aware_Preferences.STATUS_GRAVITY, Sensor.TYPE_GRAVITY);
    optionalSensors.put(Aware_Preferences.STATUS_GYROSCOPE, Sensor.TYPE_GYROSCOPE);
    optionalSensors.put(Aware_Preferences.STATUS_LIGHT, Sensor.TYPE_LIGHT);
    optionalSensors.put(Aware_Preferences.STATUS_LINEAR_ACCELEROMETER, Sensor.TYPE_LINEAR_ACCELERATION);
    optionalSensors.put(Aware_Preferences.STATUS_MAGNETOMETER, Sensor.TYPE_MAGNETIC_FIELD);
    optionalSensors.put(Aware_Preferences.STATUS_PROXIMITY, Sensor.TYPE_PROXIMITY);
    optionalSensors.put(Aware_Preferences.STATUS_ROTATION, Sensor.TYPE_ROTATION_VECTOR);
    optionalSensors.put(Aware_Preferences.STATUS_TEMPERATURE, Sensor.TYPE_AMBIENT_TEMPERATURE);
    Set<String> keys = optionalSensors.keySet();
    JSONArray to_enable = new JSONArray();
    JSONArray to_disable = new JSONArray();
    ArrayList<String> immutable_settings = new ArrayList<>();
    immutable_settings.add("status_mqtt");
    immutable_settings.add("mqtt_server");
    immutable_settings.add("mqtt_port");
    immutable_settings.add("mqtt_keep_alive");
    immutable_settings.add("mqtt_qos");
    immutable_settings.add("mqtt_username");
    immutable_settings.add("mqtt_password");
    immutable_settings.add("status_esm");
    immutable_settings.add("study_id");
    immutable_settings.add("study_start");
    immutable_settings.add("webservice_server");
    immutable_settings.add("status_webservice");
    // enable new sensors from the server
    for (int i = 0; i < server.length(); i++) {
        JSONObject server_sensor = server.getJSONObject(i);
        for (String optionalSensor : keys) {
            if (server_sensor.getString("setting").equalsIgnoreCase(optionalSensor) && !listSensorType.containsKey(optionalSensors.get(optionalSensor)))
                continue;
        }
        if (immutable_settings.contains(server_sensor.getString("setting"))) {
            // don't do anything
            continue;
        }
        boolean is_present = false;
        for (int j = 0; j < local.length(); j++) {
            JSONObject local_sensor = local.getJSONObject(j);
            if (local_sensor.getString("setting").equalsIgnoreCase(server_sensor.getString("setting")) && local_sensor.getString("value").equals(server_sensor.getString("value"))) {
                is_present = true;
                break;
            }
        }
        if (!is_present)
            to_enable.put(server_sensor);
    }
    // disable local sensors that are no longer in the server
    for (int j = 0; j < local.length(); j++) {
        JSONObject local_sensor = local.getJSONObject(j);
        if (immutable_settings.contains(local_sensor.getString("setting"))) {
            // don't do anything
            continue;
        }
        for (String optionalSensor : keys) {
            if (local_sensor.getString("setting").equalsIgnoreCase(optionalSensor) && !listSensorType.containsKey(optionalSensors.get(optionalSensor)))
                continue;
        }
        boolean remove = true;
        for (int i = 0; i < server.length(); i++) {
            JSONObject server_sensor = server.getJSONObject(i);
            if (local_sensor.getString("setting").equalsIgnoreCase(server_sensor.getString("setting"))) {
                remove = false;
                break;
            }
        }
        if (remove)
            to_disable.put(local_sensor);
    }
    ArrayList<JSONArray> output = new ArrayList<>();
    output.add(to_enable);
    output.add(to_disable);
    return output;
}
Also used : JSONArray(org.json.JSONArray) SensorManager(android.hardware.SensorManager) JSONObject(org.json.JSONObject) 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