add load/unload/reload-buttons
authorMichael Gernoth <michael@gernoth.net>
Sat, 21 May 2011 11:17:00 +0000 (13:17 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sat, 21 May 2011 11:17:00 +0000 (13:17 +0200)
MS2Debounce/res/layout/main.xml
MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
MS2Debounce/src/de/rmdir/ms2debounce/MS2Debounce.java

index 323709b..6eaa067 100644 (file)
@@ -1,14 +1,44 @@
 <?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>
 
index 0a764e5..6901353 100644 (file)
@@ -19,10 +19,7 @@ public class DebounceModuleHelper
        }
 
        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) {
@@ -47,7 +44,7 @@ public class DebounceModuleHelper
                if (!isLoaded()) {
                        return;
                }
-       
+
                if (getDelay() <= 0) {
                        return;
                }
@@ -115,6 +112,20 @@ public class DebounceModuleHelper
                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);
index 39b4e80..3b4804c 100644 (file)
@@ -7,27 +7,114 @@ import android.os.Bundle;
 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
Impressum, Datenschutz