2 * Copyright © 2013 Mike Beattie <mike@ethernal.org>
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.
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.
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.
18 package org.altusmetrum.AltosDroid;
20 import org.altusmetrum.altoslib_1.AltosState;
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.ImageView;
29 import android.widget.TextView;
31 public class TabAscent extends Fragment implements AltosDroidTab {
32 AltosDroid mAltosDroid;
34 private TextView mHeightView;
35 private TextView mMaxHeightView;
36 private TextView mSpeedView;
37 private TextView mMaxSpeedView;
38 private TextView mAccelView;
39 private TextView mMaxAccelView;
40 private TextView mLatitudeView;
41 private TextView mLongitudeView;
42 private TextView mApogeeVoltageView;
43 private GoNoGoLights mApogeeLights;
44 private TextView mMainVoltageView;
45 private GoNoGoLights mMainLights;
48 public void onAttach(Activity activity) {
49 super.onAttach(activity);
50 mAltosDroid = (AltosDroid) activity;
51 mAltosDroid.registerTab(this);
55 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
56 View v = inflater.inflate(R.layout.tab_ascent, container, false);
58 mHeightView = (TextView) v.findViewById(R.id.height_value);
59 mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value);
60 mSpeedView = (TextView) v.findViewById(R.id.speed_value);
61 mMaxSpeedView = (TextView) v.findViewById(R.id.max_speed_value);
62 mAccelView = (TextView) v.findViewById(R.id.accel_value);
63 mMaxAccelView = (TextView) v.findViewById(R.id.max_accel_value);
64 mLatitudeView = (TextView) v.findViewById(R.id.lat_value);
65 mLongitudeView = (TextView) v.findViewById(R.id.lon_value);
67 mApogeeVoltageView = (TextView) v.findViewById(R.id.apogee_voltage_value);
68 mApogeeLights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
69 (ImageView) v.findViewById(R.id.apogee_greenled),
72 mMainVoltageView = (TextView) v.findViewById(R.id.main_voltage_value);
73 mMainLights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
74 (ImageView) v.findViewById(R.id.main_greenled),
81 public void onDestroy() {
83 mAltosDroid.unregisterTab(this);
87 public void update_ui(AltosState state) {
88 mHeightView.setText(String.format("%6.0f m", state.height));
89 mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
90 mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
91 mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
92 mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
93 mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
95 mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
96 mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
98 mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
99 mApogeeLights.set(state.drogue_sense > 3.2);
101 mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
102 mMainLights.set(state.main_sense > 3.2);