use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class OpenDimeActivity method generateQRCode.
private Bitmap generateQRCode(String uri) {
Bitmap bitmap = null;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), imgWidth);
try {
bitmap = qrCodeEncoder.encodeAsBitmap();
} catch (WriterException e) {
e.printStackTrace();
}
return bitmap;
}
use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class ManualCahootsActivity method shareCahootsPayload.
private void shareCahootsPayload() {
String strCahoots = this.payload.toJSON().toString();
// tx max size in bytes == 2148
final int QR_ALPHANUM_CHAR_LIMIT = 4296;
dialog = new AppCompatDialog(this, R.style.stowaway_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setContentView(R.layout.cahoots_qr_dialog_layout);
ImageView qrCode = dialog.findViewById(R.id.qr_code_imageview);
Button copy = dialog.findViewById(R.id.cahoots_copy_btn);
Button share = dialog.findViewById(R.id.cahoots_share);
TextView qrErrorMessage = dialog.findViewById(R.id.qr_error_stowaway);
if (strCahoots.length() <= QR_ALPHANUM_CHAR_LIMIT) {
Display display = this.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int imgWidth = Math.max(size.x - 240, 150);
Bitmap bitmap = null;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(strCahoots, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), imgWidth);
try {
bitmap = qrCodeEncoder.encodeAsBitmap();
} catch (WriterException e) {
qrErrorMessage.setVisibility(View.VISIBLE);
e.printStackTrace();
}
qrCode.setImageBitmap(bitmap);
} else {
qrErrorMessage.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(), R.string.tx_too_large_qr, Toast.LENGTH_SHORT).show();
}
share.setOnClickListener(v -> {
if (!(strCahoots.length() <= QR_ALPHANUM_CHAR_LIMIT)) {
Intent txtIntent = new Intent(android.content.Intent.ACTION_SEND);
txtIntent.setType("text/plain");
txtIntent.putExtra(android.content.Intent.EXTRA_TEXT, strCahoots);
startActivity(Intent.createChooser(txtIntent, "Share"));
return;
}
String strFileName = AppUtil.getInstance(getApplicationContext()).getReceiveQRFilename();
File file = new File(strFileName);
if (!file.exists()) {
try {
file.createNewFile();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
file.setReadable(true, false);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
} catch (FileNotFoundException fnfe) {
}
if (file != null && fos != null) {
Bitmap bitmap1 = ((BitmapDrawable) qrCode.getDrawable()).getBitmap();
bitmap1.compress(Bitmap.CompressFormat.PNG, 0, fos);
try {
fos.close();
} catch (IOException ioe) {
;
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/png");
if (android.os.Build.VERSION.SDK_INT >= 24) {
// From API 24 sending FIle on intent ,require custom file provider
intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getApplicationContext().getPackageName() + ".provider", file));
} else {
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
}
ManualCahootsActivity.this.startActivity(Intent.createChooser(intent, getApplicationContext().getText(R.string.send_tx)));
}
});
copy.setOnClickListener(v -> {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getApplicationContext().getSystemService(android.content.Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = null;
clip = android.content.ClipData.newPlainText("Cahoots", strCahoots);
clipboard.setPrimaryClip(clip);
Toast.makeText(getApplicationContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
});
dialog.show();
}
use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class BIP47ShowQR method generateQRCode.
private Bitmap generateQRCode(String uri) {
Bitmap bitmap = null;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), imgWidth);
try {
bitmap = qrCodeEncoder.encodeAsBitmap();
} catch (WriterException e) {
e.printStackTrace();
}
return bitmap;
}
Aggregations