-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathMrzScannerComposeActivity.kt
More file actions
47 lines (40 loc) · 1.7 KB
/
MrzScannerComposeActivity.kt
File metadata and controls
47 lines (40 loc) · 1.7 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
package io.scanbot.example
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.camera.camera2.interop.ExperimentalCamera2Interop
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.core.view.WindowCompat
import io.scanbot.example.compose.MrzScannerViewClassic
import io.scanbot.example.compose.MrzViewModel
import io.scanbot.example.fragments.MRZDialogFragment
import io.scanbot.sdk.ScanbotSDK
import io.scanbot.sdk.mrz.MrzScannerResult
import io.scanbot.sdk.ui_v2.common.CameraConfiguration
class MrzScannerComposeActivity : AppCompatActivity() {
@ExperimentalCamera2Interop
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(ComposeView(this).apply {
setContent {
MrzScannerViewClassic(
modifier = Modifier.fillMaxSize().statusBarsPadding(),
viewModel = MrzViewModel(CameraConfiguration(), ScanbotSDK(this@MrzScannerComposeActivity)),
onMrz = { mrzRecognitionResult ->
showMrzDialog(mrzRecognitionResult)
},
onScannerClosed = {
finish()
},
)
}
})
}
private fun showMrzDialog(mrzRecognitionResult: MrzScannerResult) {
val dialogFragment = MRZDialogFragment.newInstance(mrzRecognitionResult.document)
dialogFragment.show(supportFragmentManager, MRZDialogFragment.NAME)
}
}