OmniLib : adds OmniAction runner attibute

Change-Id: Id28508b8706faf89f10b7efe9302bf4eef8108fa
diff --git a/src/org/omnirom/omnilib/actions/OmniAction.java b/src/org/omnirom/omnilib/actions/OmniAction.java
index 9c889a4..781d751 100644
--- a/src/org/omnirom/omnilib/actions/OmniAction.java
+++ b/src/org/omnirom/omnilib/actions/OmniAction.java
@@ -20,9 +20,9 @@
 import android.content.Context;
 import android.content.Intent;
 import android.os.UserHandle;
+import android.provider.Settings;
 import android.util.AttributeSet;
 import android.util.Log;
-import android.provider.Settings;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
@@ -39,6 +39,7 @@
     public String type = null;
     public String setting = null;
     public String setting_type = null;
+    public String runner = null;
 
     private Context mContext;
 
@@ -75,11 +76,19 @@
                 case "title":
                     title = mContext.getString(attrs.getAttributeResourceValue(i, 0));
                     break;
+                case "runner":
+                    runner = attrs.getAttributeValue(i);
+                    break;
             }
         }
     }
 
     public void execute() {
+        if (runner != null) {
+            executeRunner();
+            return;
+        }
+
         if (broadcast != null) {
             executeBroadcast();
             return;
@@ -92,21 +101,19 @@
     }
 
     private void executeBroadcast() {
-        if (broadcast != null) {
-            Intent i = new Intent(broadcast);
+        Intent i = new Intent(broadcast);
 
-            if (value != null) {
-                switch (value_type) {
-                    case "boolean":
-                        i.putExtra(value_key, Boolean.parseBoolean(value));
-                        break;
-                    default:
-                        i.putExtra(value_key, value);
-                }
+        if (value != null) {
+            switch (value_type) {
+                case "boolean":
+                    i.putExtra(value_key, Boolean.parseBoolean(value));
+                    break;
+                default:
+                    i.putExtra(value_key, value);
             }
-
-            mContext.sendBroadcastAsUser(i, UserHandle.CURRENT);
         }
+
+        mContext.sendBroadcastAsUser(i, UserHandle.CURRENT);
     }
 
     private void executeSetting() {
@@ -133,4 +140,16 @@
                 break;
         }
     }
+
+    private void executeRunner() {
+        try {
+            Class mRunner = Class.forName(runner);
+            Constructor<?> constructor = mRunner.getDeclaredConstructor(new Class[]{Context.class});
+            Object object = constructor.newInstance(mContext);
+            Method run = mRunner.getDeclaredMethod("run", new Class[]{String.class});
+            run.invoke(object, value);
+        } catch (Exception e) {
+            Log.e(TAG, "Runner", e);
+        }
+    }
 }