2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
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.
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.
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.
18 package org.altusmetrum.AltosDroid;
21 import org.altusmetrum.AltosDroid.R;
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.*;
37 import org.altusmetrum.altoslib_11.*;
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;
46 public static final String EXTRA_IDLE_MODE = "idle_mode";
47 public static final String EXTRA_IDLE_RESULT = "idle_result";
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;
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);
62 private String callsign() {
63 return callsign.getEditableText().toString();
66 public void connect_idle() {
67 done(IDLE_MODE_CONNECT);
70 public void disconnect_idle() {
71 AltosDebug.debug("Disconnect idle button pressed");
72 done(IDLE_MODE_DISCONNECT);
75 public void reboot_idle() {
76 done(IDLE_MODE_REBOOT);
79 public void igniters_idle() {
80 done(IDLE_MODE_IGNITERS);
84 protected void onCreate(Bundle savedInstanceState) {
85 super.onCreate(savedInstanceState);
88 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
89 setContentView(R.layout.idle_mode);
91 callsign = (EditText) findViewById(R.id.set_callsign);
92 callsign.setText(new StringBuffer(AltosPreferences.callsign()));
94 connect = (Button) findViewById(R.id.connect_idle);
95 connect.setOnClickListener(new OnClickListener() {
96 public void onClick(View v) {
100 disconnect = (Button) findViewById(R.id.disconnect_idle);
101 disconnect.setOnClickListener(new OnClickListener() {
102 public void onClick(View v) {
107 boolean idle_mode = getIntent().getBooleanExtra(AltosDroid.EXTRA_IDLE_MODE, false);
110 connect.setVisibility(View.GONE);
112 disconnect.setVisibility(View.GONE);
114 reboot = (Button) findViewById(R.id.reboot_idle);
115 reboot.setOnClickListener(new OnClickListener() {
116 public void onClick(View v) {
120 igniters = (Button) findViewById(R.id.igniters_idle);
121 igniters.setOnClickListener(new OnClickListener() {
122 public void onClick(View v) {
127 // Set result CANCELED incase the user backs out
128 setResult(Activity.RESULT_CANCELED);