From 8f2fc92945b9fafa3c511d29577e83a65e0dcb63 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Sun, 14 Oct 2018 21:55:00 -0400 Subject: [PATCH] - Now the receive fragment generate the QR code in another thread and don't stop the UI anymore --- .../fragments/ReceiveTransactionFragment.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java index 7967e3c..747d89f 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java @@ -9,6 +9,7 @@ import android.content.ContextWrapper; import android.content.DialogInterface; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.support.annotation.NonNull; @@ -95,6 +96,8 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali private FloatingActionButton fabReceive; + private AsyncTask qrCodeTask; + public static ReceiveTransactionFragment newInstance(long cryptoNetAccountId) { ReceiveTransactionFragment f = new ReceiveTransactionFragment(); @@ -323,12 +326,33 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali this.invoice.setTo(grapheneAccountSelected.getName()); this.invoice.setCurrency(this.cryptoCurrency.getName()); - try { - Bitmap bitmap = textToImageEncode(Invoice.toQrCode(invoice)); - ivQrCode.setImageBitmap(bitmap); - } catch (WriterException e) { - Log.e("ReceiveFragment", "Error creating QrCode"); + if (this.qrCodeTask != null){ + this.qrCodeTask.cancel(true); } + + this.qrCodeTask = new AsyncTask(){ + + @Override + protected Void doInBackground(Object... voids) { + try { + final Bitmap bitmap = textToImageEncode(Invoice.toQrCode(invoice)); + + if (!this.isCancelled()) { + ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + ivQrCode.setImageBitmap(bitmap); + } + }); + } + } catch (WriterException e) { + Log.e("ReceiveFragment", "Error creating QrCode"); + } + return null; + } + }; + + this.qrCodeTask.execute(null,null,null); } Bitmap textToImageEncode(String Value) throws WriterException {