List of usage examples for android.hardware Sensor TYPE_ACCELEROMETER
int TYPE_ACCELEROMETER
To view the source code for android.hardware Sensor TYPE_ACCELEROMETER.
Click Source Link
From source file:org.wso2.carbon.iot.android.sense.event.streams.speed.SpeedDataReader.java
@Override public void onSensorChanged(SensorEvent event) { Sensor devSensor = event.sensor;// w ww.j av a 2s .c om if (devSensor.getType() == Sensor.TYPE_ACCELEROMETER) { x = event.values[0]; y = event.values[1]; z = event.values[2]; } }
From source file:ch.jeda.platform.android.SensorManager.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.sensorMap.clear(); this.sensorInfoMap.clear(); this.sensorListenerMap.clear(); this.imp = (android.hardware.SensorManager) activity.getSystemService(Activity.SENSOR_SERVICE); this.checkAdd(SensorType.ACCELERATION, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); this.checkAdd(SensorType.GRAVITY, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_GRAVITY)); this.checkAdd(SensorType.LIGHT, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_LIGHT)); this.checkAdd(SensorType.LINEAR_ACCELERATION, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION)); // Android returns values in micro Tesla this.checkAdd(SensorType.MAGNETIC_FIELD, 1e-6f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)); // Android returns value in hekto Pascal this.checkAdd(SensorType.PRESSURE, 100f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_PRESSURE)); // Android returns value in centimeter this.checkAdd(SensorType.PROXIMITY, 0.01f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_PROXIMITY)); // Android returns value in degrees Celcius this.checkAdd(SensorType.TEMPERATURE, 1f, -273.15f, this.imp.getDefaultSensor(Sensor.TYPE_TEMPERATURE)); }
From source file:me.ziccard.secureit.fragment.AccelerometerFragment.java
public void onSensorChanged(SensorEvent event) { long curTime = System.currentTimeMillis(); // only allow one update every 100ms. if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { if ((curTime - lastUpdate) > 100) { long diffTime = (curTime - lastUpdate); lastUpdate = curTime;// ww w .j a v a 2s. co m accel_values = event.values.clone(); if (alert && remainingAlertPeriod > 0) { remainingAlertPeriod = remainingAlertPeriod - 1; } else { accelerometerText.setVisibility(View.INVISIBLE); alert = false; } view.renderer.setPosition(-accel_values[0], accel_values[1], accel_values[2]); if (last_accel_values != null) { float speed = Math.abs(accel_values[0] + accel_values[1] + accel_values[2] - last_accel_values[0] + last_accel_values[1] + last_accel_values[2]) / diffTime * 10000; if (speed > SHAKE_THRESHOLD) { /* * Send Alert */ alert = true; remainingAlertPeriod = maxAlertPeriod; accelerometerText.setVisibility(View.VISIBLE); Message message = new Message(); message.what = UploadService.ACCELEROMETER_MESSAGE; try { if (serviceMessenger != null) { serviceMessenger.send(message); } } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } last_accel_values = accel_values.clone(); } } }
From source file:rus.cpuinfo.AndroidDepedentModel.SensorsInfo.java
@Override @SuppressLint("NewApi") @NonNull//from w ww. j a v a2s. 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:com.developer.shade.sensors.SensorService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.v("Running onStart", "Starting SensorService Service ID: " + startId); senManager.registerListener(this, senManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); return START_STICKY; }
From source file:org.sociotech.fishification.ui.fragments.FeedFishFragment.java
@Override public void onSensorChanged(SensorEvent sensorEvent) { if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { float y = sensorEvent.values[1]; // Check for upside down movement if (y > SENSOR_TRESHOLD) { m_turnedUpsideDown = false;// w ww . j a v a 2 s . co m } if (y < -SENSOR_TRESHOLD) { m_turnedUpsideDown = true; } // Ensure that a reasonable period of time elapses before the device can turned upside down again long actualTime = System.currentTimeMillis(); int upsideDownFrequency = UPDATE_FREQUENCY; if (actualTime - m_lastUpdate < upsideDownFrequency) { return; } m_lastUpdate = actualTime; // Check if device has been turned upside down if (m_turnedUpsideDown) { // Change background color to green m_view.setBackgroundColor(Color.GREEN); // Trigger fish feed m_feedFishListener.onFeedFish(); } else { // reset background to initial state m_view.setBackgroundDrawable(m_defaultBackground); } } }
From source file:it.flaviomascetti.posture.AccuracyTestFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sp = getActivity().getSharedPreferences("saved_preferences", Context.MODE_PRIVATE); sensorManager = (SensorManager) getActivity().getApplicationContext() .getSystemService(Context.SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); }
From source file:com.sorin.cloudcog.phone.batterymeter.BatteryInfoActivity.java
@Override public void onCreate(Bundle savedInstanceState) { startMillis = System.currentTimeMillis(); context = getApplicationContext();// ww w . ja v a 2 s .co m res = getResources(); str = new Str(res); loadSettingsFiles(); super.onCreate(savedInstanceState); // Recreates Fragments, so only call // after doing necessary setup setContentView(R.layout.battery_info); pagerAdapter = new BatteryInfoPagerAdapter(getSupportFragmentManager()); viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); viewPager.setCurrentItem(1); PagerTabStrip tabStrip = (PagerTabStrip) findViewById(R.id.pager_tab_strip); tabStrip.setTabIndicatorColor(0x33b5e5); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetectorActivity(); mShakeDetector.setOnShakeListener(new OnShakeListener() { @Override public void onShake(int count) { BatteryInfoActivity.this.finish(); } }); // ShakeDetector method end }
From source file:com.commonsware.android.sensor.monitor.MainActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT) private boolean isXYZ(Sensor s) { switch (s.getType()) { case Sensor.TYPE_ACCELEROMETER: case Sensor.TYPE_GRAVITY: case Sensor.TYPE_GYROSCOPE: case Sensor.TYPE_LINEAR_ACCELERATION: case Sensor.TYPE_MAGNETIC_FIELD: case Sensor.TYPE_ROTATION_VECTOR: return (true); }/*from ww w . j a va2 s . c om*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (s.getType() == Sensor.TYPE_GAME_ROTATION_VECTOR || s.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED || s.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) { return (true); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (s.getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR) { return (true); } } return (false); }