From b514290692936f79a203a1687932e26ea9491b88 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Thu, 30 Nov 2017 21:48:01 -0400 Subject: [PATCH] - Activating QR Code scanner in the send fragment --- app/build.gradle | 1 + .../fragments/SendTransactionFragment.java | 27 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ce4faeb..520e84f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -50,6 +50,7 @@ dependencies { compile 'com.jakewharton:butterknife:8.8.1' compile 'com.github.bilthon:graphenej:0.4.6-alpha1' compile 'com.google.zxing:core:3.3.1'; + compile 'me.dm7.barcodescanner:zxing:1.9.8'; testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java index ee00954..1525114 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -12,6 +12,7 @@ import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.text.Editable; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,6 +21,8 @@ import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; +import com.google.zxing.Result; + import java.util.ArrayList; import java.util.List; @@ -39,8 +42,9 @@ import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter; +import me.dm7.barcodescanner.zxing.ZXingScannerView; -public class SendTransactionFragment extends DialogFragment implements UIValidatorListener { +public class SendTransactionFragment extends DialogFragment implements UIValidatorListener, ZXingScannerView.ResultHandler { SendTransactionValidator sendTransactionValidator; @@ -69,6 +73,8 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat //@BindView(R.id.btnCancel) Button btnCancel; + Button btnScanQrCode; + private long cryptoNetAccountId; private CryptoNetAccount cryptoNetAccount; private GrapheneAccount grapheneAccount; @@ -147,6 +153,12 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat dialog.dismiss(); } }); + builder.setNeutralButton("Scan QR Code", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + beginScanQrCode(); + } + }); AlertDialog dialog = builder.create(); @@ -155,7 +167,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat public void onShow(DialogInterface dialog) { btnSend = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE); btnCancel = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEGATIVE); - + btnScanQrCode = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEUTRAL); btnSend.setEnabled(false); } }); @@ -254,6 +266,12 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat } } + public void beginScanQrCode(){ + ZXingScannerView mScannerView = new ZXingScannerView(getContext()); + mScannerView.setResultHandler(this); + mScannerView.startCamera(); + } + @Override public void onValidationSucceeded(final ValidationField field) { final SendTransactionFragment fragment = this; @@ -294,4 +312,9 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat tvMemoError.setText(field.getMessage()); } } + + @Override + public void handleResult(Result result) { + Log.i("SendFragment",result.getText()); + } }