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