- Activating QR Code scanner in the send fragment

This commit is contained in:
Javier Varona 2017-11-30 21:48:01 -04:00
parent a541a70c1a
commit b514290692
2 changed files with 26 additions and 2 deletions

View file

@ -50,6 +50,7 @@ dependencies {
compile 'com.jakewharton:butterknife:8.8.1' compile 'com.jakewharton:butterknife:8.8.1'
compile 'com.github.bilthon:graphenej:0.4.6-alpha1' compile 'com.github.bilthon:graphenej:0.4.6-alpha1'
compile 'com.google.zxing:core:3.3.1'; compile 'com.google.zxing:core:3.3.1';
compile 'me.dm7.barcodescanner:zxing:1.9.8';
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19' testCompile 'org.mockito:mockito-core:1.10.19'

View file

@ -12,6 +12,7 @@ import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Editable; import android.text.Editable;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -20,6 +21,8 @@ import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import com.google.zxing.Result;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.UIValidatorListener;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField;
import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter; 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; SendTransactionValidator sendTransactionValidator;
@ -69,6 +73,8 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
//@BindView(R.id.btnCancel) //@BindView(R.id.btnCancel)
Button btnCancel; Button btnCancel;
Button btnScanQrCode;
private long cryptoNetAccountId; private long cryptoNetAccountId;
private CryptoNetAccount cryptoNetAccount; private CryptoNetAccount cryptoNetAccount;
private GrapheneAccount grapheneAccount; private GrapheneAccount grapheneAccount;
@ -147,6 +153,12 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
dialog.dismiss(); dialog.dismiss();
} }
}); });
builder.setNeutralButton("Scan QR Code", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
beginScanQrCode();
}
});
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
@ -155,7 +167,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
public void onShow(DialogInterface dialog) { public void onShow(DialogInterface dialog) {
btnSend = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE); btnSend = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE);
btnCancel = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEGATIVE); btnCancel = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
btnScanQrCode = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEUTRAL);
btnSend.setEnabled(false); 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 @Override
public void onValidationSucceeded(final ValidationField field) { public void onValidationSucceeded(final ValidationField field) {
final SendTransactionFragment fragment = this; final SendTransactionFragment fragment = this;
@ -294,4 +312,9 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
tvMemoError.setText(field.getMessage()); tvMemoError.setText(field.getMessage());
} }
} }
@Override
public void handleResult(Result result) {
Log.i("SendFragment",result.getText());
}
} }