package edu.uci;
import org.openintents.hardware.SensorManagerSimulator;
import org.openintents.provider.Hardware;
import android.app.Activity;
import android.content.Intent;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class testForPodcast extends Activity implements SensorListener{
SensorManager mSensorManager;
TextView tv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Hardware.mContentResolver= getContentResolver();
mSensorManager = (SensorManager) new SensorManagerSimulator( (SensorManager) getSystemService(SENSOR_SERVICE));
Intent intent = new Intent(Intent.ACTION_VIEW, Hardware.Preferences.CONTENT_URI);
startActivity(intent);
SensorManagerSimulator.connectSimulator();
registerListener();
tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
@Override
protected void onResume() {
super.onResume();
registerListener();
}
@Override
protected void onStop() {
super.onStop();
}
private void registerListener() {
mSensorManager.registerListener(this,
SensorManager.SENSOR_ACCELEROMETER |
SensorManager.SENSOR_MAGNETIC_FIELD |
SensorManager.SENSOR_ORIENTATION,
SensorManager.SENSOR_DELAY_FASTEST);
}
float x=0.0f,y=0.0f,z=0.0f;
float oCompass=0.0f,oPitch=0.0f,oRoll=0.0f;
public void onSensorChanged(int arg0, float[] arg1) {
if(arg0 == android.hardware.SensorManager.SENSOR_ACCELEROMETER){
x = arg1[0];
y = arg1[1];
z = arg1[2];
}
else if(arg0 == android.hardware.SensorManager.SENSOR_ORIENTATION){
oCompass = arg1[0];
oPitch = arg1[1];
oRoll = arg1[2];
}
tv.setText("Accelerometer:\n\t("+x+","+y+","+z+")\nOrientation:\n\t("+oCompass+","+oPitch+","+oRoll+")");
}
public void onAccuracyChanged(int arg0, int arg1) {
// TODO Auto-generated method stub
}
}