]> cvs.zerfleddert.de Git - ms2-fixes/commitdiff
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 323709bd4c29b7ecece2328b3c6db645dcad3024..6eaa06752844de2ce9d5148a89c03d94601dfaba 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 0a764e5c559d23bc671d62729045e2b9aa86104c..6901353f9893a153268fa9b96e61908108ba54a7 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 39b4e809f4673a7ac456979ee34d6d6ccde806fe..3b4804cf67c506594010ac58aa459a99cfc1dd31 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