fork download
  1. package net.npaka.socketex;
  2.  
  3. import java.util.List;
  4.  
  5. import android.app.Activity;
  6. import android.content.Context;
  7. import android.hardware.Sensor;
  8. import android.hardware.SensorEvent;
  9. import android.hardware.SensorEventListener;
  10. import android.hardware.SensorManager;
  11. import android.os.Bundle;
  12. import android.os.Handler;
  13. import android.os.Message;
  14. import android.view.WindowManager;
  15. import android.widget.LinearLayout;
  16. import android.widget.TextView;
  17.  
  18.  
  19. public class TestAccelerometer extends Activity
  20. implements SensorEventListener {
  21. private TextView txtView;
  22. // センサーマネージャ
  23. private SensorManager mSensorManager;
  24. private Sensor mAccelerometer;
  25. private float[] nValues = new float[3];
  26. private float[] oValues = new float[3];
  27. private TickHandler tickHandler;
  28.  
  29. /** Called when the activity is first created. */
  30. @Override
  31. public void onCreate(Bundle savedInstanceState) {
  32. super.onCreate(savedInstanceState);
  33. LinearLayout layout=new LinearLayout(this);
  34. layout.setOrientation(LinearLayout.VERTICAL);
  35. setContentView(layout);
  36. /*
  37.   scView=new ScrollView(this);
  38.   scView.setLayoutParams(new LinearLayout.LayoutParams(
  39.   LinearLayout.LayoutParams.MATCH_PARENT,
  40.   LinearLayout.LayoutParams.WRAP_CONTENT));
  41.   layout.addView(scView);
  42. */
  43. txtView=new TextView(this);
  44. txtView.setText("");
  45. txtView.setLayoutParams(new LinearLayout.LayoutParams(
  46. LinearLayout.LayoutParams.MATCH_PARENT,
  47. LinearLayout.LayoutParams.WRAP_CONTENT));
  48. //scView.addView(txtView);
  49. layout.addView(txtView);
  50. // センサーマネージャのインスタンスを取得
  51. mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
  52. // センサーの取得
  53. List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
  54. if (list.size()>0) {
  55. mAccelerometer = list.get(0);
  56. }
  57. // 画面のロックを防ぐ
  58. getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  59. }
  60. @Override
  61. public void onResume() {
  62. super.onResume();
  63. if (mAccelerometer!=null) {
  64. // SensorEventListenerを登録します
  65. mSensorManager.registerListener(this, mAccelerometer,SensorManager.SENSOR_DELAY_UI);
  66. }
  67. //定期処理ハンドラの生成と実行
  68. tickHandler=new TickHandler();
  69. tickHandler.sleep(0);
  70. }
  71. public void onStop() {
  72. super.onStop();
  73. mSensorManager.unregisterListener(this);
  74. //定期処理ハンドラの停止
  75. tickHandler=null;
  76. }
  77.  
  78. public void onAccuracyChanged(Sensor sensor, int accuracy) {
  79. // TODO 自動生成されたメソッド・スタブ
  80.  
  81. }
  82.  
  83. public void onSensorChanged(SensorEvent event) {
  84. // TODO 自動生成されたメソッド・スタブ
  85.  
  86. if (event.sensor.getType()!= Sensor.TYPE_ACCELEROMETER) {
  87. return;
  88. }
  89. oValues[0] = nValues[0];
  90. oValues[1] = nValues[1];
  91. oValues[2] = nValues[2];
  92. nValues[0] = event.values[SensorManager.DATA_X];
  93. nValues[1] = event.values[SensorManager.DATA_Y];
  94. nValues[2] = event.values[SensorManager.DATA_Z];
  95. }
  96. public class TickHandler extends Handler {
  97. public String str;
  98. @Override
  99.  
  100. public void handleMessage(Message msg) {
  101.  
  102.  
  103. String str1 ="新 value[0]: meams X軸" + nValues[0] + "\n";
  104. String str2 ="新 value[1]: meams Y軸" + nValues[1] + "\n";
  105. String str3 ="新 value[2]: meams Z軸" + nValues[2] + "\n";
  106. String str4 ="=================================\n";
  107. String str5 ="旧 value[0]: meams X軸" + oValues[0] + "\n";
  108. String str6 ="旧 value[1]: meams Y軸" + oValues[1] + "\n";
  109. String str7 ="旧 value[2]: meams Z軸" + oValues[2] + "\n";
  110.  
  111. str =str1+str2+str3+str4+str5+str6+str7;
  112. public String getStr() {
  113.  
  114. return str;
  115. }
  116. if (tickHandler!=null) tickHandler.sleep(2000);
  117.  
  118.  
  119. }
  120. public void sleep(long delayMills) {
  121. removeMessages(0); //使用済みのメッセージの削除
  122. /*
  123. * obtainMessageはグローバル・メッセージ・プールにある
  124. * インスタンスを使用することを指示する
  125. */
  126. sendMessageDelayed(obtainMessage(0),delayMills);
  127. }
  128.  
  129. }
  130.  
  131. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:112: illegal start of expression
			public String getStr() {
			^
Main.java:112: ';' expected
			public String getStr() {
			                    ^
2 errors
stdout
Standard output is empty