cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [15/22] git commit: Android Redirect plugin to reroute cordova.js and menu requests. Put all the web code in a www directory.
Date Mon, 22 Apr 2013 20:14:55 GMT
Android Redirect plugin to reroute cordova.js and menu requests.
Put all the web code in a www directory.


Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/022ebbbe
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/022ebbbe
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/022ebbbe

Branch: refs/heads/master
Commit: 022ebbbee850421dc7d0dc81937f1ad45e3bc38c
Parents: 22d2d33
Author: Shravan Narayan <shravanrn@google.com>
Authored: Tue Apr 16 20:01:17 2013 -0400
Committer: Shravan Narayan <shravanrn@google.com>
Committed: Tue Apr 16 21:56:11 2013 -0400

----------------------------------------------------------------------
 checkjs                                            |    2 +-
 contextMenu.html                                   |   47 ---
 index.html                                         |   17 -
 js/AddCtrl.js                                      |   24 --
 js/AppConstants.js                                 |   10 -
 js/AppsService.js                                  |  104 -------
 js/ContextMenu.js                                  |   38 ---
 js/ListCtrl.js                                     |   42 ---
 js/ResourcesLoader.js                              |  241 ---------------
 js/app.js                                          |   11 -
 js/libs/angular.min.js                             |  173 -----------
 js/libs/q.min.js                                   |   19 --
 plugins/CordovaAppHarnessRedirect/plugin.xml       |   25 ++
 .../src/android/CordovaAppHarnessRedirect.java     |   49 +++
 views/add.html                                     |   16 -
 views/list.html                                    |   12 -
 www/contextMenu.html                               |   47 +++
 www/index.html                                     |   17 +
 www/js/AddCtrl.js                                  |   24 ++
 www/js/AppConstants.js                             |   10 +
 www/js/AppsService.js                              |  104 +++++++
 www/js/ContextMenu.js                              |   38 +++
 www/js/ListCtrl.js                                 |   42 +++
 www/js/ResourcesLoader.js                          |  241 +++++++++++++++
 www/js/app.js                                      |   11 +
 www/js/libs/angular.min.js                         |  173 +++++++++++
 www/js/libs/q.min.js                               |   19 ++
 www/views/add.html                                 |   16 +
 www/views/list.html                                |   12 +
 29 files changed, 829 insertions(+), 755 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/checkjs
----------------------------------------------------------------------
diff --git a/checkjs b/checkjs
index 6f8ff2d..fc457d0 100755
--- a/checkjs
+++ b/checkjs
@@ -1,3 +1,3 @@
 #!/bin/bash
 echo "Running jsHint"
