List of usage examples for android.hardware Sensor TYPE_RELATIVE_HUMIDITY
int TYPE_RELATIVE_HUMIDITY
To view the source code for android.hardware Sensor TYPE_RELATIVE_HUMIDITY.
Click Source Link
From source file:Main.java
public static boolean isSensorCompatible(Sensor sensor) { return sensor.getType() == Sensor.TYPE_STEP_COUNTER || sensor.getType() == Sensor.TYPE_STEP_DETECTOR || sensor.getType() == Sensor.TYPE_LIGHT || sensor.getType() == Sensor.TYPE_PRESSURE || sensor.getType() == Sensor.TYPE_RELATIVE_HUMIDITY || sensor.getType() == Sensor.TYPE_SIGNIFICANT_MOTION || sensor.getType() == Sensor.TYPE_GRAVITY; }
From source file:Main.java
@SuppressWarnings("deprecation") public static String getSensorTypeStr(int type) { switch (type) { case Sensor.TYPE_ALL://-1 return "TYPE_ALL"; //Accelerometer sensor type case Sensor.TYPE_ACCELEROMETER://1 return "TYPE_ACCELEROMETER"; //Magnetic field sensor type case Sensor.TYPE_MAGNETIC_FIELD://2 return "TYPE_MAGNETIC_FIELD"; //Orientation sensor type case Sensor.TYPE_ORIENTATION://3 return "TYPE_ORIENTATION"; //Gyroscope sensor type case Sensor.TYPE_GYROSCOPE://4 return "TYPE_GYROSCOPE"; //Light sensor type case Sensor.TYPE_LIGHT://5 return "TYPE_LIGHT"; //Pressure sensor type case Sensor.TYPE_PRESSURE://6 return "TYPE_PRESSURE"; //Temperature sensor type case Sensor.TYPE_TEMPERATURE://7 return "TYPE_TEMPERATURE"; //Proximity sensor type case Sensor.TYPE_PROXIMITY://8 return "TYPE_PROXIMITY"; //Gravity sensor type case Sensor.TYPE_GRAVITY://9 return "TYPE_GRAVITY"; //Linear acceleration sensor type case Sensor.TYPE_LINEAR_ACCELERATION://10 return "TYPE_LINEAR_ACCELERATION"; //Rotation vector sensor type case Sensor.TYPE_ROTATION_VECTOR://11 return "TYPE_ROTATION_VECTOR"; //Relative humidity sensor type case Sensor.TYPE_RELATIVE_HUMIDITY://12 return "TYPE_RELATIVE_HUMIDITY"; //Ambient temperature sensor type case Sensor.TYPE_AMBIENT_TEMPERATURE://13 return "TYPE_AMBIENT_TEMPERATURE"; //Uncalibrated magnetic field sensor type case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED://14 return "TYPE_MAGNETIC_FIELD_UNCALIBRATED"; //Uncalibrated rotation vector sensor type case Sensor.TYPE_GAME_ROTATION_VECTOR://15 return "TYPE_GAME_ROTATION_VECTOR"; //Uncalibreted gyroscope sensor type case Sensor.TYPE_GYROSCOPE_UNCALIBRATED://16 return "TYPE_GYROSCOPE_UNCALIBRATED"; //Significant motion trigger sensor case Sensor.TYPE_SIGNIFICANT_MOTION://17 return "TYPE_SIGNIFICANT_MOTION"; //Step detector sensor case Sensor.TYPE_STEP_DETECTOR://18 return "TYPE_STEP_DETECTOR"; //Step counter sensor case Sensor.TYPE_STEP_COUNTER://19 return "TYPE_STEP_COUNTER"; //Geo-magnetic rotation vector case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR://20 return "TYPE_GEOMAGNETIC_ROTATION_VECTOR"; //Heart rate monitor case Sensor.TYPE_HEART_RATE://21 return "TYPE_HEART_RATE"; default://from w w w .j a v a 2 s.c om return UNKNOWN; } }
From source file:rus.cpuinfo.AndroidDepedentModel.SensorsInfo.java
@Override @SuppressLint("NewApi") @NonNull//from w ww .ja v a2 s.c o m public String getInfo(int query) { int type; switch (query) { case SENSOR_ACCELEROMETR: type = Sensor.TYPE_ACCELEROMETER; break; case SENSOR_AMBIENT_TEMPERATURE: type = Sensor.TYPE_AMBIENT_TEMPERATURE; break; case SENSOR_LINEAR_ACCELERATION: type = Sensor.TYPE_LINEAR_ACCELERATION; break; case SENSOR_LIGHT: type = Sensor.TYPE_LIGHT; break; case SENSOR_MAGNETIC_FIELD: type = Sensor.TYPE_MAGNETIC_FIELD; break; case SENSOR_ROTATION_VECTOR: type = Sensor.TYPE_ROTATION_VECTOR; break; case SENSOR_TYPE_GRAVITY: type = Sensor.TYPE_GRAVITY; break; case SENSOR_TYPE_GYROSCOPE: type = Sensor.TYPE_GYROSCOPE; break; case SENSOR_PROXIMITY: type = Sensor.TYPE_PROXIMITY; break; case SENSOR_PRESSURE: type = Sensor.TYPE_PRESSURE; break; case SENSOR_RELATIVE_HUMIDITY: type = Sensor.TYPE_RELATIVE_HUMIDITY; break; case SENSOR_TEMPERATURE: type = Sensor.TYPE_AMBIENT_TEMPERATURE; break; case SENSOR_HUMIDITY: type = Sensor.TYPE_RELATIVE_HUMIDITY; break; case SENSOR_ORIENTATION: type = Sensor.TYPE_ORIENTATION; break; case SENSOR_HEART_RATE: type = Sensor.TYPE_HEART_RATE; break; case SENSOR_SIGNIFICANT_MOTION: type = Sensor.TYPE_SIGNIFICANT_MOTION; break; case SENSOR_GEOMAGNETIC_ROTATION_VECTOR: type = Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR; break; case SENSOR_STEP_COUNTER: type = Sensor.TYPE_STEP_COUNTER; break; case SENSOR_STEP_DETECTOR: type = Sensor.TYPE_STEP_DETECTOR; break; case SENSOR_GAME_ROTATION_VECTOR: type = Sensor.TYPE_GAME_ROTATION_VECTOR; break; default: throw new IllegalArgumentException("Query must be with \"SENSOR.\" prefix"); } return getSensorName(type); }
From source file:alaindc.crowdroid.SensorsIntentService.java
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { final String action = intent.getAction(); if (action.equals(Constants.INTENT_START_SENSORS)) { // Init throughput taken SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean(Constants.THROUGHPUT_TAKEN, false); editor.commit();/* w w w. jav a2s.co m*/ // Configure sensors and eventlistener mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE); List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensorList) { if (Constants.isInMonitoredSensors(sensor.getType())) mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } // TODO STUB: Comment this in release for (int type : Constants.STUBBED_MONITORED_SENSORS) { stub_onSensorChanged(type); } } if (action.equals(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE)) { // Configure amplitude and start TEST amplitudeTask = new GetAmplitudeTask(this); amplitudeTask.getData(); } if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_AMBIENT_TEMPERATURE)) { stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1)); } if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_PRESSURE)) { stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1)); } if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_RELATIVE_HUMIDITY)) { stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1)); } if (action.equals(Constants.INTENT_RECEIVED_AMPLITUDE)) { double amplitude = intent.getDoubleExtra(Constants.EXTRA_AMPLITUDE, -1); if (amplitude > 0) { SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(Constants.PREF_SENSOR_ + Constants.TYPE_AMPLITUDE, Double.toString(amplitude)); editor.commit(); // Update view Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS); senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, "Sensor " + Constants.getNameOfSensor(Constants.TYPE_AMPLITUDE) + " value: " + Double.toString(amplitude)); LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent); } int index = Constants.getIndexAlarmForSensor(Constants.TYPE_AMPLITUDE); // Set the alarms for next sensing of amplitude alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class); intentAlarm.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE); alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0); // TIMEOUT for another monitoring of audio int seconds = 30; // TODO: De-hardcode this alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000, alarmIntent); } } }
From source file:com.fallahpoor.infocenter.fragments.SensorsFragment.java
@TargetApi(Build.VERSION_CODES.KITKAT) public ArrayList<String> getSubItemsArrayList() { HashMap<Integer, String> sensorsHashMap = new HashMap<>(); ArrayList<String> subItems = new ArrayList<>(); Iterator<Integer> iterator; String supported = getString(R.string.supported); String unsupported = getString(R.string.unsupported); ArrayList<Integer> sensorTypes = new ArrayList<>(Arrays.asList(new Integer[] { Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_AMBIENT_TEMPERATURE, Sensor.TYPE_GRAVITY, Sensor.TYPE_GYROSCOPE, Sensor.TYPE_LIGHT, Sensor.TYPE_LINEAR_ACCELERATION, Sensor.TYPE_MAGNETIC_FIELD, Sensor.TYPE_PRESSURE, Sensor.TYPE_PROXIMITY, Sensor.TYPE_RELATIVE_HUMIDITY, Sensor.TYPE_ROTATION_VECTOR })); if (mIsApiAtLeast18) { sensorTypes.add(Sensor.TYPE_GAME_ROTATION_VECTOR); sensorTypes.add(Sensor.TYPE_SIGNIFICANT_MOTION); }/*w w w. j a v a 2 s . co m*/ if (mIsApiAtLeast19) { sensorTypes.add(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR); sensorTypes.add(Sensor.TYPE_STEP_COUNTER); sensorTypes.add(Sensor.TYPE_STEP_DETECTOR); } SensorManager sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); // Get the list of all available sensors of the device List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); iterator = sensorTypes.iterator(); // Assume all sensor types are unsupported while (iterator.hasNext()) { sensorsHashMap.put(iterator.next(), unsupported); } /* * For each sensor type that is in sensors change its status from * "unsupported" to "supported". */ for (Sensor sensor : sensors) { sensorsHashMap.put(sensor.getType(), supported); } iterator = sensorTypes.iterator(); while (iterator.hasNext()) { subItems.add(sensorsHashMap.get(iterator.next())); } return subItems; }
From source file:it.unime.mobility4ckan.MySensor.java
public void registerSensor(Sensor mSensor) { LocationListener locationListener = new LocationListener() { @Override//from w w w . jav a2 s. c om public void onLocationChanged(Location location) { //latitude = location.getLatitude(); //longitude = location.getLongitude(); currentSpeed = location.getSpeed(); //locationText.setText(String.valueOf(latitude)+ " " +String.valueOf(longitude)+ " " +String.valueOf(speed)); //isGPSReady = true; } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // } @Override public void onProviderEnabled(String provider) { // } @Override public void onProviderDisabled(String provider) { // } }; SensorEventListener sensorListener = new SensorEventListener() { @Override public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType()) { case Sensor.TYPE_AMBIENT_TEMPERATURE: // Gradi Celsius (C) currentTemp = event.values[0]; break; case Sensor.TYPE_PRESSURE: currentPressure = event.values[0]; // hPa o mbar break; case Sensor.TYPE_LIGHT: // lx currentLight = event.values[0]; break; case Sensor.TYPE_ACCELEROMETER: // m/s2 currentAcceleration[0] = event.values[0]; currentAcceleration[1] = event.values[1]; currentAcceleration[2] = event.values[2]; break; case Sensor.TYPE_GYROSCOPE: // rad/s currentGyroscope[0] = event.values[0]; currentGyroscope[1] = event.values[1]; currentGyroscope[2] = event.values[2]; break; case Sensor.TYPE_MAGNETIC_FIELD: // T currentMagnetic[0] = event.values[0]; currentMagnetic[1] = event.values[1]; currentMagnetic[2] = event.values[2]; break; case Sensor.TYPE_PROXIMITY: // cm currentProximity = event.values[0]; break; case Sensor.TYPE_ROTATION_VECTOR: // unita di misura sconosciuta currentRotation[0] = event.values[0]; currentRotation[1] = event.values[1]; currentRotation[2] = event.values[2]; break; case Sensor.TYPE_GRAVITY: // m/s2 currentGravity[0] = event.values[0]; currentGravity[1] = event.values[1]; currentGravity[2] = event.values[2]; break; case Sensor.TYPE_LINEAR_ACCELERATION: // m/s2 currentLinearAcceleration[0] = event.values[0]; currentLinearAcceleration[1] = event.values[1]; currentLinearAcceleration[2] = event.values[2]; break; case Sensor.TYPE_RELATIVE_HUMIDITY: // % currentHumidity = event.values[0]; break; default: break; } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } }; //sensorManager.registerListener(locationListener, mSensor, LocationManager.GPS_PROVIDER); /* if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; }*/ locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); sensorManager.registerListener(sensorListener, mSensor, SensorManager.SENSOR_DELAY_FASTEST); }
From source file:com.vonglasow.michael.satstat.SensorSectionFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mainActivity = (MainActivity) this.getContext(); View rootView = inflater.inflate(R.layout.fragment_main_sensors, container, false); Sensor mAccSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); Sensor mGyroSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); Sensor mMagSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); Sensor mLightSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); Sensor mProximitySensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); Sensor mPressureSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); Sensor mHumiditySensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); Sensor mTempSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); mAccSensorRes = getSensorDecimals(mAccSensor, mAccSensorRes); mGyroSensorRes = getSensorDecimals(mGyroSensor, mGyroSensorRes); mMagSensorRes = getSensorDecimals(mMagSensor, mMagSensorRes); mLightSensorRes = getSensorDecimals(mLightSensor, mLightSensorRes); mProximitySensorRes = getSensorDecimals(mProximitySensor, mProximitySensorRes); mPressureSensorRes = getSensorDecimals(mPressureSensor, mPressureSensorRes); mHumiditySensorRes = getSensorDecimals(mHumiditySensor, mHumiditySensorRes); mTempSensorRes = getSensorDecimals(mTempSensor, mTempSensorRes); // Initialize controls accStatus = (TextView) rootView.findViewById(R.id.accStatus); accHeader = (TextView) rootView.findViewById(R.id.accHeader); accX = (TextView) rootView.findViewById(R.id.accX); accY = (TextView) rootView.findViewById(R.id.accY); accZ = (TextView) rootView.findViewById(R.id.accZ); accTotal = (TextView) rootView.findViewById(R.id.accTotal); rotStatus = (TextView) rootView.findViewById(R.id.rotStatus); rotHeader = (TextView) rootView.findViewById(R.id.rotHeader); rotX = (TextView) rootView.findViewById(R.id.rotX); rotY = (TextView) rootView.findViewById(R.id.rotY); rotZ = (TextView) rootView.findViewById(R.id.rotZ); rotTotal = (TextView) rootView.findViewById(R.id.rotTotal); magStatus = (TextView) rootView.findViewById(R.id.magStatus); magHeader = (TextView) rootView.findViewById(R.id.magHeader); magX = (TextView) rootView.findViewById(R.id.magX); magY = (TextView) rootView.findViewById(R.id.magY); magZ = (TextView) rootView.findViewById(R.id.magZ); magTotal = (TextView) rootView.findViewById(R.id.magTotal); orStatus = (TextView) rootView.findViewById(R.id.orStatus); orHeader = (TextView) rootView.findViewById(R.id.orHeader); orAzimuth = (TextView) rootView.findViewById(R.id.orAzimuth); orAziText = (TextView) rootView.findViewById(R.id.orAziText); orPitch = (TextView) rootView.findViewById(R.id.orPitch); orRoll = (TextView) rootView.findViewById(R.id.orRoll); miscHeader = (TextView) rootView.findViewById(R.id.miscHeader); tempStatus = (TextView) rootView.findViewById(R.id.tempStatus); tempHeader = (TextView) rootView.findViewById(R.id.tempHeader); metTemp = (TextView) rootView.findViewById(R.id.metTemp); pressureStatus = (TextView) rootView.findViewById(R.id.pressureStatus); pressureHeader = (TextView) rootView.findViewById(R.id.pressureHeader); metPressure = (TextView) rootView.findViewById(R.id.metPressure); humidStatus = (TextView) rootView.findViewById(R.id.humidStatus); humidHeader = (TextView) rootView.findViewById(R.id.humidHeader); metHumid = (TextView) rootView.findViewById(R.id.metHumid); lightStatus = (TextView) rootView.findViewById(R.id.lightStatus); lightHeader = (TextView) rootView.findViewById(R.id.lightHeader); light = (TextView) rootView.findViewById(R.id.light); proximityStatus = (TextView) rootView.findViewById(R.id.proximityStatus); proximityHeader = (TextView) rootView.findViewById(R.id.proximityHeader); proximity = (TextView) rootView.findViewById(R.id.proximity); mainActivity.sensorSectionFragment = this; return rootView; }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java
@Override public void onCreate() { // The service is being created Log.e(TAG, "onCreate"); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (pref.getBoolean(getResources().getString(R.string.in_acc), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); }//from w w w . j ava 2 s .com if (pref.getBoolean(getResources().getString(R.string.in_lig), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_pres), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_prox), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_mag), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_gyrs), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_grav), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_hum), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_lin_acc), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_tem), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } }
From source file:alaindc.crowdroid.SensorsIntentService.java
public void stub_onSensorChanged(int typeSensor) { if (typeSensor < 0) return;/*from w w w . ja va2 s. c o m*/ float value, minf, maxf; switch (typeSensor) { case Sensor.TYPE_AMBIENT_TEMPERATURE: minf = -20; maxf = 42; break; case Sensor.TYPE_PRESSURE: // https://it.wikipedia.org/wiki/Pressione_atmosferica minf = 870; maxf = 1085; break; case Sensor.TYPE_RELATIVE_HUMIDITY: minf = 30; maxf = 100; break; default: minf = 0; maxf = 0; break; } value = random.nextFloat() * (maxf - minf) + minf; int index = Constants.getIndexAlarmForSensor(typeSensor); SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(Constants.PREF_SENSOR_ + typeSensor, Float.toString(value)); editor.commit(); // Update view Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS); senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, "Sensor " + Constants.getNameOfSensor(typeSensor) + " value: " + Float.toString(value)); LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent); // Set the alarm random alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class); intentAlarm.setAction(Constants.INTENT_STUB_SENSOR_CHANGED + typeSensor); intentAlarm.putExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, typeSensor); alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0); // TODO Set timeout time from server indications int seconds = random.nextInt(50) + 10; // 10/60 sec alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000, alarmIntent); }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.fragments.GraphPlotFragment.java
private void updateTitleAndType() { ArrayList<String> grpTitle = new ArrayList<String>(); ArrayList<Integer> grpType = new ArrayList<Integer>(); ArrayList<Boolean> grpBarType = new ArrayList<Boolean>(); SharedPreferences pref = PreferenceManager .getDefaultSharedPreferences(getActivity().getApplicationContext()); if (pref.getBoolean(getResources().getString(R.string.in_hum), false)) { grpTitle.add("Humidity"); grpType.add(Sensor.TYPE_RELATIVE_HUMIDITY); grpBarType.add(false);/*from w w w. ja va 2 s. c om*/ } if (pref.getBoolean(getResources().getString(R.string.in_lig), false)) { grpTitle.add("Light in lux/min"); grpType.add(Sensor.TYPE_LIGHT); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.in_pres), false)) { grpTitle.add("Pressure in min"); grpType.add(Sensor.TYPE_PRESSURE); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.in_prox), false)) { grpTitle.add("Proximity in min"); grpType.add(Sensor.TYPE_PROXIMITY); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.in_tem), false)) { grpTitle.add("Ambient Temperature in C"); grpType.add(Sensor.TYPE_AMBIENT_TEMPERATURE); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.pulse), false)) { grpTitle.add("Heart Rate bpm"); grpType.add(999); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.in_acc), false)) { grpTitle.add("Motion Strength/min"); grpType.add(Sensor.TYPE_ACCELEROMETER); grpBarType.add(true); } if (pref.getBoolean(getResources().getString(R.string.in_mag), false)) { grpTitle.add("Magnetic Field Strength/min"); grpType.add(Sensor.TYPE_MAGNETIC_FIELD); grpBarType.add(true); } if (pref.getBoolean(getResources().getString(R.string.in_grav), false)) { grpTitle.add("Gravity Strength/min"); grpType.add(Sensor.TYPE_GRAVITY); grpBarType.add(true); } if (pref.getBoolean(getResources().getString(R.string.in_gyrs), false)) { grpTitle.add("Gyroscope Strength/min"); grpType.add(Sensor.TYPE_GYROSCOPE); grpBarType.add(true); } if (pref.getBoolean(getResources().getString(R.string.in_lin_acc), false)) { grpTitle.add("Linear Accelerometer Strength/min"); grpType.add(Sensor.TYPE_LINEAR_ACCELERATION); grpBarType.add(true); } if (grpTitle.size() == 2 && grpType.size() == 2) { firstGrpTitle = grpTitle.get(0); firstGrpType = grpType.get(0); isFirstBar = grpBarType.get(0); secondGrpTitle = grpTitle.get(1); secondGrpType = grpType.get(1); isSecondBar = grpBarType.get(1); } else if (grpTitle.size() == 1 && grpType.size() == 1) { firstGrpTitle = grpTitle.get(0); firstGrpType = grpType.get(0); isFirstBar = grpBarType.get(0); secondGrpTitle = ""; secondGrpType = -1; } }