Showing
1 changed file
with
1 additions
and
63 deletions
| 1 | package dev.steenbakker.mobile_scanner | 1 | package dev.steenbakker.mobile_scanner |
| 2 | 2 | ||
| 3 | -import android.Manifest | ||
| 4 | import android.app.Activity | 3 | import android.app.Activity |
| 5 | -import android.content.pm.PackageManager | ||
| 6 | import android.net.Uri | 4 | import android.net.Uri |
| 7 | import android.os.Handler | 5 | import android.os.Handler |
| 8 | import android.os.Looper | 6 | import android.os.Looper |
| 9 | import android.view.Surface | 7 | import android.view.Surface |
| 10 | import androidx.camera.core.* | 8 | import androidx.camera.core.* |
| 11 | import androidx.camera.lifecycle.ProcessCameraProvider | 9 | import androidx.camera.lifecycle.ProcessCameraProvider |
| 12 | -import androidx.core.app.ActivityCompat | ||
| 13 | import androidx.core.content.ContextCompat | 10 | import androidx.core.content.ContextCompat |
| 14 | import androidx.lifecycle.LifecycleOwner | 11 | import androidx.lifecycle.LifecycleOwner |
| 15 | import com.google.mlkit.vision.barcode.BarcodeScannerOptions | 12 | import com.google.mlkit.vision.barcode.BarcodeScannerOptions |
| @@ -17,8 +14,6 @@ import com.google.mlkit.vision.barcode.BarcodeScanning | @@ -17,8 +14,6 @@ import com.google.mlkit.vision.barcode.BarcodeScanning | ||
| 17 | import com.google.mlkit.vision.common.InputImage | 14 | import com.google.mlkit.vision.common.InputImage |
| 18 | import dev.steenbakker.mobile_scanner.objects.DetectionSpeed | 15 | import dev.steenbakker.mobile_scanner.objects.DetectionSpeed |
| 19 | import dev.steenbakker.mobile_scanner.objects.MobileScannerStartParameters | 16 | import dev.steenbakker.mobile_scanner.objects.MobileScannerStartParameters |
| 20 | -import io.flutter.plugin.common.MethodChannel | ||
| 21 | -import io.flutter.plugin.common.PluginRegistry | ||
| 22 | import io.flutter.view.TextureRegistry | 17 | import io.flutter.view.TextureRegistry |
| 23 | typealias MobileScannerCallback = (barcodes: List<Map<String, Any?>>, image: ByteArray?) -> Unit | 18 | typealias MobileScannerCallback = (barcodes: List<Map<String, Any?>>, image: ByteArray?) -> Unit |
| 24 | typealias AnalyzerCallback = (barcodes: List<Map<String, Any?>>?) -> Unit | 19 | typealias AnalyzerCallback = (barcodes: List<Map<String, Any?>>?) -> Unit |
| @@ -38,19 +33,10 @@ class MobileScanner( | @@ -38,19 +33,10 @@ class MobileScanner( | ||
| 38 | private val textureRegistry: TextureRegistry, | 33 | private val textureRegistry: TextureRegistry, |
| 39 | private val mobileScannerCallback: MobileScannerCallback, | 34 | private val mobileScannerCallback: MobileScannerCallback, |
| 40 | private val mobileScannerErrorCallback: MobileScannerErrorCallback | 35 | private val mobileScannerErrorCallback: MobileScannerErrorCallback |
| 41 | -) : | ||
| 42 | - PluginRegistry.RequestPermissionsResultListener { | ||
| 43 | - companion object { | ||
| 44 | - /** | ||
| 45 | - * When the application's activity is [androidx.fragment.app.FragmentActivity], requestCode can only use the lower 16 bits. | ||
| 46 | - * @see androidx.fragment.app.FragmentActivity.validateRequestPermissionsRequestCode | ||
| 47 | - */ | ||
| 48 | - private const val REQUEST_CODE = 0x0786 | ||
| 49 | - } | 36 | +) { |
| 50 | 37 | ||
| 51 | private var cameraProvider: ProcessCameraProvider? = null | 38 | private var cameraProvider: ProcessCameraProvider? = null |
| 52 | private var camera: Camera? = null | 39 | private var camera: Camera? = null |
| 53 | - private var pendingPermissionResult: MethodChannel.Result? = null | ||
| 54 | private var preview: Preview? = null | 40 | private var preview: Preview? = null |
| 55 | private var textureEntry: TextureRegistry.SurfaceTextureEntry? = null | 41 | private var textureEntry: TextureRegistry.SurfaceTextureEntry? = null |
| 56 | 42 | ||
| @@ -65,54 +51,6 @@ class MobileScanner( | @@ -65,54 +51,6 @@ class MobileScanner( | ||
| 65 | private var scanner = BarcodeScanning.getClient() | 51 | private var scanner = BarcodeScanning.getClient() |
| 66 | 52 | ||
| 67 | /** | 53 | /** |
| 68 | - * Check if we already have camera permission. | ||
| 69 | - */ | ||
| 70 | - fun hasCameraPermission(): Int { | ||
| 71 | - // Can't get exact denied or not_determined state without request. Just return not_determined when state isn't authorized | ||
| 72 | - val hasPermission = ContextCompat.checkSelfPermission( | ||
| 73 | - activity, | ||
| 74 | - Manifest.permission.CAMERA | ||
| 75 | - ) == PackageManager.PERMISSION_GRANTED | ||
| 76 | - | ||
| 77 | - return if (hasPermission) { | ||
| 78 | - 1 | ||
| 79 | - } else { | ||
| 80 | - 0 | ||
| 81 | - } | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - /** | ||
| 85 | - * Request camera permissions. | ||
| 86 | - */ | ||
| 87 | - fun requestPermission(result: MethodChannel.Result) { | ||
| 88 | - if(pendingPermissionResult != null) { | ||
| 89 | - return | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - pendingPermissionResult = result | ||
| 93 | - val permissions = arrayOf(Manifest.permission.CAMERA) | ||
| 94 | - ActivityCompat.requestPermissions(activity, permissions, REQUEST_CODE) | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - /** | ||
| 98 | - * Calls the callback after permissions are requested. | ||
| 99 | - */ | ||
| 100 | - override fun onRequestPermissionsResult( | ||
| 101 | - requestCode: Int, | ||
| 102 | - permissions: Array<out String>, | ||
| 103 | - grantResults: IntArray | ||
| 104 | - ): Boolean { | ||
| 105 | - if (requestCode != REQUEST_CODE) { | ||
| 106 | - return false | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | - pendingPermissionResult?.success(grantResults[0] == PackageManager.PERMISSION_GRANTED) | ||
| 110 | - pendingPermissionResult = null | ||
| 111 | - | ||
| 112 | - return true | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - /** | ||
| 116 | * callback for the camera. Every frame is passed through this function. | 54 | * callback for the camera. Every frame is passed through this function. |
| 117 | */ | 55 | */ |
| 118 | @ExperimentalGetImage | 56 | @ExperimentalGetImage |
-
Please register or login to post a comment