]> git.zerfleddert.de Git - ms2-fixes/blob - MS2Debounce/src/de/rmdir/ms2debounce/MS2Debounce.java
3b4804cf67c506594010ac58aa459a99cfc1dd31
[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.Button;
11 import android.widget.CheckBox;
12 import android.view.View;
13 import android.view.Menu;
14 import android.view.MenuInflater;
15 import android.view.MenuItem;
16
17 public class MS2Debounce extends Activity
18 {
19 private DebounceModuleHelper module;
20
21 public MS2Debounce()
22 {
23 super();
24 module = new DebounceModuleHelper(this);
25 }
26
27 @Override
28 public void onCreate(Bundle savedInstanceState)
29 {
30 super.onCreate(savedInstanceState);
31
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 }
70
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();
95 if (!module.isLoaded()) {
96 module.loadModule();
97 }
98 updateUI();
99 }
100
101 public void unloadModule(View view) {
102 disableUI();
103 if (module.isLoaded()) {
104 module.unloadModule();
105 }
106 updateUI();
107 }
108
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();
118 }
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 }
153 }
Impressum, Datenschutz