Advertisement
Guest User

Untitled

a guest
May 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. package com.example.myapplication5;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.hardware.Sensor;
  6. import android.hardware.SensorEvent;
  7. import android.hardware.SensorEventListener;
  8. import android.hardware.SensorManager;
  9. import android.os.Bundle;
  10. import android.util.Log;
  11. import android.widget.TextView;
  12.  
  13. import static android.content.Context.SENSOR_SERVICE;
  14.  
  15. public class AccessGyroscope implements SensorEventListener
  16. {
  17. //a TextView
  18. // private TextView tv;
  19. //the Sensor Manager
  20. private SensorManager sManager;
  21. private String st;
  22. /** Called when the activity is first created. */
  23. private Sensor mLight;
  24. public AccessGyroscope(Context context){
  25. sManager = (SensorManager) context.getSystemService(SENSOR_SERVICE);
  26. }
  27. public void register(){
  28. st="xx";
  29.  
  30. sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),SensorManager.SENSOR_DELAY_NORMAL);
  31. }
  32. @Override
  33. public void onAccuracyChanged(Sensor arg0, int arg1)
  34. {
  35. //Do nothing.
  36. }
  37.  
  38. @Override
  39. public void onSensorChanged(SensorEvent event)
  40. {
  41. //if sensor is unreliable, return void
  42.  
  43.  
  44. //else it will output the Roll, Pitch and Yawn values
  45.  
  46. String str = "Orientation X (Roll) :"+ Float.toString(event.values[2]) +"\n"+"\r"+
  47. "Orientation Y (Pitch) :"+ Float.toString(event.values[1]) +"\n"+"\r"+
  48. "Orientation Z (Yaw) :"+ Float.toString(event.values[0])+"\n"+"\r";
  49. this.st = str;
  50. }
  51. public String getSt(){
  52.  
  53. return st;
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement