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