-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathMainActivity.kt
More file actions
61 lines (55 loc) · 1.76 KB
/
MainActivity.kt
File metadata and controls
61 lines (55 loc) · 1.76 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
package com.websitebeaver.documentscanner.demo
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.websitebeaver.documentscanner.DocumentScanner
import com.websitebeaver.documentscanner.utils.ImageUtil
/**
* A demo showing how to use the document scanner
*
* @constructor creates demo activity
*/
class MainActivity : AppCompatActivity() {
/**
* @property croppedImageView the cropped image view
*/
private lateinit var croppedImageView: ImageView
/**
* @property documentScanner the document scanner
*/
private val documentScanner = DocumentScanner(
this,
useQuickCapture = true,
successHandler = { croppedImageResults ->
// display the first cropped image
croppedImageView.setImageBitmap(
ImageUtil().readBitmapFromFileUriString(
croppedImageResults.first(),
contentResolver
)
)
},
errorHandler = {
// an error happened
errorMessage -> Log.v("documentscannerlogs", errorMessage)
},
cancelHandler = {
// user canceled document scan
Log.v("documentscannerlogs", "User canceled document scan")
}
)
/**
* called when activity is created
*
* @param savedInstanceState persisted data that maintains state
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// cropped image
croppedImageView = findViewById(R.id.cropped_image_view)
// start document scan
documentScanner.startScan()
}
}