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);
}
}
}
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);
}
}
}
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;
}
}
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;
}
}
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;
}
Aggregations