]> git.gag.com Git - fw/altos/blob - altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java
Merge branch 'branch-1.6' into debian
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosDroidTab.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_8.*;
21 import android.location.Location;
22 import android.app.Activity;
23 import android.graphics.Color;
24 import android.os.Bundle;
25 import android.support.v4.app.Fragment;
26 import android.support.v4.app.FragmentTransaction;
27 import android.support.v4.app.FragmentManager;
28 import android.location.Location;
29 import android.widget.TextView;
30
31 public abstract class AltosDroidTab extends Fragment implements AltosUnitsListener {
32         TelemetryState          last_telem_state;
33         AltosState              last_state;
34         AltosGreatCircle        last_from_receiver;
35         Location                last_receiver;
36         AltosDroid              altos_droid;
37
38         public abstract void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver);
39
40         public abstract String tab_name();
41
42         public void set_map_type(int map_type) {
43         }
44
45         public void set_map_source(int map_source) {
46         }
47
48         public void units_changed(boolean imperial_units) {
49                 if (!isHidden())
50                         show(last_telem_state, last_state, last_from_receiver, last_receiver);
51         }
52
53         public void set_value(TextView text_view,
54                               AltosUnits units,
55                               int width,
56                               double value) {
57                 if (value == AltosLib.MISSING)
58                         text_view.setText("");
59                 else
60                         text_view.setText(units.show(width, value));
61         }
62
63         public void set_visible(boolean visible) {
64                 FragmentTransaction     ft = AltosDroid.fm.beginTransaction();
65                 AltosDebug.debug("set visible %b %s\n", visible, tab_name());
66                 if (visible) {
67                         ft.show(this);
68                         show(last_telem_state, last_state, last_from_receiver, last_receiver);
69                 } else
70                         ft.hide(this);
71                 ft.commitAllowingStateLoss();
72         }
73
74         @Override
75         public void onAttach(Activity activity) {
76                 super.onAttach(activity);
77                 altos_droid = (AltosDroid) activity;
78                 altos_droid.registerTab(this);
79         }
80
81         @Override
82         public void onDetach() {
83                 super.onDetach();
84                 altos_droid.unregisterTab(this);
85                 altos_droid = null;
86         }
87
88         @Override
89         public void onResume() {
90                 super.onResume();
91                 AltosDebug.debug("onResume tab %s\n", tab_name());
92                 set_visible(true);
93         }
94
95         public void update_ui(TelemetryState telem_state, AltosState state,
96                               AltosGreatCircle from_receiver, Location receiver, boolean is_current)
97         {
98                 last_telem_state = telem_state;
99                 last_state = state;
100                 last_from_receiver = from_receiver;
101                 last_receiver = receiver;
102                 if (is_current)
103                         show(telem_state, state, from_receiver, receiver);
104                 else
105                         return;
106         }
107 }