diff --git a/README.md b/README.md index c8f867d..4150d7f 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) diff --git a/plugin.xml b/plugin.xml index 860da14..03122f4 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,32 +1,39 @@ - + - Screen Dim + Screen Dim + Cordova Screen Dim Plugin + cordova,screendim - + + + - - - + + + - - - - + + + + + + + + + + - - - - - - - + + + + + + + + diff --git a/src/android/ScreenDim.java b/src/android/ScreenDim.java index 13b0bc9..1cafd14 100644 --- a/src/android/ScreenDim.java +++ b/src/android/ScreenDim.java @@ -2,37 +2,46 @@ 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.CallbackContext; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.PluginResult.Status; +import org.json.JSONArray; +import org.json.JSONException; import android.app.Activity; import android.view.WindowManager; import android.view.Window; +import android.util.Log; + +public class ScreenDim extends CordovaPlugin { + public final static String TAG = "ScreenDim"; -public class ScreenDim extends Plugin { - 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() { - LOG.d("CordovaLog", "Enable called"); + Log.d(TAG, "Enable screen dimmer"); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } public void disable() { - LOG.d("CordovaLog", "Disable called"); + Log.d(TAG, "Disable screen dimmer"); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } protected Window getWindow() { - Activity ctxActivity = (Activity) ctx.getContext(); - return ctxActivity.getWindow(); + return cordova.getActivity().getWindow(); } } diff --git a/src/ios/ScreenDim.h b/src/ios/ScreenDim.h new file mode 100644 index 0000000..3fb317a --- /dev/null +++ b/src/ios/ScreenDim.h @@ -0,0 +1,17 @@ +// +// 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:(CDVInvokedUrlCommand *)command; +- (void) disable:(CDVInvokedUrlCommand *)command; + +@end diff --git a/src/ios/ScreenDim.m b/src/ios/ScreenDim.m new file mode 100644 index 0000000..90c2a8e --- /dev/null +++ b/src/ios/ScreenDim.m @@ -0,0 +1,26 @@ +// +// 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:(CDVInvokedUrlCommand *)command +{ + [[UIApplication sharedApplication] setIdleTimerDisabled:NO]; + NSLog(@" ScreenDim Plugin: dim enabled"); +} + + +- (void) disable:(CDVInvokedUrlCommand *)command +{ + [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; + NSLog(@" ScreenDim Plugin: dim disabled"); +} + +@end diff --git a/src/ios/ScreenDimPlugin.h b/src/ios/ScreenDimPlugin.h index 432a05c..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. @@ -7,13 +7,9 @@ // #import -#ifdef CORDOVA_FRAMEWORK #import -#else -#import "CDVPlugin.h" -#endif -@interface ScreenDimPlugin : CDVPlugin +@interface ScreenDim : CDVPlugin - (void) enable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; - (void) disable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; 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 diff --git a/www/screendim.js b/www/screendim.js index 8ef0b24..a9a50ac 100644 --- a/www/screendim.js +++ b/www/screendim.js @@ -1,24 +1,24 @@ -(function (gap) { - // dims by default - var on = true; +var exec = require("cordova/exec"); - gap.screenDim = { }; +module.exports = { + on: true, + + enable: function () { + this.on = true; + exec(null, null, 'ScreenDim', 'enable', []); + }, - gap.screenDim.enable = function () { - on = true; - gap.exec(null, null, 'ScreenDim', 'enable', []); - }; + disable: function () { + this.on = false; + exec(null, null, 'ScreenDim', 'disable', []); + }, - gap.screenDim.disable = function () { - on = false; - gap.exec(null, null, 'ScreenDim', 'disable', []); - }; - - gap.screenDim.toggle = function () { - if (on) { + toggle: function () { + if (this.on) { this.disable(); } else { this.enable(); } - }; -}).call(this, (window.cordova || window.Cordova)); + }, + +};