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_14.*;
31 public class IdleModeActivity extends Activity {
32 private EditText callsignText;
33 private TextView frequencyView;
34 private Button connect;
35 private Button disconnect;
36 private Button reboot;
37 private Button igniters;
38 private double frequency;
40 public static final String EXTRA_IDLE_MODE = "idle_mode";
41 public static final String EXTRA_IDLE_RESULT = "idle_result";
43 public static final int IDLE_MODE_CONNECT = 1;
44 public static final int IDLE_MODE_REBOOT = 2;
45 public static final int IDLE_MODE_IGNITERS = 3;
46 public static final int IDLE_MODE_DISCONNECT = 4;
48 private void done(int type) {
49 AltosPreferences.set_callsign(callsign());
50 Intent intent = new Intent();
51 intent.putExtra(EXTRA_IDLE_RESULT, type);
52 setResult(Activity.RESULT_OK, intent);
56 private String callsign() {
57 return callsignText.getEditableText().toString();
60 public void connect_idle() {
61 done(IDLE_MODE_CONNECT);
64 public void disconnect_idle() {
65 AltosDebug.debug("Disconnect idle button pressed");
66 done(IDLE_MODE_DISCONNECT);
69 public void reboot_idle() {
70 done(IDLE_MODE_REBOOT);
73 public void igniters_idle() {
74 done(IDLE_MODE_IGNITERS);
78 protected void onCreate(Bundle savedInstanceState) {
79 setTheme(AltosDroid.dialog_themes[AltosDroidPreferences.font_size()]);
80 super.onCreate(savedInstanceState);
83 setContentView(R.layout.idle_mode);
85 callsignText = (EditText) findViewById(R.id.set_callsign);
86 callsignText.setText(new StringBuffer(AltosPreferences.callsign()));
88 frequency = getIntent().getDoubleExtra(AltosDroid.EXTRA_FREQUENCY, 0.0);
89 frequencyView = (TextView) findViewById(R.id.frequency);
90 frequencyView.setText(String.format("Frequency: %7.3f MHz", frequency));
92 connect = (Button) findViewById(R.id.connect_idle);
93 connect.setOnClickListener(new OnClickListener() {
94 public void onClick(View v) {
98 disconnect = (Button) findViewById(R.id.disconnect_idle);
99 disconnect.setOnClickListener(new OnClickListener() {
100 public void onClick(View v) {
105 boolean idle_mode = getIntent().getBooleanExtra(AltosDroid.EXTRA_IDLE_MODE, false);
108 connect.setVisibility(View.GONE);
110 disconnect.setVisibility(View.GONE);
112 reboot = (Button) findViewById(R.id.reboot_idle);
113 reboot.setOnClickListener(new OnClickListener() {
114 public void onClick(View v) {
118 igniters = (Button) findViewById(R.id.igniters_idle);
119 igniters.setOnClickListener(new OnClickListener() {
120 public void onClick(View v) {
125 // Set result CANCELED incase the user backs out
126 setResult(Activity.RESULT_CANCELED);