From 34fdc651eba0a7c5b2b62d069dc344eae7f8ed57 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Wed, 21 Mar 2018 16:49:52 -0700 Subject: [PATCH] Add support to scan QR codes directly from the app This requires support for one new plugin and one new permission (CAMERA) --- config.xml | 6 ++++++ package.json | 6 +++++- www/index.html | 1 + www/js/controllers.js | 29 ++++++++++++++++++++++++++--- www/templates/study-text.html | 5 +++++ 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/config.xml b/config.xml index 511f066..9a77a3d 100644 --- a/config.xml +++ b/config.xml @@ -60,6 +60,12 @@ + + + + To scan the barcode for the study + + diff --git a/package.json b/package.json index f4c8361..521406c 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,10 @@ }, "edu.berkeley.eecs.emission.cordova.auth": {}, "cordova-plugin-whitelist": {}, - "edu.berkeley.eecs.emission.cordova.transitionnotify": {} + "edu.berkeley.eecs.emission.cordova.transitionnotify": {}, + "phonegap-plugin-barcodescanner": { + "ANDROID_SUPPORT_V4_VERSION": "27.+" + } } }, "dependencies": { @@ -63,6 +66,7 @@ "fs-extra": "^5.0.0", "ionic-plugin-keyboard": "~2.2.1", "klaw-sync": "^3.0.2", + "phonegap-plugin-barcodescanner": "^7.1.0", "phonegap-plugin-push": "~1.9.2" } } \ No newline at end of file diff --git a/www/index.html b/www/index.html index b7df26a..478d71c 100644 --- a/www/index.html +++ b/www/index.html @@ -23,6 +23,7 @@ + diff --git a/www/js/controllers.js b/www/js/controllers.js index df34578..85e477b 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -9,13 +9,36 @@ angular.module('emission.controllers', ['emission.splash.updatecheck', .controller('DashCtrl', function($scope) {}) .controller('SplashCtrl', function($scope, $state, $interval, $rootScope, - UpdateCheck, PushNotify, - LocalNotify) { + $ionicPlatform, $ionicPopup, UpdateCheck, LocalNotify) { console.log('SplashCtrl invoked'); // alert("attach debugger!"); // PushNotify.startupInit(); console.log('SplashCtrl invoke finished'); -}) + + $ionicPlatform.ready(function() { + $scope.scanEnabled = true; + }); + + $scope.scanCode = function() { + if (!$scope.scanEnabled) { + $ionicPopup.alert({template: "plugins not yet initialized, please retry later"}); + } else { + cordova.plugins.barcodeScanner.scan( + function (result) { + if (result.format == "QR_CODE" && + result.cancelled == false && + result.text.substring(0,11) == "emission://") { + handleOpenURL(result.text); + } else { + $ionicPopup.alert({template: "invalid study reference "+result.text}); + } + }, + function (error) { + $ionicPopup.alert({template: "Scanning failed: " + error}); + }); + } + }; // scanCode +}) // controller .controller('ChatsCtrl', function($scope, Chats) { diff --git a/www/templates/study-text.html b/www/templates/study-text.html index 68cafa7..164712d 100644 --- a/www/templates/study-text.html +++ b/www/templates/study-text.html @@ -11,3 +11,8 @@
+ + +