97a35c9eb4a044ca9f1903f9394586725c48a409
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabRecover.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_11.*;
22
23 import android.app.Activity;
24 import android.os.Bundle;
25 import android.support.v4.app.Fragment;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.widget.TextView;
30 import android.location.Location;
31
32 public class TabRecover extends AltosDroidTab {
33         private TextView mBearingView;
34         private TextView mDirectionView;
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         @Override
45         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
46                 View v = inflater.inflate(R.layout.tab_recover, container, false);
47
48                 mBearingView   = (TextView) v.findViewById(R.id.bearing_value);
49                 mDirectionView = (TextView) v.findViewById(R.id.direction_value);
50                 mDistanceView  = (TextView) v.findViewById(R.id.distance_value);
51                 mTargetLatitudeView  = (TextView) v.findViewById(R.id.target_lat_value);
52                 mTargetLongitudeView = (TextView) v.findViewById(R.id.target_lon_value);
53                 mReceiverLatitudeView  = (TextView) v.findViewById(R.id.receiver_lat_value);
54                 mReceiverLongitudeView = (TextView) v.findViewById(R.id.receiver_lon_value);
55                 mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value);
56                 mMaxSpeedView  = (TextView) v.findViewById(R.id.max_speed_value);
57                 mMaxAccelView  = (TextView) v.findViewById(R.id.max_accel_value);
58
59                 return v;
60         }
61
62         public String tab_name() { return AltosDroid.tab_recover_name; }
63
64         public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
65                 if (from_receiver != null) {
66                         mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
67                         set_value(mDistanceView, AltosConvert.distance, 6, from_receiver.distance);
68                         String direction = AltosDroid.direction(from_receiver, receiver);
69                         if (direction == null)
70                                 mDirectionView.setText("");
71                         else
72                                 mDirectionView.setText(direction);
73                 }
74                 if (state != null && state.gps != null) {
75                         mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
76                         mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "E", "W"));
77                 }
78
79                 if (receiver != null) {
80                         mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
81                         mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "E", "W"));
82                 }
83
84                 if (state != null) {
85                         set_value(mMaxHeightView, AltosConvert.height, 6, state.max_height());
86                         set_value(mMaxAccelView, AltosConvert.accel, 6, state.max_acceleration());
87                         set_value(mMaxSpeedView, AltosConvert.speed, 6, state.max_speed());
88                 }
89         }
90 }