- Now the receive fragment generate the QR code in another thread and don't stop the UI anymore
This commit is contained in:
parent
319321c94b
commit
8f2fc92945
1 changed files with 29 additions and 5 deletions
|
@ -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<Object, Void, Void>(){
|
||||
|
||||
@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 {
|
||||
|
|
Loading…
Reference in a new issue