diff options
| author | PliablePixels <pliablepixels@gmail.com> | 2015-06-26 11:25:06 -0400 |
|---|---|---|
| committer | PliablePixels <pliablepixels@gmail.com> | 2015-06-26 11:25:06 -0400 |
| commit | 0e83a778b541591ef468d7ebda1493a000a545e5 (patch) | |
| tree | e891381b97791d98edbbd70af4963606d494e659 /plugins/nl.x-services.plugins.insomnia/src/android/nl | |
| parent | 9972b3e9171a400d7fc239385b3e1e8c3fd1b9bc (diff) | |
Added option to keep screen on when viewing footage, also cleaned up invocation of cordova plugins when in desktop - it now checks so spurious errors don't show in logs
Diffstat (limited to 'plugins/nl.x-services.plugins.insomnia/src/android/nl')
| -rw-r--r-- | plugins/nl.x-services.plugins.insomnia/src/android/nl/xservices/plugins/Insomnia.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/plugins/nl.x-services.plugins.insomnia/src/android/nl/xservices/plugins/Insomnia.java b/plugins/nl.x-services.plugins.insomnia/src/android/nl/xservices/plugins/Insomnia.java new file mode 100644 index 00000000..95094938 --- /dev/null +++ b/plugins/nl.x-services.plugins.insomnia/src/android/nl/xservices/plugins/Insomnia.java @@ -0,0 +1,47 @@ +package nl.xservices.plugins; + +import android.view.WindowManager; +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.PluginResult; +import org.json.JSONArray; +import org.json.JSONException; + +public class Insomnia extends CordovaPlugin { + + private static final String ACTION_KEEP_AWAKE = "keepAwake"; + private static final String ACTION_ALLOW_SLEEP_AGAIN = "allowSleepAgain"; + + @Override + public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { + try { + if (ACTION_KEEP_AWAKE.equals(action)) { + cordova.getActivity().runOnUiThread( + new Runnable() { + public void run() { + cordova.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + } + }); + return true; + + } else if (ACTION_ALLOW_SLEEP_AGAIN.equals(action)) { + cordova.getActivity().runOnUiThread( + new Runnable() { + public void run() { + cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + } + }); + return true; + + } else { + callbackContext.error("insomnia." + action + " is not a supported function. Did you mean '" + ACTION_KEEP_AWAKE + "'?"); + return false; + } + } catch (Exception e) { + callbackContext.error(e.getMessage()); + return false; + } + } +} |
