You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by gt...@apache.org on 2012/11/02 14:31:14 UTC
[4/5] Refactored BlackBerry into one javascript file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/air/FileTransfer.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/FileTransfer.js b/lib/webworks/air/plugin/air/FileTransfer.js
deleted file mode 100644
index b0fe799..0000000
--- a/lib/webworks/air/plugin/air/FileTransfer.js
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova'),
-FileTransferError = require('cordova/plugin/FileTransferError'),
-FileUploadResult = require('cordova/plugin/FileUploadResult');
-
-var validURLProtocol = new RegExp('^(https?|ftp):\/\/');
-
-function getParentPath(filePath) {
- var pos = filePath.lastIndexOf('/');
- return filePath.substring(0, pos + 1);
-}
-
-function getFileName(filePath) {
- var pos = filePath.lastIndexOf('/');
- return filePath.substring(pos + 1);
-}
-
-module.exports = {
- upload: function (args, win, fail) {
- var filePath = args[0],
- server = args[1],
- fileKey = args[2],
- fileName = args[3],
- mimeType = args[4],
- params = args[5],
- trustAllHosts = args[6],
- chunkedMode = args[7],
- headers = args[8];
-
- if(!validURLProtocol.exec(server)){
- return { "status" : cordova.callbackStatus.ERROR, "message" : new FileTransferError(FileTransferError.INVALID_URL_ERR) };
- }
-
- window.resolveLocalFileSystemURI(filePath, fileWin, fail);
-
- function fileWin(entryObject){
- blackberry.io.file.readFile(filePath, readWin, false);
- }
-
- function readWin(filePath, blobFile){
- var fd = new FormData();
-
- fd.append(fileKey, blobFile, fileName);
- for (var prop in params) {
- if(params.hasOwnProperty(prop)) {
- fd.append(prop, params[prop]);
- }
- }
-
- var xhr = new XMLHttpRequest();
- xhr.open("POST", server);
- xhr.onload = function(evt) {
- if (xhr.status == 200) {
- var result = new FileUploadResult();
- result.bytesSent = xhr.response.length;
- result.responseCode = xhr.status;
- result.response = xhr.response;
- win(result);
- } else if (xhr.status == 404) {
- fail(new FileTransferError(FileTransferError.INVALID_URL_ERR, null, null, xhr.status));
- } else if (xhr.status == 403) {
- fail(new FileTransferError(FileTransferError.INVALID_URL_ERR, null, null, xhr.status));
- } else {
- fail(new FileTransferError(FileTransferError.CONNECTION_ERR, null, null, xhr.status));
- }
- };
- xhr.ontimeout = function(evt) {
- fail(new FileTransferError(FileTransferError.CONNECTION_ERR, null, null, xhr.status));
- };
-
- if(headers){
- for(var i in headers){
- xhr.setRequestHeader(i, headers[i]);
- }
- }
- xhr.send(fd);
- }
-
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- },
-
- download: function(args, win, fail){
- var url = args[0],
- filePath = args[1];
-
- if(!validURLProtocol.exec(url)){
- return { "status" : cordova.callbackStatus.ERROR, "message" : new FileTransferError(FileTransferError.INVALID_URL_ERR) };
- }
-
- var xhr = new XMLHttpRequest();
-
- function writeFile(fileEntry) {
- fileEntry.createWriter(function(writer) {
- writer.onwriteend = function(evt) {
- if (!evt.target.error) {
- win(new window.FileEntry(fileEntry.name, fileEntry.toURL()));
- } else {
- fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
- }
- };
-
- writer.onerror = function(evt) {
- fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
- };
-
- var blob = blackberry.utils.stringToBlob(xhr.response);
- writer.write(blob);
-
- },
- function(error) {
- fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
- });
- }
-
- xhr.onreadystatechange = function () {
- if (xhr.readyState == xhr.DONE) {
- if (xhr.status == 200 && xhr.response) {
- window.resolveLocalFileSystemURI(getParentPath(filePath), function(dir) {
- dir.getFile(getFileName(filePath), {create: true}, writeFile, function(error) {
- fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
- });
- }, function(error) {
- fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
- });
- } else if (xhr.status == 404) {
- fail(new FileTransferError(FileTransferError.INVALID_URL_ERR, null, null, xhr.status));
- } else {
- fail(new FileTransferError(FileTransferError.CONNECTION_ERR, null, null, xhr.status));
- }
- }
- };
-
- xhr.open("GET", url, true);
- xhr.responseType = "arraybuffer";
- xhr.send();
-
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/air/FileWriter.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/FileWriter.js b/lib/webworks/air/plugin/air/FileWriter.js
deleted file mode 100644
index 1f68893..0000000
--- a/lib/webworks/air/plugin/air/FileWriter.js
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var FileError = require('cordova/plugin/FileError'),
- ProgressEvent = require('cordova/plugin/ProgressEvent');
-
-/**
- * @constructor
- * @param file {File} File object containing file properties
- * @param append if true write to the end of the file, otherwise overwrite the file
- */
-var FileWriter = function(file) {
- this.fileName = "";
- this.length = 0;
- if (file) {
- this.fileName = file.fullPath || file;
- this.length = file.size || 0;
- }
- // default is to write at the beginning of the file
- this.position = 0;
-
- this.readyState = 0; // EMPTY
-
- this.result = null;
-
- // Error
- this.error = null;
-
- // Event handlers
- this.onwritestart = null; // When writing starts
- this.onprogress = null; // While writing the file, and reporting partial file data
- this.onwrite = null; // When the write has successfully completed.
- this.onwriteend = null; // When the request has completed (either in success or failure).
- this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
- this.onerror = null; // When the write has failed (see errors).
-};
-
-// States
-FileWriter.INIT = 0;
-FileWriter.WRITING = 1;
-FileWriter.DONE = 2;
-
-/**
- * Abort writing file.
- */
-FileWriter.prototype.abort = function() {
- // check for invalid state
- if (this.readyState === FileWriter.DONE || this.readyState === FileWriter.INIT) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
-
- // set error
- this.error = new FileError(FileError.ABORT_ERR);
-
- this.readyState = FileWriter.DONE;
-
- // If abort callback
- if (typeof this.onabort === "function") {
- this.onabort(new ProgressEvent("abort", {"target":this}));
- }
-
- // If write end callback
- if (typeof this.onwriteend === "function") {
- this.onwriteend(new ProgressEvent("writeend", {"target":this}));
- }
-};
-
-/**
- * Writes data to the file
- *
- * @param text to be written
- */
-FileWriter.prototype.write = function(text) {
- // Throw an exception if we are already writing a file
- if (this.readyState === FileWriter.WRITING) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
-
- // WRITING state
- this.readyState = FileWriter.WRITING;
-
- var me = this;
-
- // If onwritestart callback
- if (typeof me.onwritestart === "function") {
- me.onwritestart(new ProgressEvent("writestart", {"target":me}));
- }
-
- var textBlob = blackberry.utils.stringToBlob(text);
-
- if(blackberry.io.file.exists(this.fileName)){
-
- var oldText = '';
- var newText = text;
-
- var getFileContents = function(path,blob){
-
- if(blob){
- oldText = blackberry.utils.blobToString(blob);
- if(oldText.length>0){
- newText = oldText.substr(0,me.position) + text;
- }
- }
-
- var tempFile = me.fileName+'temp';
- if(blackberry.io.file.exists(tempFile)){
- blackberry.io.file.deleteFile(tempFile);
- }
-
- var newTextBlob = blackberry.utils.stringToBlob(newText);
-
- // crete a temp file, delete file we are 'overwriting', then rename temp file
- blackberry.io.file.saveFile(tempFile, newTextBlob);
- blackberry.io.file.deleteFile(me.fileName);
- blackberry.io.file.rename(tempFile, me.fileName.split('/').pop());
-
- me.position = newText.length;
- me.length = me.position;
-
- if (typeof me.onwrite === "function") {
- me.onwrite(new ProgressEvent("write", {"target":me}));
- }
- };
-
- // setting asynch to off
- blackberry.io.file.readFile(this.fileName, getFileContents, false);
-
- }else{
-
- // file is new so just save it
- blackberry.io.file.saveFile(this.fileName, textBlob);
- me.position = text.length;
- me.length = me.position;
- }
-
- me.readyState = FileWriter.DONE;
-
- if (typeof me.onwriteend === "function") {
- me.onwriteend(new ProgressEvent("writeend", {"target":me}));
- }
-};
-
-/**
- * Moves the file pointer to the location specified.
- *
- * If the offset is a negative number the position of the file
- * pointer is rewound. If the offset is greater than the file
- * size the position is set to the end of the file.
- *
- * @param offset is the location to move the file pointer to.
- */
-FileWriter.prototype.seek = function(offset) {
- // Throw an exception if we are already writing a file
- if (this.readyState === FileWriter.WRITING) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
-
- if (!offset && offset !== 0) {
- return;
- }
-
- // See back from end of file.
- if (offset < 0) {
- this.position = Math.max(offset + this.length, 0);
- }
- // Offset is bigger than file size so set position
- // to the end of the file.
- else if (offset > this.length) {
- this.position = this.length;
- }
- // Offset is between 0 and file size so set the position
- // to start writing.
- else {
- this.position = offset;
- }
-};
-
-/**
- * Truncates the file to the size specified.
- *
- * @param size to chop the file at.
- */
-FileWriter.prototype.truncate = function(size) {
- // Throw an exception if we are already writing a file
- if (this.readyState === FileWriter.WRITING) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
-
- // WRITING state
- this.readyState = FileWriter.WRITING;
-
- var me = this;
-
- // If onwritestart callback
- if (typeof me.onwritestart === "function") {
- me.onwritestart(new ProgressEvent("writestart", {"target":this}));
- }
-
- if(blackberry.io.file.exists(this.fileName)){
-
- var oldText = '';
- var newText = '';
-
- var getFileContents = function(path,blob){
-
- if(blob){
- oldText = blackberry.utils.blobToString(blob);
- if(oldText.length>0){
- newText = oldText.slice(0,size);
- }else{
- // TODO: throw error
- }
- }
-
- var tempFile = me.fileName+'temp';
- if(blackberry.io.file.exists(tempFile)){
- blackberry.io.file.deleteFile(tempFile);
- }
-
- var newTextBlob = blackberry.utils.stringToBlob(newText);
-
- // crete a temp file, delete file we are 'overwriting', then rename temp file
- blackberry.io.file.saveFile(tempFile, newTextBlob);
- blackberry.io.file.deleteFile(me.fileName);
- blackberry.io.file.rename(tempFile, me.fileName.split('/').pop());
-
- me.position = newText.length;
- me.length = me.position;
-
- if (typeof me.onwrite === "function") {
- me.onwrite(new ProgressEvent("write", {"target":me}));
- }
- };
-
- // setting asynch to off - worry about making this all callbacks later
- blackberry.io.file.readFile(this.fileName, getFileContents, false);
-
- }else{
-
- // TODO: file doesn't exist - throw error
-
- }
-
- me.readyState = FileWriter.DONE;
-
- if (typeof me.onwriteend === "function") {
- me.onwriteend(new ProgressEvent("writeend", {"target":me}));
- }
-};
-
-module.exports = FileWriter;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/air/battery.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/battery.js b/lib/webworks/air/plugin/air/battery.js
deleted file mode 100644
index a922573..0000000
--- a/lib/webworks/air/plugin/air/battery.js
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova');
-
-module.exports = {
- start: function (args, win, fail) {
- // Register one listener to each of the 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});
- }
- });
-
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- },
- stop: function (args, win, fail) {
- // Unregister battery listeners.
- blackberry.system.event.deviceBatteryStateChange(null);
- blackberry.system.event.deviceBatteryLevelChange(null);
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/air/camera.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/camera.js b/lib/webworks/air/plugin/air/camera.js
deleted file mode 100644
index aef67f3..0000000
--- a/lib/webworks/air/plugin/air/camera.js
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova');
-
-module.exports = {
- takePicture: function (args, win, fail) {
- var onCaptured = blackberry.events.registerEventHandler("onCaptured", win),
- onCameraClosed = blackberry.events.registerEventHandler("onCameraClosed", function () {}),
- onError = blackberry.events.registerEventHandler("onError", fail),
- request = new blackberry.transport.RemoteFunctionCall('blackberry/media/camera/takePicture');
-
- request.addParam("onCaptured", onCaptured);
- request.addParam("onCameraClosed", onCameraClosed);
- request.addParam("onError", onError);
-
- //HACK: this is a sync call due to:
- //https://github.com/blackberry/WebWorks-TabletOS/issues/51
- request.makeSyncCall();
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/air/capture.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/capture.js b/lib/webworks/air/plugin/air/capture.js
deleted file mode 100644
index 0b837be..0000000
--- a/lib/webworks/air/plugin/air/capture.js
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova');
-
-function capture(action, win, fail) {
- var onCaptured = blackberry.events.registerEventHandler("onCaptured", function (path) {
- var file = blackberry.io.file.getFileProperties(path);
- win([{
- fullPath: path,
- lastModifiedDate: file.dateModified,
- name: path.replace(file.directory + "/", ""),
- size: file.size,
- type: file.fileExtension
- }]);
- }),
- onCameraClosed = blackberry.events.registerEventHandler("onCameraClosed", function () {}),
- onError = blackberry.events.registerEventHandler("onError", fail),
- request = new blackberry.transport.RemoteFunctionCall('blackberry/media/camera/' + action);
-
- request.addParam("onCaptured", onCaptured);
- request.addParam("onCameraClosed", onCameraClosed);
- request.addParam("onError", onError);
-
- //HACK: this is a sync call due to:
- //https://github.com/blackberry/WebWorks-TabletOS/issues/51
- request.makeSyncCall();
-}
-
-module.exports = {
- 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) {
- if (args[0].limit > 0) {
- capture("takePicture", win, fail);
- }
- else {
- win([]);
- }
-
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- },
- captureVideo: function (args, win, fail) {
- if (args[0].limit > 0) {
- capture("takeVideo", win, fail);
- }
- else {
- win([]);
- }
-
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- },
- captureAudio: function (args, win, fail) {
- var onCaptureAudioWin = function(filePath){
- // for some reason the filePath is coming back as a string between two double quotes
- filePath = filePath.slice(1, filePath.length-1);
- var file = blackberry.io.file.getFileProperties(filePath);
-
- win([{
- fullPath: filePath,
- lastModifiedDate: file.dateModified,
- name: filePath.replace(file.directory + "/", ""),
- size: file.size,
- type: file.fileExtension
- }]);
- };
-
- var onCaptureAudioFail = function(){
- fail([]);
- };
-
- if (args[0].limit > 0 && args[0].duration){
- // a sloppy way of creating a uuid since there's no built in date function to get milliseconds since epoch
- // might be better to instead check files within directory and then figure out the next file name should be
- // ie, img000 -> img001 though that would take awhile and would add a whole bunch of checks
- var id = new Date();
- id = (id.getDay()).toString() + (id.getHours()).toString() + (id.getSeconds()).toString() + (id.getMilliseconds()).toString() + (id.getYear()).toString();
-
- var fileName = blackberry.io.dir.appDirs.shared.music.path+'/audio'+id+'.wav';
- blackberry.media.microphone.record(fileName, onCaptureAudioWin, onCaptureAudioFail);
- // multiple duration by a 1000 since it comes in as seconds
- setTimeout(blackberry.media.microphone.stop,args[0].duration*1000);
- }
- else {
- win([]);
- }
- return {"status": cordova.callbackStatus.NO_RESULT, "message": "WebWorks Is On It"};
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/air/device.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/device.js b/lib/webworks/air/plugin/air/device.js
deleted file mode 100644
index 42003c0..0000000
--- a/lib/webworks/air/plugin/air/device.js
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var channel = require('cordova/channel'),
- cordova = require('cordova');
-
-// Tell cordova channel to wait on the CordovaInfoReady event
-channel.waitForInitialization('onCordovaInfoReady');
-
-module.exports = {
- getDeviceInfo : function(args, win, fail){
- win({
- platform: "PlayBook",
- version: blackberry.system.softwareVersion,
- name: blackberry.system.model,
- uuid: blackberry.identity.PIN,
- cordova: "2.2.0"
- });
-
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "Device info returned" };
- }
-
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/air/network.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/network.js b/lib/webworks/air/plugin/air/network.js
deleted file mode 100644
index 85e671e..0000000
--- a/lib/webworks/air/plugin/air/network.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova'),
- connection = require('cordova/plugin/Connection');
-
-module.exports = {
- getConnectionInfo: function (args, win, fail) {
- var connectionType = connection.NONE,
- eventType = "offline",
- callbackID,
- request;
-
- /**
- * For PlayBooks, we currently only have WiFi connections, so
- * return WiFi if there is any access at all.
- * TODO: update if/when PlayBook gets other connection types...
- */
- if (blackberry.system.hasDataCoverage()) {
- connectionType = connection.WIFI;
- eventType = "online";
- }
-
- //Register an event handler for the networkChange event
- callbackID = blackberry.events.registerEventHandler("networkChange", function (status) {
- win(status.type);
- });
-
- //pass our callback id down to our network extension
- request = new blackberry.transport.RemoteFunctionCall("org/apache/cordova/getConnectionInfo");
- request.addParam("networkStatusChangedID", callbackID);
- request.makeSyncCall();
-
- return { "status": cordova.callbackStatus.OK, "message": connectionType};
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/air/requestFileSystem.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/requestFileSystem.js b/lib/webworks/air/plugin/air/requestFileSystem.js
deleted file mode 100644
index b1079cc..0000000
--- a/lib/webworks/air/plugin/air/requestFileSystem.js
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
-FileError = require('cordova/plugin/FileError'),
-FileSystem = require('cordova/plugin/FileSystem'),
-LocalFileSystem = require('cordova/plugin/LocalFileSystem');
-
-/**
- * Request a file system in which to store application data.
- * @param type local file system type
- * @param size indicates how much storage space, in bytes, the application expects to need
- * @param successCallback invoked with a FileSystem object
- * @param errorCallback invoked if error occurs retrieving file system
- */
-var requestFileSystem = function(type, size, successCallback, errorCallback) {
- var fail = function(code) {
- if (typeof errorCallback === 'function') {
- errorCallback(new FileError(code));
- }
- };
-
- if (type < 0 || type > 3) {
- fail(FileError.SYNTAX_ERR);
- } else {
- // if successful, return a FileSystem object
- var success = function(file_system) {
- if (file_system) {
- if (typeof successCallback === 'function') {
- successCallback(file_system);
- }
- }
- else {
- // no FileSystem object returned
- fail(FileError.NOT_FOUND_ERR);
- }
- };
-
- // guessing the max file size is 2GB - 1 bytes?
- // https://bdsc.webapps.blackberry.com/native/documentation/com.qnx.doc.neutrino.user_guide/topic/limits_filesystems.html
-
- if(size>=2147483648){
- fail(FileError.QUOTA_EXCEEDED_ERR);
- return;
- }
-
-
- var theFileSystem;
- try{
- // is there a way to get space for the app that doesn't point to the appDirs folder?
- if(type==LocalFileSystem.TEMPORARY){
- theFileSystem = new FileSystem('temporary', new DirectoryEntry('root', blackberry.io.dir.appDirs.app.storage.path));
- }else if(type==LocalFileSystem.PERSISTENT){
- theFileSystem = new FileSystem('persistent', new DirectoryEntry('root', blackberry.io.dir.appDirs.app.storage.path));
- }
- success(theFileSystem);
- }catch(e){
- fail(FileError.SYNTAX_ERR);
- }
- }
-};
-module.exports = requestFileSystem;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/air/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/resolveLocalFileSystemURI.js b/lib/webworks/air/plugin/air/resolveLocalFileSystemURI.js
deleted file mode 100644
index f179fed..0000000
--- a/lib/webworks/air/plugin/air/resolveLocalFileSystemURI.js
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
- FileEntry = require('cordova/plugin/FileEntry'),
- FileError = require('cordova/plugin/FileError');
-
-/**
- * Look up file system Entry referred to by local URI.
- * @param {DOMString} uri URI referring to a local file or directory
- * @param successCallback invoked with Entry object corresponding to URI
- * @param errorCallback invoked if error occurs retrieving file system entry
- */
-module.exports = function(uri, successCallback, errorCallback) {
- // error callback
- var fail = function(error) {
- if (typeof errorCallback === 'function') {
- errorCallback(new FileError(error));
- }
- };
- // if successful, return either a file or directory entry
- var success = function(entry) {
- var result;
-
- if (entry) {
- if (typeof successCallback === 'function') {
- // create appropriate Entry object
- result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath) : new FileEntry(entry.name, entry.fullPath);
- try {
- successCallback(result);
- }
- catch (e) {
- console.log('Error invoking callback: ' + e);
- }
- }
- }
- else {
- // no Entry object returned
- fail(FileError.NOT_FOUND_ERR);
- return;
- }
- };
-
- if(!uri || uri === ""){
- fail(FileError.NOT_FOUND_ERR);
- return;
- }
-
- // decode uri if % char found
- if(uri.indexOf('%')>=0){
- uri = decodeURI(uri);
- }
-
- // pop the parameters if any
- if(uri.indexOf('?')>=0){
- uri = uri.split('?')[0];
- }
-
- // check for leading /
- if(uri.indexOf('/')===0){
- fail(FileError.ENCODING_ERR);
- return;
- }
-
- // Entry object is borked - unable to instantiate a new Entry object so just create one
- var theEntry = {};
- if(blackberry.io.dir.exists(uri)){
- theEntry.isDirectory = true;
- theEntry.name = uri.split('/').pop();
- theEntry.fullPath = uri;
-
- success(theEntry);
- }else if(blackberry.io.file.exists(uri)){
- theEntry.isDirectory = false;
- theEntry.name = uri.split('/').pop();
- theEntry.fullPath = uri;
- success(theEntry);
- return;
- }else{
- fail(FileError.NOT_FOUND_ERR);
- return;
- }
-
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/air/plugin/manager.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/manager.js b/lib/webworks/air/plugin/manager.js
deleted file mode 100644
index 09e07f1..0000000
--- a/lib/webworks/air/plugin/manager.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova'),
- plugins = {
- 'Device' : require('cordova/plugin/air/device'),
- 'Battery' : require('cordova/plugin/air/battery'),
- 'Camera' : require('cordova/plugin/air/camera'),
- 'Logger' : require('cordova/plugin/webworks/logger'),
- 'Media' : require('cordova/plugin/webworks/media'),
- 'Capture' : require('cordova/plugin/air/capture'),
- 'Accelerometer' : require('cordova/plugin/webworks/accelerometer'),
- 'NetworkStatus' : require('cordova/plugin/air/network'),
- 'Notification' : require('cordova/plugin/webworks/notification'),
- 'FileTransfer' : require('cordova/plugin/air/FileTransfer')
- };
-
-module.exports = {
- exec: function (win, fail, clazz, action, args) {
- var result = {"status" : cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION, "message" : "Class " + clazz + " cannot be found"};
-
- if (plugins[clazz]) {
- if (plugins[clazz][action]) {
- result = plugins[clazz][action](args, win, fail);
- }
- else {
- result = { "status" : cordova.callbackStatus.INVALID_ACTION, "message" : "Action not found: " + action };
- }
- }
-
- return result;
- },
- resume: function () {},
- pause: function () {},
- destroy: function () {}
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/common/plugin/webworks/accelerometer.js
----------------------------------------------------------------------
diff --git a/lib/webworks/common/plugin/webworks/accelerometer.js b/lib/webworks/common/plugin/webworks/accelerometer.js
deleted file mode 100644
index 90dc0e7..0000000
--- a/lib/webworks/common/plugin/webworks/accelerometer.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova'),
- callback;
-
-module.exports = {
- start: function (args, win, fail) {
- window.removeEventListener("devicemotion", callback);
- callback = function (motion) {
- win({
- x: motion.accelerationIncludingGravity.x,
- y: motion.accelerationIncludingGravity.y,
- z: motion.accelerationIncludingGravity.z,
- timestamp: motion.timestamp
- });
- };
- window.addEventListener("devicemotion", callback);
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- },
- stop: function (args, win, fail) {
- window.removeEventListener("devicemotion", callback);
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/common/plugin/webworks/logger.js
----------------------------------------------------------------------
diff --git a/lib/webworks/common/plugin/webworks/logger.js b/lib/webworks/common/plugin/webworks/logger.js
deleted file mode 100644
index bd47a1e..0000000
--- a/lib/webworks/common/plugin/webworks/logger.js
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova');
-
-module.exports = {
- log: function (args, win, fail) {
- console.log(args);
- return {"status" : cordova.callbackStatus.OK,
- "message" : 'Message logged to console: ' + args};
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/common/plugin/webworks/media.js
----------------------------------------------------------------------
diff --git a/lib/webworks/common/plugin/webworks/media.js b/lib/webworks/common/plugin/webworks/media.js
deleted file mode 100644
index 2499aea..0000000
--- a/lib/webworks/common/plugin/webworks/media.js
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova'),
- audioObjects = {};
-
-module.exports = {
- create: function (args, win, fail) {
- if (!args.length) {
- return {"status" : 9, "message" : "Media Object id was not sent in arguments"};
- }
-
- var id = args[0],
- src = args[1];
-
- audioObjects[id] = new Audio(src);
- return {"status" : 1, "message" : "Audio object created" };
- },
- startPlayingAudio: 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) {
- return {"status" : 9, "message" : "Media source argument not found"};
- }
-
- if (audio) {
- audio.pause();
- audioObjects[id] = undefined;
- }
-
- 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"};
- }
-
- var id = args[0],
- audio = audioObjects[id],
- result;
-
- if (!audio) {
- return {"status" : 2, "message" : "Audio Object has not been initialized"};
- }
-
- audio.pause();
- audioObjects[id] = undefined;
-
- 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"};
- }
-
- var id = args[0],
- audio = audioObjects[id],
- result;
-
- 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" : "Seek to audio succeeded" };
- }
-
- return result;
- },
- pausePlayingAudio: 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"};
- }
-
- audio.pause();
-
- 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"};
- }
-
- 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.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 { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- },
- 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;
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/common/plugin/webworks/notification.js
----------------------------------------------------------------------
diff --git a/lib/webworks/common/plugin/webworks/notification.js b/lib/webworks/common/plugin/webworks/notification.js
deleted file mode 100644
index 9de87b8..0000000
--- a/lib/webworks/common/plugin/webworks/notification.js
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var cordova = require('cordova');
-
-module.exports = {
- alert: function (args, win, fail) {
- if (args.length !== 3) {
- 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 { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- },
- 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 = btnLabel.split(",");
-
- blackberry.ui.dialog.customAskAsync.apply(this, [msg, btnLabels, win, {"title" : title} ]);
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/exec.js
----------------------------------------------------------------------
diff --git a/lib/webworks/exec.js b/lib/webworks/exec.js
deleted file mode 100644
index 0bc84e3..0000000
--- a/lib/webworks/exec.js
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var manager = require('cordova/plugin/manager'),
- cordova = require('cordova'),
- utils = require('cordova/utils');
-
-/**
- * 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
- * Asynchronous: 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
- */
-
-module.exports = function(success, fail, service, action, args) {
- try {
- var v = manager.exec(success, fail, service, action, args);
-
- // If status is OK, then return value back to caller
- if (v.status == cordova.callbackStatus.OK) {
-
- // If there is a success callback, then call it now with returned value
- if (success) {
- try {
- success(v.message);
- }
- catch (e) {
- console.log("Error in success callback: "+cordova.callbackId+" = "+e);
- }
-
- }
- return v.message;
- } else if (v.status == cordova.callbackStatus.NO_RESULT) {
-
- } else {
- // If error, then display error
- console.log("Error: Status="+v.status+" Message="+v.message);
-
- // If there is a fail callback, then call it now with returned value
- if (fail) {
- try {
- fail(v.message);
- }
- catch (e) {
- console.log("Error in error callback: "+cordova.callbackId+" = "+e);
- }
- }
- return null;
- }
- } catch (e) {
- utils.alert("Error: "+e);
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/java/platform.js
----------------------------------------------------------------------
diff --git a/lib/webworks/java/platform.js b/lib/webworks/java/platform.js
deleted file mode 100644
index 492eb83..0000000
--- a/lib/webworks/java/platform.js
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-module.exports = {
- id: "blackberry",
- initialize:function() {
- var cordova = require('cordova'),
- exec = require('cordova/exec'),
- channel = require('cordova/channel'),
- manager = require('cordova/plugin/manager'),
- app = require('cordova/plugin/java/app');
-
- // BB OS 5 does not define window.console.
- if (typeof window.console === 'undefined') {
- window.console = {};
- }
-
- // Override console.log with native logging ability.
- // BB OS 7 devices define console.log for use with web inspector
- // debugging. If console.log is already defined, invoke it in addition
- // to native logging.
- var origLog = window.console.log;
- window.console.log = function(msg) {
- if (typeof origLog === 'function') {
- origLog.call(window.console, msg);
- }
- org.apache.cordova.Logger.log(''+msg);
- };
-
- // Mapping of button events to BlackBerry key identifier.
- var buttonMapping = {
- 'backbutton' : blackberry.system.event.KEY_BACK,
- 'conveniencebutton1' : blackberry.system.event.KEY_CONVENIENCE_1,
- 'conveniencebutton2' : blackberry.system.event.KEY_CONVENIENCE_2,
- 'endcallbutton' : blackberry.system.event.KEY_ENDCALL,
- 'menubutton' : blackberry.system.event.KEY_MENU,
- 'startcallbutton' : blackberry.system.event.KEY_STARTCALL,
- 'volumedownbutton' : blackberry.system.event.KEY_VOLUMEDOWN,
- 'volumeupbutton' : blackberry.system.event.KEY_VOLUMEUP
- };
-
- // Generates a function which fires the specified event.
- var fireEvent = function(event) {
- return function() {
- cordova.fireDocumentEvent(event, null);
- };
- };
-
- var eventHandler = function(event) {
- return function() {
- // If we just attached the first handler, let native know we
- // need to override the hardware button.
- if (this.numHandlers) {
- blackberry.system.event.onHardwareKey(
- buttonMapping[event], fireEvent(event));
- }
- // If we just detached the last handler, let native know we
- // no longer override the hardware button.
- else {
- blackberry.system.event.onHardwareKey(
- buttonMapping[event], null);
- }
- };
- };
-
- // Inject listeners for buttons on the document.
- for (var button in buttonMapping) {
- if (buttonMapping.hasOwnProperty(button)) {
- var buttonChannel = cordova.addDocumentEventHandler(button);
- buttonChannel.onHasSubscribersChange = eventHandler(button);
- }
- }
-
- // Fires off necessary code to pause/resume app
- var resume = function() {
- cordova.fireDocumentEvent('resume');
- manager.resume();
- };
- var pause = function() {
- cordova.fireDocumentEvent('pause');
- manager.pause();
- };
-
- /************************************************
- * Patch up the generic pause/resume listeners. *
- ************************************************/
-
- // Unsubscribe handler - turns off native backlight change
- // listener
- var onHasSubscribersChange = function() {
- // If we just attached the first handler and there are
- // no pause handlers, start the backlight system
- // listener on the native side.
- if (this.numHandlers && (channel.onResume.numHandlers + channel.onPause.numHandlers === 1)) {
- exec(backlightWin, backlightFail, "App", "detectBacklight", []);
- } else if (channel.onResume.numHandlers === 0 && channel.onPause.numHandlers === 0) {
- exec(null, null, 'App', 'ignoreBacklight', []);
- }
- };
-
- // Native backlight detection win/fail callbacks
- var backlightWin = function(isOn) {
- if (isOn === true) {
- resume();
- } else {
- pause();
- }
- };
- var backlightFail = function(e) {
- console.log("Error detecting backlight on/off.");
- };
-
- // Override stock resume and pause listeners so we can trigger
- // some native methods during attach/remove
- channel.onResume = cordova.addDocumentEventHandler('resume');
- channel.onResume.onHasSubscribersChange = onHasSubscribersChange;
- channel.onPause = cordova.addDocumentEventHandler('pause');
- channel.onPause.onHasSubscribersChange = onHasSubscribersChange;
-
- // Fire resume event when application brought to foreground.
- blackberry.app.event.onForeground(resume);
-
- // Fire pause event when application sent to background.
- blackberry.app.event.onBackground(pause);
-
- // Trap BlackBerry WebWorks exit. Allow plugins to clean up before exiting.
- blackberry.app.event.onExit(app.exitApp);
- },
- objects: {
- navigator: {
- children: {
- app: {
- path: "cordova/plugin/java/app"
- }
- }
- },
- File: { // exists natively on BlackBerry OS 7, override
- path: "cordova/plugin/File"
- }
- },
- merges: {
- navigator: {
- children: {
- contacts: {
- path: 'cordova/plugin/java/contacts'
- },
- notification: {
- path: 'cordova/plugin/java/notification'
- }
- }
- },
- Contact: {
- path: 'cordova/plugin/java/Contact'
- },
- DirectoryEntry: {
- path: 'cordova/plugin/java/DirectoryEntry'
- },
- Entry: {
- path: 'cordova/plugin/java/Entry'
- },
- MediaError: { // Exists natively on BB OS 6+, merge in Cordova specifics
- path: 'cordova/plugin/java/MediaError'
- }
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/webworks/java/plugin/java/Contact.js
----------------------------------------------------------------------
diff --git a/lib/webworks/java/plugin/java/Contact.js b/lib/webworks/java/plugin/java/Contact.js
deleted file mode 100644
index 52d82cf..0000000
--- a/lib/webworks/java/plugin/java/Contact.js
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-var ContactError = require('cordova/plugin/ContactError'),
- ContactUtils = require('cordova/plugin/java/ContactUtils'),
- utils = require('cordova/utils'),
- ContactAddress = require('cordova/plugin/ContactAddress'),
- exec = require('cordova/exec');
-
-// ------------------
-// Utility functions
-// ------------------
-
-/**
- * Retrieves a BlackBerry contact from the device by unique id.
- *
- * @param uid
- * Unique id of the contact on the device
- * @return {blackberry.pim.Contact} BlackBerry contact or null if contact with
- * specified id is not found
- */
-var findByUniqueId = function(uid) {
- if (!uid) {
- return null;
- }
- var bbContacts = blackberry.pim.Contact.find(new blackberry.find.FilterExpression("uid", "==", uid));
- return bbContacts[0] || null;
-};
-
-/**
- * Creates a BlackBerry contact object from the W3C Contact object and persists
- * it to device storage.
- *
- * @param {Contact}
- * contact The contact to save
- * @return a new contact object with all properties set
- */
-var saveToDevice = function(contact) {
-
- if (!contact) {
- return;
- }
-
- var bbContact = null;
- var update = false;
-
- // if the underlying BlackBerry contact already exists, retrieve it for
- // update
- if (contact.id) {
- // we must attempt to retrieve the BlackBerry contact from the device
- // because this may be an update operation
- bbContact = findByUniqueId(contact.id);
- }
-
- // contact not found on device, create a new one
- if (!bbContact) {
- bbContact = new blackberry.pim.Contact();
- }
- // update the existing contact
- else {
- update = true;
- }
-
- // NOTE: The user may be working with a partial Contact object, because only
- // user-specified Contact fields are returned from a find operation (blame
- // the W3C spec). If this is an update to an existing Contact, we don't
- // want to clear an attribute from the contact database simply because the
- // Contact object that the user passed in contains a null value for that
- // attribute. So we only copy the non-null Contact attributes to the
- // BlackBerry contact object before saving.
- //
- // This means that a user must explicitly set a Contact attribute to a
- // non-null value in order to update it in the contact database.
- //
- // name
- if (contact.name !== null) {
- if (contact.name.givenName) {
- bbContact.firstName = contact.name.givenName;
- }
- if (contact.name.familyName) {
- bbContact.lastName = contact.name.familyName;
- }
- if (contact.name.honorificPrefix) {
- bbContact.title = contact.name.honorificPrefix;
- }
- }
-
- // display name
- if (contact.displayName !== null) {
- bbContact.user1 = contact.displayName;
- }
-
- // note
- if (contact.note !== null) {
- bbContact.note = contact.note;
- }
-
- // birthday
- //
- // user may pass in Date object or a string representation of a date
- // if it is a string, we don't know the date format, so try to create a
- // new Date with what we're given
- //
- // NOTE: BlackBerry's Date.parse() does not work well, so use new Date()
- //
- if (contact.birthday !== null) {
- if (utils.isDate(contact.birthday)) {
- bbContact.birthday = contact.birthday;
- } else {
- var bday = contact.birthday.toString();
- bbContact.birthday = (bday.length > 0) ? new Date(bday) : "";
- }
- }
-
- // BlackBerry supports three email addresses
- if (contact.emails && utils.isArray(contact.emails)) {
-
- // if this is an update, re-initialize email addresses
- if (update) {
- bbContact.email1 = "";
- bbContact.email2 = "";
- bbContact.email3 = "";
- }
-
- // copy the first three email addresses found
- var email = null;
- for ( var i = 0; i < contact.emails.length; i += 1) {
- email = contact.emails[i];
- if (!email || !email.value) {
- continue;
- }
- if (bbContact.email1 === "") {
- bbContact.email1 = email.value;
- } else if (bbContact.email2 === "") {
- bbContact.email2 = email.value;
- } else if (bbContact.email3 === "") {
- bbContact.email3 = email.value;
- }
- }
- }
-
- // BlackBerry supports a finite number of phone numbers
- // copy into appropriate fields based on type
- if (contact.phoneNumbers && utils.isArray(contact.phoneNumbers)) {
-
- // if this is an update, re-initialize phone numbers
- if (update) {
- bbContact.homePhone = "";
- bbContact.homePhone2 = "";
- bbContact.workPhone = "";
- bbContact.workPhone2 = "";
- bbContact.mobilePhone = "";
- bbContact.faxPhone = "";
- bbContact.pagerPhone = "";
- bbContact.otherPhone = "";
- }
-
- var type = null;
- var number = null;
- for ( var j = 0; j < contact.phoneNumbers.length; j += 1) {
- if (!contact.phoneNumbers[j] || !contact.phoneNumbers[j].value) {
- continue;
- }
- type = contact.phoneNumbers[j].type;
- number = contact.phoneNumbers[j].value;
- if (type === 'home') {
- if (bbContact.homePhone === "") {
- bbContact.homePhone = number;
- } else if (bbContact.homePhone2 === "") {
- bbContact.homePhone2 = number;
- }
- } else if (type === 'work') {
- if (bbContact.workPhone === "") {
- bbContact.workPhone = number;
- } else if (bbContact.workPhone2 === "") {
- bbContact.workPhone2 = number;
- }
- } else if (type === 'mobile' && bbContact.mobilePhone === "") {
- bbContact.mobilePhone = number;
- } else if (type === 'fax' && bbContact.faxPhone === "") {
- bbContact.faxPhone = number;
- } else if (type === 'pager' && bbContact.pagerPhone === "") {
- bbContact.pagerPhone = number;
- } else if (bbContact.otherPhone === "") {
- bbContact.otherPhone = number;
- }
- }
- }
-
- // BlackBerry supports two addresses: home and work
- // copy the first two addresses found from Contact
- if (contact.addresses && utils.isArray(contact.addresses)) {
-
- // if this is an update, re-initialize addresses
- if (update) {
- bbContact.homeAddress = null;
- bbContact.workAddress = null;
- }
-
- var address = null;
- var bbHomeAddress = null;
- var bbWorkAddress = null;
- for ( var k = 0; k < contact.addresses.length; k += 1) {
- address = contact.addresses[k];
- if (!address || address.id === undefined || address.pref === undefined || address.type === undefined || address.formatted === undefined) {
- continue;
- }
-
- if (bbHomeAddress === null && (!address.type || address.type === "home")) {
- bbHomeAddress = createBlackBerryAddress(address);
- bbContact.homeAddress = bbHomeAddress;
- } else if (bbWorkAddress === null && (!address.type || address.type === "work")) {
- bbWorkAddress = createBlackBerryAddress(address);
- bbContact.workAddress = bbWorkAddress;
- }
- }
- }
-
- // copy first url found to BlackBerry 'webpage' field
- if (contact.urls && utils.isArray(contact.urls)) {
-
- // if this is an update, re-initialize web page
- if (update) {
- bbContact.webpage = "";
- }
-
- var url = null;
- for ( var m = 0; m < contact.urls.length; m += 1) {
- url = contact.urls[m];
- if (!url || !url.value) {
- continue;
- }
- if (bbContact.webpage === "") {
- bbContact.webpage = url.value;
- break;
- }
- }
- }
-
- // copy fields from first organization to the
- // BlackBerry 'company' and 'jobTitle' fields
- if (contact.organizations && utils.isArray(contact.organizations)) {
-
- // if this is an update, re-initialize org attributes
- if (update) {
- bbContact.company = "";
- }
-
- var org = null;
- for ( var n = 0; n < contact.organizations.length; n += 1) {
- org = contact.organizations[n];
- if (!org) {
- continue;
- }
- if (bbContact.company === "") {
- bbContact.company = org.name || "";
- bbContact.jobTitle = org.title || "";
- break;
- }
- }
- }
-
- // categories
- if (contact.categories && utils.isArray(contact.categories)) {
- bbContact.categories = [];
- var category = null;
- for ( var o = 0; o < contact.categories.length; o += 1) {
- category = contact.categories[o];
- if (typeof category == "string") {
- bbContact.categories.push(category);
- }
- }
- }
-
- // save to device
- bbContact.save();
-
- // invoke native side to save photo
- // fail gracefully if photo URL is no good, but log the error
- if (contact.photos && utils.isArray(contact.photos)) {
- var photo = null;
- for ( var p = 0; p < contact.photos.length; p += 1) {
- photo = contact.photos[p];
- if (!photo || !photo.value) {
- continue;
- }
- exec(
- // success
- function() {
- },
- // fail
- function(e) {
- console.log('Contact.setPicture failed:' + e);
- }, "Contacts", "setPicture", [ bbContact.uid, photo.type,
- photo.value ]);
- break;
- }
- }
-
- // Use the fully populated BlackBerry contact object to create a
- // corresponding W3C contact object.
- return ContactUtils.createContact(bbContact, [ "*" ]);
-};
-
-/**
- * Creates a BlackBerry Address object from a W3C ContactAddress.
- *
- * @return {blackberry.pim.Address} a BlackBerry address object
- */
-var createBlackBerryAddress = function(address) {
- var bbAddress = new blackberry.pim.Address();
-
- if (!address) {
- return bbAddress;
- }
-
- bbAddress.address1 = address.streetAddress || "";
- bbAddress.city = address.locality || "";
- bbAddress.stateProvince = address.region || "";
- bbAddress.zipPostal = address.postalCode || "";
- bbAddress.country = address.country || "";
-
- return bbAddress;
-};
-
-module.exports = {
- /**
- * Persists contact to device storage.
- */
- save : function(success, fail) {
- try {
- // save the contact and store it's unique id
- var fullContact = saveToDevice(this);
- this.id = fullContact.id;
-
- // This contact object may only have a subset of properties
- // if the save was an update of an existing contact. This is
- // because the existing contact was likely retrieved using a
- // subset of properties, so only those properties were set in the
- // object. For this reason, invoke success with the contact object
- // returned by saveToDevice since it is fully populated.
- if (typeof success === 'function') {
- success(fullContact);
- }
- } catch (e) {
- console.log('Error saving contact: ' + e);
- if (typeof fail === 'function') {
- fail(new ContactError(ContactError.UNKNOWN_ERROR));
- }
- }
- },
-
- /**
- * Removes contact from device storage.
- *
- * @param success
- * success callback
- * @param fail
- * error callback
- */
- remove : function(success, fail) {
- try {
- // retrieve contact from device by id
- var bbContact = null;
- if (this.id) {
- bbContact = findByUniqueId(this.id);
- }
-
- // if contact was found, remove it
- if (bbContact) {
- console.log('removing contact: ' + bbContact.uid);
- bbContact.remove();
- if (typeof success === 'function') {
- success(this);
- }
- }
- // attempting to remove a contact that hasn't been saved
- else if (typeof fail === 'function') {
- fail(new ContactError(ContactError.UNKNOWN_ERROR));
- }
- } catch (e) {
- console.log('Error removing contact ' + this.id + ": " + e);
- if (typeof fail === 'function') {
- fail(new ContactError(ContactError.UNKNOWN_ERROR));
- }
- }
- }
-};