]> git.zerfleddert.de Git - ms2-fixes/blame - MS2Debounce/src/de/rmdir/ms2debounce/MS2Debounce.java
add load/unload/reload-buttons
[ms2-fixes] / MS2Debounce / src / de / rmdir / ms2debounce / MS2Debounce.java
CommitLineData
7bcde8d7
MG
1package de.rmdir.ms2debounce;
2
3import android.app.Activity;
fd8f8652
MG
4import android.app.Dialog;
5import android.app.AlertDialog;
7bcde8d7 6import android.os.Bundle;
ae569a50 7import android.content.Intent;
fd8f8652 8import android.content.DialogInterface;
ee6322a1 9import android.widget.TextView;
dea0f4b0
MG
10import android.widget.Button;
11import android.widget.CheckBox;
12import android.view.View;
fd8f8652
MG
13import android.view.Menu;
14import android.view.MenuInflater;
15import android.view.MenuItem;
7bcde8d7
MG
16
17public class MS2Debounce extends Activity
18{
dea0f4b0
MG
19 private DebounceModuleHelper module;
20
21 public MS2Debounce()
22 {
23 super();
24 module = new DebounceModuleHelper(this);
25 }
26
226a7d4d
MG
27 @Override
28 public void onCreate(Bundle savedInstanceState)
29 {
30 super.onCreate(savedInstanceState);
ae569a50 31
dea0f4b0
MG
32 //if (!module.isLoaded()) {
33 // module.loadModule();
34 //}
35
36 setContentView(R.layout.main);
37 updateUI();
38 }
39
40 private void updateUI() {
41 TextView text = (TextView)findViewById(R.id.text);
42
43 disableUI();
44
45 boolean loaded = module.isLoaded();
46 boolean safe_to_load = module.is_safe_to_load();
47
48 text.setText("Current status:\n\nModule loaded: " + loaded + "\ndebounce_delay: " + module.getDelay() + "ms\nsafe_to_load: " + safe_to_load);
49
50 Button reload = (Button)findViewById(R.id.reload);
51 if (loaded) {
52 reload.setEnabled(true);
53 } else {
54 reload.setEnabled(false);
55 }
56
57 Button load = (Button)findViewById(R.id.load);
58 if (loaded) {
59 load.setEnabled(false);
60 } else {
61 load.setEnabled(true);
62 }
63
64 Button unload = (Button)findViewById(R.id.unload);
65 if (loaded) {
66 unload.setEnabled(true);
67 } else {
68 unload.setEnabled(false);
69 }
226a7d4d 70
dea0f4b0
MG
71 CheckBox on_boot = (CheckBox)findViewById(R.id.on_boot);
72 if (safe_to_load) {
73 on_boot.setEnabled(true);
74 } else {
75 on_boot.setEnabled(false);
76 }
77 }
78
79 private void disableUI() {
80 Button reload = (Button)findViewById(R.id.reload);
81 reload.setEnabled(false);
82
83 Button load = (Button)findViewById(R.id.load);
84 load.setEnabled(false);
85
86 Button unload = (Button)findViewById(R.id.unload);
87 unload.setEnabled(false);
88
89 CheckBox on_boot = (CheckBox)findViewById(R.id.on_boot);
90 on_boot.setEnabled(false);
91 }
92
93 public void loadModule(View view) {
94 disableUI();
226a7d4d
MG
95 if (!module.isLoaded()) {
96 module.loadModule();
97 }
dea0f4b0
MG
98 updateUI();
99 }
ae569a50 100
dea0f4b0
MG
101 public void unloadModule(View view) {
102 disableUI();
103 if (module.isLoaded()) {
104 module.unloadModule();
105 }
106 updateUI();
107 }
ee6322a1 108
dea0f4b0
MG
109 public void reloadModule(View view) {
110 disableUI();
111 if (module.isLoaded()) {
112 module.unloadModule();
113 }
114 if (!module.isLoaded()) {
115 module.loadModule();
116 }
117 updateUI();
226a7d4d 118 }
fd8f8652
MG
119
120 @Override
121 public boolean onCreateOptionsMenu(Menu menu) {
122 MenuInflater inflater = getMenuInflater();
123 inflater.inflate(R.menu.main, menu);
124 return true;
125 }
126
127 @Override
128 public boolean onOptionsItemSelected(MenuItem item) {
129 switch (item.getItemId()) {
130 case R.id.about:
131 showDialog(42);
132 return true;
133 default:
134 return super.onOptionsItemSelected(item);
135 }
136 }
137
138 protected Dialog onCreateDialog(int id) {
139 Dialog dlg = null;
140
141 AlertDialog.Builder about = new AlertDialog.Builder(this);
142 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")
143 .setCancelable(true)
144 .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
145 public void onClick(DialogInterface dialog, int id) {
146 dialog.cancel();
147 }
148 });
149 dlg = about.create();
150
151 return dlg;
152 }
7bcde8d7 153}
Impressum, Datenschutz