altosdroid: whitespace and import tidyup
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosDroid.java
index 3715c3f9600a4d1d06b55c5f0efb08e3f81173de..3247c91e081b18d0e89c1e693701ee4f36602630 100644 (file)
@@ -37,7 +37,6 @@ import android.os.Message;
 import android.os.Messenger;
 import android.os.RemoteException;
 import android.support.v4.app.FragmentActivity;
-import android.support.v4.view.ViewPager;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
@@ -82,9 +81,9 @@ public class AltosDroid extends FragmentActivity {
        private TextView mVersion;
 
        // Tabs
-       TabHost     mTabHost;
-       AltosViewPager   mViewPager;
-       TabsAdapter mTabsAdapter;
+       TabHost         mTabHost;
+       AltosViewPager  mViewPager;
+       TabsAdapter     mTabsAdapter;
        ArrayList<AltosDroidTab> mTabs = new ArrayList<AltosDroidTab>();
 
        // Timer and Saved flight state for Age calculation
@@ -126,7 +125,6 @@ public class AltosDroid extends FragmentActivity {
                                        ad.mTitle.setText(R.string.title_connected_to);
                                        ad.mTitle.append(str);
                                        Toast.makeText(ad.getApplicationContext(), "Connected to " + str, Toast.LENGTH_SHORT).show();
-                                       ad.mAltosVoice.speak("Connected");
                                        break;
                                case TelemetryService.STATE_CONNECTING:
                                        ad.mTitle.setText(R.string.title_connecting);
@@ -206,13 +204,11 @@ public class AltosDroid extends FragmentActivity {
 
        void set_location(Location location) {
                saved_location = location;
-               if (saved_state != null) {
-                       update_ui(saved_state);
-               }
+               update_ui(saved_state);
        }
 
        void update_ui(AltosState state) {
-               if (saved_state != null) {
+               if (state != null && saved_state != null) {
                        if (saved_state.state != state.state) {
                                String currentTab = mTabHost.getCurrentTabTag();
                                switch (state.state) {
@@ -232,7 +228,7 @@ public class AltosDroid extends FragmentActivity {
 
                AltosGreatCircle from_receiver = null;
 
-               if (saved_location != null && state.gps != null && state.gps.locked) {
+               if (state != null && saved_location != null && state.gps != null && state.gps.locked) {
                        double altitude = 0;
                        if (saved_location.hasAltitude())
                                altitude = saved_location.getAltitude();
@@ -244,16 +240,19 @@ public class AltosDroid extends FragmentActivity {
                                                             state.gps.alt);
                }
 
-               mCallsignView.setText(state.data.callsign);
-               mSerialView.setText(String.format("%d", state.data.serial));
-               mFlightView.setText(String.format("%d", state.data.flight));
-               mStateView.setText(state.data.state());
-               mRSSIView.setText(String.format("%d", state.data.rssi));
+               if (state != null) {
+                       mCallsignView.setText(state.data.callsign);
+                       mSerialView.setText(String.format("%d", state.data.serial));
+                       mFlightView.setText(String.format("%d", state.data.flight));
+                       mStateView.setText(state.data.state());
+                       mRSSIView.setText(String.format("%d", state.data.rssi));
+               }
 
                for (AltosDroidTab mTab : mTabs)
                        mTab.update_ui(state, from_receiver, saved_location);
 
-               mAltosVoice.tell(state);
+               if (state != null)
+                       mAltosVoice.tell(state);
        }
 
        private void onTimerTick() {
@@ -265,6 +264,8 @@ public class AltosDroid extends FragmentActivity {
 
        static String pos(double p, String pos, String neg) {
                String  h = pos;
+               if (p == AltosRecord.MISSING)
+                       return "";
                if (p < 0) {
                        h = neg;
                        p = -p;
@@ -274,6 +275,18 @@ public class AltosDroid extends FragmentActivity {
                return String.format("%d°%9.4f\" %s", deg, min, h);
        }
 
+       static String number(String format, double value) {
+               if (value == AltosRecord.MISSING)
+                       return "";
+               return String.format(format, value);
+       }
+
+       static String integer(String format, int value) {
+               if (value == AltosRecord.MISSING)
+                       return "";
+               return String.format(format, value);
+       }
+
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);