From df68dd965691cd8d8383d5c1e3298e5b2280c588 Mon Sep 17 00:00:00 2001 From: DavideBicego Date: Thu, 22 Apr 2021 16:34:11 +0200 Subject: [PATCH 1/4] Lock screen rotation when scanner shown in Android --- .../barcode_scan/BarcodeScannerActivity.kt | 18 ++++++++++++++++++ example/android/build.gradle | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScannerActivity.kt b/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScannerActivity.kt index 7e27ebe..a99f157 100644 --- a/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScannerActivity.kt +++ b/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScannerActivity.kt @@ -1,10 +1,14 @@ package de.mintware.barcode_scan import android.app.Activity +import android.content.Context import android.content.Intent +import android.content.pm.ActivityInfo import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.view.Surface +import android.view.WindowManager import com.google.zxing.BarcodeFormat import com.google.zxing.Result import me.dm7.barcodescanner.zxing.ZXingScannerView @@ -45,6 +49,18 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + //lock orientation + val rotation = (getSystemService( + Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.rotation + var orientation = when (rotation) { + Surface.ROTATION_0 -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + Surface.ROTATION_90 -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + Surface.ROTATION_180 -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT + else -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE + } + + requestedOrientation = orientation + config = Protos.Configuration.parseFrom(intent.extras!!.getByteArray(EXTRA_CONFIG)) } @@ -120,6 +136,8 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler { override fun handleResult(result: Result?) { val intent = Intent() + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED + val builder = Protos.ScanResult.newBuilder() if (result == null) { diff --git a/example/android/build.gradle b/example/android/build.gradle index c377c71..e539730 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:4.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } From 3eee45c7d73667be35a376774c6f210f6e6784e8 Mon Sep 17 00:00:00 2001 From: DavideBicego Date: Thu, 22 Apr 2021 17:12:31 +0200 Subject: [PATCH 2/4] Lock screen rotation when scanner shown in iOS --- ios/Classes/BarcodeScannerViewController.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ios/Classes/BarcodeScannerViewController.swift b/ios/Classes/BarcodeScannerViewController.swift index 858f5ee..cb5d204 100644 --- a/ios/Classes/BarcodeScannerViewController.swift +++ b/ios/Classes/BarcodeScannerViewController.swift @@ -53,6 +53,8 @@ class BarcodeScannerViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() + + UIDevice.current.endGeneratingDeviceOrientationNotifications() #if targetEnvironment(simulator) view.backgroundColor = .lightGray @@ -88,6 +90,8 @@ class BarcodeScannerViewController: UIViewController { scanner!.stopScanning() } + UIDevice.current.endGeneratingDeviceOrientationNotifications() + scanRect?.startAnimating() MTBBarcodeScanner.requestCameraPermission(success: { success in if success { @@ -104,6 +108,8 @@ class BarcodeScannerViewController: UIViewController { scanner?.stopScanning() scanRect?.stopAnimating() + UIDevice.current.beginGeneratingDeviceOrientationNotifications() + if isFlashOn { setFlashState(false) } From f04a624f2b05f355b8db2d8cf4d07a2874b23736 Mon Sep 17 00:00:00 2001 From: DavideBicego Date: Mon, 26 Apr 2021 11:48:10 +0200 Subject: [PATCH 3/4] Updates CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24cbd14..d35fca2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.1.0 + +- Lock screen rotation when scanner is shown + ## 4.0.0 - Original [barcode_scan](https://pub.dev/packages/barcode_scan) was discontinued, so [barcode_scan2](https://pub.dev/packages/barcode_scan) was borned with sound null safety support🎉 From dedffa6082af7cb470ffb143c0328a883422bbc7 Mon Sep 17 00:00:00 2001 From: "Masayuki Ono (mono)" Date: Tue, 27 Apr 2021 17:50:39 +0900 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16af328..71dc31e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ -## 4.0.1 +## 4.1.0 -- Fix When ViewController whose view is not in the window hierarchy, present Scan ViewController failed will failed. - Lock screen rotation when scanner is shown +## 4.0.1 + +- Fix When ViewController whose view is not in the window hierarchy, present Scan ViewController failed will failed. ## 4.0.0