abdabfcbae72bdca610807938dd1abb611e7e8c3
[ms2-fixes] / MS2Debounce / src / de / rmdir / ms2debounce / MS2Debounce.java
1 package de.rmdir.ms2debounce;
2
3 import android.app.Activity;
4 import android.app.Dialog;
5 import android.app.AlertDialog;
6 import android.os.Bundle;
7 import android.content.Intent;
8 import android.content.DialogInterface;
9 import android.widget.TextView;
10 import android.widget.EditText;
11 import android.widget.Button;
12 import android.widget.CheckBox;
13 import android.view.View;
14 import android.view.Menu;
15 import android.view.MenuInflater;
16 import android.view.MenuItem;
17
18 public class MS2Debounce extends Activity
19 {
20 private DebounceModuleHelper module;
21
22 public MS2Debounce()
23 {
24 super();
25 module = new DebounceModuleHelper(this);
26 }
27
28 @Override
29 public void onCreate(Bundle savedInstanceState)
30 {
31 super.onCreate(savedInstanceState);
32
33 //if (!module.isLoaded()) {
34 // module.loadModule();
35 //}
36
37 setContentView(R.layout.main);
38 updateUI();
39 }
40
41 private void updateUI() {
42 disableUI();
43
44 boolean loaded = module.isLoaded();
45 boolean safe_to_load = module.is_safe_to_load();
46
47 TextView text = (TextView)findViewById(R.id.text);
48 text.setText("Current status:\n\nModule loaded: " + loaded + "\ndebounce_delay: " + module.getDelay() + "ms\nsafe_to_load: " + safe_to_load);
49
50 //EditText textDelay = (EditText)findViewById(R.id.debounce_delay);
51 //textDelay.setText(module.getSavedDelay());
52
53 Button reload = (Button)findViewById(R.id.reload);
54 if (loaded) {
55 reload.setEnabled(true);
56 } else {
57 reload.setEnabled(false);
58 }
59
60 Button load = (Button)findViewById(R.id.load);
61 if (loaded) {
62 load.setEnabled(false);
63 } else {
64 load.setEnabled(true);
65 }
66
67 Button unload = (Button)findViewById(R.id.unload);
68 if (loaded) {
69 unload.setEnabled(true);
70 } else {
71 unload.setEnabled(false);
72 }
73
74 CheckBox on_boot = (CheckBox)findViewById(R.id.on_boot);
75 on_boot.setChecked(module.get_on_boot());
76 if (safe_to_load) {
77 on_boot.setEnabled(true);
78 } else {
79 on_boot.setEnabled(false);
80 }
81 }
82
83 private void disableUI() {
84 Button reload = (Button)findViewById(R.id.reload);
85 reload.setEnabled(false);
86
87 Button load = (Button)findViewById(R.id.load);
88 load.setEnabled(false);
89
90 Button unload = (Button)findViewById(R.id.unload);
91 unload.setEnabled(false);
92
93 CheckBox on_boot = (CheckBox)findViewById(R.id.on_boot);
94 on_boot.setEnabled(false);
95 }
96
97 public void loadModule(View view) {
98 disableUI();
99 if (!module.isLoaded()) {
100 module.loadModule();
101 }
102 updateUI();
103 }
104
105 public void unloadModule(View view) {
106 disableUI();
107 if (module.isLoaded()) {
108 module.unloadModule();
109 }
110 updateUI();
111 }
112
113 public void reloadModule(View view) {
114 disableUI();
115 if (module.isLoaded()) {
116 module.unloadModule();
117 }
118 if (!module.isLoaded()) {
119 module.loadModule();
120 }
121 updateUI();
122 }
123
124 public void toggle_on_boot(View view) {
125 CheckBox on_boot = (CheckBox)view;
126
127 module.set_on_boot(on_boot.isChecked());
128 }
129
130 @Override
131 public boolean onCreateOptionsMenu(Menu menu) {
132 MenuInflater inflater = getMenuInflater();
133 inflater.inflate(R.menu.main, menu);
134 return true;
135 }
136
137 @Override
138 public boolean onOptionsItemSelected(MenuItem item) {
139 switch (item.getItemId()) {
140 case R.id.about:
141 showDialog(42);
142 return true;
143 default:
144 return super.onOptionsItemSelected(item);
145 }
146 }
147
148 protected Dialog onCreateDialog(int id) {
149 Dialog dlg = null;
150
151 AlertDialog.Builder about = new AlertDialog.Builder(this);
152 about.setMessage("Milestone 2 Debounce\n\n(C) 2011 Michael Gernoth <michael@gernoth.net>\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA")
153 .setCancelable(true)
154 .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
155 public void onClick(DialogInterface dialog, int id) {
156 dialog.cancel();
157 }
158 });
159 dlg = about.create();
160
161 return dlg;
162 }
163 }
Impressum, Datenschutz