Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Navaron Bracke
2022-11-22 08:23:56 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8f598135cb27ca6ec79edf5ada10a1370a1a6bb3
8f598135
1 parent
b71c3135
remove permission callback; move method call result to delegate
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
28 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerPlugin.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
8f59813
...
...
@@ -17,10 +17,9 @@ import com.google.mlkit.vision.barcode.BarcodeScanning
import com.google.mlkit.vision.common.InputImage
import dev.steenbakker.mobile_scanner.objects.DetectionSpeed
import dev.steenbakker.mobile_scanner.objects.MobileScannerStartParameters
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry
import io.flutter.view.TextureRegistry
typealias PermissionCallback = (permissionGranted: Boolean) -> Unit
typealias MobileScannerCallback = (barcodes: List<Map<String, Any?>>, image: ByteArray?) -> Unit
typealias AnalyzerCallback = (barcodes: List<Map<String, Any?>>?) -> Unit
typealias MobileScannerErrorCallback = (error: String) -> Unit
...
...
@@ -49,10 +48,9 @@ class MobileScanner(
private const val REQUEST_CODE = 0x0786
}
private var listener: PluginRegistry.RequestPermissionsResultListener? = null
private var cameraProvider: ProcessCameraProvider? = null
private var camera: Camera? = null
private var pendingPermissionResult: MethodChannel.Result? = null
private var preview: Preview? = null
private var textureEntry: TextureRegistry.SurfaceTextureEntry? = null
...
...
@@ -86,17 +84,7 @@ class MobileScanner(
/**
* Request camera permissions.
*/
fun requestPermission(permissionCallback: PermissionCallback) {
listener
?: PluginRegistry.RequestPermissionsResultListener { requestCode, _, grantResults ->
if (requestCode != REQUEST_CODE) {
false
} else {
val authorized = grantResults[0] == PackageManager.PERMISSION_GRANTED
permissionCallback(authorized)
true
}
}
fun requestPermission(result: MethodChannel.Result) {
val permissions = arrayOf(Manifest.permission.CAMERA)
ActivityCompat.requestPermissions(activity, permissions, REQUEST_CODE)
}
...
...
@@ -109,7 +97,14 @@ class MobileScanner(
permissions: Array<out String>,
grantResults: IntArray
): Boolean {
return listener?.onRequestPermissionsResult(requestCode, permissions, grantResults) ?: false
if (requestCode != REQUEST_CODE) {
return false
}
pendingPermissionResult?.success(grantResults[0] == PackageManager.PERMISSION_GRANTED)
pendingPermissionResult = null
return true
}
/**
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerPlugin.kt
View file @
8f59813
...
...
@@ -23,14 +23,8 @@ class MobileScannerPlugin : FlutterPlugin, ActivityAware, MethodChannel.MethodCa
private lateinit var barcodeHandler: BarcodeHandler
private var permissionResult: MethodChannel.Result? = null
private var analyzerResult: MethodChannel.Result? = null
private val permissionCallback: PermissionCallback = {hasPermission: Boolean ->
permissionResult?.success(hasPermission)
permissionResult = null
}
private val callback: MobileScannerCallback = { barcodes: List<Map<String, Any?>>, image: ByteArray? ->
if (image != null) {
barcodeHandler.publishEvent(mapOf(
...
...
@@ -78,7 +72,7 @@ class MobileScannerPlugin : FlutterPlugin, ActivityAware, MethodChannel.MethodCa
}
when (call.method) {
"state" -> result.success(handler!!.hasCameraPermission())
"request" -> requestPermission(result)
"request" ->
handler!!.
requestPermission(result)
"start" -> start(call, result)
"torch" -> toggleTorch(call, result)
"stop" -> stop(result)
...
...
@@ -124,11 +118,6 @@ class MobileScannerPlugin : FlutterPlugin, ActivityAware, MethodChannel.MethodCa
onDetachedFromActivity()
}
private fun requestPermission(result: MethodChannel.Result) {
permissionResult = result
handler!!.requestPermission(permissionCallback)
}
@ExperimentalGetImage
private fun start(call: MethodCall, result: MethodChannel.Result) {
val torch: Boolean = call.argument<Boolean>("torch") ?: false
...
...
Please
register
or
login
to post a comment