Add QrCode scanner

This commit is contained in:
Pierre HUBERT 2022-02-15 20:04:54 +01:00
parent fbca24f147
commit d2847107b4
4 changed files with 34 additions and 4 deletions

View File

@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId "org.communiquons.dccaggregator"
minSdk 21
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
@ -41,6 +41,7 @@ dependencies {
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.preference:preference:1.2.0'
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

View File

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.communiquons.dccaggregator">
<application
android:name=".DCCAggregator"
android:allowBackup="false"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
@ -27,8 +29,14 @@
<!-- Manage certificates -->
<activity
android:name=".activities.CertsManager"
android:label="@string/activity_certsmanagers"
android:exported="false" />
android:exported="false"
android:label="@string/activity_certsmanagers" />
<!-- Fix Qr scanner orientation -->
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
</application>
</manifest>

View File

@ -4,12 +4,17 @@ import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
import org.communiquons.dccaggregator.R
import org.communiquons.dccaggregator.databinding.ActivityCertsManagerBinding
class CertsManager : AppCompatActivity() {
private lateinit var binding: ActivityCertsManagerBinding
private val TAG = CertsManager::class.java.canonicalName
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCertsManagerBinding.inflate(layoutInflater)
@ -18,7 +23,7 @@ class CertsManager : AppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
binding.scanCertButton.setOnClickListener {
Log.d("d", "FAb clicked!")
addNewCertificate()
}
}
@ -30,4 +35,19 @@ class CertsManager : AppCompatActivity() {
return super.onOptionsItemSelected(item)
}
private val barcodeLauncher = registerForActivityResult(ScanContract()) {
if (it.contents == null)
return@registerForActivityResult
Log.v(TAG, it.contents)
}
private fun addNewCertificate() {
barcodeLauncher.launch(ScanOptions().apply {
setOrientationLocked(true)
setDesiredBarcodeFormats(ScanOptions.QR_CODE)
setPrompt(resources.getString(R.string.scan_qr_prompt))
})
}
}

View File

@ -2,4 +2,5 @@
<string name="app_name">DCCAggregator</string>
<string name="activity_certsmanagers">Input certificates</string>
<string name="add_certificate">Add a new certificate</string>
<string name="scan_qr_prompt">Please present the QrCode of the certificate you want to add</string>
</resources>