QrCode: improve UI

This commit is contained in:
Benoit Marty 2020-01-28 12:05:06 +01:00
parent 69ab5e43d5
commit 20c7e4c3ad
5 changed files with 27 additions and 26 deletions

View File

@ -34,8 +34,6 @@ fun String.toBitMatrix(size: Int): BitMatrix {
fun BitMatrix.toBitmap(@ColorInt backgroundColor: Int = Color.WHITE,
@ColorInt foregroundColor: Int = Color.BLACK): Bitmap {
val height: Int = height
val width: Int = width
val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
for (x in 0 until width) {
for (y in 0 until height) {

View File

@ -17,6 +17,7 @@
package im.vector.riotx.core.ui.views
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.AnimationDrawable
import android.graphics.drawable.BitmapDrawable
import android.util.AttributeSet
@ -32,6 +33,10 @@ class QrCodeImageView @JvmOverloads constructor(
private var data: String? = null
private var animate = false
init {
setBackgroundColor(Color.WHITE)
}
fun setData(data: String, animate: Boolean) {
this.data = data
this.animate = animate
@ -46,24 +51,24 @@ class QrCodeImageView @JvmOverloads constructor(
private fun render() {
data
?.takeIf { width > 0 }
?.takeIf { height > 0 }
?.let {
if (animate) {
// NOT SUPPORTED YET val anim = createAnimation(it)
// NOT SUPPORTED YET setImageDrawable(anim)
// NOT SUPPORTED YET anim.start()
// NOT SUPPORTED YET setImageDrawable(BitmapDrawable(resources, it.toBitMatrix(width).toBitmap()))
val bitmap = it.toBitMatrix(width).toBitmap()
// NOT SUPPORTED YET setImageDrawable(BitmapDrawable(resources, it.toBitMatrix(height).toBitmap()))
val bitmap = it.toBitMatrix(height).toBitmap()
post { setImageBitmap(bitmap) }
} else {
val bitmap = it.toBitMatrix(width).toBitmap()
val bitmap = it.toBitMatrix(height).toBitmap()
post { setImageBitmap(bitmap) }
}
}
}
private fun createAnimation(data: String): AnimationDrawable {
val finalQr = data.toBitMatrix(width)
val finalQr = data.toBitMatrix(height)
val list = mutableListOf(finalQr)

View File

@ -16,7 +16,6 @@
*/
package im.vector.riotx.features.crypto.verification.epoxy
import androidx.core.view.ViewCompat
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.riotx.R
@ -25,7 +24,7 @@ import im.vector.riotx.core.epoxy.VectorEpoxyModel
import im.vector.riotx.core.ui.views.QrCodeImageView
/**
* A action for bottom sheet.
* An Epoxy item displaying a QR code
*/
@EpoxyModelClass(layout = R.layout.item_verification_qr_code)
abstract class BottomSheetVerificationQrCodeItem : VectorEpoxyModel<BottomSheetVerificationQrCodeItem.Holder>() {
@ -36,21 +35,11 @@ abstract class BottomSheetVerificationQrCodeItem : VectorEpoxyModel<BottomSheetV
@EpoxyAttribute
var animate = false
@EpoxyAttribute
var contentDescription: String? = null
override fun bind(holder: Holder) {
holder.qsrCodeImage.setData(data, animate)
if (contentDescription == null) {
ViewCompat.setImportantForAccessibility(holder.qsrCodeImage, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO)
} else {
ViewCompat.setImportantForAccessibility(holder.qsrCodeImage, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES)
holder.qsrCodeImage.contentDescription = contentDescription
}
}
class Holder : VectorEpoxyHolder() {
val qsrCodeImage by bind<QrCodeImageView>(R.id.itemVerificationBigImage)
val qsrCodeImage by bind<QrCodeImageView>(R.id.itemVerificationQrCodeImage)
}
}

View File

@ -1,8 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<im.vector.riotx.core.ui.views.QrCodeImageView xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/itemVerificationBigImage"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_margin="8dp"
tools:src="@drawable/ic_shield_trusted" />
android:layout_height="wrap_content"
android:layout_margin="8dp">
<im.vector.riotx.core.ui.views.QrCodeImageView
android:id="@+id/itemVerificationQrCodeImage"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/a11y_qr_code_for_verification"
tools:src="@color/riotx_header_panel_background_black" />
</FrameLayout>

View File

@ -100,7 +100,6 @@
<string name="room_settings_enable_encryption_dialog_content">Once enabled, encryption for a room cannot be disabled. Messages sent in an encrypted room cannot be seen by the server, only by the participants of the room. Enabling encryption may prevent many bots and bridges from working correctly.</string>
<string name="room_settings_enable_encryption_dialog_submit">Enable encryption</string>
<string name="verification_request_notice">For extra security, verify %s by checking a one-time code.</string>
<string name="verification_request_start_notice">For maximum security, do this in person.</string>
@ -146,4 +145,6 @@
<string name="initialize_cross_signing">Initialize CrossSigning</string>
<string name="reset_cross_signing">Reset Keys</string>
<string name="a11y_qr_code_for_verification">QR code</string>
</resources>