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;
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.*;
29 import org.altusmetrum.altoslib_13.*;
31 public class IdleModeActivity extends Activity {
32 private EditText callsign;
33 private Button connect;
34 private Button disconnect;
35 private Button reboot;
36 private Button igniters;
38 public static final String EXTRA_IDLE_MODE = "idle_mode";
39 public static final String EXTRA_IDLE_RESULT = "idle_result";
41 public static final int IDLE_MODE_CONNECT = 1;
42 public static final int IDLE_MODE_REBOOT = 2;
43 public static final int IDLE_MODE_IGNITERS = 3;
44 public static final int IDLE_MODE_DISCONNECT = 4;
46 private void done(int type) {
47 AltosPreferences.set_callsign(callsign());
48 Intent intent = new Intent();
49 intent.putExtra(EXTRA_IDLE_RESULT, type);
50 setResult(Activity.RESULT_OK, intent);
54 private String callsign() {
55 return callsign.getEditableText().toString();
58 public void connect_idle() {
59 done(IDLE_MODE_CONNECT);
62 public void disconnect_idle() {
63 AltosDebug.debug("Disconnect idle button pressed");
64 done(IDLE_MODE_DISCONNECT);
67 public void reboot_idle() {
68 done(IDLE_MODE_REBOOT);
71 public void igniters_idle() {
72 done(IDLE_MODE_IGNITERS);
76 protected void onCreate(Bundle savedInstanceState) {
77 super.onCreate(savedInstanceState);
80 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
81 setContentView(R.layout.idle_mode);
83 callsign = (EditText) findViewById(R.id.set_callsign);
84 callsign.setText(new StringBuffer(AltosPreferences.callsign()));
86 connect = (Button) findViewById(R.id.connect_idle);
87 connect.setOnClickListener(new OnClickListener() {
88 public void onClick(View v) {
92 disconnect = (Button) findViewById(R.id.disconnect_idle);
93 disconnect.setOnClickListener(new OnClickListener() {
94 public void onClick(View v) {
99 boolean idle_mode = getIntent().getBooleanExtra(AltosDroid.EXTRA_IDLE_MODE, false);
102 connect.setVisibility(View.GONE);
104 disconnect.setVisibility(View.GONE);
106 reboot = (Button) findViewById(R.id.reboot_idle);
107 reboot.setOnClickListener(new OnClickListener() {
108 public void onClick(View v) {
112 igniters = (Button) findViewById(R.id.igniters_idle);
113 igniters.setOnClickListener(new OnClickListener() {
114 public void onClick(View v) {
119 // Set result CANCELED incase the user backs out
120 setResult(Activity.RESULT_CANCELED);