Fix QR code UI issue

This commit is contained in:
Niels Andriesse 2019-09-10 16:12:16 +10:00
parent 0948156ddf
commit f209784648
2 changed files with 11 additions and 2 deletions

View File

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

View File

@ -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++) {