Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabAscent.java
index bda6b1fd3b5dfdb4fe63b0b8d3ff8f919a7f1926..afce937f415f3d8d88122a219c935a0c9adcc3f7 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.AltosState;
+import org.altusmetrum.altoslib_7.*;
 
 import android.app.Activity;
 import android.os.Bundle;
@@ -27,10 +27,9 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.TextView;
+import android.location.Location;
 
-public class TabAscent extends Fragment implements AltosDroidTab {
-       AltosDroid mAltosDroid;
-
+public class TabAscent extends AltosDroidTab {
        private TextView mHeightView;
        private TextView mMaxHeightView;
        private TextView mSpeedView;
@@ -44,13 +43,6 @@ public class TabAscent extends Fragment implements AltosDroidTab {
        private TextView mMainVoltageView;
        private GoNoGoLights mMainLights;
 
-       @Override
-       public void onAttach(Activity activity) {
-               super.onAttach(activity);
-               mAltosDroid = (AltosDroid) activity;
-               mAltosDroid.registerTab(this);
-       }
-
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                View v = inflater.inflate(R.layout.tab_ascent, container, false);
@@ -77,28 +69,33 @@ public class TabAscent extends Fragment implements AltosDroidTab {
                return v;
        }
 
-       @Override
-       public void onDestroy() {
-               super.onDestroy();
-               mAltosDroid.unregisterTab(this);
-               mAltosDroid = null;
+       public String tab_name() {
+               return "ascent";
        }
 
-       public void update_ui(AltosState state) {
-               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));
-
-               mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
-               mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
-
-               mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
-               mApogeeLights.set(state.drogue_sense > 3.2);
-
-               mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
-               mMainLights.set(state.main_sense > 3.2);
+       public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
+               if (state != null) {
+                       set_value(mHeightView, AltosConvert.height, 6, state.height());
+                       set_value(mHeightView, AltosConvert.height, 6, state.height());
+                       set_value(mMaxHeightView, AltosConvert.height, 6, state.max_height());
+                       set_value(mSpeedView, AltosConvert.speed, 6, state.speed());
+                       set_value(mMaxSpeedView, AltosConvert.speed, 6, state.max_speed());
+                       set_value(mAccelView, AltosConvert.accel, 6, state.acceleration());
+                       set_value(mMaxAccelView, AltosConvert.accel, 6, state.max_acceleration());
+
+                       if (state.gps != null) {
+                               mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
+                               mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "E", "W"));
+                       } else {
+                               mLatitudeView.setText("");
+                               mLongitudeView.setText("");
+                       }
+
+                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.apogee_voltage));
+                       mApogeeLights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
+
+                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_voltage));
+                       mMainLights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
+               }
        }
 }