Guest User

Untitled

a guest
Dec 11th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package no.westman.hallvard;
  6.  
  7. //import android.hardware.SensorListener;
  8. import android.hardware.Sensor;
  9. import android.hardware.SensorEvent;
  10. import android.hardware.SensorEventListener;
  11. import android.hardware.SensorManager;
  12.  
  13. /**
  14.  *
  15.  * @author hallvardwestman
  16.  */
  17. public class AccelerationHandler implements SensorEventListener {
  18.    
  19.     private SensorManager sensorMan;
  20.     static public String initiatedEvent;
  21.    
  22.     public AccelerationHandler(SensorManager sm){
  23.         sensorMan = sm;
  24.         //startListening();
  25.        
  26.     }
  27.    
  28.     /*
  29.      * Initializes the sensor listening.
  30.      */
  31.     public void startListening() {
  32.         sensorMan.registerListener(this,
  33.                 sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
  34.                 SensorManager.SENSOR_DELAY_FASTEST);//FAST AS POSSIBLE. IF YOU GO ANY FASTER, U R SUPRMAN! Droid on steroids
  35.     }
  36.     public void stopListening() {
  37.          sensorMan.unregisterListener(this);
  38.      }
  39.    
  40.     /*
  41.      * sets current accelerometer-data
  42.      */
  43.     public void onSensorChanged(SensorEvent event) {
  44.        
  45.         int sensorType = event.sensor.getType();
  46.        
  47.         if (sensorType == Sensor.TYPE_ACCELEROMETER) {
  48.             initiatedEvent = "x: "+event.values[0]+" Y: "+event.values[1]+"";            
  49.         }
  50.        
  51.        
  52.     }
  53.    
  54.     /*
  55.      * Never in use
  56.      */
  57.     public void onAccuracyChanged(Sensor arg0, int arg1) {
  58.        // throw new UnsupportedOperationException("Not supported yet.");
  59.     }
  60.    
  61.     /*
  62.      * returns accelerometer-data when polled
  63.      */
  64.     public String returnAcceleration(){
  65.        
  66.         //JØRN! eg startListening/stopListening utafør klassen ATM
  67.         return initiatedEvent;
  68.        
  69.     }
  70. }
Add Comment
Please, Sign In to add comment