Skip to content

Commit

Permalink
Merge pull request #128 from newlogic/feature/zxing-integration
Browse files Browse the repository at this point in the history
Add truncated PDF417 support
  • Loading branch information
nicholemnl authored Nov 1, 2022
2 parents 037dd2b + dba91ca commit 234b13c
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 136 deletions.
19 changes: 17 additions & 2 deletions app/src/main/java/org/newlogic/smartscanner/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ class MainActivity : AppCompatActivity() {

override fun onStart() {
super.onStart()
// Choose scan type
// Choose scan modes
binding.itemBarcode.item.setOnClickListener { scanBarcode(BarcodeOptions.default) }
binding.itemIdpassLite.item.setOnClickListener { scanIDPassLite() }
binding.itemMrz.item.setOnClickListener { scanMRZ() }
binding.itemQr.item.setOnClickListener { scanQRCode() }
binding.itemNfc.item.setOnClickListener { scanNFC() }
binding.itemPdf417.item.setOnClickListener { scanPDF417() }
binding.itemQr.item.setOnClickListener { scanQRCode() }
// Change language
binding.languageSettings.setOnClickListener {
startActivity(Intent(this, SettingsActivity::class.java))
Expand Down Expand Up @@ -151,6 +152,20 @@ class MainActivity : AppCompatActivity() {

}

private fun scanPDF417() {
val intent = Intent(this, SmartScannerActivity::class.java)
intent.putExtra(
SmartScannerActivity.SCANNER_OPTIONS,
ScannerOptions(
mode = Modes.PDF_417.value,
language = getLanguage(preference),
scannerSize = ScannerSize.SMALL.value,
config = sampleConfig(false)
)
)
startActivityForResult(intent, OP_SCANNER)
}

private fun scanQRCode() {
val intent = ScannerIntent.intentQRCode(
isGzipped = true,
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/res/drawable/ic_scan_pdf417.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#646464"
android:pathData="M41.3934,22.0812h0l-0.001,0 -0.0066,-0.0029 -13.4191,-5.751C27.976,16.2172 28,16.1119 28,16a3.9954,3.9954 0,0 0,-3 -3.858L25,8L35,8a1,1 0,0 0,0 -2L13,6a1,1 0,0 0,0 2L23,8v4.142A3.9954,3.9954 0,0 0,20 16c0,0.1119 0.024,0.2172 0.0331,0.3268L6.614,22.0778l-0.0066,0.0029 -0.001,0h0A0.9989,0.9989 0,0 0,6 23L6,41a1,1 0,0 0,1 1L41,42a1,1 0,0 0,1 -1L42,23A0.9989,0.9989 0,0 0,41.3934 22.0812ZM24,14a2,2 0,1 1,-2 2A2.0027,2.0027 0,0 1,24 14ZM24,20a3.9979,3.9979 0,0 0,3.3214 -1.7747L36.1289,22L11.8711,22l8.8075,-3.7747A3.9979,3.9979 0,0 0,24 20ZM40,40L8,40L8,24L40,24Z" />
<path
android:fillColor="#646464"
android:pathData="M15,36a1,1 0,0 0,1 -1V29a1,1 0,0 0,-2 0v6A1,1 0,0 0,15 36Z" />
<path
android:fillColor="#646464"
android:pathData="M21,36a1,1 0,0 0,1 -1V29a1,1 0,0 0,-2 0v6A1,1 0,0 0,21 36Z" />
<path
android:fillColor="#646464"
android:pathData="M27,36a1,1 0,0 0,1 -1V29a1,1 0,0 0,-2 0v6A1,1 0,0 0,27 36Z" />
<path
android:fillColor="#646464"
android:pathData="M33,36a1,1 0,0 0,1 -1V29a1,1 0,0 0,-2 0v6A1,1 0,0 0,33 36Z" />
</vector>
205 changes: 116 additions & 89 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,119 +9,146 @@
android:orientation="vertical"
tools:context="org.newlogic.smartscanner.MainActivity">

<ImageView
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/language_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_settings_menu"
app:layout_constraintBottom_toTopOf="@+id/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.976"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.4" />
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginTop="64dp"
android:paddingStart="48dp"
android:paddingEnd="48dp"
app:srcCompat="@drawable/ic_id_pass_logo"
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="40dp"
android:layout_marginBottom="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@+id/language_settings">

<TextView
android:id="@+id/toolbar_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:fontFamily="@font/sourcesanspro_bold"
android:text="@string/app_name"
android:textColor="@color/newlogic_black"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/start"
app:layout_constraintTop_toBottomOf="@+id/logo" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center|center_vertical"
android:orientation="vertical"
tools:context="org.newlogic.smartscanner.MainActivity">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.54" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:paddingStart="48dp"
android:paddingEnd="48dp"
android:layout_marginTop="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_id_pass_logo" />

<include
android:id="@+id/item_barcode"
layout="@layout/item_barcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar_title" />
<TextView
android:id="@+id/toolbar_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:fontFamily="@font/sourcesanspro_bold"
android:text="@string/app_name"
android:textColor="@color/newlogic_black"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/start"
app:layout_constraintTop_toBottomOf="@+id/logo" />

<include
android:id="@+id/item_idpass_lite"
layout="@layout/item_idpass_lite"
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_barcode" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.54" />

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

<include
android:id="@+id/item_nfc"
layout="@layout/item_nfc"
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_idpass_lite"
layout="@layout/item_idpass_lite"
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_barcode" />

<include
android:id="@+id/item_qr"
layout="@layout/item_qr"
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_nfc" />
<include
android:id="@+id/item_pdf417"
layout="@layout/item_pdf417"
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_idpass_lite" />

<include
android:id="@+id/item_mrz"
layout="@layout/item_mrz"
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_pdf417" />

<include
android:id="@+id/item_nfc"
layout="@layout/item_nfc"
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_qr"
layout="@layout/item_qr"
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_nfc" />

</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

<TextView
android:id="@+id/branding_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="8dp"
android:gravity="center|bottom"
android:fontFamily="@font/sourcesanspro_regular"
android:gravity="center|bottom"
android:text="@string/label_newlogic"
android:textSize="13sp"
android:layout_marginStart="24dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
46 changes: 46 additions & 0 deletions app/src/main/res/layout/item_pdf417.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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"
android:paddingTop="16dp">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_scan_pdf417"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/txt_pdf417"
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_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: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" />

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="mode_idpass_lite">معرف باس لايت</string>
<string name="mode_mrz">كود MRZ</string>
<string name="mode_nfc">الجواز الالكتروني/بطاقة الهوية (NFC)</string>
<string name="mode_pdf417">PDF417</string>
<string name="mode_qr">كيو ار كود</string>

<!--Labels-->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="mode_idpass_lite">ID PASS Lite</string>
<string name="mode_mrz">MRZ Code</string>
<string name="mode_nfc">E-Passport/ID Card (NFC)</string>
<string name="mode_pdf417">PDF417</string>
<string name="mode_qr">QR Code</string>

<!--Labels-->
Expand Down
3 changes: 3 additions & 0 deletions core-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@ dependencies {
def work_version = "2.7.0"
implementation "androidx.work:work-runtime:$work_version"
implementation "androidx.work:work-runtime-ktx:$work_version"
// Barcode
implementation('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false }
implementation 'com.google.zxing:core:3.3.0'
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
package org.idpass.smartscanner.lib

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("org.idpass.smartscanner.test", appContext.packageName)
}
}
@RunWith(JUnit4::class)
class ExampleInstrumentedTest
Loading

0 comments on commit 234b13c

Please sign in to comment.