From f209784648a60a8d082f5da99b35cb6c5f71de2d Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 10 Sep 2019 16:12:16 +1000 Subject: [PATCH] Fix QR code UI issue --- src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt | 7 ++++++- src/org/thoughtcrime/securesms/qr/QrCode.java | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt b/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt index ae3b36f3c7..3e15a97059 100644 --- a/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt +++ b/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt @@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.loki import android.os.Bundle import android.support.v4.app.Fragment +import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -9,6 +10,7 @@ import kotlinx.android.synthetic.main.fragment_qr_code.* import network.loki.messenger.R import org.thoughtcrime.securesms.ApplicationPreferencesActivity import org.thoughtcrime.securesms.qr.QrCode +import org.thoughtcrime.securesms.util.ServiceUtil.getWindowManager import org.thoughtcrime.securesms.util.TextSecurePreferences class QRCodeFragment : Fragment() { @@ -20,7 +22,10 @@ class QRCodeFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context) - val qrCode = QrCode.create(hexEncodedPublicKey) + val displayMetrics = DisplayMetrics() + getWindowManager(context).defaultDisplay.getMetrics(displayMetrics) + val size = displayMetrics.widthPixels - 2 * toPx(32, resources) + val qrCode = QrCode.create(hexEncodedPublicKey, size) qrCodeImageView.setImageBitmap(qrCode) } diff --git a/src/org/thoughtcrime/securesms/qr/QrCode.java b/src/org/thoughtcrime/securesms/qr/QrCode.java index 0917ec105d..f561daa2d2 100644 --- a/src/org/thoughtcrime/securesms/qr/QrCode.java +++ b/src/org/thoughtcrime/securesms/qr/QrCode.java @@ -16,8 +16,12 @@ public class QrCode { public static final String TAG = QrCode.class.getSimpleName(); public static @NonNull Bitmap create(String data) { + return create(data, 1024); + } + + public static @NonNull Bitmap create(String data, int size) { try { - BitMatrix result = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, 1024, 1024); + BitMatrix result = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, size, size); Bitmap bitmap = Bitmap.createBitmap(result.getWidth(), result.getHeight(), Bitmap.Config.ARGB_8888); for (int y = 0; y < result.getHeight(); y++) {