You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7360 lines
199 KiB

  1. /*!
  2. * ngCordova
  3. * v0.1.27-alpha
  4. * Copyright 2015 Drifty Co. http://drifty.com/
  5. * See LICENSE in this repository for license information
  6. */
  7. (function(){
  8. angular.module('ngCordova', [
  9. 'ngCordova.plugins'
  10. ]);
  11. // install : cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-3dtouch.git
  12. // link : https://github.com/EddyVerbruggen/cordova-plugin-3dtouch
  13. angular.module('ngCordova.plugins.3dtouch', [])
  14. .factory('$cordova3DTouch', ['$q', function($q) {
  15. var quickActions = [];
  16. var quickActionHandler = {};
  17. var createQuickActionHandler = function(quickActionHandler) {
  18. return function (payload) {
  19. for (var key in quickActionHandler) {
  20. if (payload.type === key) {
  21. quickActionHandler[key]();
  22. }
  23. }
  24. };
  25. };
  26. return {
  27. /*
  28. * Checks if Cordova 3D touch is present and loaded
  29. *
  30. * @return promise
  31. */
  32. isAvailable: function () {
  33. var deferred = $q.defer();
  34. if (!window.cordova) {
  35. deferred.reject('Not supported in browser');
  36. } else {
  37. if (!window.ThreeDeeTouch) {
  38. deferred.reject('Could not find 3D touch plugin');
  39. } else {
  40. window.ThreeDeeTouch.isAvailable(function (value) {
  41. deferred.resolve(value);
  42. }, function (err) {
  43. deferred.reject(err);
  44. });
  45. }
  46. }
  47. return deferred.promise;
  48. },
  49. /*
  50. * Add a quick action to menu
  51. *
  52. * @param string type
  53. * @param string title
  54. * @param string iconType (optional)
  55. * @param string subtitle (optional)
  56. * @param function callback (optional)
  57. * @return promise
  58. */
  59. addQuickAction: function(type, title, iconType, iconTemplate, subtitle, callback) {
  60. var deferred = $q.defer();
  61. var quickAction = {
  62. type: type,
  63. title: title,
  64. subtitle: subtitle
  65. };
  66. if (iconType) {
  67. quickAction.iconType = iconType;
  68. }
  69. if (iconTemplate) {
  70. quickAction.iconTemplate = iconTemplate;
  71. }
  72. this.isAvailable().then(function() {
  73. quickActions.push(quickAction);
  74. quickActionHandler[type] = callback;
  75. window.ThreeDeeTouch.configureQuickActions(quickActions);
  76. window.ThreeDeeTouch.onHomeIconPressed = createQuickActionHandler(quickActionHandler);
  77. deferred.resolve(quickActions);
  78. },
  79. function(err) {
  80. deferred.reject(err);
  81. });
  82. return deferred.promise;
  83. },
  84. /*
  85. * Add a quick action handler. Used for static quick actions
  86. *
  87. * @param string type
  88. * @param function callback
  89. * @return promise
  90. */
  91. addQuickActionHandler: function(type, callback) {
  92. var deferred = $q.defer();
  93. this.isAvailable().then(function() {
  94. quickActionHandler[type] = callback;
  95. window.ThreeDeeTouch.onHomeIconPressed = createQuickActionHandler(quickActionHandler);
  96. deferred.resolve(true);
  97. },
  98. function(err) {
  99. deferred.reject(err);
  100. });
  101. return deferred.promise;
  102. },
  103. /*
  104. * Enable link preview popup when force touch is appled to link elements
  105. *
  106. * @return bool
  107. */
  108. enableLinkPreview: function() {
  109. var deferred = $q.defer();
  110. this.isAvailable().then(function() {
  111. window.ThreeDeeTouch.enableLinkPreview();
  112. deferred.resolve(true);
  113. },
  114. function(err) {
  115. deferred.reject(err);
  116. });
  117. return deferred.promise;
  118. },
  119. /*
  120. * Add a hanlder function for force touch events,
  121. *
  122. * @param function callback
  123. * @return promise
  124. */
  125. addForceTouchHandler: function(callback) {
  126. var deferred = $q.defer();
  127. this.isAvailable().then(function() {
  128. window.ThreeDeeTouch.watchForceTouches(callback);
  129. deferred.resolve(true);
  130. },
  131. function(err) {
  132. deferred.reject(err);
  133. });
  134. return deferred.promise;
  135. }
  136. };
  137. }]);
  138. // install : cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-actionsheet.git
  139. // link : https://github.com/EddyVerbruggen/cordova-plugin-actionsheet
  140. angular.module('ngCordova.plugins.actionSheet', [])
  141. .factory('$cordovaActionSheet', ['$q', '$window', function ($q, $window) {
  142. return {
  143. show: function (options) {
  144. var q = $q.defer();
  145. $window.plugins.actionsheet.show(options, function (result) {
  146. q.resolve(result);
  147. });
  148. return q.promise;
  149. },
  150. hide: function () {
  151. return $window.plugins.actionsheet.hide();
  152. }
  153. };
  154. }]);
  155. // install : cordova plugin add https://github.com/floatinghotpot/cordova-plugin-admob.git
  156. // link : https://github.com/floatinghotpot/cordova-plugin-admob
  157. angular.module('ngCordova.plugins.adMob', [])
  158. .factory('$cordovaAdMob', ['$q', '$window', function ($q, $window) {
  159. return {
  160. createBannerView: function (options) {
  161. var d = $q.defer();
  162. $window.plugins.AdMob.createBannerView(options, function () {
  163. d.resolve();
  164. }, function () {
  165. d.reject();
  166. });
  167. return d.promise;
  168. },
  169. createInterstitialView: function (options) {
  170. var d = $q.defer();
  171. $window.plugins.AdMob.createInterstitialView(options, function () {
  172. d.resolve();
  173. }, function () {
  174. d.reject();
  175. });
  176. return d.promise;
  177. },
  178. requestAd: function (options) {
  179. var d = $q.defer();
  180. $window.plugins.AdMob.requestAd(options, function () {
  181. d.resolve();
  182. }, function () {
  183. d.reject();
  184. });
  185. return d.promise;
  186. },
  187. showAd: function (options) {
  188. var d = $q.defer();
  189. $window.plugins.AdMob.showAd(options, function () {
  190. d.resolve();
  191. }, function () {
  192. d.reject();
  193. });
  194. return d.promise;
  195. },
  196. requestInterstitialAd: function (options) {
  197. var d = $q.defer();
  198. $window.plugins.AdMob.requestInterstitialAd(options, function () {
  199. d.resolve();
  200. }, function () {
  201. d.reject();
  202. });
  203. return d.promise;
  204. }
  205. };
  206. }]);
  207. // install : cordova plugin add https://github.com/ohh2ahh/AppAvailability.git
  208. // link : https://github.com/ohh2ahh/AppAvailability
  209. /* globals appAvailability: true */
  210. angular.module('ngCordova.plugins.appAvailability', [])
  211. .factory('$cordovaAppAvailability', ['$q', function ($q) {
  212. return {
  213. check: function (urlScheme) {
  214. var q = $q.defer();
  215. appAvailability.check(urlScheme, function (result) {
  216. q.resolve(result);
  217. }, function (err) {
  218. q.reject(err);
  219. });
  220. return q.promise;
  221. }
  222. };
  223. }]);
  224. // install : cordova plugin add https://github.com/pushandplay/cordova-plugin-apprate.git
  225. // link : https://github.com/pushandplay/cordova-plugin-apprate
  226. /* globals AppRate: true */
  227. angular.module('ngCordova.plugins.appRate', [])
  228. .provider('$cordovaAppRate', [function () {
  229. /**
  230. * Set defaults settings to AppRate
  231. *
  232. * @param {Object} defaults - AppRate default settings
  233. * @param {string} defaults.language
  234. * @param {string} defaults.appName
  235. * @param {boolean} defaults.promptForNewVersion
  236. * @param {boolean} defaults.openStoreInApp
  237. * @param {number} defaults.usesUntilPrompt
  238. * @param {boolean} defaults.useCustomRateDialog
  239. * @param {string} defaults.iosURL
  240. * @param {string} defaults.androidURL
  241. * @param {string} defaults.blackberryURL
  242. * @param {string} defaults.windowsURL
  243. */
  244. this.setPreferences = function (defaults) {
  245. if (!defaults || !angular.isObject(defaults)) {
  246. return;
  247. }
  248. AppRate.preferences.useLanguage = defaults.language || null;
  249. AppRate.preferences.displayAppName = defaults.appName || '';
  250. AppRate.preferences.promptAgainForEachNewVersion = defaults.promptForNewVersion || true;
  251. AppRate.preferences.openStoreInApp = defaults.openStoreInApp || false;
  252. AppRate.preferences.usesUntilPrompt = defaults.usesUntilPrompt || 3;
  253. AppRate.preferences.useCustomRateDialog = defaults.useCustomRateDialog || false;
  254. AppRate.preferences.storeAppURL.ios = defaults.iosURL || null;
  255. AppRate.preferences.storeAppURL.android = defaults.androidURL || null;
  256. AppRate.preferences.storeAppURL.blackberry = defaults.blackberryURL || null;
  257. AppRate.preferences.storeAppURL.windows8 = defaults.windowsURL || null;
  258. };
  259. /**
  260. * Set custom locale
  261. *
  262. * @param {Object} customObj
  263. * @param {string} customObj.title
  264. * @param {string} customObj.message
  265. * @param {string} customObj.cancelButtonLabel
  266. * @param {string} customObj.laterButtonLabel
  267. * @param {string} customObj.rateButtonLabel
  268. */
  269. this.setCustomLocale = function (customObj) {
  270. var strings = {
  271. title: 'Rate %@',
  272. message: 'If you enjoy using %@, would you mind taking a moment to rate it? It won’t take more than a minute. Thanks for your support!',
  273. cancelButtonLabel: 'No, Thanks',
  274. laterButtonLabel: 'Remind Me Later',
  275. rateButtonLabel: 'Rate It Now'
  276. };
  277. strings = angular.extend(strings, customObj);
  278. AppRate.preferences.customLocale = strings;
  279. };
  280. this.$get = ['$q', function ($q) {
  281. return {
  282. promptForRating: function (immediate) {
  283. var q = $q.defer();
  284. var prompt = AppRate.promptForRating(immediate);
  285. q.resolve(prompt);
  286. return q.promise;
  287. },
  288. navigateToAppStore: function () {
  289. var q = $q.defer();
  290. var navigate = AppRate.navigateToAppStore();
  291. q.resolve(navigate);
  292. return q.promise;
  293. },
  294. onButtonClicked: function (cb) {
  295. AppRate.preferences.callbacks.onButtonClicked = cb.bind(this);
  296. },
  297. onRateDialogShow: function (cb) {
  298. AppRate.preferences.callbacks.onRateDialogShow = cb.bind(this);
  299. }
  300. };
  301. }];
  302. }]);
  303. // install : cordova plugin add https://github.com/whiteoctober/cordova-plugin-app-version.git
  304. // link : https://github.com/whiteoctober/cordova-plugin-app-version
  305. angular.module('ngCordova.plugins.appVersion', [])
  306. .factory('$cordovaAppVersion', ['$q', function ($q) {
  307. return {
  308. getAppName: function () {
  309. var q = $q.defer();
  310. cordova.getAppVersion.getAppName(function (name) {
  311. q.resolve(name);
  312. });
  313. return q.promise;
  314. },
  315. getPackageName: function () {
  316. var q = $q.defer();
  317. cordova.getAppVersion.getPackageName(function (pack) {
  318. q.resolve(pack);
  319. });
  320. return q.promise;
  321. },
  322. getVersionNumber: function () {
  323. var q = $q.defer();
  324. cordova.getAppVersion.getVersionNumber(function (version) {
  325. q.resolve(version);
  326. });
  327. return q.promise;
  328. },
  329. getVersionCode: function () {
  330. var q = $q.defer();
  331. cordova.getAppVersion.getVersionCode(function (code) {
  332. q.resolve(code);
  333. });
  334. return q.promise;
  335. }
  336. };
  337. }]);
  338. // install : cordova plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git
  339. // link : https://github.com/christocracy/cordova-plugin-background-geolocation
  340. angular.module('ngCordova.plugins.backgroundGeolocation', [])
  341. .factory('$cordovaBackgroundGeolocation', ['$q', '$window', function ($q, $window) {
  342. return {
  343. init: function () {
  344. $window.navigator.geolocation.getCurrentPosition(function (location) {
  345. return location;
  346. });
  347. },
  348. configure: function (options) {
  349. this.init();
  350. var q = $q.defer();
  351. $window.plugins.backgroundGeoLocation.configure(
  352. function (result) {
  353. q.notify(result);
  354. $window.plugins.backgroundGeoLocation.finish();
  355. },
  356. function (err) {
  357. q.reject(err);
  358. }, options);
  359. this.start();
  360. return q.promise;
  361. },
  362. start: function () {
  363. var q = $q.defer();
  364. $window.plugins.backgroundGeoLocation.start(
  365. function (result) {
  366. q.resolve(result);
  367. },
  368. function (err) {
  369. q.reject(err);
  370. });
  371. return q.promise;
  372. },
  373. stop: function () {
  374. var q = $q.defer();
  375. $window.plugins.backgroundGeoLocation.stop(
  376. function (result) {
  377. q.resolve(result);
  378. },
  379. function (err) {
  380. q.reject(err);
  381. });
  382. return q.promise;
  383. }
  384. };
  385. }
  386. ]);
  387. // install : cordova plugin add https://github.com/katzer/cordova-plugin-badge.git
  388. // link : https://github.com/katzer/cordova-plugin-badge
  389. angular.module('ngCordova.plugins.badge', [])
  390. .factory('$cordovaBadge', ['$q', function ($q) {
  391. return {
  392. hasPermission: function () {
  393. var q = $q.defer();
  394. cordova.plugins.notification.badge.hasPermission(function (permission) {
  395. if (permission) {
  396. q.resolve(true);
  397. } else {
  398. q.reject('You do not have permission');
  399. }
  400. });
  401. return q.promise;
  402. },
  403. promptForPermission: function () {
  404. return cordova.plugins.notification.badge.promptForPermission();
  405. },
  406. set: function (badge, callback, scope) {
  407. var q = $q.defer();
  408. cordova.plugins.notification.badge.hasPermission(function (permission) {
  409. if (permission) {
  410. q.resolve(
  411. cordova.plugins.notification.badge.set(badge, callback, scope)
  412. );
  413. } else {
  414. q.reject('You do not have permission to set Badge');
  415. }
  416. });
  417. return q.promise;
  418. },
  419. get: function () {
  420. var q = $q.defer();
  421. cordova.plugins.notification.badge.hasPermission(function (permission) {
  422. if (permission) {
  423. cordova.plugins.notification.badge.get(function (badge) {
  424. q.resolve(badge);
  425. });
  426. } else {
  427. q.reject('You do not have permission to get Badge');
  428. }
  429. });
  430. return q.promise;
  431. },
  432. clear: function (callback, scope) {
  433. var q = $q.defer();
  434. cordova.plugins.notification.badge.hasPermission(function (permission) {
  435. if (permission) {
  436. q.resolve(cordova.plugins.notification.badge.clear(callback, scope));
  437. } else {
  438. q.reject('You do not have permission to clear Badge');
  439. }
  440. });
  441. return q.promise;
  442. },
  443. increase: function (count, callback, scope) {
  444. var q = $q.defer();
  445. this.hasPermission().then(function (){
  446. q.resolve(
  447. cordova.plugins.notification.badge.increase(count, callback, scope)
  448. );
  449. }, function (){
  450. q.reject('You do not have permission to increase Badge');
  451. }) ;
  452. return q.promise;
  453. },
  454. decrease: function (count, callback, scope) {
  455. var q = $q.defer();
  456. this.hasPermission().then(function (){
  457. q.resolve(
  458. cordova.plugins.notification.badge.decrease(count, callback, scope)
  459. );
  460. }, function (){
  461. q.reject('You do not have permission to decrease Badge');
  462. }) ;
  463. return q.promise;
  464. },
  465. configure: function (config) {
  466. return cordova.plugins.notification.badge.configure(config);
  467. }
  468. };
  469. }]);
  470. // install : cordova plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner.git
  471. // link : https://github.com/phonegap/phonegap-plugin-barcodescanner
  472. angular.module('ngCordova.plugins.barcodeScanner', [])
  473. .factory('$cordovaBarcodeScanner', ['$q', function ($q) {
  474. return {
  475. scan: function (config) {
  476. var q = $q.defer();
  477. cordova.plugins.barcodeScanner.scan(function (result) {
  478. q.resolve(result);
  479. }, function (err) {
  480. q.reject(err);
  481. }, config);
  482. return q.promise;
  483. },
  484. encode: function (type, data) {
  485. var q = $q.defer();
  486. type = type || 'TEXT_TYPE';
  487. cordova.plugins.barcodeScanner.encode(type, data, function (result) {
  488. q.resolve(result);
  489. }, function (err) {
  490. q.reject(err);
  491. });
  492. return q.promise;
  493. }
  494. };
  495. }]);
  496. // install : cordova plugin add cordova-plugin-battery-status
  497. // link : https://github.com/apache/cordova-plugin-battery-status
  498. angular.module('ngCordova.plugins.batteryStatus', [])
  499. .factory('$cordovaBatteryStatus', ['$rootScope', '$window', '$timeout', function ($rootScope, $window, $timeout) {
  500. /**
  501. * @param {string} status
  502. */
  503. var batteryStatus = function (status) {
  504. $timeout(function () {
  505. $rootScope.$broadcast('$cordovaBatteryStatus:status', status);
  506. });
  507. };
  508. /**
  509. * @param {string} status
  510. */
  511. var batteryCritical = function (status) {
  512. $timeout(function () {
  513. $rootScope.$broadcast('$cordovaBatteryStatus:critical', status);
  514. });
  515. };
  516. /**
  517. * @param {string} status
  518. */
  519. var batteryLow = function (status) {
  520. $timeout(function () {
  521. $rootScope.$broadcast('$cordovaBatteryStatus:low', status);
  522. });
  523. };
  524. document.addEventListener('deviceready', function () {
  525. if (navigator.battery) {
  526. $window.addEventListener('batterystatus', batteryStatus, false);
  527. $window.addEventListener('batterycritical', batteryCritical, false);
  528. $window.addEventListener('batterylow', batteryLow, false);
  529. }
  530. }, false);
  531. return true;
  532. }])
  533. .run(['$injector', function ($injector) {
  534. $injector.get('$cordovaBatteryStatus'); //ensure the factory and subsequent event listeners get initialised
  535. }]);
  536. // install : cordova plugin add https://github.com/petermetz/cordova-plugin-ibeacon.git
  537. // link : https://github.com/petermetz/cordova-plugin-ibeacon
  538. angular.module('ngCordova.plugins.beacon', [])
  539. .factory('$cordovaBeacon', ['$window', '$rootScope', '$timeout', '$q', function ($window, $rootScope, $timeout, $q) {
  540. var callbackDidDetermineStateForRegion = null;
  541. var callbackDidStartMonitoringForRegion = null;
  542. var callbackDidExitRegion = null;
  543. var callbackDidEnterRegion = null;
  544. var callbackDidRangeBeaconsInRegion = null;
  545. var callbackPeripheralManagerDidStartAdvertising = null;
  546. var callbackPeripheralManagerDidUpdateState = null;
  547. var callbackDidChangeAuthorizationStatus = null;
  548. document.addEventListener('deviceready', function () {
  549. if ($window.cordova &&
  550. $window.cordova.plugins &&
  551. $window.cordova.plugins.locationManager) {
  552. var delegate = new $window.cordova.plugins.locationManager.Delegate();
  553. delegate.didDetermineStateForRegion = function (pluginResult) {
  554. $timeout(function () {
  555. $rootScope.$broadcast('$cordovaBeacon:didDetermineStateForRegion', pluginResult);
  556. });
  557. if (callbackDidDetermineStateForRegion) {
  558. callbackDidDetermineStateForRegion(pluginResult);
  559. }
  560. };
  561. delegate.didStartMonitoringForRegion = function (pluginResult) {
  562. $timeout(function () {
  563. $rootScope.$broadcast('$cordovaBeacon:didStartMonitoringForRegion', pluginResult);
  564. });
  565. if (callbackDidStartMonitoringForRegion) {
  566. callbackDidStartMonitoringForRegion(pluginResult);
  567. }
  568. };
  569. delegate.didExitRegion = function (pluginResult) {
  570. $timeout(function () {
  571. $rootScope.$broadcast('$cordovaBeacon:didExitRegion', pluginResult);
  572. });
  573. if (callbackDidExitRegion) {
  574. callbackDidExitRegion(pluginResult);
  575. }
  576. };
  577. delegate.didEnterRegion = function (pluginResult) {
  578. $timeout(function () {
  579. $rootScope.$broadcast('$cordovaBeacon:didEnterRegion', pluginResult);
  580. });
  581. if (callbackDidEnterRegion) {
  582. callbackDidEnterRegion(pluginResult);
  583. }
  584. };
  585. delegate.didRangeBeaconsInRegion = function (pluginResult) {
  586. $timeout(function () {
  587. $rootScope.$broadcast('$cordovaBeacon:didRangeBeaconsInRegion', pluginResult);
  588. });
  589. if (callbackDidRangeBeaconsInRegion) {
  590. callbackDidRangeBeaconsInRegion(pluginResult);
  591. }
  592. };
  593. delegate.peripheralManagerDidStartAdvertising = function (pluginResult) {
  594. $timeout(function () {
  595. $rootScope.$broadcast('$cordovaBeacon:peripheralManagerDidStartAdvertising', pluginResult);
  596. });
  597. if (callbackPeripheralManagerDidStartAdvertising) {
  598. callbackPeripheralManagerDidStartAdvertising(pluginResult);
  599. }
  600. };
  601. delegate.peripheralManagerDidUpdateState = function (pluginResult) {
  602. $timeout(function () {
  603. $rootScope.$broadcast('$cordovaBeacon:peripheralManagerDidUpdateState', pluginResult);
  604. });
  605. if (callbackPeripheralManagerDidUpdateState) {
  606. callbackPeripheralManagerDidUpdateState(pluginResult);
  607. }
  608. };
  609. delegate.didChangeAuthorizationStatus = function (status) {
  610. $timeout(function () {
  611. $rootScope.$broadcast('$cordovaBeacon:didChangeAuthorizationStatus', status);
  612. });
  613. if (callbackDidChangeAuthorizationStatus) {
  614. callbackDidChangeAuthorizationStatus(status);
  615. }
  616. };
  617. $window.cordova.plugins.locationManager.setDelegate(delegate);
  618. }
  619. }, false);
  620. return {
  621. setCallbackDidDetermineStateForRegion: function (callback) {
  622. callbackDidDetermineStateForRegion = callback;
  623. },
  624. setCallbackDidStartMonitoringForRegion: function (callback) {
  625. callbackDidStartMonitoringForRegion = callback;
  626. },
  627. setCallbackDidExitRegion: function (callback) {
  628. callbackDidExitRegion = callback;
  629. },
  630. setCallbackDidEnterRegion: function (callback) {
  631. callbackDidEnterRegion = callback;
  632. },
  633. setCallbackDidRangeBeaconsInRegion: function (callback) {
  634. callbackDidRangeBeaconsInRegion = callback;
  635. },
  636. setCallbackPeripheralManagerDidStartAdvertising: function (callback) {
  637. callbackPeripheralManagerDidStartAdvertising = callback;
  638. },
  639. setCallbackPeripheralManagerDidUpdateState: function (callback) {
  640. callbackPeripheralManagerDidUpdateState = callback;
  641. },
  642. setCallbackDidChangeAuthorizationStatus: function (callback) {
  643. callbackDidChangeAuthorizationStatus = callback;
  644. },
  645. createBeaconRegion: function (identifier, uuid, major, minor, notifyEntryStateOnDisplay) {
  646. major = major || undefined;
  647. minor = minor || undefined;
  648. return new $window.cordova.plugins.locationManager.BeaconRegion(
  649. identifier,
  650. uuid,
  651. major,
  652. minor,
  653. notifyEntryStateOnDisplay
  654. );
  655. },
  656. isBluetoothEnabled: function () {
  657. return $q.when($window.cordova.plugins.locationManager.isBluetoothEnabled());
  658. },
  659. enableBluetooth: function () {
  660. return $q.when($window.cordova.plugins.locationManager.enableBluetooth());
  661. },
  662. disableBluetooth: function () {
  663. return $q.when($window.cordova.plugins.locationManager.disableBluetooth());
  664. },
  665. startMonitoringForRegion: function (region) {
  666. return $q.when($window.cordova.plugins.locationManager.startMonitoringForRegion(region));
  667. },
  668. stopMonitoringForRegion: function (region) {
  669. return $q.when($window.cordova.plugins.locationManager.stopMonitoringForRegion(region));
  670. },
  671. requestStateForRegion: function (region) {
  672. return $q.when($window.cordova.plugins.locationManager.requestStateForRegion(region));
  673. },
  674. startRangingBeaconsInRegion: function (region) {
  675. return $q.when($window.cordova.plugins.locationManager.startRangingBeaconsInRegion(region));
  676. },
  677. stopRangingBeaconsInRegion: function (region) {
  678. return $q.when($window.cordova.plugins.locationManager.stopRangingBeaconsInRegion(region));
  679. },
  680. getAuthorizationStatus: function () {
  681. return $q.when($window.cordova.plugins.locationManager.getAuthorizationStatus());
  682. },
  683. requestWhenInUseAuthorization: function () {
  684. return $q.when($window.cordova.plugins.locationManager.requestWhenInUseAuthorization());
  685. },
  686. requestAlwaysAuthorization: function () {
  687. return $q.when($window.cordova.plugins.locationManager.requestAlwaysAuthorization());
  688. },
  689. getMonitoredRegions: function () {
  690. return $q.when($window.cordova.plugins.locationManager.getMonitoredRegions());
  691. },
  692. getRangedRegions: function () {
  693. return $q.when($window.cordova.plugins.locationManager.getRangedRegions());
  694. },
  695. isRangingAvailable: function () {
  696. return $q.when($window.cordova.plugins.locationManager.isRangingAvailable());
  697. },
  698. isMonitoringAvailableForClass: function (region) {
  699. return $q.when($window.cordova.plugins.locationManager.isMonitoringAvailableForClass(region));
  700. },
  701. startAdvertising: function (region, measuredPower) {
  702. return $q.when($window.cordova.plugins.locationManager.startAdvertising(region, measuredPower));
  703. },
  704. stopAdvertising: function () {
  705. return $q.when($window.cordova.plugins.locationManager.stopAdvertising());
  706. },
  707. isAdvertisingAvailable: function () {
  708. return $q.when($window.cordova.plugins.locationManager.isAdvertisingAvailable());
  709. },
  710. isAdvertising: function () {
  711. return $q.when($window.cordova.plugins.locationManager.isAdvertising());
  712. },
  713. disableDebugLogs: function () {
  714. return $q.when($window.cordova.plugins.locationManager.disableDebugLogs());
  715. },
  716. enableDebugNotifications: function () {
  717. return $q.when($window.cordova.plugins.locationManager.enableDebugNotifications());
  718. },
  719. disableDebugNotifications: function () {
  720. return $q.when($window.cordova.plugins.locationManager.disableDebugNotifications());
  721. },
  722. enableDebugLogs: function () {
  723. return $q.when($window.cordova.plugins.locationManager.enableDebugLogs());
  724. },
  725. appendToDeviceLog: function (message) {
  726. return $q.when($window.cordova.plugins.locationManager.appendToDeviceLog(message));
  727. }
  728. };
  729. }]);
  730. // install : cordova plugin add https://github.com/don/cordova-plugin-ble-central.git
  731. // link : https://github.com/don/cordova-plugin-ble-central
  732. /* globals ble: true */
  733. angular.module('ngCordova.plugins.ble', [])
  734. .factory('$cordovaBLE', ['$q', '$timeout', '$log', function ($q, $timeout, $log) {
  735. return {
  736. scan: function (services, seconds) {
  737. var q = $q.defer();
  738. ble.startScan(services, function (result) {
  739. q.notify(result);
  740. }, function (error) {
  741. q.reject(error);
  742. });
  743. $timeout(function () {
  744. ble.stopScan(function () {
  745. q.resolve();
  746. }, function (error) {
  747. q.reject(error);
  748. });
  749. }, seconds*1000);
  750. return q.promise;
  751. },
  752. startScan: function (services, callback, errorCallback) {
  753. return ble.startScan(services, callback, errorCallback);
  754. },
  755. stopScan: function () {
  756. var q = $q.defer();
  757. ble.stopScan(function () {
  758. q.resolve();
  759. }, function (error) {
  760. q.reject(error);
  761. });
  762. return q.promise;
  763. },
  764. connect: function (deviceID) {
  765. var q = $q.defer();
  766. ble.connect(deviceID, function (result) {
  767. q.resolve(result);
  768. }, function (error) {
  769. q.reject(error);
  770. });
  771. return q.promise;
  772. },
  773. disconnect: function (deviceID) {
  774. var q = $q.defer();
  775. ble.disconnect(deviceID, function (result) {
  776. q.resolve(result);
  777. }, function (error) {
  778. q.reject(error);
  779. });
  780. return q.promise;
  781. },
  782. read: function (deviceID, serviceUUID, characteristicUUID) {
  783. var q = $q.defer();
  784. ble.read(deviceID, serviceUUID, characteristicUUID, function (result) {
  785. q.resolve(result);
  786. }, function (error) {
  787. q.reject(error);
  788. });
  789. return q.promise;
  790. },
  791. write: function (deviceID, serviceUUID, characteristicUUID, data) {
  792. var q = $q.defer();
  793. ble.write(deviceID, serviceUUID, characteristicUUID, data, function (result) {
  794. q.resolve(result);
  795. }, function (error) {
  796. q.reject(error);
  797. });
  798. return q.promise;
  799. },
  800. writeWithoutResponse: function (deviceID, serviceUUID, characteristicUUID, data) {
  801. var q = $q.defer();
  802. ble.writeWithoutResponse(deviceID, serviceUUID, characteristicUUID, data, function (result) {
  803. q.resolve(result);
  804. }, function (error) {
  805. q.reject(error);
  806. });
  807. return q.promise;
  808. },
  809. writeCommand: function (deviceID, serviceUUID, characteristicUUID, data) {
  810. $log.warning('writeCommand is deprecated, use writeWithoutResponse');
  811. return this.writeWithoutResponse(deviceID, serviceUUID, characteristicUUID, data);
  812. },
  813. startNotification: function (deviceID, serviceUUID, characteristicUUID, callback, errorCallback) {
  814. return ble.startNotification(deviceID, serviceUUID, characteristicUUID, callback, errorCallback);
  815. },
  816. stopNotification: function (deviceID, serviceUUID, characteristicUUID) {
  817. var q = $q.defer();
  818. ble.stopNotification(deviceID, serviceUUID, characteristicUUID, function (result) {
  819. q.resolve(result);
  820. }, function (error) {
  821. q.reject(error);
  822. });
  823. return q.promise;
  824. },
  825. isConnected: function (deviceID) {
  826. var q = $q.defer();
  827. ble.isConnected(deviceID, function (result) {
  828. q.resolve(result);
  829. }, function (error) {
  830. q.reject(error);
  831. });
  832. return q.promise;
  833. },
  834. enable: function () {
  835. var q = $q.defer();
  836. ble.enable(function (result) {
  837. q.resolve(result);
  838. }, function (error) {
  839. q.reject(error);
  840. });
  841. return q.promise;
  842. },
  843. isEnabled: function () {
  844. var q = $q.defer();
  845. ble.isEnabled(function (result) {
  846. q.resolve(result);
  847. }, function (error) {
  848. q.reject(error);
  849. });
  850. return q.promise;
  851. }
  852. };
  853. }]);
  854. // install : cordova plugin add https://github.com/don/BluetoothSerial.git
  855. // link : https://github.com/don/BluetoothSerial
  856. angular.module('ngCordova.plugins.bluetoothSerial', [])
  857. .factory('$cordovaBluetoothSerial', ['$q', '$window', function ($q, $window) {
  858. return {
  859. connect: function (address) {
  860. var q = $q.defer();
  861. var disconnectionPromise = $q.defer();
  862. var isConnected = false;
  863. $window.bluetoothSerial.connect(address, function () {
  864. isConnected = true;
  865. q.resolve(disconnectionPromise);
  866. }, function (error) {
  867. if(isConnected === false) {
  868. disconnectionPromise.reject(error);
  869. }
  870. q.reject(error);
  871. });
  872. return q.promise;
  873. },
  874. // not supported on iOS
  875. connectInsecure: function (address) {
  876. var q = $q.defer();
  877. $window.bluetoothSerial.connectInsecure(address, function () {
  878. q.resolve();
  879. }, function (error) {
  880. q.reject(error);
  881. });
  882. return q.promise;
  883. },
  884. disconnect: function () {
  885. var q = $q.defer();
  886. $window.bluetoothSerial.disconnect(function () {
  887. q.resolve();
  888. }, function (error) {
  889. q.reject(error);
  890. });
  891. return q.promise;
  892. },
  893. list: function () {
  894. var q = $q.defer();
  895. $window.bluetoothSerial.list(function (data) {
  896. q.resolve(data);
  897. }, function (error) {
  898. q.reject(error);
  899. });
  900. return q.promise;
  901. },
  902. discoverUnpaired: function () {
  903. var q = $q.defer();
  904. $window.bluetoothSerial.discoverUnpaired(function (data) {
  905. q.resolve(data);
  906. }, function (error) {
  907. q.reject(error);
  908. });
  909. return q.promise;
  910. },
  911. setDeviceDiscoveredListener: function () {
  912. var q = $q.defer();
  913. $window.bluetoothSerial.setDeviceDiscoveredListener(function (data) {
  914. q.notify(data);
  915. });
  916. return q.promise;
  917. },
  918. clearDeviceDiscoveredListener: function () {
  919. $window.bluetoothSerial.clearDeviceDiscoveredListener();
  920. },
  921. showBluetoothSettings: function () {
  922. var q = $q.defer();
  923. $window.bluetoothSerial.showBluetoothSettings(function () {
  924. q.resolve();
  925. }, function (error) {
  926. q.reject(error);
  927. });
  928. return q.promise;
  929. },
  930. isEnabled: function () {
  931. var q = $q.defer();
  932. $window.bluetoothSerial.isEnabled(function () {
  933. q.resolve();
  934. }, function () {
  935. q.reject();
  936. });
  937. return q.promise;
  938. },
  939. enable: function () {
  940. var q = $q.defer();
  941. $window.bluetoothSerial.enable(function () {
  942. q.resolve();
  943. }, function () {
  944. q.reject();
  945. });
  946. return q.promise;
  947. },
  948. isConnected: function () {
  949. var q = $q.defer();
  950. $window.bluetoothSerial.isConnected(function () {
  951. q.resolve();
  952. }, function () {
  953. q.reject();
  954. });
  955. return q.promise;
  956. },
  957. available: function () {
  958. var q = $q.defer();
  959. $window.bluetoothSerial.available(function (data) {
  960. q.resolve(data);
  961. }, function (error) {
  962. q.reject(error);
  963. });
  964. return q.promise;
  965. },
  966. read: function () {
  967. var q = $q.defer();
  968. $window.bluetoothSerial.read(function (data) {
  969. q.resolve(data);
  970. }, function (error) {
  971. q.reject(error);
  972. });
  973. return q.promise;
  974. },
  975. readUntil: function (delimiter) {
  976. var q = $q.defer();
  977. $window.bluetoothSerial.readUntil(delimiter, function (data) {
  978. q.resolve(data);
  979. }, function (error) {
  980. q.reject(error);
  981. });
  982. return q.promise;
  983. },
  984. write: function (data) {
  985. var q = $q.defer();
  986. $window.bluetoothSerial.write(data, function () {
  987. q.resolve();
  988. }, function (error) {
  989. q.reject(error);
  990. });
  991. return q.promise;
  992. },
  993. subscribe: function (delimiter) {
  994. var q = $q.defer();
  995. $window.bluetoothSerial.subscribe(delimiter, function (data) {
  996. q.notify(data);
  997. }, function (error) {
  998. q.reject(error);
  999. });
  1000. return q.promise;
  1001. },
  1002. subscribeRawData: function () {
  1003. var q = $q.defer();
  1004. $window.bluetoothSerial.subscribeRawData(function (data) {
  1005. q.notify(data);
  1006. }, function (error) {
  1007. q.reject(error);
  1008. });
  1009. return q.promise;
  1010. },
  1011. unsubscribe: function () {
  1012. var q = $q.defer();
  1013. $window.bluetoothSerial.unsubscribe(function () {
  1014. q.resolve();
  1015. }, function (error) {
  1016. q.reject(error);
  1017. });
  1018. return q.promise;
  1019. },
  1020. unsubscribeRawData: function () {
  1021. var q = $q.defer();
  1022. $window.bluetoothSerial.unsubscribeRawData(function () {
  1023. q.resolve();
  1024. }, function (error) {
  1025. q.reject(error);
  1026. });
  1027. return q.promise;
  1028. },
  1029. clear: function () {
  1030. var q = $q.defer();
  1031. $window.bluetoothSerial.clear(function () {
  1032. q.resolve();
  1033. }, function (error) {
  1034. q.reject(error);
  1035. });
  1036. return q.promise;
  1037. },
  1038. readRSSI: function () {
  1039. var q = $q.defer();
  1040. $window.bluetoothSerial.readRSSI(function (data) {
  1041. q.resolve(data);
  1042. }, function (error) {
  1043. q.reject(error);
  1044. });
  1045. return q.promise;
  1046. }
  1047. };
  1048. }]);
  1049. // install : cordova plugin add https://github.com/fiscal-cliff/phonegap-plugin-brightness.git
  1050. // link : https://github.com/fiscal-cliff/phonegap-plugin-brightness
  1051. angular.module('ngCordova.plugins.brightness', [])
  1052. .factory('$cordovaBrightness', ['$q', '$window', function ($q, $window) {
  1053. return {
  1054. get: function () {
  1055. var q = $q.defer();
  1056. if (!$window.cordova) {
  1057. q.reject('Not supported without cordova.js');
  1058. } else {
  1059. $window.cordova.plugins.brightness.getBrightness(function (result) {
  1060. q.resolve(result);
  1061. }, function (err) {
  1062. q.reject(err);
  1063. });
  1064. }
  1065. return q.promise;
  1066. },
  1067. set: function (data) {
  1068. var q = $q.defer();
  1069. if (!$window.cordova) {
  1070. q.reject('Not supported without cordova.js');
  1071. } else {
  1072. $window.cordova.plugins.brightness.setBrightness(data, function (result) {
  1073. q.resolve(result);
  1074. }, function (err) {
  1075. q.reject(err);
  1076. });
  1077. }
  1078. return q.promise;
  1079. },
  1080. setKeepScreenOn: function (bool) {
  1081. var q = $q.defer();
  1082. if (!$window.cordova) {
  1083. q.reject('Not supported without cordova.js');
  1084. } else {
  1085. $window.cordova.plugins.brightness.setKeepScreenOn(bool, function (result) {
  1086. q.resolve(result);
  1087. }, function (err) {
  1088. q.reject(err);
  1089. });
  1090. }
  1091. return q.promise;
  1092. }
  1093. };
  1094. }]);
  1095. // install : cordova plugin add https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin.git
  1096. // link : https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin
  1097. angular.module('ngCordova.plugins.calendar', [])
  1098. .factory('$cordovaCalendar', ['$q', '$window', function ($q, $window) {
  1099. return {
  1100. createCalendar: function (options) {
  1101. var d = $q.defer(),
  1102. createCalOptions = $window.plugins.calendar.getCreateCalendarOptions();
  1103. if (typeof options === 'string') {
  1104. createCalOptions.calendarName = options;
  1105. } else {
  1106. createCalOptions = angular.extend(createCalOptions, options);
  1107. }
  1108. $window.plugins.calendar.createCalendar(createCalOptions, function (message) {
  1109. d.resolve(message);
  1110. }, function (error) {
  1111. d.reject(error);
  1112. });
  1113. return d.promise;
  1114. },
  1115. deleteCalendar: function (calendarName) {
  1116. var d = $q.defer();
  1117. $window.plugins.calendar.deleteCalendar(calendarName, function (message) {
  1118. d.resolve(message);
  1119. }, function (error) {
  1120. d.reject(error);
  1121. });
  1122. return d.promise;
  1123. },
  1124. createEvent: function (options) {
  1125. var d = $q.defer(),
  1126. defaultOptions = {
  1127. title: null,
  1128. location: null,
  1129. notes: null,
  1130. startDate: null,
  1131. endDate: null
  1132. };
  1133. defaultOptions = angular.extend(defaultOptions, options);
  1134. $window.plugins.calendar.createEvent(
  1135. defaultOptions.title,
  1136. defaultOptions.location,
  1137. defaultOptions.notes,
  1138. new Date(defaultOptions.startDate),
  1139. new Date(defaultOptions.endDate),
  1140. function (message) {
  1141. d.resolve(message);
  1142. }, function (error) {
  1143. d.reject(error);
  1144. }
  1145. );
  1146. return d.promise;
  1147. },
  1148. createEventWithOptions: function (options) {
  1149. var d = $q.defer(),
  1150. defaultOptionKeys = [],
  1151. calOptions = window.plugins.calendar.getCalendarOptions(),
  1152. defaultOptions = {
  1153. title: null,
  1154. location: null,
  1155. notes: null,
  1156. startDate: null,
  1157. endDate: null
  1158. };
  1159. defaultOptionKeys = Object.keys(defaultOptions);
  1160. for (var key in options) {
  1161. if (defaultOptionKeys.indexOf(key) === -1) {
  1162. calOptions[key] = options[key];
  1163. } else {
  1164. defaultOptions[key] = options[key];
  1165. }
  1166. }
  1167. $window.plugins.calendar.createEventWithOptions(
  1168. defaultOptions.title,
  1169. defaultOptions.location,
  1170. defaultOptions.notes,
  1171. new Date(defaultOptions.startDate),
  1172. new Date(defaultOptions.endDate),
  1173. calOptions,
  1174. function (message) {
  1175. d.resolve(message);
  1176. }, function (error) {
  1177. d.reject(error);
  1178. }
  1179. );
  1180. return d.promise;
  1181. },
  1182. createEventInteractively: function (options) {
  1183. var d = $q.defer(),
  1184. defaultOptions = {
  1185. title: null,
  1186. location: null,
  1187. notes: null,
  1188. startDate: null,
  1189. endDate: null
  1190. };
  1191. defaultOptions = angular.extend(defaultOptions, options);
  1192. $window.plugins.calendar.createEventInteractively(
  1193. defaultOptions.title,
  1194. defaultOptions.location,
  1195. defaultOptions.notes,
  1196. new Date(defaultOptions.startDate),
  1197. new Date(defaultOptions.endDate),
  1198. function (message) {
  1199. d.resolve(message);
  1200. }, function (error) {
  1201. d.reject(error);
  1202. }
  1203. );
  1204. return d.promise;
  1205. },
  1206. createEventInNamedCalendar: function (options) {
  1207. var d = $q.defer(),
  1208. defaultOptions = {
  1209. title: null,
  1210. location: null,
  1211. notes: null,
  1212. startDate: null,
  1213. endDate: null,
  1214. calendarName: null
  1215. };
  1216. defaultOptions = angular.extend(defaultOptions, options);
  1217. $window.plugins.calendar.createEventInNamedCalendar(
  1218. defaultOptions.title,
  1219. defaultOptions.location,
  1220. defaultOptions.notes,
  1221. new Date(defaultOptions.startDate),
  1222. new Date(defaultOptions.endDate),
  1223. defaultOptions.calendarName,
  1224. function (message) {
  1225. d.resolve(message);
  1226. }, function (error) {
  1227. d.reject(error);
  1228. }
  1229. );
  1230. return d.promise;
  1231. },
  1232. findEvent: function (options) {
  1233. var d = $q.defer(),
  1234. defaultOptions = {
  1235. title: null,
  1236. location: null,
  1237. notes: null,
  1238. startDate: null,
  1239. endDate: null
  1240. };
  1241. defaultOptions = angular.extend(defaultOptions, options);
  1242. $window.plugins.calendar.findEvent(
  1243. defaultOptions.title,
  1244. defaultOptions.location,
  1245. defaultOptions.notes,
  1246. new Date(defaultOptions.startDate),
  1247. new Date(defaultOptions.endDate),
  1248. function (foundEvent) {
  1249. d.resolve(foundEvent);
  1250. }, function (error) {
  1251. d.reject(error);
  1252. }
  1253. );
  1254. return d.promise;
  1255. },
  1256. listEventsInRange: function (startDate, endDate) {
  1257. var d = $q.defer();
  1258. $window.plugins.calendar.listEventsInRange(startDate, endDate, function (events) {
  1259. d.resolve(events);
  1260. }, function (error) {
  1261. d.reject(error);
  1262. });
  1263. return d.promise;
  1264. },
  1265. listCalendars: function () {
  1266. var d = $q.defer();
  1267. $window.plugins.calendar.listCalendars(function (calendars) {
  1268. d.resolve(calendars);
  1269. }, function (error) {
  1270. d.reject(error);
  1271. });
  1272. return d.promise;
  1273. },
  1274. findAllEventsInNamedCalendar: function (calendarName) {
  1275. var d = $q.defer();
  1276. $window.plugins.calendar.findAllEventsInNamedCalendar(calendarName, function (events) {
  1277. d.resolve(events);
  1278. }, function (error) {
  1279. d.reject(error);
  1280. });
  1281. return d.promise;
  1282. },
  1283. modifyEvent: function (options) {
  1284. var d = $q.defer(),
  1285. defaultOptions = {
  1286. title: null,
  1287. location: null,
  1288. notes: null,
  1289. startDate: null,
  1290. endDate: null,
  1291. newTitle: null,
  1292. newLocation: null,
  1293. newNotes: null,
  1294. newStartDate: null,
  1295. newEndDate: null
  1296. };
  1297. defaultOptions = angular.extend(defaultOptions, options);
  1298. $window.plugins.calendar.modifyEvent(
  1299. defaultOptions.title,
  1300. defaultOptions.location,
  1301. defaultOptions.notes,
  1302. new Date(defaultOptions.startDate),
  1303. new Date(defaultOptions.endDate),
  1304. defaultOptions.newTitle,
  1305. defaultOptions.newLocation,
  1306. defaultOptions.newNotes,
  1307. new Date(defaultOptions.newStartDate),
  1308. new Date(defaultOptions.newEndDate),
  1309. function (message) {
  1310. d.resolve(message);
  1311. }, function (error) {
  1312. d.reject(error);
  1313. }
  1314. );
  1315. return d.promise;
  1316. },
  1317. deleteEvent: function (options) {
  1318. var d = $q.defer(),
  1319. defaultOptions = {
  1320. newTitle: null,
  1321. location: null,
  1322. notes: null,
  1323. startDate: null,
  1324. endDate: null
  1325. };
  1326. defaultOptions = angular.extend(defaultOptions, options);
  1327. $window.plugins.calendar.deleteEvent(
  1328. defaultOptions.newTitle,
  1329. defaultOptions.location,
  1330. defaultOptions.notes,
  1331. new Date(defaultOptions.startDate),
  1332. new Date(defaultOptions.endDate),
  1333. function (message) {
  1334. d.resolve(message);
  1335. }, function (error) {
  1336. d.reject(error);
  1337. }
  1338. );
  1339. return d.promise;
  1340. }
  1341. };
  1342. }]);
  1343. // install : cordova plugin add cordova-plugin-camera
  1344. // link : https://github.com/apache/cordova-plugin-camera
  1345. angular.module('ngCordova.plugins.camera', [])
  1346. .factory('$cordovaCamera', ['$q', function ($q) {
  1347. return {
  1348. getPicture: function (options) {
  1349. var q = $q.defer();
  1350. if (!navigator.camera) {
  1351. q.resolve(null);
  1352. return q.promise;
  1353. }
  1354. navigator.camera.getPicture(function (imageData) {
  1355. q.resolve(imageData);
  1356. }, function (err) {
  1357. q.reject(err);
  1358. }, options);
  1359. return q.promise;
  1360. },
  1361. cleanup: function () {
  1362. var q = $q.defer();
  1363. navigator.camera.cleanup(function () {
  1364. q.resolve();
  1365. }, function (err) {
  1366. q.reject(err);
  1367. });
  1368. return q.promise;
  1369. }
  1370. };
  1371. }]);
  1372. // install : cordova plugin add cordova-plugin-media-capture
  1373. // link : https://github.com/apache/cordova-plugin-media-capture
  1374. angular.module('ngCordova.plugins.capture', [])
  1375. .factory('$cordovaCapture', ['$q', function ($q) {
  1376. return {
  1377. captureAudio: function (options) {
  1378. var q = $q.defer();
  1379. if (!navigator.device.capture) {
  1380. q.resolve(null);
  1381. return q.promise;
  1382. }
  1383. navigator.device.capture.captureAudio(function (audioData) {
  1384. q.resolve(audioData);
  1385. }, function (err) {
  1386. q.reject(err);
  1387. }, options);
  1388. return q.promise;
  1389. },
  1390. captureImage: function (options) {
  1391. var q = $q.defer();
  1392. if (!navigator.device.capture) {
  1393. q.resolve(null);
  1394. return q.promise;
  1395. }
  1396. navigator.device.capture.captureImage(function (imageData) {
  1397. q.resolve(imageData);
  1398. }, function (err) {
  1399. q.reject(err);
  1400. }, options);
  1401. return q.promise;
  1402. },
  1403. captureVideo: function (options) {
  1404. var q = $q.defer();
  1405. if (!navigator.device.capture) {
  1406. q.resolve(null);
  1407. return q.promise;
  1408. }
  1409. navigator.device.capture.captureVideo(function (videoData) {
  1410. q.resolve(videoData);
  1411. }, function (err) {
  1412. q.reject(err);
  1413. }, options);
  1414. return q.promise;
  1415. }
  1416. };
  1417. }]);
  1418. // install : cordova plugin add https://github.com/vkeepe/card.io.git
  1419. // link : https://github.com/vkeepe/card.io.git
  1420. /* globals CardIO: true */
  1421. angular.module('ngCordova.plugins.cardIO', [])
  1422. .provider(
  1423. '$cordovaNgCardIO', [function () {
  1424. /**
  1425. * Default array of response data from cardIO scan card
  1426. */
  1427. var defaultRespFields = [
  1428. 'card_type',
  1429. 'redacted_card_number',
  1430. 'card_number',
  1431. 'expiry_month',
  1432. 'expiry_year',
  1433. 'short_expiry_year',
  1434. 'cvv',
  1435. 'zip'
  1436. ];
  1437. /**
  1438. * Default config for cardIO scan function
  1439. */
  1440. var defaultScanConfig = {
  1441. 'expiry': true,
  1442. 'cvv': true,
  1443. 'zip': false,
  1444. 'suppressManual': false,
  1445. 'suppressConfirm': false,
  1446. 'hideLogo': true
  1447. };
  1448. /**
  1449. * Configuring defaultRespFields using $cordovaNgCardIOProvider
  1450. *
  1451. */
  1452. this.setCardIOResponseFields = function (fields) {
  1453. if (!fields || !angular.isArray(fields)) {
  1454. return;
  1455. }
  1456. defaultRespFields = fields;
  1457. };
  1458. /**
  1459. *
  1460. * Configuring defaultScanConfig using $cordovaNgCardIOProvider
  1461. */
  1462. this.setScanerConfig = function (config) {
  1463. if (!config || !angular.isObject(config)) {
  1464. return;
  1465. }
  1466. defaultScanConfig.expiry = config.expiry || true;
  1467. defaultScanConfig.cvv = config.cvv || true;
  1468. defaultScanConfig.zip = config.zip || false;
  1469. defaultScanConfig.suppressManual = config.suppressManual || false;
  1470. defaultScanConfig.suppressConfirm = config.suppressConfirm || false;
  1471. defaultScanConfig.hideLogo = config.hideLogo || true;
  1472. };
  1473. /**
  1474. * Function scanCard for $cordovaNgCardIO service to make scan of card
  1475. *
  1476. */
  1477. this.$get = ['$q', function ($q) {
  1478. return {
  1479. scanCard: function () {
  1480. var deferred = $q.defer();
  1481. CardIO.scan(
  1482. defaultScanConfig,
  1483. function (response) {
  1484. if (response === null) {
  1485. deferred.reject(null);
  1486. } else {
  1487. var respData = {};
  1488. for (
  1489. var i = 0, len = defaultRespFields.length; i < len; i++) {
  1490. var field = defaultRespFields[i];
  1491. if (field === 'short_expiry_year') {
  1492. respData[field] = String(response.expiry_year).substr( // jshint ignore:line
  1493. 2, 2
  1494. ) || '';
  1495. } else {
  1496. respData[field] = response[field] || '';
  1497. }
  1498. }
  1499. deferred.resolve(respData);
  1500. }
  1501. },
  1502. function () {
  1503. deferred.reject(null);
  1504. }
  1505. );
  1506. return deferred.promise;
  1507. }
  1508. };
  1509. }];
  1510. }]
  1511. );
  1512. // install : cordova plugin add https://github.com/VersoSolutions/CordovaClipboard.git
  1513. // link : https://github.com/VersoSolutions/CordovaClipboard
  1514. angular.module('ngCordova.plugins.clipboard', [])
  1515. .factory('$cordovaClipboard', ['$q', '$window', function ($q, $window) {
  1516. return {
  1517. copy: function (text) {
  1518. var q = $q.defer();
  1519. $window.cordova.plugins.clipboard.copy(text,
  1520. function () {
  1521. q.resolve();
  1522. }, function () {
  1523. q.reject();
  1524. });
  1525. return q.promise;
  1526. },
  1527. paste: function () {
  1528. var q = $q.defer();
  1529. $window.cordova.plugins.clipboard.paste(function (text) {
  1530. q.resolve(text);
  1531. }, function () {
  1532. q.reject();
  1533. });
  1534. return q.promise;
  1535. }
  1536. };
  1537. }]);
  1538. // install : cordova plugin add cordova-plugin-contacts
  1539. // link : https://github.com/apache/cordova-plugin-contacts
  1540. angular.module('ngCordova.plugins.contacts', [])
  1541. .factory('$cordovaContacts', ['$q', function ($q) {
  1542. return {
  1543. save: function (contact) {
  1544. var q = $q.defer();
  1545. var deviceContact = navigator.contacts.create(contact);
  1546. deviceContact.save(function (result) {
  1547. q.resolve(result);
  1548. }, function (err) {
  1549. q.reject(err);
  1550. });
  1551. return q.promise;
  1552. },
  1553. remove: function (contact) {
  1554. var q = $q.defer();
  1555. var deviceContact = navigator.contacts.create(contact);
  1556. deviceContact.remove(function (result) {
  1557. q.resolve(result);
  1558. }, function (err) {
  1559. q.reject(err);
  1560. });
  1561. return q.promise;
  1562. },
  1563. clone: function (contact) {
  1564. var deviceContact = navigator.contacts.create(contact);
  1565. return deviceContact.clone(contact);
  1566. },
  1567. find: function (options) {
  1568. var q = $q.defer();
  1569. var fields = options.fields || ['id', 'displayName'];
  1570. delete options.fields;
  1571. if (Object.keys(options).length === 0) {
  1572. navigator.contacts.find(fields, function (results) {
  1573. q.resolve(results);
  1574. },function (err) {
  1575. q.reject(err);
  1576. });
  1577. }
  1578. else {
  1579. navigator.contacts.find(fields, function (results) {
  1580. q.resolve(results);
  1581. }, function (err) {
  1582. q.reject(err);
  1583. }, options);
  1584. }
  1585. return q.promise;
  1586. },
  1587. pickContact: function () {
  1588. var q = $q.defer();
  1589. navigator.contacts.pickContact(function (contact) {
  1590. q.resolve(contact);
  1591. }, function (err) {
  1592. q.reject(err);
  1593. });
  1594. return q.promise;
  1595. }
  1596. // TODO: method to set / get ContactAddress
  1597. // TODO: method to set / get ContactError
  1598. // TODO: method to set / get ContactField
  1599. // TODO: method to set / get ContactName
  1600. // TODO: method to set / get ContactOrganization
  1601. };
  1602. }]);
  1603. // install : cordova plugin add https://github.com/VitaliiBlagodir/cordova-plugin-datepicker.git
  1604. // link : https://github.com/VitaliiBlagodir/cordova-plugin-datepicker
  1605. angular.module('ngCordova.plugins.datePicker', [])
  1606. .factory('$cordovaDatePicker', ['$window', '$q', function ($window, $q) {
  1607. return {
  1608. show: function (options) {
  1609. var q = $q.defer();
  1610. options = options || {date: new Date(), mode: 'date'};
  1611. $window.datePicker.show(options, function (date) {
  1612. q.resolve(date);
  1613. }, function (error){
  1614. q.reject(error);
  1615. });
  1616. return q.promise;
  1617. }
  1618. };
  1619. }]);
  1620. // install : cordova plugin add cordova-plugin-device
  1621. // link : https://github.com/apache/cordova-plugin-device
  1622. /* globals device: true */
  1623. angular.module('ngCordova.plugins.device', [])
  1624. .factory('$cordovaDevice', [function () {
  1625. return {
  1626. /**
  1627. * Returns the whole device object.
  1628. * @see https://github.com/apache/cordova-plugin-device
  1629. * @returns {Object} The device object.
  1630. */
  1631. getDevice: function () {
  1632. return device;
  1633. },
  1634. /**
  1635. * Returns the Cordova version.
  1636. * @see https://github.com/apache/cordova-plugin-device#devicecordova
  1637. * @returns {String} The Cordova version.
  1638. */
  1639. getCordova: function () {
  1640. return device.cordova;
  1641. },
  1642. /**
  1643. * Returns the name of the device's model or product.
  1644. * @see https://github.com/apache/cordova-plugin-device#devicemodel
  1645. * @returns {String} The name of the device's model or product.
  1646. */
  1647. getModel: function () {
  1648. return device.model;
  1649. },
  1650. /**
  1651. * @deprecated device.name is deprecated as of version 2.3.0. Use device.model instead.
  1652. * @returns {String}
  1653. */
  1654. getName: function () {
  1655. return device.name;
  1656. },
  1657. /**
  1658. * Returns the device's operating system name.
  1659. * @see https://github.com/apache/cordova-plugin-device#deviceplatform
  1660. * @returns {String} The device's operating system name.
  1661. */
  1662. getPlatform: function () {
  1663. return device.platform;
  1664. },
  1665. /**
  1666. * Returns the device's Universally Unique Identifier.
  1667. * @see https://github.com/apache/cordova-plugin-device#deviceuuid
  1668. * @returns {String} The device's Universally Unique Identifier
  1669. */
  1670. getUUID: function () {
  1671. return device.uuid;
  1672. },
  1673. /**
  1674. * Returns the operating system version.
  1675. * @see https://github.com/apache/cordova-plugin-device#deviceversion
  1676. * @returns {String}
  1677. */
  1678. getVersion: function () {
  1679. return device.version;
  1680. },
  1681. /**
  1682. * Returns the device manufacturer.
  1683. * @returns {String}
  1684. */
  1685. getManufacturer: function () {
  1686. return device.manufacturer;
  1687. }
  1688. };
  1689. }]);
  1690. // install : cordova plugin add cordova-plugin-device-motion
  1691. // link : https://github.com/apache/cordova-plugin-device-motion
  1692. angular.module('ngCordova.plugins.deviceMotion', [])
  1693. .factory('$cordovaDeviceMotion', ['$q', function ($q) {
  1694. return {
  1695. getCurrentAcceleration: function () {
  1696. var q = $q.defer();
  1697. if (angular.isUndefined(navigator.accelerometer) ||
  1698. !angular.isFunction(navigator.accelerometer.getCurrentAcceleration)) {
  1699. q.reject('Device do not support watchAcceleration');
  1700. return q.promise;
  1701. }
  1702. navigator.accelerometer.getCurrentAcceleration(function (result) {
  1703. q.resolve(result);
  1704. }, function (err) {
  1705. q.reject(err);
  1706. });
  1707. return q.promise;
  1708. },
  1709. watchAcceleration: function (options) {
  1710. var q = $q.defer();
  1711. if (angular.isUndefined(navigator.accelerometer) ||
  1712. !angular.isFunction(navigator.accelerometer.watchAcceleration)) {
  1713. q.reject('Device do not support watchAcceleration');
  1714. return q.promise;
  1715. }
  1716. var watchID = navigator.accelerometer.watchAcceleration(function (result) {
  1717. q.notify(result);
  1718. }, function (err) {
  1719. q.reject(err);
  1720. }, options);
  1721. q.promise.cancel = function () {
  1722. navigator.accelerometer.clearWatch(watchID);
  1723. };
  1724. q.promise.clearWatch = function (id) {
  1725. navigator.accelerometer.clearWatch(id || watchID);
  1726. };
  1727. q.promise.watchID = watchID;
  1728. return q.promise;
  1729. },
  1730. clearWatch: function (watchID) {
  1731. return navigator.accelerometer.clearWatch(watchID);
  1732. }
  1733. };
  1734. }]);
  1735. // install : cordova plugin add cordova-plugin-device-orientation
  1736. // link : https://github.com/apache/cordova-plugin-device-orientation
  1737. angular.module('ngCordova.plugins.deviceOrientation', [])
  1738. .factory('$cordovaDeviceOrientation', ['$q', function ($q) {
  1739. var defaultOptions = {
  1740. frequency: 3000 // every 3s
  1741. };
  1742. return {
  1743. getCurrentHeading: function () {
  1744. var q = $q.defer();
  1745. if(!navigator.compass) {
  1746. q.reject('No compass on Device');
  1747. return q.promise;
  1748. }
  1749. navigator.compass.getCurrentHeading(function (result) {
  1750. q.resolve(result);
  1751. }, function (err) {
  1752. q.reject(err);
  1753. });
  1754. return q.promise;
  1755. },
  1756. watchHeading: function (options) {
  1757. var q = $q.defer();
  1758. if(!navigator.compass) {
  1759. q.reject('No compass on Device');
  1760. return q.promise;
  1761. }
  1762. var _options = angular.extend(defaultOptions, options);
  1763. var watchID = navigator.compass.watchHeading(function (result) {
  1764. q.notify(result);
  1765. }, function (err) {
  1766. q.reject(err);
  1767. }, _options);
  1768. q.promise.cancel = function () {
  1769. navigator.compass.clearWatch(watchID);
  1770. };
  1771. q.promise.clearWatch = function (id) {
  1772. navigator.compass.clearWatch(id || watchID);
  1773. };
  1774. q.promise.watchID = watchID;
  1775. return q.promise;
  1776. },
  1777. clearWatch: function (watchID) {
  1778. return navigator.compass.clearWatch(watchID);
  1779. }
  1780. };
  1781. }]);
  1782. // install : cordova plugin add cordova-plugin-dialogs
  1783. // link : https://github.com/apache/cordova-plugin-dialogs
  1784. angular.module('ngCordova.plugins.dialogs', [])
  1785. .factory('$cordovaDialogs', ['$q', '$window', function ($q, $window) {
  1786. return {
  1787. alert: function (message, title, buttonName) {
  1788. var q = $q.defer();
  1789. if (!$window.navigator.notification) {
  1790. $window.alert(message);
  1791. q.resolve();
  1792. } else {
  1793. navigator.notification.alert(message, function () {
  1794. q.resolve();
  1795. }, title, buttonName);
  1796. }
  1797. return q.promise;
  1798. },
  1799. confirm: function (message, title, buttonLabels) {
  1800. var q = $q.defer();
  1801. if (!$window.navigator.notification) {
  1802. if ($window.confirm(message)) {
  1803. q.resolve(1);
  1804. } else {
  1805. q.resolve(2);
  1806. }
  1807. } else {
  1808. navigator.notification.confirm(message, function (buttonIndex) {
  1809. q.resolve(buttonIndex);
  1810. }, title, buttonLabels);
  1811. }
  1812. return q.promise;
  1813. },
  1814. prompt: function (message, title, buttonLabels, defaultText) {
  1815. var q = $q.defer();
  1816. if (!$window.navigator.notification) {
  1817. var res = $window.prompt(message, defaultText);
  1818. if (res !== null) {
  1819. q.resolve({input1: res, buttonIndex: 1});
  1820. } else {
  1821. q.resolve({input1: res, buttonIndex: 2});
  1822. }
  1823. } else {
  1824. navigator.notification.prompt(message, function (result) {
  1825. q.resolve(result);
  1826. }, title, buttonLabels, defaultText);
  1827. }
  1828. return q.promise;
  1829. },
  1830. beep: function (times) {
  1831. return navigator.notification.beep(times);
  1832. },
  1833. activityStart: function (message, title) {
  1834. var q = $q.defer();
  1835. if (cordova.platformId === 'android') {
  1836. navigator.notification.activityStart(title, message);
  1837. q.resolve();
  1838. } else {
  1839. q.reject(message, title);
  1840. }
  1841. return q.promise;
  1842. },
  1843. activityStop: function () {
  1844. var q = $q.defer();
  1845. if (cordova.platformId === 'android') {
  1846. navigator.notification.activityStop();
  1847. q.resolve();
  1848. } else {
  1849. q.reject();
  1850. }
  1851. return q.promise;
  1852. },
  1853. progressStart: function (message, title) {
  1854. var q = $q.defer();
  1855. if (cordova.platformId === 'android') {
  1856. navigator.notification.progressStart(title, message);
  1857. q.resolve();
  1858. } else {
  1859. q.reject(message, title);
  1860. }
  1861. return q.promise;
  1862. },
  1863. progressStop: function () {
  1864. var q = $q.defer();
  1865. if (cordova.platformId === 'android') {
  1866. navigator.notification.progressStop();
  1867. q.resolve();
  1868. } else {
  1869. q.reject();
  1870. }
  1871. return q.promise;
  1872. },
  1873. progressValue: function (value) {
  1874. var q = $q.defer();
  1875. if (cordova.platformId === 'android') {
  1876. navigator.notification.progressValue(value);
  1877. q.resolve();
  1878. } else {
  1879. q.reject(value);
  1880. }
  1881. return q.promise;
  1882. }
  1883. };
  1884. }]);
  1885. // install : cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git
  1886. // link : https://github.com/katzer/cordova-plugin-email-composer
  1887. angular.module('ngCordova.plugins.emailComposer', [])
  1888. .factory('$cordovaEmailComposer', ['$q', function ($q) {
  1889. return {
  1890. isAvailable: function () {
  1891. var q = $q.defer();
  1892. cordova.plugins.email.isAvailable(function (isAvailable) {
  1893. if (isAvailable) {
  1894. q.resolve();
  1895. } else {
  1896. q.reject();
  1897. }
  1898. });
  1899. return q.promise;
  1900. },
  1901. open: function (properties) {
  1902. var q = $q.defer();
  1903. cordova.plugins.email.open(properties, function () {
  1904. q.reject(); // user closed email composer
  1905. });
  1906. return q.promise;
  1907. },
  1908. addAlias: function (app, schema) {
  1909. cordova.plugins.email.addAlias(app, schema);
  1910. }
  1911. };
  1912. }]);
  1913. // install : cordova -d plugin add https://github.com/Wizcorp/phonegap-facebook-plugin.git --variable APP_ID="123456789" --variable APP_NAME="myApplication"
  1914. // link : https://github.com/Wizcorp/phonegap-facebook-plugin
  1915. /* globals facebookConnectPlugin: true */
  1916. angular.module('ngCordova.plugins.facebook', [])
  1917. .provider('$cordovaFacebook', [function () {
  1918. /**
  1919. * Init browser settings for Facebook plugin
  1920. *
  1921. * @param {number} id
  1922. * @param {string} version
  1923. */
  1924. this.browserInit = function (id, version) {
  1925. this.appID = id;
  1926. this.appVersion = version || 'v2.0';
  1927. facebookConnectPlugin.browserInit(this.appID, this.appVersion);
  1928. };
  1929. this.$get = ['$q', function ($q) {
  1930. return {
  1931. login: function (permissions) {
  1932. var q = $q.defer();
  1933. facebookConnectPlugin.login(permissions, function (res) {
  1934. q.resolve(res);
  1935. }, function (res) {
  1936. q.reject(res);
  1937. });
  1938. return q.promise;
  1939. },
  1940. showDialog: function (options) {
  1941. var q = $q.defer();
  1942. facebookConnectPlugin.showDialog(options, function (res) {
  1943. q.resolve(res);
  1944. }, function (err) {
  1945. q.reject(err);
  1946. });
  1947. return q.promise;
  1948. },
  1949. api: function (path, permissions) {
  1950. var q = $q.defer();
  1951. facebookConnectPlugin.api(path, permissions, function (res) {
  1952. q.resolve(res);
  1953. }, function (err) {
  1954. q.reject(err);
  1955. });
  1956. return q.promise;
  1957. },
  1958. getAccessToken: function () {
  1959. var q = $q.defer();
  1960. facebookConnectPlugin.getAccessToken(function (res) {
  1961. q.resolve(res);
  1962. }, function (err) {
  1963. q.reject(err);
  1964. });
  1965. return q.promise;
  1966. },
  1967. getLoginStatus: function () {
  1968. var q = $q.defer();
  1969. facebookConnectPlugin.getLoginStatus(function (res) {
  1970. q.resolve(res);
  1971. }, function (err) {
  1972. q.reject(err);
  1973. });
  1974. return q.promise;
  1975. },
  1976. logout: function () {
  1977. var q = $q.defer();
  1978. facebookConnectPlugin.logout(function (res) {
  1979. q.resolve(res);
  1980. }, function (err) {
  1981. q.reject(err);
  1982. });
  1983. return q.promise;
  1984. }
  1985. };
  1986. }];
  1987. }]);
  1988. // install : cordova plugin add https://github.com/floatinghotpot/cordova-plugin-facebookads.git
  1989. // link : https://github.com/floatinghotpot/cordova-plugin-facebookads
  1990. angular.module('ngCordova.plugins.facebookAds', [])
  1991. .factory('$cordovaFacebookAds', ['$q', '$window', function ($q, $window) {
  1992. return {
  1993. setOptions: function (options) {
  1994. var d = $q.defer();
  1995. $window.FacebookAds.setOptions(options, function () {
  1996. d.resolve();
  1997. }, function () {
  1998. d.reject();
  1999. });
  2000. return d.promise;
  2001. },
  2002. createBanner: function (options) {
  2003. var d = $q.defer();
  2004. $window.FacebookAds.createBanner(options, function () {
  2005. d.resolve();
  2006. }, function () {
  2007. d.reject();
  2008. });
  2009. return d.promise;
  2010. },
  2011. removeBanner: function () {
  2012. var d = $q.defer();
  2013. $window.FacebookAds.removeBanner(function () {
  2014. d.resolve();
  2015. }, function () {
  2016. d.reject();
  2017. });
  2018. return d.promise;
  2019. },
  2020. showBanner: function (position) {
  2021. var d = $q.defer();
  2022. $window.FacebookAds.showBanner(position, function () {
  2023. d.resolve();
  2024. }, function () {
  2025. d.reject();
  2026. });
  2027. return d.promise;
  2028. },
  2029. showBannerAtXY: function (x, y) {
  2030. var d = $q.defer();
  2031. $window.FacebookAds.showBannerAtXY(x, y, function () {
  2032. d.resolve();
  2033. }, function () {
  2034. d.reject();
  2035. });
  2036. return d.promise;
  2037. },
  2038. hideBanner: function () {
  2039. var d = $q.defer();
  2040. $window.FacebookAds.hideBanner(function () {
  2041. d.resolve();
  2042. }, function () {
  2043. d.reject();
  2044. });
  2045. return d.promise;
  2046. },
  2047. prepareInterstitial: function (options) {
  2048. var d = $q.defer();
  2049. $window.FacebookAds.prepareInterstitial(options, function () {
  2050. d.resolve();
  2051. }, function () {
  2052. d.reject();
  2053. });
  2054. return d.promise;
  2055. },
  2056. showInterstitial: function () {
  2057. var d = $q.defer();
  2058. $window.FacebookAds.showInterstitial(function () {
  2059. d.resolve();
  2060. }, function () {
  2061. d.reject();
  2062. });
  2063. return d.promise;
  2064. }
  2065. };
  2066. }]);
  2067. // install : cordova plugin add cordova-plugin-file
  2068. // link : https://github.com/apache/cordova-plugin-file
  2069. angular.module('ngCordova.plugins.file', [])
  2070. .constant('$cordovaFileError', {
  2071. 1: 'NOT_FOUND_ERR',
  2072. 2: 'SECURITY_ERR',
  2073. 3: 'ABORT_ERR',
  2074. 4: 'NOT_READABLE_ERR',
  2075. 5: 'ENCODING_ERR',
  2076. 6: 'NO_MODIFICATION_ALLOWED_ERR',
  2077. 7: 'INVALID_STATE_ERR',
  2078. 8: 'SYNTAX_ERR',
  2079. 9: 'INVALID_MODIFICATION_ERR',
  2080. 10: 'QUOTA_EXCEEDED_ERR',
  2081. 11: 'TYPE_MISMATCH_ERR',
  2082. 12: 'PATH_EXISTS_ERR'
  2083. })
  2084. .provider('$cordovaFile', [function () {
  2085. this.$get = ['$q', '$window', '$cordovaFileError', function ($q, $window, $cordovaFileError) {
  2086. return {
  2087. getFreeDiskSpace: function () {
  2088. var q = $q.defer();
  2089. cordova.exec(function (result) {
  2090. q.resolve(result);
  2091. }, function (error) {
  2092. q.reject(error);
  2093. }, 'File', 'getFreeDiskSpace', []);
  2094. return q.promise;
  2095. },
  2096. checkDir: function (path, dir) {
  2097. var q = $q.defer();
  2098. if ((/^\//.test(dir))) {
  2099. q.reject('directory cannot start with \/');
  2100. }
  2101. try {
  2102. var directory = path + dir;
  2103. $window.resolveLocalFileSystemURL(directory, function (fileSystem) {
  2104. if (fileSystem.isDirectory === true) {
  2105. q.resolve(fileSystem);
  2106. } else {
  2107. q.reject({code: 13, message: 'input is not a directory'});
  2108. }
  2109. }, function (error) {
  2110. error.message = $cordovaFileError[error.code];
  2111. q.reject(error);
  2112. });
  2113. } catch (err) {
  2114. err.message = $cordovaFileError[err.code];
  2115. q.reject(err);
  2116. }
  2117. return q.promise;
  2118. },
  2119. checkFile: function (path, file) {
  2120. var q = $q.defer();
  2121. if ((/^\//.test(file))) {
  2122. q.reject('directory cannot start with \/');
  2123. }
  2124. try {
  2125. var directory = path + file;
  2126. $window.resolveLocalFileSystemURL(directory, function (fileSystem) {
  2127. if (fileSystem.isFile === true) {
  2128. q.resolve(fileSystem);
  2129. } else {
  2130. q.reject({code: 13, message: 'input is not a file'});
  2131. }
  2132. }, function (error) {
  2133. error.message = $cordovaFileError[error.code];
  2134. q.reject(error);
  2135. });
  2136. } catch (err) {
  2137. err.message = $cordovaFileError[err.code];
  2138. q.reject(err);
  2139. }
  2140. return q.promise;
  2141. },
  2142. createDir: function (path, dirName, replaceBool) {
  2143. var q = $q.defer();
  2144. if ((/^\//.test(dirName))) {
  2145. q.reject('directory cannot start with \/');
  2146. }
  2147. replaceBool = replaceBool ? false : true;
  2148. var options = {
  2149. create: true,
  2150. exclusive: replaceBool
  2151. };
  2152. try {
  2153. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2154. fileSystem.getDirectory(dirName, options, function (result) {
  2155. q.resolve(result);
  2156. }, function (error) {
  2157. error.message = $cordovaFileError[error.code];
  2158. q.reject(error);
  2159. });
  2160. }, function (err) {
  2161. err.message = $cordovaFileError[err.code];
  2162. q.reject(err);
  2163. });
  2164. } catch (e) {
  2165. e.message = $cordovaFileError[e.code];
  2166. q.reject(e);
  2167. }
  2168. return q.promise;
  2169. },
  2170. createFile: function (path, fileName, replaceBool) {
  2171. var q = $q.defer();
  2172. if ((/^\//.test(fileName))) {
  2173. q.reject('file-name cannot start with \/');
  2174. }
  2175. replaceBool = replaceBool ? false : true;
  2176. var options = {
  2177. create: true,
  2178. exclusive: replaceBool
  2179. };
  2180. try {
  2181. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2182. fileSystem.getFile(fileName, options, function (result) {
  2183. q.resolve(result);
  2184. }, function (error) {
  2185. error.message = $cordovaFileError[error.code];
  2186. q.reject(error);
  2187. });
  2188. }, function (err) {
  2189. err.message = $cordovaFileError[err.code];
  2190. q.reject(err);
  2191. });
  2192. } catch (e) {
  2193. e.message = $cordovaFileError[e.code];
  2194. q.reject(e);
  2195. }
  2196. return q.promise;
  2197. },
  2198. removeDir: function (path, dirName) {
  2199. var q = $q.defer();
  2200. if ((/^\//.test(dirName))) {
  2201. q.reject('file-name cannot start with \/');
  2202. }
  2203. try {
  2204. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2205. fileSystem.getDirectory(dirName, {create: false}, function (dirEntry) {
  2206. dirEntry.remove(function () {
  2207. q.resolve({success: true, fileRemoved: dirEntry});
  2208. }, function (error) {
  2209. error.message = $cordovaFileError[error.code];
  2210. q.reject(error);
  2211. });
  2212. }, function (err) {
  2213. err.message = $cordovaFileError[err.code];
  2214. q.reject(err);
  2215. });
  2216. }, function (er) {
  2217. er.message = $cordovaFileError[er.code];
  2218. q.reject(er);
  2219. });
  2220. } catch (e) {
  2221. e.message = $cordovaFileError[e.code];
  2222. q.reject(e);
  2223. }
  2224. return q.promise;
  2225. },
  2226. removeFile: function (path, fileName) {
  2227. var q = $q.defer();
  2228. if ((/^\//.test(fileName))) {
  2229. q.reject('file-name cannot start with \/');
  2230. }
  2231. try {
  2232. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2233. fileSystem.getFile(fileName, {create: false}, function (fileEntry) {
  2234. fileEntry.remove(function () {
  2235. q.resolve({success: true, fileRemoved: fileEntry});
  2236. }, function (error) {
  2237. error.message = $cordovaFileError[error.code];
  2238. q.reject(error);
  2239. });
  2240. }, function (err) {
  2241. err.message = $cordovaFileError[err.code];
  2242. q.reject(err);
  2243. });
  2244. }, function (er) {
  2245. er.message = $cordovaFileError[er.code];
  2246. q.reject(er);
  2247. });
  2248. } catch (e) {
  2249. e.message = $cordovaFileError[e.code];
  2250. q.reject(e);
  2251. }
  2252. return q.promise;
  2253. },
  2254. removeRecursively: function (path, dirName) {
  2255. var q = $q.defer();
  2256. if ((/^\//.test(dirName))) {
  2257. q.reject('file-name cannot start with \/');
  2258. }
  2259. try {
  2260. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2261. fileSystem.getDirectory(dirName, {create: false}, function (dirEntry) {
  2262. dirEntry.removeRecursively(function () {
  2263. q.resolve({success: true, fileRemoved: dirEntry});
  2264. }, function (error) {
  2265. error.message = $cordovaFileError[error.code];
  2266. q.reject(error);
  2267. });
  2268. }, function (err) {
  2269. err.message = $cordovaFileError[err.code];
  2270. q.reject(err);
  2271. });
  2272. }, function (er) {
  2273. er.message = $cordovaFileError[er.code];
  2274. q.reject(er);
  2275. });
  2276. } catch (e) {
  2277. e.message = $cordovaFileError[e.code];
  2278. q.reject(e);
  2279. }
  2280. return q.promise;
  2281. },
  2282. writeFile: function (path, fileName, text, replaceBool) {
  2283. var q = $q.defer();
  2284. if ((/^\//.test(fileName))) {
  2285. q.reject('file-name cannot start with \/');
  2286. }
  2287. replaceBool = replaceBool ? false : true;
  2288. var options = {
  2289. create: true,
  2290. exclusive: replaceBool
  2291. };
  2292. try {
  2293. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2294. fileSystem.getFile(fileName, options, function (fileEntry) {
  2295. fileEntry.createWriter(function (writer) {
  2296. if (options.append === true) {
  2297. writer.seek(writer.length);
  2298. }
  2299. if (options.truncate) {
  2300. writer.truncate(options.truncate);
  2301. }
  2302. writer.onwriteend = function (evt) {
  2303. if (this.error) {
  2304. q.reject(this.error);
  2305. } else {
  2306. q.resolve(evt);
  2307. }
  2308. };
  2309. writer.write(text);
  2310. q.promise.abort = function () {
  2311. writer.abort();
  2312. };
  2313. });
  2314. }, function (error) {
  2315. error.message = $cordovaFileError[error.code];
  2316. q.reject(error);
  2317. });
  2318. }, function (err) {
  2319. err.message = $cordovaFileError[err.code];
  2320. q.reject(err);
  2321. });
  2322. } catch (e) {
  2323. e.message = $cordovaFileError[e.code];
  2324. q.reject(e);
  2325. }
  2326. return q.promise;
  2327. },
  2328. writeExistingFile: function (path, fileName, text) {
  2329. var q = $q.defer();
  2330. if ((/^\//.test(fileName))) {
  2331. q.reject('file-name cannot start with \/');
  2332. }
  2333. try {
  2334. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2335. fileSystem.getFile(fileName, {create: false}, function (fileEntry) {
  2336. fileEntry.createWriter(function (writer) {
  2337. writer.seek(writer.length);
  2338. writer.onwriteend = function (evt) {
  2339. if (this.error) {
  2340. q.reject(this.error);
  2341. } else {
  2342. q.resolve(evt);
  2343. }
  2344. };
  2345. writer.write(text);
  2346. q.promise.abort = function () {
  2347. writer.abort();
  2348. };
  2349. });
  2350. }, function (error) {
  2351. error.message = $cordovaFileError[error.code];
  2352. q.reject(error);
  2353. });
  2354. }, function (err) {
  2355. err.message = $cordovaFileError[err.code];
  2356. q.reject(err);
  2357. });
  2358. } catch (e) {
  2359. e.message = $cordovaFileError[e.code];
  2360. q.reject(e);
  2361. }
  2362. return q.promise;
  2363. },
  2364. readAsText: function (path, file) {
  2365. var q = $q.defer();
  2366. if ((/^\//.test(file))) {
  2367. q.reject('file-name cannot start with \/');
  2368. }
  2369. try {
  2370. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2371. fileSystem.getFile(file, {create: false}, function (fileEntry) {
  2372. fileEntry.file(function (fileData) {
  2373. var reader = new FileReader();
  2374. reader.onloadend = function (evt) {
  2375. if (evt.target.result !== undefined || evt.target.result !== null) {
  2376. q.resolve(evt.target.result);
  2377. } else if (evt.target.error !== undefined || evt.target.error !== null) {
  2378. q.reject(evt.target.error);
  2379. } else {
  2380. q.reject({code: null, message: 'READER_ONLOADEND_ERR'});
  2381. }
  2382. };
  2383. reader.readAsText(fileData);
  2384. });
  2385. }, function (error) {
  2386. error.message = $cordovaFileError[error.code];
  2387. q.reject(error);
  2388. });
  2389. }, function (err) {
  2390. err.message = $cordovaFileError[err.code];
  2391. q.reject(err);
  2392. });
  2393. } catch (e) {
  2394. e.message = $cordovaFileError[e.code];
  2395. q.reject(e);
  2396. }
  2397. return q.promise;
  2398. },
  2399. readAsDataURL: function (path, file) {
  2400. var q = $q.defer();
  2401. if ((/^\//.test(file))) {
  2402. q.reject('file-name cannot start with \/');
  2403. }
  2404. try {
  2405. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2406. fileSystem.getFile(file, {create: false}, function (fileEntry) {
  2407. fileEntry.file(function (fileData) {
  2408. var reader = new FileReader();
  2409. reader.onloadend = function (evt) {
  2410. if (evt.target.result !== undefined || evt.target.result !== null) {
  2411. q.resolve(evt.target.result);
  2412. } else if (evt.target.error !== undefined || evt.target.error !== null) {
  2413. q.reject(evt.target.error);
  2414. } else {
  2415. q.reject({code: null, message: 'READER_ONLOADEND_ERR'});
  2416. }
  2417. };
  2418. reader.readAsDataURL(fileData);
  2419. });
  2420. }, function (error) {
  2421. error.message = $cordovaFileError[error.code];
  2422. q.reject(error);
  2423. });
  2424. }, function (err) {
  2425. err.message = $cordovaFileError[err.code];
  2426. q.reject(err);
  2427. });
  2428. } catch (e) {
  2429. e.message = $cordovaFileError[e.code];
  2430. q.reject(e);
  2431. }
  2432. return q.promise;
  2433. },
  2434. readAsBinaryString: function (path, file) {
  2435. var q = $q.defer();
  2436. if ((/^\//.test(file))) {
  2437. q.reject('file-name cannot start with \/');
  2438. }
  2439. try {
  2440. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2441. fileSystem.getFile(file, {create: false}, function (fileEntry) {
  2442. fileEntry.file(function (fileData) {
  2443. var reader = new FileReader();
  2444. reader.onloadend = function (evt) {
  2445. if (evt.target.result !== undefined || evt.target.result !== null) {
  2446. q.resolve(evt.target.result);
  2447. } else if (evt.target.error !== undefined || evt.target.error !== null) {
  2448. q.reject(evt.target.error);
  2449. } else {
  2450. q.reject({code: null, message: 'READER_ONLOADEND_ERR'});
  2451. }
  2452. };
  2453. reader.readAsBinaryString(fileData);
  2454. });
  2455. }, function (error) {
  2456. error.message = $cordovaFileError[error.code];
  2457. q.reject(error);
  2458. });
  2459. }, function (err) {
  2460. err.message = $cordovaFileError[err.code];
  2461. q.reject(err);
  2462. });
  2463. } catch (e) {
  2464. e.message = $cordovaFileError[e.code];
  2465. q.reject(e);
  2466. }
  2467. return q.promise;
  2468. },
  2469. readAsArrayBuffer: function (path, file) {
  2470. var q = $q.defer();
  2471. if ((/^\//.test(file))) {
  2472. q.reject('file-name cannot start with \/');
  2473. }
  2474. try {
  2475. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2476. fileSystem.getFile(file, {create: false}, function (fileEntry) {
  2477. fileEntry.file(function (fileData) {
  2478. var reader = new FileReader();
  2479. reader.onloadend = function (evt) {
  2480. if (evt.target.result !== undefined || evt.target.result !== null) {
  2481. q.resolve(evt.target.result);
  2482. } else if (evt.target.error !== undefined || evt.target.error !== null) {
  2483. q.reject(evt.target.error);
  2484. } else {
  2485. q.reject({code: null, message: 'READER_ONLOADEND_ERR'});
  2486. }
  2487. };
  2488. reader.readAsArrayBuffer(fileData);
  2489. });
  2490. }, function (error) {
  2491. error.message = $cordovaFileError[error.code];
  2492. q.reject(error);
  2493. });
  2494. }, function (err) {
  2495. err.message = $cordovaFileError[err.code];
  2496. q.reject(err);
  2497. });
  2498. } catch (e) {
  2499. e.message = $cordovaFileError[e.code];
  2500. q.reject(e);
  2501. }
  2502. return q.promise;
  2503. },
  2504. moveFile: function (path, fileName, newPath, newFileName) {
  2505. var q = $q.defer();
  2506. newFileName = newFileName || fileName;
  2507. if ((/^\//.test(fileName)) || (/^\//.test(newFileName))) {
  2508. q.reject('file-name cannot start with \/');
  2509. }
  2510. try {
  2511. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2512. fileSystem.getFile(fileName, {create: false}, function (fileEntry) {
  2513. $window.resolveLocalFileSystemURL(newPath, function (newFileEntry) {
  2514. fileEntry.moveTo(newFileEntry, newFileName, function (result) {
  2515. q.resolve(result);
  2516. }, function (error) {
  2517. q.reject(error);
  2518. });
  2519. }, function (err) {
  2520. q.reject(err);
  2521. });
  2522. }, function (err) {
  2523. q.reject(err);
  2524. });
  2525. }, function (er) {
  2526. q.reject(er);
  2527. });
  2528. } catch (e) {
  2529. q.reject(e);
  2530. }
  2531. return q.promise;
  2532. },
  2533. moveDir: function (path, dirName, newPath, newDirName) {
  2534. var q = $q.defer();
  2535. newDirName = newDirName || dirName;
  2536. if (/^\//.test(dirName) || (/^\//.test(newDirName))) {
  2537. q.reject('file-name cannot start with \/');
  2538. }
  2539. try {
  2540. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2541. fileSystem.getDirectory(dirName, {create: false}, function (dirEntry) {
  2542. $window.resolveLocalFileSystemURL(newPath, function (newDirEntry) {
  2543. dirEntry.moveTo(newDirEntry, newDirName, function (result) {
  2544. q.resolve(result);
  2545. }, function (error) {
  2546. q.reject(error);
  2547. });
  2548. }, function (erro) {
  2549. q.reject(erro);
  2550. });
  2551. }, function (err) {
  2552. q.reject(err);
  2553. });
  2554. }, function (er) {
  2555. q.reject(er);
  2556. });
  2557. } catch (e) {
  2558. q.reject(e);
  2559. }
  2560. return q.promise;
  2561. },
  2562. copyDir: function (path, dirName, newPath, newDirName) {
  2563. var q = $q.defer();
  2564. newDirName = newDirName || dirName;
  2565. if (/^\//.test(dirName) || (/^\//.test(newDirName))) {
  2566. q.reject('file-name cannot start with \/');
  2567. }
  2568. try {
  2569. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2570. fileSystem.getDirectory(dirName, {create: false, exclusive: false}, function (dirEntry) {
  2571. $window.resolveLocalFileSystemURL(newPath, function (newDirEntry) {
  2572. dirEntry.copyTo(newDirEntry, newDirName, function (result) {
  2573. q.resolve(result);
  2574. }, function (error) {
  2575. error.message = $cordovaFileError[error.code];
  2576. q.reject(error);
  2577. });
  2578. }, function (erro) {
  2579. erro.message = $cordovaFileError[erro.code];
  2580. q.reject(erro);
  2581. });
  2582. }, function (err) {
  2583. err.message = $cordovaFileError[err.code];
  2584. q.reject(err);
  2585. });
  2586. }, function (er) {
  2587. er.message = $cordovaFileError[er.code];
  2588. q.reject(er);
  2589. });
  2590. } catch (e) {
  2591. e.message = $cordovaFileError[e.code];
  2592. q.reject(e);
  2593. }
  2594. return q.promise;
  2595. },
  2596. copyFile: function (path, fileName, newPath, newFileName) {
  2597. var q = $q.defer();
  2598. newFileName = newFileName || fileName;
  2599. if ((/^\//.test(fileName))) {
  2600. q.reject('file-name cannot start with \/');
  2601. }
  2602. try {
  2603. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2604. fileSystem.getFile(fileName, {create: false, exclusive: false}, function (fileEntry) {
  2605. $window.resolveLocalFileSystemURL(newPath, function (newFileEntry) {
  2606. fileEntry.copyTo(newFileEntry, newFileName, function (result) {
  2607. q.resolve(result);
  2608. }, function (error) {
  2609. error.message = $cordovaFileError[error.code];
  2610. q.reject(error);
  2611. });
  2612. }, function (erro) {
  2613. erro.message = $cordovaFileError[erro.code];
  2614. q.reject(erro);
  2615. });
  2616. }, function (err) {
  2617. err.message = $cordovaFileError[err.code];
  2618. q.reject(err);
  2619. });
  2620. }, function (er) {
  2621. er.message = $cordovaFileError[er.code];
  2622. q.reject(er);
  2623. });
  2624. } catch (e) {
  2625. e.message = $cordovaFileError[e.code];
  2626. q.reject(e);
  2627. }
  2628. return q.promise;
  2629. },
  2630. readFileMetadata: function (path, file) {
  2631. var q = $q.defer();
  2632. if ((/^\//.test(file))) {
  2633. q.reject('directory cannot start with \/');
  2634. }
  2635. try {
  2636. var directory = path + file;
  2637. $window.resolveLocalFileSystemURL(directory, function (fileEntry) {
  2638. fileEntry.file(function (result) {
  2639. q.resolve(result);
  2640. }, function (error) {
  2641. error.message = $cordovaFileError[error.code];
  2642. q.reject(error);
  2643. });
  2644. }, function (err) {
  2645. err.message = $cordovaFileError[err.code];
  2646. q.reject(err);
  2647. });
  2648. } catch (e) {
  2649. e.message = $cordovaFileError[e.code];
  2650. q.reject(e);
  2651. }
  2652. return q.promise;
  2653. }
  2654. /*
  2655. listFiles: function (path, dir) {
  2656. },
  2657. listDir: function (path, dirName) {
  2658. var q = $q.defer();
  2659. try {
  2660. $window.resolveLocalFileSystemURL(path, function (fileSystem) {
  2661. fileSystem.getDirectory(dirName, options, function (parent) {
  2662. var reader = parent.createReader();
  2663. reader.readEntries(function (entries) {
  2664. q.resolve(entries);
  2665. }, function () {
  2666. q.reject('DIR_READ_ERROR : ' + path + dirName);
  2667. });
  2668. }, function (error) {
  2669. error.message = $cordovaFileError[error.code];
  2670. q.reject(error);
  2671. });
  2672. }, function (err) {
  2673. err.message = $cordovaFileError[err.code];
  2674. q.reject(err);
  2675. });
  2676. } catch (e) {
  2677. e.message = $cordovaFileError[e.code];
  2678. q.reject(e);
  2679. }
  2680. return q.promise;
  2681. },
  2682. */
  2683. };
  2684. }];
  2685. }]);
  2686. // install : cordova plugin add https://github.com/pwlin/cordova-plugin-file-opener2.git
  2687. // link : https://github.com/pwlin/cordova-plugin-file-opener2
  2688. angular.module('ngCordova.plugins.fileOpener2', [])
  2689. .factory('$cordovaFileOpener2', ['$q', function ($q) {
  2690. return {
  2691. open: function (file, type) {
  2692. var q = $q.defer();
  2693. cordova.plugins.fileOpener2.open(file, type, {
  2694. error: function (e) {
  2695. q.reject(e);
  2696. }, success: function () {
  2697. q.resolve();
  2698. }
  2699. });
  2700. return q.promise;
  2701. },
  2702. uninstall: function (pack) {
  2703. var q = $q.defer();
  2704. cordova.plugins.fileOpener2.uninstall(pack, {
  2705. error: function (e) {
  2706. q.reject(e);
  2707. }, success: function () {
  2708. q.resolve();
  2709. }
  2710. });
  2711. return q.promise;
  2712. },
  2713. appIsInstalled: function (pack) {
  2714. var q = $q.defer();
  2715. cordova.plugins.fileOpener2.appIsInstalled(pack, {
  2716. success: function (res) {
  2717. q.resolve(res);
  2718. }
  2719. });
  2720. return q.promise;
  2721. }
  2722. };
  2723. }]);
  2724. // install : cordova plugin add cordova-plugin-file-transfer
  2725. // link : https://github.com/apache/cordova-plugin-file-transfer
  2726. /* globals FileTransfer: true */
  2727. angular.module('ngCordova.plugins.fileTransfer', [])
  2728. .factory('$cordovaFileTransfer', ['$q', '$timeout', function ($q, $timeout) {
  2729. return {
  2730. download: function (source, filePath, options, trustAllHosts) {
  2731. var q = $q.defer();
  2732. var ft = new FileTransfer();
  2733. var uri = (options && options.encodeURI === false) ? source : encodeURI(source);
  2734. if (options && options.timeout !== undefined && options.timeout !== null) {
  2735. $timeout(function () {
  2736. ft.abort();
  2737. }, options.timeout);
  2738. options.timeout = null;
  2739. }
  2740. ft.onprogress = function (progress) {
  2741. q.notify(progress);
  2742. };
  2743. q.promise.abort = function () {
  2744. ft.abort();
  2745. };
  2746. ft.download(uri, filePath, q.resolve, q.reject, trustAllHosts, options);
  2747. return q.promise;
  2748. },
  2749. upload: function (server, filePath, options, trustAllHosts) {
  2750. var q = $q.defer();
  2751. var ft = new FileTransfer();
  2752. var uri = (options && options.encodeURI === false) ? server : encodeURI(server);
  2753. if (options && options.timeout !== undefined && options.timeout !== null) {
  2754. $timeout(function () {
  2755. ft.abort();
  2756. }, options.timeout);
  2757. options.timeout = null;
  2758. }
  2759. ft.onprogress = function (progress) {
  2760. q.notify(progress);
  2761. };
  2762. q.promise.abort = function () {
  2763. ft.abort();
  2764. };
  2765. ft.upload(filePath, uri, q.resolve, q.reject, options, trustAllHosts);
  2766. return q.promise;
  2767. }
  2768. };
  2769. }]);
  2770. // install : cordova plugin add https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin.git
  2771. // link : https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin
  2772. angular.module('ngCordova.plugins.flashlight', [])
  2773. .factory('$cordovaFlashlight', ['$q', '$window', function ($q, $window) {
  2774. return {
  2775. available: function () {
  2776. var q = $q.defer();
  2777. $window.plugins.flashlight.available(function (isAvailable) {
  2778. q.resolve(isAvailable);
  2779. });
  2780. return q.promise;
  2781. },
  2782. switchOn: function () {
  2783. var q = $q.defer();
  2784. $window.plugins.flashlight.switchOn(function (response) {
  2785. q.resolve(response);
  2786. }, function (error) {
  2787. q.reject(error);
  2788. });
  2789. return q.promise;
  2790. },
  2791. switchOff: function () {
  2792. var q = $q.defer();
  2793. $window.plugins.flashlight.switchOff(function (response) {
  2794. q.resolve(response);
  2795. }, function (error) {
  2796. q.reject(error);
  2797. });
  2798. return q.promise;
  2799. },
  2800. toggle: function () {
  2801. var q = $q.defer();
  2802. $window.plugins.flashlight.toggle(function (response) {
  2803. q.resolve(response);
  2804. }, function (error) {
  2805. q.reject(error);
  2806. });
  2807. return q.promise;
  2808. }
  2809. };
  2810. }]);
  2811. // install : cordova plugin add https://github.com/floatinghotpot/cordova-plugin-flurry.git
  2812. // link : https://github.com/floatinghotpot/cordova-plugin-flurry
  2813. angular.module('ngCordova.plugins.flurryAds', [])
  2814. .factory('$cordovaFlurryAds', ['$q', '$window', function ($q, $window) {
  2815. return {
  2816. setOptions: function (options) {
  2817. var d = $q.defer();
  2818. $window.FlurryAds.setOptions(options, function () {
  2819. d.resolve();
  2820. }, function () {
  2821. d.reject();
  2822. });
  2823. return d.promise;
  2824. },
  2825. createBanner: function (options) {
  2826. var d = $q.defer();
  2827. $window.FlurryAds.createBanner(options, function () {
  2828. d.resolve();
  2829. }, function () {
  2830. d.reject();
  2831. });
  2832. return d.promise;
  2833. },
  2834. removeBanner: function () {
  2835. var d = $q.defer();
  2836. $window.FlurryAds.removeBanner(function () {
  2837. d.resolve();
  2838. }, function () {
  2839. d.reject();
  2840. });
  2841. return d.promise;
  2842. },
  2843. showBanner: function (position) {
  2844. var d = $q.defer();
  2845. $window.FlurryAds.showBanner(position, function () {
  2846. d.resolve();
  2847. }, function () {
  2848. d.reject();
  2849. });
  2850. return d.promise;
  2851. },
  2852. showBannerAtXY: function (x, y) {
  2853. var d = $q.defer();
  2854. $window.FlurryAds.showBannerAtXY(x, y, function () {
  2855. d.resolve();
  2856. }, function () {
  2857. d.reject();
  2858. });
  2859. return d.promise;
  2860. },
  2861. hideBanner: function () {
  2862. var d = $q.defer();
  2863. $window.FlurryAds.hideBanner(function () {
  2864. d.resolve();
  2865. }, function () {
  2866. d.reject();
  2867. });
  2868. return d.promise;
  2869. },
  2870. prepareInterstitial: function (options) {
  2871. var d = $q.defer();
  2872. $window.FlurryAds.prepareInterstitial(options, function () {
  2873. d.resolve();
  2874. }, function () {
  2875. d.reject();
  2876. });
  2877. return d.promise;
  2878. },
  2879. showInterstitial: function () {
  2880. var d = $q.defer();
  2881. $window.FlurryAds.showInterstitial(function () {
  2882. d.resolve();
  2883. }, function () {
  2884. d.reject();
  2885. });
  2886. return d.promise;
  2887. }
  2888. };
  2889. }]);
  2890. // install : cordova plugin add https://github.com/phonegap-build/GAPlugin.git
  2891. // link : https://github.com/phonegap-build/GAPlugin
  2892. angular.module('ngCordova.plugins.ga', [])
  2893. .factory('$cordovaGA', ['$q', '$window', function ($q, $window) {
  2894. return {
  2895. init: function (id, mingap) {
  2896. var q = $q.defer();
  2897. mingap = (mingap >= 0) ? mingap : 10;
  2898. $window.plugins.gaPlugin.init(function (result) {
  2899. q.resolve(result);
  2900. },
  2901. function (error) {
  2902. q.reject(error);
  2903. },
  2904. id, mingap);
  2905. return q.promise;
  2906. },
  2907. trackEvent: function (success, fail, category, eventAction, eventLabel, eventValue) {
  2908. var q = $q.defer();
  2909. $window.plugins.gaPlugin.trackEvent(function (result) {
  2910. q.resolve(result);
  2911. },
  2912. function (error) {
  2913. q.reject(error);
  2914. },
  2915. category, eventAction, eventLabel, eventValue);
  2916. return q.promise;
  2917. },
  2918. trackPage: function (success, fail, pageURL) {
  2919. var q = $q.defer();
  2920. $window.plugins.gaPlugin.trackPage(function (result) {
  2921. q.resolve(result);
  2922. },
  2923. function (error) {
  2924. q.reject(error);
  2925. },
  2926. pageURL);
  2927. return q.promise;
  2928. },
  2929. setVariable: function (success, fail, index, value) {
  2930. var q = $q.defer();
  2931. $window.plugins.gaPlugin.setVariable(function (result) {
  2932. q.resolve(result);
  2933. },
  2934. function (error) {
  2935. q.reject(error);
  2936. },
  2937. index, value);
  2938. return q.promise;
  2939. },
  2940. exit: function () {
  2941. var q = $q.defer();
  2942. $window.plugins.gaPlugin.exit(function (result) {
  2943. q.resolve(result);
  2944. },
  2945. function (error) {
  2946. q.reject(error);
  2947. });
  2948. return q.promise;
  2949. }
  2950. };
  2951. }]);
  2952. // install : cordova plugin add cordova-plugin-geolocation
  2953. // link : https://github.com/apache/cordova-plugin-geolocation
  2954. angular.module('ngCordova.plugins.geolocation', [])
  2955. .factory('$cordovaGeolocation', ['$q', function ($q) {
  2956. return {
  2957. getCurrentPosition: function (options) {
  2958. var q = $q.defer();
  2959. navigator.geolocation.getCurrentPosition(function (result) {
  2960. q.resolve(result);
  2961. }, function (err) {
  2962. q.reject(err);
  2963. }, options);
  2964. return q.promise;
  2965. },
  2966. watchPosition: function (options) {
  2967. var q = $q.defer();
  2968. var watchID = navigator.geolocation.watchPosition(function (result) {
  2969. q.notify(result);
  2970. }, function (err) {
  2971. q.reject(err);
  2972. }, options);
  2973. q.promise.cancel = function () {
  2974. navigator.geolocation.clearWatch(watchID);
  2975. };
  2976. q.promise.clearWatch = function (id) {
  2977. navigator.geolocation.clearWatch(id || watchID);
  2978. };
  2979. q.promise.watchID = watchID;
  2980. return q.promise;
  2981. },
  2982. clearWatch: function (watchID) {
  2983. return navigator.geolocation.clearWatch(watchID);
  2984. }
  2985. };
  2986. }]);
  2987. // install : cordova plugin add cordova-plugin-globalization
  2988. // link : https://github.com/apache/cordova-plugin-globalization
  2989. angular.module('ngCordova.plugins.globalization', [])
  2990. .factory('$cordovaGlobalization', ['$q', function ($q) {
  2991. return {
  2992. getPreferredLanguage: function () {
  2993. var q = $q.defer();
  2994. navigator.globalization.getPreferredLanguage(function (result) {
  2995. q.resolve(result);
  2996. },
  2997. function (err) {
  2998. q.reject(err);
  2999. });
  3000. return q.promise;
  3001. },
  3002. getLocaleName: function () {
  3003. var q = $q.defer();
  3004. navigator.globalization.getLocaleName(function (result) {
  3005. q.resolve(result);
  3006. },
  3007. function (err) {
  3008. q.reject(err);
  3009. });
  3010. return q.promise;
  3011. },
  3012. getFirstDayOfWeek: function () {
  3013. var q = $q.defer();
  3014. navigator.globalization.getFirstDayOfWeek(function (result) {
  3015. q.resolve(result);
  3016. },
  3017. function (err) {
  3018. q.reject(err);
  3019. });
  3020. return q.promise;
  3021. },
  3022. // "date" parameter must be a JavaScript Date Object.
  3023. dateToString: function (date, options) {
  3024. var q = $q.defer();
  3025. navigator.globalization.dateToString(
  3026. date,
  3027. function (result) {
  3028. q.resolve(result);
  3029. },
  3030. function (err) {
  3031. q.reject(err);
  3032. },
  3033. options);
  3034. return q.promise;
  3035. },
  3036. stringToDate: function (dateString, options) {
  3037. var q = $q.defer();
  3038. navigator.globalization.stringToDate(
  3039. dateString,
  3040. function (result) {
  3041. q.resolve(result);
  3042. },
  3043. function (err) {
  3044. q.reject(err);
  3045. },
  3046. options);
  3047. return q.promise;
  3048. },
  3049. getDatePattern: function (options) {
  3050. var q = $q.defer();
  3051. navigator.globalization.getDatePattern(
  3052. function (result) {
  3053. q.resolve(result);
  3054. },
  3055. function (err) {
  3056. q.reject(err);
  3057. },
  3058. options);
  3059. return q.promise;
  3060. },
  3061. getDateNames: function (options) {
  3062. var q = $q.defer();
  3063. navigator.globalization.getDateNames(
  3064. function (result) {
  3065. q.resolve(result);
  3066. },
  3067. function (err) {
  3068. q.reject(err);
  3069. },
  3070. options);
  3071. return q.promise;
  3072. },
  3073. // "date" parameter must be a JavaScript Date Object.
  3074. isDayLightSavingsTime: function (date) {
  3075. var q = $q.defer();
  3076. navigator.globalization.isDayLightSavingsTime(
  3077. date,
  3078. function (result) {
  3079. q.resolve(result);
  3080. },
  3081. function (err) {
  3082. q.reject(err);
  3083. });
  3084. return q.promise;
  3085. },
  3086. numberToString: function (number, options) {
  3087. var q = $q.defer();
  3088. navigator.globalization.numberToString(
  3089. number,
  3090. function (result) {
  3091. q.resolve(result);
  3092. },
  3093. function (err) {
  3094. q.reject(err);
  3095. },
  3096. options);
  3097. return q.promise;
  3098. },
  3099. stringToNumber: function (numberString, options) {
  3100. var q = $q.defer();
  3101. navigator.globalization.stringToNumber(
  3102. numberString,
  3103. function (result) {
  3104. q.resolve(result);
  3105. },
  3106. function (err) {
  3107. q.reject(err);
  3108. },
  3109. options);
  3110. return q.promise;
  3111. },
  3112. getNumberPattern: function (options) {
  3113. var q = $q.defer();
  3114. navigator.globalization.getNumberPattern(
  3115. function (result) {
  3116. q.resolve(result);
  3117. },
  3118. function (err) {
  3119. q.reject(err);
  3120. },
  3121. options);
  3122. return q.promise;
  3123. },
  3124. getCurrencyPattern: function (currencyCode) {
  3125. var q = $q.defer();
  3126. navigator.globalization.getCurrencyPattern(
  3127. currencyCode,
  3128. function (result) {
  3129. q.resolve(result);
  3130. },
  3131. function (err) {
  3132. q.reject(err);
  3133. });
  3134. return q.promise;
  3135. }
  3136. };
  3137. }]);
  3138. // install : cordova plugin add https://github.com/floatinghotpot/cordova-admob-pro.git
  3139. // link : https://github.com/floatinghotpot/cordova-admob-pro
  3140. angular.module('ngCordova.plugins.googleAds', [])
  3141. .factory('$cordovaGoogleAds', ['$q', '$window', function ($q, $window) {
  3142. return {
  3143. setOptions: function (options) {
  3144. var d = $q.defer();
  3145. $window.AdMob.setOptions(options, function () {
  3146. d.resolve();
  3147. }, function () {
  3148. d.reject();
  3149. });
  3150. return d.promise;
  3151. },
  3152. createBanner: function (options) {
  3153. var d = $q.defer();
  3154. $window.AdMob.createBanner(options, function () {
  3155. d.resolve();
  3156. }, function () {
  3157. d.reject();
  3158. });
  3159. return d.promise;
  3160. },
  3161. removeBanner: function () {
  3162. var d = $q.defer();
  3163. $window.AdMob.removeBanner(function () {
  3164. d.resolve();
  3165. }, function () {
  3166. d.reject();
  3167. });
  3168. return d.promise;
  3169. },
  3170. showBanner: function (position) {
  3171. var d = $q.defer();
  3172. $window.AdMob.showBanner(position, function () {
  3173. d.resolve();
  3174. }, function () {
  3175. d.reject();
  3176. });
  3177. return d.promise;
  3178. },
  3179. showBannerAtXY: function (x, y) {
  3180. var d = $q.defer();
  3181. $window.AdMob.showBannerAtXY(x, y, function () {
  3182. d.resolve();
  3183. }, function () {
  3184. d.reject();
  3185. });
  3186. return d.promise;
  3187. },
  3188. hideBanner: function () {
  3189. var d = $q.defer();
  3190. $window.AdMob.hideBanner(function () {
  3191. d.resolve();
  3192. }, function () {
  3193. d.reject();
  3194. });
  3195. return d.promise;
  3196. },
  3197. prepareInterstitial: function (options) {
  3198. var d = $q.defer();
  3199. $window.AdMob.prepareInterstitial(options, function () {
  3200. d.resolve();
  3201. }, function () {
  3202. d.reject();
  3203. });
  3204. return d.promise;
  3205. },
  3206. showInterstitial: function () {
  3207. var d = $q.defer();
  3208. $window.AdMob.showInterstitial(function () {
  3209. d.resolve();
  3210. }, function () {
  3211. d.reject();
  3212. });
  3213. return d.promise;
  3214. }
  3215. };
  3216. }]);
  3217. // install : cordova plugin add https://github.com/danwilson/google-analytics-plugin.git
  3218. // link : https://github.com/danwilson/google-analytics-plugin
  3219. angular.module('ngCordova.plugins.googleAnalytics', [])
  3220. .factory('$cordovaGoogleAnalytics', ['$q', '$window', function ($q, $window) {
  3221. return {
  3222. startTrackerWithId: function (id) {
  3223. var d = $q.defer();
  3224. $window.analytics.startTrackerWithId(id, function (response) {
  3225. d.resolve(response);
  3226. }, function (error) {
  3227. d.reject(error);
  3228. });
  3229. return d.promise;
  3230. },
  3231. setUserId: function (id) {
  3232. var d = $q.defer();
  3233. $window.analytics.setUserId(id, function (response) {
  3234. d.resolve(response);
  3235. }, function (error) {
  3236. d.reject(error);
  3237. });
  3238. return d.promise;
  3239. },
  3240. debugMode: function () {
  3241. var d = $q.defer();
  3242. $window.analytics.debugMode(function (response) {
  3243. d.resolve(response);
  3244. }, function () {
  3245. d.reject();
  3246. });
  3247. return d.promise;
  3248. },
  3249. trackView: function (screenName) {
  3250. var d = $q.defer();
  3251. $window.analytics.trackView(screenName, function (response) {
  3252. d.resolve(response);
  3253. }, function (error) {
  3254. d.reject(error);
  3255. });
  3256. return d.promise;
  3257. },
  3258. addCustomDimension: function (key, value) {
  3259. var d = $q.defer();
  3260. var parsedKey = parseInt(key, 10);
  3261. if (isNaN(parsedKey)) {
  3262. d.reject('Parameter "key" must be an integer.');
  3263. }
  3264. $window.analytics.addCustomDimension(parsedKey, value, function () {
  3265. d.resolve();
  3266. }, function (error) {
  3267. d.reject(error);
  3268. });
  3269. return d.promise;
  3270. },
  3271. trackEvent: function (category, action, label, value) {
  3272. var d = $q.defer();
  3273. $window.analytics.trackEvent(category, action, label, value, function (response) {
  3274. d.resolve(response);
  3275. }, function (error) {
  3276. d.reject(error);
  3277. });
  3278. return d.promise;
  3279. },
  3280. trackException: function (description, fatal) {
  3281. var d = $q.defer();
  3282. $window.analytics.trackException(description, fatal, function (response) {
  3283. d.resolve(response);
  3284. }, function (error) {
  3285. d.reject(error);
  3286. });
  3287. return d.promise;
  3288. },
  3289. trackTiming: function (category, milliseconds, variable, label) {
  3290. var d = $q.defer();
  3291. $window.analytics.trackTiming(category, milliseconds, variable, label, function (response) {
  3292. d.resolve(response);
  3293. }, function (error) {
  3294. d.reject(error);
  3295. });
  3296. return d.promise;
  3297. },
  3298. addTransaction: function (transactionId, affiliation, revenue, tax, shipping, currencyCode) {
  3299. var d = $q.defer();
  3300. $window.analytics.addTransaction(transactionId, affiliation, revenue, tax, shipping, currencyCode, function (response) {
  3301. d.resolve(response);
  3302. }, function (error) {
  3303. d.reject(error);
  3304. });
  3305. return d.promise;
  3306. },
  3307. addTransactionItem: function (transactionId, name, sku, category, price, quantity, currencyCode) {
  3308. var d = $q.defer();
  3309. $window.analytics.addTransactionItem(transactionId, name, sku, category, price, quantity, currencyCode, function (response) {
  3310. d.resolve(response);
  3311. }, function (error) {
  3312. d.reject(error);
  3313. });
  3314. return d.promise;
  3315. }
  3316. };
  3317. }]);
  3318. // install :
  3319. // link :
  3320. // Google Maps needs ALOT of work!
  3321. // Not for production use
  3322. angular.module('ngCordova.plugins.googleMap', [])
  3323. .factory('$cordovaGoogleMap', ['$q', '$window', function ($q, $window) {
  3324. var map = null;
  3325. return {
  3326. getMap: function (options) {
  3327. var q = $q.defer();
  3328. if (!$window.plugin.google.maps) {
  3329. q.reject(null);
  3330. } else {
  3331. var div = document.getElementById('map_canvas');
  3332. map = $window.plugin.google.maps.Map.getMap(options);
  3333. map.setDiv(div);
  3334. q.resolve(map);
  3335. }
  3336. return q.promise;
  3337. },
  3338. isMapLoaded: function () { // check if an instance of the map exists
  3339. return !!map;
  3340. },
  3341. addMarker: function (markerOptions) { // add a marker to the map with given markerOptions
  3342. var q = $q.defer();
  3343. map.addMarker(markerOptions, function (marker) {
  3344. q.resolve(marker);
  3345. });
  3346. return q.promise;
  3347. },
  3348. getMapTypeIds: function () {
  3349. return $window.plugin.google.maps.mapTypeId;
  3350. },
  3351. setVisible: function (isVisible) {
  3352. var q = $q.defer();
  3353. map.setVisible(isVisible);
  3354. return q.promise;
  3355. },
  3356. // I don't know how to deallocate te map and the google map plugin.
  3357. cleanup: function () {
  3358. map = null;
  3359. // delete map;
  3360. }
  3361. };
  3362. }]);
  3363. // install : cordova plugin add https://github.com/ptgamr/cordova-google-play-game.git --variable APP_ID=123456789
  3364. // link : https://github.com/ptgamr/cordova-google-play-game
  3365. /* globals googleplaygame: true */
  3366. angular.module('ngCordova.plugins.googlePlayGame', [])
  3367. .factory('$cordovaGooglePlayGame', ['$q', function ($q) {
  3368. return {
  3369. auth: function () {
  3370. var q = $q.defer();
  3371. googleplaygame.auth(function (success) {
  3372. return q.resolve(success);
  3373. }, function (err) {
  3374. return q.reject(err);
  3375. });
  3376. return q.promise;
  3377. },
  3378. signout: function () {
  3379. var q = $q.defer();
  3380. googleplaygame.signout(function (success) {
  3381. return q.resolve(success);
  3382. }, function (err) {
  3383. return q.reject(err);
  3384. });
  3385. return q.promise;
  3386. },
  3387. isSignedIn: function () {
  3388. var q = $q.defer();
  3389. googleplaygame.isSignedIn(function (success) {
  3390. return q.resolve(success);
  3391. }, function (err) {
  3392. return q.reject(err);
  3393. });
  3394. return q.promise;
  3395. },
  3396. showPlayer: function () {
  3397. var q = $q.defer();
  3398. googleplaygame.showPlayer(function (success) {
  3399. return q.resolve(success);
  3400. }, function (err) {
  3401. return q.reject(err);
  3402. });
  3403. return q.promise;
  3404. },
  3405. submitScore: function (data) {
  3406. var q = $q.defer();
  3407. googleplaygame.submitScore(data, function (success) {
  3408. return q.resolve(success);
  3409. }, function (err) {
  3410. return q.reject(err);
  3411. });
  3412. return q.promise;
  3413. },
  3414. showAllLeaderboards: function () {
  3415. var q = $q.defer();
  3416. googleplaygame.showAllLeaderboards(function (success) {
  3417. return q.resolve(success);
  3418. }, function (err) {
  3419. return q.reject(err);
  3420. });
  3421. return q.promise;
  3422. },
  3423. showLeaderboard: function (data) {
  3424. var q = $q.defer();
  3425. googleplaygame.showLeaderboard(data, function (success) {
  3426. return q.resolve(success);
  3427. }, function (err) {
  3428. return q.reject(err);
  3429. });
  3430. return q.promise;
  3431. },
  3432. unlockAchievement: function (data) {
  3433. var q = $q.defer();
  3434. googleplaygame.unlockAchievement(data, function (success) {
  3435. return q.resolve(success);
  3436. }, function (err) {
  3437. return q.reject(err);
  3438. });
  3439. return q.promise;
  3440. },
  3441. incrementAchievement: function (data) {
  3442. var q = $q.defer();
  3443. googleplaygame.incrementAchievement(data, function (success) {
  3444. return q.resolve(success);
  3445. }, function (err) {
  3446. return q.reject(err);
  3447. });
  3448. return q.promise;
  3449. },
  3450. showAchievements: function () {
  3451. var q = $q.defer();
  3452. googleplaygame.showAchievements(function (success) {
  3453. return q.resolve(success);
  3454. }, function (err) {
  3455. return q.reject(err);
  3456. });
  3457. return q.promise;
  3458. }
  3459. };
  3460. }]);
  3461. // install : cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus.git
  3462. // link : https://github.com/EddyVerbruggen/cordova-plugin-googleplus
  3463. angular.module('ngCordova.plugins.googlePlus', [])
  3464. .factory('$cordovaGooglePlus', ['$q', '$window', function ($q, $window) {
  3465. return {
  3466. login: function (iosKey) {
  3467. var q = $q.defer();
  3468. if (iosKey === undefined) {
  3469. iosKey = {};
  3470. }
  3471. $window.plugins.googleplus.login({'iOSApiKey': iosKey}, function (response) {
  3472. q.resolve(response);
  3473. }, function (error) {
  3474. q.reject(error);
  3475. });
  3476. return q.promise;
  3477. },
  3478. silentLogin: function (iosKey) {
  3479. var q = $q.defer();
  3480. if (iosKey === undefined) {
  3481. iosKey = {};
  3482. }
  3483. $window.plugins.googleplus.trySilentLogin({'iOSApiKey': iosKey}, function (response) {
  3484. q.resolve(response);
  3485. }, function (error) {
  3486. q.reject(error);
  3487. });
  3488. return q.promise;
  3489. },
  3490. logout: function () {
  3491. var q = $q.defer();
  3492. $window.plugins.googleplus.logout(function (response) {
  3493. q.resolve(response);
  3494. });
  3495. },
  3496. disconnect: function () {
  3497. var q = $q.defer();
  3498. $window.plugins.googleplus.disconnect(function (response) {
  3499. q.resolve(response);
  3500. });
  3501. },
  3502. isAvailable: function () {
  3503. var q = $q.defer();
  3504. $window.plugins.googleplus.isAvailable(function (available) {
  3505. if (available) {
  3506. q.resolve(available);
  3507. } else {
  3508. q.reject(available);
  3509. }
  3510. });
  3511. return q.promise;
  3512. }
  3513. };
  3514. }]);
  3515. // install : cordova plugin add https://github.com/Telerik-Verified-Plugins/HealthKit.git
  3516. // link : https://github.com/Telerik-Verified-Plugins/HealthKit
  3517. angular.module('ngCordova.plugins.healthKit', [])
  3518. .factory('$cordovaHealthKit', ['$q', '$window', function ($q, $window) {
  3519. return {
  3520. isAvailable: function () {
  3521. var q = $q.defer();
  3522. $window.plugins.healthkit.available(function (success) {
  3523. q.resolve(success);
  3524. }, function (err) {
  3525. q.reject(err);
  3526. });
  3527. return q.promise;
  3528. },
  3529. /**
  3530. * Check whether or not the user granted your app access to a specific HealthKit type.
  3531. * Reference for possible types:
  3532. * https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HealthKit_Constants/
  3533. */
  3534. checkAuthStatus: function (type) {
  3535. var q = $q.defer();
  3536. type = type || 'HKQuantityTypeIdentifierHeight';
  3537. $window.plugins.healthkit.checkAuthStatus({
  3538. 'type': type
  3539. }, function (success) {
  3540. q.resolve(success);
  3541. }, function (err) {
  3542. q.reject(err);
  3543. });
  3544. return q.promise;
  3545. },
  3546. /**
  3547. * Request authorization to access HealthKit data. See the full HealthKit constants
  3548. * reference for possible read and write types:
  3549. * https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HealthKit_Constants/
  3550. */
  3551. requestAuthorization: function (readTypes, writeTypes) {
  3552. var q = $q.defer();
  3553. readTypes = readTypes || [
  3554. 'HKCharacteristicTypeIdentifierDateOfBirth', 'HKQuantityTypeIdentifierActiveEnergyBurned', 'HKQuantityTypeIdentifierHeight'
  3555. ];
  3556. writeTypes = writeTypes || [
  3557. 'HKQuantityTypeIdentifierActiveEnergyBurned', 'HKQuantityTypeIdentifierHeight', 'HKQuantityTypeIdentifierDistanceCycling'
  3558. ];
  3559. $window.plugins.healthkit.requestAuthorization({
  3560. 'readTypes': readTypes,
  3561. 'writeTypes': writeTypes
  3562. }, function (success) {
  3563. q.resolve(success);
  3564. }, function (err) {
  3565. q.reject(err);
  3566. });
  3567. return q.promise;
  3568. },
  3569. readDateOfBirth: function () {
  3570. var q = $q.defer();
  3571. $window.plugins.healthkit.readDateOfBirth(
  3572. function (success) {
  3573. q.resolve(success);
  3574. },
  3575. function (err) {
  3576. q.resolve(err);
  3577. }
  3578. );
  3579. return q.promise;
  3580. },
  3581. readGender: function () {
  3582. var q = $q.defer();
  3583. $window.plugins.healthkit.readGender(
  3584. function (success) {
  3585. q.resolve(success);
  3586. },
  3587. function (err) {
  3588. q.resolve(err);
  3589. }
  3590. );
  3591. return q.promise;
  3592. },
  3593. saveWeight: function (value, units, date) {
  3594. var q = $q.defer();
  3595. $window.plugins.healthkit.saveWeight({
  3596. 'unit': units || 'lb',
  3597. 'amount': value,
  3598. 'date': date || new Date()
  3599. },
  3600. function (success) {
  3601. q.resolve(success);
  3602. },
  3603. function (err) {
  3604. q.resolve(err);
  3605. }
  3606. );
  3607. return q.promise;
  3608. },
  3609. readWeight: function (units) {
  3610. var q = $q.defer();
  3611. $window.plugins.healthkit.readWeight({
  3612. 'unit': units || 'lb'
  3613. },
  3614. function (success) {
  3615. q.resolve(success);
  3616. },
  3617. function (err) {
  3618. q.resolve(err);
  3619. }
  3620. );
  3621. return q.promise;
  3622. },
  3623. saveHeight: function (value, units, date) {
  3624. var q = $q.defer();
  3625. $window.plugins.healthkit.saveHeight({
  3626. 'unit': units || 'in',
  3627. 'amount': value,
  3628. 'date': date || new Date()
  3629. },
  3630. function (success) {
  3631. q.resolve(success);
  3632. },
  3633. function (err) {
  3634. q.resolve(err);
  3635. }
  3636. );
  3637. return q.promise;
  3638. },
  3639. readHeight: function (units) {
  3640. var q = $q.defer();
  3641. $window.plugins.healthkit.readHeight({
  3642. 'unit': units || 'in'
  3643. },
  3644. function (success) {
  3645. q.resolve(success);
  3646. },
  3647. function (err) {
  3648. q.resolve(err);
  3649. }
  3650. );
  3651. return q.promise;
  3652. },
  3653. findWorkouts: function () {
  3654. var q = $q.defer();
  3655. $window.plugins.healthkit.findWorkouts({},
  3656. function (success) {
  3657. q.resolve(success);
  3658. },
  3659. function (err) {
  3660. q.resolve(err);
  3661. }
  3662. );
  3663. return q.promise;
  3664. },
  3665. /**
  3666. * Save a workout.
  3667. *
  3668. * Workout param should be of the format:
  3669. {
  3670. 'activityType': 'HKWorkoutActivityTypeCycling', // HKWorkoutActivityType constant (https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HKWorkout_Class/#//apple_ref/c/tdef/HKWorkoutActivityType)
  3671. 'quantityType': 'HKQuantityTypeIdentifierDistanceCycling',
  3672. 'startDate': new Date(), // mandatory
  3673. 'endDate': null, // optional, use either this or duration
  3674. 'duration': 3600, // in seconds, optional, use either this or endDate
  3675. 'energy': 300, //
  3676. 'energyUnit': 'kcal', // J|cal|kcal
  3677. 'distance': 11, // optional
  3678. 'distanceUnit': 'km' // probably useful with the former param
  3679. // 'extraData': "", // Not sure how necessary this is
  3680. },
  3681. */
  3682. saveWorkout: function (workout) {
  3683. var q = $q.defer();
  3684. $window.plugins.healthkit.saveWorkout(workout,
  3685. function (success) {
  3686. q.resolve(success);
  3687. },
  3688. function (err) {
  3689. q.resolve(err);
  3690. }
  3691. );
  3692. return q.promise;
  3693. },
  3694. /**
  3695. * Sample any kind of health data through a given date range.
  3696. * sampleQuery of the format:
  3697. {
  3698. 'startDate': yesterday, // mandatory
  3699. 'endDate': tomorrow, // mandatory
  3700. 'sampleType': 'HKQuantityTypeIdentifierHeight',
  3701. 'unit' : 'cm'
  3702. },
  3703. */
  3704. querySampleType: function (sampleQuery) {
  3705. var q = $q.defer();
  3706. $window.plugins.healthkit.querySampleType(sampleQuery,
  3707. function (success) {
  3708. q.resolve(success);
  3709. },
  3710. function (err) {
  3711. q.resolve(err);
  3712. }
  3713. );
  3714. return q.promise;
  3715. }
  3716. };
  3717. }]);
  3718. // install : cordova plugin add https://github.com/floatinghotpot/cordova-httpd.git
  3719. // link : https://github.com/floatinghotpot/cordova-httpd
  3720. angular.module('ngCordova.plugins.httpd', [])
  3721. .factory('$cordovaHttpd', ['$q', function ($q) {
  3722. return {
  3723. startServer: function (options) {
  3724. var d = $q.defer();
  3725. cordova.plugins.CorHttpd.startServer(options, function () {
  3726. d.resolve();
  3727. }, function () {
  3728. d.reject();
  3729. });
  3730. return d.promise;
  3731. },
  3732. stopServer: function () {
  3733. var d = $q.defer();
  3734. cordova.plugins.CorHttpd.stopServer(function () {
  3735. d.resolve();
  3736. }, function () {
  3737. d.reject();
  3738. });
  3739. return d.promise;
  3740. },
  3741. getURL: function () {
  3742. var d = $q.defer();
  3743. cordova.plugins.CorHttpd.getURL(function (url) {
  3744. d.resolve(url);
  3745. }, function () {
  3746. d.reject();
  3747. });
  3748. return d.promise;
  3749. },
  3750. getLocalPath: function () {
  3751. var d = $q.defer();
  3752. cordova.plugins.CorHttpd.getLocalPath(function (path) {
  3753. d.resolve(path);
  3754. }, function () {
  3755. d.reject();
  3756. });
  3757. return d.promise;
  3758. }
  3759. };
  3760. }]);
  3761. // install : cordova plugin add https://github.com/floatinghotpot/cordova-plugin-iad.git
  3762. // link : https://github.com/floatinghotpot/cordova-plugin-iad
  3763. angular.module('ngCordova.plugins.iAd', [])
  3764. .factory('$cordovaiAd', ['$q', '$window', function ($q, $window) {
  3765. return {
  3766. setOptions: function (options) {
  3767. var d = $q.defer();
  3768. $window.iAd.setOptions(options, function () {
  3769. d.resolve();
  3770. }, function () {
  3771. d.reject();
  3772. });
  3773. return d.promise;
  3774. },
  3775. createBanner: function (options) {
  3776. var d = $q.defer();
  3777. $window.iAd.createBanner(options, function () {
  3778. d.resolve();
  3779. }, function () {
  3780. d.reject();
  3781. });
  3782. return d.promise;
  3783. },
  3784. removeBanner: function () {
  3785. var d = $q.defer();
  3786. $window.iAd.removeBanner(function () {
  3787. d.resolve();
  3788. }, function () {
  3789. d.reject();
  3790. });
  3791. return d.promise;
  3792. },
  3793. showBanner: function (position) {
  3794. var d = $q.defer();
  3795. $window.iAd.showBanner(position, function () {
  3796. d.resolve();
  3797. }, function () {
  3798. d.reject();
  3799. });
  3800. return d.promise;
  3801. },
  3802. showBannerAtXY: function (x, y) {
  3803. var d = $q.defer();
  3804. $window.iAd.showBannerAtXY(x, y, function () {
  3805. d.resolve();
  3806. }, function () {
  3807. d.reject();
  3808. });
  3809. return d.promise;
  3810. },
  3811. hideBanner: function () {
  3812. var d = $q.defer();
  3813. $window.iAd.hideBanner(function () {
  3814. d.resolve();
  3815. }, function () {
  3816. d.reject();
  3817. });
  3818. return d.promise;
  3819. },
  3820. prepareInterstitial: function (options) {
  3821. var d = $q.defer();
  3822. $window.iAd.prepareInterstitial(options, function () {
  3823. d.resolve();
  3824. }, function () {
  3825. d.reject();
  3826. });
  3827. return d.promise;
  3828. },
  3829. showInterstitial: function () {
  3830. var d = $q.defer();
  3831. $window.iAd.showInterstitial(function () {
  3832. d.resolve();
  3833. }, function () {
  3834. d.reject();
  3835. });
  3836. return d.promise;
  3837. }
  3838. };
  3839. }]);
  3840. // install : cordova plugin add https://github.com/wymsee/cordova-imagePicker.git
  3841. // link : https://github.com/wymsee/cordova-imagePicker
  3842. angular.module('ngCordova.plugins.imagePicker', [])
  3843. .factory('$cordovaImagePicker', ['$q', '$window', function ($q, $window) {
  3844. return {
  3845. getPictures: function (options) {
  3846. var q = $q.defer();
  3847. $window.imagePicker.getPictures(function (results) {
  3848. q.resolve(results);
  3849. }, function (error) {
  3850. q.reject(error);
  3851. }, options);
  3852. return q.promise;
  3853. }
  3854. };
  3855. }]);
  3856. // install : cordova plugin add cordova-plugin-inappbrowser
  3857. // link : https://github.com/apache/cordova-plugin-inappbrowser
  3858. angular.module('ngCordova.plugins.inAppBrowser', [])
  3859. .provider('$cordovaInAppBrowser', [function () {
  3860. var ref;
  3861. var defaultOptions = this.defaultOptions = {};
  3862. this.setDefaultOptions = function (config) {
  3863. defaultOptions = angular.extend(defaultOptions, config);
  3864. };
  3865. this.$get = ['$rootScope', '$q', '$window', '$timeout', function ($rootScope, $q, $window, $timeout) {
  3866. return {
  3867. open: function (url, target, requestOptions) {
  3868. var q = $q.defer();
  3869. if (requestOptions && !angular.isObject(requestOptions)) {
  3870. q.reject('options must be an object');
  3871. return q.promise;
  3872. }
  3873. var options = angular.extend({}, defaultOptions, requestOptions);
  3874. var opt = [];
  3875. angular.forEach(options, function (value, key) {
  3876. opt.push(key + '=' + value);
  3877. });
  3878. var optionsString = opt.join();
  3879. ref = $window.open(url, target, optionsString);
  3880. ref.addEventListener('loadstart', function (event) {
  3881. $timeout(function () {
  3882. $rootScope.$broadcast('$cordovaInAppBrowser:loadstart', event);
  3883. });
  3884. }, false);
  3885. ref.addEventListener('loadstop', function (event) {
  3886. q.resolve(event);
  3887. $timeout(function () {
  3888. $rootScope.$broadcast('$cordovaInAppBrowser:loadstop', event);
  3889. });
  3890. }, false);
  3891. ref.addEventListener('loaderror', function (event) {
  3892. q.reject(event);
  3893. $timeout(function () {
  3894. $rootScope.$broadcast('$cordovaInAppBrowser:loaderror', event);
  3895. });
  3896. }, false);
  3897. ref.addEventListener('exit', function (event) {
  3898. $timeout(function () {
  3899. $rootScope.$broadcast('$cordovaInAppBrowser:exit', event);
  3900. });
  3901. }, false);
  3902. return q.promise;
  3903. },
  3904. close: function () {
  3905. ref.close();
  3906. ref = null;
  3907. },
  3908. show: function () {
  3909. ref.show();
  3910. },
  3911. executeScript: function (details) {
  3912. var q = $q.defer();
  3913. ref.executeScript(details, function (result) {
  3914. q.resolve(result);
  3915. });
  3916. return q.promise;
  3917. },
  3918. insertCSS: function (details) {
  3919. var q = $q.defer();
  3920. ref.insertCSS(details, function (result) {
  3921. q.resolve(result);
  3922. });
  3923. return q.promise;
  3924. }
  3925. };
  3926. }];
  3927. }]);
  3928. // install : cordova plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git
  3929. // link : https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin
  3930. angular.module('ngCordova.plugins.insomnia', [])
  3931. .factory('$cordovaInsomnia', ['$window', function ($window) {
  3932. return {
  3933. keepAwake: function () {
  3934. return $window.plugins.insomnia.keepAwake();
  3935. },
  3936. allowSleepAgain: function () {
  3937. return $window.plugins.insomnia.allowSleepAgain();
  3938. }
  3939. };
  3940. }]);
  3941. // install : cordova plugins add https://github.com/vstirbu/InstagramPlugin.git
  3942. // link : https://github.com/vstirbu/InstagramPlugin
  3943. /* globals Instagram: true */
  3944. angular.module('ngCordova.plugins.instagram', [])
  3945. .factory('$cordovaInstagram', ['$q', function ($q) {
  3946. return {
  3947. share: function (options) {
  3948. var q = $q.defer();
  3949. if (!window.Instagram) {
  3950. console.error('Tried to call Instagram.share but the Instagram plugin isn\'t installed!');
  3951. q.resolve(null);
  3952. return q.promise;
  3953. }
  3954. Instagram.share(options.image, options.caption, function (err) {
  3955. if(err) {
  3956. q.reject(err);
  3957. } else {
  3958. q.resolve(true);
  3959. }
  3960. });
  3961. return q.promise;
  3962. },
  3963. isInstalled: function () {
  3964. var q = $q.defer();
  3965. if (!window.Instagram) {
  3966. console.error('Tried to call Instagram.isInstalled but the Instagram plugin isn\'t installed!');
  3967. q.resolve(null);
  3968. return q.promise;
  3969. }
  3970. Instagram.isInstalled(function (err, installed) {
  3971. if (err) {
  3972. q.reject(err);
  3973. } else {
  3974. q.resolve(installed);
  3975. }
  3976. });
  3977. return q.promise;
  3978. }
  3979. };
  3980. }]);
  3981. // install : cordova plugin add https://github.com/driftyco/ionic-plugins-keyboard.git
  3982. // link : https://github.com/driftyco/ionic-plugins-keyboard
  3983. angular.module('ngCordova.plugins.keyboard', [])
  3984. .factory('$cordovaKeyboard', ['$rootScope', function ($rootScope) {
  3985. var keyboardShowEvent = function () {
  3986. $rootScope.$evalAsync(function () {
  3987. $rootScope.$broadcast('$cordovaKeyboard:show');
  3988. });
  3989. };
  3990. var keyboardHideEvent = function () {
  3991. $rootScope.$evalAsync(function () {
  3992. $rootScope.$broadcast('$cordovaKeyboard:hide');
  3993. });
  3994. };
  3995. document.addEventListener('deviceready', function () {
  3996. if (cordova.plugins.Keyboard) {
  3997. window.addEventListener('native.keyboardshow', keyboardShowEvent, false);
  3998. window.addEventListener('native.keyboardhide', keyboardHideEvent, false);
  3999. }
  4000. });
  4001. return {
  4002. hideAccessoryBar: function (bool) {
  4003. return cordova.plugins.Keyboard.hideKeyboardAccessoryBar(bool);
  4004. },
  4005. close: function () {
  4006. return cordova.plugins.Keyboard.close();
  4007. },
  4008. show: function () {
  4009. return cordova.plugins.Keyboard.show();
  4010. },
  4011. disableScroll: function (bool) {
  4012. return cordova.plugins.Keyboard.disableScroll(bool);
  4013. },
  4014. isVisible: function () {
  4015. return cordova.plugins.Keyboard.isVisible;
  4016. },
  4017. clearShowWatch: function () {
  4018. document.removeEventListener('native.keyboardshow', keyboardShowEvent);
  4019. $rootScope.$$listeners['$cordovaKeyboard:show'] = [];
  4020. },
  4021. clearHideWatch: function () {
  4022. document.removeEventListener('native.keyboardhide', keyboardHideEvent);
  4023. $rootScope.$$listeners['$cordovaKeyboard:hide'] = [];
  4024. }
  4025. };
  4026. }]);
  4027. // install : cordova plugin add https://github.com/shazron/KeychainPlugin.git
  4028. // link : https://github.com/shazron/KeychainPlugin
  4029. /* globals Keychain: true */
  4030. angular.module('ngCordova.plugins.keychain', [])
  4031. .factory('$cordovaKeychain', ['$q', function ($q) {
  4032. return {
  4033. getForKey: function (key, serviceName) {
  4034. var defer = $q.defer(),
  4035. kc = new Keychain();
  4036. kc.getForKey(defer.resolve, defer.reject, key, serviceName);
  4037. return defer.promise;
  4038. },
  4039. setForKey: function (key, serviceName, value) {
  4040. var defer = $q.defer(),
  4041. kc = new Keychain();
  4042. kc.setForKey(defer.resolve, defer.reject, key, serviceName, value);
  4043. return defer.promise;
  4044. },
  4045. removeForKey: function (key, serviceName) {
  4046. var defer = $q.defer(),
  4047. kc = new Keychain();
  4048. kc.removeForKey(defer.resolve, defer.reject, key, serviceName);
  4049. return defer.promise;
  4050. }
  4051. };
  4052. }]);
  4053. // install : cordova plugin add uk.co.workingedge.phonegap.plugin.launchnavigator
  4054. // link : https://github.com/dpa99c/phonegap-launch-navigator
  4055. /* globals launchnavigator: true */
  4056. angular.module('ngCordova.plugins.launchNavigator', [])
  4057. .factory('$cordovaLaunchNavigator', ['$q', function ($q) {
  4058. return {
  4059. navigate: function (destination, start, options) {
  4060. var q = $q.defer();
  4061. launchnavigator.navigate(
  4062. destination,
  4063. start,
  4064. function (){
  4065. q.resolve();
  4066. },
  4067. function (error){
  4068. q.reject(error);
  4069. },
  4070. options);
  4071. return q.promise;
  4072. }
  4073. };
  4074. }]);
  4075. // install : cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
  4076. // link : https://github.com/katzer/cordova-plugin-local-notifications
  4077. angular.module('ngCordova.plugins.localNotification', [])
  4078. .factory('$cordovaLocalNotification', ['$q', '$window', '$rootScope', '$timeout', function ($q, $window, $rootScope, $timeout) {
  4079. document.addEventListener('deviceready', function () {
  4080. if ($window.cordova &&
  4081. $window.cordova.plugins &&
  4082. $window.cordova.plugins.notification &&
  4083. $window.cordova.plugins.notification.local) {
  4084. // ----- "Scheduling" events
  4085. // A local notification was scheduled
  4086. $window.cordova.plugins.notification.local.on('schedule', function (notification, state) {
  4087. $timeout(function () {
  4088. $rootScope.$broadcast('$cordovaLocalNotification:schedule', notification, state);
  4089. });
  4090. });
  4091. // A local notification was triggered
  4092. $window.cordova.plugins.notification.local.on('trigger', function (notification, state) {
  4093. $timeout(function () {
  4094. $rootScope.$broadcast('$cordovaLocalNotification:trigger', notification, state);
  4095. });
  4096. });
  4097. // ----- "Update" events
  4098. // A local notification was updated
  4099. $window.cordova.plugins.notification.local.on('update', function (notification, state) {
  4100. $timeout(function () {
  4101. $rootScope.$broadcast('$cordovaLocalNotification:update', notification, state);
  4102. });
  4103. });
  4104. // ----- "Clear" events
  4105. // A local notification was cleared from the notification center
  4106. $window.cordova.plugins.notification.local.on('clear', function (notification, state) {
  4107. $timeout(function () {
  4108. $rootScope.$broadcast('$cordovaLocalNotification:clear', notification, state);
  4109. });
  4110. });
  4111. // All local notifications were cleared from the notification center
  4112. $window.cordova.plugins.notification.local.on('clearall', function (state) {
  4113. $timeout(function () {
  4114. $rootScope.$broadcast('$cordovaLocalNotification:clearall', state);
  4115. });
  4116. });
  4117. // ----- "Cancel" events
  4118. // A local notification was cancelled
  4119. $window.cordova.plugins.notification.local.on('cancel', function (notification, state) {
  4120. $timeout(function () {
  4121. $rootScope.$broadcast('$cordovaLocalNotification:cancel', notification, state);
  4122. });
  4123. });
  4124. // All local notifications were cancelled
  4125. $window.cordova.plugins.notification.local.on('cancelall', function (state) {
  4126. $timeout(function () {
  4127. $rootScope.$broadcast('$cordovaLocalNotification:cancelall', state);
  4128. });
  4129. });
  4130. // ----- Other events
  4131. // A local notification was clicked
  4132. $window.cordova.plugins.notification.local.on('click', function (notification, state) {
  4133. $timeout(function () {
  4134. $rootScope.$broadcast('$cordovaLocalNotification:click', notification, state);
  4135. });
  4136. });
  4137. }
  4138. }, false);
  4139. return {
  4140. schedule: function (options, scope) {
  4141. var q = $q.defer();
  4142. scope = scope || null;
  4143. $window.cordova.plugins.notification.local.schedule(options, function (result) {
  4144. q.resolve(result);
  4145. }, scope);
  4146. return q.promise;
  4147. },
  4148. add: function (options, scope) {
  4149. console.warn('Deprecated: use "schedule" instead.');
  4150. var q = $q.defer();
  4151. scope = scope || null;
  4152. $window.cordova.plugins.notification.local.schedule(options, function (result) {
  4153. q.resolve(result);
  4154. }, scope);
  4155. return q.promise;
  4156. },
  4157. update: function (options, scope) {
  4158. var q = $q.defer();
  4159. scope = scope || null;
  4160. $window.cordova.plugins.notification.local.update(options, function (result) {
  4161. q.resolve(result);
  4162. }, scope);
  4163. return q.promise;
  4164. },
  4165. clear: function (ids, scope) {
  4166. var q = $q.defer();
  4167. scope = scope || null;
  4168. $window.cordova.plugins.notification.local.clear(ids, function (result) {
  4169. q.resolve(result);
  4170. }, scope);
  4171. return q.promise;
  4172. },
  4173. clearAll: function (scope) {
  4174. var q = $q.defer();
  4175. scope = scope || null;
  4176. $window.cordova.plugins.notification.local.clearAll(function (result) {
  4177. q.resolve(result);
  4178. }, scope);
  4179. return q.promise;
  4180. },
  4181. cancel: function (ids, scope) {
  4182. var q = $q.defer();
  4183. scope = scope || null;
  4184. $window.cordova.plugins.notification.local.cancel(ids, function (result) {
  4185. q.resolve(result);
  4186. }, scope);
  4187. return q.promise;
  4188. },
  4189. cancelAll: function (scope) {
  4190. var q = $q.defer();
  4191. scope = scope || null;
  4192. $window.cordova.plugins.notification.local.cancelAll(function (result) {
  4193. q.resolve(result);
  4194. }, scope);
  4195. return q.promise;
  4196. },
  4197. isPresent: function (id, scope) {
  4198. var q = $q.defer();
  4199. scope = scope || null;
  4200. $window.cordova.plugins.notification.local.isPresent(id, function (result) {
  4201. q.resolve(result);
  4202. }, scope);
  4203. return q.promise;
  4204. },
  4205. isScheduled: function (id, scope) {
  4206. var q = $q.defer();
  4207. scope = scope || null;
  4208. $window.cordova.plugins.notification.local.isScheduled(id, function (result) {
  4209. q.resolve(result);
  4210. }, scope);
  4211. return q.promise;
  4212. },
  4213. isTriggered: function (id, scope) {
  4214. var q = $q.defer();
  4215. scope = scope || null;
  4216. $window.cordova.plugins.notification.local.isTriggered(id, function (result) {
  4217. q.resolve(result);
  4218. }, scope);
  4219. return q.promise;
  4220. },
  4221. hasPermission: function (scope) {
  4222. var q = $q.defer();
  4223. scope = scope || null;
  4224. $window.cordova.plugins.notification.local.hasPermission(function (result) {
  4225. if (result) {
  4226. q.resolve(result);
  4227. } else {
  4228. q.reject(result);
  4229. }
  4230. }, scope);
  4231. return q.promise;
  4232. },
  4233. registerPermission: function (scope) {
  4234. var q = $q.defer();
  4235. scope = scope || null;
  4236. $window.cordova.plugins.notification.local.registerPermission(function (result) {
  4237. if (result) {
  4238. q.resolve(result);
  4239. } else {
  4240. q.reject(result);
  4241. }
  4242. }, scope);
  4243. return q.promise;
  4244. },
  4245. promptForPermission: function (scope) {
  4246. console.warn('Deprecated: use "registerPermission" instead.');
  4247. var q = $q.defer();
  4248. scope = scope || null;
  4249. $window.cordova.plugins.notification.local.registerPermission(function (result) {
  4250. if (result) {
  4251. q.resolve(result);
  4252. } else {
  4253. q.reject(result);
  4254. }
  4255. }, scope);
  4256. return q.promise;
  4257. },
  4258. getAllIds: function (scope) {
  4259. var q = $q.defer();
  4260. scope = scope || null;
  4261. $window.cordova.plugins.notification.local.getAllIds(function (result) {
  4262. q.resolve(result);
  4263. }, scope);
  4264. return q.promise;
  4265. },
  4266. getIds: function (scope) {
  4267. var q = $q.defer();
  4268. scope = scope || null;
  4269. $window.cordova.plugins.notification.local.getIds(function (result) {
  4270. q.resolve(result);
  4271. }, scope);
  4272. return q.promise;
  4273. },
  4274. getScheduledIds: function (scope) {
  4275. var q = $q.defer();
  4276. scope = scope || null;
  4277. $window.cordova.plugins.notification.local.getScheduledIds(function (result) {
  4278. q.resolve(result);
  4279. }, scope);
  4280. return q.promise;
  4281. },
  4282. getTriggeredIds: function (scope) {
  4283. var q = $q.defer();
  4284. scope = scope || null;
  4285. $window.cordova.plugins.notification.local.getTriggeredIds(function (result) {
  4286. q.resolve(result);
  4287. }, scope);
  4288. return q.promise;
  4289. },
  4290. get: function (ids, scope) {
  4291. var q = $q.defer();
  4292. scope = scope || null;
  4293. $window.cordova.plugins.notification.local.get(ids, function (result) {
  4294. q.resolve(result);
  4295. }, scope);
  4296. return q.promise;
  4297. },
  4298. getAll: function (scope) {
  4299. var q = $q.defer();
  4300. scope = scope || null;
  4301. $window.cordova.plugins.notification.local.getAll(function (result) {
  4302. q.resolve(result);
  4303. }, scope);
  4304. return q.promise;
  4305. },
  4306. getScheduled: function (ids, scope) {
  4307. var q = $q.defer();
  4308. scope = scope || null;
  4309. $window.cordova.plugins.notification.local.getScheduled(ids, function (result) {
  4310. q.resolve(result);
  4311. }, scope);
  4312. return q.promise;
  4313. },
  4314. getAllScheduled: function (scope) {
  4315. var q = $q.defer();
  4316. scope = scope || null;
  4317. $window.cordova.plugins.notification.local.getAllScheduled(function (result) {
  4318. q.resolve(result);
  4319. }, scope);
  4320. return q.promise;
  4321. },
  4322. getTriggered: function (ids, scope) {
  4323. var q = $q.defer();
  4324. scope = scope || null;
  4325. $window.cordova.plugins.notification.local.getTriggered(ids, function (result) {
  4326. q.resolve(result);
  4327. }, scope);
  4328. return q.promise;
  4329. },
  4330. getAllTriggered: function (scope) {
  4331. var q = $q.defer();
  4332. scope = scope || null;
  4333. $window.cordova.plugins.notification.local.getAllTriggered(function (result) {
  4334. q.resolve(result);
  4335. }, scope);
  4336. return q.promise;
  4337. },
  4338. getDefaults: function () {
  4339. return $window.cordova.plugins.notification.local.getDefaults();
  4340. },
  4341. setDefaults: function (Object) {
  4342. $window.cordova.plugins.notification.local.setDefaults(Object);
  4343. }
  4344. };
  4345. }]);
  4346. // install : cordova plugin add https://github.com/floatinghotpot/cordova-plugin-mmedia.git
  4347. // link : https://github.com/floatinghotpot/cordova-plugin-mmedia
  4348. angular.module('ngCordova.plugins.mMediaAds', [])
  4349. .factory('$cordovaMMediaAds', ['$q', '$window', function ($q, $window) {
  4350. return {
  4351. setOptions: function (options) {
  4352. var d = $q.defer();
  4353. $window.mMedia.setOptions(options, function () {
  4354. d.resolve();
  4355. }, function () {
  4356. d.reject();
  4357. });
  4358. return d.promise;
  4359. },
  4360. createBanner: function (options) {
  4361. var d = $q.defer();
  4362. $window.mMedia.createBanner(options, function () {
  4363. d.resolve();
  4364. }, function () {
  4365. d.reject();
  4366. });
  4367. return d.promise;
  4368. },
  4369. removeBanner: function () {
  4370. var d = $q.defer();
  4371. $window.mMedia.removeBanner(function () {
  4372. d.resolve();
  4373. }, function () {
  4374. d.reject();
  4375. });
  4376. return d.promise;
  4377. },
  4378. showBanner: function (position) {
  4379. var d = $q.defer();
  4380. $window.mMedia.showBanner(position, function () {
  4381. d.resolve();
  4382. }, function () {
  4383. d.reject();
  4384. });
  4385. return d.promise;
  4386. },
  4387. showBannerAtXY: function (x, y) {
  4388. var d = $q.defer();
  4389. $window.mMedia.showBannerAtXY(x, y, function () {
  4390. d.resolve();
  4391. }, function () {
  4392. d.reject();
  4393. });
  4394. return d.promise;
  4395. },
  4396. hideBanner: function () {
  4397. var d = $q.defer();
  4398. $window.mMedia.hideBanner(function () {
  4399. d.resolve();
  4400. }, function () {
  4401. d.reject();
  4402. });
  4403. return d.promise;
  4404. },
  4405. prepareInterstitial: function (options) {
  4406. var d = $q.defer();
  4407. $window.mMedia.prepareInterstitial(options, function () {
  4408. d.resolve();
  4409. }, function () {
  4410. d.reject();
  4411. });
  4412. return d.promise;
  4413. },
  4414. showInterstitial: function () {
  4415. var d = $q.defer();
  4416. $window.mMedia.showInterstitial(function () {
  4417. d.resolve();
  4418. }, function () {
  4419. d.reject();
  4420. });
  4421. return d.promise;
  4422. }
  4423. };
  4424. }]);
  4425. // install : cordova plugin add cordova-plugin-media
  4426. // link : https://github.com/apache/cordova-plugin-media
  4427. /* globals Media: true */
  4428. angular.module('ngCordova.plugins.media', [])
  4429. .service('NewMedia', ['$q', '$interval', function ($q, $interval) {
  4430. var q, q2, q3, mediaStatus = null, mediaPosition = -1, mediaTimer, mediaDuration = -1;
  4431. function setTimer(media) {
  4432. if (angular.isDefined(mediaTimer)) {
  4433. return;
  4434. }
  4435. mediaTimer = $interval(function () {
  4436. if (mediaDuration < 0) {
  4437. mediaDuration = media.getDuration();
  4438. if (q && mediaDuration > 0) {
  4439. q.notify({duration: mediaDuration});
  4440. }
  4441. }
  4442. media.getCurrentPosition(
  4443. // success callback
  4444. function (position) {
  4445. if (position > -1) {
  4446. mediaPosition = position;
  4447. }
  4448. },
  4449. // error callback
  4450. function (e) {
  4451. console.log('Error getting pos=' + e);
  4452. });
  4453. if (q) {
  4454. q.notify({position: mediaPosition});
  4455. }
  4456. }, 1000);
  4457. }
  4458. function clearTimer() {
  4459. if (angular.isDefined(mediaTimer)) {
  4460. $interval.cancel(mediaTimer);
  4461. mediaTimer = undefined;
  4462. }
  4463. }
  4464. function resetValues() {
  4465. mediaPosition = -1;
  4466. mediaDuration = -1;
  4467. }
  4468. function NewMedia(src) {
  4469. this.media = new Media(src,
  4470. function (success) {
  4471. clearTimer();
  4472. resetValues();
  4473. q.resolve(success);
  4474. }, function (error) {
  4475. clearTimer();
  4476. resetValues();
  4477. q.reject(error);
  4478. }, function (status) {
  4479. mediaStatus = status;
  4480. q.notify({status: mediaStatus});
  4481. });
  4482. }
  4483. // iOS quirks :
  4484. // - myMedia.play({ numberOfLoops: 2 }) -> looping
  4485. // - myMedia.play({ playAudioWhenScreenIsLocked : false })
  4486. NewMedia.prototype.play = function (options) {
  4487. q = $q.defer();
  4488. if (typeof options !== 'object') {
  4489. options = {};
  4490. }
  4491. this.media.play(options);
  4492. setTimer(this.media);
  4493. return q.promise;
  4494. };
  4495. NewMedia.prototype.pause = function () {
  4496. clearTimer();
  4497. this.media.pause();
  4498. };
  4499. NewMedia.prototype.stop = function () {
  4500. this.media.stop();
  4501. };
  4502. NewMedia.prototype.release = function () {
  4503. this.media.release();
  4504. this.media = undefined;
  4505. };
  4506. NewMedia.prototype.seekTo = function (timing) {
  4507. this.media.seekTo(timing);
  4508. };
  4509. NewMedia.prototype.setVolume = function (volume) {
  4510. this.media.setVolume(volume);
  4511. };
  4512. NewMedia.prototype.startRecord = function () {
  4513. this.media.startRecord();
  4514. };
  4515. NewMedia.prototype.stopRecord = function () {
  4516. this.media.stopRecord();
  4517. };
  4518. NewMedia.prototype.currentTime = function () {
  4519. q2 = $q.defer();
  4520. this.media.getCurrentPosition(function (position){
  4521. q2.resolve(position);
  4522. });
  4523. return q2.promise;
  4524. };
  4525. NewMedia.prototype.getDuration = function () {
  4526. q3 = $q.defer();
  4527. this.media.getDuration(function (duration){
  4528. q3.resolve(duration);
  4529. });
  4530. return q3.promise;
  4531. };
  4532. return NewMedia;
  4533. }])
  4534. .factory('$cordovaMedia', ['NewMedia', function (NewMedia) {
  4535. return {
  4536. newMedia: function (src) {
  4537. return new NewMedia(src);
  4538. }
  4539. };
  4540. }]);
  4541. // install : cordova plugin add https://github.com/floatinghotpot/cordova-mobfox-pro.git
  4542. // link : https://github.com/floatinghotpot/cordova-mobfox-pro
  4543. angular.module('ngCordova.plugins.mobfoxAds', [])
  4544. .factory('$cordovaMobFoxAds', ['$q', '$window', function ($q, $window) {
  4545. return {
  4546. setOptions: function (options) {
  4547. var d = $q.defer();
  4548. $window.MobFox.setOptions(options, function () {
  4549. d.resolve();
  4550. }, function () {
  4551. d.reject();
  4552. });
  4553. return d.promise;
  4554. },
  4555. createBanner: function (options) {
  4556. var d = $q.defer();
  4557. $window.MobFox.createBanner(options, function () {
  4558. d.resolve();
  4559. }, function () {
  4560. d.reject();
  4561. });
  4562. return d.promise;
  4563. },
  4564. removeBanner: function () {
  4565. var d = $q.defer();
  4566. $window.MobFox.removeBanner(function () {
  4567. d.resolve();
  4568. }, function () {
  4569. d.reject();
  4570. });
  4571. return d.promise;
  4572. },
  4573. showBanner: function (position) {
  4574. var d = $q.defer();
  4575. $window.MobFox.showBanner(position, function () {
  4576. d.resolve();
  4577. }, function () {
  4578. d.reject();
  4579. });
  4580. return d.promise;
  4581. },
  4582. showBannerAtXY: function (x, y) {
  4583. var d = $q.defer();
  4584. $window.MobFox.showBannerAtXY(x, y, function () {
  4585. d.resolve();
  4586. }, function () {
  4587. d.reject();
  4588. });
  4589. return d.promise;
  4590. },
  4591. hideBanner: function () {
  4592. var d = $q.defer();
  4593. $window.MobFox.hideBanner(function () {
  4594. d.resolve();
  4595. }, function () {
  4596. d.reject();
  4597. });
  4598. return d.promise;
  4599. },
  4600. prepareInterstitial: function (options) {
  4601. var d = $q.defer();
  4602. $window.MobFox.prepareInterstitial(options, function () {
  4603. d.resolve();
  4604. }, function () {
  4605. d.reject();
  4606. });
  4607. return d.promise;
  4608. },
  4609. showInterstitial: function () {
  4610. var d = $q.defer();
  4611. $window.MobFox.showInterstitial(function () {
  4612. d.resolve();
  4613. }, function () {
  4614. d.reject();
  4615. });
  4616. return d.promise;
  4617. }
  4618. };
  4619. }]);
  4620. angular.module('ngCordova.plugins', [
  4621. 'ngCordova.plugins.3dtouch',
  4622. 'ngCordova.plugins.actionSheet',
  4623. 'ngCordova.plugins.adMob',
  4624. 'ngCordova.plugins.appAvailability',
  4625. 'ngCordova.plugins.appRate',
  4626. 'ngCordova.plugins.appVersion',
  4627. 'ngCordova.plugins.backgroundGeolocation',
  4628. 'ngCordova.plugins.badge',
  4629. 'ngCordova.plugins.barcodeScanner',
  4630. 'ngCordova.plugins.batteryStatus',
  4631. 'ngCordova.plugins.beacon',
  4632. 'ngCordova.plugins.ble',
  4633. 'ngCordova.plugins.bluetoothSerial',
  4634. 'ngCordova.plugins.brightness',
  4635. 'ngCordova.plugins.calendar',
  4636. 'ngCordova.plugins.camera',
  4637. 'ngCordova.plugins.capture',
  4638. 'ngCordova.plugins.clipboard',
  4639. 'ngCordova.plugins.contacts',
  4640. 'ngCordova.plugins.datePicker',
  4641. 'ngCordova.plugins.device',
  4642. 'ngCordova.plugins.deviceMotion',
  4643. 'ngCordova.plugins.deviceOrientation',
  4644. 'ngCordova.plugins.dialogs',
  4645. 'ngCordova.plugins.emailComposer',
  4646. 'ngCordova.plugins.facebook',
  4647. 'ngCordova.plugins.facebookAds',
  4648. 'ngCordova.plugins.file',
  4649. 'ngCordova.plugins.fileTransfer',
  4650. 'ngCordova.plugins.fileOpener2',
  4651. 'ngCordova.plugins.flashlight',
  4652. 'ngCordova.plugins.flurryAds',
  4653. 'ngCordova.plugins.ga',
  4654. 'ngCordova.plugins.geolocation',
  4655. 'ngCordova.plugins.globalization',
  4656. 'ngCordova.plugins.googleAds',
  4657. 'ngCordova.plugins.googleAnalytics',
  4658. 'ngCordova.plugins.googleMap',
  4659. 'ngCordova.plugins.googlePlayGame',
  4660. 'ngCordova.plugins.googlePlus',
  4661. 'ngCordova.plugins.healthKit',
  4662. 'ngCordova.plugins.httpd',
  4663. 'ngCordova.plugins.iAd',
  4664. 'ngCordova.plugins.imagePicker',
  4665. 'ngCordova.plugins.inAppBrowser',
  4666. 'ngCordova.plugins.instagram',
  4667. 'ngCordova.plugins.keyboard',
  4668. 'ngCordova.plugins.keychain',
  4669. 'ngCordova.plugins.launchNavigator',
  4670. 'ngCordova.plugins.localNotification',
  4671. 'ngCordova.plugins.media',
  4672. 'ngCordova.plugins.mMediaAds',
  4673. 'ngCordova.plugins.mobfoxAds',
  4674. 'ngCordova.plugins.mopubAds',
  4675. 'ngCordova.plugins.nativeAudio',
  4676. 'ngCordova.plugins.network',
  4677. 'ngCordova.plugins.pinDialog',
  4678. 'ngCordova.plugins.preferences',
  4679. 'ngCordova.plugins.printer',
  4680. 'ngCordova.plugins.progressIndicator',
  4681. 'ngCordova.plugins.push',
  4682. 'ngCordova.plugins.push_v5',
  4683. 'ngCordova.plugins.sms',
  4684. 'ngCordova.plugins.socialSharing',
  4685. 'ngCordova.plugins.spinnerDialog',
  4686. 'ngCordova.plugins.splashscreen',
  4687. 'ngCordova.plugins.sqlite',
  4688. 'ngCordova.plugins.statusbar',
  4689. 'ngCordova.plugins.toast',
  4690. 'ngCordova.plugins.touchid',
  4691. 'ngCordova.plugins.vibration',
  4692. 'ngCordova.plugins.videoCapturePlus',
  4693. 'ngCordova.plugins.zip',
  4694. 'ngCordova.plugins.insomnia'
  4695. ]);
  4696. // install : cordova plugin add https://github.com/floatinghotpot/cordova-plugin-mopub.git
  4697. // link : https://github.com/floatinghotpot/cordova-plugin-mopub
  4698. angular.module('ngCordova.plugins.mopubAds', [])
  4699. .factory('$cordovaMoPubAds', ['$q', '$window', function ($q, $window) {
  4700. return {
  4701. setOptions: function (options) {
  4702. var d = $q.defer();
  4703. $window.MoPub.setOptions(options, function () {
  4704. d.resolve();
  4705. }, function () {
  4706. d.reject();
  4707. });
  4708. return d.promise;
  4709. },
  4710. createBanner: function (options) {
  4711. var d = $q.defer();
  4712. $window.MoPub.createBanner(options, function () {
  4713. d.resolve();
  4714. }, function () {
  4715. d.reject();
  4716. });
  4717. return d.promise;
  4718. },
  4719. removeBanner: function () {
  4720. var d = $q.defer();
  4721. $window.MoPub.removeBanner(function () {
  4722. d.resolve();
  4723. }, function () {
  4724. d.reject();
  4725. });
  4726. return d.promise;
  4727. },
  4728. showBanner: function (position) {
  4729. var d = $q.defer();
  4730. $window.MoPub.showBanner(position, function () {
  4731. d.resolve();
  4732. }, function () {
  4733. d.reject();
  4734. });
  4735. return d.promise;
  4736. },
  4737. showBannerAtXY: function (x, y) {
  4738. var d = $q.defer();
  4739. $window.MoPub.showBannerAtXY(x, y, function () {
  4740. d.resolve();
  4741. }, function () {
  4742. d.reject();
  4743. });
  4744. return d.promise;
  4745. },
  4746. hideBanner: function () {
  4747. var d = $q.defer();
  4748. $window.MoPub.hideBanner(function () {
  4749. d.resolve();
  4750. }, function () {
  4751. d.reject();
  4752. });
  4753. return d.promise;
  4754. },
  4755. prepareInterstitial: function (options) {
  4756. var d = $q.defer();
  4757. $window.MoPub.prepareInterstitial(options, function () {
  4758. d.resolve();
  4759. }, function () {
  4760. d.reject();
  4761. });
  4762. return d.promise;
  4763. },
  4764. showInterstitial: function () {
  4765. var d = $q.defer();
  4766. $window.MoPub.showInterstitial(function () {
  4767. d.resolve();
  4768. }, function () {
  4769. d.reject();
  4770. });
  4771. return d.promise;
  4772. }
  4773. };
  4774. }]);
  4775. // install : cordova plugin add https://github.com/sidneys/cordova-plugin-nativeaudio.git
  4776. // link : https://github.com/sidneys/cordova-plugin-nativeaudio
  4777. angular.module('ngCordova.plugins.nativeAudio', [])
  4778. .factory('$cordovaNativeAudio', ['$q', '$window', function ($q, $window) {
  4779. return {
  4780. preloadSimple: function (id, assetPath) {
  4781. var q = $q.defer();
  4782. $window.plugins.NativeAudio.preloadSimple(id, assetPath, function (result) {
  4783. q.resolve(result);
  4784. }, function (err) {
  4785. q.reject(err);
  4786. });
  4787. return q.promise;
  4788. },
  4789. preloadComplex: function (id, assetPath, volume, voices, delay) {
  4790. var q = $q.defer();
  4791. $window.plugins.NativeAudio.preloadComplex(id, assetPath, volume, voices, delay, function (result) {
  4792. q.resolve(result);
  4793. }, function (err) {
  4794. q.reject(err);
  4795. });
  4796. return q.promise;
  4797. },
  4798. play: function (id, completeCallback) {
  4799. var q = $q.defer();
  4800. $window.plugins.NativeAudio.play(id, function (result) {
  4801. q.resolve(result);
  4802. }, function (err) {
  4803. q.reject(err);
  4804. }, completeCallback);
  4805. return q.promise;
  4806. },
  4807. stop: function (id) {
  4808. var q = $q.defer();
  4809. $window.plugins.NativeAudio.stop(id, function (result) {
  4810. q.resolve(result);
  4811. }, function (err) {
  4812. q.reject(err);
  4813. });
  4814. return q.promise;
  4815. },
  4816. loop: function (id) {
  4817. var q = $q.defer();
  4818. $window.plugins.NativeAudio.loop(id, function (result) {
  4819. q.resolve(result);
  4820. }, function (err) {
  4821. q.reject(err);
  4822. });
  4823. return q.promise;
  4824. },
  4825. unload: function (id) {
  4826. var q = $q.defer();
  4827. $window.plugins.NativeAudio.unload(id, function (result) {
  4828. q.resolve(result);
  4829. }, function (err) {
  4830. q.reject(err);
  4831. });
  4832. return q.promise;
  4833. },
  4834. setVolumeForComplexAsset: function (id, volume) {
  4835. var q = $q.defer();
  4836. $window.plugins.NativeAudio.setVolumeForComplexAsset(id, volume, function (result) {
  4837. q.resolve(result);
  4838. }, function (err) {
  4839. q.reject(err);
  4840. });
  4841. return q.promise;
  4842. }
  4843. };
  4844. }]);
  4845. // install : cordova plugin add cordova-plugin-network-information
  4846. // link : https://github.com/apache/cordova-plugin-network-information
  4847. /* globals Connection: true */
  4848. angular.module('ngCordova.plugins.network', [])
  4849. .factory('$cordovaNetwork', ['$rootScope', '$timeout', function ($rootScope, $timeout) {
  4850. /**
  4851. * Fires offline a event
  4852. */
  4853. var offlineEvent = function () {
  4854. var networkState = navigator.connection.type;
  4855. $timeout(function () {
  4856. $rootScope.$broadcast('$cordovaNetwork:offline', networkState);
  4857. });
  4858. };
  4859. /**
  4860. * Fires online a event
  4861. */
  4862. var onlineEvent = function () {
  4863. var networkState = navigator.connection.type;
  4864. $timeout(function () {
  4865. $rootScope.$broadcast('$cordovaNetwork:online', networkState);
  4866. });
  4867. };
  4868. document.addEventListener('deviceready', function () {
  4869. if (navigator.connection) {
  4870. document.addEventListener('offline', offlineEvent, false);
  4871. document.addEventListener('online', onlineEvent, false);
  4872. }
  4873. });
  4874. return {
  4875. getNetwork: function () {
  4876. return navigator.connection.type;
  4877. },
  4878. isOnline: function () {
  4879. var networkState = navigator.connection.type;
  4880. return networkState !== Connection.UNKNOWN && networkState !== Connection.NONE;
  4881. },
  4882. isOffline: function () {
  4883. var networkState = navigator.connection.type;
  4884. return networkState === Connection.UNKNOWN || networkState === Connection.NONE;
  4885. },
  4886. clearOfflineWatch: function () {
  4887. document.removeEventListener('offline', offlineEvent);
  4888. $rootScope.$$listeners['$cordovaNetwork:offline'] = [];
  4889. },
  4890. clearOnlineWatch: function () {
  4891. document.removeEventListener('online', onlineEvent);
  4892. $rootScope.$$listeners['$cordovaNetwork:online'] = [];
  4893. }
  4894. };
  4895. }])
  4896. .run(['$injector', function ($injector) {
  4897. $injector.get('$cordovaNetwork'); //ensure the factory always gets initialised
  4898. }]);
  4899. // install : cordova plugin add https://github.com/Paldom/PinDialog.git
  4900. // link : https://github.com/Paldom/PinDialog
  4901. angular.module('ngCordova.plugins.pinDialog', [])
  4902. .factory('$cordovaPinDialog', ['$q', '$window', function ($q, $window) {
  4903. return {
  4904. prompt: function (message, title, buttons) {
  4905. var q = $q.defer();
  4906. $window.plugins.pinDialog.prompt(message, function (res) {
  4907. q.resolve(res);
  4908. }, title, buttons);
  4909. return q.promise;
  4910. }
  4911. };
  4912. }]);
  4913. // install : cordova plugin add cordova-plugin-app-preferences
  4914. // link : https://github.com/apla/me.apla.cordova.app-preferences
  4915. angular.module('ngCordova.plugins.preferences', [])
  4916. .factory('$cordovaPreferences', ['$window', '$q', function ($window, $q) {
  4917. return {
  4918. pluginNotEnabledMessage: 'Plugin not enabled',
  4919. /**
  4920. * Decorate the promise object.
  4921. * @param promise The promise object.
  4922. */
  4923. decoratePromise: function (promise){
  4924. promise.success = function (fn) {
  4925. promise.then(fn);
  4926. return promise;
  4927. };
  4928. promise.error = function (fn) {
  4929. promise.then(null, fn);
  4930. return promise;
  4931. };
  4932. },
  4933. /**
  4934. * Store the value of the given dictionary and key.
  4935. * @param key The key of the preference.
  4936. * @param value The value to set.
  4937. * @param dict The dictionary. It's optional.
  4938. * @returns Returns a promise.
  4939. */
  4940. store: function (key, value, dict) {
  4941. var deferred = $q.defer();
  4942. var promise = deferred.promise;
  4943. function ok(value){
  4944. deferred.resolve(value);
  4945. }
  4946. function errorCallback(error){
  4947. deferred.reject(new Error(error));
  4948. }
  4949. if($window.plugins){
  4950. var storeResult;
  4951. if(arguments.length === 3){
  4952. storeResult = $window.plugins.appPreferences.store(dict, key, value);
  4953. } else {
  4954. storeResult = $window.plugins.appPreferences.store(key, value);
  4955. }
  4956. storeResult.then(ok, errorCallback);
  4957. } else {
  4958. deferred.reject(new Error(this.pluginNotEnabledMessage));
  4959. }
  4960. this.decoratePromise(promise);
  4961. return promise;
  4962. },
  4963. /**
  4964. * Fetch the value by the given dictionary and key.
  4965. * @param key The key of the preference to retrieve.
  4966. * @param dict The dictionary. It's optional.
  4967. * @returns Returns a promise.
  4968. */
  4969. fetch: function (key, dict) {
  4970. var deferred = $q.defer();
  4971. var promise = deferred.promise;
  4972. function ok(value){
  4973. deferred.resolve(value);
  4974. }
  4975. function errorCallback(error){
  4976. deferred.reject(new Error(error));
  4977. }
  4978. if($window.plugins){
  4979. var fetchResult;
  4980. if(arguments.length === 2){
  4981. fetchResult = $window.plugins.appPreferences.fetch(dict, key);
  4982. } else {
  4983. fetchResult = $window.plugins.appPreferences.fetch(key);
  4984. }
  4985. fetchResult.then(ok, errorCallback);
  4986. } else {
  4987. deferred.reject(new Error(this.pluginNotEnabledMessage));
  4988. }
  4989. this.decoratePromise(promise);
  4990. return promise;
  4991. },
  4992. /**
  4993. * Remove the value by the given key.
  4994. * @param key The key of the preference to retrieve.
  4995. * @param dict The dictionary. It's optional.
  4996. * @returns Returns a promise.
  4997. */
  4998. remove: function (key, dict) {
  4999. var deferred = $q.defer();
  5000. var promise = deferred.promise;
  5001. function ok(value){
  5002. deferred.resolve(value);
  5003. }
  5004. function errorCallback(error){
  5005. deferred.reject(new Error(error));
  5006. }
  5007. if($window.plugins){
  5008. var removeResult;
  5009. if(arguments.length === 2){
  5010. removeResult = $window.plugins.appPreferences.remove(dict, key);
  5011. } else {
  5012. removeResult = $window.plugins.appPreferences.remove(key);
  5013. }
  5014. removeResult.then(ok, errorCallback);
  5015. } else {
  5016. deferred.reject(new Error(this.pluginNotEnabledMessage));
  5017. }
  5018. this.decoratePromise(promise);
  5019. return promise;
  5020. },
  5021. /**
  5022. * Show the application preferences.
  5023. * @returns Returns a promise.
  5024. */
  5025. show: function () {
  5026. var deferred = $q.defer();
  5027. var promise = deferred.promise;
  5028. function ok(value){
  5029. deferred.resolve(value);
  5030. }
  5031. function errorCallback(error){
  5032. deferred.reject(new Error(error));
  5033. }
  5034. if($window.plugins){
  5035. $window.plugins.appPreferences.show()
  5036. .then(ok, errorCallback);
  5037. } else {
  5038. deferred.reject(new Error(this.pluginNotEnabledMessage));
  5039. }
  5040. this.decoratePromise(promise);
  5041. return promise;
  5042. }
  5043. };
  5044. }]);
  5045. // install : cordova plugin add https://github.com/katzer/cordova-plugin-printer.git
  5046. // link : https://github.com/katzer/cordova-plugin-printer
  5047. angular.module('ngCordova.plugins.printer', [])
  5048. .factory('$cordovaPrinter', ['$q', '$window', function ($q, $window) {
  5049. return {
  5050. isAvailable: function () {
  5051. var q = $q.defer();
  5052. $window.plugin.printer.isAvailable(function (isAvailable) {
  5053. q.resolve(isAvailable);
  5054. });
  5055. return q.promise;
  5056. },
  5057. print: function (doc, options) {
  5058. var q = $q.defer();
  5059. $window.plugin.printer.print(doc, options, function () {
  5060. q.resolve();
  5061. });
  5062. return q.promise;
  5063. }
  5064. };
  5065. }]);
  5066. // install : cordova plugin add https://github.com/pbernasconi/cordova-progressIndicator.git
  5067. // link : http://pbernasconi.github.io/cordova-progressIndicator/
  5068. /* globals ProgressIndicator: true */
  5069. angular.module('ngCordova.plugins.progressIndicator', [])
  5070. .factory('$cordovaProgress', [function () {
  5071. return {
  5072. show: function (_message) {
  5073. var message = _message || 'Please wait...';
  5074. return ProgressIndicator.show(message);
  5075. },
  5076. showSimple: function (_dim) {
  5077. var dim = _dim || false;
  5078. return ProgressIndicator.showSimple(dim);
  5079. },
  5080. showSimpleWithLabel: function (_dim, _label) {
  5081. var dim = _dim || false;
  5082. var label = _label || 'Loading...';
  5083. return ProgressIndicator.showSimpleWithLabel(dim, label);
  5084. },
  5085. showSimpleWithLabelDetail: function (_dim, _label, _detail) {
  5086. var dim = _dim || false;
  5087. var label = _label || 'Loading...';
  5088. var detail = _detail || 'Please wait';
  5089. return ProgressIndicator.showSimpleWithLabelDetail(dim, label, detail);
  5090. },
  5091. showDeterminate: function (_dim, _timeout) {
  5092. var dim = _dim || false;
  5093. var timeout = _timeout || 50000;
  5094. return ProgressIndicator.showDeterminate(dim, timeout);
  5095. },
  5096. showDeterminateWithLabel: function (_dim, _timeout, _label) {
  5097. var dim = _dim || false;
  5098. var timeout = _timeout || 50000;
  5099. var label = _label || 'Loading...';
  5100. return ProgressIndicator.showDeterminateWithLabel(dim, timeout, label);
  5101. },
  5102. showAnnular: function (_dim, _timeout) {
  5103. var dim = _dim || false;
  5104. var timeout = _timeout || 50000;
  5105. return ProgressIndicator.showAnnular(dim, timeout);
  5106. },
  5107. showAnnularWithLabel: function (_dim, _timeout, _label) {
  5108. var dim = _dim || false;
  5109. var timeout = _timeout || 50000;
  5110. var label = _label || 'Loading...';
  5111. return ProgressIndicator.showAnnularWithLabel(dim, timeout, label);
  5112. },
  5113. showBar: function (_dim, _timeout) {
  5114. var dim = _dim || false;
  5115. var timeout = _timeout || 50000;
  5116. return ProgressIndicator.showBar(dim, timeout);
  5117. },
  5118. showBarWithLabel: function (_dim, _timeout, _label) {
  5119. var dim = _dim || false;
  5120. var timeout = _timeout || 50000;
  5121. var label = _label || 'Loading...';
  5122. return ProgressIndicator.showBarWithLabel(dim, timeout, label);
  5123. },
  5124. showSuccess: function (_dim, _label) {
  5125. var dim = _dim || false;
  5126. var label = _label || 'Success';
  5127. return ProgressIndicator.showSuccess(dim, label);
  5128. },
  5129. showText: function (_dim, _text, _position) {
  5130. var dim = _dim || false;
  5131. var text = _text || 'Warning';
  5132. var position = _position || 'center';
  5133. return ProgressIndicator.showText(dim, text, position);
  5134. },
  5135. hide: function () {
  5136. return ProgressIndicator.hide();
  5137. }
  5138. };
  5139. }]);
  5140. // install : cordova plugin add https://github.com/phonegap-build/PushPlugin.git
  5141. // link : https://github.com/phonegap-build/PushPlugin
  5142. angular.module('ngCordova.plugins.push', [])
  5143. .factory('$cordovaPush', ['$q', '$window', '$rootScope', '$timeout', function ($q, $window, $rootScope, $timeout) {
  5144. return {
  5145. onNotification: function (notification) {
  5146. $timeout(function () {
  5147. $rootScope.$broadcast('$cordovaPush:notificationReceived', notification);
  5148. });
  5149. },
  5150. register: function (config) {
  5151. var q = $q.defer();
  5152. var injector;
  5153. if (config !== undefined && config.ecb === undefined) {
  5154. if (document.querySelector('[ng-app]') === null) {
  5155. injector = 'document.body';
  5156. }
  5157. else {
  5158. injector = 'document.querySelector(\'[ng-app]\')';
  5159. }
  5160. config.ecb = 'angular.element(' + injector + ').injector().get(\'$cordovaPush\').onNotification';
  5161. }
  5162. $window.plugins.pushNotification.register(function (token) {
  5163. q.resolve(token);
  5164. }, function (error) {
  5165. q.reject(error);
  5166. }, config);
  5167. return q.promise;
  5168. },
  5169. unregister: function (options) {
  5170. var q = $q.defer();
  5171. $window.plugins.pushNotification.unregister(function (result) {
  5172. q.resolve(result);
  5173. }, function (error) {
  5174. q.reject(error);
  5175. }, options);
  5176. return q.promise;
  5177. },
  5178. // iOS only
  5179. setBadgeNumber: function (number) {
  5180. var q = $q.defer();
  5181. $window.plugins.pushNotification.setApplicationIconBadgeNumber(function (result) {
  5182. q.resolve(result);
  5183. }, function (error) {
  5184. q.reject(error);
  5185. }, number);
  5186. return q.promise;
  5187. }
  5188. };
  5189. }]);
  5190. // install : cordova plugin add phonegap-plugin-push
  5191. // link : https://github.com/phonegap/phonegap-plugin-push
  5192. angular.module('ngCordova.plugins.push_v5', [])
  5193. .factory('$cordovaPushV5',['$q', '$rootScope', '$timeout', function ($q, $rootScope, $timeout) {
  5194. /*global PushNotification*/
  5195. var push;
  5196. return {
  5197. initialize : function (options) {
  5198. var q = $q.defer();
  5199. push = PushNotification.init(options);
  5200. q.resolve(push);
  5201. return q.promise;
  5202. },
  5203. onNotification : function () {
  5204. $timeout(function () {
  5205. push.on('notification', function (notification) {
  5206. $rootScope.$emit('$cordovaPushV5:notificationReceived', notification);
  5207. });
  5208. });
  5209. },
  5210. onError : function () {
  5211. $timeout(function () {
  5212. push.on('error', function (error) { $rootScope.$emit('$cordovaPushV5:errorOccurred', error);});
  5213. });
  5214. },
  5215. register : function () {
  5216. var q = $q.defer();
  5217. if (push === undefined) {
  5218. q.reject(new Error('init must be called before any other operation'));
  5219. } else {
  5220. push.on('registration', function (data) {
  5221. q.resolve(data.registrationId);
  5222. });
  5223. }
  5224. return q.promise;
  5225. },
  5226. unregister : function () {
  5227. var q = $q.defer();
  5228. if (push === undefined) {
  5229. q.reject(new Error('init must be called before any other operation'));
  5230. } else {
  5231. push.unregister(function (success) {
  5232. q.resolve(success);
  5233. },function (error) {
  5234. q.reject(error);
  5235. });
  5236. }
  5237. return q.promise;
  5238. },
  5239. getBadgeNumber : function () {
  5240. var q = $q.defer();
  5241. if (push === undefined) {
  5242. q.reject(new Error('init must be called before any other operation'));
  5243. } else {
  5244. push.getApplicationIconBadgeNumber(function (success) {
  5245. q.resolve(success);
  5246. }, function (error) {
  5247. q.reject(error);
  5248. });
  5249. }
  5250. return q.promise;
  5251. },
  5252. setBadgeNumber : function (number) {
  5253. var q = $q.defer();
  5254. if (push === undefined) {
  5255. q.reject(new Error('init must be called before any other operation'));
  5256. } else {
  5257. push.setApplicationIconBadgeNumber(function (success) {
  5258. q.resolve(success);
  5259. }, function (error) {
  5260. q.reject(error);
  5261. }, number);
  5262. }
  5263. return q.promise;
  5264. },
  5265. finish: function (){
  5266. var q = $q.defer();
  5267. if (push === undefined) {
  5268. q.reject(new Error('init must be called before any other operation'));
  5269. } else {
  5270. push.finish(function (success) {
  5271. q.resolve(success);
  5272. }, function (error) {
  5273. q.reject(error);
  5274. });
  5275. }
  5276. return q.promise;
  5277. }
  5278. };
  5279. }]);
  5280. // install : cordova plugin add cordova-plugin-recentscontrol
  5281. // link : https://github.com/smcpjames/cordova-plugin-recentscontrol
  5282. /* globals RecentsControl: true */
  5283. angular.module('ngCordova.plugins.recentsControl', [])
  5284. .factory('$cordovaRecents', function () {
  5285. return {
  5286. setColor: function (color) {
  5287. return RecentsControl.setColor(color);
  5288. },
  5289. setDescription: function (desc) {
  5290. return RecentsControl.setDescription(desc);
  5291. },
  5292. setOptions: function (colorStr, desc) {
  5293. return RecentsControl.setOptions(colorStr, desc);
  5294. }
  5295. };
  5296. });
  5297. // install : cordova plugin add https://github.com/gitawego/cordova-screenshot.git
  5298. // link : https://github.com/gitawego/cordova-screenshot
  5299. angular.module('ngCordova.plugins.screenshot', [])
  5300. .factory('$cordovaScreenshot', ['$q', function ($q) {
  5301. return {
  5302. captureToFile: function (opts) {
  5303. var options = opts || {};
  5304. var extension = options.extension || 'jpg';
  5305. var quality = options.quality || '100';
  5306. var defer = $q.defer();
  5307. if (!navigator.screenshot) {
  5308. defer.resolve(null);
  5309. return defer.promise;
  5310. }
  5311. navigator.screenshot.save(function (error, res) {
  5312. if (error) {
  5313. defer.reject(error);
  5314. } else {
  5315. defer.resolve(res.filePath);
  5316. }
  5317. }, extension, quality, options.filename);
  5318. return defer.promise;
  5319. },
  5320. captureToUri: function (opts) {
  5321. var options = opts || {};
  5322. var extension = options.extension || 'jpg';
  5323. var quality = options.quality || '100';
  5324. var defer = $q.defer();
  5325. if (!navigator.screenshot) {
  5326. defer.resolve(null);
  5327. return defer.promise;
  5328. }
  5329. navigator.screenshot.URI(function (error, res) {
  5330. if (error) {
  5331. defer.reject(error);
  5332. } else {
  5333. defer.resolve(res.URI);
  5334. }
  5335. }, extension, quality, options.filename);
  5336. return defer.promise;
  5337. }
  5338. };
  5339. }]);
  5340. // install : cordova plugin add https://github.com/xseignard/cordovarduino.git
  5341. // link : https://github.com/xseignard/cordovarduino
  5342. /* globals serial: true */
  5343. angular.module('ngCordova.plugins.serial', [])
  5344. .factory('$cordovaSerial', ['$q', function ($q) {
  5345. var serialService = {};
  5346. serialService.requestPermission = function requestPermission(options) {
  5347. var q = $q.defer();
  5348. serial.requestPermission(options, function success() {
  5349. q.resolve();
  5350. }, function error(err) {
  5351. q.reject(err);
  5352. });
  5353. return q.promise;
  5354. };
  5355. serialService.open = function(options) {
  5356. var q = $q.defer();
  5357. serial.open(options, function success() {
  5358. q.resolve();
  5359. }, function error(err) {
  5360. q.reject(err);
  5361. });
  5362. return q.promise;
  5363. };
  5364. serialService.write = function(data) {
  5365. var q = $q.defer();
  5366. serial.write(data, function success() {
  5367. q.resolve();
  5368. }, function error(err) {
  5369. q.reject(err);
  5370. });
  5371. return q.promise;
  5372. };
  5373. serialService.writeHex = function(data) {
  5374. var q = $q.defer();
  5375. serial.writeHex(data, function success() {
  5376. q.resolve();
  5377. }, function error(err) {
  5378. q.reject(err);
  5379. });
  5380. return q.promise;
  5381. };
  5382. serialService.read = function() {
  5383. var q = $q.defer();
  5384. serial.read(function success(buffer) {
  5385. var view = new Uint8Array(buffer);
  5386. q.resolve(view);
  5387. }, function error(err) {
  5388. q.reject(err);
  5389. });
  5390. return q.promise;
  5391. };
  5392. serialService.registerReadCallback = function(successCallback, errorCallback) {
  5393. serial.registerReadCallback(function success(buffer) {
  5394. var view = new Uint8Array(buffer);
  5395. successCallback(view);
  5396. }, errorCallback);
  5397. };
  5398. serialService.close = function() {
  5399. var q = $q.defer();
  5400. serial.close(function success() {
  5401. q.resolve();
  5402. }, function error(err) {
  5403. q.reject(err);
  5404. });
  5405. return q.promise;
  5406. };
  5407. return serialService;
  5408. }]);
  5409. // install : cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git
  5410. // link : https://github.com/cordova-sms/cordova-sms-plugin
  5411. /* globals sms: true */
  5412. angular.module('ngCordova.plugins.sms', [])
  5413. .factory('$cordovaSms', ['$q', function ($q) {
  5414. return {
  5415. send: function (number, message, options) {
  5416. var q = $q.defer();
  5417. sms.send(number, message, options, function (res) {
  5418. q.resolve(res);
  5419. }, function (err) {
  5420. q.reject(err);
  5421. });
  5422. return q.promise;
  5423. }
  5424. };
  5425. }]);
  5426. // install : cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git
  5427. // link : https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
  5428. // NOTE: shareViaEmail -> if user cancels sharing email, success is still called
  5429. // TODO: add support for iPad
  5430. angular.module('ngCordova.plugins.socialSharing', [])
  5431. .factory('$cordovaSocialSharing', ['$q', '$window', function ($q, $window) {
  5432. return {
  5433. share: function (message, subject, file, link) {
  5434. var q = $q.defer();
  5435. subject = subject || null;
  5436. file = file || null;
  5437. link = link || null;
  5438. $window.plugins.socialsharing.share(message, subject, file, link, function () {
  5439. q.resolve(true);
  5440. }, function () {
  5441. q.reject(false);
  5442. });
  5443. return q.promise;
  5444. },
  5445. shareWithOptions: function (options) {
  5446. var q = $q.defer();
  5447. $window.plugins.socialsharing.shareWithOptions(options, function () {
  5448. q.resolve(true);
  5449. }, function () {
  5450. q.reject(false);
  5451. });
  5452. return q.promise;
  5453. },
  5454. shareViaTwitter: function (message, file, link) {
  5455. var q = $q.defer();
  5456. file = file || null;
  5457. link = link || null;
  5458. $window.plugins.socialsharing.shareViaTwitter(message, file, link, function () {
  5459. q.resolve(true);
  5460. }, function () {
  5461. q.reject(false);
  5462. });
  5463. return q.promise;
  5464. },
  5465. shareViaWhatsApp: function (message, file, link) {
  5466. var q = $q.defer();
  5467. file = file || null;
  5468. link = link || null;
  5469. $window.plugins.socialsharing.shareViaWhatsApp(message, file, link, function () {
  5470. q.resolve(true);
  5471. }, function () {
  5472. q.reject(false);
  5473. });
  5474. return q.promise;
  5475. },
  5476. shareViaFacebook: function (message, file, link) {
  5477. var q = $q.defer();
  5478. message = message || null;
  5479. file = file || null;
  5480. link = link || null;
  5481. $window.plugins.socialsharing.shareViaFacebook(message, file, link, function () {
  5482. q.resolve(true);
  5483. }, function () {
  5484. q.reject(false);
  5485. });
  5486. return q.promise;
  5487. },
  5488. shareViaFacebookWithPasteMessageHint: function (message, file, link, pasteMessageHint) {
  5489. var q = $q.defer();
  5490. file = file || null;
  5491. link = link || null;
  5492. $window.plugins.socialsharing.shareViaFacebookWithPasteMessageHint(message, file, link, pasteMessageHint, function () {
  5493. q.resolve(true);
  5494. }, function () {
  5495. q.reject(false);
  5496. });
  5497. return q.promise;
  5498. },
  5499. shareViaSMS: function (message, commaSeparatedPhoneNumbers) {
  5500. var q = $q.defer();
  5501. $window.plugins.socialsharing.shareViaSMS(message, commaSeparatedPhoneNumbers, function () {
  5502. q.resolve(true);
  5503. }, function () {
  5504. q.reject(false);
  5505. });
  5506. return q.promise;
  5507. },
  5508. shareViaEmail: function (message, subject, toArr, ccArr, bccArr, fileArr) {
  5509. var q = $q.defer();
  5510. toArr = toArr || null;
  5511. ccArr = ccArr || null;
  5512. bccArr = bccArr || null;
  5513. fileArr = fileArr || null;
  5514. $window.plugins.socialsharing.shareViaEmail(message, subject, toArr, ccArr, bccArr, fileArr, function () {
  5515. q.resolve(true);
  5516. }, function () {
  5517. q.reject(false);
  5518. });
  5519. return q.promise;
  5520. },
  5521. shareVia: function (via, message, subject, file, link) {
  5522. var q = $q.defer();
  5523. message = message || null;
  5524. subject = subject || null;
  5525. file = file || null;
  5526. link = link || null;
  5527. $window.plugins.socialsharing.shareVia(via, message, subject, file, link, function () {
  5528. q.resolve(true);
  5529. }, function () {
  5530. q.reject(false);
  5531. });
  5532. return q.promise;
  5533. },
  5534. canShareViaEmail: function () {
  5535. var q = $q.defer();
  5536. $window.plugins.socialsharing.canShareViaEmail(function () {
  5537. q.resolve(true);
  5538. }, function () {
  5539. q.reject(false);
  5540. });
  5541. return q.promise;
  5542. },
  5543. canShareVia: function (via, message, subject, file, link) {
  5544. var q = $q.defer();
  5545. $window.plugins.socialsharing.canShareVia(via, message, subject, file, link, function (success) {
  5546. q.resolve(success);
  5547. }, function (error) {
  5548. q.reject(error);
  5549. });
  5550. return q.promise;
  5551. },
  5552. available: function () {
  5553. var q = $q.defer();
  5554. window.plugins.socialsharing.available(function (isAvailable) {
  5555. if (isAvailable) {
  5556. q.resolve();
  5557. }
  5558. else {
  5559. q.reject();
  5560. }
  5561. });
  5562. return q.promise;
  5563. }
  5564. };
  5565. }]);
  5566. // install : cordova plugin add https://github.com/Paldom/SpinnerDialog.git
  5567. // link : https://github.com/Paldom/SpinnerDialog
  5568. angular.module('ngCordova.plugins.spinnerDialog', [])
  5569. .factory('$cordovaSpinnerDialog', ['$window', function ($window) {
  5570. return {
  5571. show: function (title, message, fixed, iosOptions) {
  5572. fixed = fixed || false;
  5573. return $window.plugins.spinnerDialog.show(title, message, fixed, iosOptions);
  5574. },
  5575. hide: function () {
  5576. return $window.plugins.spinnerDialog.hide();
  5577. }
  5578. };
  5579. }]);
  5580. // install : cordova plugin add cordova-plugin-splashscreen
  5581. // link : https://github.com/apache/cordova-plugin-splashscreen
  5582. angular.module('ngCordova.plugins.splashscreen', [])
  5583. .factory('$cordovaSplashscreen', [function () {
  5584. return {
  5585. hide: function () {
  5586. return navigator.splashscreen.hide();
  5587. },
  5588. show: function () {
  5589. return navigator.splashscreen.show();
  5590. }
  5591. };
  5592. }]);
  5593. // install : cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git
  5594. // link : https://github.com/litehelpers/Cordova-sqlite-storage
  5595. angular.module('ngCordova.plugins.sqlite', [])
  5596. .factory('$cordovaSQLite', ['$q', '$window', function ($q, $window) {
  5597. return {
  5598. openDB: function (options, background) {
  5599. if (angular.isObject(options) && !angular.isString(options)) {
  5600. if (typeof background !== 'undefined') {
  5601. options.bgType = background;
  5602. }
  5603. return $window.sqlitePlugin.openDatabase(options);
  5604. }
  5605. return $window.sqlitePlugin.openDatabase({
  5606. name: options,
  5607. bgType: background
  5608. });
  5609. },
  5610. execute: function (db, query, binding) {
  5611. var q = $q.defer();
  5612. db.transaction(function (tx) {
  5613. tx.executeSql(query, binding, function (tx, result) {
  5614. q.resolve(result);
  5615. },
  5616. function (transaction, error) {
  5617. q.reject(error);
  5618. });
  5619. });
  5620. return q.promise;
  5621. },
  5622. insertCollection: function (db, query, bindings) {
  5623. var q = $q.defer();
  5624. var coll = bindings.slice(0); // clone collection
  5625. db.transaction(function (tx) {
  5626. (function insertOne() {
  5627. var record = coll.splice(0, 1)[0]; // get the first record of coll and reduce coll by one
  5628. try {
  5629. tx.executeSql(query, record, function (tx, result) {
  5630. if (coll.length === 0) {
  5631. q.resolve(result);
  5632. } else {
  5633. insertOne();
  5634. }
  5635. }, function (transaction, error) {
  5636. q.reject(error);
  5637. return;
  5638. });
  5639. } catch (exception) {
  5640. q.reject(exception);
  5641. }
  5642. })();
  5643. });
  5644. return q.promise;
  5645. },
  5646. nestedExecute: function (db, query1, query2, binding1, binding2) {
  5647. var q = $q.defer();
  5648. db.transaction(function (tx) {
  5649. tx.executeSql(query1, binding1, function (tx, result) {
  5650. q.resolve(result);
  5651. tx.executeSql(query2, binding2, function (tx, res) {
  5652. q.resolve(res);
  5653. });
  5654. });
  5655. },
  5656. function (transaction, error) {
  5657. q.reject(error);
  5658. });
  5659. return q.promise;
  5660. },
  5661. deleteDB: function (dbName) {
  5662. var q = $q.defer();
  5663. $window.sqlitePlugin.deleteDatabase(dbName, function (success) {
  5664. q.resolve(success);
  5665. }, function (error) {
  5666. q.reject(error);
  5667. });
  5668. return q.promise;
  5669. }
  5670. };
  5671. }]);
  5672. // install : cordova plugin add cordova-plugin-statusbar
  5673. // link : https://github.com/apache/cordova-plugin-statusbar
  5674. /* globals StatusBar: true */
  5675. angular.module('ngCordova.plugins.statusbar', [])
  5676. .factory('$cordovaStatusbar', [function () {
  5677. return {
  5678. /**
  5679. * @param {boolean} bool
  5680. */
  5681. overlaysWebView: function (bool) {
  5682. return StatusBar.overlaysWebView(!!bool);
  5683. },
  5684. STYLES: {
  5685. DEFAULT: 0,
  5686. LIGHT_CONTENT: 1,
  5687. BLACK_TRANSLUCENT: 2,
  5688. BLACK_OPAQUE: 3
  5689. },
  5690. /**
  5691. * @param {number} style
  5692. */
  5693. style: function (style) {
  5694. switch (style) {
  5695. // Default
  5696. case 0:
  5697. return StatusBar.styleDefault();
  5698. // LightContent
  5699. case 1:
  5700. return StatusBar.styleLightContent();
  5701. // BlackTranslucent
  5702. case 2:
  5703. return StatusBar.styleBlackTranslucent();
  5704. // BlackOpaque
  5705. case 3:
  5706. return StatusBar.styleBlackOpaque();
  5707. default:
  5708. return StatusBar.styleDefault();
  5709. }
  5710. },
  5711. // supported names:
  5712. // black, darkGray, lightGray, white, gray, red, green,
  5713. // blue, cyan, yellow, magenta, orange, purple, brown
  5714. styleColor: function (color) {
  5715. return StatusBar.backgroundColorByName(color);
  5716. },
  5717. styleHex: function (colorHex) {
  5718. return StatusBar.backgroundColorByHexString(colorHex);
  5719. },
  5720. hide: function () {
  5721. return StatusBar.hide();
  5722. },
  5723. show: function () {
  5724. return StatusBar.show();
  5725. },
  5726. isVisible: function () {
  5727. return StatusBar.isVisible;
  5728. }
  5729. };
  5730. }]);
  5731. // install : cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
  5732. // link : https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin
  5733. angular.module('ngCordova.plugins.toast', [])
  5734. .factory('$cordovaToast', ['$q', '$window', function ($q, $window) {
  5735. return {
  5736. showShortTop: function (message) {
  5737. var q = $q.defer();
  5738. $window.plugins.toast.showShortTop(message, function (response) {
  5739. q.resolve(response);
  5740. }, function (error) {
  5741. q.reject(error);
  5742. });
  5743. return q.promise;
  5744. },
  5745. showShortCenter: function (message) {
  5746. var q = $q.defer();
  5747. $window.plugins.toast.showShortCenter(message, function (response) {
  5748. q.resolve(response);
  5749. }, function (error) {
  5750. q.reject(error);
  5751. });
  5752. return q.promise;
  5753. },
  5754. showShortBottom: function (message) {
  5755. var q = $q.defer();
  5756. $window.plugins.toast.showShortBottom(message, function (response) {
  5757. q.resolve(response);
  5758. }, function (error) {
  5759. q.reject(error);
  5760. });
  5761. return q.promise;
  5762. },
  5763. showLongTop: function (message) {
  5764. var q = $q.defer();
  5765. $window.plugins.toast.showLongTop(message, function (response) {
  5766. q.resolve(response);
  5767. }, function (error) {
  5768. q.reject(error);
  5769. });
  5770. return q.promise;
  5771. },
  5772. showLongCenter: function (message) {
  5773. var q = $q.defer();
  5774. $window.plugins.toast.showLongCenter(message, function (response) {
  5775. q.resolve(response);
  5776. }, function (error) {
  5777. q.reject(error);
  5778. });
  5779. return q.promise;
  5780. },
  5781. showLongBottom: function (message) {
  5782. var q = $q.defer();
  5783. $window.plugins.toast.showLongBottom(message, function (response) {
  5784. q.resolve(response);
  5785. }, function (error) {
  5786. q.reject(error);
  5787. });
  5788. return q.promise;
  5789. },
  5790. showWithOptions: function (options) {
  5791. var q = $q.defer();
  5792. $window.plugins.toast.showWithOptions(options, function (response) {
  5793. q.resolve(response);
  5794. }, function (error) {
  5795. q.reject(error);
  5796. });
  5797. return q.promise;
  5798. },
  5799. show: function (message, duration, position) {
  5800. var q = $q.defer();
  5801. $window.plugins.toast.show(message, duration, position, function (response) {
  5802. q.resolve(response);
  5803. }, function (error) {
  5804. q.reject(error);
  5805. });
  5806. return q.promise;
  5807. },
  5808. hide: function () {
  5809. var q = $q.defer();
  5810. try {
  5811. $window.plugins.toast.hide();
  5812. q.resolve();
  5813. } catch (error) {
  5814. q.reject(error && error.message);
  5815. }
  5816. return q.promise;
  5817. }
  5818. };
  5819. }]);
  5820. // install : cordova plugin add https://github.com/leecrossley/cordova-plugin-touchid.git
  5821. // link : https://github.com/leecrossley/cordova-plugin-touchid
  5822. /* globals touchid: true */
  5823. angular.module('ngCordova.plugins.touchid', [])
  5824. .factory('$cordovaTouchID', ['$q', function ($q) {
  5825. return {
  5826. checkSupport: function () {
  5827. var defer = $q.defer();
  5828. if (!window.cordova) {
  5829. defer.reject('Not supported without cordova.js');
  5830. } else {
  5831. touchid.checkSupport(function (value) {
  5832. defer.resolve(value);
  5833. }, function (err) {
  5834. defer.reject(err);
  5835. });
  5836. }
  5837. return defer.promise;
  5838. },
  5839. authenticate: function (authReasonText) {
  5840. var defer = $q.defer();
  5841. if (!window.cordova) {
  5842. defer.reject('Not supported without cordova.js');
  5843. } else {
  5844. touchid.authenticate(function (value) {
  5845. defer.resolve(value);
  5846. }, function (err) {
  5847. defer.reject(err);
  5848. }, authReasonText);
  5849. }
  5850. return defer.promise;
  5851. }
  5852. };
  5853. }]);
  5854. // install : cordova plugin add cordova-plugin-tts
  5855. // link : https://github.com/smcpjames/cordova-plugin-tts
  5856. /* globals TTS: true */
  5857. angular.module('ngCordova.plugins.tts', [])
  5858. .factory('$cordovaTTS', function () {
  5859. return {
  5860. speak: function (text, onfulfilled, onrejected) {
  5861. return TTS.speak(text, onfulfilled, onrejected);
  5862. }
  5863. };
  5864. });
  5865. // install : cordova plugin add https://github.com/aerogear/aerogear-cordova-push.git
  5866. // link : https://github.com/aerogear/aerogear-cordova-push
  5867. angular.module('ngCordova.plugins.upsPush', [])
  5868. .factory('$cordovaUpsPush', ['$q', '$window', '$rootScope', '$timeout', function ($q, $window, $rootScope, $timeout) {
  5869. return {
  5870. register: function (config) {
  5871. var q = $q.defer();
  5872. $window.push.register(function (notification) {
  5873. $timeout(function () {
  5874. $rootScope.$broadcast('$cordovaUpsPush:notificationReceived', notification);
  5875. });
  5876. }, function () {
  5877. q.resolve();
  5878. }, function (error) {
  5879. q.reject(error);
  5880. }, config);
  5881. return q.promise;
  5882. },
  5883. unregister: function (options) {
  5884. var q = $q.defer();
  5885. $window.push.unregister(function () {
  5886. q.resolve();
  5887. }, function (error) {
  5888. q.reject(error);
  5889. }, options);
  5890. return q.promise;
  5891. },
  5892. // iOS only
  5893. setBadgeNumber: function (number) {
  5894. var q = $q.defer();
  5895. $window.push.setApplicationIconBadgeNumber(function () {
  5896. q.resolve();
  5897. }, number);
  5898. return q.promise;
  5899. }
  5900. };
  5901. }]);
  5902. // install : cordova plugin add cordova-plugin-vibration
  5903. // link : https://github.com/apache/cordova-plugin-vibration
  5904. angular.module('ngCordova.plugins.vibration', [])
  5905. .factory('$cordovaVibration', [function () {
  5906. return {
  5907. vibrate: function (times) {
  5908. return navigator.notification.vibrate(times);
  5909. },
  5910. vibrateWithPattern: function (pattern, repeat) {
  5911. return navigator.notification.vibrateWithPattern(pattern, repeat);
  5912. },
  5913. cancelVibration: function () {
  5914. return navigator.notification.cancelVibration();
  5915. }
  5916. };
  5917. }]);
  5918. // install : cordova plugin add https://github.com/EddyVerbruggen/VideoCapturePlus-PhoneGap-Plugin.git
  5919. // link : https://github.com/EddyVerbruggen/VideoCapturePlus-PhoneGap-Plugin
  5920. angular.module('ngCordova.plugins.videoCapturePlus', [])
  5921. .provider('$cordovaVideoCapturePlus', [function () {
  5922. var defaultOptions = {};
  5923. /**
  5924. * the nr of videos to record, default 1 (on iOS always 1)
  5925. *
  5926. * @param limit
  5927. */
  5928. this.setLimit = function setLimit(limit) {
  5929. defaultOptions.limit = limit;
  5930. };
  5931. /**
  5932. * max duration in seconds, default 0, which is 'forever'
  5933. *
  5934. * @param seconds
  5935. */
  5936. this.setMaxDuration = function setMaxDuration(seconds) {
  5937. defaultOptions.duration = seconds;
  5938. };
  5939. /**
  5940. * set to true to override the default low quality setting
  5941. *
  5942. * @param {Boolean} highquality
  5943. */
  5944. this.setHighQuality = function setHighQuality(highquality) {
  5945. defaultOptions.highquality = highquality;
  5946. };
  5947. /**
  5948. * you'll want to sniff the user-Agent/device and pass the best overlay based on that..
  5949. * set to true to override the default backfacing camera setting. iOS: works fine, Android: YMMV (#18)
  5950. *
  5951. * @param {Boolean} frontcamera
  5952. */
  5953. this.useFrontCamera = function useFrontCamera(frontcamera) {
  5954. defaultOptions.frontcamera = frontcamera;
  5955. };
  5956. /**
  5957. * put the png in your www folder
  5958. *
  5959. * @param {String} imageUrl
  5960. */
  5961. this.setPortraitOverlay = function setPortraitOverlay(imageUrl) {
  5962. defaultOptions.portraitOverlay = imageUrl;
  5963. };
  5964. /**
  5965. *
  5966. * @param {String} imageUrl
  5967. */
  5968. this.setLandscapeOverlay = function setLandscapeOverlay(imageUrl) {
  5969. defaultOptions.landscapeOverlay = imageUrl;
  5970. };
  5971. /**
  5972. * iOS only
  5973. *
  5974. * @param text
  5975. */
  5976. this.setOverlayText = function setOverlayText(text) {
  5977. defaultOptions.overlayText = text;
  5978. };
  5979. this.$get = ['$q', '$window', function ($q, $window) {
  5980. return {
  5981. captureVideo: function (options) {
  5982. var q = $q.defer();
  5983. if (!$window.plugins.videocaptureplus) {
  5984. q.resolve(null);
  5985. return q.promise;
  5986. }
  5987. $window.plugins.videocaptureplus.captureVideo(q.resolve, q.reject,
  5988. angular.extend({}, defaultOptions, options));
  5989. return q.promise;
  5990. }
  5991. };
  5992. }];
  5993. }]);
  5994. // install : cordova plugin add https://github.com/MobileChromeApps/zip.git
  5995. // link : https://github.com/MobileChromeApps/zip
  5996. angular.module('ngCordova.plugins.zip', [])
  5997. .factory('$cordovaZip', ['$q', '$window', function ($q, $window) {
  5998. return {
  5999. unzip: function (source, destination) {
  6000. var q = $q.defer();
  6001. $window.zip.unzip(source, destination, function (isError) {
  6002. if (isError === 0) {
  6003. q.resolve();
  6004. } else {
  6005. q.reject();
  6006. }
  6007. }, function (progressEvent) {
  6008. q.notify(progressEvent);
  6009. });
  6010. return q.promise;
  6011. }
  6012. };
  6013. }]);
  6014. })();