]> Pileus Git - ~andy/iBeaconNav/blobdiff - src/edu/ucla/iBeaconNav/Main.java
Switch to a single service design
[~andy/iBeaconNav] / src / edu / ucla / iBeaconNav / Main.java
index b74f9c81cc7fa5eed372561461032696211b30af..9082279c9640887711cf34454391eb5ce17b396c 100644 (file)
@@ -31,7 +31,8 @@ import android.widget.Toast;
 
 import android.os.Bundle;
  
-import com.google.android.gms.maps.MapView;
+import com.google.android.gms.maps.*;
+import com.google.android.gms.maps.model.*;
 
 public class Main extends Activity
 {
@@ -48,6 +49,8 @@ public class Main extends Activity
        private LinearLayout state;
        private TextView     debug;
        private ScrollView   scroll;
+       private Button       rstHdBttn;
+       private Button       rstDstBttn;
 
        /* Private helper methods */
        private void notice(String text)
@@ -61,10 +64,10 @@ public class Main extends Activity
        /* Private handler methods */
        private void onRegister(Task task)
        {
-               Util.debug("Main: onRegister");
+               Util.debug("Main: onRegister_task");
                this.task    = task;
        }
-
+       
        private void onPosition()
        {
                Util.debug("Main: onPosition");
@@ -78,6 +81,85 @@ public class Main extends Activity
                this.toast.show();
        }
 
+       private void onShowData(float[] data){
+               TextView textView1 = null;
+               TextView textView2 = null;
+               TextView textView3 = null;
+               int displayNum = 3;
+               int dataId = (int)(data[0]+0.5);
+               CMD.Data dataType = CMD.Data.values()[dataId];
+               switch (dataType){
+               case ACC:
+                       textView1 = (TextView)findViewById(R.id.accText1);
+                       textView2 = (TextView)findViewById(R.id.accText2);
+                       textView3 = (TextView)findViewById(R.id.accText3);
+                       break;
+               case MAG:
+                       return;
+                       /*textView1 = (TextView)findViewById(R.id.magText1);
+                       textView2 = (TextView)findViewById(R.id.magText2);
+                       textView3 = (TextView)findViewById(R.id.magText3);
+                       break;*/
+               case GYR:
+                       textView1 = (TextView)findViewById(R.id.gyrText1);
+                       textView2 = (TextView)findViewById(R.id.gyrText2);
+                       textView3 = (TextView)findViewById(R.id.gyrText3);
+                       break;
+               case GYR1HZ:
+                       textView1 = (TextView)findViewById(R.id.gyr1hzx);
+                       textView2 = (TextView)findViewById(R.id.gyr1hzy);
+                       textView3 = (TextView)findViewById(R.id.gyr1hzz);
+                       break;
+               case ORIENT:
+                       textView1 = (TextView)findViewById(R.id.orientText1);
+                       textView2 = (TextView)findViewById(R.id.orientText2);
+                       textView3 = (TextView)findViewById(R.id.orientText3);
+                       break;
+               case WRDACC:
+                       textView1 = (TextView)findViewById(R.id.wrdAccText1);
+                       textView2 = (TextView)findViewById(R.id.wrdAccText2);
+                       textView3 = (TextView)findViewById(R.id.wrdAccText3);
+                       break;
+               case STPCNT:
+                       textView1 = (TextView)findViewById(R.id.stepCntText);
+                       textView2 = (TextView)findViewById(R.id.calGrvText);
+                       displayNum = 2;
+                       break;
+               case POSITION:
+                       textView1 = (TextView)findViewById(R.id.curPosXText);
+                       textView2 = (TextView)findViewById(R.id.curPosYText);
+                       displayNum = 2;
+                       break;
+               case ROTATION:
+                       textView1 = (TextView)findViewById(R.id.roll);
+                       textView2 = (TextView)findViewById(R.id.pitch);
+                       textView3 = (TextView)findViewById(R.id.yaw);
+                       break;
+               case HEADING:
+                       textView1 = (TextView)findViewById(R.id.headingText);
+                       displayNum = 1;
+                       break;
+               case WRDGYR:
+                       textView1 = (TextView)findViewById(R.id.wrdGyrText1);
+                       displayNum = 1;
+                       break;
+               case STABLE:
+                       textView1 = (TextView)findViewById(R.id.stableText);
+                       displayNum = 1;
+                       break;
+               default:
+                       Util.debug("Main: Nothing Matches");
+               }
+               
+               textView1.setText(Float.toString(data[1]));
+               if (displayNum >1){
+                       textView2.setText(Float.toString(data[2]));
+               }
+               if (displayNum >2){
+                       textView3.setText(Float.toString(data[3]));
+               }
+       }
+       
        /* Private service methods */
        private void register()
        {
@@ -136,10 +218,34 @@ public class Main extends Activity
                        this.state     = (LinearLayout) findViewById(R.id.state);
                        this.debug     = (TextView)     findViewById(R.id.debug);
                        this.scroll    = (ScrollView)   findViewById(R.id.debug_scroll);
+                       this.rstHdBttn = (Button)       findViewById(R.id.rstHdBttn);
+                       this.rstDstBttn= (Button)       findViewById(R.id.rstDstBttn);
+                       
+                       // TODO - remove these
+                       rstHdBttn.setOnClickListener(new View.OnClickListener() {
+                               @Override
+                               public void onClick(View v) {
+                                       // TODO Auto-generated method stub
+                                       startService(new Intent(Main.this, Task.class)
+                                       .putExtra("Command",   CMD.Command.RSTHEAD));
+                               }
+                       });
+                       
+                       rstDstBttn.setOnClickListener(new View.OnClickListener() {
+                               @Override
+                               public void onClick(View v) {
+                                       // TODO Auto-generated method stub
+                                       startService(new Intent(Main.this, Task.class)
+                                       .putExtra("Command",   CMD.Command.RSTDST));
+                               }
+                       });
 
                        // Get a handle to the Map Fragment
-                       //GoogleMap map = ((MapFragment)getFragmentManager()
-                       //      .findFragmentById(R.id.map_fragment)).getMap();
+                       GoogleMap map = ((MapFragment)getFragmentManager()
+                               .findFragmentById(R.id.map_fragment)).getMap();
+                       Marker mark = map.addMarker(new MarkerOptions()
+                                       .position(new LatLng(34.0722, -118.4441))
+                                       .title("UCLA"));
 
                        //LatLng sydney = new LatLng(-33.867, 151.206);
 
@@ -154,14 +260,14 @@ public class Main extends Activity
                        // Add window tabs
                        this.window.setup();
 
-                       this.window.addTab(this.window
-                                       .newTabSpec("map")
-                                       .setIndicator("Map")
-                                       .setContent(R.id.map));
                        this.window.addTab(this.window
                                        .newTabSpec("state")
                                        .setIndicator("State")
                                        .setContent(R.id.state));
+                       this.window.addTab(this.window
+                                       .newTabSpec("map")
+                                       .setIndicator("Map")
+                                       .setContent(R.id.map));
                        this.window.addTab(this.window
                                        .newTabSpec("debug")
                                        .setIndicator("Debug")
@@ -257,16 +363,20 @@ public class Main extends Activity
        /* Handler class */
        class MainHandler extends Handler
        {
+               @Override
                public void handleMessage(android.os.Message msg)
                {
                        CMD.Response resp = CMD.Response.values()[msg.what];
                        switch (resp) {
-                               case POSITION:
-                                       Main.this.onPosition();
+                               case REGISTER:
+                                       Main.this.onRegister((Task)msg.obj);
                                        break;
                                case NOTIFY:
                                        Main.this.onNotify((String)msg.obj);
                                        break;
+                               case SHOWDATA:
+                                       Main.this.onShowData((float[])msg.obj);
+                                       break;
                                default:
                                        Util.debug("Main: unknown message - " + resp);
                                        break;