Merge remote-tracking branch 'mjb/altosdroid'
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabLanded.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.AltosState;
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.TextView;
29
30 public class TabLanded extends Fragment implements AltosDroidTab {
31         AltosDroid mAltosDroid;
32
33         private TextView mBearingView;
34         private TextView mDistanceView;
35         private TextView mLatitudeView;
36         private TextView mLongitudeView;
37         private TextView mMaxHeightView;
38         private TextView mMaxSpeedView;
39         private TextView mMaxAccelView;
40
41
42         @Override
43         public void onAttach(Activity activity) {
44                 super.onAttach(activity);
45                 mAltosDroid = (AltosDroid) activity;
46                 mAltosDroid.registerTab(this);
47         }
48
49         @Override
50         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
51                 View v = inflater.inflate(R.layout.tab_landed, container, false);
52
53                 mBearingView   = (TextView) v.findViewById(R.id.bearing_value);
54                 mDistanceView  = (TextView) v.findViewById(R.id.distance_value);
55                 mLatitudeView  = (TextView) v.findViewById(R.id.lat_value);
56                 mLongitudeView = (TextView) v.findViewById(R.id.lon_value);
57                 mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value);
58                 mMaxSpeedView  = (TextView) v.findViewById(R.id.max_speed_value);
59                 mMaxAccelView  = (TextView) v.findViewById(R.id.max_accel_value);
60
61                 return v;
62         }
63
64         @Override
65         public void onDestroy() {
66                 super.onDestroy();
67                 mAltosDroid.unregisterTab(this);
68                 mAltosDroid = null;
69         }
70
71         public void update_ui(AltosState state) {
72                 if (state.from_pad != null) {
73                         mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
74                         mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance));
75                 }
76                 mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
77                 mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
78                 mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
79                 mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
80                 mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
81         }
82
83 }