Display QrCode on main activity

This commit is contained in:
Pierre HUBERT 2022-02-17 10:53:16 +01:00
parent 01e0cb96aa
commit 80f91f822e
4 changed files with 83 additions and 9 deletions

View File

@ -8,7 +8,7 @@
<entry key="app/src/main/res/drawable/ic_launcher_foreground.xml" value="0.2234375" />
<entry key="app/src/main/res/drawable/splashscreen.xml" value="0.3859375" />
<entry key="app/src/main/res/layout/activity_certs_manager.xml" value="0.29483695652173914" />
<entry key="app/src/main/res/layout/activity_main.xml" value="0.20729166666666668" />
<entry key="app/src/main/res/layout/activity_main.xml" value="0.33" />
<entry key="app/src/main/res/layout/content_certs.xml" value="0.29483695652173914" />
<entry key="app/src/main/res/layout/fragment_first.xml" value="0.29483695652173914" />
<entry key="app/src/main/res/layout/fragment_second.xml" value="0.29483695652173914" />

View File

@ -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)
}
}
}

View File

@ -6,13 +6,56 @@
android:layout_height="match_parent"
tools:context=".activities.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/qr_code"
android:layout_width="@dimen/qr_code_fullscreen_size"
android:layout_height="@dimen/qr_code_fullscreen_size"
android:contentDescription="@string/certificate_qr_code"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_qr" />
<TextView
android:id="@+id/fullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/qr_code"
tools:text="John Doe" />
<TextView
android:id="@+id/date_of_birth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fullName"
tools:text="01/01/1995" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,4 +2,5 @@
<resources>
<dimen name="qr_code_widget_dcc_size">200dp</dimen>
<dimen name="qr_code_widget_size">110dp</dimen>
<dimen name="qr_code_fullscreen_size">240dp</dimen>
</resources>