Change version

Added auto start camera on send fragment
This commit is contained in:
Henry Varona 2018-09-21 16:11:18 -04:00
parent 5356331a25
commit ed21712f68
2 changed files with 65 additions and 20 deletions

View file

@ -16,7 +16,7 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 27 targetSdkVersion 27
versionCode 2 versionCode 2
versionName "0.2t.alpha" versionName "0.2M.alpha"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables { vectorDrawables {
useSupportLibrary true useSupportLibrary true

View file

@ -1,5 +1,7 @@
package cy.agorise.crystalwallet.fragments; package cy.agorise.crystalwallet.fragments;
import android.Manifest;
import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.arch.lifecycle.LiveData; import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer; import android.arch.lifecycle.Observer;
@ -8,6 +10,7 @@ import android.content.Context;
import android.content.ContextWrapper; import android.content.ContextWrapper;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
@ -15,6 +18,7 @@ import android.os.Handler;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
@ -106,6 +110,12 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
TextView btnCancel; TextView btnCancel;
@BindView(R.id.ivPeople) @BindView(R.id.ivPeople)
ImageView ivPeople; ImageView ivPeople;
@BindView(R.id.ivCamera)
ImageView ivCamera;
ZXingScannerView mScannerView;
CryptoCurrencyAdapter assetAdapter; CryptoCurrencyAdapter assetAdapter;
@BindView(R.id.gravatar) @BindView(R.id.gravatar)
@ -120,6 +130,8 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
private FloatingActionButton fabSend; private FloatingActionButton fabSend;
private AlertDialog.Builder builder; private AlertDialog.Builder builder;
public static SendTransactionFragment newInstance(long cryptoNetAccountId) { public static SendTransactionFragment newInstance(long cryptoNetAccountId) {
SendTransactionFragment f = new SendTransactionFragment(); SendTransactionFragment f = new SendTransactionFragment();
@ -260,18 +272,25 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
} }
loadUserImage(); loadUserImage();
try {
verifyCameraPermissions(getActivity());
beginScanQrCode();
}catch(Exception e){
e.printStackTrace();
}
return builder.setView(view).create(); return builder.setView(view).create();
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
builder.setNeutralButton("Scan QR Code", new DialogInterface.OnClickListener() { /*builder.setNeutralButton("Scan QR Code", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
beginScanQrCode(); beginScanQrCode();
} }
}); });*/
// Force dialog fragment to use the full width of the screen // Force dialog fragment to use the full width of the screen
Window dialogWindow = getDialog().getWindow(); Window dialogWindow = getDialog().getWindow();
@ -290,6 +309,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
fabSend.show(); fabSend.show();
} }
}, 400); }, 400);
mScannerView.stopCamera();
} }
public void loadUserImage(){ public void loadUserImage(){
@ -430,11 +450,32 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
} }
public void beginScanQrCode(){ public void beginScanQrCode(){
ZXingScannerView mScannerView = new ZXingScannerView(getContext()); mScannerView = new ZXingScannerView(getContext());
mScannerView.setResultHandler(this); mScannerView.setResultHandler(this);
mScannerView.startCamera(); 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 @Override
public void onValidationSucceeded(final ValidationField field) { public void onValidationSucceeded(final ValidationField field) {
final SendTransactionFragment fragment = this; final SendTransactionFragment fragment = this;
@ -487,11 +528,12 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
@Override @Override
public void handleResult(Result result) { public void handleResult(Result result) {
try {
Invoice invoice = Invoice.fromQrCode(result.getText()); Invoice invoice = Invoice.fromQrCode(result.getText());
etTo.setText(invoice.getTo()); etTo.setText(invoice.getTo());
for (int i=0;i<assetAdapter.getCount();i++) { for (int i = 0; i < assetAdapter.getCount(); i++) {
if (assetAdapter.getItem(i).getName().equals(invoice.getCurrency())) { if (assetAdapter.getItem(i).getName().equals(invoice.getCurrency())) {
spAsset.setSelection(i); spAsset.setSelection(i);
break; break;
@ -508,6 +550,9 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
df.setRoundingMode(RoundingMode.CEILING); df.setRoundingMode(RoundingMode.CEILING);
df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH)); df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
etAmount.setText(df.format(amount)); etAmount.setText(df.format(amount));
Log.i("SendFragment",result.getText()); Log.i("SendFragment", result.getText());
}catch(Exception e){
e.printStackTrace();
}
} }
} }