From ed21712f6810ffbca0c2c1df5404214f5111d2ec Mon Sep 17 00:00:00 2001 From: Henry Varona Date: Fri, 21 Sep 2018 16:11:18 -0400 Subject: [PATCH] Change version Added auto start camera on send fragment --- app/build.gradle | 2 +- .../fragments/SendTransactionFragment.java | 83 ++++++++++++++----- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f20eac1..29eb088 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,7 +16,7 @@ android { minSdkVersion 21 targetSdkVersion 27 versionCode 2 - versionName "0.2t.alpha" + versionName "0.2M.alpha" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary true 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 c145e27..65d5742 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -1,5 +1,7 @@ package cy.agorise.crystalwallet.fragments; +import android.Manifest; +import android.app.Activity; import android.app.Dialog; import android.arch.lifecycle.LiveData; import android.arch.lifecycle.Observer; @@ -8,6 +10,7 @@ import android.content.Context; import android.content.ContextWrapper; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; @@ -15,6 +18,7 @@ import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; +import android.support.v4.app.ActivityCompat; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; @@ -106,6 +110,12 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat TextView btnCancel; @BindView(R.id.ivPeople) ImageView ivPeople; + + @BindView(R.id.ivCamera) + ImageView ivCamera; + + ZXingScannerView mScannerView; + CryptoCurrencyAdapter assetAdapter; @BindView(R.id.gravatar) @@ -120,6 +130,8 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat private FloatingActionButton fabSend; private AlertDialog.Builder builder; + + public static SendTransactionFragment newInstance(long cryptoNetAccountId) { SendTransactionFragment f = new SendTransactionFragment(); @@ -260,18 +272,25 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat } loadUserImage(); + try { + verifyCameraPermissions(getActivity()); + beginScanQrCode(); + }catch(Exception e){ + e.printStackTrace(); + } + return builder.setView(view).create(); } @Override public void onResume() { super.onResume(); - builder.setNeutralButton("Scan QR Code", new DialogInterface.OnClickListener() { + /*builder.setNeutralButton("Scan QR Code", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { beginScanQrCode(); } - }); + });*/ // Force dialog fragment to use the full width of the screen Window dialogWindow = getDialog().getWindow(); @@ -290,6 +309,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat fabSend.show(); } }, 400); + mScannerView.stopCamera(); } public void loadUserImage(){ @@ -430,11 +450,32 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat } public void beginScanQrCode(){ - ZXingScannerView mScannerView = new ZXingScannerView(getContext()); + mScannerView = new ZXingScannerView(getContext()); mScannerView.setResultHandler(this); mScannerView.startCamera(); } + // Camera Permissions + private static final int REQUEST_CAMERA_PERMISSION = 1; + private static String[] PERMISSIONS_CAMERA = { + Manifest.permission.CAMERA + }; + + + public static void verifyCameraPermissions(Activity activity) { + // Check if we have write permission + int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA); + + if (permission != PackageManager.PERMISSION_GRANTED) { + // We don't have permission so prompt the user + ActivityCompat.requestPermissions( + activity, + PERMISSIONS_CAMERA, + REQUEST_CAMERA_PERMISSION + ); + } + } + @Override public void onValidationSucceeded(final ValidationField field) { final SendTransactionFragment fragment = this; @@ -487,27 +528,31 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat @Override public void handleResult(Result result) { - Invoice invoice = Invoice.fromQrCode(result.getText()); + try { + Invoice invoice = Invoice.fromQrCode(result.getText()); - etTo.setText(invoice.getTo()); + etTo.setText(invoice.getTo()); - for (int i=0;i