altosdroid: more updates for new AltosState
[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_2.*;
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 import android.location.Location;
30
31 public class TabLanded extends Fragment implements AltosDroidTab {
32         AltosDroid mAltosDroid;
33
34         private TextView mBearingView;
35         private TextView mDistanceView;
36         private TextView mTargetLatitudeView;
37         private TextView mTargetLongitudeView;
38         private TextView mReceiverLatitudeView;
39         private TextView mReceiverLongitudeView;
40         private TextView mMaxHeightView;
41         private TextView mMaxSpeedView;
42         private TextView mMaxAccelView;
43
44
45         @Override
46         public void onAttach(Activity activity) {
47                 super.onAttach(activity);
48                 mAltosDroid = (AltosDroid) activity;
49                 mAltosDroid.registerTab(this);
50         }
51
52         @Override
53         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
54                 View v = inflater.inflate(R.layout.tab_landed, container, false);
55
56                 mBearingView   = (TextView) v.findViewById(R.id.bearing_value);
57                 mDistanceView  = (TextView) v.findViewById(R.id.distance_value);
58                 mTargetLatitudeView  = (TextView) v.findViewById(R.id.target_lat_value);
59                 mTargetLongitudeView = (TextView) v.findViewById(R.id.target_lon_value);
60                 mReceiverLatitudeView  = (TextView) v.findViewById(R.id.receiver_lat_value);
61                 mReceiverLongitudeView = (TextView) v.findViewById(R.id.receiver_lon_value);
62                 mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value);
63                 mMaxSpeedView  = (TextView) v.findViewById(R.id.max_speed_value);
64                 mMaxAccelView  = (TextView) v.findViewById(R.id.max_accel_value);
65
66                 return v;
67         }
68
69         @Override
70         public void onDestroy() {
71                 super.onDestroy();
72                 mAltosDroid.unregisterTab(this);
73                 mAltosDroid = null;
74         }
75
76         public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
77                 if (from_receiver != null) {
78                         mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
79                         mDistanceView.setText(String.format("%6.0f m", from_receiver.distance));
80                 }
81                 if (state != null && state.gps != null) {
82                         mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
83                         mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
84                 }
85
86                 if (receiver != null) {
87                         mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
88                         mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E"));
89                 }
90                
91                 if (state != null) {
92                         mMaxHeightView.setText(String.format("%6.0f m", state.max_height()));
93                         mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration()));
94                         mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
95                 }
96         }
97
98 }