Don't invert QR codes

This commit is contained in:
Niels Andriesse 2020-01-17 14:24:33 +11:00
parent 5c8bbc161b
commit 6fccd873db
4 changed files with 7 additions and 7 deletions

View File

@ -16,10 +16,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:weightSum="2" > android:weightSum="3" >
<org.thoughtcrime.securesms.components.ShapeScrim <org.thoughtcrime.securesms.components.ShapeScrim
android:layout_weight="1" android:layout_weight="2"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp"/> android:layout_height="0dp"/>

View File

@ -122,7 +122,7 @@ class ViewMyQRCodeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val size = toPx(280, resources) val size = toPx(280, resources)
val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size) val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size, false, false)
qrCodeImageView.setImageBitmap(qrCode) qrCodeImageView.setImageBitmap(qrCode)
val explanation = SpannableStringBuilder("This is your unique public QR code. Other users can scan this to start a conversation with you.") val explanation = SpannableStringBuilder("This is your unique public QR code. Other users can scan this to start a conversation with you.")
explanation.setSpan(StyleSpan(Typeface.BOLD), 8, 34, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) explanation.setSpan(StyleSpan(Typeface.BOLD), 8, 34, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

View File

@ -33,7 +33,7 @@ class LinkDeviceMasterModeDialog : DialogFragment(), DeviceLinkingSessionListene
contentView = LayoutInflater.from(context!!).inflate(R.layout.dialog_link_device_master_mode, null) contentView = LayoutInflater.from(context!!).inflate(R.layout.dialog_link_device_master_mode, null)
val size = toPx(128, resources) val size = toPx(128, resources)
val hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context!!) val hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context!!)
val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size) val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size, false, false)
contentView.qrCodeImageView.setImageBitmap(qrCode) contentView.qrCodeImageView.setImageBitmap(qrCode)
contentView.cancelButton.setOnClickListener { onDeviceLinkCanceled() } contentView.cancelButton.setOnClickListener { onDeviceLinkCanceled() }
contentView.authorizeButton.setOnClickListener { authorizeDeviceLink() } contentView.authorizeButton.setOnClickListener { authorizeDeviceLink() }

View File

@ -9,7 +9,7 @@ import com.google.zxing.qrcode.QRCodeWriter
object QRCodeUtilities { object QRCodeUtilities {
fun encode(data: String, size: Int, hasTransparentBackground: Boolean = true): Bitmap { fun encode(data: String, size: Int, isInverted: Boolean = false, hasTransparentBackground: Boolean = true): Bitmap {
try { try {
val hints = hashMapOf( EncodeHintType.MARGIN to 1 ) val hints = hashMapOf( EncodeHintType.MARGIN to 1 )
val result = QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, size, size, hints) val result = QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, size, size, hints)
@ -17,9 +17,9 @@ object QRCodeUtilities {
for (y in 0 until result.height) { for (y in 0 until result.height) {
for (x in 0 until result.width) { for (x in 0 until result.width) {
if (result.get(x, y)) { if (result.get(x, y)) {
bitmap.setPixel(x, y, Color.WHITE) bitmap.setPixel(x, y, if (isInverted) Color.WHITE else Color.BLACK)
} else if (!hasTransparentBackground) { } else if (!hasTransparentBackground) {
bitmap.setPixel(x, y, Color.BLACK) bitmap.setPixel(x, y, if (isInverted) Color.BLACK else Color.WHITE)
} }
} }
} }