use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class SendActivity 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(SendActivity.this);
showTx.setText(hexTx);
showTx.setTextIsSelectable(true);
showTx.setPadding(40, 10, 40, 10);
showTx.setTextSize(18.0f);
final CheckBox cbMarkInputsUnspent = new CheckBox(SendActivity.this);
cbMarkInputsUnspent.setText(R.string.mark_inputs_as_unspendable);
cbMarkInputsUnspent.setChecked(false);
LinearLayout hexLayout = new LinearLayout(SendActivity.this);
hexLayout.setOrientation(LinearLayout.VERTICAL);
hexLayout.addView(cbMarkInputsUnspent);
hexLayout.addView(showTx);
new AlertDialog.Builder(SendActivity.this).setTitle(txHash).setView(hexLayout).setCancelable(false).setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (cbMarkInputsUnspent.isChecked()) {
markUTXOAsUnspendable(hexTx);
Intent intent = new Intent("com.samourai.wallet.BalanceFragment.REFRESH");
intent.putExtra("notifTx", false);
intent.putExtra("fetch", true);
LocalBroadcastManager.getInstance(SendActivity.this).sendBroadcast(intent);
}
dialog.dismiss();
SendActivity.this.finish();
}
}).setNegativeButton(R.string.show_qr, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (cbMarkInputsUnspent.isChecked()) {
markUTXOAsUnspendable(hexTx);
Intent intent = new Intent("com.samourai.wallet.BalanceFragment.REFRESH");
intent.putExtra("notifTx", false);
intent.putExtra("fetch", true);
LocalBroadcastManager.getInstance(SendActivity.this).sendBroadcast(intent);
}
if (hexTx.length() <= QR_ALPHANUM_CHAR_LIMIT) {
final ImageView ivQR = new ImageView(SendActivity.this);
Display display = (SendActivity.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(SendActivity.this);
qrLayout.setOrientation(LinearLayout.VERTICAL);
qrLayout.addView(ivQR);
new AlertDialog.Builder(SendActivity.this).setTitle(txHash).setView(qrLayout).setCancelable(false).setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
SendActivity.this.finish();
}
}).setNegativeButton(R.string.share_qr, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String strFileName = AppUtil.getInstance(SendActivity.this).getReceiveQRFilename();
File file = new File(strFileName);
if (!file.exists()) {
try {
file.createNewFile();
} catch (Exception e) {
Toast.makeText(SendActivity.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");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(Intent.createChooser(intent, SendActivity.this.getText(R.string.send_tx)));
}
}
}).show();
} else {
Toast.makeText(SendActivity.this, R.string.tx_too_large_qr, Toast.LENGTH_SHORT).show();
}
}
}).show();
}
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() {
final String[] accounts;
if (AddressFactory.getInstance(SettingsActivity2.this).getHighestTxReceiveIdx(SamouraiWallet.MIXING_ACCOUNT) == 0) {
accounts = new String[] { getString(R.string.account_Samourai) };
} else {
accounts = new String[] { getString(R.string.account_Samourai), getString(R.string.account_shuffling) };
}
final int sel = 0;
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.select_account).setSingleChoiceItems(accounts, sel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
String xpub = null;
try {
xpub = HD_WalletFactory.getInstance(SettingsActivity2.this).get().getAccount(which).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();
}
final String _xpub = xpub;
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);
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();
}
}).show();
}
use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class UTXODetailsActivity method viewPrivateKey.
private void viewPrivateKey() {
ECKey ecKey = SendFactory.getPrivKey(addr, account);
String strPrivKey = ecKey.getPrivateKeyAsWiF(SamouraiWallet.getInstance().getCurrentNetworkParams());
ImageView showQR = new ImageView(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(this);
showText.setText(strPrivKey);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
LinearLayout privkeyLayout = new LinearLayout(this);
privkeyLayout.setOrientation(LinearLayout.VERTICAL);
privkeyLayout.addView(showQR);
privkeyLayout.addView(showText);
new AlertDialog.Builder(this).setTitle(R.string.app_name).setView(privkeyLayout).setCancelable(false).setPositiveButton(R.string.ok, (dialog, whichButton) -> {
}).show();
}
use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-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 samourai-wallet-android by Samourai-Wallet.
the class AddressCalcActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_address_calc);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
edIndex = (EditText) findViewById(R.id.index);
spType = (Spinner) findViewById(R.id.address_type_spinner);
spType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
if (position == 3) {
tvChain.setVisibility(View.INVISIBLE);
rChain.setVisibility(View.INVISIBLE);
} else {
tvChain.setVisibility(View.VISIBLE);
rChain.setVisibility(View.VISIBLE);
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
;
}
});
populateSpinner();
tvChain = (TextView) findViewById(R.id.chain_label);
rChain = (RadioGroup) findViewById(R.id.chain);
btOK = (Button) findViewById(R.id.ok);
btOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
HD_Address hd_addr = null;
final SegwitAddress segwitAddress;
String strIndex = edIndex.getText().toString();
if (strIndex == null || strIndex.length() < 1) {
Toast.makeText(AddressCalcActivity.this, R.string.invalid_index, Toast.LENGTH_SHORT).show();
return;
}
int index = Integer.parseInt(strIndex);
int chain = 0;
int selectedId = rChain.getCheckedRadioButtonId();
if (spType.getSelectedItemPosition() == 3) {
chain = 0;
} else if (selectedId == R.id.change) {
chain = 1;
} else {
chain = 0;
}
if (spType.getSelectedItemPosition() == 1) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(0).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else if (spType.getSelectedItemPosition() == 2) {
segwitAddress = null;
hd_addr = HD_WalletFactory.getInstance(AddressCalcActivity.this).get().getAccount(0).getChain(chain).getAddressAt(index);
} else if (spType.getSelectedItemPosition() == 3) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(RicochetMeta.getInstance(AddressCalcActivity.this).getRicochetAccount()).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else if (spType.getSelectedItemPosition() == 4) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(WhirlpoolMeta.getInstance(AddressCalcActivity.this).getWhirlpoolPremixAccount()).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else if (spType.getSelectedItemPosition() == 5) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(WhirlpoolMeta.getInstance(AddressCalcActivity.this).getWhirlpoolPostmix()).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else if (spType.getSelectedItemPosition() == 6) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(WhirlpoolMeta.getInstance(AddressCalcActivity.this).getWhirlpoolBadBank()).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else {
hd_addr = BIP49Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(0).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
}
final ECKey ecKey;
final String strAddress;
if (spType.getSelectedItemPosition() == 2) {
ecKey = hd_addr.getECKey();
strAddress = hd_addr.getAddressString();
} else {
ecKey = segwitAddress.getECKey();
if (spType.getSelectedItemPosition() == 0) {
strAddress = segwitAddress.getAddressAsString();
} else {
strAddress = segwitAddress.getBech32AsString();
}
}
String message = spType.getSelectedItem().toString();
message += "\n";
message += (chain == 1) ? AddressCalcActivity.this.getText(R.string.change_chain) : AddressCalcActivity.this.getText(R.string.receive_chain);
message += "\n";
message += index + ":";
message += "\n";
message += strAddress;
final TextView tvText = new TextView(getApplicationContext());
tvText.setText(message);
tvText.setTextIsSelectable(true);
tvText.setPadding(40, 10, 40, 10);
tvText.setTextColor(0xffffffff);
AlertDialog.Builder dlg = new AlertDialog.Builder(AddressCalcActivity.this).setTitle(R.string.app_name).setView(tvText).setCancelable(true).setNeutralButton(R.string.utxo_sign, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
String addr = strAddress;
String msg = null;
if (FormatsUtil.getInstance().isValidBech32(addr) || Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), addr).isP2SHAddress()) {
msg = AddressCalcActivity.this.getString(R.string.utxo_sign_text3);
try {
JSONObject obj = new JSONObject();
obj.put("pubkey", ecKey.getPublicKeyAsHex());
obj.put("address", addr);
msg += " " + obj.toString();
} catch (JSONException je) {
msg += ":";
msg += addr;
msg += ", ";
msg += "pubkey:";
msg += ecKey.getPublicKeyAsHex();
}
} else {
msg = AddressCalcActivity.this.getString(R.string.utxo_sign_text2);
}
if (ecKey != null) {
MessageSignUtil.getInstance(AddressCalcActivity.this).doSign(AddressCalcActivity.this.getString(R.string.utxo_sign), AddressCalcActivity.this.getString(R.string.utxo_sign_text1), msg, ecKey);
}
}
}).setNegativeButton(R.string.options_display_privkey, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String strPrivKey = ecKey.getPrivateKeyAsWiF(SamouraiWallet.getInstance().getCurrentNetworkParams());
ImageView showQR = new ImageView(AddressCalcActivity.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(AddressCalcActivity.this);
showText.setText(strPrivKey);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
LinearLayout privkeyLayout = new LinearLayout(AddressCalcActivity.this);
privkeyLayout.setOrientation(LinearLayout.VERTICAL);
privkeyLayout.addView(showQR);
privkeyLayout.addView(showText);
new AlertDialog.Builder(AddressCalcActivity.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 (spType.getSelectedItemPosition() != 2) {
dlg.setPositiveButton(R.string.options_display_redeem_script, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String redeemScript = org.spongycastle.util.encoders.Hex.toHexString(segwitAddress.segWitRedeemScript().getProgram());
TextView showText = new TextView(AddressCalcActivity.this);
showText.setText(redeemScript);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
new AlertDialog.Builder(AddressCalcActivity.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();
}
});
}
if (!isFinishing()) {
dlg.show();
}
} catch (Exception e) {
Toast.makeText(AddressCalcActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
btCancel = (Button) findViewById(R.id.cancel);
btCancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
Aggregations