Skip to content

Commit 8fa393b

Browse files
committed
Updated samples
1 parent fff1903 commit 8fa393b

26 files changed

Lines changed: 595 additions & 215 deletions

Samples/Advanced/DocumentReader-Kotlin/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ lint/generated/
8383
lint/outputs/
8484
lint/tmp/
8585
# lint/reports/
86+
87+
88+
app/src/main/assets/Regula/db.dat

Samples/Advanced/DocumentReader-Kotlin/app/build.gradle

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ plugins {
44
}
55

66
android {
7-
compileSdkVersion 30
7+
allprojects {
8+
repositories {
9+
maven {
10+
url "https://maven.regulaforensics.com/RegulaDocumentReader"
11+
}
12+
}
13+
}
14+
15+
compileSdkVersion 31
816
buildToolsVersion "30.0.3"
917

1018
defaultConfig {
1119
applicationId "com.regula.documentreader"
1220
minSdkVersion 23
13-
targetSdkVersion 30
21+
targetSdkVersion 31
1422
versionCode 1
1523
versionName "1.0"
1624

@@ -33,35 +41,31 @@ android {
3341
targetCompatibility JavaVersion.VERSION_1_8
3442
}
3543
kotlinOptions {
36-
jvmTarget = '1.8'
44+
jvmTarget = '11'
3745
}
3846
}
3947

4048
dependencies {
4149
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
42-
implementation 'androidx.core:core-ktx:1.5.0'
43-
implementation 'androidx.appcompat:appcompat:1.3.0'
44-
implementation 'com.google.android.material:material:1.3.0'
45-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
50+
implementation 'androidx.core:core-ktx:1.6.0'
51+
implementation 'androidx.appcompat:appcompat:1.3.1'
52+
implementation 'com.google.android.material:material:1.4.0'
53+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
4654
implementation 'androidx.preference:preference-ktx:1.1.1'
4755
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
4856
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
4957
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
5058
testImplementation 'junit:junit:4.13.2'
51-
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
52-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
59+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
60+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
5361

54-
//noinspection GradleDynamicVersion
55-
implementation 'com.regula.documentreader.core:fullrfid:5.7.+@aar'
56-
//noinspection GradleDynamicVersion
57-
implementation('com.regula.documentreader:api:5.7.+@aar') {
62+
implementation 'com.regula.documentreader.core:fullrfid:5.8.+@aar'
63+
implementation('com.regula.documentreader:api:5.8.+@aar') {
5864
transitive = true
5965
}
6066

61-
implementation "androidx.recyclerview:recyclerview:1.2.0"
62-
implementation "com.google.android.material:material:1.3.0"
67+
implementation "androidx.recyclerview:recyclerview:1.2.1"
6368
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1"
64-
implementation 'com.google.android.material:material:1.4.0-beta01'
6569

6670
implementation 'com.github.kittinunf.fuel:fuel:2.3.1'
6771
}

Samples/Advanced/DocumentReader-Kotlin/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
tools:ignore="LockedOrientationActivity" />
3232
<activity
3333
android:name=".MainActivity"
34+
android:exported="true"
3435
android:screenOrientation="portrait"
3536
tools:ignore="LockedOrientationActivity">
3637
<intent-filter>

Samples/Advanced/DocumentReader-Kotlin/app/src/main/assets/Regula/.gitignore

Whitespace-only changes.

Samples/Advanced/DocumentReader-Kotlin/app/src/main/java/com/regula/documentreader/BottomSheet.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ class BottomSheet :
9292
return dialog
9393
}
9494

95-
override fun onActivityCreated(savedInstanceState: Bundle?) {
96-
super.onActivityCreated(savedInstanceState)
97-
(view?.parent as View).setBackgroundColor(Color.TRANSPARENT)
95+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
96+
super.onViewCreated(view, savedInstanceState)
97+
(view.parent as View).setBackgroundColor(Color.TRANSPARENT)
9898
}
9999

100100
private fun countHeight(maxHeightPx: Int, fullHeight: Boolean): Int {

Samples/Advanced/DocumentReader-Kotlin/app/src/main/java/com/regula/documentreader/CommonRecyclerAdapter.kt

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
3838
is TextResult -> TEXT_RESULT
3939
is Image -> IMAGE
4040
is Status -> STATUS
41+
is InputDouble -> INPUT_DOUBLE
4142
else -> 0
4243
}
4344

@@ -56,6 +57,7 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
5657
TEXT_RESULT -> VH.TextResultVH(RvTextResultBinding.inflate(li, parent, false))
5758
IMAGE -> VH.ImageVH(RvImageBinding.inflate(li, parent, false))
5859
STATUS -> VH.StatusVH(RvStatusBinding.inflate(li, parent, false))
60+
INPUT_DOUBLE -> VH.InputDoubleVH(RvTitleValueBinding.inflate(li, parent, false))
5961
else -> VH.SectionVH(RvSectionBinding.inflate(li, parent, false))
6062
}
6163
}
@@ -129,8 +131,12 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
129131
val switch = base as Switch
130132
binding.switcher.text = switch.title
131133
binding.switcher.setOnCheckedChangeListener(null)
132-
binding.switcher.isChecked = switch.get()
134+
binding.switcher.isChecked = switch.get() ?: false
133135
binding.switcher.setOnCheckedChangeListener { _, isChecked -> switch.set(isChecked) }
136+
137+
val enabled = switch.enabled()
138+
binding.switcher.isEnabled = enabled
139+
binding.alphaChanger.alpha = grayedOutAlpha(enabled)
134140
}
135141
}
136142

