Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package no.westman.hallvard;
- //import android.hardware.SensorListener;
- import android.hardware.Sensor;
- import android.hardware.SensorEvent;
- import android.hardware.SensorEventListener;
- import android.hardware.SensorManager;
- /**
- *
- * @author hallvardwestman
- */
- public class AccelerationHandler implements SensorEventListener {
- private SensorManager sensorMan;
- static public String initiatedEvent;
- public AccelerationHandler(SensorManager sm){
- sensorMan = sm;
- //startListening();
- }
- /*
- * Initializes the sensor listening.
- */
- public void startListening() {
- sensorMan.registerListener(this,
- sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
- SensorManager.SENSOR_DELAY_FASTEST);//FAST AS POSSIBLE. IF YOU GO ANY FASTER, U R SUPRMAN! Droid on steroids
- }
- public void stopListening() {
- sensorMan.unregisterListener(this);
- }
- /*
- * sets current accelerometer-data
- */
- public void onSensorChanged(SensorEvent event) {
- int sensorType = event.sensor.getType();
- if (sensorType == Sensor.TYPE_ACCELEROMETER) {
- initiatedEvent = "x: "+event.values[0]+" Y: "+event.values[1]+"";
- }
- }
- /*
- * Never in use
- */
- public void onAccuracyChanged(Sensor arg0, int arg1) {
- // throw new UnsupportedOperationException("Not supported yet.");
- }
- /*
- * returns accelerometer-data when polled
- */
- public String returnAcceleration(){
- //JØRN! eg startListening/stopListening utafør klassen ATM
- return initiatedEvent;
- }
- }
Add Comment
Please, Sign In to add comment