Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Commit

Permalink
Merge branch 'fix-autofocus' of https://github.com/oznecniV97/flutter…
Browse files Browse the repository at this point in the history
…_barcode_reader into oznecniV97-fix-autofocus
  • Loading branch information
devtronic committed May 8, 2020
2 parents 58bb4c0 + bde741c commit 54e6bb7
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import me.dm7.barcodescanner.zxing.ZXingScannerView
class ZXingAutofocusScannerView(context: Context) : ZXingScannerView(context) {

private var callbackFocus = false
private var autofocusPresence = false

override fun setupCameraPreview(cameraWrapper: CameraWrapper?) {
cameraWrapper?.mCamera?.parameters?.let { parameters ->
try {
autofocusPresence = parameters.supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO);
parameters.focusMode = Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
cameraWrapper.mCamera.parameters = parameters
} catch (ex: Exception) {
Expand All @@ -23,6 +25,9 @@ class ZXingAutofocusScannerView(context: Context) : ZXingScannerView(context) {
}

override fun setAutoFocus(state: Boolean) {
super.setAutoFocus(callbackFocus)
//Fix to avoid crash on devices without autofocus (Issue #226)
if(autofocusPresence){
super.setAutoFocus(callbackFocus)
}
}
}

0 comments on commit 54e6bb7

Please sign in to comment.