From 92826c6187da05942fbdd8919df7566b8f9e5631 Mon Sep 17 00:00:00 2001 From: lcnvdl Date: Mon, 25 Aug 2014 23:10:31 -0300 Subject: [PATCH 01/21] 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 02/21] 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); From 1def3c12be33e07a19e34bfc6285e35e66ecfca8 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:14:37 +0100 Subject: [PATCH 03/21] Update plugin.xml --- plugin.xml | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/plugin.xml b/plugin.xml index 3c66828..5dcd4bc 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,32 +1,39 @@ - - + + Screen Dim - - + Cordova Screen Dim Plugin + cordova,screendim + + + + + + + + - - + + + + + - + + - + - + - + From 2e75da5fefa37ea32b82cad7b1abe1342b518804 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:16:23 +0100 Subject: [PATCH 04/21] Update ScreenDimPlugin.m --- src/ios/ScreenDimPlugin.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ios/ScreenDimPlugin.m b/src/ios/ScreenDimPlugin.m index 94bfb70..60d3226 100644 --- a/src/ios/ScreenDimPlugin.m +++ b/src/ios/ScreenDimPlugin.m @@ -13,12 +13,14 @@ @implementation ScreenDimPlugin - (void) enable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { [[UIApplication sharedApplication] setIdleTimerDisabled:NO]; + NSLog(@" ScreenDim Plugin: dim enabled"); } - (void) disable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; + NSLog(@" ScreenDim Plugin: dim disabled"); } @end From 539dc69e7938422f6121fcf3113023ded442e6eb Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:19:02 +0100 Subject: [PATCH 05/21] Update plugin.xml --- plugin.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index 5dcd4bc..14b725a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -24,8 +24,8 @@ - - + + From 3df72c17318228593491bce4ac8d009f95cf45c9 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:21:00 +0100 Subject: [PATCH 06/21] Update ScreenDimPlugin.h --- src/ios/ScreenDimPlugin.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ios/ScreenDimPlugin.h b/src/ios/ScreenDimPlugin.h index 432a05c..02a98d7 100644 --- a/src/ios/ScreenDimPlugin.h +++ b/src/ios/ScreenDimPlugin.h @@ -7,11 +7,7 @@ // #import -#ifdef CORDOVA_FRAMEWORK #import -#else -#import "CDVPlugin.h" -#endif @interface ScreenDimPlugin : CDVPlugin From 77be74737a601fa467bfeb6d13efa142cad9523d Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:36:36 +0100 Subject: [PATCH 07/21] Update screendim.js --- www/screendim.js | 55 ++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/www/screendim.js b/www/screendim.js index d6acc88..a9a50ac 100644 --- a/www/screendim.js +++ b/www/screendim.js @@ -1,39 +1,24 @@ -(function (gap, w) { - // dims by default - var on = true; - - var screenDim = { }; - - if(gap) { +var exec = require("cordova/exec"); - screenDim.enable = function () { - on = true; - gap.exec(null, null, 'ScreenDim', 'enable', []); - }; +module.exports = { + on: true, + + enable: function () { + this.on = true; + exec(null, null, 'ScreenDim', 'enable', []); + }, - screenDim.disable = function () { - on = false; - gap.exec(null, null, 'ScreenDim', 'disable', []); - }; + disable: function () { + this.on = false; + exec(null, null, 'ScreenDim', 'disable', []); + }, - 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; - } + toggle: function () { + if (this.on) { + this.disable(); + } else { + this.enable(); + } + }, -}).call(this, (window.cordova || window.Cordova), window); +}; From 2bda694fc2212ab34fe0f80c6f489f81cfd11d18 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:40:38 +0100 Subject: [PATCH 08/21] Update plugin.xml --- plugin.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index 14b725a..5dcd4bc 100644 --- a/plugin.xml +++ b/plugin.xml @@ -24,8 +24,8 @@ - - + + From 02d9adcffcd5b0575027e9f46feb572d391b4689 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:43:26 +0100 Subject: [PATCH 09/21] Update ScreenDimPlugin.h --- src/ios/ScreenDimPlugin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/ScreenDimPlugin.h b/src/ios/ScreenDimPlugin.h index 02a98d7..5bb488b 100644 --- a/src/ios/ScreenDimPlugin.h +++ b/src/ios/ScreenDimPlugin.h @@ -1,5 +1,5 @@ // -// ScreenDimPlugin.h +// ScreenDim.h // ios-cordova // // Created by Andrew Lunny on 12-07-11. @@ -9,7 +9,7 @@ #import #import -@interface ScreenDimPlugin : CDVPlugin +@interface ScreenDim : CDVPlugin - (void) enable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; - (void) disable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; From ee24257676254d471e7ae47112af794500bee9ce Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:44:15 +0100 Subject: [PATCH 10/21] Create ScreenDim.h --- src/ios/ScreenDim.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/ios/ScreenDim.h diff --git a/src/ios/ScreenDim.h b/src/ios/ScreenDim.h new file mode 100644 index 0000000..587be6b --- /dev/null +++ b/src/ios/ScreenDim.h @@ -0,0 +1 @@ +x From c80b84802f7386acb61e5db29a5f55e5da14eaac Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:44:34 +0100 Subject: [PATCH 11/21] Create ScreenDim.m --- src/ios/ScreenDim.m | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/ios/ScreenDim.m diff --git a/src/ios/ScreenDim.m b/src/ios/ScreenDim.m new file mode 100644 index 0000000..975fbec --- /dev/null +++ b/src/ios/ScreenDim.m @@ -0,0 +1 @@ +y From 4ec244c471e68669b6d7107861b92599af4511f2 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:45:14 +0100 Subject: [PATCH 12/21] Update ScreenDim.h --- src/ios/ScreenDim.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ios/ScreenDim.h b/src/ios/ScreenDim.h index 587be6b..5bb488b 100644 --- a/src/ios/ScreenDim.h +++ b/src/ios/ScreenDim.h @@ -1 +1,17 @@ -x +// +// ScreenDim.h +// ios-cordova +// +// Created by Andrew Lunny on 12-07-11. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import +#import + +@interface ScreenDim : CDVPlugin + +- (void) enable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) disable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; + +@end From 75a6907b7e17b4dc96a262072ec283722885bde0 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:45:53 +0100 Subject: [PATCH 13/21] Update ScreenDim.m --- src/ios/ScreenDim.m | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ios/ScreenDim.m b/src/ios/ScreenDim.m index 975fbec..78567f8 100644 --- a/src/ios/ScreenDim.m +++ b/src/ios/ScreenDim.m @@ -1 +1,26 @@ -y +// +// ScreenDim.m +// ios-cordova +// +// Created by Andrew Lunny on 12-07-11. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "ScreenDim.h" + +@implementation ScreenDim + +- (void) enable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +{ + [[UIApplication sharedApplication] setIdleTimerDisabled:NO]; + NSLog(@" ScreenDim Plugin: dim enabled"); +} + + +- (void) disable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +{ + [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; + NSLog(@" ScreenDim Plugin: dim disabled"); +} + +@end From 792060bb7e065968298c347fb5915d943ecc770f Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:51:39 +0100 Subject: [PATCH 14/21] Update ScreenDim.h --- src/ios/ScreenDim.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/ScreenDim.h b/src/ios/ScreenDim.h index 5bb488b..3fb317a 100644 --- a/src/ios/ScreenDim.h +++ b/src/ios/ScreenDim.h @@ -11,7 +11,7 @@ @interface ScreenDim : CDVPlugin -- (void) enable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; -- (void) disable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) enable:(CDVInvokedUrlCommand *)command; +- (void) disable:(CDVInvokedUrlCommand *)command; @end From dae5d03152c611a72914aeef93cce7036c4e03b9 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 18 Nov 2014 16:52:24 +0100 Subject: [PATCH 15/21] Update ScreenDim.m --- src/ios/ScreenDim.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/ScreenDim.m b/src/ios/ScreenDim.m index 78567f8..90c2a8e 100644 --- a/src/ios/ScreenDim.m +++ b/src/ios/ScreenDim.m @@ -10,14 +10,14 @@ @implementation ScreenDim -- (void) enable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +- (void) enable:(CDVInvokedUrlCommand *)command { [[UIApplication sharedApplication] setIdleTimerDisabled:NO]; NSLog(@" ScreenDim Plugin: dim enabled"); } -- (void) disable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +- (void) disable:(CDVInvokedUrlCommand *)command { [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; NSLog(@" ScreenDim Plugin: dim disabled"); From c46778e0170f2be67a27e070da9308c17b1b805b Mon Sep 17 00:00:00 2001 From: jossemarGT Date: Thu, 4 Dec 2014 15:59:59 -0600 Subject: [PATCH 16/21] Fixing android support --- plugin.xml | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/plugin.xml b/plugin.xml index 5dcd4bc..44374f5 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,19 +1,20 @@ - - Screen Dim - Cordova Screen Dim Plugin + xmlns:android="http://schemas.android.com/apk/res/android" + id="com.phonegap.build.screendim" + version="1.0.3"> + + Screen Dim + Cordova Screen Dim Plugin cordova,screendim - - - - - - - - + + + + + + + + @@ -27,13 +28,15 @@ - + - - + + - - - - + + + + + + From 150293b9a60584b7cab4fc835e4cfde4b75497ad Mon Sep 17 00:00:00 2001 From: jossemarGT Date: Thu, 4 Dec 2014 16:10:14 -0600 Subject: [PATCH 17/21] Debuging symbols added --- plugin.xml | 23 ++++++++++------------- src/android/ScreenDim.java | 7 ++++++- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/plugin.xml b/plugin.xml index 44374f5..03122f4 100644 --- a/plugin.xml +++ b/plugin.xml @@ -16,23 +16,20 @@ - - - - - - - - - - - - + + + + + + + + + + - diff --git a/src/android/ScreenDim.java b/src/android/ScreenDim.java index 2c017ba..a802fcf 100644 --- a/src/android/ScreenDim.java +++ b/src/android/ScreenDim.java @@ -9,8 +9,11 @@ import android.app.Activity; import android.view.WindowManager; import android.view.Window; +import android.util.Log; public class ScreenDim extends CordovaPlugin { + private final String tag= "ScreenDim"; + public PluginResult execute(String action, JSONArray args, String callbackId) { if (action.equals("enable")) { enable(); @@ -22,10 +25,12 @@ public PluginResult execute(String action, JSONArray args, String callbackId) { } public void enable() { + Log.d(this.tag, "Enable screen dimmer"); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } - public void disable() { + public void disable() { + Log.d(this.tag, "Disable screen dimmer"); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } From 6dba5b56d91e5d1b62a18d61df348787c2d777b1 Mon Sep 17 00:00:00 2001 From: jossemarGT Date: Thu, 4 Dec 2014 16:19:03 -0600 Subject: [PATCH 18/21] Debuging symbols added --- src/android/ScreenDim.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/ScreenDim.java b/src/android/ScreenDim.java index a802fcf..bde4c0d 100644 --- a/src/android/ScreenDim.java +++ b/src/android/ScreenDim.java @@ -12,7 +12,7 @@ import android.util.Log; public class ScreenDim extends CordovaPlugin { - private final String tag= "ScreenDim"; + public final static String TAG = "ScreenDim"; public PluginResult execute(String action, JSONArray args, String callbackId) { if (action.equals("enable")) { @@ -25,12 +25,12 @@ public PluginResult execute(String action, JSONArray args, String callbackId) { } public void enable() { - Log.d(this.tag, "Enable screen dimmer"); + Log.d(TAG, "Enable screen dimmer"); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } public void disable() { - Log.d(this.tag, "Disable screen dimmer"); + Log.d(TAG, "Disable screen dimmer"); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } From a7d8764cbb95938d4acf7a425fae576ba7cceb15 Mon Sep 17 00:00:00 2001 From: jossemarGT Date: Thu, 4 Dec 2014 16:32:59 -0600 Subject: [PATCH 19/21] Little refactor in .java source --- src/android/ScreenDim.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/android/ScreenDim.java b/src/android/ScreenDim.java index bde4c0d..1cafd14 100644 --- a/src/android/ScreenDim.java +++ b/src/android/ScreenDim.java @@ -2,9 +2,11 @@ import org.json.JSONArray; +import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.PluginResult; -import org.apache.cordova.LOG; +import org.apache.cordova.PluginResult.Status; +import org.json.JSONArray; +import org.json.JSONException; import android.app.Activity; import android.view.WindowManager; @@ -14,14 +16,19 @@ public class ScreenDim extends CordovaPlugin { public final static String TAG = "ScreenDim"; - public PluginResult execute(String action, JSONArray args, String callbackId) { + @Override + public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) + throws JSONException { if (action.equals("enable")) { enable(); } else if (action.equals("disable")) { disable(); + } else { + // Returning false results in a "MethodNotFound" error. + return false; } - return new PluginResult(PluginResult.Status.OK); + return true; } public void enable() { From 7f8244fef2195aa5ffb40b17e652dc67322a8310 Mon Sep 17 00:00:00 2001 From: jossemarGT Date: Thu, 4 Dec 2014 16:46:53 -0600 Subject: [PATCH 20/21] Finally, android support with cordova 3.6.x and 4.1.x --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8f867d..fcbc912 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ScreenDim -> PhoneGap/Cordova plugin for enabling/disabling screen dim +Cordova/Phonegap plugin for enabling/disabling screen dim. ## Usage @@ -27,7 +27,9 @@ ## Installation -Use `pluginstall` - https://github.com/alunny/pluginstall +``` +cordova plugin add +``` ## What/Why @@ -51,3 +53,10 @@ part of your app, and enable it again once you're done. ## LICENSE MIT + +## Changelog + +1.0.3 Update for cordova >= 3.6.x (Android) +1.0.2 Update for cordova >= 3.6.x (iOS) +1.0.1 Update for cordova 3.0.x (Android/iOS) +1.0.0 Initial release (Android/iOS) From ad88aef7a2dff0675b647eefeaa0ad6a9bf4de67 Mon Sep 17 00:00:00 2001 From: "J. Jossemar Cordero R." Date: Mon, 22 Dec 2014 22:23:22 -0600 Subject: [PATCH 21/21] Typo fix --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fcbc912..4150d7f 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ MIT ## Changelog -1.0.3 Update for cordova >= 3.6.x (Android) -1.0.2 Update for cordova >= 3.6.x (iOS) -1.0.1 Update for cordova 3.0.x (Android/iOS) -1.0.0 Initial release (Android/iOS) +* 1.0.3 Update for cordova >= 3.6.x (Android) +* 1.0.2 Update for cordova >= 3.6.x (iOS) +* 1.0.1 Update for cordova 3.0.x (Android/iOS) +* 1.0.0 Initial release (Android/iOS)