使 用
Eclipse
环 境 和
Android
Developer Tools 插
件创建的应用程序。
( 关 于 使 用 Eclipse
开 发
Android 应 用
程 序 的 信 息 , 请 参
见
参 考 资 料 。 ) 清
单
1 展 示 了 该 应
用程序的代码。
清
单
1.
IBMEyes.java
1
package
com.msi.ibm.eyes; import android.app.Activity;
2
import android.os.Bundle; import android.util.Log;
3
import android.widget.TextView; import android.hardware.SensorManager;
4
import android.hardware.SensorListener; public class IBMEyes extends Activity
implements SensorListener {
5
final String tag = "IBMEyes"; SensorManager sm = null;
6
TextView xViewA = null; TextView yViewA = null;
7
TextView zViewA = null; TextView xViewO = null;
8
TextView yViewO = null; TextView zViewO = null;
9
/** Called when the activity is first created. */
10
@Override public void onCreate(Bundle savedInstanceState) {
11
super.onCreate(savedInstanceState); // get reference to SensorManager
12
sm
=
(SensorManager)
getSystemService(SENSOR_SERVICE);
setContentView(R.layout.main);
13
xViewA
=
(TextView)
findViewById(R.id.xbox);
yViewA
=
(TextView)
findViewById(R.id.ybox);
14
zViewA
=
(TextView)
findViewById(R.id.zbox);
xViewO
=
(TextView)
findViewById(R.id.xboxo);
15
yViewO
=
(TextView)
findViewById(R.id.yboxo);
zViewO
=
(TextView)
findViewById(R.id.zboxo);
16
} public void onSensorChanged(int sensor, float[] values) {