Bump java library versions
[fw/altos] / altosdroid / src / 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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.AltosDroid;
19
20 import java.util.*;
21 import org.altusmetrum.AltosDroid.R;
22
23 import android.app.Activity;
24 import android.bluetooth.BluetoothAdapter;
25 import android.bluetooth.BluetoothDevice;
26 import android.content.BroadcastReceiver;
27 import android.content.Context;
28 import android.content.Intent;
29 import android.content.IntentFilter;
30 import android.os.Bundle;
31 import android.view.View;
32 import android.view.Window;
33 import android.view.View.OnClickListener;
34 import android.widget.*;
35 import android.widget.AdapterView.*;
36
37 import org.altusmetrum.altoslib_11.*;
38
39 public class IdleModeActivity extends Activity {
40         private EditText callsign;
41         private Button connect;
42         private Button disconnect;
43         private Button reboot;
44         private Button igniters;
45
46         public static final String EXTRA_IDLE_MODE = "idle_mode";
47         public static final String EXTRA_IDLE_RESULT = "idle_result";
48
49         public static final int IDLE_MODE_CONNECT = 1;
50         public static final int IDLE_MODE_REBOOT = 2;
51         public static final int IDLE_MODE_IGNITERS = 3;
52         public static final int IDLE_MODE_DISCONNECT = 4;
53
54         private void done(int type) {
55                 AltosPreferences.set_callsign(callsign());
56                 Intent intent = new Intent();
57                 intent.putExtra(EXTRA_IDLE_RESULT, type);
58                 setResult(Activity.RESULT_OK, intent);
59                 finish();
60         }
61
62         private String callsign() {
63                 return callsign.getEditableText().toString();
64         }
65
66         public void connect_idle() {
67                 done(IDLE_MODE_CONNECT);
68         }
69
70         public void disconnect_idle() {
71                 AltosDebug.debug("Disconnect idle button pressed");
72                 done(IDLE_MODE_DISCONNECT);
73         }
74
75         public void reboot_idle() {
76                 done(IDLE_MODE_REBOOT);
77         }
78
79         public void igniters_idle() {
80                 done(IDLE_MODE_IGNITERS);
81         }
82
83         @Override
84         protected void onCreate(Bundle savedInstanceState) {
85                 super.onCreate(savedInstanceState);
86
87                 // Setup the window
88                 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
89                 setContentView(R.layout.idle_mode);
90
91                 callsign = (EditText) findViewById(R.id.set_callsign);
92                 callsign.setText(new StringBuffer(AltosPreferences.callsign()));
93
94                 connect = (Button) findViewById(R.id.connect_idle);
95                 connect.setOnClickListener(new OnClickListener() {
96                                 public void onClick(View v) {
97                                         connect_idle();
98                                 }
99                         });
100                 disconnect = (Button) findViewById(R.id.disconnect_idle);
101                 disconnect.setOnClickListener(new OnClickListener() {
102                                 public void onClick(View v) {
103                                         disconnect_idle();
104                                 }
105                         });
106
107                 boolean idle_mode = getIntent().getBooleanExtra(AltosDroid.EXTRA_IDLE_MODE, false);
108
109                 if (idle_mode)
110                         connect.setVisibility(View.GONE);
111                 else
112                         disconnect.setVisibility(View.GONE);
113
114                 reboot = (Button) findViewById(R.id.reboot_idle);
115                 reboot.setOnClickListener(new OnClickListener() {
116                                 public void onClick(View v) {
117                                         reboot_idle();
118                                 }
119                         });
120                 igniters = (Button) findViewById(R.id.igniters_idle);
121                 igniters.setOnClickListener(new OnClickListener() {
122                                 public void onClick(View v) {
123                                         igniters_idle();
124                                 }
125                         });
126
127                 // Set result CANCELED incase the user backs out
128                 setResult(Activity.RESULT_CANCELED);
129         }
130 }