List of usage examples for android.hardware Sensor TYPE_PRESSURE
int TYPE_PRESSURE
To view the source code for android.hardware Sensor TYPE_PRESSURE.
Click Source Link
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); }// www . j av a2 s . c o m 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:root.gast.playground.sensor.altitude.DetermineAltitudeActivity.java
@Override protected void onResume() { super.onResume(); List<String> enabledProviders = locationManager.getProviders(true); if (enabledProviders.isEmpty() || !enabledProviders.contains(LocationManager.GPS_PROVIDER)) { Toast.makeText(this, R.string.gpsNotEnabledMessage, Toast.LENGTH_LONG).show(); } else {/*from ww w .j a va 2 s .c o m*/ // Register every location provider returned from LocationManager for (String provider : enabledProviders) { // Register for updates every minute locationManager.requestLocationUpdates(provider, 60000, // minimum time of 60000 ms (1 minute) 0, // Minimum distance of 0 this, null); } } Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); // Only make registration call if device has a pressure sensor if (sensor != null) { sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } }
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:uk.ac.horizon.ubihelper.service.Service.java
@Override public void onCreate() { // One-time set-up... Log.d(TAG, "onCreate()"); // TODO/*ww w. ja v a 2 s. c om*/ super.onCreate(); // handler for requests mHandler = new Handler(); // create taskbar notification int icon = R.drawable.service_notification_icon; CharSequence tickerText = getText(R.string.notification_start_message); long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = this; CharSequence contentTitle = getText(R.string.notification_title); CharSequence contentText = getText(R.string.notification_description); Intent notificationIntent = new Intent(this, MainPreferences.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); startForeground(RUNNING_ID, notification); channelManager = new ChannelManager(peerChannelFactory); // sensors if (!isEmulator()) { Log.d(TAG, "Create sensor channels..."); SensorChannel magnetic = new SensorChannel("magnetic", this, Sensor.TYPE_MAGNETIC_FIELD); channelManager.addChannel(magnetic); SensorChannel accelerometer = new SensorChannel("accelerometer", this, Sensor.TYPE_ACCELEROMETER); channelManager.addChannel(accelerometer); SensorChannel gyro = new SensorChannel("gyro", this, Sensor.TYPE_GYROSCOPE); channelManager.addChannel(gyro); SensorChannel light = new SensorChannel("light", this, Sensor.TYPE_LIGHT); channelManager.addChannel(light); SensorChannel pressure = new SensorChannel("pressure", this, Sensor.TYPE_PRESSURE); channelManager.addChannel(pressure); SensorChannel proximity = new SensorChannel("proximity", this, Sensor.TYPE_PROXIMITY); channelManager.addChannel(proximity); SensorChannel temperature = new SensorChannel("temperature", this, Sensor.TYPE_TEMPERATURE); channelManager.addChannel(temperature); try { Field f = Sensor.class.getField("TYPE_AMBIENT_TEMPERATURE"); SensorChannel sc = new SensorChannel("ambientTemperature", this, f.getInt(null)); channelManager.addChannel(sc); } catch (Exception e) { Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE"); } try { Field f = Sensor.class.getField("TYPE_RELATIVE_HUMIDITY"); SensorChannel sc = new SensorChannel("relativeHumidity", this, f.getInt(null)); channelManager.addChannel(sc); } catch (Exception e) { Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE"); } // all sensors by full name SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); if (sensorManager != null) { List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensors) { SensorChannel sc = new SensorChannel("sensor." + sensor.getName(), this, sensor); channelManager.addChannel(sc); } } BluetoothDiscoveryChannel btchannel = new BluetoothDiscoveryChannel(this, mHandler, "bluetooth"); channelManager.addChannel(btchannel); WifiScannerChannel wifichannel = new WifiScannerChannel(this, mHandler, "wifi"); channelManager.addChannel(wifichannel); GpsStatusChannel gpsstatus = new GpsStatusChannel("gpsstatus", this); channelManager.addChannel(gpsstatus); CellLocationChannel cellchannel = new CellLocationChannel(mHandler, this, "cell.location", false); channelManager.addChannel(cellchannel); CellLocationChannel cellchannel2 = new CellLocationChannel(mHandler, this, "cell.neighbors", true); channelManager.addChannel(cellchannel2); CellStrengthChannel cellchannel3 = new CellStrengthChannel(this, "cell.strength"); channelManager.addChannel(cellchannel3); } channelManager.addChannel(new TimeChannel(mHandler, "time")); List<String> locationProviders = LocationChannel.getAllProviders(this); for (String provider : locationProviders) { LocationChannel locchannel = new LocationChannel("location." + provider, this, provider); channelManager.addChannel(locchannel); } channelManager.addChannel(new MicChannel(mHandler, "mic")); Log.d(TAG, "Create http server..."); // http server httpPort = getPort(); httpListener = new HttpListener(this, httpPort); httpListener.start(); // peer communication peerManager = new PeerManager(this); int serverPort = peerManager.getServerPort(); channelManager.addChannel(new EnabledPeersChannel(this, peerManager, "peers")); // wifi discovery wifiDiscoveryManager = new WifiDiscoveryManager(this); wifiDiscoverable = getWifiDiscoverable(); wifiDiscoveryManager.setServerPort(serverPort); wifiDiscoveryManager.setEnabled(wifiDiscoverable); bluetooth = BluetoothAdapter.getDefaultAdapter(); if (bluetooth != null) btmac = bluetooth.getAddress(); telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (telephony != null) imei = telephony.getDeviceId(); logManager = new LogManager(this, channelManager); logManager.checkPreferences(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(onRunChangeListener); Log.d(TAG, "onCreate() finished"); }
From source file:alaindc.crowdroid.SensorsIntentService.java
public void stub_onSensorChanged(int typeSensor) { if (typeSensor < 0) return;// w w w.j a va 2s.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:org.dartlang.phonegap.barometer.BarometerListener.java
/** * Called when the accuracy of the sensor has changed. * * @param sensor/*w w w . j a v a 2s. co m*/ * @param accuracy */ public void onAccuracyChanged(Sensor sensor, int accuracy) { // Only look at barometer events if (sensor.getType() != Sensor.TYPE_PRESSURE) { return; } // If not running, then just return if (this.status == BarometerListener.STOPPED) { return; } this.accuracy = accuracy; }
From source file:org.dartlang.phonegap.barometer.BarometerListener.java
/** * Sensor listener event.//from w ww .jav a 2 s . com * * @param SensorEvent event */ public void onSensorChanged(SensorEvent event) { // Only look at barometer events if (event.sensor.getType() != Sensor.TYPE_PRESSURE) { return; } // If not running, then just return if (this.status == BarometerListener.STOPPED) { return; } this.setStatus(BarometerListener.RUNNING); if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) { // Save time that event was received this.timestamp = System.currentTimeMillis(); this.pressure = event.values[0]; this.win(); } }
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 v a 2 s. co m*/ } 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; } }
From source file:it.unime.mobility4ckan.MySensor.java
void registerPressureSensor() { pressureSensorListener = new SensorEventListener() { @Override// w ww. ja v a 2 s . co m public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_PRESSURE) { currentPressure = event.values[0]; } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } }; sensorManager.registerListener(pressureSensorListener, pressureSensor, SensorManager.SENSOR_DELAY_FASTEST); }
From source file:foam.starwisp.StarwispActivity.java
protected void DeclareSensors() { String str = ""; str += "(define sensor-accelerometer " + Sensor.TYPE_ACCELEROMETER + ")"; str += "(define sensor-ambient-temperature " + Sensor.TYPE_AMBIENT_TEMPERATURE + ")"; str += "(define sensor-game-rotation-vector " + Sensor.TYPE_GAME_ROTATION_VECTOR + ")"; str += "(define sensor-geomagnetic-rotation-vector " + Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR + ")"; str += "(define sensor-gravity " + Sensor.TYPE_GRAVITY + ")"; str += "(define sensor-gyroscope " + Sensor.TYPE_GYROSCOPE + ")"; str += "(define sensor-gyroscope-uncalibrated " + Sensor.TYPE_GYROSCOPE_UNCALIBRATED + ")"; str += "(define sensor-heart-rate " + Sensor.TYPE_HEART_RATE + ")"; str += "(define sensor-light " + Sensor.TYPE_LIGHT + ")"; str += "(define sensor-linear-acceleration " + Sensor.TYPE_LINEAR_ACCELERATION + ")"; str += "(define sensor-magnetic-field " + Sensor.TYPE_MAGNETIC_FIELD + ")"; str += "(define sensor-magnetic-field-uncalibrated " + Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED + ")"; str += "(define sensor-orientation " + Sensor.TYPE_ORIENTATION + ")"; str += "(define sensor-pressure " + Sensor.TYPE_PRESSURE + ")"; str += "(define sensor-proximity " + Sensor.TYPE_PROXIMITY + ")"; str += "(define sensor-relative-humidity " + Sensor.TYPE_RELATIVE_HUMIDITY + ")"; str += "(define sensor-rotation-vector " + Sensor.TYPE_ROTATION_VECTOR + ")"; str += "(define sensor-significant-motion " + Sensor.TYPE_SIGNIFICANT_MOTION + ")"; str += "(define sensor-step-counter " + Sensor.TYPE_STEP_COUNTER + ")"; str += "(define sensor-step-detector " + Sensor.TYPE_STEP_DETECTOR + ")"; m_Scheme.eval(str);//from w ww .j a v a2 s . c o m }