Merge branch 'develop' of https://github.com/Agorise/crystal-wallet-android into develop-local
This commit is contained in:
commit
5b8d12f886
4 changed files with 142 additions and 111 deletions
|
@ -87,6 +87,7 @@ dependencies {
|
||||||
implementation 'com.jakewharton:butterknife:8.8.1'
|
implementation 'com.jakewharton:butterknife:8.8.1'
|
||||||
implementation 'com.github.bilthon:graphenej:0.4.6'
|
implementation 'com.github.bilthon:graphenej:0.4.6'
|
||||||
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
|
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
|
||||||
|
|
||||||
implementation 'com.github.sjaramillo10:AnimatedTabLayout:1.0.3'
|
implementation 'com.github.sjaramillo10:AnimatedTabLayout:1.0.3'
|
||||||
|
|
||||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.5.0'
|
implementation 'com.squareup.okhttp3:logging-interceptor:3.5.0'
|
||||||
|
@ -125,4 +126,7 @@ dependencies {
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
|
||||||
|
|
||||||
debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
|
debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
|
||||||
|
|
||||||
|
implementation 'com.google.zxing:core:3.2.1'
|
||||||
|
implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -35,6 +36,7 @@ import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.MultiFormatWriter;
|
import com.google.zxing.MultiFormatWriter;
|
||||||
import com.google.zxing.WriterException;
|
import com.google.zxing.WriterException;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
import com.journeyapps.barcodescanner.BarcodeEncoder;
|
||||||
|
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
||||||
|
@ -84,6 +86,8 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
|
||||||
TextView tvAssetError;
|
TextView tvAssetError;
|
||||||
@BindView(R.id.ivQrCode)
|
@BindView(R.id.ivQrCode)
|
||||||
ImageView ivQrCode;
|
ImageView ivQrCode;
|
||||||
|
@BindView(R.id.pbQrCode)
|
||||||
|
ProgressBar pbQrCode;
|
||||||
@BindView(R.id.tvCancel)
|
@BindView(R.id.tvCancel)
|
||||||
TextView tvCancel;
|
TextView tvCancel;
|
||||||
|
|
||||||
|
@ -106,6 +110,8 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
|
||||||
|
|
||||||
private AsyncTask qrCodeTask;
|
private AsyncTask qrCodeTask;
|
||||||
|
|
||||||
|
private Double lastAmount = -1.0;
|
||||||
|
|
||||||
public static ReceiveTransactionFragment newInstance(long cryptoNetAccountId) {
|
public static ReceiveTransactionFragment newInstance(long cryptoNetAccountId) {
|
||||||
ReceiveTransactionFragment f = new ReceiveTransactionFragment();
|
ReceiveTransactionFragment f = new ReceiveTransactionFragment();
|
||||||
|
|
||||||
|
@ -337,144 +343,147 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createQrCode(){
|
public void createQrCode(){
|
||||||
Double amount = 0.0;
|
final Double amount;
|
||||||
try{
|
try{
|
||||||
amount = Double.valueOf(this.etAmount.getText().toString());
|
amount = Double.valueOf(this.etAmount.getText().toString());
|
||||||
|
|
||||||
} catch(NumberFormatException e){
|
} catch(NumberFormatException e){
|
||||||
|
lastAmount = -1.0;
|
||||||
Log.e("ReceiveFragment","Amount casting error.");
|
Log.e("ReceiveFragment","Amount casting error.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CryptoNetAccount toAccountSelected = (CryptoNetAccount) spTo.getSelectedItem();
|
if (!amount.equals(lastAmount)) {
|
||||||
|
pbQrCode.setVisibility(View.VISIBLE);
|
||||||
if (this.cryptoNetAccount.getCryptoNet() == CryptoNet.BITSHARES) {
|
lastAmount = amount;
|
||||||
/*
|
CryptoNetAccount toAccountSelected = (CryptoNetAccount) spTo.getSelectedItem();
|
||||||
* this is only for graphene accounts.
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
GrapheneAccount grapheneAccountSelected = new GrapheneAccount(toAccountSelected);
|
|
||||||
grapheneAccountSelected.loadInfo(db.grapheneAccountInfoDao().getByAccountId(toAccountSelected.getId()));
|
|
||||||
|
|
||||||
|
|
||||||
this.invoiceItems.clear();
|
|
||||||
this.invoiceItems.add(
|
|
||||||
new LineItem("transfer", 1, amount)
|
|
||||||
);
|
|
||||||
|
|
||||||
LineItem items[] = new LineItem[this.invoiceItems.size()];
|
|
||||||
items = this.invoiceItems.toArray(items);
|
|
||||||
this.invoice.setLineItems(items);
|
|
||||||
this.invoice.setTo(grapheneAccountSelected.getName());
|
|
||||||
this.invoice.setCurrency(this.cryptoCurrency.getName());
|
|
||||||
|
|
||||||
if (this.qrCodeTask != null) {
|
if (this.qrCodeTask != null) {
|
||||||
this.qrCodeTask.cancel(true);
|
this.qrCodeTask.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.qrCodeTask = new AsyncTask<Object, Void, Void>() {
|
if (this.cryptoNetAccount.getCryptoNet() == CryptoNet.BITSHARES) {
|
||||||
|
/*
|
||||||
|
* this is only for graphene accounts.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
GrapheneAccount grapheneAccountSelected = new GrapheneAccount(toAccountSelected);
|
||||||
|
grapheneAccountSelected.loadInfo(db.grapheneAccountInfoDao().getByAccountId(toAccountSelected.getId()));
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Object... voids) {
|
|
||||||
try {
|
|
||||||
final Bitmap bitmap = textToImageEncode(Invoice.toQrCode(invoice));
|
|
||||||
|
|
||||||
if (!this.isCancelled()) {
|
this.invoiceItems.clear();
|
||||||
ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() {
|
this.invoiceItems.add(
|
||||||
@Override
|
new LineItem("transfer", 1, amount)
|
||||||
public void run() {
|
);
|
||||||
ivQrCode.setImageBitmap(bitmap);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (WriterException e) {
|
|
||||||
Log.e("ReceiveFragment", "Error creating QrCode");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.qrCodeTask.execute(null, null, null);
|
LineItem items[] = new LineItem[this.invoiceItems.size()];
|
||||||
} else {
|
items = this.invoiceItems.toArray(items);
|
||||||
final CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0);
|
this.invoice.setLineItems(items);
|
||||||
|
this.invoice.setTo(grapheneAccountSelected.getName());
|
||||||
|
this.invoice.setCurrency(this.cryptoCurrency.getName());
|
||||||
|
|
||||||
//final NextBitcoinAccountAddressRequest addressRequest = new NextBitcoinAccountAddressRequest(this.cryptoNetAccount, cryptoCoin, getContext());
|
//if (this.qrCodeTask != null) {
|
||||||
|
// this.qrCodeTask.cancel(true);
|
||||||
|
//}
|
||||||
|
|
||||||
//addressRequest.setListener(new CryptoNetInfoRequestListener() {
|
this.qrCodeTask = new AsyncTask<Object, Void, Void>() {
|
||||||
// @Override
|
|
||||||
// public void onCarryOut() {
|
|
||||||
// if (addressRequest.getStatus() == NextBitcoinAccountAddressRequest.StatusCode.SUCCEEDED){
|
|
||||||
final CalculateBitcoinUriRequest uriRequest = new CalculateBitcoinUriRequest(cryptoCoin, cryptoNetAccount, getContext(), amount);
|
|
||||||
|
|
||||||
uriRequest.setListener(new CryptoNetInfoRequestListener(){
|
@Override
|
||||||
@Override
|
protected Void doInBackground(Object... voids) {
|
||||||
public void onCarryOut(){
|
try {
|
||||||
if (uriRequest.getUri() != null){
|
final Bitmap bitmap = textToImageEncode(Invoice.toQrCode(invoice));
|
||||||
qrCodeTask = new AsyncTask<Object, Void, Void>() {
|
|
||||||
|
|
||||||
@Override
|
if (!this.isCancelled()) {
|
||||||
protected Void doInBackground(Object... voids) {
|
ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() {
|
||||||
try {
|
@Override
|
||||||
final Bitmap bitmap = textToImageEncode(uriRequest.getUri());
|
public void run() {
|
||||||
|
ivQrCode.setImageBitmap(bitmap);
|
||||||
if (!this.isCancelled()) {
|
pbQrCode.setVisibility(View.GONE);
|
||||||
ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() {
|
}
|
||||||
@Override
|
});
|
||||||
public void run() {
|
|
||||||
ivQrCode.setImageBitmap(bitmap);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (WriterException e) {
|
|
||||||
Log.e("ReceiveFragment", "Error creating QrCode");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
qrCodeTask.execute(null, null, null);
|
|
||||||
} else {
|
|
||||||
Log.e("ReceiveFragment", "Error obtaining the uri");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
} catch (WriterException e) {
|
||||||
|
Log.e("ReceiveFragment", "Error creating QrCode");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.qrCodeTask.execute(null, null, null);
|
||||||
|
} else {
|
||||||
|
final CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0);
|
||||||
|
|
||||||
|
final CalculateBitcoinUriRequest uriRequest = new CalculateBitcoinUriRequest(cryptoCoin, cryptoNetAccount, getContext(), amount);
|
||||||
|
|
||||||
|
uriRequest.setListener(new CryptoNetInfoRequestListener() {
|
||||||
|
@Override
|
||||||
|
public void onCarryOut() {
|
||||||
|
if (uriRequest.getUri() != null) {
|
||||||
|
qrCodeTask = new AsyncTask<Object, Void, Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Object... voids) {
|
||||||
|
try {
|
||||||
|
final Bitmap bitmap = textToImageEncode(uriRequest.getUri());
|
||||||
|
|
||||||
|
if (!this.isCancelled()) {
|
||||||
|
ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
//Double amountNow = -1.0;
|
||||||
|
//try{
|
||||||
|
// amountNow = Double.valueOf(etAmount.getText().toString());
|
||||||
|
//} catch(NumberFormatException e){
|
||||||
|
//}
|
||||||
|
//if (amountNow >= 0) {
|
||||||
|
if (amount.equals(lastAmount)) {
|
||||||
|
if (!isCancelled()) {
|
||||||
|
ivQrCode.setImageBitmap(bitmap);
|
||||||
|
pbQrCode.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (WriterException e) {
|
||||||
|
Log.e("ReceiveFragment", "Error creating QrCode");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
qrCodeTask.execute(null, null, null);
|
||||||
|
} else {
|
||||||
|
Log.e("ReceiveFragment", "Error obtaining the uri");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Thread thread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
CryptoNetInfoRequests.getInstance().addRequest(uriRequest);
|
CryptoNetInfoRequests.getInstance().addRequest(uriRequest);
|
||||||
// } else {
|
}
|
||||||
// Toast.makeText(getContext(),"Error creating address",Toast.LENGTH_SHORT);
|
});
|
||||||
// }
|
thread.start();
|
||||||
// }
|
}
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap textToImageEncode(String Value) throws WriterException {
|
Bitmap textToImageEncode(String Value) throws WriterException {
|
||||||
//TODO: do this in another thread
|
Bitmap bitmap = null;
|
||||||
|
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
||||||
BitMatrix bitMatrix;
|
|
||||||
try {
|
try {
|
||||||
bitMatrix = new MultiFormatWriter().encode(
|
BitMatrix bitMatrix = multiFormatWriter.encode(Value, BarcodeFormat.QR_CODE, ivQrCode.getWidth(), ivQrCode.getHeight());
|
||||||
Value,
|
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
|
||||||
BarcodeFormat.DATA_MATRIX.QR_CODE,
|
bitmap = barcodeEncoder.createBitmap(bitMatrix);
|
||||||
ivQrCode.getWidth(), ivQrCode.getHeight(), null
|
} catch (WriterException e) {
|
||||||
);
|
e.printStackTrace();
|
||||||
|
|
||||||
} catch (IllegalArgumentException Illegalargumentexception) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int bitMatrixWidth = bitMatrix.getWidth();
|
|
||||||
int bitMatrixHeight = bitMatrix.getHeight();
|
|
||||||
int[] pixels = new int[bitMatrixWidth * bitMatrixHeight];
|
|
||||||
|
|
||||||
for (int y = 0; y < bitMatrixHeight; y++) {
|
|
||||||
int offset = y * bitMatrixWidth;
|
|
||||||
|
|
||||||
for (int x = 0; x < bitMatrixWidth; x++) {
|
|
||||||
pixels[offset + x] = bitMatrix.get(x, y) ?
|
|
||||||
getResources().getColor(R.color.QRCodeBlackColor):getResources().getColor(R.color.QRCodeWhiteColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(bitMatrixWidth, bitMatrixHeight, Bitmap.Config.ARGB_4444);
|
|
||||||
bitmap.setPixels(pixels, 0, ivQrCode.getWidth(), 0, 0, bitMatrixWidth, bitMatrixHeight);
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -542,7 +542,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
|
||||||
System.out.println("GeneralAccountMAnager uri calculated : " + uri.toString());
|
System.out.println("GeneralAccountMAnager uri calculated : " + uri.toString());
|
||||||
|
|
||||||
request.setUri(uri.toString());
|
request.setUri(uri.toString());
|
||||||
request.validate();
|
//request.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseUri(BitcoinUriParseRequest request){
|
private void parseUri(BitcoinUriParseRequest request){
|
||||||
|
|
|
@ -103,6 +103,8 @@
|
||||||
android:textColor="@color/red"
|
android:textColor="@color/red"
|
||||||
android:layout_below="@+id/spAsset"/>
|
android:layout_below="@+id/spAsset"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<cy.agorise.crystalwallet.util.SquaredImageView
|
<cy.agorise.crystalwallet.util.SquaredImageView
|
||||||
android:id="@+id/ivQrCode"
|
android:id="@+id/ivQrCode"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -116,6 +118,22 @@
|
||||||
android:layout_below="@+id/tvAmountError"
|
android:layout_below="@+id/tvAmountError"
|
||||||
android:layout_centerHorizontal="true"/>
|
android:layout_centerHorizontal="true"/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/pbQrCode"
|
||||||
|
style="?android:attr/progressBarStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/tvAmountError"
|
||||||
|
android:layout_alignBottom="@+id/ivQrCode"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:contentDescription="@string/qr_code"
|
||||||
|
android:src="@color/gray"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvShare"
|
android:id="@+id/tvShare"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in a new issue