--- /dev/null
+package mobile.miki;
+
+import android.content.Intent;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.View;
+import android.widget.TextView;
+
+import com.ic.jni.ICJniUtils;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import mobile.miki.mainui.ButtonViewTwo;
+import mobile.miki.mainui.TestMainActivity;
+import mobile.miki.util.Config;
+import mobile.miki.util.FTUtils;
+
+public class GyroScope extends BaseActivity implements View.OnClickListener, SensorEventListener {
+
+ private ButtonViewTwo buttonView;
+ boolean running;
+ public static final int TYPE_HEART_RATE = 21;
+ Timer mTimer=null;
+
+ private TextView tv_x;
+ private TextView tv_y;
+ private TextView tv_z;
+
+ private SensorManager mSensorManager=null;
+ private Sensor mGyroScope=null;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.gyroscope_layout);
+ initView();
+
+ Intent intent = getIntent();
+ running = false;
+ if (intent != null) {
+ running = intent.getBooleanExtra("running", false);
+ }
+
+
+ mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
+ mGyroScope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
+ boolean ret = mSensorManager.registerListener(this, mGyroScope, SensorManager.SENSOR_DELAY_NORMAL);
+ Log.i("dxc", " GyroScope opened ret :: " + ret);
+
+
+ }
+
+ Handler mhandler=new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(Message message) {
+
+ switch(message.what)
+ {
+
+ case 1: {
+ Bundle bdl = message.getData();
+ String x = bdl.getString("X");
+ String y = bdl.getString("Y");
+ String z = bdl.getString("Z");
+ if (!x.trim().isEmpty() && !y.trim().isEmpty()&& !z.trim().isEmpty()) {
+ tv_x.setText(" " + x);
+ tv_y.setText(" " + y);
+ tv_z.setText(" " + z);
+ } else {
+ tv_x.setText(" " + GyroScope.this.getResources().getString(R.string.no_gyroscope));
+ tv_y.setText("");
+ tv_z.setText("");
+ }
+ }
+ break;
+
+ }
+
+ return false;
+ }
+ });
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ mSensorManager.unregisterListener(this);
+ Log.i("dxc", "GyroScope closed");
+
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ Log.i( "dxc","GyroScope onPause");
+
+ }
+
+ private void initView() {
+ buttonView = (ButtonViewTwo) findViewById(R.id.btn_set);
+ buttonView.btn_left.setOnClickListener(this);
+ buttonView.btn_right.setOnClickListener(this);
+ buttonView.setSuccessColor();
+ buttonView.btn_left.setClickable(true);
+
+ tv_x=(TextView)findViewById(R.id.tv_gyro_xvalue);
+ tv_y=(TextView)findViewById(R.id.tv_gyro_yvalue);
+ tv_z=(TextView)findViewById(R.id.tv_gyro_zvalue);
+
+ }
+
+ @Override
+ public void onClick(View view) {
+ Intent intent = Config.getNextTestIntent(this,this.getClass());//new Intent(this, SimDetectActivity.class);
+ intent.putExtra("running", true);
+ Intent intent1 = new Intent(this, TestMainActivity.class);
+ // TestResult testResult = (TestResult) getApplicationContext();
+ switch (view.getId()) {
+
+ case R.id.btn_two_left:
+ if (!running) {
+ startActivity(intent1);
+ } else {
+ startActivity(intent);
+ }
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("gyroscope", "true").commit();
+ finish();
+ break;
+ case R.id.btn_two_right:
+ if (!running) {
+ startActivity(intent1);
+ } else {
+ startActivity(intent);
+ }
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("gyroscope", "false").commit();
+ finish();
+ break;
+ }
+ }
+
+ @Override
+ public void onSensorChanged(SensorEvent sensorEvent) {
+ float values[]=sensorEvent.values;
+ int length = values.length;
+ Log.i( "dxc","onSensorChanged() is called "+length
+ +" X = "+values[0]
+ +", Y = "+values[1]
+ +", Z = "+values[2]
+ );
+
+ Message msg=new Message();
+ Bundle bdl=new Bundle();
+ msg.what=1;
+ bdl.putString("X", String.format("%.5f",values[0]));
+ bdl.putString("Y",String.format("%.5f",values[1]));
+ bdl.putString("Z",String.format("%.5f",values[2]));
+ msg.setData(bdl);
+ mhandler.sendMessage(msg);
+
+ }
+
+ @Override
+ public void onAccuracyChanged(Sensor sensor, int i) {
+ Log.i("dxc","onAccuracyChanged() is called "+sensor.getName()+" accuracy="+i);
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:orientation="vertical" android:layout_width="match_parent"\r
+ android:layout_height="match_parent">\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:orientation="vertical">\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
+ android:orientation="horizontal">\r
+\r
+ <TextView\r
+ android:id="@+id/tv_gyro_X"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="X:"\r
+ android:textSize="36sp" />\r
+\r
+ <TextView\r
+ android:id="@+id/tv_gyro_xvalue"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="0"\r
+ android:textSize="36sp" />\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
+ android:orientation="horizontal">\r
+\r
+ <TextView\r
+ android:id="@+id/tv_gyro_Y"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="Y:"\r
+ android:textSize="36sp" />\r
+\r
+ <TextView\r
+ android:id="@+id/tv_gyro_yvalue"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="0"\r
+ android:textSize="36sp" />\r
+ </LinearLayout>\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
+ android:orientation="horizontal">\r
+\r
+ <TextView\r
+ android:id="@+id/tv_gyro_Z"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="Z:"\r
+ android:textSize="36sp" />\r
+\r
+ <TextView\r
+ android:id="@+id/tv_gyro_zvalue"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="0"\r
+ android:textSize="36sp" />\r
+ </LinearLayout>\r
+ </LinearLayout>\r
+\r
+ <mobile.miki.mainui.ButtonViewTwo\r
+ android:id="@+id/btn_set"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:layout_alignParentBottom="true"\r
+ android:layout_centerHorizontal="true" >\r
+ </mobile.miki.mainui.ButtonViewTwo>\r
+\r
+</RelativeLayout>
\ No newline at end of file