Skip to content

Commit

Permalink
Merge pull request #48 from BlinkID/develop
Browse files Browse the repository at this point in the history
v4.9.0.0
  • Loading branch information
matvidako authored Apr 29, 2019
2 parents acf591b + 5fe3a36 commit 722e70f
Show file tree
Hide file tree
Showing 54 changed files with 424 additions and 908 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This library depends on _BlinkID SDK_ so you'll need to add _BlinkID_ maven repo
Now you can add _BlinkID UI_ as a new module to your project

* in Android Studio menu, click File - New - New Module - Import Gradle Project
* select blinkid-ui-lib folder and click FInish
* select blinkid-ui-lib folder and click Finish
* in your `settings.gradle` add `include 'blinkid-ui-lib'`
* in your app's `build.gradle` add new module dependency `implementation project(':blinkid-ui-lib')`

Expand All @@ -39,7 +39,13 @@ If you're using Proguard, you'll need to add the following line to your Proguard

## <a name="faq"></a> FAQ
### How do I customise colors, icons and other resources?
You have to name your resource the same as the resource you want to override in the library. For example, if you want to change torch icon, name you icon `mb_ic_torch_on`.
To use your custom theme in scan activity, extend `MbScanTheme` and override attribues you want to change.

To use custom theme in country selection activity, extend either `MbChooseCountryLightTheme` or `MbChooseCountryDarkTheme` and override `createDocumentChooser()` in your scan activity to return your theme.

For other resources, name your resource the same as the resource you want to override in the library. For example, if you want to change torch icon, name you icon `mb_ic_torch_on`.

Check the sample app for examples of customisation.

### How do I disable translations?
To disable translations for country names, override `createLocalizationManager()` and return your custom `LocaleManager` that limits languages to which to translate to.
Expand Down
2 changes: 1 addition & 1 deletion blinkid-ui-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ String getBlinkIdDependency() {
if (project.hasProperty(altDependencyProperty)) {
return project.property(altDependencyProperty)
} else {
return "com.microblink:blinkid:4.8.0@aar"
return "com.microblink:blinkid:4.9.0@aar"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import android.support.annotation.AnyThread
import android.support.annotation.CallSuper
import android.support.annotation.UiThread
import android.support.design.widget.TabLayout
import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import android.view.animation.AccelerateDecelerateInterpolator
import com.microblink.documentscanflow.country.CountryFactory
import com.microblink.documentscanflow.document.Document
Expand Down Expand Up @@ -73,6 +73,7 @@ import com.microblink.view.recognition.ScanResultListener
import kotlinx.android.synthetic.main.mb_activity_scan_document.*
import kotlinx.android.synthetic.main.mb_include_scan_bottom_container.*
import kotlinx.android.synthetic.main.mb_include_splash_overlay.*
import java.lang.Exception
import java.util.*
import kotlin.math.max

Expand Down Expand Up @@ -194,15 +195,14 @@ abstract class BaseDocumentScanActivity : AppCompatActivity(), ScanResultListene
}

override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.MbBlinkIdUiTheme_FullScreen)
ensureCorrectThemeIsSet()

requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
super.onCreate(savedInstanceState)

setupCountryFactory()

