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
Julian Steenbakker
2022-12-13 13:23:54 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
23f68537b62d7fc138975150ffc443b1a78d1dfa
23f68537
1 parent
188aea90
bug: fix merge conflicts and refactor
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
129 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MethodCallHandlerImpl.kt → android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerPermissions.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerPermissionsListener.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerPlugin.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
23f6853
package dev.steenbakker.mobile_scanner
import android.app.Activity
import android.content.pm.PackageManager
import android.graphics.Rect
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.Surface
import androidx.camera.core.*
import androidx.camera.lifecycle.ProcessCameraProvider
...
...
@@ -217,10 +215,6 @@ class MobileScanner(
torchStateCallback(state)
}
// val analysisSize = analysis.resolutionInfo?.resolution ?: Size(0, 0)
// val previewSize = preview!!.resolutionInfo?.resolution ?: Size(0, 0)
// Log.i("LOG", "Analyzer: $analysisSize")
// Log.i("LOG", "Preview: $previewSize")
// Enable torch if provided
camera!!.cameraControl.enableTorch(torch)
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/M
ethodCallHandlerImpl
.kt → android/src/main/kotlin/dev/steenbakker/mobile_scanner/M
obileScannerHandler
.kt
View file @
23f6853
...
...
@@ -15,7 +15,7 @@ import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.view.TextureRegistry
import java.io.File
class M
ethodCallHandlerImpl
(
class M
obileScannerHandler
(
private val activity: Activity,
private val barcodeHandler: BarcodeHandler,
binaryMessenger: BinaryMessenger,
...
...
@@ -38,12 +38,14 @@ class MethodCallHandlerImpl(
private var analyzerResult: MethodChannel.Result? = null
private val callback: MobileScannerCallback = { barcodes: List<Map<String, Any?>>, image: ByteArray? ->
private val callback: MobileScannerCallback = { barcodes: List<Map<String, Any?>>, image: ByteArray?
, width: Int?, height: Int?
->
if (image != null) {
barcodeHandler.publishEvent(mapOf(
"name" to "barcode",
"data" to barcodes,
"image" to image
"image" to image,
"width" to width!!.toDouble(),
"height" to height!!.toDouble()
))
} else {
barcodeHandler.publishEvent(mapOf(
...
...
@@ -112,6 +114,8 @@ class MethodCallHandlerImpl(
"torch" -> toggleTorch(call, result)
"stop" -> stop(result)
"analyzeImage" -> analyzeImage(call, result)
"setScale" -> setScale(call, result)
"updateScanWindow" -> updateScanWindow(call)
else -> result.notImplemented()
}
}
...
...
@@ -213,4 +217,19 @@ class MethodCallHandlerImpl(
result.error("MobileScanner", "Called toggleTorch() while stopped!", null)
}
}
private fun setScale(call: MethodCall, result: MethodChannel.Result) {
try {
mobileScanner!!.setScale(call.arguments as Double)
result.success(null)
} catch (e: ZoomWhenStopped) {
result.error("MobileScanner", "Called setScale() while stopped!", null)
} catch (e: ZoomNotInRange) {
result.error("MobileScanner", "Scale should be within 0 and 1", null)
}
}
private fun updateScanWindow(call: MethodCall) {
mobileScanner!!.scanWindow = call.argument<List<Float>>("rect")
}
}
\ No newline at end of file
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerPermissions.kt
View file @
23f6853
...
...
@@ -86,40 +86,3 @@ class MobileScannerPermissions {
}
}
/**
* This class handles incoming camera permission results.
*/
@SuppressWarnings("deprecation")
private class MobileScannerPermissionsListener(
private val resultCallback: MobileScannerPermissions.ResultCallback,
): RequestPermissionsResultListener {
// There's no way to unregister permission listeners in the v1 embedding, so we'll be called
// duplicate times in cases where the user denies and then grants a permission. Keep track of if
// we've responded before and bail out of handling the callback manually if this is a repeat
// call.
private var alreadyCalled: Boolean = false
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
): Boolean {
if (alreadyCalled || requestCode != MobileScannerPermissions.REQUEST_CODE) {
return false
}
alreadyCalled = true
// grantResults could be empty if the permissions request with the user is interrupted
// https://developer.android.com/reference/android/app/Activity#onRequestPermissionsResult(int,%20java.lang.String[],%20int[])
if (grantResults.isEmpty() || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
resultCallback.onResult(
MobileScannerPermissions.CAMERA_ACCESS_DENIED,
MobileScannerPermissions.CAMERA_ACCESS_DENIED_MESSAGE)
} else {
resultCallback.onResult(null, null)
}
return true
}
}
\ No newline at end of file
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerPermissionsListener.kt
0 → 100644
View file @
23f6853
package dev.steenbakker.mobile_scanner
import android.content.pm.PackageManager
import io.flutter.plugin.common.PluginRegistry
/**
* This class handles incoming camera permission results.
*/
internal class MobileScannerPermissionsListener(
private val resultCallback: MobileScannerPermissions.ResultCallback,
): PluginRegistry.RequestPermissionsResultListener {
// There's no way to unregister permission listeners in the v1 embedding, so we'll be called
// duplicate times in cases where the user denies and then grants a permission. Keep track of if
// we've responded before and bail out of handling the callback manually if this is a repeat
// call.
private var alreadyCalled: Boolean = false
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
): Boolean {
if (alreadyCalled || requestCode != MobileScannerPermissions.REQUEST_CODE) {
return false
}
alreadyCalled = true
// grantResults could be empty if the permissions request with the user is interrupted
// https://developer.android.com/reference/android/app/Activity#onRequestPermissionsResult(int,%20java.lang.String[],%20int[])
if (grantResults.isEmpty() || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
resultCallback.onResult(
MobileScannerPermissions.CAMERA_ACCESS_DENIED,
MobileScannerPermissions.CAMERA_ACCESS_DENIED_MESSAGE)
} else {
resultCallback.onResult(null, null)
}
return true
}
}
\ No newline at end of file
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerPlugin.kt
View file @
23f6853
...
...
@@ -8,73 +8,7 @@ import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
class MobileScannerPlugin : FlutterPlugin, ActivityAware {
private var activityPluginBinding: ActivityPluginBinding? = null
private var flutterPluginBinding: FlutterPlugin.FlutterPluginBinding? = null
private var methodCallHandler: MethodCallHandlerImpl? = null
private var handler: MobileScanner? = null
private var method: MethodChannel? = null
private lateinit var barcodeHandler: BarcodeHandler
private var analyzerResult: MethodChannel.Result? = null
private val callback: MobileScannerCallback = { barcodes: List<Map<String, Any?>>, image: ByteArray?, width: Int?, height: Int? ->
if (image != null) {
barcodeHandler.publishEvent(mapOf(
"name" to "barcode",
"data" to barcodes,
"image" to image,
"width" to width!!.toDouble(),
"height" to height!!.toDouble()
))
} else {
barcodeHandler.publishEvent(mapOf(
"name" to "barcode",
"data" to barcodes
))
}
}
private val analyzerCallback: AnalyzerCallback = { barcodes: List<Map<String, Any?>>?->
if (barcodes != null) {
barcodeHandler.publishEvent(mapOf(
"name" to "barcode",
"data" to barcodes
))
analyzerResult?.success(true)
} else {
analyzerResult?.success(false)
}
analyzerResult = null
}
private val errorCallback: MobileScannerErrorCallback = {error: String ->
barcodeHandler.publishEvent(mapOf(
"name" to "error",
"data" to error,
))
}
private val torchStateCallback: TorchStateCallback = {state: Int ->
barcodeHandler.publishEvent(mapOf("name" to "torchState", "data" to state))
}
@ExperimentalGetImage
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
if (handler == null) {
result.error("MobileScanner", "Called ${call.method} before initializing.", null)
return
}
when (call.method) {
"state" -> result.success(handler!!.hasCameraPermission())
"request" -> handler!!.requestPermission(result)
"start" -> start(call, result)
"torch" -> toggleTorch(call, result)
"stop" -> stop(result)
"analyzeImage" -> analyzeImage(call, result)
"setScale" -> setScale(call, result)
"updateScanWindow" -> updateScanWindow(call)
else -> result.notImplemented()
}
}
private var methodCallHandler: MobileScannerHandler? = null
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
this.flutterPluginBinding = binding
...
...
@@ -87,7 +21,7 @@ class MobileScannerPlugin : FlutterPlugin, ActivityAware {
override fun onAttachedToActivity(activityPluginBinding: ActivityPluginBinding) {
val binaryMessenger = this.flutterPluginBinding!!.binaryMessenger
methodCallHandler = M
ethodCallHandlerImpl
(
methodCallHandler = M
obileScannerHandler
(
activityPluginBinding.activity,
BarcodeHandler(binaryMessenger),
binaryMessenger,
...
...
@@ -112,19 +46,4 @@ class MobileScannerPlugin : FlutterPlugin, ActivityAware {
override fun onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity()
}
private fun setScale(call: MethodCall, result: MethodChannel.Result) {
try {
handler!!.setScale(call.arguments as Double)
result.success(null)
} catch (e: ZoomWhenStopped) {
result.error("MobileScanner", "Called setScale() while stopped!", null)
} catch (e: ZoomNotInRange) {
result.error("MobileScanner", "Scale should be within 0 and 1", null)
}
}
private fun updateScanWindow(call: MethodCall) {
handler!!.scanWindow = call.argument<List<Float>>("rect")
}
}
...
...
Please
register
or
login
to post a comment