diff --git a/Android/PowerManagement/README.md b/Android/PowerManagement/README.md index 2e97442..1c36035 100644 --- a/Android/PowerManagement/README.md +++ b/Android/PowerManagement/README.md @@ -20,14 +20,13 @@ Copy the *PowerManagement.java* file to your *src/* directory. Edit your *AndroidManifest.xml* and add the following permission: `` -In addition you have to edit your *res/xml/plugins.xml* file to let PhoneGap know about the plugin: +In addition you have to edit your *res/xml/plugins.xml* file to let Cordova know about the plugin: `` ### iOS -Copy the *PowerManagement.h* and *PowerManagement.m* files to your project. +Copy the *PowerManagement.h* and *PowerManagement.m* files to your projects "Plugins" folder. -Add the PowerManagement plugin to the *PhoneGap.plist*: -See http://wiki.phonegap.com/w/page/41733808/PhoneGap-iOS-Plugins-Problems +Add the PowerManagement plugin to the *Cordova.plist* file (to the Plugins list). Both Key and Value are "PowerManagement". License diff --git a/iPhone/PowerManagement/LICENSE b/iOS/PowerManagement/LICENSE similarity index 100% rename from iPhone/PowerManagement/LICENSE rename to iOS/PowerManagement/LICENSE diff --git a/iPhone/PowerManagement/PowerManagement.h b/iOS/PowerManagement/PowerManagement.h similarity index 79% rename from iPhone/PowerManagement/PowerManagement.h rename to iOS/PowerManagement/PowerManagement.h index ef68ed7..6fd219d 100644 --- a/iPhone/PowerManagement/PowerManagement.h +++ b/iOS/PowerManagement/PowerManagement.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Wolfgang Koller + * Copyright (C) 2011-2012 Wolfgang Koller * * This file is part of GOFG Sports Computer - http://www.gofg.at/. * @@ -18,20 +18,19 @@ */ /** - * PhoneGap (iOS) plugin for accessing the power-management functions of the device + * Cordova (iOS) plugin for accessing the power-management functions of the device */ -#import -#import -#ifdef PHONEGAP_FRAMEWORK -#import + +#ifdef CORDOVA_FRAMEWORK +#import #else -#import "PGPlugin.h" +#import "CORDOVA/CDVPlugin.h" #endif /** * Interface which does the actual handling */ -@interface PowerManagement : PGPlugin { +@interface PowerManagement :CDVPlugin { } /** * Sets the idleTimerDisable property to true so that the idle timeout is disabled diff --git a/iPhone/PowerManagement/PowerManagement.m b/iOS/PowerManagement/PowerManagement.m similarity index 77% rename from iPhone/PowerManagement/PowerManagement.m rename to iOS/PowerManagement/PowerManagement.m index d17a846..708c8d7 100644 --- a/iPhone/PowerManagement/PowerManagement.m +++ b/iOS/PowerManagement/PowerManagement.m @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Wolfgang Koller + * Copyright (C) 2011-2012 Wolfgang Koller * * This file is part of GOFG Sports Computer - http://www.gofg.at/. * @@ -18,7 +18,7 @@ */ /** - * PhoneGap (iOS) plugin for accessing the power-management functions of the device + * Cordova (iOS) plugin for accessing the power-management functions of the device */ #import "PowerManagement.h" @@ -28,7 +28,7 @@ @implementation PowerManagement - (void) acquire:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { - PluginResult* result = nil; + CDVPluginResult* result = nil; NSString* jsString = nil; NSString* callbackId = [arguments objectAtIndex:0]; @@ -38,11 +38,11 @@ if( ![app isIdleTimerDisabled] ) { [app setIdleTimerDisabled:true]; - result = [PluginResult resultWithStatus:PGCommandStatus_OK]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; jsString = [result toSuccessCallbackString:callbackId]; } else { - result = [PluginResult resultWithStatus:PGCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer already disabled"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer already disabled"]; jsString = [result toErrorCallbackString:callbackId]; } @@ -52,7 +52,7 @@ - (void) release:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { - PluginResult* result = nil; + CDVPluginResult* result = nil; NSString* jsString = nil; NSString* callbackId = [arguments objectAtIndex:0]; @@ -62,11 +62,11 @@ if( [app isIdleTimerDisabled] ) { [app setIdleTimerDisabled:false]; - result = [PluginResult resultWithStatus:PGCommandStatus_OK]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; jsString = [result toSuccessCallbackString:callbackId]; } else { - result = [PluginResult resultWithStatus:PGCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer not disabled"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer not disabled"]; jsString = [result toErrorCallbackString:callbackId]; } diff --git a/iPhone/PowerManagement/README.md b/iOS/PowerManagement/README.md similarity index 65% rename from iPhone/PowerManagement/README.md rename to iOS/PowerManagement/README.md index 28e5df8..1c36035 100644 --- a/iPhone/PowerManagement/README.md +++ b/iOS/PowerManagement/README.md @@ -1,6 +1,6 @@ PowerManagement =============== -Plugin for PhoneGap +Plugin for Cordova (1.6+) The PowerManagement plugin offers access to the devices power-management functionality. It should be used for applications which keep running for a long time without any user interaction. @@ -14,12 +14,24 @@ Platforms --------- Currently available on: -* Android (don't forget android.permission.WAKE_LOCK in your AndroidManifest.xml) -* iOS (don't forget to add it to your PhoneGap.plist) +### Android +Copy the *PowerManagement.java* file to your *src/* directory. + +Edit your *AndroidManifest.xml* and add the following permission: +`` + +In addition you have to edit your *res/xml/plugins.xml* file to let Cordova know about the plugin: +`` + +### iOS +Copy the *PowerManagement.h* and *PowerManagement.m* files to your projects "Plugins" folder. + +Add the PowerManagement plugin to the *Cordova.plist* file (to the Plugins list). Both Key and Value are "PowerManagement". + License ======= -Copyright (C) 2011 Wolfgang Koller +Copyright (C) 2011-2012 Wolfgang Koller This file is part of GOFG Sports Computer - http://www.gofg.at/. diff --git a/iOS/PowerManagement/powermanagement.js b/iOS/PowerManagement/powermanagement.js new file mode 100644 index 0000000..e3705e5 --- /dev/null +++ b/iOS/PowerManagement/powermanagement.js @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011-2012 Wolfgang Koller + * + * This file is part of GOFG Sports Computer - http://www.gofg.at/. + * + * GOFG Sports Computer is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GOFG Sports Computer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GOFG Sports Computer. If not, see . + */ + +cordova.define("cordova/plugin/powermanagement", function(require, exports, module) { + var exec = require('cordova/exec'); + + var PowerManagement = function() {}; + + /** + * Acquire a new wake-lock (keep device awake) + * + * @param successCallback function to be called when the wake-lock was acquired successfully + * @param errorCallback function to be called when there was a problem with acquiring the wake-lock + */ + PowerManagement.prototype.acquire = function(successCallback,failureCallback) { + exec(successCallback, failureCallback, 'PowerManagement', 'acquire', []); + } + + /** + * Release the wake-lock + * + * @param successCallback function to be called when the wake-lock was released successfully + * @param errorCallback function to be called when there was a problem while releasing the wake-lock + */ + PowerManagement.prototype.release = function(successCallback,failureCallback) { + exec(successCallback, failureCallback, 'PowerManagement', 'release', []); + } + + /** + * Acquire a partial wake-lock, allowing the device to dim the screen + * + * @param successCallback function to be called when the wake-lock was acquired successfully + * @param errorCallback function to be called when there was a problem with acquiring the wake-lock + */ + PowerManagement.prototype.dim = function(successCallback,failureCallback) { + exec(successCallback, failureCallback, 'PowerManagement', 'acquire', [true]); + } + + var powermanagement = new PowerManagement(); + module.exports = powermanagement; +}); diff --git a/iPhone/PowerManagement/powermanagement.js b/iPhone/PowerManagement/powermanagement.js deleted file mode 100644 index 976ad04..0000000 --- a/iPhone/PowerManagement/powermanagement.js +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2011 Wolfgang Koller - * - * This file is part of GOFG Sports Computer - http://www.gofg.at/. - * - * GOFG Sports Computer is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GOFG Sports Computer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GOFG Sports Computer. If not, see . - */ - -if( !PhoneGap.hasResource("powermanagement") ) { - PhoneGap.addResource("powermanagement"); - - /** - * @returns instance of powermanagement - */ - function PowerManagement() { - }; - - /** - * Acquire a new wake-lock (keep device awake) - * - * @param successCallback function to be called when the wake-lock was acquired successfully - * @param errorCallback function to be called when there was a problem with acquiring the wake-lock - */ - PowerManagement.prototype.acquire = function(successCallback, errorCallback) { - PhoneGap.exec(successCallback, errorCallback, "PowerManagement", "acquire", []); - }; - - /** - * Release the wake-lock - * - * @param successCallback function to be called when the wake-lock was released successfully - * @param errorCallback function to be called when there was a problem while releasing the wake-lock - */ - PowerManagement.prototype.release = function(successCallback, errorCallback) { - PhoneGap.exec(successCallback, errorCallback, "PowerManagement", "release", []); - }; - - /** - * NOT SUPPORTED ON iOS (by design) - * - * @param successCallback function to be called when the wake-lock was acquired successfully - * @param errorCallback function to be called when there was a problem with acquiring the wake-lock - */ - PowerManagement.prototype.dim = function(successCallback, errorCallback) { - errorCallback( "Not supported" ); - }; - - /** - * Register the plugin with PhoneGap - */ - PowerManagement.install = function() { - if(!window.plugins) window.plugins = {}; - - window.plugins.PowerManagement = new PowerManagement(); - - return window.plugins.PowerManagement; - }; - - PhoneGap.addConstructor(PowerManagement.install); -}