<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
+<Button
+ android:id="@+id/reload"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="10dip"
+ android:layout_alignParentLeft="true"
+ android:onClick="reloadModule"
+ android:text="Reload" />
+<Button
+ android:id="@+id/load"
+ android:layout_below="@id/reload"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:onClick="loadModule"
+ android:text="Load" />
+<Button
+ android:id="@+id/unload"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toRightOf="@id/load"
+ android:layout_alignTop="@id/load"
+ android:onClick="unloadModule"
+ android:text="Unload" />
+<CheckBox
+ android:id="@+id/on_boot"
+ android:layout_below="@id/load"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="Load module on boot" />
<TextView
android:id="@+id/text"
+ android:layout_below="@id/on_boot"
android:layout_width="fill_parent"
- android:layout_height="wrap_content"
+ android:layout_height="fill_parent"
android:text=""
/>
-</LinearLayout>
+</RelativeLayout>
}
public void loadModule() {
- SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
-
- int delay = settings.getInt("debounce_delay", 10);
- loadModule(delay);
+ loadModule(getSavedDelay());
}
public synchronized void loadModule(int delay) {
if (!isLoaded()) {
return;
}
-
+
if (getDelay() <= 0) {
return;
}
loadModule(delay);
}
+ public synchronized int getSavedDelay() {
+ SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
+
+ return settings.getInt("debounce_delay", 10);
+ }
+
+ public synchronized void setSavedDelay(int delay) {
+ SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
+ SharedPreferences.Editor editor = settings.edit();
+
+ editor.putInt("debounce_delay", delay);
+ editor.commit();
+ }
+
public synchronized boolean is_safe_to_load() {
SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
boolean safe_to_load = settings.getBoolean("safe_to_load", false);
import android.content.Intent;
import android.content.DialogInterface;
import android.widget.TextView;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.view.View;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MS2Debounce extends Activity
{
+ private DebounceModuleHelper module;
+
+ public MS2Debounce()
+ {
+ super();
+ module = new DebounceModuleHelper(this);
+ }
+
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
- DebounceModuleHelper module = new DebounceModuleHelper(this);
+ //if (!module.isLoaded()) {
+ // module.loadModule();
+ //}
+
+ setContentView(R.layout.main);
+ updateUI();
+ }
+
+ private void updateUI() {
+ TextView text = (TextView)findViewById(R.id.text);
+
+ disableUI();
+
+ boolean loaded = module.isLoaded();
+ boolean safe_to_load = module.is_safe_to_load();
+
+ text.setText("Current status:\n\nModule loaded: " + loaded + "\ndebounce_delay: " + module.getDelay() + "ms\nsafe_to_load: " + safe_to_load);
+
+ Button reload = (Button)findViewById(R.id.reload);
+ if (loaded) {
+ reload.setEnabled(true);
+ } else {
+ reload.setEnabled(false);
+ }
+
+ Button load = (Button)findViewById(R.id.load);
+ if (loaded) {
+ load.setEnabled(false);
+ } else {
+ load.setEnabled(true);
+ }
+
+ Button unload = (Button)findViewById(R.id.unload);
+ if (loaded) {
+ unload.setEnabled(true);
+ } else {
+ unload.setEnabled(false);
+ }
+ CheckBox on_boot = (CheckBox)findViewById(R.id.on_boot);
+ if (safe_to_load) {
+ on_boot.setEnabled(true);
+ } else {
+ on_boot.setEnabled(false);
+ }
+ }
+
+ private void disableUI() {
+ Button reload = (Button)findViewById(R.id.reload);
+ reload.setEnabled(false);
+
+ Button load = (Button)findViewById(R.id.load);
+ load.setEnabled(false);
+
+ Button unload = (Button)findViewById(R.id.unload);
+ unload.setEnabled(false);
+
+ CheckBox on_boot = (CheckBox)findViewById(R.id.on_boot);
+ on_boot.setEnabled(false);
+ }
+
+ public void loadModule(View view) {
+ disableUI();
if (!module.isLoaded()) {
module.loadModule();
}
+ updateUI();
+ }
- setContentView(R.layout.main);
+ public void unloadModule(View view) {
+ disableUI();
+ if (module.isLoaded()) {
+ module.unloadModule();
+ }
+ updateUI();
+ }
- TextView text = (TextView)findViewById(R.id.text);
- text.setText("You will soon be able to set the debounce_delay here.\nModule loaded: " + module.isLoaded() + "\ndebounce_delay: " + module.getDelay() + "ms\nsafe_to_load: " + module.is_safe_to_load());
+ public void reloadModule(View view) {
+ disableUI();
+ if (module.isLoaded()) {
+ module.unloadModule();
+ }
+ if (!module.isLoaded()) {
+ module.loadModule();
+ }
+ updateUI();
}
@Override