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.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_colorimetry_liquid); setTitle("Analysis"); Intent intent = getIntent();/* w w w.j a v a 2s .c om*/ mIsCalibration = intent.getBooleanExtra("isCalibration", false); mSwatchValue = intent.getDoubleExtra("swatchValue", 0); sound = new SoundPoolPlayer(this); textDilution = (TextView) findViewById(R.id.textDilution); TextView textSubtitle = (TextView) findViewById(R.id.textSubtitle); //Set up the shake detector mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetector(new ShakeDetector.OnShakeListener() { @Override public void onShake() { if ((mIgnoreShake) || mWaitingForStillness || mCameraFragment == null) { return; } if (isDestroyed()) { return; } mWaitingForStillness = true; showError(String.format(TWO_SENTENCE_FORMAT, getString(R.string.errorTestInterrupted), getString(R.string.doNotMoveDeviceDuringTest)), null); } }, new ShakeDetector.OnNoShakeListener() { @Override public void onNoShake() { if (mWaitingForStillness) { mWaitingForStillness = false; dismissShakeAndStartTest(); } } }); mSensorManager.unregisterListener(mShakeDetector); mShakeDetector.setMinShakeAcceleration(5); mShakeDetector.setMaxShakeDuration(MAX_SHAKE_DURATION); textSubtitle.setText(R.string.placeDevice); }
From source file:org.apache.cordova.AccelListener.java
/** * Sensor listener event.//w w w . j a v a 2 s . c o m * * @param SensorEvent event */ public void onSensorChanged(SensorEvent event) { // Only look at accelerometer events if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) { return; } // If not running, then just return if (this.status == AccelListener.STOPPED) { return; } this.setStatus(AccelListener.RUNNING); if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) { // Save time that event was received this.timestamp = System.currentTimeMillis(); this.x = event.values[0]; this.y = event.values[1]; this.z = event.values[2]; this.win(); } }
From source file:edu.Groove9.TunesMaster.songplayer.SongPlayerFragment.java
private void setupShakeDetector() { // ShakeDetector initialization mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetector(); mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeListener() { @Override//from ww w . j a v a2 s.c o m public void onShake(int count) { mPresenter.shuffleSong(); Logger.get().log(new UserEvent(UserEvent.Source.Gesture, UserEvent.Action.Shuffle)); } }); }
From source file:com.example.jony.myapp.reader_APP.ui.DailyDetailsActivity.java
@Override protected void onResume() { super.onResume(); mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); isShakeMode = Settings.getInstance().getBoolean(Settings.SHAKE_TO_RETURN, true); }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopDetailsFragment.java
/** * {@inheritDoc}/*from w w w . ja v a 2 s . c o m*/ */ @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = getActivity().getApplicationContext(); // Get the various resources and services. bsd = BusStopDatabase.getInstance(context); sd = SettingsDatabase.getInstance(context); locMan = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); sensMan = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); accelerometer = sensMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); magnetometer = sensMan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); stopCode = getArguments().getString(ARG_STOPCODE); hitboxSize = getResources().getDimensionPixelOffset(R.dimen.star_hitbox_size); }
From source file:com.example.android.camera2video.CameraActivity.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { logText("ACCELEROMETER," + event.values[0] + "," + event.values[1] + "," + event.values[2]); mAccVal = event.values;/*from ww w . j av a 2s.c o m*/ } else if (event.sensor.getType() == Sensor.TYPE_GRAVITY) { logText("GRAVITY," + event.values[0] + "," + event.values[1] + "," + event.values[2]); } else if (event.sensor.getType() == Sensor.TYPE_LINEAR_ACCELERATION) { logText("LINEAR_ACCELERATION," + event.values[0] + "," + event.values[1] + "," + event.values[2]); } else if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) { logText("GYROSCOPE," + event.values[0] + "," + event.values[1] + "," + event.values[2]); } else if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) { logText("GYROSCOPE_UNCALIBRATED," + event.values[0] + "," + event.values[1] + "," + event.values[2] + "," + event.values[3] + "," + event.values[4] + "," + event.values[5]); } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { logText("MAGNETIC_FIELD," + event.values[0] + "," + event.values[1] + "," + event.values[2]); mMagVal = event.values; if (mAccVal != null) { float R[] = new float[9]; float I[] = new float[9]; boolean success = SensorManager.getRotationMatrix(R, I, mAccVal, mMagVal); if (success) { float orientation[] = new float[3]; SensorManager.getOrientation(R, orientation); logText("ORIENTATION," + orientation[0] + "," + orientation[1] + "," + orientation[2]); //azimuth, pitch and roll } } } }
From source file:com.bsafe.sensors.motion.BSMotionSensorsPlugin.java
/** * Called when the accuracy of the sensor has changed. * * @param sensor/*from w w w. j av a 2s . c o m*/ * @param accuracy */ public void onAccuracyChanged(Sensor sensor, int accuracy) { // Only look at accelerometer events if (sensor.getType() != Sensor.TYPE_ACCELEROMETER) { return; } // If not running, then just return if (this.status == BSMotionSensorsPlugin.STOPPED) { return; } this.accuracy = accuracy; }
From source file:ch.bfh.sensordataprocessor.sensor.SensorDisplayFragment.java
/** * @see android.hardware.SensorEventListener#onSensorChanged(android.hardware.SensorEvent) *///from ww w. j a va 2 s .c o m @Override public void onSensorChanged(SensorEvent event) { onAccuracyChanged(event.sensor, event.accuracy); timestampLabel.setVisibility(View.VISIBLE); timestamp.setVisibility(View.VISIBLE); timestamp.setText(String.valueOf(event.timestamp)); timestampUnits.setVisibility(View.VISIBLE); switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: showEventData("Acceleration - gravity on axis", ACCELERATION_UNITS, event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_MAGNETIC_FIELD: showEventData("Abient Magnetic Field", "uT", event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_GYROSCOPE: showEventData("Angular speed around axis", "radians/sec", event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_LIGHT: showEventData("Ambient light", "lux", event.values[0]); break; case Sensor.TYPE_PRESSURE: showEventData("Atmospheric pressure", "hPa", event.values[0]); break; case Sensor.TYPE_PROXIMITY: showEventData("Distance", "cm", event.values[0]); break; case Sensor.TYPE_GRAVITY: showEventData("Gravity", ACCELERATION_UNITS, event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_LINEAR_ACCELERATION: showEventData("Acceleration (not including gravity)", ACCELERATION_UNITS, event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_ROTATION_VECTOR: showEventData("Rotation Vector", null, event.values[0], event.values[1], event.values[2]); xAxisLabel.setText("x*sin(" + THETA + "/2)"); yAxisLabel.setText("y*sin(" + THETA + "/2)"); zAxisLabel.setText("z*sin(" + THETA + "/2)"); if (event.values.length == 4) { cosLabel.setVisibility(View.VISIBLE); cos.setVisibility(View.VISIBLE); cos.setText(String.valueOf(event.values[3])); } break; case Sensor.TYPE_ORIENTATION: showEventData("Angle", "Degrees", event.values[0], event.values[1], event.values[2]); xAxisLabel.setText(R.string.azimuthLabel); yAxisLabel.setText(R.string.pitchLabel); zAxisLabel.setText(R.string.rollLabel); break; case Sensor.TYPE_RELATIVE_HUMIDITY: showEventData("Relatice ambient air humidity", "%", event.values[0]); break; case Sensor.TYPE_AMBIENT_TEMPERATURE: showEventData("Ambien temperature", "degree Celcius", event.values[0]); break; } }
From source file:com.developer.shade.sensors.SensorService.java
@Override public void onSensorChanged(SensorEvent event) { Log.d("Running onSensorChanged", "Implementing Devices Sensors"); if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { x = event.values[0]; // Note: Obtained X Coordinate y = event.values[1]; // Note: Obtained Y Coordinate z = event.values[2]; // Note: Obtained Z Coordinate double value = EuclideanNorm(x, y, z); Log.d("Sensor", "Value: " + value); if ((value > 25) || (value < 1)) { onActivateTimerActivity();//ww w. j a va 2 s. co m onSystemVibrate(15000); onDestroy(); } } }
From source file:devbox.com.br.minercompanion.ProfileActivity.java
@Override public void onSensorChanged(SensorEvent event) { synchronized (this) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: float[] sensor1 = event.values; sensors.acelerometer = sensor1; //acelerText.setText("x: " + sensor1[0] + " y: " + sensor1[1] + " z: " + sensor1[2]); break; case Sensor.TYPE_ORIENTATION: float[] sensor2 = event.values; sensors.orientation = sensor2; //gyroText.setText("x: " + sensor2[0] + " y: " + sensor2[1] + " z: " + sensor2[2]); break; case Sensor.TYPE_GYROSCOPE: float[] sensor3 = event.values; sensors.gyroscope = sensor3; //orienText.setText("x: " + sensor3[0] + " y: " + sensor3[1] + " z: " + sensor3[2]); break; case Sensor.TYPE_LIGHT: sensors.luminosity = event.values[0]; //ligthText.setText("Luminosidade: " + event.values[0]); break; }// w w w .j a va2s. com } }