-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathCheckScannerActivity.kt
More file actions
104 lines (92 loc) · 3.68 KB
/
CheckScannerActivity.kt
File metadata and controls
104 lines (92 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package io.scanbot.example
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import io.scanbot.common.Result
import io.scanbot.common.onFailure
import io.scanbot.common.onSuccess
import io.scanbot.example.common.applyEdgeToEdge
import io.scanbot.sdk.ScanbotSDK
import io.scanbot.sdk.camera.CameraPreviewMode
import io.scanbot.sdk.check.CheckScannerFrameHandler
import io.scanbot.sdk.check.CheckScannerFrameHandler.Companion.attach
import io.scanbot.sdk.check.CheckScanningResult
import io.scanbot.sdk.check.CheckMagneticInkStripScanningStatus
import io.scanbot.sdk.ui.camera.ScanbotCameraXView
class CheckScannerActivity : AppCompatActivity() {
private lateinit var cameraView: ScanbotCameraXView
private lateinit var resultView: TextView
private lateinit var frameHandler: CheckScannerFrameHandler
var flashEnabled = false
override fun onCreate(savedInstanceState: Bundle?) {
supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_check_scanner)
supportActionBar?.hide()
applyEdgeToEdge(this.findViewById(R.id.root_view))
cameraView = findViewById<ScanbotCameraXView>(R.id.camera).also { cameraView ->
cameraView.setPreviewMode(CameraPreviewMode.FIT_IN)
cameraView.setCameraOpenCallback {
cameraView.postDelayed({
cameraView.useFlash(flashEnabled)
cameraView.continuousFocus()
}, 700)
}
}
resultView = findViewById<View>(R.id.result) as TextView
val scanbotSDK = ScanbotSDK(this)
scanbotSDK.createCheckScanner().onSuccess { checkScanner ->
frameHandler = attach(cameraView, checkScanner)
frameHandler.addResultHandler { result, frame ->
result.onSuccess { scanningResult ->
if (scanningResult.status == CheckMagneticInkStripScanningStatus.SUCCESS) {
frameHandler.isEnabled = false
startActivity(
CheckScannerResultActivity.newIntent(
this@CheckScannerActivity,
scanningResult
)
)
}
}.onFailure {
if (it is Result.InvalidLicenseError) {
frameHandler.isEnabled = false
runOnUiThread {
Toast.makeText(
this@CheckScannerActivity,
"License is expired",
Toast.LENGTH_LONG
).show()
finish()
}
}
}
false
}
}
findViewById<View>(R.id.flash).setOnClickListener {
flashEnabled = !flashEnabled
cameraView.useFlash(flashEnabled)
}
Toast.makeText(
this,
if (scanbotSDK.licenseInfo.isValid) "License is active" else "License is expired",
Toast.LENGTH_LONG
).show()
}
override fun onResume() {
super.onResume()
frameHandler.isEnabled = true
}
companion object {
@JvmStatic
fun newIntent(context: Context?): Intent {
return Intent(context, CheckScannerActivity::class.java)
}
}
}