if (Build.VERSION.SDK_INT >= 21) {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
setupWindowParams()

setContentView(getLayoutId())
setSupportActionBar(toolbarActivityScan)
Expand Down Expand Up @@ -233,7 +233,7 @@ abstract class BaseDocumentScanActivity : AppCompatActivity(), ScanResultListene

scanSuccessPlayer.prepare()

arrowRight.drawable.mutate().setColorFilter(ContextCompat.getColor(this, R.color.mbIconSelectCountry), PorterDuff.Mode.MULTIPLY)
arrowRight.drawable.mutate().setColorFilter(getThemeColor(R.attr.mbScanIconColorSelectCountry), PorterDuff.Mode.MULTIPLY)

bottomContainer.addOnLayoutChangeListener(object: View.OnLayoutChangeListener {
override fun onLayoutChange(v: View?, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) {
Expand All @@ -252,6 +252,23 @@ abstract class BaseDocumentScanActivity : AppCompatActivity(), ScanResultListene
})
}

private fun ensureCorrectThemeIsSet() {
val testColor = getThemeColor(R.attr.mbScanBgColorCameraOverlay)
if (testColor == 0) {
Log.e(this, "Invalid theme set, defaulting to MbScanTheme")
setTheme(R.style.MbScanTheme)
}
}

private fun setupWindowParams() {
if (Build.VERSION.SDK_INT >= 21) {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
window.statusBarColor = getThemeColor(R.attr.mbScanBgColorStatusBar)
} else if (Build.VERSION.SDK_INT >= 19) {
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
}

private fun updateDocumentTypeSelectionTabs(document: Document) {
if (!documentChooser.shouldShowDocumentTypeTabs()) {
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.microblink.documentscanflow

import android.content.res.Resources
import android.content.Context
import android.support.annotation.AttrRes
import android.support.annotation.ColorInt
import android.support.annotation.LayoutRes
import android.util.TypedValue
import android.view.LayoutInflater
Expand Down Expand Up @@ -106,14 +108,14 @@ private fun buildDetectorRecognizerFromPreset(documentSpecPreset: DocumentSpecif
return detectorRecognizer
}

internal fun Resources.getFloatValue(id : Int) : Float {
val outValue = TypedValue()
getValue(id, outValue, true)
return outValue.float
}
internal fun Calendar.currentDate() = Date(get(Calendar.DAY_OF_MONTH), get(Calendar.MONTH) + 1, get(Calendar.YEAR))

fun View.pxToDp(px: Float): Float {
return px / resources.displayMetrics.density
}

internal fun Calendar.currentDate() = Date(get(Calendar.DAY_OF_MONTH), get(Calendar.MONTH) + 1, get(Calendar.YEAR))
@ColorInt
internal fun Context.getThemeColor(@AttrRes id: Int): Int {
val typedValue = TypedValue()
val a = obtainStyledAttributes(typedValue.data, intArrayOf(id))
val color = a.getColor(0, 0)
a.recycle()
return color
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface Country {
DocumentType.NEW_ID -> R.string.mb_new_id_card
DocumentType.TEMPORARY_RESIDENT_ID -> R.string.mb_temporary_resident_id
DocumentType.PERMANENT_RESIDENT_ID -> R.string.mb_permanent_resident_id
DocumentType.VICTORIA_DL -> R.string.mb_victoria_dl
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class SupportedCountry(override val code: String,
AUSTRALIA("au",
recognitions {
id = UNSUPPORTED
victoriaDl = VictoriaDlRecognition()
}),

AUSTRIA("at",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum class DocumentType {
MILITARY_ID,
NEW_ID,
TEMPORARY_RESIDENT_ID,
PERMANENT_RESIDENT_ID
PERMANENT_RESIDENT_ID,
VICTORIA_DL

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ internal class RecognitionsBuilder {
addRecognition(DocumentType.PERMANENT_RESIDENT_ID, value)
}

var victoriaDl: BaseRecognition? = null
set(value) {
field = value
addRecognition(DocumentType.VICTORIA_DL, value)
}

init {
id = GenericRecognition.id
drivingLicence = GenericRecognition.drivingLicence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class BaseRecognition(val isFullySupported: Boolean = true) {
extractImages()

val result = RecognitionResult(title ?: "",
resultEntries.toList(),
resultEntries.toList().sortedBy { it.key.ordinal },
firstSideDocumentImage,
secondSideDocumentImage,
faceImage,
Expand Down Expand Up @@ -173,6 +173,8 @@ abstract class BaseRecognition(val isFullySupported: Boolean = true) {
}
}

protected fun addDateOfExpiry(dateResult: DateResult) = addDateOfExpiry(dateResult.date)

protected fun addDateOfExpiry(date: Date?) {
if (date != null) {
resultEntries.add(entryBuilder.build(ResultKey.DATE_OF_EXPIRY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.microblink.entities.recognizers.Recognizer
import com.microblink.entities.recognizers.blinkbarcode.pdf417.Pdf417Recognizer
import com.microblink.entities.recognizers.blinkid.documentface.DocumentFaceRecognizer
import com.microblink.entities.recognizers.blinkid.mrtd.MrtdRecognizer
import com.microblink.entities.recognizers.blinkid.passport.PassportRecognizer

class GenericRecognition(isFullySupported: Boolean, private val recognizerProvider: RecognizerProvider) : BaseRecognition(isFullySupported) {

Expand All @@ -26,12 +27,18 @@ class GenericRecognition(isFullySupported: Boolean, private val recognizerProvid
override fun extractData(): String? {
var result: String? = null
for (recognizer in recognizerProvider.recognizers) {
if (recognizer is MrtdRecognizer && recognizer.result.isNotEmpty()) {
extractMrzResult(recognizer.result.mrzResult)
result = buildMrtdTitle(recognizer.result.mrzResult)
}
if (recognizer is Pdf417Recognizer && recognizer.result.isNotEmpty()) {
add(ResultKey.BARCODE_DATA, recognizer.result.stringData)
if (recognizer.result.isNotEmpty()) {
when (recognizer) {
is MrtdRecognizer -> {
extractMrzResult(recognizer.result.mrzResult)
result = buildMrtdTitle(recognizer.result.mrzResult)
}
is PassportRecognizer -> {
extractMrzResult(recognizer.result.mrzResult)
result = buildMrtdTitle(recognizer.result.mrzResult)
}
is Pdf417Recognizer -> add(ResultKey.BARCODE_DATA, recognizer.result.stringData)
}
}
}
return result
Expand All @@ -45,10 +52,16 @@ class GenericRecognition(isFullySupported: Boolean, private val recognizerProvid

val drivingLicence = faceId1(false)

val passport = mrtd(true)
val passport = passport()

val visa = mrtd(true)

private fun passport(): GenericRecognition {
return GenericRecognition(true, object: RecognizerProvider() {
override fun createRecognizers() = listOf(PassportRecognizer())
})
}

fun mrtd(isFullySupported: Boolean): GenericRecognition {
return GenericRecognition(isFullySupported, object: RecognizerProvider() {
override fun createRecognizers() = listOf(MrtdRecognizer())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
package com.microblink.documentscanflow.recognition.implementations

import com.microblink.entities.recognizers.blinkbarcode.usdl.UsdlKeys

class NigeriaDlRecognition: UsdlRecognition() {

override val keysToExcludeFromResults: Set<UsdlKeys>
get() = setOf(UsdlKeys.Height, UsdlKeys.HeightCm, UsdlKeys.HeightIn)

}
class NigeriaDlRecognition: UsdlRecognition()
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
package com.microblink.documentscanflow.recognition.implementations

import android.text.TextUtils
import com.microblink.documentscanflow.isEmpty
import com.microblink.documentscanflow.recognition.resultentry.StringResultEntry
import com.microblink.documentscanflow.recognition.BaseRecognition
import com.microblink.documentscanflow.recognition.resultentry.ResultKey
import com.microblink.documentscanflow.recognition.util.FormattingUtils
import com.microblink.entities.recognizers.Recognizer
import com.microblink.entities.recognizers.blinkbarcode.usdl.UsdlKeys
import com.microblink.entities.recognizers.blinkbarcode.usdl.UsdlRecognizer
import com.microblink.entities.recognizers.blinkid.documentface.DocumentFaceRecognizer
import com.microblink.documentscanflow.recognition.resultentry.ResultKey.*
import com.microblink.entities.recognizers.blinkbarcode.usdl.UsdlKeys

open class UsdlRecognition : BaseRecognition() {

private val recognizer by lazy { UsdlRecognizer() }
private val faceRecognizer by lazy { DocumentFaceRecognizer() }

protected open val keysToExcludeFromResults
get() = setOf<UsdlKeys>()

override fun getSingleSideRecognizers(): List<Recognizer<*, *>> {
return listOf(faceRecognizer, recognizer)
}
Expand All @@ -29,24 +23,21 @@ open class UsdlRecognition : BaseRecognition() {
return null
}

val sb = StringBuilder()
sb.append(result.getField(UsdlKeys.CustomerFirstName))
val middleName = result.getField(UsdlKeys.CustomerMiddleName)
if (!middleName.isEmpty()) {
sb.append(" ").append(middleName)
}
val fullName = FormattingUtils.formatResultTitle(
sb.toString(),
result.getField(UsdlKeys.CustomerFamilyName))

for (key in UsdlKeys.values()) {
val value = result.getField(key)
if (!TextUtils.isEmpty(value) && !keysToExcludeFromResults.contains(key)) {
resultEntries.add(StringResultEntry(ResultKey.fromUsdlKey(key), value))
}
}

return fullName
add(FIRST_NAME, result.firstName)
add(LAST_NAME, result.lastName)
add(FULL_NAME, result.fullName)
add(DATE_OF_BIRTH, result.dateOfBirth)
add(DATE_OF_ISSUE, result.dateOfIssue)
addDateOfExpiry(result.dateOfExpiry.date)
add(DOCUMENT_NUMBER, result.getField(UsdlKeys.CustomerIdNumber))
add(ADDRESS, result.address)
add(SEX, result.sex)
add(VEHICLE_CLASS, result.vehicleClass)
add(ENDORSEMENTS, result.endorsements)
add(DRIVER_RESTRICTIONS, result.restrictions)
add(BARCODE_DATA, result.rawStringData)

return result.fullName
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.microblink.documentscanflow.recognition.implementations

import com.microblink.documentscanflow.isNotEmpty
import com.microblink.documentscanflow.recognition.BaseTwoSideRecognition
import com.microblink.documentscanflow.recognition.ResultValidator
import com.microblink.entities.recognizers.Recognizer
import com.microblink.entities.recognizers.blinkid.australia.AustraliaDlBackRecognizer
import com.microblink.entities.recognizers.blinkid.australia.AustraliaDlFrontRecognizer
import com.microblink.documentscanflow.recognition.resultentry.ResultKey.*

class VictoriaDlRecognition : BaseTwoSideRecognition() {

private val frontRecognizer by lazy { AustraliaDlFrontRecognizer() }
private val backRecognizer by lazy { AustraliaDlBackRecognizer() }

private val frontResult by lazy { frontRecognizer.result }
private val backResult by lazy { backRecognizer.result }

override fun createValidator() = ResultValidator().match(frontResult.licenceExpiry, backResult.licenceExpiry)

override fun extractFields() {
if (frontResult.isNotEmpty()) {
frontResult.apply {
add(ADDRESS, address)
add(DATE_OF_BIRTH, dateOfBirth)
add(FULL_NAME, fullName)
addDateOfExpiry(licenceExpiry)
add(LICENCE_NUMBER, licenceNumber)
add(LICENCE_TYPE, licenceType)
}
}

if (backResult.isNotEmpty()) {
backResult.apply {
add(LAST_NAME, lastName)
add(ADDRESS, address)
add(LICENCE_NUMBER, licenceNumber)
addDateOfExpiry(licenceExpiry)
}
}
}

override fun getResultTitle(): String? {
if (frontResult.isNotEmpty()) {
return frontResult.fullName
}
if (backResult.isNotEmpty()) {
return backResult.lastName
}
return null
}

override fun getSingleSideRecognizers() = listOf<Recognizer<*, *>>(frontRecognizer, backRecognizer)

}
Loading

0 comments on commit 722e70f

Please sign in to comment.