Bump java lib versions in preparation for 1.9.2
[fw/altos] / altosdroid / app / src / main / java / 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; 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_14.*;
22 import android.location.Location;
23 import android.app.Activity;
24 import android.content.*;
25 import androidx.fragment.app.Fragment;
26 import androidx.fragment.app.FragmentTransaction;
27 import android.widget.TextView;
28
29 public abstract class AltosDroidTab extends Fragment implements AltosUnitsListener {
30         TelemetryState          last_telem_state;
31         AltosState              last_state;
32         AltosGreatCircle        last_from_receiver;
33         Location                last_receiver;
34         AltosDroid              altos_droid;
35
36         public abstract void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver);
37
38         public abstract String tab_name();
39
40         public void units_changed(boolean imperial_units) {
41                 if (!isHidden())
42                         show(last_telem_state, last_state, last_from_receiver, last_receiver);
43         }
44
45         public void set_value(TextView text_view,
46                               AltosUnits units,
47                               int width,
48                               double value) {
49                 if (value == AltosLib.MISSING)
50                         text_view.setText("");
51                 else
52                         text_view.setText(units.show(width, value));
53         }
54
55         public void set_visible(boolean visible) {
56                 FragmentTransaction     ft = AltosDroid.fm.beginTransaction();
57                 AltosDebug.debug("set visible %b %s\n", visible, tab_name());
58                 if (visible) {
59                         ft.show(this);
60                         show(last_telem_state, last_state, last_from_receiver, last_receiver);
61                 } else
62                         ft.hide(this);
63                 try {
64                         ft.commitAllowingStateLoss();
65                 } catch (IllegalStateException ie) {
66                 }
67         }
68
69         @Override
70         public void onAttach(Context context) {
71                 super.onAttach(context);
72                 altos_droid = (AltosDroid) context;
73                 altos_droid.registerTab(this);
74         }
75
76         @Override
77         public void onDetach() {
78                 super.onDetach();
79                 altos_droid.unregisterTab(this);
80                 altos_droid = null;
81         }
82
83         @Override
84         public void onResume() {
85                 super.onResume();
86                 AltosDebug.debug("onResume tab %s\n", tab_name());
87                 set_visible(true);
88         }
89
90         public void update_ui(TelemetryState telem_state, AltosState state,
91                               AltosGreatCircle from_receiver, Location receiver, boolean is_current)
92         {
93                 last_telem_state = telem_state;
94                 last_state = state;
95                 last_from_receiver = from_receiver;
96                 last_receiver = receiver;
97                 if (is_current)
98                         show(telem_state, state, from_receiver, receiver);
99                 else
100                         return;
101         }
102 }