altosdroid: Update tab contents before switching
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabAscent.java
index 23d2e97cead2eb9d48e8000316183999a0d7f8b4..c146c27746d274dbde683582fff5dc9ee56064fa 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_5.*;
 
 import android.app.Activity;
 import android.os.Bundle;
@@ -29,7 +29,7 @@ import android.widget.ImageView;
 import android.widget.TextView;
 import android.location.Location;
 
-public class TabAscent extends Fragment implements AltosDroidTab {
+public class TabAscent extends AltosDroidTab {
        AltosDroid mAltosDroid;
 
        private TextView mHeightView;
@@ -85,25 +85,32 @@ public class TabAscent extends Fragment implements AltosDroidTab {
                mAltosDroid = null;
        }
 
-       public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
+       public String tab_name() {
+               return "ascent";
+       }
+
+       public void show(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
                if (state != null) {
-                       mHeightView.setText(String.format("%6.0f m", state.height));
-                       mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
-                       mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
-                       mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
-                       mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
-                       mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
+                       mHeightView.setText(AltosDroid.number("%6.0f m", state.height()));
+                       mMaxHeightView.setText(AltosDroid.number("%6.0f m", state.max_height()));
+                       mSpeedView.setText(AltosDroid.number("%6.0f m/s", state.speed()));
+                       mMaxSpeedView.setText(AltosDroid.number("%6.0f m/s", state.max_speed()));
+                       mAccelView.setText(AltosDroid.number("%6.0f m/s²", state.acceleration()));
+                       mMaxAccelView.setText(AltosDroid.number("%6.0f m/s²", state.max_acceleration()));
 
                        if (state.gps != null) {
                                mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
                                mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+                       } else {
+                               mLatitudeView.setText("");
+                               mLongitudeView.setText("");
                        }
 
-                       mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
-                       mApogeeLights.set(state.drogue_sense > 3.2);
+                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.apogee_voltage));
+                       mApogeeLights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
 
-                       mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
-                       mMainLights.set(state.main_sense > 3.2);
+                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_voltage));
+                       mMainLights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
                }
        }
 }