Bump java lib versions in preparation for 1.9.2
[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_14.*;
30
31 public class IdleModeActivity extends Activity {
32         private EditText callsignText;
33         private TextView frequencyView;
34         private Button connect;
35         private Button disconnect;
36         private Button reboot;
37         private Button igniters;
38         private double frequency;
39
40         public static final String EXTRA_IDLE_MODE = "idle_mode";
41         public static final String EXTRA_IDLE_RESULT = "idle_result";
42
43         public static final int IDLE_MODE_CONNECT = 1;
44         public static final int IDLE_MODE_REBOOT = 2;
45         public static final int IDLE_MODE_IGNITERS = 3;
46         public static final int IDLE_MODE_DISCONNECT = 4;
47
48         private void done(int type) {
49                 AltosPreferences.set_callsign(callsign());
50                 Intent intent = new Intent();
51                 intent.putExtra(EXTRA_IDLE_RESULT, type);
52                 setResult(Activity.RESULT_OK, intent);
53                 finish();
54         }
55
56         private String callsign() {
57                 return callsignText.getEditableText().toString();
58         }
59
60         public void connect_idle() {
61                 done(IDLE_MODE_CONNECT);
62         }
63
64         public void disconnect_idle() {
65                 AltosDebug.debug("Disconnect idle button pressed");
66                 done(IDLE_MODE_DISCONNECT);
67         }
68
69         public void reboot_idle() {
70                 done(IDLE_MODE_REBOOT);
71         }
72
73         public void igniters_idle() {
74                 done(IDLE_MODE_IGNITERS);
75         }
76
77         @Override
78         protected void onCreate(Bundle savedInstanceState) {
79                 setTheme(AltosDroid.dialog_themes[AltosDroidPreferences.font_size()]);
80                 super.onCreate(savedInstanceState);
81
82                 // Setup the window
83                 setContentView(R.layout.idle_mode);
84
85                 callsignText = (EditText) findViewById(R.id.set_callsign);
86                 callsignText.setText(new StringBuffer(AltosPreferences.callsign()));
87
88                 frequency = getIntent().getDoubleExtra(AltosDroid.EXTRA_FREQUENCY, 0.0);
89                 frequencyView = (TextView) findViewById(R.id.frequency);
90                 frequencyView.setText(String.format("Frequency: %7.3f MHz", frequency));
91
92                 connect = (Button) findViewById(R.id.connect_idle);
93                 connect.setOnClickListener(new OnClickListener() {
94                                 public void onClick(View v) {
95                                         connect_idle();
96                                 }
97                         });
98                 disconnect = (Button) findViewById(R.id.disconnect_idle);
99                 disconnect.setOnClickListener(new OnClickListener() {
100                                 public void onClick(View v) {
101                                         disconnect_idle();
102                                 }
103                         });
104
105                 boolean idle_mode = getIntent().getBooleanExtra(AltosDroid.EXTRA_IDLE_MODE, false);
106
107                 if (idle_mode)
108                         connect.setVisibility(View.GONE);
109                 else
110                         disconnect.setVisibility(View.GONE);
111
112                 reboot = (Button) findViewById(R.id.reboot_idle);
113                 reboot.setOnClickListener(new OnClickListener() {
114                                 public void onClick(View v) {
115                                         reboot_idle();
116                                 }
117                         });
118                 igniters = (Button) findViewById(R.id.igniters_idle);
119                 igniters.setOnClickListener(new OnClickListener() {
120                                 public void onClick(View v) {
121                                         igniters_idle();
122                                 }
123                         });
124
125                 // Set result CANCELED incase the user backs out
126                 setResult(Activity.RESULT_CANCELED);
127         }
128 }