merging in gord changes on playbook
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/ce4a05cc Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/ce4a05cc Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/ce4a05cc Branch: refs/heads/master Commit: ce4a05cc9937c8b31dee64d4bef4aa555289d6e7 Parents: b78cd90 Author: Tim Kim <[email protected]> Authored: Thu Jun 7 13:50:31 2012 -0700 Committer: Tim Kim <[email protected]> Committed: Thu Jun 7 13:50:31 2012 -0700 ---------------------------------------------------------------------- lib/playbook/plugin/manager.js | 418 +++++++++++++++++++---------------- 1 files changed, 225 insertions(+), 193 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/ce4a05cc/lib/playbook/plugin/manager.js ---------------------------------------------------------------------- diff --git a/lib/playbook/plugin/manager.js b/lib/playbook/plugin/manager.js index 593c812..04d070d 100644 --- a/lib/playbook/plugin/manager.js +++ b/lib/playbook/plugin/manager.js @@ -11,80 +11,67 @@ var cordova = require('cordova'), return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" }; }, batteryAPI = { - execute: function (webWorksResult, action, args, win, fail) { - if (action === 'start') { - // Register one listener to each of level and state change - // events using WebWorks API. - blackberry.system.event.deviceBatteryStateChange(function(state) { - var me = navigator.battery; - // state is either CHARGING or UNPLUGGED - if (state === 2 || state === 3) { - var info = { - "level" : me._level, - "isPlugged" : state === 2 - }; - - if (me._isPlugged !== info.isPlugged && typeof win === 'function') { - win(info); - } + start: function (args, win, fail) { + // Register one listener to each of level and state change + // events using WebWorks API. + blackberry.system.event.deviceBatteryStateChange(function(state) { + var me = navigator.battery; + // state is either CHARGING or UNPLUGGED + if (state === 2 || state === 3) { + var info = { + "level" : me._level, + "isPlugged" : state === 2 + }; + + if (me._isPlugged !== info.isPlugged && typeof win === 'function') { + win(info); } - }); - blackberry.system.event.deviceBatteryLevelChange(function(level) { - var me = navigator.battery; - if (level != me._level && typeof win === 'function') { - win({'level' : level, 'isPlugged' : me._isPlugged}); - } - }); - } else if (action === 'stop') { - // Unregister battery listeners. - blackberry.system.event.deviceBatteryStateChange(null); - blackberry.system.event.deviceBatteryLevelChange(null); - } else { - return retInvalidAction(); - } + } + }); + blackberry.system.event.deviceBatteryLevelChange(function(level) { + var me = navigator.battery; + if (level != me._level && typeof win === 'function') { + win({'level' : level, 'isPlugged' : me._isPlugged}); + } + }); + + return retAsyncCall(); + }, + stop: function (args, win, fail) { + // Unregister battery listeners. + blackberry.system.event.deviceBatteryStateChange(null); + blackberry.system.event.deviceBatteryLevelChange(null); + return retAsyncCall(); } }, cameraAPI = { - execute: function (webWorksResult, action, args, win, fail) { - if (action === 'takePicture') { - blackberry.media.camera.takePicture(win, fail, fail); - return retAsyncCall(); - } - else { - return retInvalidAction(); - } + takePicture: function (args, win, fail) { + blackberry.media.camera.takePicture(win, fail, fail); + return retAsyncCall(); } }, deviceAPI = { - execute: function (webWorksResult, action, args, win, fail) { - if (action === 'getDeviceInfo') { - return {"status" : cordova.callbackStatus.OK, - "message" : { - "version" : blackberry.system.softwareVersion, - "name" : blackberry.system.model, - "uuid" : blackberry.identity.PIN, - "platform" : "PlayBook", - "cordova" : "1.8.0" - } - }; - } - return retInvalidAction(); + getDeviceInfo: function (args, win, fail) { + return {"status" : cordova.callbackStatus.OK, + "message" : { + "version" : blackberry.system.softwareVersion, + "name" : blackberry.system.model, + "uuid" : blackberry.identity.PIN, + "platform" : "PlayBook", + "cordova" : "1.7.0rc1" + } + }; } }, loggerAPI = { - execute: function (webWorksResult, action, args, win, fail) { - if (action === 'log') { - console.log(args); - return {"status" : cordova.callbackStatus.OK, - "message" : 'Message logged to console: ' + args}; - } - else { - return retInvalidAction(); - } + log: function (args, win, fail) { + console.log(args); + return {"status" : cordova.callbackStatus.OK, + "message" : 'Message logged to console: ' + args}; } }, mediaAPI = { - execute: function (webWorksResult, action, args, win, fail) { + startPlayingAudio: function (args, win, fail) { if (!args.length) { return {"status" : 9, "message" : "Media Object id was not sent in arguments"}; } @@ -93,150 +80,189 @@ var cordova = require('cordova'), audio = audioObjects[id], result; - switch (action) { - case 'startPlayingAudio': - if (args.length === 1) { - result = {"status" : 9, "message" : "Media source argument not found"}; + if (args.length === 1) { + return {"status" : 9, "message" : "Media source argument not found"}; + } - } + if (audio) { + audio.pause(); + audioObjects[id] = undefined; + } - if (audio) { - audio.pause(); - audioObjects[id] = undefined; - } + audio = audioObjects[id] = new Audio(args[1]); + audio.play(); - audio = audioObjects[id] = new Audio(args[1]); - audio.play(); + return {"status" : 1, "message" : "Audio play started" }; + }, + stopPlayingAudio: function (args, win, fail) { + if (!args.length) { + return {"status" : 9, "message" : "Media Object id was not sent in arguments"}; + } - result = {"status" : 1, "message" : "Audio play started" }; - break; - case 'stopPlayingAudio': - if (!audio) { - return {"status" : 2, "message" : "Audio Object has not been initialized"}; - } + var id = args[0], + audio = audioObjects[id], + result; - audio.pause(); - audioObjects[id] = undefined; + if (!audio) { + return {"status" : 2, "message" : "Audio Object has not been initialized"}; + } - result = {"status" : 1, "message" : "Audio play stopped" }; - break; - case 'seekToAudio': - if (!audio) { - result = {"status" : 2, "message" : "Audio Object has not been initialized"}; - } else if (args.length === 1) { - result = {"status" : 9, "message" : "Media seek time argument not found"}; - } else { - try { - audio.currentTime = args[1]; - } catch (e) { - console.log('Error seeking audio: ' + e); - return {"status" : 3, "message" : "Error seeking audio: " + e}; - } + audio.pause(); + audioObjects[id] = undefined; - result = {"status" : 1, "message" : "Seek to audio succeeded" }; - } - break; - case 'pausePlayingAudio': - if (!audio) { - return {"status" : 2, "message" : "Audio Object has not been initialized"}; - } + return {"status" : 1, "message" : "Audio play stopped" }; + }, + seekToAudio: function (args, win, fail) { + if (!args.length) { + return {"status" : 9, "message" : "Media Object id was not sent in arguments"}; + } - audio.pause(); + var id = args[0], + audio = audioObjects[id], + result; - result = {"status" : 1, "message" : "Audio paused" }; - break; - case 'getCurrentPositionAudio': - if (!audio) { - return {"status" : 2, "message" : "Audio Object has not been initialized"}; + if (!audio) { + result = {"status" : 2, "message" : "Audio Object has not been initialized"}; + } else if (args.length === 1) { + result = {"status" : 9, "message" : "Media seek time argument not found"}; + } else { + try { + audio.currentTime = args[1]; + } catch (e) { + console.log('Error seeking audio: ' + e); + return {"status" : 3, "message" : "Error seeking audio: " + e}; } - result = {"status" : 1, "message" : audio.currentTime }; - break; - case 'getDuration': - if (!audio) { - return {"status" : 2, "message" : "Audio Object has not been initialized"}; - } + result = {"status" : 1, "message" : "Seek to audio succeeded" }; + } - result = {"status" : 1, "message" : audio.duration }; - break; - case 'startRecordingAudio': - if (args.length <= 1) { - result = {"status" : 9, "message" : "Media start recording, insufficient arguments"}; - } + return result; + }, + pausePlayingAudio: function (args, win, fail) { + if (!args.length) { + return {"status" : 9, "message" : "Media Object id was not sent in arguments"}; + } - blackberry.media.microphone.record(args[1], win, fail); - result = retAsyncCall(); - break; - case 'stopRecordingAudio': - break; - case 'release': - if (audio) { - audioObjects[id] = undefined; - audio.src = undefined; - //delete audio; - } + var id = args[0], + audio = audioObjects[id], + result; - result = {"status" : 1, "message" : "Media resources released"}; - break; - default: - result = retInvalidAction(); + if (!audio) { + return {"status" : 2, "message" : "Audio Object has not been initialized"}; } - return result; - } - }, - mediaCaptureAPI = { - execute: function (webWorksResult, action, args, win, fail) { - var limit = args[0], - pictureFiles = [], - captureMethod; - - function captureCB(filePath) { - var mediaFile; - - if (filePath) { - mediaFile = new MediaFile(); - mediaFile.fullPath = filePath; - pictureFiles.push(mediaFile); - } + audio.pause(); - if (limit > 0) { - limit--; - blackberry.media.camera[captureMethod](win, fail, fail); - return; - } + return {"status" : 1, "message" : "Audio paused" }; + }, + getCurrentPositionAudio: function (args, win, fail) { + if (!args.length) { + return {"status" : 9, "message" : "Media Object id was not sent in arguments"}; + } - win(pictureFiles); + var id = args[0], + audio = audioObjects[id], + result; - return retAsyncCall(); + if (!audio) { + return {"status" : 2, "message" : "Audio Object has not been initialized"}; } - switch (action) { - case 'getSupportedAudioModes': - case 'getSupportedImageModes': - case 'getSupportedVideoModes': - return {"status": cordova.callbackStatus.OK, "message": []}; - case 'captureImage': - captureMethod = "takePicture"; - captureCB(); - break; - case 'captureVideo': - captureMethod = "takeVideo"; - captureCB(); - break; - case 'captureAudio': - return {"status": cordova.callbackStatus.INVALID_ACTION, "message": "captureAudio is not currently supported"}; + return {"status" : 1, "message" : audio.currentTime }; + }, + getDuration: function (args, win, fail) { + if (!args.length) { + return {"status" : 9, "message" : "Media Object id was not sent in arguments"}; } + var id = args[0], + audio = audioObjects[id], + result; + + if (!audio) { + return {"status" : 2, "message" : "Audio Object has not been initialized"}; + } + + return {"status" : 1, "message" : audio.duration }; + }, + startRecordingAudio: function (args, win, fail) { + if (!args.length) { + return {"status" : 9, "message" : "Media Object id was not sent in arguments"}; + } + + var id = args[0], + audio = audioObjects[id], + result; + + if (args.length <= 1) { + result = {"status" : 9, "message" : "Media start recording, insufficient arguments"}; + } + + blackberry.media.microphone.record(args[1], win, fail); return retAsyncCall(); + }, + stopRecordingAudio: function (args, win, fail) { + }, + release: function (args, win, fail) { + if (!args.length) { + return {"status" : 9, "message" : "Media Object id was not sent in arguments"}; + } + + var id = args[0], + audio = audioObjects[id], + result; + + if (audio) { + audioObjects[id] = undefined; + audio.src = undefined; + //delete audio; + } + + result = {"status" : 1, "message" : "Media resources released"}; + + return result; } }, - networkAPI = { - execute: function (webWorksResult, action, args, win, fail) { - if (action !== 'getConnectionInfo') { - return retInvalidAction(); + mediaCaptureAPI = { + getSupportedAudioModes: function (args, win, fail) { + return {"status": cordova.callbackStatus.OK, "message": []}; + }, + getSupportedImageModes: function (args, win, fail) { + return {"status": cordova.callbackStatus.OK, "message": []}; + }, + getSupportedVideoModes: function (args, win, fail) { + return {"status": cordova.callbackStatus.OK, "message": []}; + }, + captureImage: function (args, win, fail) { + var limit = args[0]; + + if (limit > 0) { + blackberry.media.camera.takePicture(win, fail, fail); + } + else { + win([]); } + return retAsyncCall(); + }, + captureVideo: function (args, win, fail) { + var limit = args[0]; + + if (limit > 0) { + blackberry.media.camera.takeVideo(win, fail, fail); + } + else { + win([]); + } + + return retAsyncCall(); + }, + captureAudio: function (args, win, fail) { + return {"status": cordova.callbackStatus.INVALID_ACTION, "message": "captureAudio is not currently supported"}; + } + }, + networkAPI = { + getConnectionInfo: function (args, win, fail) { var connectionType = require("cordova/plugin/Connection").NONE, eventType = "offline", callbackID, @@ -266,29 +292,32 @@ var cordova = require('cordova'), } }, notificationAPI = { - execute: function (webWorksResult, action, args, win, fail) { + alert: function (args, win, fail) { if (args.length !== 3) { - return {"status" : 9, "message" : "Notification action - " + action + " arguments not found"}; + return {"status" : 9, "message" : "Notification action - alert arguments not found"}; + } + + //Unpack and map the args + var msg = args[0], + title = args[1], + btnLabel = args[2]; + blackberry.ui.dialog.customAskAsync.apply(this, [ msg, [ btnLabel ], win, { "title" : title } ]); + return retAsyncCall(); + }, + confirm: function (args, win, fail) { + if (args.length !== 3) { + return {"status" : 9, "message" : "Notification action - confirm arguments not found"}; } //Unpack and map the args var msg = args[0], title = args[1], btnLabel = args[2], - btnLabels; - - switch (action) { - case 'alert': - blackberry.ui.dialog.customAskAsync.apply(this, [ msg, [ btnLabel ], win, { "title" : title } ]); - return retAsyncCall(); - case 'confirm': btnLabels = btnLabel.split(","); - blackberry.ui.dialog.customAskAsync.apply(this, [msg, btnLabels, win, {"title" : title} ]); - return retAsyncCall(); - } - return retInvalidAction(); + blackberry.ui.dialog.customAskAsync.apply(this, [msg, btnLabels, win, {"title" : title} ]); + return retAsyncCall(); } }, plugins = { @@ -306,10 +335,13 @@ module.exports = { exec: function (win, fail, clazz, action, args) { var result = {"status" : cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION, "message" : "Class " + clazz + " cannot be found"}; - //We got a sync result or a not found from WW that we can pass on to get a native mixin - //For async calls there's nothing to do if (plugins[clazz]) { - result = plugins[clazz].execute(result.message, action, args, win, fail); + if (plugins[clazz][action]) { + result = plugins[clazz][action](args, win, fail); + } + else { + result = retInvalidAction(); + } } return result;
