use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class SettingsActivity2 method getYPUB.
private void getYPUB() {
final String ypub = BIP49Util.getInstance(SettingsActivity2.this).getWallet().getAccount(0).ypubstr();
ImageView showQR = new ImageView(SettingsActivity2.this);
Bitmap bitmap = null;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(ypub, 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(ypub);
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("YPUB", ypub);
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 UTXOActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_utxo);
setTitle(R.string.options_utxo);
data = new ArrayList<DisplayData>();
doNotSpend = new ArrayList<DisplayData>();
listView = (ListView) findViewById(R.id.list);
update(false);
adapter = new UTXOAdapter();
listView.setAdapter(adapter);
AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
Log.d("UTXOActivity", "menu:" + data.get(position).addr);
Log.d("UTXOActivity", "menu:" + data.get(position).hash + "-" + data.get(position).idx);
PopupMenu menu = new PopupMenu(UTXOActivity.this, view, Gravity.RIGHT);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
switch(id) {
case R.id.item_do_not_spend:
{
if (data.get(position).amount < BlockedUTXO.BLOCKED_UTXO_THRESHOLD && BlockedUTXO.getInstance().contains(data.get(position).hash, data.get(position).idx)) {
AlertDialog.Builder builder = new AlertDialog.Builder(UTXOActivity.this);
builder.setTitle(R.string.dusting_tx);
builder.setMessage(R.string.dusting_tx_unblock);
builder.setCancelable(true);
builder.setPositiveButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
;
}
});
builder.setNegativeButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
BlockedUTXO.getInstance().remove(data.get(position).hash, data.get(position).idx);
BlockedUTXO.getInstance().addNotDusted(data.get(position).hash, data.get(position).idx);
update(true);
}
});
AlertDialog alert = builder.create();
alert.show();
} else if (BlockedUTXO.getInstance().contains(data.get(position).hash, data.get(position).idx)) {
AlertDialog.Builder builder = new AlertDialog.Builder(UTXOActivity.this);
builder.setTitle(R.string.mark_spend);
builder.setMessage(R.string.mark_utxo_spend);
builder.setCancelable(true);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
BlockedUTXO.getInstance().remove(data.get(position).hash, data.get(position).idx);
Log.d("UTXOActivity", "removed:" + data.get(position).hash + "-" + data.get(position).idx);
update(true);
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
;
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(UTXOActivity.this);
builder.setTitle(R.string.mark_do_not_spend);
builder.setMessage(R.string.mark_utxo_do_not_spend);
builder.setCancelable(true);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
BlockedUTXO.getInstance().add(data.get(position).hash, data.get(position).idx, data.get(position).amount);
Log.d("UTXOActivity", "added:" + data.get(position).hash + "-" + data.get(position).idx);
update(true);
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
;
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
break;
case R.id.item_sign:
{
String addr = data.get(position).addr;
ECKey ecKey = SendFactory.getPrivKey(addr);
String msg = null;
if (Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), addr).isP2SHAddress() || FormatsUtil.getInstance().isValidBech32(addr)) {
msg = UTXOActivity.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 = UTXOActivity.this.getString(R.string.utxo_sign_text2);
}
if (ecKey != null) {
MessageSignUtil.getInstance(UTXOActivity.this).doSign(UTXOActivity.this.getString(R.string.utxo_sign), UTXOActivity.this.getString(R.string.utxo_sign_text1), msg, ecKey);
}
}
break;
case R.id.item_redeem:
{
String addr = data.get(position).addr;
ECKey ecKey = SendFactory.getPrivKey(addr);
SegwitAddress p2sh_p2wpkh = new SegwitAddress(ecKey.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
if (ecKey != null && p2sh_p2wpkh != null) {
String redeemScript = Hex.toHexString(p2sh_p2wpkh.segWitRedeemScript().getProgram());
TextView showText = new TextView(UTXOActivity.this);
showText.setText(redeemScript);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
new AlertDialog.Builder(UTXOActivity.this).setTitle(R.string.app_name).setView(showText).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
}
}
break;
case R.id.item_view:
{
int sel = PrefsUtil.getInstance(UTXOActivity.this).getValue(PrefsUtil.BLOCK_EXPLORER, 0);
if (sel >= BlockExplorerUtil.getInstance().getBlockExplorerAddressUrls().length) {
sel = 0;
}
CharSequence url = BlockExplorerUtil.getInstance().getBlockExplorerTxUrls()[sel];
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url + data.get(position).hash));
startActivity(browserIntent);
}
break;
case R.id.item_privkey:
{
String addr = data.get(position).addr;
ECKey ecKey = SendFactory.getPrivKey(addr);
String strPrivKey = ecKey.getPrivateKeyAsWiF(SamouraiWallet.getInstance().getCurrentNetworkParams());
ImageView showQR = new ImageView(UTXOActivity.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(UTXOActivity.this);
showText.setText(strPrivKey);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
LinearLayout privkeyLayout = new LinearLayout(UTXOActivity.this);
privkeyLayout.setOrientation(LinearLayout.VERTICAL);
privkeyLayout.addView(showQR);
privkeyLayout.addView(showText);
new AlertDialog.Builder(UTXOActivity.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();
}
break;
}
return true;
}
});
menu.inflate(R.menu.utxo_menu);
if (BlockedUTXO.getInstance().contains(data.get(position).hash, data.get(position).idx)) {
menu.getMenu().findItem(R.id.item_do_not_spend).setTitle(R.string.mark_spend);
} else {
menu.getMenu().findItem(R.id.item_do_not_spend).setTitle(R.string.mark_do_not_spend);
}
String addr = data.get(position).addr;
if (!Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), addr).isP2SHAddress()) {
menu.getMenu().findItem(R.id.item_redeem).setVisible(false);
}
menu.show();
}
};
listView.setOnItemClickListener(listener);
}
use of com.google.zxing.client.android.encode.QRCodeEncoder in project samourai-wallet-android by Samourai-Wallet.
the class ShowPayNymQRBottomSheet method generateQRCode.
private Observable<Bitmap> generateQRCode(String uri) {
return Observable.fromCallable(() -> {
Bitmap bitmap = null;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), 250);
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 BatchSendActivity 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(BatchSendActivity.this);
showTx.setText(hexTx);
showTx.setTextIsSelectable(true);
showTx.setPadding(40, 10, 40, 10);
showTx.setTextSize(18.0f);
final CheckBox cbMarkInputsUnspent = new CheckBox(BatchSendActivity.this);
cbMarkInputsUnspent.setText(R.string.mark_inputs_as_unspendable);
cbMarkInputsUnspent.setChecked(false);
LinearLayout hexLayout = new LinearLayout(BatchSendActivity.this);
hexLayout.setOrientation(LinearLayout.VERTICAL);
hexLayout.addView(cbMarkInputsUnspent);
hexLayout.addView(showTx);
new AlertDialog.Builder(BatchSendActivity.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(BatchSendActivity.this).markUTXOAsUnspendable(hexTx);
Intent intent = new Intent("com.samourai.wallet.BalanceFragment.REFRESH");
intent.putExtra("notifTx", false);
intent.putExtra("fetch", true);
LocalBroadcastManager.getInstance(BatchSendActivity.this).sendBroadcast(intent);
}
dialog.dismiss();
BatchSendActivity.this.finish();
}
}).setNegativeButton(R.string.show_qr, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (cbMarkInputsUnspent.isChecked()) {
UTXOFactory.getInstance(BatchSendActivity.this).markUTXOAsUnspendable(hexTx);
Intent intent = new Intent("com.samourai.wallet.BalanceFragment.REFRESH");
intent.putExtra("notifTx", false);
intent.putExtra("fetch", true);
LocalBroadcastManager.getInstance(BatchSendActivity.this).sendBroadcast(intent);
}
if (hexTx.length() <= QR_ALPHANUM_CHAR_LIMIT) {
final ImageView ivQR = new ImageView(BatchSendActivity.this);
Display display = (BatchSendActivity.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(BatchSendActivity.this);
qrLayout.setOrientation(LinearLayout.VERTICAL);
qrLayout.addView(ivQR);
new AlertDialog.Builder(BatchSendActivity.this).setTitle(txHash).setView(qrLayout).setCancelable(false).setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
BatchSendActivity.this.finish();
}
}).setNegativeButton(R.string.share_qr, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String strFileName = AppUtil.getInstance(BatchSendActivity.this).getReceiveQRFilename();
File file = new File(strFileName);
if (!file.exists()) {
try {
file.createNewFile();
} catch (Exception e) {
Toast.makeText(BatchSendActivity.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(BatchSendActivity.this, getApplicationContext().getPackageName() + ".provider", file));
} else {
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
}
startActivity(Intent.createChooser(intent, BatchSendActivity.this.getText(R.string.send_tx)));
}
}
}).show();
} else {
Toast.makeText(BatchSendActivity.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 displayWhirlpoolGUIPairing.
private void displayWhirlpoolGUIPairing(JSONObject pairingObj) {
if (pairingObj == null || !pairingObj.has("pairing")) {
Toast.makeText(SettingsActivity2.this, "HD wallet error", Toast.LENGTH_SHORT).show();
return;
}
ImageView showQR = new ImageView(SettingsActivity2.this);
Bitmap bitmap = null;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(pairingObj.toString(), 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(pairingObj.toString());
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
LinearLayout pairingLayout = new LinearLayout(SettingsActivity2.this);
pairingLayout.setOrientation(LinearLayout.VERTICAL);
pairingLayout.addView(showQR);
pairingLayout.addView(showText);
final String _pairing = pairingObj.toString();
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setView(pairingLayout).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("GUI pairing", _pairing);
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();
}
Aggregations