Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Few fixes and improvements to QR scanner views

Michael Rademaker642759e19ea5
diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/ui/QrScannerActivity.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/ui/QrScannerActivity.kt
index 53b6f1a2e..ff57a0fbf 100644
--- a/console/android/ORLib/src/main/java/io/openremote/orlib/ui/QrScannerActivity.kt
+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/ui/QrScannerActivity.kt
@@ -35,6 +35,7 @@ class QrScannerActivity : AppCompatActivity() {
setContentView(view)
supportActionBar!!.title = "Scan QR Code"
initViews()
+ initialiseDetectorsAndSources()
}
private fun initViews() {
@@ -128,14 +129,18 @@ class QrScannerActivity : AppCompatActivity() {
}
}
- override fun onPause() {
- super.onPause()
- cameraSource!!.release()
- }
+ override fun onDestroy() {
+ if (barcodeDetector != null) {
+ barcodeDetector!!.release()
+ barcodeDetector = null
+ }
- override fun onResume() {
- super.onResume()
- initialiseDetectorsAndSources()
+ if (cameraSource != null) {
+ cameraSource!!.stop()
+ cameraSource!!.release()
+ cameraSource = null
+ }
+ super.onDestroy()
}
companion object {
diff --git a/console/iOS/ORLib/ORLib/ConsoleProviders/QrScannerProvider.swift b/console/iOS/ORLib/ORLib/ConsoleProviders/QrScannerProvider.swift
index 3628866a8..f686bd088 100644
--- a/console/iOS/ORLib/ORLib/ConsoleProviders/QrScannerProvider.swift
+++ b/console/iOS/ORLib/ORLib/ConsoleProviders/QrScannerProvider.swift
@@ -145,7 +145,9 @@ public class QrScannerProvider: NSObject {
}
}))
alertController.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
- currentViewController.present(alertController, animated: true, completion: nil)
+ DispatchQueue.main.async {
+ currentViewController.present(alertController, animated: true, completion: nil)
+ }
}
})
}
@@ -154,7 +156,7 @@ public class QrScannerProvider: NSObject {
extension QrScannerProvider: QrScannerDelegate {
- public func codeScanned(_ codeContents: String) {
+ public func codeScanned(_ codeContents: String?) {
scanner?.dismiss(animated: true) {
self.scannedCallback?(
[
diff --git a/console/iOS/ORLib/ORLib/UI/QrScannerViewController.swift b/console/iOS/ORLib/ORLib/UI/QrScannerViewController.swift
index 2600844ed..5187b3e92 100644
--- a/console/iOS/ORLib/ORLib/UI/QrScannerViewController.swift
+++ b/console/iOS/ORLib/ORLib/UI/QrScannerViewController.swift
@@ -9,7 +9,7 @@ import AVFoundation
import UIKit
public protocol QrScannerDelegate: AnyObject {
- func codeScanned(_ codeContents:String)
+ func codeScanned(_ codeContents:String?)
}
public class QrScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
@@ -58,9 +58,28 @@ public class QrScannerViewController: UIViewController, AVCaptureMetadataOutputO
previewLayer.cornerRadius = 5
metadataOutput.rectOfInterest = previewLayer.rectOfInterest
- view.layer.addSublayer(previewLayer)
+ let subView = UIView(frame: view.frame)
+
+ subView.layer.addSublayer(previewLayer)
+ view.addSubview(subView)
captureSession.startRunning()
+
+ let cancelButton = UIButton(type: .close)
+ cancelButton.layer.cornerRadius = 25
+ cancelButton.backgroundColor = .white.withAlphaComponent(0.7)
+ cancelButton.setTitleColor(.black, for: [.normal, .highlighted, .selected])
+ cancelButton.addTarget(self, action: #selector(cancelButtonTapped), for: .touchUpInside)
+ cancelButton.frame = CGRect(x: 20, y: 20, width: 48, height: 48)
+ view.addSubview(cancelButton)
+ }
+
+ @objc func cancelButtonTapped() {
+ if (delegate != nil) {
+ delegate?.codeScanned(nil)
+ } else {
+ self.dismiss(animated: true, completion: nil)
+ }
}
func failed() {