@@ -177,13 +183,13 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
177183
val bs = base as BS
178184
init(bs)
179185
for (item in bs.items)
180-
if (item.title == bs.get()) {
186+
if (item.value == bs.get()) {
181187
selected = item
182188
item.selected = true
183189
}
184190
binding.root.setOnClickListener(OnClickListenerSerializable {
185191
BottomSheet.newInstance(bs.bsTitle, bs.items, true) {
186-
bs.set(it.title)
192+
bs.set(it.value)
187193
init(bs)
188194
if (selected != null)
189195
selected?.selected = false
@@ -198,7 +204,7 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
198204
if (bs.get() == null || bs.get()!!.isEmpty())
199205
binding.value.text = context.resources.getString(R.string.string_default)
200206
else
201-
binding.value.text = bs.get()
207+
binding.value.text = bs.getFromMap()
202208
}
203209
}
204210

@@ -207,15 +213,18 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
207213
override fun bind(base: Base) {
208214
val bs = base as BSMulti
209215
init(bs)
216+
for (item in bs.items)
217+
if (bs.get().contains(item.value))
218+
item.selected = true
210219
binding.root.setOnClickListener(OnClickListenerSerializable {
211220
BottomSheet.newInstance(bs.bsTitle, bs.items, false, "Close") {
212221
if (it.selected) {
213222
val list = bs.get()
214-
list.remove(it.title)
223+
list.remove(it.value)
215224
bs.set(list)
216225
} else {
217226
val list = bs.get()
218-
list.add(it.title)
227+
list.add(it.value)
219228
bs.set(list)
220229
}
221230
it.selected = !it.selected
@@ -226,7 +235,7 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
226235

227236
private fun init(bsMulti: BSMulti) {
228237
binding.title.text = bsMulti.title
229-
binding.value.text = listToString(bsMulti.get(), context)
238+
binding.value.text = listToString(bsMulti.getFromMap(), context)
230239
}
231240
}
232241

@@ -260,6 +269,36 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
260269
}
261270
}
262271

272+
class InputDoubleVH(private val binding: RvTitleValueBinding) : VH(binding.root) {
273+
override fun bind(base: Base) {
274+
val input = base as InputDouble
275+
init(input)
276+
binding.root.setOnClickListener {
277+
val editText = EditText(context)
278+
editText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
279+
input.get()?.let { editText.setText(it.toString()) }
280+
MaterialAlertDialogBuilder(
281+
context,
282+
R.style.AlertDialogTheme
283+
).setTitle(input.title).setView(editText)
284+
.setPositiveButton("Done") { _, _ ->
285+
if (editText.text.toString().isEmpty())
286+
input.set(null)
287+
else try {
288+
input.set(editText.text.toString().toDouble())
289+
} catch (e: Exception) {
290+
}
291+
init(input)
292+
}.setNegativeButton("Cancel", null).show()
293+
}
294+
}
295+
296+
private fun init(inputDouble: InputDouble) {
297+
binding.title.text = inputDouble.title
298+
binding.value.text = inputDouble.get()?.toString() ?: ""
299+
}
300+
}
301+
263302
class InputStringVH(private val binding: RvTitleValueBinding) : VH(binding.root) {
264303
override fun bind(base: Base) {
265304
val input = base as InputString
@@ -293,6 +332,7 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
293332
binding.value.text = textResult.value
294333
binding.value.setTextColor(textResult.color)
295334
binding.lcid.text = textResult.lcid
335+
binding.pageIndex.text = context.getString(R.string.pageIndex, textResult.pageIndex)
296336
}
297337
}
298338

@@ -329,5 +369,6 @@ class CommonRecyclerAdapter(private val items: List<Base>) :
329369
private const val TEXT_RESULT = 7
330370
private const val IMAGE = 8
331371
private const val STATUS = 9
372+
private const val INPUT_DOUBLE = 10
332373
}
333374
}

Samples/Advanced/DocumentReader-Kotlin/app/src/main/java/com/regula/documentreader/CustomRfidActivity.kt

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.regula.documentreader
22

33
import android.app.Activity
44
import android.app.PendingIntent
5+
import android.app.PendingIntent.FLAG_IMMUTABLE
56
import android.content.BroadcastReceiver
67
import android.content.Context
78
import android.content.Intent
@@ -77,7 +78,7 @@ class CustomRfidActivity : AppCompatActivity() {
7778
}
7879

7980
private fun checkAdapterEnabled() {
80-
if (nfcAdapter.isEnabled && DocumentReader.Instance().documentReaderIsReady)
81+
if (nfcAdapter.isEnabled && DocumentReader.Instance().isReady)
8182
setupForegroundDispatch(this, nfcAdapter)
8283
else
8384
Log.e(TAG, "NFC is not enabled")
@@ -89,7 +90,7 @@ class CustomRfidActivity : AppCompatActivity() {
8990
*/
9091
private fun setupForegroundDispatch(activity: Activity, adapter: NfcAdapter) {
9192
val intent = Intent(activity.applicationContext, activity.javaClass)
92-
val pendingIntent = PendingIntent.getActivity(activity.applicationContext, 0, intent, 0)
93+
val pendingIntent = PendingIntent.getActivity(activity.applicationContext, 0, intent, FLAG_IMMUTABLE)
9394
val filters = arrayOfNulls<IntentFilter>(1)
9495

9596
// Notice that this is the same filter as in our manifest.
@@ -130,7 +131,7 @@ class CustomRfidActivity : AppCompatActivity() {
130131
DocumentReader.Instance().readRFID(isoDepTag) { rfidAction, results, error ->
131132
when (rfidAction) {
132133
DocReaderAction.COMPLETE -> {
133-
MainActivity.results = results
134+
MainActivity.results = results!!
134135
if (results.rfidResult == 0x00000001) {
135136
setResult(RESULT_OK)
136137
binding.rfidStatus.text =
@@ -158,17 +159,17 @@ class CustomRfidActivity : AppCompatActivity() {
158159
binding.currentDataGroupLt.visibility = View.VISIBLE
159160
binding.rfidStatus.setTextColor(getColor(android.R.color.holo_orange_light))
160161
}
161-
rfidProgress(
162-
results.documentReaderNotification!!.code,
163-
results.documentReaderNotification!!.value
164-
)
165162
}
163+
rfidProgress(
164+
results!!.documentReaderNotification!!.code,
165+
results.documentReaderNotification!!.value
166+
)
166167
}
167168
DocReaderAction.ERROR -> {
168169
val builder =
169170
getString(R.string.RFID_Error_Failed) + "\n" + eRFID_NotificationAndErrorCodes.getTranslation(
170171
this,
171-
results.rfidResult
172+
results!!.rfidResult
172173
)
173174
binding.rfidStatus.text = builder
174175
binding.rfidStatus.setTextColor(getColor(R.color.reg_red_fail))
@@ -179,26 +180,19 @@ class CustomRfidActivity : AppCompatActivity() {
179180
}
180181
}
181182

182-
// private fun codeToType(code: Int): Int = code and 0x10000
183+
private fun codeToType(code: Int): Int = code and 0x10000
183184

184185
private fun rfidProgress(code: Int, value: Int) {
185-
val hiword = code and -0x10000
186-
val loword = code and 0x0000FFFF
187-
val progress = value and -0x10
188-
189-
var currentDataGroup: String? = null
190-
if (hiword == eRFID_NotificationAndErrorCodes.RFID_NOTIFICATION_PCSC_READING_DATAGROUP)
191-
currentDataGroup = if (value == 100) null else String.format(
192-
getString(com.regula.documentreader.api.R.string.strReadingRFIDDG),
193-
eRFID_DataFile_Type.getTranslation(applicationContext, loword)
194-
)
195-
196-
if (currentDataGroup != null && currentDataGroup.isNotEmpty()) {
197-
binding.currentRfidDgTv.text = currentDataGroup
198-
}
199-
200-
if (progress in 1..100) {
201-
binding.progressBar.progress = progress
186+
when (code and -0x10000) {
187+
eRFID_NotificationAndErrorCodes.RFID_NOTIFICATION_PCSC_READING_DATAGROUP -> if (value == 0) {
188+
handler.post {
189+
binding.currentRfidDgTv.text = String.format(
190+
getString(R.string.strReadingRFIDDG), eRFID_DataFile_Type.getTranslation(
191+
applicationContext, codeToType(code)
192+
)
193+
)
194+
}
195+
}
202196
}
203197
}
204198

Samples/Advanced/DocumentReader-Kotlin/app/src/main/java/com/regula/documentreader/DirectResultsActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import com.regula.documentreader.databinding.ActivityDirectResultsBinding
3333
import com.regula.documentreader.databinding.FragmentRvAddParameterBinding
3434
import java.io.Serializable
3535

36-
3736
class DirectResultsActivity : AppCompatActivity() {
3837
lateinit var binding: ActivityDirectResultsBinding
3938
var fields = mutableListOf<ParameterField>()

0 commit comments

Comments
 (0)