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