Skip to content

Commit

Permalink
Add OCR feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jlduragos committed Oct 31, 2023
1 parent 507ce07 commit d0e1a35
Show file tree
Hide file tree
Showing 30 changed files with 816 additions and 116 deletions.
28 changes: 28 additions & 0 deletions app/src/main/java/org/newlogic/smartscanner/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MainActivity : AppCompatActivity() {
binding.itemBarcode.item.setOnClickListener { scanBarcode(BarcodeOptions.default) }
binding.itemIdpassLite.item.setOnClickListener { scanIDPassLite() }
binding.itemMrz.item.setOnClickListener { scanMRZ() }
binding.itemOcr.item.setOnClickListener { scanOCR() }
binding.itemQr.item.setOnClickListener { scanQRCode() }
// binding.itemQrGzip.item.setOnClickListener { scanQRCodeGzip() }
binding.itemNfc.item.setOnClickListener { scanNFC() }
Expand Down Expand Up @@ -145,6 +146,33 @@ class MainActivity : AppCompatActivity() {
startActivityForResult(intent, OP_SCANNER)
}

private fun scanOCR() {
val intent = Intent(this, SmartScannerActivity::class.java)
intent.putExtra(
SmartScannerActivity.SCANNER_OPTIONS,
ScannerOptions(
mode = Modes.OCR.value,
language = getLanguage(preference),
ocrOptions = OCROptions(
analyzeStart = 1000
),
config = Config(
branding = true,
imageResultType = imageType,
label = "",
isManualCapture = false,
orientation = getOrientation(preference),
showOcrGuide = true,
xGuide = 0.5,
yGuide = 0.5,
widthGuide = 150,
heightGuide = 40
)
)
)
startActivityForResult(intent, OP_SCANNER)
}

private fun scanNFC() {
if (isNFCSupported()) {
val intent = Intent(this, SmartScannerActivity::class.java)
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_scan_ocr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
android:height="36dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#646464"
android:pathData="M43.2,137.6c-3.7,0 -6.6,-3 -6.6,-6.6L36.6,71.7c0,-19.4 15.8,-35.2 35.2,-35.2L131,36.5c3.7,0 6.6,3 6.6,6.6s-3,6.6 -6.6,6.6L71.7,49.7c-12.1,0 -21.9,9.8 -21.9,21.9v59.2c0.1,3.8 -2.9,6.8 -6.6,6.8zM130.9,475.4L71.6,475.4c-19.3,0 -35,-15.7 -35,-35v-59.3c0,-3.7 3,-6.6 6.6,-6.6s6.6,3 6.6,6.6v59.3c0,12 9.8,21.8 21.8,21.8h59.3c3.7,0 6.6,3 6.6,6.6 0.1,3.7 -2.9,6.6 -6.6,6.6zM440.5,475.4h-59.4c-3.7,0 -6.6,-3 -6.6,-6.6 0,-3.7 3,-6.6 6.6,-6.6h59.4c11.9,0 21.6,-9.7 21.6,-21.6v-59.4c0,-3.7 3,-6.6 6.6,-6.6 3.7,0 6.6,3 6.6,6.6v59.4c0.1,19.2 -15.5,34.8 -34.8,34.8zM468.8,137.6c-3.7,0 -6.6,-3 -6.6,-6.6L462.2,71.6c0,-12 -9.8,-21.8 -21.8,-21.8h-59.3c-3.7,0 -6.6,-3 -6.6,-6.6s3,-6.6 6.6,-6.6h59.3c19.3,0 35,15.7 35,35v59.3c0,3.7 -2.9,6.7 -6.6,6.7zM130.6,316.2c-9.4,0 -18,-1.9 -25.8,-5.7 -7.8,-3.8 -14.4,-8.8 -20,-15.1 -5.5,-6.2 -9.8,-13.4 -12.9,-21.4 -3,-8.1 -4.6,-16.3 -4.6,-24.8 0,-8.8 1.6,-17.2 4.8,-25.3 3.2,-8.1 7.7,-15.2 13.3,-21.4 5.6,-6.2 12.3,-11.1 20.1,-14.8 7.8,-3.7 16.2,-5.5 25.4,-5.5 9.4,0 18,2 25.8,5.9 7.8,3.9 14.4,9 19.9,15.4 5.5,6.3 9.8,13.5 12.8,21.5s4.6,16.2 4.6,24.5c0,8.8 -1.6,17.2 -4.7,25.3 -3.2,8.1 -7.6,15.2 -13.3,21.3 -5.7,6.1 -12.4,11 -20.2,14.7 -7.7,3.6 -16.1,5.4 -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4,6 -5.4,1.4 -10.7,2 -15.9,2 -9.3,0 -17.8,-2 -25.5,-6 -7.7,-4 -14.3,-9.1 -19.9,-15.5 -5.6,-6.4 -9.9,-13.6 -13,-21.8 -3.2,-8 -4.8,-16.3 -4.8,-24.7zM343,315.3L343,183.1h57.5c6,0 11.4,1.2 16.5,3.7 5,2.5 9.3,5.7 12.9,9.8 3.6,4 6.4,8.6 8.5,13.8 2,5.2 3.1,10.4 3.1,15.7 0,4.5 -0.6,8.7 -1.9,12.8 -1.2,4.1 -3,7.9 -5.2,11.4s-5,6.5 -8.2,9c-3.2,2.5 -6.8,4.4 -10.6,5.7l31.1,50.3L423,315.3l-28.7,-46h-30.5v46L343,315.3zM363.9,250.9h36.5c3,0 5.7,-0.7 8.1,-2 2.4,-1.3 4.5,-3.1 6.2,-5.4 1.7,-2.3 3.1,-4.9 4.1,-7.9 1,-3 1.5,-6.1 1.5,-9.5 0,-3.4 -0.6,-6.5 -1.8,-9.5 -1.2,-3 -2.7,-5.6 -4.7,-7.8 -1.9,-2.2 -4.2,-4 -6.7,-5.3 -2.5,-1.3 -5.2,-2 -7.9,-2h-35.4v49.4z" />
</vector>
13 changes: 12 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_pdf417" />

<include
android:id="@+id/item_ocr"
layout="@layout/item_ocr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_mrz" />

<include
android:id="@+id/item_nfc"
layout="@layout/item_nfc"
Expand All @@ -121,7 +132,7 @@
android:layout_marginTop="4dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_mrz" />
app:layout_constraintTop_toBottomOf="@+id/item_ocr" />

<include
android:id="@+id/item_qr"
Expand Down
15 changes: 7 additions & 8 deletions app/src/main/res/layout/item_barcode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingTop="16dp">
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:src="@drawable/ic_scan_barcode"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -24,22 +24,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_barcode"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginTop="12dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_barcode" />
app:layout_constraintTop_toBottomOf="@id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
15 changes: 7 additions & 8 deletions app/src/main/res/layout/item_idpass_lite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingTop="16dp">
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:src="@drawable/ic_scan_idpass_lite"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -24,22 +24,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_idpass_lite"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginTop="12dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_idpass" />
app:layout_constraintTop_toBottomOf="@id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
17 changes: 8 additions & 9 deletions app/src/main/res/layout/item_mrz.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingTop="16dp">
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:src="@drawable/ic_scan_mrz"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -24,22 +24,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_mrz"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginTop="12dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_mrz" />
app:layout_constraintTop_toBottomOf="@id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
19 changes: 9 additions & 10 deletions app/src/main/res/layout/item_nfc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingTop="16dp">
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_height="38dp"
android:layout_marginStart="18dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_scan_nfc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -23,23 +23,22 @@
android:id="@+id/txt_nfc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginStart="18dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_nfc"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginTop="10dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_nfc" />
app:layout_constraintTop_toBottomOf="@+id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
47 changes: 47 additions & 0 deletions app/src/main/res/layout/item_ocr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:padding="2dp"
android:layout_marginTop="12dp"
android:src="@drawable/ic_scan_ocr"
android:scaleType="fitXY"
android:adjustViewBounds="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/txt_ocr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_ocr"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="12dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
18 changes: 9 additions & 9 deletions app/src/main/res/layout/item_pdf417.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingTop="16dp">
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:src="@drawable/ic_scan_pdf417"
android:scaleType="fitXY"
android:adjustViewBounds="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Expand All @@ -24,23 +26,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_pdf417"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginTop="12dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_pdf417" />
app:layout_constraintTop_toBottomOf="@id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit d0e1a35

Please sign in to comment.