0e141ae47e942e2983333a1ef526c79b67b13c2d
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabAscent.java
1 /*
2  * Copyright © 2013 Mike Beattie <mike@ethernal.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.AltosDroid;
19
20 import org.altusmetrum.altoslib_1.*;
21
22 import android.app.Activity;
23 import android.os.Bundle;
24 import android.support.v4.app.Fragment;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.ImageView;
29 import android.widget.TextView;
30 import android.location.Location;
31
32 public class TabAscent extends Fragment implements AltosDroidTab {
33         AltosDroid mAltosDroid;
34
35         private TextView mHeightView;
36         private TextView mMaxHeightView;
37         private TextView mSpeedView;
38         private TextView mMaxSpeedView;
39         private TextView mAccelView;
40         private TextView mMaxAccelView;
41         private TextView mLatitudeView;
42         private TextView mLongitudeView;
43         private TextView mApogeeVoltageView;
44         private GoNoGoLights mApogeeLights;
45         private TextView mMainVoltageView;
46         private GoNoGoLights mMainLights;
47
48         @Override
49         public void onAttach(Activity activity) {
50                 super.onAttach(activity);
51                 mAltosDroid = (AltosDroid) activity;
52                 mAltosDroid.registerTab(this);
53         }
54
55         @Override
56         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
57                 View v = inflater.inflate(R.layout.tab_ascent, container, false);
58
59                 mHeightView    = (TextView) v.findViewById(R.id.height_value);
60                 mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value);
61                 mSpeedView     = (TextView) v.findViewById(R.id.speed_value);
62                 mMaxSpeedView  = (TextView) v.findViewById(R.id.max_speed_value);
63                 mAccelView     = (TextView) v.findViewById(R.id.accel_value);
64                 mMaxAccelView  = (TextView) v.findViewById(R.id.max_accel_value);
65                 mLatitudeView  = (TextView) v.findViewById(R.id.lat_value);
66                 mLongitudeView = (TextView) v.findViewById(R.id.lon_value);
67
68                 mApogeeVoltageView = (TextView) v.findViewById(R.id.apogee_voltage_value);
69                 mApogeeLights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
70                                                  (ImageView) v.findViewById(R.id.apogee_greenled),
71                                                  getResources());
72
73                 mMainVoltageView = (TextView) v.findViewById(R.id.main_voltage_value);
74                 mMainLights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
75                                                (ImageView) v.findViewById(R.id.main_greenled),
76                                                getResources());
77
78                 return v;
79         }
80
81         @Override
82         public void onDestroy() {
83                 super.onDestroy();
84                 mAltosDroid.unregisterTab(this);
85                 mAltosDroid = null;
86         }
87
88         public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
89                 if (state != null) {
90                         mHeightView.setText(AltosDroid.number("%6.0f m", state.height));
91                         mMaxHeightView.setText(AltosDroid.number("%6.0f m", state.max_height));
92                         mSpeedView.setText(AltosDroid.number("%6.0f m/s", state.speed()));
93                         mMaxSpeedView.setText(AltosDroid.number("%6.0f m/s", state.max_speed()));
94                         mAccelView.setText(AltosDroid.number("%6.0f m/s²", state.acceleration));
95                         mMaxAccelView.setText(AltosDroid.number("%6.0f m/s²", state.max_acceleration));
96
97                         if (state.gps != null) {
98                                 mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
99                                 mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
100                         } else {
101                                 mLatitudeView.setText("");
102                                 mLongitudeView.setText("");
103                         }
104
105                         mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense));
106                         mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING);
107
108                         mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense));
109                         mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING);
110                 }
111         }
112 }