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; either version 2 of the License, or
7 * (at your option) any later version.
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.
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.
19 package org.altusmetrum.AltosDroid;
21 import org.altusmetrum.altoslib_13.*;
22 import android.location.Location;
23 import android.app.Activity;
24 import androidx.fragment.app.Fragment;
25 import androidx.fragment.app.FragmentTransaction;
26 import android.widget.TextView;
28 public abstract class AltosDroidTab extends Fragment implements AltosUnitsListener {
29 TelemetryState last_telem_state;
30 AltosState last_state;
31 AltosGreatCircle last_from_receiver;
32 Location last_receiver;
33 AltosDroid altos_droid;
35 public abstract void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver);
37 public abstract String tab_name();
39 public void units_changed(boolean imperial_units) {
41 show(last_telem_state, last_state, last_from_receiver, last_receiver);
44 public void set_value(TextView text_view,
48 if (value == AltosLib.MISSING)
49 text_view.setText("");
51 text_view.setText(units.show(width, value));
54 public void set_visible(boolean visible) {
55 FragmentTransaction ft = AltosDroid.fm.beginTransaction();
56 AltosDebug.debug("set visible %b %s\n", visible, tab_name());
59 show(last_telem_state, last_state, last_from_receiver, last_receiver);
63 ft.commitAllowingStateLoss();
64 } catch (IllegalStateException ie) {
69 public void onAttach(Activity activity) {
70 super.onAttach(activity);
71 altos_droid = (AltosDroid) activity;
72 altos_droid.registerTab(this);
76 public void onDetach() {
78 altos_droid.unregisterTab(this);
83 public void onResume() {
85 AltosDebug.debug("onResume tab %s\n", tab_name());
89 public void update_ui(TelemetryState telem_state, AltosState state,
90 AltosGreatCircle from_receiver, Location receiver, boolean is_current)
92 last_telem_state = telem_state;
94 last_from_receiver = from_receiver;
95 last_receiver = receiver;
97 show(telem_state, state, from_receiver, receiver);