-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathCheckScannerResultActivity.kt
More file actions
68 lines (57 loc) · 2.42 KB
/
CheckScannerResultActivity.kt
File metadata and controls
68 lines (57 loc) · 2.42 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
package io.scanbot.example
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import io.scanbot.example.common.applyEdgeToEdge
import io.scanbot.sdk.check.CheckScanningResult
import io.scanbot.sdk.genericdocument.GenericDocument
class CheckScannerResultActivity : AppCompatActivity() {
private lateinit var checkResultImageView: ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_check_result)
supportActionBar?.hide()
applyEdgeToEdge(this.findViewById(R.id.root_view))
val fieldsLayout = findViewById<LinearLayout>(R.id.check_result_fields_layout)
checkResultImageView = findViewById(R.id.check_result_image)
intent.getParcelableExtra<GenericDocument>(EXTRA_CHECK_DOCUMENT)?.also { checkDocument ->
addValueView(fieldsLayout, "Type", checkDocument.type.name)
checkDocument.fields.forEach { field ->
field.value?.let { ocrResult ->
addValueView(fieldsLayout, field.type.name, ocrResult.text)
}
}
}
tempDocumentImage?.let {
checkResultImageView.visibility = View.VISIBLE
checkResultImageView.setImageBitmap(it)
}
findViewById<View>(R.id.retry).setOnClickListener {
tempDocumentImage = null
finish()
}
}
private fun addValueView(layout: LinearLayout, title: String, value: String) {
val v = layoutInflater.inflate(R.layout.view_key_value, layout, false)
v.findViewById<TextView>(R.id.view_text_key).text = title
v.findViewById<TextView>(R.id.view_text_value).text = value
layout.addView(v)
}
companion object {
const val EXTRA_CHECK_DOCUMENT = "CheckDocument"
// TODO: handle image more carefully in production code
var tempDocumentImage: Bitmap? = null
@JvmStatic
fun newIntent(context: Context?, result: CheckScanningResult): Intent {
val intent = Intent(context, CheckScannerResultActivity::class.java)
intent.putExtra(EXTRA_CHECK_DOCUMENT, result.check)
return intent
}
}
}