altosdroid: Add multi-tracker support
[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_7.*;
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         private TextView mBearingView;
33         private TextView mDistanceView;
34         private TextView mTargetLatitudeView;
35         private TextView mTargetLongitudeView;
36         private TextView mReceiverLatitudeView;
37         private TextView mReceiverLongitudeView;
38         private TextView mMaxHeightView;
39         private TextView mMaxSpeedView;
40         private TextView mMaxAccelView;
41
42         @Override
43         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
44                 View v = inflater.inflate(R.layout.tab_landed, container, false);
45
46                 mBearingView   = (TextView) v.findViewById(R.id.bearing_value);
47                 mDistanceView  = (TextView) v.findViewById(R.id.distance_value);
48                 mTargetLatitudeView  = (TextView) v.findViewById(R.id.target_lat_value);
49                 mTargetLongitudeView = (TextView) v.findViewById(R.id.target_lon_value);
50                 mReceiverLatitudeView  = (TextView) v.findViewById(R.id.receiver_lat_value);
51                 mReceiverLongitudeView = (TextView) v.findViewById(R.id.receiver_lon_value);
52                 mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value);
53                 mMaxSpeedView  = (TextView) v.findViewById(R.id.max_speed_value);
54                 mMaxAccelView  = (TextView) v.findViewById(R.id.max_accel_value);
55
56                 return v;
57         }
58
59         public String tab_name() { return "landed"; }
60
61         public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
62                 if (from_receiver != null) {
63                         mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
64                         set_value(mDistanceView, AltosConvert.distance, 6, from_receiver.distance);
65                 }
66                 if (state != null && state.gps != null) {
67                         mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
68                         mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "E", "W"));
69                 }
70
71                 if (receiver != null) {
72                         mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
73                         mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "E", "W"));
74                 }
75
76                 if (state != null) {
77                         set_value(mMaxHeightView, AltosConvert.height, 6, state.max_height());
78                         set_value(mMaxAccelView, AltosConvert.accel, 6, state.max_acceleration());
79                         set_value(mMaxSpeedView, AltosConvert.speed, 6, state.max_speed());
80                 }
81         }
82 }