From 92826c6187da05942fbdd8919df7566b8f9e5631 Mon Sep 17 00:00:00 2001 From: lcnvdl Date: Mon, 25 Aug 2014 23:10:31 -0300 Subject: [PATCH 1/2] Working with the lastest cordova Plugin updated to work with the last cordova --- plugin.xml | 2 +- src/android/ScreenDim.java | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/plugin.xml b/plugin.xml index 860da14..3c66828 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="com.phonegap.build.screendim" - version="1.0.0"> + version="1.0.1"> Screen Dim diff --git a/src/android/ScreenDim.java b/src/android/ScreenDim.java index 13b0bc9..2c017ba 100644 --- a/src/android/ScreenDim.java +++ b/src/android/ScreenDim.java @@ -2,15 +2,15 @@ import org.json.JSONArray; -import org.apache.cordova.api.Plugin; -import org.apache.cordova.api.PluginResult; -import org.apache.cordova.api.LOG; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.PluginResult; +import org.apache.cordova.LOG; import android.app.Activity; import android.view.WindowManager; import android.view.Window; -public class ScreenDim extends Plugin { +public class ScreenDim extends CordovaPlugin { public PluginResult execute(String action, JSONArray args, String callbackId) { if (action.equals("enable")) { enable(); @@ -22,17 +22,14 @@ public PluginResult execute(String action, JSONArray args, String callbackId) { } public void enable() { - LOG.d("CordovaLog", "Enable called"); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } - public void disable() { - LOG.d("CordovaLog", "Disable called"); + public void disable() { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } protected Window getWindow() { - Activity ctxActivity = (Activity) ctx.getContext(); - return ctxActivity.getWindow(); + return cordova.getActivity().getWindow(); } } From 48f25757376258ba809f04617ba118ab784e2c0c Mon Sep 17 00:00:00 2001 From: lcnvdl Date: Tue, 26 Aug 2014 00:03:49 -0300 Subject: [PATCH 2/2] Compatibility with "browser" platform Compatibility with "browser" platform --- www/screendim.js | 53 +++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/www/screendim.js b/www/screendim.js index 8ef0b24..d6acc88 100644 --- a/www/screendim.js +++ b/www/screendim.js @@ -1,24 +1,39 @@ -(function (gap) { +(function (gap, w) { // dims by default var on = true; + + var screenDim = { }; + + if(gap) { - gap.screenDim = { }; + screenDim.enable = function () { + on = true; + gap.exec(null, null, 'ScreenDim', 'enable', []); + }; - gap.screenDim.enable = function () { - on = true; - gap.exec(null, null, 'ScreenDim', 'enable', []); - }; + screenDim.disable = function () { + on = false; + gap.exec(null, null, 'ScreenDim', 'disable', []); + }; - gap.screenDim.disable = function () { - on = false; - gap.exec(null, null, 'ScreenDim', 'disable', []); - }; - - gap.screenDim.toggle = function () { - if (on) { - this.disable(); - } else { - this.enable(); - } - }; -}).call(this, (window.cordova || window.Cordova)); + screenDim.toggle = function () { + if (on) { + this.disable(); + } else { + this.enable(); + } + }; + + gap.screenDim = screenDim; + } + else { + screenDim.enable = function(){}; + screenDim.disable = screenDim.enable; + screenDim.toggle = screenDim.enable; + } + + if(!w.screenDim) { + w.screenDim = screenDim; + } + +}).call(this, (window.cordova || window.Cordova), window);