From 80f91f822ed41870fd82ed0de6b8cabfbc1e2462 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 17 Feb 2022 10:53:16 +0100 Subject: [PATCH] Display QrCode on main activity --- .idea/misc.xml | 2 +- .../dccaggregator/activities/MainActivity.kt | 32 ++++++++++- app/src/main/res/layout/activity_main.xml | 57 ++++++++++++++++--- app/src/main/res/values/dimens.xml | 1 + 4 files changed, 83 insertions(+), 9 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d737463..ddef8b0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + diff --git a/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt b/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt index 94b4aca..75af45c 100644 --- a/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt +++ b/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt @@ -5,13 +5,25 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AppCompatDelegate +import com.google.zxing.BarcodeFormat +import com.journeyapps.barcodescanner.BarcodeEncoder import org.communiquons.dccaggregator.R +import org.communiquons.dccaggregator.databinding.ActivityMainBinding +import org.communiquons.dccaggregator.ext.toDimensSize class MainActivity : BaseActivity() { + private lateinit var binding: ActivityMainBinding + + private val qrSize by lazy { + R.dimen.qr_code_fullscreen_size.toDimensSize(this).toInt() + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setTheme(R.style.Theme_DCCAggregator) - setContentView(R.layout.activity_main) + + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) @@ -20,6 +32,12 @@ class MainActivity : BaseActivity() { openCertsManager() } + override fun onResume() { + super.onResume() + + refreshInfo() + } + override fun onCreateOptionsMenu(menu: Menu?): Boolean { menuInflater.inflate(R.menu.main_activity_top_menu, menu) return super.onCreateOptionsMenu(menu) @@ -37,4 +55,16 @@ class MainActivity : BaseActivity() { fun openCertsManager() { startActivity(Intent(this, CertsManager::class.java)) } + + fun refreshInfo() { + certsManager.aggregatedCertificate?.apply { + binding.fullName.text = fullName.uppercase() + binding.dateOfBirth.text = dateOfBirth + + val bitmap = + BarcodeEncoder().encodeBitmap(encoded, BarcodeFormat.QR_CODE, qrSize, qrSize) + binding.qrCode.setImageBitmap(bitmap) + } + + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index fd8eba3..83235d9 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,13 +6,56 @@ android:layout_height="match_parent" tools:context=".activities.MainActivity"> - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 5865630..6b48800 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -2,4 +2,5 @@ 200dp 110dp + 240dp \ No newline at end of file