1 package de
.rmdir
.ms2debounce
;
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 import android
.text
.TextWatcher
;
18 import android
.text
.Editable
;
20 public class MS2Debounce
extends Activity
22 private DebounceModuleHelper module
;
27 module
= new DebounceModuleHelper(this);
31 public void onCreate(Bundle savedInstanceState
)
33 super.onCreate(savedInstanceState
);
35 setContentView(R
.layout
.main
);
37 EditText textDelay
= (EditText
)findViewById(R
.id
.debounce_delay
);
38 textDelay
.addTextChangedListener(new TextWatcher() {
40 public void afterTextChanged(Editable delay
) {
41 if (delay
.toString().length() > 0) {
42 module
.setSavedDelay(Integer
.parseInt(delay
.toString()));
44 Button reload
= (Button
)findViewById(R
.id
.reload
);
45 if (module
.isLoaded() && module
.getSavedDelay() != module
.getDelay()) {
46 reload
.setEnabled(true);
48 reload
.setEnabled(false);
54 public void beforeTextChanged(CharSequence s
, int start
, int count
, int after
) {
58 public void onTextChanged(CharSequence s
, int start
, int before
, int count
) {
65 private void updateUI() {
68 // Calling these is expensive, so cache the result...
69 boolean loaded
= module
.isLoaded();
70 boolean safe_to_load
= module
.is_safe_to_load();
71 int debounce_delay
= module
.getDelay();
73 TextView text
= (TextView
)findViewById(R
.id
.text
);
74 text
.setText("Current status:\n\nModule loaded: " + loaded
+ "\ndebounce_delay: " + debounce_delay
+ "ms\nsafe_to_load: " + safe_to_load
);
76 EditText textDelay
= (EditText
)findViewById(R
.id
.debounce_delay
);
77 textDelay
.setText(Integer
.toString(module
.getSavedDelay()));
78 textDelay
.setEnabled(true);
80 Button reload
= (Button
)findViewById(R
.id
.reload
);
81 if (loaded
&& module
.getSavedDelay() != debounce_delay
) {
82 reload
.setEnabled(true);
84 reload
.setEnabled(false);
87 Button load
= (Button
)findViewById(R
.id
.load
);
89 load
.setEnabled(false);
91 load
.setEnabled(true);
94 Button unload
= (Button
)findViewById(R
.id
.unload
);
96 unload
.setEnabled(true);
98 unload
.setEnabled(false);
101 CheckBox on_boot
= (CheckBox
)findViewById(R
.id
.on_boot
);
102 on_boot
.setChecked(module
.get_on_boot());
104 on_boot
.setEnabled(true);
106 on_boot
.setEnabled(false);
110 private void disableUI() {
111 EditText textDelay
= (EditText
)findViewById(R
.id
.debounce_delay
);
112 textDelay
.setEnabled(false);
114 Button reload
= (Button
)findViewById(R
.id
.reload
);
115 reload
.setEnabled(false);
117 Button load
= (Button
)findViewById(R
.id
.load
);
118 load
.setEnabled(false);
120 Button unload
= (Button
)findViewById(R
.id
.unload
);
121 unload
.setEnabled(false);
123 CheckBox on_boot
= (CheckBox
)findViewById(R
.id
.on_boot
);
124 on_boot
.setEnabled(false);
127 public void loadModule(View view
) {
129 if (!module
.isLoaded()) {
135 public void unloadModule(View view
) {
137 if (module
.isLoaded()) {
138 module
.unloadModule();
143 public void reloadModule(View view
) {
145 if (module
.isLoaded()) {
146 module
.unloadModule();
148 if (!module
.isLoaded()) {
154 public void toggle_on_boot(View view
) {
155 CheckBox on_boot
= (CheckBox
)view
;
157 module
.set_on_boot(on_boot
.isChecked());
161 public boolean onCreateOptionsMenu(Menu menu
) {
162 MenuInflater inflater
= getMenuInflater();
163 inflater
.inflate(R
.menu
.main
, menu
);
168 public boolean onOptionsItemSelected(MenuItem item
) {
169 switch (item
.getItemId()) {
174 return super.onOptionsItemSelected(item
);
178 protected Dialog
onCreateDialog(int id
) {
181 AlertDialog
.Builder about
= new AlertDialog
.Builder(this);
182 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")
184 .setPositiveButton("Ok", new DialogInterface
.OnClickListener() {
185 public void onClick(DialogInterface dialog
, int id
) {
189 dlg
= about
.create();