1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*
* Copyright © 2013 Mike Beattie <mike@ethernal.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
package org.altusmetrum.AltosDroid;
import org.altusmetrum.altoslib_12.*;
import android.location.Location;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentManager;
import android.location.Location;
import android.widget.TextView;
public abstract class AltosDroidTab extends Fragment implements AltosUnitsListener {
TelemetryState last_telem_state;
AltosState last_state;
AltosGreatCircle last_from_receiver;
Location last_receiver;
AltosDroid altos_droid;
public abstract void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver);
public abstract String tab_name();
public void units_changed(boolean imperial_units) {
if (!isHidden())
show(last_telem_state, last_state, last_from_receiver, last_receiver);
}
public void set_value(TextView text_view,
AltosUnits units,
int width,
double value) {
if (value == AltosLib.MISSING)
text_view.setText("");
else
text_view.setText(units.show(width, value));
}
public void set_visible(boolean visible) {
FragmentTransaction ft = AltosDroid.fm.beginTransaction();
AltosDebug.debug("set visible %b %s\n", visible, tab_name());
if (visible) {
ft.show(this);
show(last_telem_state, last_state, last_from_receiver, last_receiver);
} else
ft.hide(this);
ft.commitAllowingStateLoss();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
altos_droid = (AltosDroid) activity;
altos_droid.registerTab(this);
}
@Override
public void onDetach() {
super.onDetach();
altos_droid.unregisterTab(this);
altos_droid = null;
}
@Override
public void onResume() {
super.onResume();
AltosDebug.debug("onResume tab %s\n", tab_name());
set_visible(true);
}
public void update_ui(TelemetryState telem_state, AltosState state,
AltosGreatCircle from_receiver, Location receiver, boolean is_current)
{
last_telem_state = telem_state;
last_state = state;
last_from_receiver = from_receiver;
last_receiver = receiver;
if (is_current)
show(telem_state, state, from_receiver, receiver);
else
return;
}
}
|