Move java source, and resources to new paths for gradle
[fw/altos] / altosdroid / app / src / main / java / org / altusmetrum / AltosDroid / TabFlight.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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.AltosDroid;
20
21 import org.altusmetrum.altoslib_13.*;
22
23 import android.app.Activity;
24 import android.os.Bundle;
25 import android.support.v4.app.Fragment;
26 import android.view.*;
27 import android.widget.*;
28 import android.location.Location;
29
30 public class TabFlight extends AltosDroidTab {
31         private TextView speed_view;
32         private TextView height_view;
33         private TextView max_speed_view;
34         private TextView max_height_view;
35         private TextView elevation_view;
36         private TextView range_view;
37         private TextView bearing_view;
38         private TextView compass_view;
39         private TextView distance_view;
40         private TextView latitude_view;
41         private TextView longitude_view;
42         private View apogee_view;
43         private TextView apogee_voltage_view;
44         private TextView apogee_voltage_label;
45         private GoNoGoLights apogee_lights;
46         private View main_view;
47         private TextView main_voltage_view;
48         private TextView main_voltage_label;
49         private GoNoGoLights main_lights;
50
51         @Override
52         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
53                 View v = inflater.inflate(R.layout.tab_flight, container, false);
54
55                 speed_view     = (TextView) v.findViewById(R.id.speed_value);
56                 height_view    = (TextView) v.findViewById(R.id.height_value);
57                 max_speed_view = (TextView) v.findViewById(R.id.max_speed_value);
58                 max_height_view= (TextView) v.findViewById(R.id.max_height_value);
59                 elevation_view = (TextView) v.findViewById(R.id.elevation_value);
60                 range_view     = (TextView) v.findViewById(R.id.range_value);
61                 bearing_view   = (TextView) v.findViewById(R.id.bearing_value);
62                 compass_view   = (TextView) v.findViewById(R.id.compass_value);
63                 distance_view  = (TextView) v.findViewById(R.id.distance_value);
64                 latitude_view  = (TextView) v.findViewById(R.id.lat_value);
65                 longitude_view = (TextView) v.findViewById(R.id.lon_value);
66
67                 apogee_view = v.findViewById(R.id.apogee_view);
68                 apogee_voltage_view = (TextView) v.findViewById(R.id.apogee_voltage_value);
69                 apogee_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
70                                                  (ImageView) v.findViewById(R.id.apogee_greenled),
71                                                  getResources());
72                 apogee_voltage_label = (TextView) v.findViewById(R.id.apogee_voltage_label);
73
74                 main_view = v.findViewById(R.id.main_view);
75                 main_voltage_view = (TextView) v.findViewById(R.id.main_voltage_value);
76                 main_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
77                                                (ImageView) v.findViewById(R.id.main_greenled),
78                                                getResources());
79                 main_voltage_label = (TextView) v.findViewById(R.id.main_voltage_label);
80
81                 return v;
82         }
83
84         public String tab_name() { return AltosDroid.tab_flight_name; }
85
86         public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
87                 if (state != null) {
88                         set_value(speed_view, AltosConvert.speed, 6, state.speed());
89                         set_value(height_view, AltosConvert.height, 6, state.height());
90                         set_value(max_speed_view, AltosConvert.speed, 6, state.max_speed());
91                         set_value(max_height_view, AltosConvert.height, 6, state.max_height());
92                         if (from_receiver != null) {
93                                 elevation_view.setText(AltosDroid.number("%3.0f°", from_receiver.elevation));
94                                 set_value(range_view, AltosConvert.distance, 6, from_receiver.range);
95                                 bearing_view.setText(AltosDroid.number("%3.0f°", from_receiver.bearing));
96                                 compass_view.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
97                                 set_value(distance_view, AltosConvert.distance, 6, from_receiver.distance);
98                         } else { 
99                                 elevation_view.setText("<unknown>");
100                                 range_view.setText("<unknown>");
101                                 bearing_view.setText("<unknown>");
102                                 compass_view.setText("<unknown>");
103                                 distance_view.setText("<unknown>");
104                         }
105                         if (state.gps != null) {
106                                 latitude_view.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
107                                 longitude_view.setText(AltosDroid.pos(state.gps.lon, "E", "W"));
108                         }
109
110                         if (state.apogee_voltage == AltosLib.MISSING) {
111                                 apogee_view.setVisibility(View.GONE);
112                         } else {
113                                 apogee_voltage_view.setText(AltosDroid.number("%4.2f V", state.apogee_voltage));
114                                 apogee_lights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
115                                 apogee_view.setVisibility(View.VISIBLE);
116                         }
117
118                         if (state.main_voltage == AltosLib.MISSING) {
119                                 main_view.setVisibility(View.GONE);
120                         } else {
121                                 main_voltage_view.setText(AltosDroid.number("%4.2f V", state.main_voltage));
122                                 main_lights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
123                                 main_view.setVisibility(View.VISIBLE);
124                         }
125                 }
126         }
127
128 }