altosdroid: Add 'Auto' to map tracker list
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosDroid.java
index 6cd9463afbc056f39e7cde3561134a943bd75933..71ac298e77b6d6000d4620db1a16eddd57871b5b 100644 (file)
@@ -87,6 +87,11 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
        private int mAgeNewColor;
        private int mAgeOldColor;
 
+       public static final String      tab_pad_name = "pad";
+       public static final String      tab_flight_name = "flight";
+       public static final String      tab_recover_name = "recover";
+       public static final String      tab_map_name = "map";
+
        // field to display the version at the bottom of the screen
        private TextView mVersion;
 
@@ -128,7 +133,6 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
 
                        switch (msg.what) {
                        case MSG_STATE:
-                               AltosDebug.debug("MSG_STATE");
                                if (msg.obj == null) {
                                        AltosDebug.debug("telemetry_state null!");
                                        return;
@@ -136,7 +140,6 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                                ad.update_state((TelemetryState) msg.obj);
                                break;
                        case MSG_UPDATE_AGE:
-                               AltosDebug.debug("MSG_UPDATE_AGE");
                                ad.update_age();
                                break;
                        }
@@ -399,9 +402,9 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                                if (prev_locked != locked) {
                                        String currentTab = mTabHost.getCurrentTabTag();
                                        if (locked) {
-                                               if (currentTab.equals("pad")) mTabHost.setCurrentTabByTag("flight");
+                                               if (currentTab.equals(tab_pad_name)) mTabHost.setCurrentTabByTag(tab_flight_name);
                                        } else {
-                                               if (currentTab.equals("flight")) mTabHost.setCurrentTabByTag("pad");
+                                               if (currentTab.equals(tab_flight_name)) mTabHost.setCurrentTabByTag(tab_pad_name);
                                        }
                                }
                        } else {
@@ -409,13 +412,13 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                                        String currentTab = mTabHost.getCurrentTabTag();
                                        switch (state.state) {
                                        case AltosLib.ao_flight_boost:
-                                               if (currentTab.equals("pad")) mTabHost.setCurrentTabByTag("flight");
+                                               if (currentTab.equals(tab_pad_name)) mTabHost.setCurrentTabByTag(tab_flight_name);
                                                break;
                                        case AltosLib.ao_flight_landed:
-                                               if (currentTab.equals("flight")) mTabHost.setCurrentTabByTag("recover");
+                                               if (currentTab.equals(tab_flight_name)) mTabHost.setCurrentTabByTag(tab_recover_name);
                                                break;
                                        case AltosLib.ao_flight_stateless:
-                                               if (currentTab.equals("pad")) mTabHost.setCurrentTabByTag("flight");
+                                               if (currentTab.equals(tab_pad_name)) mTabHost.setCurrentTabByTag(tab_flight_name);
                                                break;
                                        }
                                }
@@ -461,8 +464,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                for (AltosDroidTab mTab : mTabs)
                        mTab.update_ui(telem_state, state, from_receiver, location, mTab == mTabsAdapter.currentItem());
 
-               if (state != null && mAltosVoice != null)
-                       mAltosVoice.tell(state, from_receiver);
+               if (mAltosVoice != null)
+                       mAltosVoice.tell(telem_state, state, from_receiver, location, (AltosDroidTab) mTabsAdapter.currentItem());
 
                saved_state = state;
        }
@@ -535,10 +538,10 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
 
                mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);
 
-               mTabsAdapter.addTab(mTabHost.newTabSpec("pad").setIndicator(create_tab_view("Pad")), TabPad.class, null);
-               mTabsAdapter.addTab(mTabHost.newTabSpec("flight").setIndicator(create_tab_view("Flight")), TabFlight.class, null);
-               mTabsAdapter.addTab(mTabHost.newTabSpec("recover").setIndicator(create_tab_view("Recover")), TabRecover.class, null);
-               mTabsAdapter.addTab(mTabHost.newTabSpec("map").setIndicator(create_tab_view("Map")), TabMap.class, null);
+               mTabsAdapter.addTab(mTabHost.newTabSpec(tab_pad_name).setIndicator(create_tab_view("Pad")), TabPad.class, null);
+               mTabsAdapter.addTab(mTabHost.newTabSpec(tab_flight_name).setIndicator(create_tab_view("Flight")), TabFlight.class, null);
+               mTabsAdapter.addTab(mTabHost.newTabSpec(tab_recover_name).setIndicator(create_tab_view("Recover")), TabRecover.class, null);
+               mTabsAdapter.addTab(mTabHost.newTabSpec(tab_map_name).setIndicator(create_tab_view("Map")), TabMap.class, null);
 
                // Display the Version
                mVersion = (TextView) findViewById(R.id.version);
@@ -649,6 +652,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                super.onStart();
                AltosDebug.debug("++ ON START ++");
 
+               set_switch_time();
+
                noticeIntent(getIntent());
 
                // Start Telemetry Service
@@ -686,12 +691,6 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
        public void onStop() {
                super.onStop();
                AltosDebug.debug("-- ON STOP --");
-
-               doUnbindService();
-               if (mAltosVoice != null) {
-                       mAltosVoice.stop();
-                       mAltosVoice = null;
-               }
        }
 
        @Override
@@ -699,7 +698,11 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                super.onDestroy();
                AltosDebug.debug("--- ON DESTROY ---");
 
-               if (mAltosVoice != null) mAltosVoice.stop();
+               doUnbindService();
+               if (mAltosVoice != null) {
+                       mAltosVoice.stop();
+                       mAltosVoice = null;
+               }
                stop_timer();
        }
 
@@ -854,6 +857,26 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                update_state(null);
        }
 
+       void touch_trackers(Integer[] serials) {
+               AlertDialog.Builder builder_tracker = new AlertDialog.Builder(this);
+               builder_tracker.setTitle("Select Tracker");
+               final String[] trackers = new String[serials.length + 1];
+               trackers[0] = "Auto";
+               for (int i = 0; i < serials.length; i++)
+                       trackers[i+1] = String.format("%d", serials[i]);
+               builder_tracker.setItems(trackers,
+                                        new DialogInterface.OnClickListener() {
+                                                public void onClick(DialogInterface dialog, int item) {
+                                                        if (item == 0)
+                                                                select_tracker(0);
+                                                        else
+                                                                select_tracker(Integer.parseInt(trackers[item]));
+                                                }
+                                        });
+               AlertDialog alert_tracker = builder_tracker.create();
+               alert_tracker.show();
+       }
+
        void delete_track(int serial) {
                try {
                        mService.send(Message.obtain(null, TelemetryService.MSG_DELETE_SERIAL, (Integer) serial));
@@ -990,4 +1013,35 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                }
                return false;
        }
+
+       static String direction(AltosGreatCircle from_receiver,
+                            Location receiver) {
+               if (from_receiver == null)
+                       return null;
+
+               if (receiver == null)
+                       return null;
+
+               if (!receiver.hasBearing())
+                       return null;
+
+               float   bearing = receiver.getBearing();
+               float   heading = (float) from_receiver.bearing - bearing;
+
+               while (heading <= -180.0f)
+                       heading += 360.0f;
+               while (heading > 180.0f)
+                       heading -= 360.0f;
+
+               int iheading = (int) (heading + 0.5f);
+
+               if (-1 < iheading && iheading < 1)
+                       return "ahead";
+               else if (iheading < -179 || 179 < iheading)
+                       return "backwards";
+               else if (iheading < 0)
+                       return String.format("left %d°", -iheading);
+               else
+                       return String.format("right %d°", iheading);
+       }
 }