use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class SettingsActivity2 method getXPUB.
private void getXPUB(int purpose, int account) {
String xpub = "";
switch(purpose) {
case 49:
xpub = BIP49Util.getInstance(SettingsActivity2.this).getWallet().getAccount(account).ypubstr();
break;
case 84:
xpub = BIP84Util.getInstance(SettingsActivity2.this).getWallet().getAccountAt(account).zpubstr();
break;
default:
try {
xpub = HD_WalletFactory.getInstance(SettingsActivity2.this).get().getAccount(account).xpubstr();
} catch (IOException ioe) {
ioe.printStackTrace();
Toast.makeText(SettingsActivity2.this, "HD wallet error", Toast.LENGTH_SHORT).show();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
Toast.makeText(SettingsActivity2.this, "HD wallet error", Toast.LENGTH_SHORT).show();
}
break;
}
ImageView showQR = new ImageView(SettingsActivity2.this);
Bitmap bitmap = null;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(xpub, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), 500);
try {
bitmap = qrCodeEncoder.encodeAsBitmap();
} catch (WriterException e) {
e.printStackTrace();
}
showQR.setImageBitmap(bitmap);
TextView showText = new TextView(SettingsActivity2.this);
showText.setText(xpub);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
LinearLayout xpubLayout = new LinearLayout(SettingsActivity2.this);
xpubLayout.setOrientation(LinearLayout.VERTICAL);
xpubLayout.addView(showQR);
xpubLayout.addView(showText);
final String _xpub = xpub;
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setView(xpubLayout).setCancelable(false).setPositiveButton(R.string.copy_to_clipboard, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) SettingsActivity2.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = null;
clip = android.content.ClipData.newPlainText("XPUB", _xpub);
clipboard.setPrimaryClip(clip);
Toast.makeText(SettingsActivity2.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
}).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
}
use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class PayNymCalcActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paynym_calc);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
edPayNym = (EditText) findViewById(R.id.paynym);
edIndex = (EditText) findViewById(R.id.index);
edPayNym.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// final int DRAWABLE_LEFT = 0;
// final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_UP && event.getRawX() >= (edPayNym.getRight() - edPayNym.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
final List<String> entries = new ArrayList<String>();
entries.addAll(BIP47Meta.getInstance().getSortedByLabels(true));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(PayNymCalcActivity.this, android.R.layout.select_dialog_singlechoice);
for (int i = 0; i < entries.size(); i++) {
arrayAdapter.add(BIP47Meta.getInstance().getDisplayLabel(entries.get(i)));
}
AlertDialog.Builder dlg = new AlertDialog.Builder(PayNymCalcActivity.this);
dlg.setIcon(R.drawable.ic_launcher);
dlg.setTitle(R.string.app_name);
dlg.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
edPayNym.setText(entries.get(which));
}
});
dlg.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dlg.show();
return true;
}
return false;
}
});
btOK = (Button) findViewById(R.id.ok);
btOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String strPayNym = edPayNym.getText().toString();
String strIndex = edIndex.getText().toString();
PaymentCode pcode = new PaymentCode(strPayNym);
if (pcode == null) {
Toast.makeText(PayNymCalcActivity.this, R.string.invalid_payment_code, Toast.LENGTH_SHORT).show();
return;
}
if (strIndex == null || strIndex.length() < 1) {
Toast.makeText(PayNymCalcActivity.this, R.string.invalid_index, Toast.LENGTH_SHORT).show();
return;
}
try {
int index = Integer.parseInt(strIndex);
String message = strPayNym;
final ECKey receiveECKey;
final SegwitAddress receiveSegwit;
PaymentAddress receiveAddress = BIP47Util.getInstance(PayNymCalcActivity.this).getReceiveAddress(new PaymentCode(strPayNym), index);
PaymentAddress sendAddress = BIP47Util.getInstance(PayNymCalcActivity.this).getSendAddress(new PaymentCode(strPayNym), index);
receiveECKey = receiveAddress.getReceiveECKey();
ECKey sendECKey = sendAddress.getSendECKey();
receiveSegwit = new SegwitAddress(receiveECKey, SamouraiWallet.getInstance().getCurrentNetworkParams());
SegwitAddress sendSegwit = new SegwitAddress(sendECKey, SamouraiWallet.getInstance().getCurrentNetworkParams());
message += "\n";
message += index + ":";
message += "\n";
message += "\n";
message += PayNymCalcActivity.this.getText(R.string.receive_addresses).toString() + ":";
message += "\n";
message += receiveECKey.toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
message += "\n";
message += receiveSegwit.getAddressAsString();
message += "\n";
message += receiveSegwit.getBech32AsString();
message += "\n";
message += PayNymCalcActivity.this.getText(R.string.send_addresses).toString() + ":";
message += "\n";
message += sendECKey.toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
message += "\n";
message += sendSegwit.getAddressAsString();
message += "\n";
message += sendSegwit.getBech32AsString();
message += "\n";
final TextView tvText = new TextView(getApplicationContext());
tvText.setTextSize(12);
tvText.setText(message);
tvText.setTextIsSelectable(true);
tvText.setPadding(40, 10, 40, 10);
tvText.setTextColor(0xffffffff);
AlertDialog.Builder dlg = new AlertDialog.Builder(PayNymCalcActivity.this).setTitle(R.string.app_name).setView(tvText).setCancelable(true).setPositiveButton(R.string.display_receive_redeem, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String redeemScript = org.spongycastle.util.encoders.Hex.toHexString(receiveSegwit.segWitRedeemScript().getProgram());
TextView showText = new TextView(PayNymCalcActivity.this);
showText.setText(redeemScript);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
new AlertDialog.Builder(PayNymCalcActivity.this).setTitle(R.string.app_name).setView(showText).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
}).show();
}
}).setNeutralButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
}).setNegativeButton(R.string.display_receive_privkey, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String strPrivKey = receiveECKey.getPrivateKeyAsWiF(SamouraiWallet.getInstance().getCurrentNetworkParams());
ImageView showQR = new ImageView(PayNymCalcActivity.this);
Bitmap bitmap = null;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(strPrivKey, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), 500);
try {
bitmap = qrCodeEncoder.encodeAsBitmap();
} catch (WriterException e) {
e.printStackTrace();
}
showQR.setImageBitmap(bitmap);
TextView showText = new TextView(PayNymCalcActivity.this);
showText.setText(strPrivKey);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
LinearLayout privkeyLayout = new LinearLayout(PayNymCalcActivity.this);
privkeyLayout.setOrientation(LinearLayout.VERTICAL);
privkeyLayout.addView(showQR);
privkeyLayout.addView(showText);
new AlertDialog.Builder(PayNymCalcActivity.this).setTitle(R.string.app_name).setView(privkeyLayout).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
}
});
if (!isFinishing()) {
dlg.show();
}
} catch (Exception e) {
Toast.makeText(PayNymCalcActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
btCancel = (Button) findViewById(R.id.cancel);
btCancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class TxAnimUIActivity method doShowTx.
private void doShowTx(final String hexTx, final String txHash) {
// tx max size in bytes == 2148
final int QR_ALPHANUM_CHAR_LIMIT = 4296;
TextView showTx = new TextView(TxAnimUIActivity.this);
showTx.setText(hexTx);
showTx.setTextIsSelectable(true);
showTx.setPadding(40, 10, 40, 10);
showTx.setTextSize(18.0f);
final CheckBox cbMarkInputsUnspent = new CheckBox(TxAnimUIActivity.this);
cbMarkInputsUnspent.setText(R.string.mark_inputs_as_unspendable);
cbMarkInputsUnspent.setChecked(false);
LinearLayout hexLayout = new LinearLayout(TxAnimUIActivity.this);
hexLayout.setOrientation(LinearLayout.VERTICAL);
hexLayout.addView(cbMarkInputsUnspent);
hexLayout.addView(showTx);
new AlertDialog.Builder(TxAnimUIActivity.this).setTitle(txHash).setView(hexLayout).setCancelable(false).setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (cbMarkInputsUnspent.isChecked()) {
UTXOFactory.getInstance(TxAnimUIActivity.this).markUTXOAsUnspendable(hexTx);
Intent intent = new Intent("com.samourai.wallet.BalanceFragment.REFRESH");
intent.putExtra("notifTx", false);
intent.putExtra("fetch", true);
LocalBroadcastManager.getInstance(TxAnimUIActivity.this).sendBroadcast(intent);
}
dialog.dismiss();
TxAnimUIActivity.this.finish();
}
}).setNeutralButton(R.string.copy_to_clipboard, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) TxAnimUIActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = null;
clip = android.content.ClipData.newPlainText("TX", hexTx);
clipboard.setPrimaryClip(clip);
Toast.makeText(TxAnimUIActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
}).setNegativeButton(R.string.show_qr, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (cbMarkInputsUnspent.isChecked()) {
UTXOFactory.getInstance(TxAnimUIActivity.this).markUTXOAsUnspendable(hexTx);
Intent intent = new Intent("com.samourai.wallet.BalanceFragment.REFRESH");
intent.putExtra("notifTx", false);
intent.putExtra("fetch", true);
LocalBroadcastManager.getInstance(TxAnimUIActivity.this).sendBroadcast(intent);
}
if (hexTx.length() <= QR_ALPHANUM_CHAR_LIMIT) {
final ImageView ivQR = new ImageView(TxAnimUIActivity.this);
Display display = (TxAnimUIActivity.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(hexTx, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), imgWidth);
try {
bitmap = qrCodeEncoder.encodeAsBitmap();
} catch (WriterException e) {
e.printStackTrace();
}
ivQR.setImageBitmap(bitmap);
LinearLayout qrLayout = new LinearLayout(TxAnimUIActivity.this);
qrLayout.setOrientation(LinearLayout.VERTICAL);
qrLayout.addView(ivQR);
new AlertDialog.Builder(TxAnimUIActivity.this).setTitle(txHash).setView(qrLayout).setCancelable(false).setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
TxAnimUIActivity.this.finish();
}
}).setNegativeButton(R.string.share_qr, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String strFileName = AppUtil.getInstance(TxAnimUIActivity.this).getReceiveQRFilename();
File file = new File(strFileName);
if (!file.exists()) {
try {
file.createNewFile();
} catch (Exception e) {
Toast.makeText(TxAnimUIActivity.this, 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 bitmap = ((BitmapDrawable) ivQR.getDrawable()).getBitmap();
bitmap.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(TxAnimUIActivity.this, getApplicationContext().getPackageName() + ".provider", file));
} else {
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
}
startActivity(Intent.createChooser(intent, TxAnimUIActivity.this.getText(R.string.send_tx)));
}
}
}).show();
} else {
Toast.makeText(TxAnimUIActivity.this, R.string.tx_too_large_qr, Toast.LENGTH_SHORT).show();
}
}
}).show();
}
use of com.google.zxing.client.android.encode.QRCodeEncoder in project sentinel-android by Samourai-Wallet.
the class ReceiveActivity 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 sentinel-android by Samourai-Wallet.
the class ShowQRActivity 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