altosdroid: Fix a pile of compile warnings
[fw/altos] / altosdroid / app / src / main / java / org / altusmetrum / AltosDroid / IdleModeActivity.java
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
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 android.app.Activity;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.view.View;
25 import android.view.Window;
26 import android.view.View.OnClickListener;
27 import android.widget.*;
28
29 import org.altusmetrum.altoslib_13.*;
30
31 public class IdleModeActivity extends Activity {
32         private EditText callsign;
33         private Button connect;
34         private Button disconnect;
35         private Button reboot;
36         private Button igniters;
37
38         public static final String EXTRA_IDLE_MODE = "idle_mode";
39         public static final String EXTRA_IDLE_RESULT = "idle_result";
40
41         public static final int IDLE_MODE_CONNECT = 1;
42         public static final int IDLE_MODE_REBOOT = 2;
43         public static final int IDLE_MODE_IGNITERS = 3;
44         public static final int IDLE_MODE_DISCONNECT = 4;
45
46         private void done(int type) {
47                 AltosPreferences.set_callsign(callsign());
48                 Intent intent = new Intent();
49                 intent.putExtra(EXTRA_IDLE_RESULT, type);
50                 setResult(Activity.RESULT_OK, intent);
51                 finish();
52         }
53
54         private String callsign() {
55                 return callsign.getEditableText().toString();
56         }
57
58         public void connect_idle() {
59                 done(IDLE_MODE_CONNECT);
60         }
61
62         public void disconnect_idle() {
63                 AltosDebug.debug("Disconnect idle button pressed");
64                 done(IDLE_MODE_DISCONNECT);
65         }
66
67         public void reboot_idle() {
68                 done(IDLE_MODE_REBOOT);
69         }
70
71         public void igniters_idle() {
72                 done(IDLE_MODE_IGNITERS);
73         }
74
75         @Override
76         protected void onCreate(Bundle savedInstanceState) {
77                 setTheme(AltosDroid.dialog_themes[AltosDroidPreferences.font_size()]);
78                 super.onCreate(savedInstanceState);
79
80                 // Setup the window
81                 setContentView(R.layout.idle_mode);
82
83                 callsign = (EditText) findViewById(R.id.set_callsign);
84                 callsign.setText(new StringBuffer(AltosPreferences.callsign()));
85
86                 connect = (Button) findViewById(R.id.connect_idle);
87                 connect.setOnClickListener(new OnClickListener() {
88                                 public void onClick(View v) {
89                                         connect_idle();
90                                 }
91                         });
92                 disconnect = (Button) findViewById(R.id.disconnect_idle);
93                 disconnect.setOnClickListener(new OnClickListener() {
94                                 public void onClick(View v) {
95                                         disconnect_idle();
96                                 }
97                         });
98
99                 boolean idle_mode = getIntent().getBooleanExtra(AltosDroid.EXTRA_IDLE_MODE, false);
100
101                 if (idle_mode)
102                         connect.setVisibility(View.GONE);
103                 else
104                         disconnect.setVisibility(View.GONE);
105
106                 reboot = (Button) findViewById(R.id.reboot_idle);
107                 reboot.setOnClickListener(new OnClickListener() {
108                                 public void onClick(View v) {
109                                         reboot_idle();
110                                 }
111                         });
112                 igniters = (Button) findViewById(R.id.igniters_idle);
113                 igniters.setOnClickListener(new OnClickListener() {
114                                 public void onClick(View v) {
115                                         igniters_idle();
116                                 }
117                         });
118
119                 // Set result CANCELED incase the user backs out
120                 setResult(Activity.RESULT_CANCELED);
121         }
122 }