Using java Syntax Highlighting
- package com.GoogleProject.AccReader;
- import android.app.Activity;
- import android.hardware.SensorListener;
- import android.hardware.SensorManager;
- import android.os.Bundle;
- import android.widget.TextView;
- public class AccReader extends Activity implements SensorListener{
- private float x;
- private float y;
- private float z;
- //private TextView tv = new TextView(this);
- private SensorManager mSensMgr;
- //private SensorListener mSensLsnr;
- public TextView updateTV(TextView tv) {
- tv.setText("X: " + x + " ,Y :" + y+ " ,Z: " + z);
- return tv;
- }
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- TextView tv = new TextView(this);
- mSensMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
- mSensMgr.registerListener(this, SensorManager.SENSOR_ACCELEROMETER, SensorManager.SENSOR_DELAY_FASTEST);
- setContentView(updateTV(tv));
- }
- public void onAccuracyChanged(int sensor, int accuracy) {
- // TODO Auto-generated method stub
- }
- public void onSensorChanged(int sensor, float[] values) {
- // TODO Auto-generated method stub
- if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
- x = values[0];
- y = values[1];
- z = values[2];
- }else {
- x = -1;
- y = -1;
- z = -1;
- }
- //this.setContentView(updateTV(tv));
- }
- }
Parsed in 0.015 seconds, using GeSHi 1.0.8.4
Nothing happens when I run the app on G1.
All I get is
[font=Courier New]
X: 0.0 ,Y = 0.0 ,Z = 0.0
[/font]
And it remains that way no matter how hard I shake the phone.