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