package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class SensorTest extends Activity implements SensorEventListener{
private SensorManager sensorManager = null;
private Sensor gyroSensor = null;
private TextView vX;
private TextView vY;
private TextView vZ;
private TextView v;
private Button button;
private static final float NS2S = 1.0f / 1000000000.0f;
private float timestamp;
private float[] angle = new float[3];
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
setContentView(.activity_sensor_test);
vX = (TextView) findViewById();
vY = (TextView)findViewById();
vZ = (TextView)findViewById();
v = (TextView)findViewById();
button = (Button)findViewById();
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
gyroSensor = sensorManager
.getDefaultSensor(Sensor.TYPE_ORIENTATION);
("!!!!!!");
(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//Declare variable string
StringBuffer sb = new StringBuffer();
//Get all sensors on your phone
List<Sensor> sensors = (Sensor.TYPE_ALL);
//Iterative output to obtain the sensor on
for (Sensor sensor : sensors) {
//(().toString());
(().toString());
("\n");
("Sensor", ().toString());
}
// Assign values to text control
(());
}
});
}
public SensorTest() {
// TODO Auto-generated constructor stub
angle[0] = 0;
angle[1] = 0;
angle[2] = 0;
timestamp = 0;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(.activity_sensor_test, menu);
return true;
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
();
(this); // Unregister the listener
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
();
(this, gyroSensor,
SensorManager.SENSOR_DELAY_NORMAL); //Register listener for sensor
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
// if ( == SensorManager.SENSOR_STATUS_UNRELIABLE)
// {
// return;
// }
// if (timestamp != 0) {
// final float dT = ( - timestamp) * NS2S;
// angle[0] += [0] * dT * 100;
// angle[1] += [1] * dT * 100;
// angle[2] += [2] * dT * 100;
// }
// timestamp = ;
//
//
// ("X: " + (angle[0]));
// ("Y: " + (angle[1]));
// ("Z: " + (angle[2]));
// The direction sensor provides three data, namely azimuth, pitch and roll.
//
// azimuth: Azimuth, the angle between the magnetic north pole and the Y axis when returning to horizontal, ranging from 0° to 360°.
// 0°=North, 90°=East, 180°=South, 270°=West.
//
// pitch: The angle between the x-axis and the horizontal plane, ranging from -180° to 180°.
// When the z-axis rotates to the y-axis, the angle is positive.
//
// roll: The angle between the y-axis and the horizontal plane, which ranges from -90° to 90° due to historical reasons.
// When the x-axis moves to the z-axis, the angle is positive.
("Orientation X: " + [0]);
("Orientation Y: " + [1]);
("Orientation Z: " + [2]);
}
}