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; either version 2 of the License, or
7 * (at your option) any later version.
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.
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.
19 package org.altusmetrum.AltosDroid;
22 import org.altusmetrum.AltosDroid.R;
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.*;
38 import org.altusmetrum.altoslib_11.*;
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;
47 public static final String EXTRA_IDLE_MODE = "idle_mode";
48 public static final String EXTRA_IDLE_RESULT = "idle_result";
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;
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);
63 private String callsign() {
64 return callsign.getEditableText().toString();
67 public void connect_idle() {
68 done(IDLE_MODE_CONNECT);
71 public void disconnect_idle() {
72 AltosDebug.debug("Disconnect idle button pressed");
73 done(IDLE_MODE_DISCONNECT);
76 public void reboot_idle() {
77 done(IDLE_MODE_REBOOT);
80 public void igniters_idle() {
81 done(IDLE_MODE_IGNITERS);
85 protected void onCreate(Bundle savedInstanceState) {
86 super.onCreate(savedInstanceState);
89 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
90 setContentView(R.layout.idle_mode);
92 callsign = (EditText) findViewById(R.id.set_callsign);
93 callsign.setText(new StringBuffer(AltosPreferences.callsign()));
95 connect = (Button) findViewById(R.id.connect_idle);
96 connect.setOnClickListener(new OnClickListener() {
97 public void onClick(View v) {
101 disconnect = (Button) findViewById(R.id.disconnect_idle);
102 disconnect.setOnClickListener(new OnClickListener() {
103 public void onClick(View v) {
108 boolean idle_mode = getIntent().getBooleanExtra(AltosDroid.EXTRA_IDLE_MODE, false);
111 connect.setVisibility(View.GONE);
113 disconnect.setVisibility(View.GONE);
115 reboot = (Button) findViewById(R.id.reboot_idle);
116 reboot.setOnClickListener(new OnClickListener() {
117 public void onClick(View v) {
121 igniters = (Button) findViewById(R.id.igniters_idle);
122 igniters.setOnClickListener(new OnClickListener() {
123 public void onClick(View v) {
128 // Set result CANCELED incase the user backs out
129 setResult(Activity.RESULT_CANCELED);