Initial commit
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/3920f44a Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/3920f44a Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/3920f44a Branch: refs/heads/master Commit: 3920f44a73653de3cdd0bf1b6d91da97cdaa88fe Parents: 058b400 Author: Markus Leutwyler <ml...@yahoo.com> Authored: Thu Oct 11 15:49:33 2012 +0200 Committer: Markus Leutwyler <ml...@yahoo.com> Committed: Thu Oct 11 15:49:33 2012 +0200 ---------------------------------------------------------------------- lib/scripts/bootstrap-webos.js | 1 + lib/webos/exec.js | 38 ++++++ lib/webos/platform.js | 44 ++++++ lib/webos/plugin/webos/accelerometer.js | 33 +++++ lib/webos/plugin/webos/application.js | 51 +++++++ lib/webos/plugin/webos/camera.js | 29 ++++ lib/webos/plugin/webos/compass.js | 20 +++ lib/webos/plugin/webos/device.js | 32 +++++ lib/webos/plugin/webos/file.js | 18 +++ lib/webos/plugin/webos/filereader.js | 100 ++++++++++++++ lib/webos/plugin/webos/geolocation.js | 34 +++++ lib/webos/plugin/webos/keyboard.js | 46 +++++++ lib/webos/plugin/webos/network.js | 33 +++++ lib/webos/plugin/webos/notification.js | 154 ++++++++++++++++++++++ lib/webos/plugin/webos/orientation.js | 15 ++ lib/webos/plugin/webos/requestfilesystem.js | 20 +++ lib/webos/plugin/webos/service.js | 73 ++++++++++ lib/webos/plugin/webos/window.js | 70 ++++++++++ 18 files changed, 811 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/scripts/bootstrap-webos.js ---------------------------------------------------------------------- diff --git a/lib/scripts/bootstrap-webos.js b/lib/scripts/bootstrap-webos.js new file mode 100644 index 0000000..a994abf --- /dev/null +++ b/lib/scripts/bootstrap-webos.js @@ -0,0 +1 @@ +require('cordova/channel').onNativeReady.fire(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/exec.js ---------------------------------------------------------------------- diff --git a/lib/webos/exec.js b/lib/webos/exec.js new file mode 100644 index 0000000..8c050ce --- /dev/null +++ b/lib/webos/exec.js @@ -0,0 +1,38 @@ +/** + * Execute a cordova command. It is up to the native side whether this action + * is synchronous or asynchronous. The native side can return: + * Synchronous: PluginResult object as a JSON string + * Asynchrounous: Empty string "" + * If async, the native side will cordova.callbackSuccess or cordova.callbackError, + * depending upon the result of the action. + * + * @param {Function} success The success callback + * @param {Function} fail The fail callback + * @param {String} service The name of the service to use + * @param {String} action Action to be run in cordova + * @param {String[]} [args] Zero or more arguments to pass to the method + */ + +var plugins = { + "Device": require('cordova/plugin/webos/device'), + "NetworkStatus": require('cordova/plugin/webos/network'), + "Compass": require('cordova/plugin/webos/compass'), + "Camera": require('cordova/plugin/webos/camera'), + "Accelerometer" : require('cordova/plugin/webos/accelerometer'), + "Notification" : require('cordova/plugin/webos/notification'), + /*"File" : require('cordova/plugin/webos/filereader'),*/ + "Geolocation": require('cordova/plugin/webos/geolocation') +}; + +module.exports = function(success, fail, service, action, args) { + try { + console.error("exec:call plugin:"+service+":"+action); + plugins[service][action](success, fail, args); + } + catch(e) { + console.error("missing exec: " + service + "." + action); + console.error(args); + console.error(e); + console.error(e.stack); + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/platform.js ---------------------------------------------------------------------- diff --git a/lib/webos/platform.js b/lib/webos/platform.js new file mode 100644 index 0000000..60106d1 --- /dev/null +++ b/lib/webos/platform.js @@ -0,0 +1,44 @@ +module.exports = { + id: "webos", + initialize: function() { + if (window.PalmSystem) { + window.PalmSystem.stageReady(); + } + Mojo = window.Mojo || {}; + Mojo.stageActivated = function() { + console.error("stageActivated"); + } + }, + objects: { + requestFileSystem:{ + path: 'cordova/plugin/webos/requestfilesystem' + }, + FileReader: { + path: "cordova/plugin/webos/filereader" + } + }, + merges: { + navigator: { + children: { + service: { + path: "cordova/plugin/webos/service" + }, + application: { + path: "cordova/plugin/webos/application" + }, + window: { + path: "cordova/plugin/webos/window" + }, + notification: { + path: "cordova/plugin/webos/notification" + }, + orientation: { + path: "cordova/plugin/webos/orientation" + }, + keyboard: { + path: "cordova/plugin/webos/keyboard" + } + } + } + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/accelerometer.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/accelerometer.js b/lib/webos/plugin/webos/accelerometer.js new file mode 100644 index 0000000..b11e0e8 --- /dev/null +++ b/lib/webos/plugin/webos/accelerometer.js @@ -0,0 +1,33 @@ +var callback; +module.exports={ + +/* + * Tells WebOS to put higher priority on accelerometer resolution. Also relaxes the internal garbage collection events. + * @param {Boolean} state + * Dependencies: Mojo.windowProperties + * Example: + * navigator.accelerometer.setFastAccelerometer(true) + */ +setFastAccelerometer: function(state) { + navigator.windowProperties.fastAccelerometer = state; + navigator.window.setWindowProperties(); +}, + +/* + * Starts the native acceleration listener. + */ +start: function(win,fail,args) { + console.error("webos plugin accelerometer start"); + window.removeEventListener("acceleration", callback); + callback=function(event) { + var accel = new Acceleration(event.accelX*-9.81, event.accelY*-9.81, event.accelZ*-9.81); + win(accel); + } + document.addEventListener("acceleration", callback); +}, +stop: function (win,fail,args) { + console.error("webos plugin accelerometer stop"); + window.removeEventListener("acceleration", callback); +} + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/application.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/application.js b/lib/webos/plugin/webos/application.js new file mode 100644 index 0000000..e3d65c4 --- /dev/null +++ b/lib/webos/plugin/webos/application.js @@ -0,0 +1,51 @@ +module.exports={ + +isActivated: function(inWindow) { + inWindow = inWindow || window; + if(inWindow.PalmSystem) { + return inWindow.PalmSystem.isActivated + } + return false; +}, + +/* + * Tell webOS to activate the current page of your app, bringing it into focus. + * Example: + * navigator.application.activate(); + */ +activate: function(inWindow) { + inWindow = inWindow || window; + if(inWindow.PalmSystem) { + inWindow.PalmSystem.activate(); + } +}, + +/* + * Tell webOS to deactivate your app. + * Example: + * navigator.application.deactivate(); + */ +deactivate: function(inWindow) { + inWindow = inWindow || window; + if(inWindow.PalmSystem) { + inWindow.PalmSystem.deactivate(); + } +}, + +/* + * Returns the identifier of the current running application (e.g. com.yourdomain.yourapp). + * Example: + * navigator.application.getIdentifier(); + */ +getIdentifier: function() { + return PalmSystem.identifier; +}, + +fetchAppId: function() { + if (window.PalmSystem) { + // PalmSystem.identifier: <appid> <processid> + return PalmSystem.identifier.split(" ")[0]; + } +} + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/camera.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/camera.js b/lib/webos/plugin/webos/camera.js new file mode 100644 index 0000000..913b7b9 --- /dev/null +++ b/lib/webos/plugin/webos/camera.js @@ -0,0 +1,29 @@ +var service=require('cordova/plugin/webos/service'); + +module.exports = { + +takePicture: function(successCallback, errorCallback, options) { + + var filename = ""; + + if (typeof options != 'undefined' && typeof options.filename != 'undefined') { + filename = options.filename; + } + + this.service = service.Request('palm://com.palm.applicationManager', { + method: 'launch', + parameters: { + id: 'com.palm.app.camera', + params: { + appId: 'com.palm.app.camera', + name: 'capture', + sublaunch: true, + filename: filename + } + }, + onSuccess: successCallback, + onFailure: errorCallback + }); +} + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/compass.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/compass.js b/lib/webos/plugin/webos/compass.js new file mode 100644 index 0000000..0d554a9 --- /dev/null +++ b/lib/webos/plugin/webos/compass.js @@ -0,0 +1,20 @@ +var CompassHeading = require('cordova/plugin/CompassHeading'), +CompassError = require('cordova/plugin/CompassError'); + +module.exports={ + getHeading: function(win,lose) { + // only TouchPad and Pre3 have a Compass/Gyro + if (device.name!=="TouchPad" && device.name!=="Pr"+String.fromCharCode(275)+"3") { + lose({code: CompassError.COMPASS_NOT_SUPPORTED}); + } else { + console.error("webos plugin compass getheading"); + var that = this; + this.onReadingChanged = function(e) { + var heading = new CompassHeading(event.magHeading,event.trueHeading); + document.removeEventListener("compass",that.onReadingChanged); + win(heading); + } + document.addEventListener("compass", this.onReadingChanged); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/device.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/device.js b/lib/webos/plugin/webos/device.js new file mode 100644 index 0000000..722f1cf --- /dev/null +++ b/lib/webos/plugin/webos/device.js @@ -0,0 +1,32 @@ +var service=require('cordova/plugin/webos/service') + +module.exports={ + getDeviceInfo: function(success, fail, args) { + console.log("webOS Plugin: Device - getDeviceInfo"); + + this.request = service.Request('palm://com.palm.preferences/systemProperties', { + method:"Get", + parameters:{"key": "com.palm.properties.nduid" }, + onSuccess: postData + }); + + function postData(result) { + + var uuid=result["com.palm.properties.nduid"]; + + var parsedData = JSON.parse(PalmSystem.deviceInfo); + + // fixed data + var info={}; + info.cordova = "2.0.0"; + info.platform = "HP webOS"; + // variable data + info.name = parsedData.modelName; + info.version = parsedData.platformVersion; + info.uuid = uuid; + + success(info); + } + + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/file.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/file.js b/lib/webos/plugin/webos/file.js new file mode 100644 index 0000000..1f2a9b6 --- /dev/null +++ b/lib/webos/plugin/webos/file.js @@ -0,0 +1,18 @@ +/** + * Constructor. + * name {DOMString} name of the file, without path information + * fullPath {DOMString} the full path of the file, including the name + * type {DOMString} mime type + * lastModifiedDate {Date} last modified date + * size {Number} size of the file in bytes + */ + +var File = function(name, fullPath, type, lastModifiedDate, size){ + this.name = name || ''; + this.fullPath = fullPath || null; + this.type = type || null; + this.lastModifiedDate = lastModifiedDate || null; + this.size = size || 0; +}; + +module.exports = File; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/filereader.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/filereader.js b/lib/webos/plugin/webos/filereader.js new file mode 100644 index 0000000..f5aecb5 --- /dev/null +++ b/lib/webos/plugin/webos/filereader.js @@ -0,0 +1,100 @@ +var FileError = require('cordova/plugin/FileError'), + ProgressEvent = require('cordova/plugin/ProgressEvent'); + +var FileReader = function() { + this.fileName = ""; + + this.readyState = 0; // FileReader.EMPTY + + // File data + this.result = null; + + // Error + this.error = null; + + // Event handlers + this.onloadstart = null; // When the read starts. + this.onprogress = null; // While reading (and decoding) file or fileBlob data, and reporting partial file data (progess.loaded/progress.total) + this.onload = null; // When the read has successfully completed. + this.onerror = null; // When the read has failed (see errors). + this.onloadend = null; // When the request has completed (either in success or failure). + this.onabort = null; // When the read has been aborted. For instance, by invoking the abort() method. +}; + +FileReader.prototype.readAsText=function(file, encoding) { + console.error("webos plugin filereader readastext:"+file); + //Mojo has no file i/o yet, so we use an xhr. very limited + + // Already loading something + if (this.readyState == FileReader.LOADING) { + throw new FileError(FileError.INVALID_STATE_ERR); + } + + // LOADING state + this.readyState = FileReader.LOADING; + + // If loadstart callback + if (typeof this.onloadstart === "function") { + this.onloadstart(new ProgressEvent("loadstart", {target:this})); + } + + // Default encoding is UTF-8 + var enc = encoding ? encoding : "UTF-8"; + + var me = this; + + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + console.error("onreadystatechange:"+xhr.readyState+" "+xhr.status); + if (xhr.readyState == 4) { + if (xhr.status == 200 && xhr.responseText != null) { + console.error("file read completed"); + // Save result + me.result = xhr.responseText; + + // If onload callback + if (typeof me.onload === "function") { + me.onload(new ProgressEvent("load", {target:me})); + } + + // DONE state + me.readyState = FileReader.DONE; + + // If onloadend callback + if (typeof me.onloadend === "function") { + me.onloadend(new ProgressEvent("loadend", {target:me})); + } + + } else { + + // If DONE (cancelled), then don't do anything + if (me.readyState === FileReader.DONE) { + return; + } + + // DONE state + me.readyState = FileReader.DONE; + + me.result = null; + + // Save error + me.error = new FileError(FileError.NOT_FOUND_ERR); + + // If onerror callback + if (typeof me.onerror === "function") { + me.onerror(new ProgressEvent("error", {target:me})); + } + + // If onloadend callback + if (typeof me.onloadend === "function") { + me.onloadend(new ProgressEvent("loadend", {target:me})); + } + + } + } + }; + xhr.open("GET", file, true); + xhr.send(); +}; + +module.exports = FileReader; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/geolocation.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/geolocation.js b/lib/webos/plugin/webos/geolocation.js new file mode 100644 index 0000000..9973848 --- /dev/null +++ b/lib/webos/plugin/webos/geolocation.js @@ -0,0 +1,34 @@ +var service=require('cordova/plugin/webos/service'); + +module.exports = { + +getLocation: function(successCallback, errorCallback, options) { + console.error("webos plugin geolocation getlocation"); + var request=service.Request('palm://com.palm.location', { + method: "getCurrentPosition", + onSuccess: function(event) { + var alias={}; + alias.lastPosition = { + coords: { + latitude: event.latitude, + longitude: event.longitude, + altitude: (event.altitude >= 0 ? event.altitude: null), + speed: (event.velocity >= 0 ? event.velocity: null), + heading: (event.heading >= 0 ? event.heading: null), + accuracy: (event.horizAccuracy >= 0 ? event.horizAccuracy: null), + altitudeAccuracy: (event.vertAccuracy >= 0 ? event.vertAccuracy: null) + }, + timestamp: new Date().getTime() + }; + + successCallback(alias.lastPosition); + }, + onFailure: function() { + errorCallback(); + } + }); + +} + +}; + http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/keyboard.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/keyboard.js b/lib/webos/plugin/webos/keyboard.js new file mode 100644 index 0000000..4cae17f --- /dev/null +++ b/lib/webos/plugin/webos/keyboard.js @@ -0,0 +1,46 @@ +module.exports={ + +types: { + text: 0, + password: 1, + search: 2, + range: 3, + email: 4, + number: 5, + phone: 6, + url: 7, + color: 8 +}, +_isShowing:null, +_manual:null, +isManualMode:null, +isShowing: function() { + return _isShowing || false; +}, +show: function(type){ + if(isManualMode()) { + PalmSystem.keyboardShow(type || 0); + } +}, +hide: function(){ + if(isManualMode()) { + PalmSystem.keyboardHide(); + } +}, +setManualMode: function(mode){ + _manual = mode; + PalmSystem.setManualKeyboardEnabled(mode); +}, +isManualMode: function(){ + return _manual || false; +}, +forceShow: function(inType){ + this.setManualMode(true); + PalmSystem.keyboardShow(inType || 0); +}, +forceHide: function(){ + this.setManualMode(true); + PalmSystem.keyboardHide(); +} + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/network.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/network.js b/lib/webos/plugin/webos/network.js new file mode 100644 index 0000000..af71c12 --- /dev/null +++ b/lib/webos/plugin/webos/network.js @@ -0,0 +1,33 @@ +var service=require('cordova/plugin/webos/service') + +module.exports = { +/** + * Get connection info + * + * @param {Function} successCallback The function to call when the Connection data is available + * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL) + */ + getConnectionInfo: function (successCallback, errorCallback) { + // Get info + console.log("webos Plugin: NetworkStatus - getConnectionInfo"); + + this.request = service.Request('palm://com.palm.connectionmanager', { + method: 'getstatus', + parameters: {}, + onSuccess: postData, + onFailure: function() {} + }); + + function postData(result) { + console.log("result:"+JSON.stringify(result)); + + var info={}; + if (!result.isInternetConnectionAvailable) { info.type="Connection.NONE"; } + if (result.wifi.onInternet) { info.type="Connection.WIFI"; } + if (result.wan.state==="connected") { info.type="Connection.CELL_2G"; } + + successCallback(info.type); + } + + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/notification.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/notification.js b/lib/webos/plugin/webos/notification.js new file mode 100644 index 0000000..2f0a6e1 --- /dev/null +++ b/lib/webos/plugin/webos/notification.js @@ -0,0 +1,154 @@ +module.exports={ +/* + * adds a dashboard to the WebOS app + * @param {String} url + * @param {String} html + * Example: + * navigator.notification.newDashboard("dashboard.html"); + */ +newDashboard: function(url, html) { + var win = window.open(url, "_blank", "attributes={\"window\":\"dashboard\"}"); + html && win.document.write(html); + win.PalmSystem.stageReady(); +}, + +/* + * Displays a banner notification. If specified, will send your 'response' object as data via the 'palmsystem' DOM event. + * If no 'icon' filename is specified, will use a small version of your application icon. + * @param {String} message + * @param {Object} response + * @param {String} icon + * @param {String} soundClass class of the sound; supported classes are: "ringtones", "alerts", "alarm", "calendar", "notification" + * @param {String} soundFile partial or full path to the sound file + * @param {String} soundDurationMs of sound in ms + * Example: + * navigator.notification.showBanner('test message'); + */ +showBanner: function(message, response, icon, soundClass, soundFile, soundDurationMs) { + var response = response || { + banner: true + }; + PalmSystem.addBannerMessage(message, JSON.stringify(response), icon, soundClass, soundFile, soundDurationMs); +}, + +/** + * Remove a banner from the banner area. The category parameter defaults to 'banner'. Will not remove + * messages that are already displayed. + * @param {String} category + Value defined by the application and usually same one used in {@link showBanner}. + It is used if you have more than one kind of banner message. + */ +removeBannerMessage: function(category) { + var bannerKey = category || 'banner'; + var bannerId = this.banners.get(bannerKey); + if (bannerId) { + try { + PalmSystem.removeBannerMessage(bannerId); + } catch(removeBannerException) { + window.debug.error(removeBannerException.toString()); + } + } +}, + +/* + * Remove all pending banner messages from the banner area. Will not remove messages that are already displayed. + */ +clearBannerMessage: function() { + PalmSystem.clearBannerMessage(); +}, + +/* + * This function vibrates the device + * @param {number} duration The duration in ms to vibrate for. + * @param {number} intensity The intensity of the vibration + */ +vibrate_private: function(duration, intensity) { + //the intensity for palm is inverted; 0=high intensity, 100=low intensity + //this is opposite from our api, so we invert + if (isNaN(intensity) || intensity > 100 || intensity <= 0) + intensity = 0; + else + intensity = 100 - intensity; + + // if the app id does not have the namespace "com.palm.", an error will be thrown here + //this.vibhandle = new Mojo.Service.Request("palm://com.palm.vibrate", { + this.vibhandle = navigator.service.Request("palm://com.palm.vibrate", { + method: 'vibrate', + parameters: { + 'period': intensity, + 'duration': duration + } + }, + false); +}, + +vibrate: function(param) { + PalmSystem.playSoundNotification('vibrate'); +}, +/* + * Plays the specified sound + * @param {String} soundClass class of the sound; supported classes are: "ringtones", "alerts", "alarm", "calendar", "notification" + * @param {String} soundFile partial or full path to the sound file + * @param {String} soundDurationMs of sound in ms + */ +//beep: function(soundClass, soundFile, soundDurationMs) { +beep: function(param) { + //PalmSystem.playSoundNotification(soundClass, soundFile, soundDurationMs); + PalmSystem.playSoundNotification('alerts'); +}, + +getRootWindow: function() { + var w = window.opener || window.rootWindow || window.top || window; + if(!w.setTimeout) { // use this window as the root if we don't have access to the real root. + w = window; + } + return w; +}, + +open: function(inOpener, inUrl, inName, inAttributes, inWindowInfo) { + var url = inUrl; + var a = inAttributes && JSON.stringify(inAttributes); + var a = "attributes=" + a; + var i = inWindowInfo ? inWindowInfo + ", " : ""; + return inOpener.open(url, inName, i + a); +}, + +openWindow: function(inUrl, inName, inParams, inAttributes, inWindowInfo) { + //var attributes = inAttributes || {}; + //attributes.window = attributes.window || "card"; + // NOTE: make the root window open all windows. + var root = this.getRootWindow(); + w = this.open(root, inUrl, inName || "", inAttributes, inWindowInfo); + return w; + +}, + +alert: function(message,callback,title,buttonName) { + var inAttributes = {}; + //inAttributes.window = "card"; // create card + inAttributes.window = "popupalert"; // create popup + //inAttributes.window="dashboard"; // create dashboard + var html='<html><head><script>setTimeout(function(f){var el=window.document.getElementById("b1");console.error(el);el.addEventListener("click",function(f){window.close();},false);},500);</script></head><body>'+message+'<br/><button id="b1">'+buttonName+'</button></body></html>'; + var inName="PopupAlert"; + var inUrl=""; + var inParams={}; + var inHeight=120; + var w = this.openWindow(inUrl, inName, inParams, inAttributes, "height=" + (inHeight || 200)); + w.document.write(html); + w.PalmSystem.stageReady(); +}, + +/* + * displays a notification + * @param {String} message + * @param {Object} response + * @param {String} icon + */ +alert_old: function(message, callback, title, buttonName) { + var response = response || { + banner: true + }; + this.showBanner(message, response, icon); +} + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/orientation.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/orientation.js b/lib/webos/plugin/webos/orientation.js new file mode 100644 index 0000000..2c7fecb --- /dev/null +++ b/lib/webos/plugin/webos/orientation.js @@ -0,0 +1,15 @@ +module.exports={ + +setOrientation: function(orientation) { + PalmSystem.setWindowOrientation(orientation); +}, + +/* + * Returns the current window orientation + * orientation is one of 'up', 'down', 'left', 'right', or 'free' + */ +getCurrentOrientation: function() { + return PalmSystem.windowOrientation; +} + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/requestfilesystem.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/requestfilesystem.js b/lib/webos/plugin/webos/requestfilesystem.js new file mode 100644 index 0000000..daddf0a --- /dev/null +++ b/lib/webos/plugin/webos/requestfilesystem.js @@ -0,0 +1,20 @@ +var requestFileSystem=function(type,size,successCallback,errorCallback) { + console.error("requestFileSystem"); + + var theFileSystem={}; + theFileSystem.name="webOS"; + theFileSystem.root={}; + theFileSystem.root.name="Root"; + + theFileSystem.root.getFile=function(filename,options,successCallback,errorCallback) { + console.error("getFile"); + if (options.create) { errorCallback(); } + var theFile=filename; + successCallback(theFile); + } + + successCallback(theFileSystem); +}; + +module.exports = requestFileSystem; + http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/service.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/service.js b/lib/webos/plugin/webos/service.js new file mode 100644 index 0000000..e302473 --- /dev/null +++ b/lib/webos/plugin/webos/service.js @@ -0,0 +1,73 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +function Service() { + +}; + +Service.prototype.Request = function (uri, params) { + var req = new PalmServiceBridge(); + var url = uri + "/" + (params.method || ""); + req.url = url; + + this.req = req; + this.url = url; + this.params = params || {}; + + this.call(params); + + return this; +}; + +Service.prototype.call = function(params) { + var onsuccess = null; + var onfailure = null; + var oncomplete = null; + + if (typeof params.onSuccess === 'function') + onsuccess = params.onSuccess; + + if (typeof params.onFailure === 'function') + onerror = params.onFailure; + + if (typeof params.onComplete === 'function') + oncomplete = params.onComplete; + + this.req.onservicecallback = callback; + + function callback(msg) { + var response = JSON.parse(msg); + + if ((response.errorCode) && onfailure) + onfailure(response); + else if (onsuccess) + onsuccess(response); + + if (oncomplete) + oncomplete(response); + } + + this.data = (typeof params.parameters === 'object') ? JSON.stringify(params.parameters) : '{}'; + + this.req.call(this.url, this.data); +} + +module.exports=new Service(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/3920f44a/lib/webos/plugin/webos/window.js ---------------------------------------------------------------------- diff --git a/lib/webos/plugin/webos/window.js b/lib/webos/plugin/webos/window.js new file mode 100644 index 0000000..5f40ba1 --- /dev/null +++ b/lib/webos/plugin/webos/window.js @@ -0,0 +1,70 @@ +module.exports={ + +launchParams: function() { + return JSON.parse(PalmSystem.launchParams) || {}; +}, +/* + * This is a thin wrapper for 'window.open()' which optionally sets document contents to 'html', and calls 'PalmSystem.stageReady()' + * on your new card. Note that this new card will not come with your framework (if any) or anything for that matter. + * @param {String} url + * @param {String} html + * Example: + * navigator.window.newCard('about:blank', '<html><body>Hello again!</body></html>'); + */ +newCard: function(url, html) { + var win = window.open(url || ""); + if (html) + win.document.write(html); + win.PalmSystem.stageReady(); +}, + +/* + * Enable or disable full screen display (full screen removes the app menu bar and the rounded corners of the screen). + * @param {Boolean} state + * Example: + * navigator.window.setFullScreen(true); + */ +setFullScreen: function(state) { + // valid state values are: true or false + PalmSystem.enableFullScreenMode(state); +}, + +/* + * used to set the window properties of the WebOS app + * @param {Object} props + * Example: + * private method used by other member functions - ideally we shouldn't call this method + */ +setWindowProperties: function(inWindow, inProps) { + if(arguments.length==1) { + inProps = inWindow; + inWindow = window; + } + if(inWindow.PalmSystem) { + inWindow.PalmSystem.setWindowProperties(inProps); + } +}, + +/* + * Enable or disable screen timeout. When enabled, the device screen will not dim. This is useful for navigation, clocks or other "dock" apps. + * @param {Boolean} state + * Example: + * navigator.window.blockScreenTimeout(true); + */ +blockScreenTimeout: function(state) { + navigator.windowProperties.blockScreenTimeout = state; + this.setWindowProperties(); +}, + +/* + * Sets the lightbar to be a little dimmer for screen locked notifications. + * @param {Boolean} state + * Example: + * navigator.window.setSubtleLightbar(true); + */ +setSubtleLightbar: function(state) { + navigator.windowProperties.setSubtleLightbar = state; + this.setWindowProperties(); +} + +} \ No newline at end of file