From 13676c1c84def271ac667e7ee46d6b1cd1e64a1b Mon Sep 17 00:00:00 2001 From: Yail Peralta Date: Mon, 20 Jun 2016 21:04:41 -0300 Subject: [PATCH 1/2] Wikitude cordova plugin added --- dist/ng-cordova.js | 147 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 1 deletion(-) diff --git a/dist/ng-cordova.js b/dist/ng-cordova.js index a59620b6..3b7d5c49 100644 --- a/dist/ng-cordova.js +++ b/dist/ng-cordova.js @@ -5589,6 +5589,7 @@ angular.module('ngCordova.plugins', [ 'ngCordova.plugins.touchid', 'ngCordova.plugins.vibration', 'ngCordova.plugins.videoCapturePlus', + 'ngCordova.plugins.wikitudePlugin', 'ngCordova.plugins.zip', 'ngCordova.plugins.insomnia' ]); @@ -7031,6 +7032,150 @@ angular.module('ngCordova.plugins.videoCapturePlus', []) }; }]; }]); + +// install : cordova plugin add https://github.com/Wikitude/wikitude-cordova-plugin.git + +angular.module('ngCordova.plugins.wikitudePlugin', []) + + .factory('$wikitudePlugin', ['$q', '$window', '$exceptionHandler', function ($q, $window, $exceptionHandler) { + + return { + /** + * internal listeners for success and error, they are invoked in cordova.exec() function + */ + setInternalListeners: function () { + $window.plugins.wikitudePlugin.prototype.onWikitudeOK = function (success) { + //success callback + }; + + $window.plugins.wikitudePlugin.prototype.onWikitudeError = function (error) { + // error callback + throw (error); + }; + }, + + /** + * array of requiredFeatures for instance [ "2d_tracking", "geo" ] + * if no argument is passed the default value is 2d tracking + * @param requiredFeatures + * @returns {*} + */ + isDeviceSupported: function(requiredFeatures) { + + // set the internal listeners for success and error + this.setInternalListeners(); + + var self = this; + var q = $q.defer(); + + // store features in the $wikitudePlugin for accessing it in all methods + self.features = requiredFeatures || [ '2d_tracking' ]; + + $window.plugins.wikitudePlugin.isDeviceSupported(function () { + //device supported + q.resolve(self); + }, function () { + //device not supported + q.reject('device not supported!'); + }, self.features); + + return q.promise; + }, + + /** + * + * @param worldPath + * @param startupConfiguration + */ + loadARchitectWorld: function (worldPath, startupConfiguration) { + var q = $q.defer(); + + // startup configuration converted to json + var config = JSON.stringify( startupConfiguration || { 'camera_position': 'back' } ); + + if (typeof worldPath === 'string') { + + $window.plugins.wikitudePlugin.loadARchitectWorld(function (loadedURL) { + // loadedSuccessful + q.resolve(loadedURL); + }, function (errorMessage) { + // error local path is wrong or the remote url returned an error code + q.reject(errorMessage); + },worldPath, this.features, config); + } + + return q.promise; + }, + + /** + * inject a location into the Wikitude SDK + * @param latitude + * @param longitude + * @param altitude + * @param accuracy + */ + setLocation: function (latitude, longitude, altitude, accuracy) { + try { + //inject a location into the Wikitude SDK + $window.plugins.wikitudePlugin.setLocation(latitude, longitude, altitude, accuracy); + } catch (e) { + // handle execption + $exceptionHandler(e.message); + } + }, + + /** + * The first argument Indicates if the ARchitect + * web view should be included in the generated screenshot or not. + * If a file path or file name is given in the second argument, + * the generated screenshot will be saved in the application bundle. + * Passing null will save the photo in the device photo library + * @param includeWebView + * @param imagePath + * @returns {*} + */ + captureScreen: function (includeWebView, imagePath) { + var q = $q.defer(); + + $window.plugins.wikitudePlugin.captureScreen(includeWebView, imagePath, function (bundlePath) { + //success + q.resolve(bundlePath); + }, function (error) { + //error + q.reject(error); + }); + + return q.promise; + }, + + callJavaScript: function (js) { + try { + $window.plugins.wikitudePlugin.callJavaScript(js); + } catch (e) { + $exceptionHandler(e); + } + }, + + setOnUrlInvokeCallback: function (onUrlInvokeCallback) { + $window.plugins.wikitudePlugin.setOnUrlInvokeCallback(onUrlInvokeCallback); + }, + + + close: function () { + $window.plugins.wikitudePlugin.close(); + }, + + show: function () { + $window.plugins.wikitudePlugin.show(); + }, + + hide: function () { + $window.plugins.wikitudePlugin.hide(); + } + + };// end of wikitudePlugin factory + + }]); // install : cordova plugin add https://github.com/MobileChromeApps/zip.git // link : https://github.com/MobileChromeApps/zip @@ -7058,4 +7203,4 @@ angular.module('ngCordova.plugins.zip', []) }; }]); -})(); \ No newline at end of file +})(); From 02e3bd47789421b6d6abeeca2ffbc4ab416fc163 Mon Sep 17 00:00:00 2001 From: yailPeralta Date: Fri, 29 Jul 2016 19:43:10 -0300 Subject: [PATCH 2/2] wikitudePlugin --- src/plugins/module.js | 1 + src/plugins/wikitudePlugin.js | 151 ++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 src/plugins/wikitudePlugin.js diff --git a/src/plugins/module.js b/src/plugins/module.js index 829e90fe..2bfb2d5c 100644 --- a/src/plugins/module.js +++ b/src/plugins/module.js @@ -71,6 +71,7 @@ angular.module('ngCordova.plugins', [ 'ngCordova.plugins.touchid', 'ngCordova.plugins.vibration', 'ngCordova.plugins.videoCapturePlus', + 'ngCordova.plugins.wikitudePlugin', 'ngCordova.plugins.zip', 'ngCordova.plugins.insomnia' ]); diff --git a/src/plugins/wikitudePlugin.js b/src/plugins/wikitudePlugin.js new file mode 100644 index 00000000..101867b8 --- /dev/null +++ b/src/plugins/wikitudePlugin.js @@ -0,0 +1,151 @@ +/** + * Created by yailanderson on 10/06/16. + */ +'use strict'; + +// install : cordova plugin add https://github.com/Wikitude/wikitude-cordova-plugin.git + +(function (angular) { + + angular.module('ngCordova.plugins.wikitudePlugin', []) + .factory('$wikitudePlugin', ['$q', '$window', '$exceptionHandler', function ($q, $window, $exceptionHandler) { + + return { + /** + * internal listeners for success and error, they are invoked in cordova.exec() function + */ + setInternalListeners: function () { + $window.plugins.wikitudePlugin.prototype.onWikitudeOK = function () { + //success callback + }; + + $window.plugins.wikitudePlugin.prototype.onWikitudeError = function (error) { + // error callback + throw (error); + }; + }, + + /** + * array of requiredFeatures for instance [ "2d_tracking", "geo" ] + * if no argument is passed the default value is 2d tracking + * @param requiredFeatures + * @returns {*} + */ + isDeviceSupported: function (requiredFeatures) { + + // set the internal listeners for success and error + this.setInternalListeners(); + + var self = this; + var q = $q.defer(); + + // store features in the $wikitudePlugin for accessing it in all methods + self.features = requiredFeatures || [ '2d_tracking' ]; + + $window.plugins.wikitudePlugin.isDeviceSupported(function () { + //device supported + q.resolve(self); + }, function () { + //device not supported + q.reject('device not supported!'); + }, self.features); + + return q.promise; + }, + + /** + * + * @param worldPath + * @param startupConfiguration + */ + loadARchitectWorld: function (worldPath, startupConfiguration) { + var q = $q.defer(); + + // startup configuration converted to json + var config = JSON.stringify( startupConfiguration || { 'camera_position': 'back' } ); + + if (typeof worldPath === 'string') { + + $window.plugins.wikitudePlugin.loadARchitectWorld(function (loadedURL) { + // loadedSuccessful + q.resolve(loadedURL); + }, function (errorMessage) { + // error local path is wrong or the remote url returned an error code + q.reject(errorMessage); + },worldPath, this.features, config); + } + + return q.promise; + }, + + /** + * inject a location into the Wikitude SDK + * @param latitude + * @param longitude + * @param altitude + * @param accuracy + */ + setLocation: function (latitude, longitude, altitude, accuracy) { + try { + //inject a location into the Wikitude SDK + $window.plugins.wikitudePlugin.setLocation(latitude, longitude, altitude, accuracy); + } catch (e) { + // handle execption + $exceptionHandler(e.message); + } + }, + + /** + * The first argument Indicates if the ARchitect + * web view should be included in the generated screenshot or not. + * If a file path or file name is given in the second argument, + * the generated screenshot will be saved in the application bundle. + * Passing null will save the photo in the device photo library + * @param includeWebView + * @param imagePath + * @returns {*} + */ + captureScreen: function (includeWebView, imagePath) { + var q = $q.defer(); + + $window.plugins.wikitudePlugin.captureScreen(includeWebView, imagePath, function (bundlePath) { + //success + q.resolve(bundlePath); + }, function (error) { + //error + q.reject(error); + }); + + return q.promise; + }, + + callJavaScript: function (js) { + try { + $window.plugins.wikitudePlugin.callJavaScript(js); + } catch (e) { + $exceptionHandler(e); + } + }, + + setOnUrlInvokeCallback: function (onUrlInvokeCallback) { + $window.plugins.wikitudePlugin.setOnUrlInvokeCallback(onUrlInvokeCallback); + }, + + + close: function () { + $window.plugins.wikitudePlugin.close(); + }, + + show: function () { + $window.plugins.wikitudePlugin.show(); + }, + + hide: function () { + $window.plugins.wikitudePlugin.hide(); + } + + };// end of wikitudePlugin factory + + }]); + +})(window.angular);