4c69d869c8b4839ed8ab38deccbdc2bf933480bc
[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_6.*;
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 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 String tab_name() { return "landed"; }
77
78         public void show(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
79                 if (from_receiver != null) {
80                         mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
81                         set_value(mDistanceView, AltosConvert.distance, 6, from_receiver.distance);
82                 }
83                 if (state != null && state.gps != null) {
84                         mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
85                         mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "E", "W"));
86                 }
87
88                 if (receiver != null) {
89                         mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
90                         mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "E", "W"));
91                 }
92
93                 if (state != null) {
94                         set_value(mMaxHeightView, AltosConvert.height, 6, state.max_height());
95                         set_value(mMaxAccelView, AltosConvert.accel, 6, state.max_acceleration());
96                         set_value(mMaxSpeedView, AltosConvert.speed, 6, state.max_speed());
97                 }
98         }
99 }