-jshint js/ --verbose --show-non-errors
+jshint www/js/ --verbose --show-non-errors

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/contextMenu.html
----------------------------------------------------------------------
diff --git a/contextMenu.html b/contextMenu.html
deleted file mode 100644
index 27ddd0d..0000000
--- a/contextMenu.html
+++ /dev/null
@@ -1,47 +0,0 @@
-<!-- Keep stylesheet as a part of the html as this file gets injected into the app -->
-<style>
-#__cordovaappharness_contextMenu_div
-{
-    position: fixed;
-    left : 0px;
-    top : 0px;
-    z-index: 2000;
-    background-color:rgba(0,0,0,0.75);
-    width: 100%;
-    height: 100%;
-    display: none;
-}
-#__cordovaappharness_contextMenu_div p
-{
-    color: white;
-    text-align: center;
-}
-
-#__cordovaappharness_contextMenu_div ul
-{
-    list-style-type: none;
-    margin-left: 20%;
-    margin-right: 20%;
-    padding: 0;
-    width: 60%;
-}
-
-#__cordovaappharness_contextMenu_div li, #__cordovaappharness_contextMenu_div button
-{
-    width: 100%;
-}
-</style>
-<div id="__cordovaappharness_contextMenu_div">
-    <p>Tap Anywhere to Close</p>
-    <ul>
-        <li>
-            <button>Update</button>
-        </li>
-        <li>
-            <button>Restart</button>
-        </li>
-        <li>
-            <a href="file://__cordovaappharness_contextMenu_mainmenu"><button>Back
to Main Menu</button></a>
-        </li>
-    </ul>
-</div>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/index.html
----------------------------------------------------------------------
diff --git a/index.html b/index.html
deleted file mode 100644
index c897d14..0000000
--- a/index.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <title>Cordova App Harness</title>
-        <script type="text/javascript" src="cordova.js"></script>
-        <script type="text/javascript" src="js/libs/q.min.js"></script>
-        <script type="text/javascript" src="js/libs/angular.min.js"></script>
-        <script type="text/javascript" src="js/app.js"></script>
-        <script type="text/javascript" src="js/AppConstants.js"></script>
-        <script type="text/javascript" src="js/ResourcesLoader.js"></script>
-        <script type="text/javascript" src="js/AppsService.js"></script>
-        <script type="text/javascript" src="js/ListCtrl.js"></script>
-        <script type="text/javascript" src="js/AddCtrl.js"></script>
-    </head>
-    <body ng-app="CordovaAppHarness" ng-view>
-    </body>
-</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/js/AddCtrl.js
----------------------------------------------------------------------
diff --git a/js/AddCtrl.js b/js/AddCtrl.js
deleted file mode 100644
index f828f54..0000000
--- a/js/AddCtrl.js
+++ /dev/null
@@ -1,24 +0,0 @@
-(function(){
-    "use strict";
-    /* global myApp */
-    myApp.controller("AddCtrl", ["$scope", "AppsService", function ($scope, AppsService)
{
-
-        $scope.addApp = function(appName, appSource, appUrl) {
-            if(appSource === "urlToZip") {
-                if(!appUrl) {
-                    alert("Url not specified");
-                    return;
-                }
-
-                AppsService.addAppFromZipUrl(appName, appUrl)
-                .then(function() {
-                    alert("Successfully installed");
-                }, function(error) {
-                    console.error(error);
-                    alert("Unable to add application because: \n" + JSON.stringify(error));
-                });
-            }
-        };
-    }]);
-
-})();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/js/AppConstants.js
----------------------------------------------------------------------
diff --git a/js/AppConstants.js b/js/AppConstants.js
deleted file mode 100644
index 461c700..0000000
--- a/js/AppConstants.js
+++ /dev/null
@@ -1,10 +0,0 @@
-(function() {
-    var TEMP_DIRECTORY = "cordova_app_harness_tempDir/";
-    var INSTALL_DIRECTORY = "cordova_app_harness_installed_apps/";
-    var APPS_JSON = "cordova_app_harness_installed_apps/apps.json";
-
-    /* global myApp */
-    myApp.value("TEMP_DIRECTORY", TEMP_DIRECTORY);
-    myApp.value("INSTALL_DIRECTORY", INSTALL_DIRECTORY);
-    myApp.value("APPS_JSON", APPS_JSON);
-})();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/js/AppsService.js
----------------------------------------------------------------------
diff --git a/js/AppsService.js b/js/AppsService.js
deleted file mode 100644
index ba012a9..0000000
--- a/js/AppsService.js
+++ /dev/null
@@ -1,104 +0,0 @@
-(function() {
-    "use strict";
-    /* global myApp */
-    myApp.factory("AppsService", [ "ResourcesLoader", "INSTALL_DIRECTORY", "TEMP_DIRECTORY",
"APPS_JSON", "$window", function(ResourcesLoader, INSTALL_DIRECTORY, TEMP_DIRECTORY, APPS_JSON,
$window) {
-
-        function addNewAppFromUrl(appName, appUrl) {
-            var fileName = TEMP_DIRECTORY + appName + ".zip";
-            var _fullFilePath;
-
-            return ResourcesLoader.downloadFromUrl(appUrl, fileName)
-            .then(function(fullFilePath){
-                _fullFilePath = fullFilePath;
-                return ResourcesLoader.ensureDirectoryExists(INSTALL_DIRECTORY + appName);
-            })
-            .then(function(directoryPath){
-                return extractZipToDirectory(_fullFilePath, directoryPath);
-            })
-            .then(function(){
-                return registerApp(appName, "urlToZip", appUrl);
-            });
-        }
-
-        function extractZipToDirectory(fileName, outputDirectory){
-            var deferred = Q.defer();
-
-            var onZipDone = function(returnCode) {
-                if(returnCode !== 0) {
-                    deferred.reject(new Error("Something went wrong during the unzipping
of: " + fileName));
-                } else {
-                    deferred.resolve();
-                }
-            };
-
-            /* global zip */
-            zip.unzip(fileName, outputDirectory, onZipDone);
-            return deferred.promise;
-        }
-
-        function registerApp(appName, appSource, appUrl) {
-            return ResourcesLoader.readJSONFileContents(APPS_JSON)
-            .then(function(result){
-                result.installedApps = result.installedApps || [];
-                result.installedApps.push({
-                    "Name" :  appName,
-                    "Source" : appSource,
-                    "Url" : appUrl
-                });
-                return ResourcesLoader.writeJSONFileContents(APPS_JSON, result);
-            });
-        }
-
-        function getAbsoluteUrl(relativeUrl) {
-            // Can't use $document from angularJS as it does not provie the create constructor
-            /* global document */
-            var a = document.createElement("a");
-            a.href = relativeUrl;
-            return a.href;
-        }
-
-        function getAppStartPageFromAppLocation(appLocation) {
-            appLocation += (appLocation.substring(appLocation.length - 1) === "/") ? "" :
"/";
-            var startLocation = appLocation + "www/index.html";
-            return startLocation;
-        }
-
-        return {
-            //return promise with the array of apps
-            getAppsList : function() {
-                return ResourcesLoader.ensureDirectoryExists(APPS_JSON)
-                .then(function() {
-                    return ResourcesLoader.readJSONFileContents(APPS_JSON);
-                })
-                .then(function(result){
-                    result.installedApps = result.installedApps || [];
-                    var newAppsList = [];
-
-                    for(var i = 0; i < result.installedApps.length; i++){
-                        newAppsList.push(result.installedApps[i].Name);
-                    }
-
-                    return newAppsList;
-                });
-            },
-
-            launchApp : function(appName) {
-                return ResourcesLoader.getFullFilePath(INSTALL_DIRECTORY + appName)
-                .then(function(appLocation) {
-                    var startLocation = getAppStartPageFromAppLocation(appLocation);
-                    document.location = startLocation;
-                });
-            },
-
-            addAppFromZipUrl : function(appName, appUrl) {
-                return this.getAppsList()
-                .then(function(appsList){
-                    if(appsList.indexOf(appName) !== -1) {
-                        throw new Error("An app with this name already exists");
-                    }
-                    return addNewAppFromUrl(appName, appUrl);
-                });
-            }
-        };
-    }]);
-})();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/js/ContextMenu.js
----------------------------------------------------------------------
diff --git a/js/ContextMenu.js b/js/ContextMenu.js
deleted file mode 100644
index 1e3a760..0000000
--- a/js/ContextMenu.js
+++ /dev/null
@@ -1,38 +0,0 @@
-(function () {
-
-    function initialise() {
-        var contextHTMLUrl = "file://__cordovaappharness_contextMenu_page.html";
-        var xhr = new window.XMLHttpRequest();
-        xhr.onreadystatechange=function()
-        {
-            if (xhr.readyState==4 && xhr.status==200)
-            {
-                var stringifiedHtml = xhr.responseText;
-                onInject(stringifiedHtml);
-            }
-        };
-        // retrieve the context menu
-        xhr.open("GET", contextHTMLUrl, true);
-        xhr.send();
-    }
-
-    function onInject(stringifiedHtml) {
-
-        document.body.innerHTML += stringifiedHtml;
-
-        var contextDiv = "__cordovaappharness_contextMenu_div";
-        // Setup the listeners to toggle the context menu
-        document.addEventListener("touchmove", function (event) {
-            if(event.touches.length >= 3) {
-                document.getElementById(contextDiv).style.display = "inline";
-            }
-        }, false);
-
-        document.getElementById(contextDiv).onclick = function() {
-            document.getElementById(contextDiv).style.display = "none";
-        };
-    }
-
-    initialise();
-})();
-

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/js/ListCtrl.js
----------------------------------------------------------------------
diff --git a/js/ListCtrl.js b/js/ListCtrl.js
deleted file mode 100644
index 233c0dc..0000000
--- a/js/ListCtrl.js
+++ /dev/null
@@ -1,42 +0,0 @@
-(function(){
-    "use strict";
-    /* global myApp */
-    myApp.controller("ListCtrl", [ "$scope", "$document", "AppsService", function ($scope,
$document, AppsService) {
-
-        $scope.appsList = [];
-
-        $scope.loadAppsList = function( source ) {
-            AppsService.getAppsList()
-            .then(function(newAppsList){
-                //clear the old apps list
-                $scope.appsList.splice(0, $scope.appsList.length);
-                angular.extend($scope.appsList, newAppsList);
-                if(source === "deviceready") {
-                    $scope.$apply();
-                }
-            }, function(error){
-                var str = "There was an error retrieving the apps list";
-                console.error(str + JSON.stringify(error));
-                alert(str);
-            });
-        };
-
-        $scope.launchApp = function(app){
-            AppsService.launchApp(app)
-            .then(null, function(error){
-                console.error("Error during loading of app: " + error);
-                alert("Something went wrong during the loading of the app. Please try again.");
-            });
-        };
-
-        $scope.refreshApp = function(app) {
-            alert("refreshApp called: " + app);
-        };
-
-        $scope.removeApp = function(app) {
-            alert("removeApp called: " + app);
-        };
-
-        $document.bind("deviceready", function() { $scope.loadAppsList("deviceready"); });
-    }]);
-})();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/js/ResourcesLoader.js
----------------------------------------------------------------------
diff --git a/js/ResourcesLoader.js b/js/ResourcesLoader.js
deleted file mode 100644
index 2b4f768..0000000
--- a/js/ResourcesLoader.js
+++ /dev/null
@@ -1,241 +0,0 @@
-(function() {
-    "use strict";
-
-    /* global myApp */
-    myApp.factory("ResourcesLoader", [ "$window", "$document", function ($window, $document)
{
-        var fs;
-        var initialised = false;
-
-        function initialise() {
-            initialised = true;
-
-            var failedFileSystemLookUp = function (error) {
-                var errorString = "An error occurred while reading the file system.";
-                if(error) {
-                    errorString += " " + JSON.stringify(error);
-                }
-                console.error(errorString);
-            };
-
-            var success = function(_fs) {
-                fs = _fs;
-            };
-
-            try {
-                $window.requestFileSystem($window.LocalFileSystem.PERSISTENT, 0, success,
failedFileSystemLookUp);
-            } catch (e) {
-                failedFileSystemLookUp(e);
-            }
-        }
-
-        $document.bind("deviceready", function() { initialise(); });
-
-        //promise returns full path to downloaded file
-        function downloadFromUrl(url, fullFilePath) {
-            var deferred = Q.defer();
-
-            var downloadFail = function(error) {
-                var str = "There was an error while downloading the file " + JSON.stringify(error);
-                deferred.reject(new Error(str));
-            };
-
-            var downloadSuccess = function(fileEntry) {
-                deferred.resolve(fileEntry.fullPath);
-            };
-
-            var fileTransfer = new $window.FileTransfer();
-            var uri = encodeURI(url);
-            fileTransfer.download(uri, fullFilePath, downloadSuccess, downloadFail);
-            return deferred.promise;
-        }
-
-        function trim(str) {
-            return str && str.replace(/^\s+|\s+$/g, "");
-        }
-
-        function makeRelativeToRoot(path) {
-            if(path && (path.charAt(0) === "/")) {
-                path = path.substring(1);
-            } else if(path && path.substring(0, 8) === "file:///") {
-                path = path.substring(8);
-            }
-            return path;
-        }
-
-        //promise returns the file entry
-        function getFileEntry(fileName) {
-            var deferred = Q.defer();
-
-            var errorWhileGettingFileEntry = function(error) {
-                var str = "There was an error while getting the file entry for file " + fileName
+ " " + JSON.stringify(error);
-                deferred.reject(new Error(str));
-            };
-            var success = function(fileEntry) {
-                deferred.resolve(fileEntry);
-            };
-            fs.root.getFile(fileName, {create: true, exclusive: false}, success, errorWhileGettingFileEntry);
-            return deferred.promise;
-        }
-
-        //promise returns the file
-        function getFile(fileName) {
-            return getFileEntry(fileName).
-            then(function(fileEntry){
-                var deferred = Q.defer();
-
-                var errorWhileGettingFile = function(error) {
-                    var str = "There was an error while getting the file for file " + fileName
+ " " + JSON.stringify(error);
-                    deferred.reject(new Error(str));
-                };
-
-                fileEntry.file(deferred.resolve, errorWhileGettingFile);
-                return deferred.promise;
-            });
-        }
-
-        function truncateToDirectoryPath(path) {
-            //remove the filename if it exists
-            var lastLevelIndex = path.search(/[\w ]+(\.[\w ]+)+$/g);
-            if(lastLevelIndex !== -1) {
-                path = path.substring(0, lastLevelIndex);
-            }
-            return path;
-        }
-
-        return {
-            // returns a promise with a full path to the dir
-            ensureDirectoryExists : function(directory) {
-                var deferred = Q.defer();
-
-                directory = truncateToDirectoryPath(directory);
-                directory = makeRelativeToRoot(directory);
-
-                var gotDirEntry = function(dirEntry) {
-                    deferred.resolve(dirEntry.fullPath);
-                };
-
-                var failedToGetDirEntry = function(error) {
-                    var str = "There was an error checking the directory: " + directory +
" " + JSON.stringify(error);
-                    deferred.reject(new Error(str));
-                };
-
-                fs.root.getDirectory(directory, {create: true, exclusive: false}, gotDirEntry,
failedToGetDirEntry);
-                return deferred.promise;
-            },
-
-            // promise returns full path to file
-            getFullFilePath : function(filePath) {
-                var deferred = Q.defer();
-
-                // Use the file's parent folder to get the full path
-                var directory = filePath;
-                var fileName = "";
-
-                //remove the filename if it exists
-                var lastLevelIndex = directory.search(/\/[\w ]+\.[\w ]+$/g);
-                if(lastLevelIndex !== -1) {
-                    directory = filePath.substring(0, lastLevelIndex);
-                    fileName = filePath.substring(lastLevelIndex + 1);
-                }
-
-                //we need the directory name w.r.t the root, so remove any slashes in the
beginning
-                if(directory.indexOf("/") === 0) {
-                    directory = directory.substring(1);
-                }
-
-                var gotFullPath = function(dirEntry) {
-                    var fullFilePath = dirEntry.fullPath + "/" + fileName;
-                    deferred.resolve(fullFilePath);
-                };
-
-                var failedToGetFullPath = function(error) {
-                    var str = "There was an error getting the full path of file: " + filePath
+ " " + JSON.stringify(error);
-                    deferred.reject(new Error(str));
-                };
-
-                fs.root.getDirectory(directory, {create: true, exclusive: false}, gotFullPath,
failedToGetFullPath);
-                return deferred.promise;
-            },
-
-            // returns a promise with a full path to the downloaded file
-            downloadFromUrl : function(url, filePath) {
-                var self = this;
-                return this.ensureDirectoryExists(filePath)
-                .then(function(){
-                    return self.getFullFilePath(filePath);
-                })
-                .then(function(fullFilePath){
-                    return downloadFromUrl(url, fullFilePath);
-                });
-            },
-
-            //returns a promise with the contents of the file
-            readFileContents : function(fileName) {
-                return getFile(fileName)
-                .then(function(file){
-                    var deferred = Q.defer();
-
-                    var reader = new $window.FileReader();
-                    reader.onload = function(evt) {
-                        var text = evt.target.result;
-                        deferred.resolve(text);
-                    };
-                    reader.onerror = function(evt) {
-                        deferred.reject(new Error(evt));
-                    };
-                    reader.readAsText(file);
-
-                    return deferred.promise;
-                });
-            },
-
-            //returns a promise with the json contents of the file
-            readJSONFileContents : function(fileName) {
-                return this.readFileContents(fileName)
-                .then(function (text) {
-                    text = trim(text);
-                    var resultJson = {};
-                    if(text) {
-                        resultJson = JSON.parse(text);
-                    }
-                    return resultJson;
-                });
-            },
-
-            //returns a promise when file is written
-            writeFileContents : function(fileName, contents) {
-                return getFileEntry(fileName)
-                .then(function(fileEntry){
-                    var deferred = Q.defer();
-
-                    var errorGettingFileWriter = function(error) {
-                        var str = "There was an error writing the file." + JSON.stringify(error);
-                        deferred.reject(new Error(str));
-                    };
-
-                    var gotFileWriter = function(writer) {
-                        writer.onwrite = deferred.resolve;
-                        writer.onerror = function(evt) {
-                            deferred.reject(new Error(evt));
-                        };
-                        writer.write(contents);
-                    };
-                    fileEntry.createWriter(gotFileWriter, errorGettingFileWriter);
-                    return deferred.promise;
-                });
-            },
-
-            //returns a promise when json file is written
-            writeJSONFileContents : function(fileName, contents) {
-                var stringContents;
-                if(typeof contents === "string") {
-                    stringContents = contents;
-                } else {
-                    stringContents = JSON.stringify(contents);
-                }
-                return this.writeFileContents(fileName, stringContents);
-            }
-        };
-    }]);
-
-})();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/022ebbbe/js/app.js
----------------------------------------------------------------------
diff --git a/js/app.js b/js/app.js
deleted file mode 100644
index 962571e..0000000
--- a/js/app.js
+++ /dev/null
@@ -1,11 +0,0 @@
-var myApp = angular.module("CordovaAppHarness", []);
-myApp.config(["$routeProvider", function($routeProvider){
-    $routeProvider.when("/", {
-        templateUrl: "views/list.html",
-        controller: "ListCtrl"
-    });
-    $routeProvider.when("/add", {
-        templateUrl: "views/add.html",
-        controller: "AddCtrl"
-    });
-}]);
\ No newline at end of file


Mime
View raw message