Código PHP:
package com.daPhyre.RotateAngle;
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class RotateBitmap extends Activity implements SensorEventListener {
private SensorManager sSensorManager;
private Sensor sSensor;
public float angle = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sSensor = sSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
setContentView(R.layout.main);
}
@Override
protected void onResume() {
super.onResume();
sSensorManager.registerListener(this, sSensor, Sensor.TYPE_ACCELEROMETER);
}
@Override
protected void onPause() {
super.onPause();
sSensorManager.unregisterListener(this, sSensor);
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
if (event.sensor != sSensor)
return;
float aX = event.values[0];
float aY = event.values[1];
//float aZ = event.values[2];
angle = Math.atan2(aX, aY)/(Math.PI/180);
}
}