diff --git a/package.json b/package.json index 7f16885..727a0e3 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,9 @@ "cordova-plugin-splashscreen", "cordova-plugin-statusbar", "ionic-plugin-keyboard", - "cordova-plugin-inappbrowser" + "cordova-plugin-inappbrowser", + "cordova-plugin-file", + "org.apache.cordova.file-transfer" ], "cordovaPlatforms": [ "android" diff --git a/platforms/android/AndroidManifest.xml b/platforms/android/AndroidManifest.xml index 8b810ac..44d6674 100644 --- a/platforms/android/AndroidManifest.xml +++ b/platforms/android/AndroidManifest.xml @@ -14,4 +14,5 @@ + diff --git a/platforms/android/android.json b/platforms/android/android.json index ebd9a8d..6074b4f 100644 --- a/platforms/android/android.json +++ b/platforms/android/android.json @@ -12,6 +12,12 @@ "xml": "", "count": 1 } + ], + "/*": [ + { + "xml": "", + "count": 2 + } ] } }, @@ -45,6 +51,14 @@ { "xml": "", "count": 1 + }, + { + "xml": "", + "count": 1 + }, + { + "xml": "", + "count": 1 } ] } @@ -58,6 +72,16 @@ } ] } + }, + "config.xml": { + "parents": { + "/*": [ + { + "xml": "", + "count": 1 + } + ] + } } } }, @@ -86,6 +110,12 @@ }, "cordova-plugin-inappbrowser": { "PACKAGE_NAME": "com.raataar.wolle_rosen_kaufen" + }, + "cordova-plugin-file": { + "PACKAGE_NAME": "com.raataar.wolle_rosen_kaufen" + }, + "cordova-plugin-file-transfer": { + "PACKAGE_NAME": "com.raataar.wolle_rosen_kaufen" } }, "dependent_plugins": {}, @@ -145,6 +175,189 @@ "cordova.InAppBrowser.open", "window.open" ] + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryEntry.js", + "id": "cordova-plugin-file.DirectoryEntry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.DirectoryEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryReader.js", + "id": "cordova-plugin-file.DirectoryReader", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.DirectoryReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Entry.js", + "id": "cordova-plugin-file.Entry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Entry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/File.js", + "id": "cordova-plugin-file.File", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.File" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileEntry.js", + "id": "cordova-plugin-file.FileEntry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileError.js", + "id": "cordova-plugin-file.FileError", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileError" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileReader.js", + "id": "cordova-plugin-file.FileReader", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileSystem.js", + "id": "cordova-plugin-file.FileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadOptions.js", + "id": "cordova-plugin-file.FileUploadOptions", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileUploadOptions" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadResult.js", + "id": "cordova-plugin-file.FileUploadResult", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileUploadResult" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileWriter.js", + "id": "cordova-plugin-file.FileWriter", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileWriter" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Flags.js", + "id": "cordova-plugin-file.Flags", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Flags" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/LocalFileSystem.js", + "id": "cordova-plugin-file.LocalFileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.LocalFileSystem" + ], + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Metadata.js", + "id": "cordova-plugin-file.Metadata", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Metadata" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/ProgressEvent.js", + "id": "cordova-plugin-file.ProgressEvent", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.ProgressEvent" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystems.js", + "id": "cordova-plugin-file.fileSystems", + "pluginId": "cordova-plugin-file" + }, + { + "file": "plugins/cordova-plugin-file/www/requestFileSystem.js", + "id": "cordova-plugin-file.requestFileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.requestFileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js", + "id": "cordova-plugin-file.resolveLocalFileSystemURI", + "pluginId": "cordova-plugin-file", + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/android/FileSystem.js", + "id": "cordova-plugin-file.androidFileSystem", + "pluginId": "cordova-plugin-file", + "merges": [ + "FileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystems-roots.js", + "id": "cordova-plugin-file.fileSystems-roots", + "pluginId": "cordova-plugin-file", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystemPaths.js", + "id": "cordova-plugin-file.fileSystemPaths", + "pluginId": "cordova-plugin-file", + "merges": [ + "cordova" + ], + "runs": true + }, + { + "file": "plugins/cordova-plugin-file-transfer/www/FileTransferError.js", + "id": "cordova-plugin-file-transfer.FileTransferError", + "pluginId": "cordova-plugin-file-transfer", + "clobbers": [ + "window.FileTransferError" + ] + }, + { + "file": "plugins/cordova-plugin-file-transfer/www/FileTransfer.js", + "id": "cordova-plugin-file-transfer.FileTransfer", + "pluginId": "cordova-plugin-file-transfer", + "clobbers": [ + "window.FileTransfer" + ] } ], "plugin_metadata": { @@ -155,6 +368,8 @@ "cordova-plugin-statusbar": "2.0.0", "cordova-plugin-whitelist": "1.2.0", "ionic-plugin-keyboard": "1.0.8", - "cordova-plugin-inappbrowser": "1.1.1" + "cordova-plugin-inappbrowser": "1.1.1", + "cordova-plugin-file": "3.0.0", + "cordova-plugin-file-transfer": "1.4.0" } } \ No newline at end of file diff --git a/platforms/android/assets/www/cordova_plugins.js b/platforms/android/assets/www/cordova_plugins.js index d0dae10..e310c63 100644 --- a/platforms/android/assets/www/cordova_plugins.js +++ b/platforms/android/assets/www/cordova_plugins.js @@ -55,6 +55,189 @@ module.exports = [ "cordova.InAppBrowser.open", "window.open" ] + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryEntry.js", + "id": "cordova-plugin-file.DirectoryEntry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.DirectoryEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryReader.js", + "id": "cordova-plugin-file.DirectoryReader", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.DirectoryReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Entry.js", + "id": "cordova-plugin-file.Entry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Entry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/File.js", + "id": "cordova-plugin-file.File", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.File" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileEntry.js", + "id": "cordova-plugin-file.FileEntry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileError.js", + "id": "cordova-plugin-file.FileError", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileError" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileReader.js", + "id": "cordova-plugin-file.FileReader", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileSystem.js", + "id": "cordova-plugin-file.FileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadOptions.js", + "id": "cordova-plugin-file.FileUploadOptions", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileUploadOptions" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadResult.js", + "id": "cordova-plugin-file.FileUploadResult", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileUploadResult" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileWriter.js", + "id": "cordova-plugin-file.FileWriter", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileWriter" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Flags.js", + "id": "cordova-plugin-file.Flags", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Flags" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/LocalFileSystem.js", + "id": "cordova-plugin-file.LocalFileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.LocalFileSystem" + ], + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Metadata.js", + "id": "cordova-plugin-file.Metadata", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Metadata" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/ProgressEvent.js", + "id": "cordova-plugin-file.ProgressEvent", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.ProgressEvent" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystems.js", + "id": "cordova-plugin-file.fileSystems", + "pluginId": "cordova-plugin-file" + }, + { + "file": "plugins/cordova-plugin-file/www/requestFileSystem.js", + "id": "cordova-plugin-file.requestFileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.requestFileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js", + "id": "cordova-plugin-file.resolveLocalFileSystemURI", + "pluginId": "cordova-plugin-file", + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/android/FileSystem.js", + "id": "cordova-plugin-file.androidFileSystem", + "pluginId": "cordova-plugin-file", + "merges": [ + "FileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystems-roots.js", + "id": "cordova-plugin-file.fileSystems-roots", + "pluginId": "cordova-plugin-file", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystemPaths.js", + "id": "cordova-plugin-file.fileSystemPaths", + "pluginId": "cordova-plugin-file", + "merges": [ + "cordova" + ], + "runs": true + }, + { + "file": "plugins/cordova-plugin-file-transfer/www/FileTransferError.js", + "id": "cordova-plugin-file-transfer.FileTransferError", + "pluginId": "cordova-plugin-file-transfer", + "clobbers": [ + "window.FileTransferError" + ] + }, + { + "file": "plugins/cordova-plugin-file-transfer/www/FileTransfer.js", + "id": "cordova-plugin-file-transfer.FileTransfer", + "pluginId": "cordova-plugin-file-transfer", + "clobbers": [ + "window.FileTransfer" + ] } ]; module.exports.metadata = @@ -67,7 +250,9 @@ module.exports.metadata = "cordova-plugin-statusbar": "2.0.0", "cordova-plugin-whitelist": "1.2.0", "ionic-plugin-keyboard": "1.0.8", - "cordova-plugin-inappbrowser": "1.1.1" + "cordova-plugin-inappbrowser": "1.1.1", + "cordova-plugin-file": "3.0.0", + "cordova-plugin-file-transfer": "1.4.0" } // BOTTOM OF METADATA }); \ No newline at end of file diff --git a/platforms/android/assets/www/index.html b/platforms/android/assets/www/index.html index b4066a8..387514f 100644 --- a/platforms/android/assets/www/index.html +++ b/platforms/android/assets/www/index.html @@ -25,7 +25,7 @@ - + diff --git a/platforms/android/assets/www/js/controllers.js b/platforms/android/assets/www/js/controllers.js index d2641b8..ec6a833 100644 --- a/platforms/android/assets/www/js/controllers.js +++ b/platforms/android/assets/www/js/controllers.js @@ -1,25 +1,14 @@ angular.module('starter.controllers', []) -.controller('DashCtrl', function($scope,$ionicPopup,$http) { +.controller('DashCtrl', function($scope,$ionicPopup,$http, $localstorage) { $scope.preis=""; $scope.name=""; $scope.freitext=""; - var showAlert=0; + $scope.items=[]; + $scope.item=[]; $scope.validate = function() { - showAlert=0; - if ($scope.name.length < 1){ - showAlert=1; - } - if ($scope.freitext.length < 1){ - showAlert=1; - } - - if (showAlert==1){ - $scope.showAlert(); - return; - } var link = 'http://api.raataar.de/rosen/vorschau.php'; @@ -31,21 +20,19 @@ angular.module('starter.controllers', []) }; - $scope.showAlert = function() { - var alertPopup = $ionicPopup.alert({ - title: 'Uuuupppsssiii', - template: 'Bitte prüfe deine Eingaben.' - }); - alertPopup.then(function(res) { - console.log('Thank you for not eating my delicious ice cream cone'); - }); - }; + $scope.loaddata = function() { + $scope.items=$localstorage.getObject('items'); + alert(JSON.stringify($scope.items)); + }; - function buysuccessHandler (result) { - inappbilling.consumePurchase(successHandler, errorHandler, "3xrose"); - } + $scope.savedata = function() { + $scope.item={name: $scope.name, freitext: $scope.freitext, rosen: $scope.preis, bild: "test"}; + alert(JSON.stringify($scope.item)); + $scope.items.push($scope.item); + $localstorage.setObject('items',$scope.items); + }; - function successHandler (result) { + function successBuyHandler (result) { var strResult = ""; if(typeof result === 'object') { strResult = JSON.stringify(result); @@ -55,16 +42,35 @@ angular.module('starter.controllers', []) alert("SUCCESS: \r\n"+strResult ); } - function errorHandler (error) { + function successConsumeHandler (result) { + var strResult = ""; + if(typeof result === 'object') { + strResult = JSON.stringify(result); + } else { + strResult = result; + } + alert("SUCCESS: \r\n"+strResult ); + } + + function errorBuyHandler (error) { alert("ERROR: \r\n"+error ); - } + } - $scope.buyAdFree = function() { + function errorConsumeHandler (error) { + alert("ERROR: \r\n"+error ); + } - alert($scope.preis); + + function buysuccessHandler (result) { + inappbilling.consumePurchase(successConsumeHandler, errorConsumeHandler, $scope.preis); + } + + $scope.buyRose = function() { + + //alert($scope.preis); if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") { - inappbilling.buy(buysuccessHandler, errorHandler,"3xrose"); + inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis); } } diff --git a/platforms/android/assets/www/js/services.js b/platforms/android/assets/www/js/services.js index 73837bf..ac7c5b6 100644 --- a/platforms/android/assets/www/js/services.js +++ b/platforms/android/assets/www/js/services.js @@ -1,50 +1,19 @@ angular.module('starter.services', []) -.factory('Chats', function() { - // Might use a resource here that returns a JSON array - - // Some fake testing data - var chats = [{ - id: 0, - name: 'Ben Sparrow', - lastText: 'You on your way?', - face: 'img/ben.png' - }, { - id: 1, - name: 'Max Lynx', - lastText: 'Hey, it\'s me', - face: 'img/max.png' - }, { - id: 2, - name: 'Adam Bradleyson', - lastText: 'I should buy a boat', - face: 'img/adam.jpg' - }, { - id: 3, - name: 'Perry Governor', - lastText: 'Look at my mukluks!', - face: 'img/perry.png' - }, { - id: 4, - name: 'Mike Harrington', - lastText: 'This is wicked good ice cream.', - face: 'img/mike.png' - }]; +.factory('$localstorage', ['$window', function($window) { return { - all: function() { - return chats; + set: function(key, value) { + $window.localStorage[key] = value; }, - remove: function(chat) { - chats.splice(chats.indexOf(chat), 1); + get: function(key, defaultValue) { + return $window.localStorage[key] || defaultValue; }, - get: function(chatId) { - for (var i = 0; i < chats.length; i++) { - if (chats[i].id === parseInt(chatId)) { - return chats[i]; - } - } - return null; + setObject: function(key, value) { + $window.localStorage[key] = JSON.stringify(value); + }, + getObject: function(key) { + return JSON.parse($window.localStorage[key] || '{}'); } - }; -}); + } +}]); diff --git a/platforms/android/assets/www/plugins/cordova-plugin-file-transfer/www/FileTransfer.js b/platforms/android/assets/www/plugins/cordova-plugin-file-transfer/www/FileTransfer.js new file mode 100644 index 0000000..ff0e6c9 --- /dev/null +++ b/platforms/android/assets/www/plugins/cordova-plugin-file-transfer/www/FileTransfer.js @@ -0,0 +1,237 @@ +cordova.define("cordova-plugin-file-transfer.FileTransfer", function(require, exports, module) { /* + * + * 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 argscheck = require('cordova/argscheck'), + exec = require('cordova/exec'), + FileTransferError = require('./FileTransferError'), + ProgressEvent = require('cordova-plugin-file.ProgressEvent'); + +function newProgressEvent(result) { + var pe = new ProgressEvent(); + pe.lengthComputable = result.lengthComputable; + pe.loaded = result.loaded; + pe.total = result.total; + return pe; +} + +function getUrlCredentials(urlString) { + var credentialsPattern = /^https?\:\/\/(?:(?:(([^:@\/]*)(?::([^@\/]*))?)?@)?([^:\/?#]*)(?::(\d*))?).*$/, + credentials = credentialsPattern.exec(urlString); + + return credentials && credentials[1]; +} + +function getBasicAuthHeader(urlString) { + var header = null; + + + // This is changed due to MS Windows doesn't support credentials in http uris + // so we detect them by regexp and strip off from result url + // Proof: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/a327cf3c-f033-4a54-8b7f-03c56ba3203f/windows-foundation-uri-security-problem + + if (window.btoa) { + var credentials = getUrlCredentials(urlString); + if (credentials) { + var authHeader = "Authorization"; + var authHeaderValue = "Basic " + window.btoa(credentials); + + header = { + name : authHeader, + value : authHeaderValue + }; + } + } + + return header; +} + +function convertHeadersToArray(headers) { + var result = []; + for (var header in headers) { + if (headers.hasOwnProperty(header)) { + var headerValue = headers[header]; + result.push({ + name: header, + value: headerValue.toString() + }); + } + } + return result; +} + +var idCounter = 0; + +/** + * FileTransfer uploads a file to a remote server. + * @constructor + */ +var FileTransfer = function() { + this._id = ++idCounter; + this.onprogress = null; // optional callback +}; + +/** +* Given an absolute file path, uploads a file on the device to a remote server +* using a multipart HTTP request. +* @param filePath {String} Full path of the file on the device +* @param server {String} URL of the server to receive the file +* @param successCallback (Function} Callback to be invoked when upload has completed +* @param errorCallback {Function} Callback to be invoked upon error +* @param options {FileUploadOptions} Optional parameters such as file name and mimetype +* @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false +*/ +FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback, options, trustAllHosts) { + argscheck.checkArgs('ssFFO*', 'FileTransfer.upload', arguments); + // check for options + var fileKey = null; + var fileName = null; + var mimeType = null; + var params = null; + var chunkedMode = true; + var headers = null; + var httpMethod = null; + var basicAuthHeader = getBasicAuthHeader(server); + if (basicAuthHeader) { + server = server.replace(getUrlCredentials(server) + '@', ''); + + options = options || {}; + options.headers = options.headers || {}; + options.headers[basicAuthHeader.name] = basicAuthHeader.value; + } + + if (options) { + fileKey = options.fileKey; + fileName = options.fileName; + mimeType = options.mimeType; + headers = options.headers; + httpMethod = options.httpMethod || "POST"; + if (httpMethod.toUpperCase() == "PUT"){ + httpMethod = "PUT"; + } else { + httpMethod = "POST"; + } + if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") { + chunkedMode = options.chunkedMode; + } + if (options.params) { + params = options.params; + } + else { + params = {}; + } + } + + if (cordova.platformId === "windowsphone") { + headers = headers && convertHeadersToArray(headers); + params = params && convertHeadersToArray(params); + } + + var fail = errorCallback && function(e) { + var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body, e.exception); + errorCallback(error); + }; + + var self = this; + var win = function(result) { + if (typeof result.lengthComputable != "undefined") { + if (self.onprogress) { + self.onprogress(newProgressEvent(result)); + } + } else { + successCallback && successCallback(result); + } + }; + exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id, httpMethod]); +}; + +/** + * Downloads a file form a given URL and saves it to the specified directory. + * @param source {String} URL of the server to receive the file + * @param target {String} Full path of the file on the device + * @param successCallback (Function} Callback to be invoked when upload has completed + * @param errorCallback {Function} Callback to be invoked upon error + * @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false + * @param options {FileDownloadOptions} Optional parameters such as headers + */ +FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts, options) { + argscheck.checkArgs('ssFF*', 'FileTransfer.download', arguments); + var self = this; + + var basicAuthHeader = getBasicAuthHeader(source); + if (basicAuthHeader) { + source = source.replace(getUrlCredentials(source) + '@', ''); + + options = options || {}; + options.headers = options.headers || {}; + options.headers[basicAuthHeader.name] = basicAuthHeader.value; + } + + var headers = null; + if (options) { + headers = options.headers || null; + } + + if (cordova.platformId === "windowsphone" && headers) { + headers = convertHeadersToArray(headers); + } + + var win = function(result) { + if (typeof result.lengthComputable != "undefined") { + if (self.onprogress) { + return self.onprogress(newProgressEvent(result)); + } + } else if (successCallback) { + var entry = null; + if (result.isDirectory) { + entry = new (require('cordova-plugin-file.DirectoryEntry'))(); + } + else if (result.isFile) { + entry = new (require('cordova-plugin-file.FileEntry'))(); + } + entry.isDirectory = result.isDirectory; + entry.isFile = result.isFile; + entry.name = result.name; + entry.fullPath = result.fullPath; + entry.filesystem = new FileSystem(result.filesystemName || (result.filesystem == window.PERSISTENT ? 'persistent' : 'temporary')); + entry.nativeURL = result.nativeURL; + successCallback(entry); + } + }; + + var fail = errorCallback && function(e) { + var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body, e.exception); + errorCallback(error); + }; + + exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id, headers]); +}; + +/** + * Aborts the ongoing file transfer on this object. The original error + * callback for the file transfer will be called if necessary. + */ +FileTransfer.prototype.abort = function() { + exec(null, null, 'FileTransfer', 'abort', [this._id]); +}; + +module.exports = FileTransfer; + +}); diff --git a/platforms/android/assets/www/plugins/cordova-plugin-file-transfer/www/FileTransferError.js b/platforms/android/assets/www/plugins/cordova-plugin-file-transfer/www/FileTransferError.js new file mode 100644 index 0000000..8339c2b --- /dev/null +++ b/platforms/android/assets/www/plugins/cordova-plugin-file-transfer/www/FileTransferError.js @@ -0,0 +1,43 @@ +cordova.define("cordova-plugin-file-transfer.FileTransferError", function(require, exports, module) { /* + * + * 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. + * +*/ + +/** + * FileTransferError + * @constructor + */ +var FileTransferError = function(code, source, target, status, body, exception) { + this.code = code || null; + this.source = source || null; + this.target = target || null; + this.http_status = status || null; + this.body = body || null; + this.exception = exception || null; +}; + +FileTransferError.FILE_NOT_FOUND_ERR = 1; +FileTransferError.INVALID_URL_ERR = 2; +FileTransferError.CONNECTION_ERR = 3; +FileTransferError.ABORT_ERR = 4; +FileTransferError.NOT_MODIFIED_ERR = 5; + +module.exports = FileTransferError; + +}); diff --git a/platforms/android/assets/www/plugins/cordova-plugin-file/www/DirectoryEntry.js b/platforms/android/assets/www/plugins/cordova-plugin-file/www/DirectoryEntry.js new file mode 100644 index 0000000..464d339 --- /dev/null +++ b/platforms/android/assets/www/plugins/cordova-plugin-file/www/DirectoryEntry.js @@ -0,0 +1,119 @@ +cordova.define("cordova-plugin-file.DirectoryEntry", function(require, exports, module) { /* + * + * 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 argscheck = require('cordova/argscheck'), + utils = require('cordova/utils'), + exec = require('cordova/exec'), + Entry = require('./Entry'), + FileError = require('./FileError'), + DirectoryReader = require('./DirectoryReader'); + +/** + * An interface representing a directory on the file system. + * + * {boolean} isFile always false (readonly) + * {boolean} isDirectory always true (readonly) + * {DOMString} name of the directory, excluding the path leading to it (readonly) + * {DOMString} fullPath the absolute full path to the directory (readonly) + * {FileSystem} filesystem on which the directory resides (readonly) + */ +var DirectoryEntry = function(name, fullPath, fileSystem, nativeURL) { + + // add trailing slash if it is missing + if ((fullPath) && !/\/$/.test(fullPath)) { + fullPath += "/"; + } + // add trailing slash if it is missing + if (nativeURL && !/\/$/.test(nativeURL)) { + nativeURL += "/"; + } + DirectoryEntry.__super__.constructor.call(this, false, true, name, fullPath, fileSystem, nativeURL); +}; + +utils.extend(DirectoryEntry, Entry); + +/** + * Creates a new DirectoryReader to read entries from this directory + */ +DirectoryEntry.prototype.createReader = function() { + return new DirectoryReader(this.toInternalURL()); +}; + +/** + * Creates or looks up a directory + * + * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory + * @param {Flags} options to create or exclusively create the directory + * @param {Function} successCallback is called with the new entry + * @param {Function} errorCallback is called with a FileError + */ +DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) { + argscheck.checkArgs('sOFF', 'DirectoryEntry.getDirectory', arguments); + var fs = this.filesystem; + var win = successCallback && function(result) { + var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL); + successCallback(entry); + }; + var fail = errorCallback && function(code) { + errorCallback(new FileError(code)); + }; + exec(win, fail, "File", "getDirectory", [this.toInternalURL(), path, options]); +}; + +/** + * Deletes a directory and all of it's contents + * + * @param {Function} successCallback is called with no parameters + * @param {Function} errorCallback is called with a FileError + */ +DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) { + argscheck.checkArgs('FF', 'DirectoryEntry.removeRecursively', arguments); + var fail = errorCallback && function(code) { + errorCallback(new FileError(code)); + }; + exec(successCallback, fail, "File", "removeRecursively", [this.toInternalURL()]); +}; + +/** + * Creates or looks up a file + * + * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file + * @param {Flags} options to create or exclusively create the file + * @param {Function} successCallback is called with the new entry + * @param {Function} errorCallback is called with a FileError + */ +DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) { + argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments); + var fs = this.filesystem; + var win = successCallback && function(result) { + var FileEntry = require('./FileEntry'); + var entry = new FileEntry(result.name, result.fullPath, fs, result.nativeURL); + successCallback(entry); + }; + var fail = errorCallback && function(code) { + errorCallback(new FileError(code)); + }; + exec(win, fail, "File", "getFile", [this.toInternalURL(), path, options]); +}; + +module.exports = DirectoryEntry; + +}); diff --git a/platforms/android/assets/www/plugins/cordova-plugin-file/www/DirectoryReader.js b/platforms/android/assets/www/plugins/cordova-plugin-file/www/DirectoryReader.js new file mode 100644 index 0000000..921b486 --- /dev/null +++ b/platforms/android/assets/www/plugins/cordova-plugin-file/www/DirectoryReader.js @@ -0,0 +1,75 @@ +cordova.define("cordova-plugin-file.DirectoryReader", function(require, exports, module) { /* + * + * 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 exec = require('cordova/exec'), + FileError = require('./FileError') ; + +/** + * An interface that lists the files and directories in a directory. + */ +function DirectoryReader(localURL) { + this.localURL = localURL || null; + this.hasReadEntries = false; +} + +/** + * Returns a list of entries from a directory. + * + * @param {Function} successCallback is called with a list of entries + * @param {Function} errorCallback is called with a FileError + */ +DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) { + // If we've already read and passed on this directory's entries, return an empty list. + if (this.hasReadEntries) { + successCallback([]); + return; + } + var reader = this; + var win = typeof successCallback !== 'function' ? null : function(result) { + var retVal = []; + for (var i=0; i or + *