use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == SCAN_COLD_STORAGE) {
if (data != null && data.getStringExtra(ZBarConstants.SCAN_RESULT) != null) {
final String strResult = data.getStringExtra(ZBarConstants.SCAN_RESULT);
doPrivKey(strResult);
}
} else if (resultCode == Activity.RESULT_CANCELED && requestCode == SCAN_COLD_STORAGE) {
} else if (resultCode == Activity.RESULT_OK && requestCode == SCAN_QR) {
if (data != null && data.getStringExtra(ZBarConstants.SCAN_RESULT) != null) {
final String strResult = data.getStringExtra(ZBarConstants.SCAN_RESULT);
PrivKeyReader privKeyReader = new PrivKeyReader(new CharSequenceX(strResult.trim()));
try {
if (privKeyReader.getFormat() != null) {
doPrivKey(strResult.trim());
} else if (Cahoots.isCahoots(strResult.trim())) {
Intent cahootIntent = new Intent(this, ManualCahootsActivity.class);
cahootIntent.putExtra("_account", account);
cahootIntent.putExtra("payload", strResult.trim());
startActivity(cahootIntent);
} else if (FormatsUtil.getInstance().isPSBT(strResult.trim())) {
CahootsUtil.getInstance(BalanceActivity.this).doPSBT(strResult.trim());
} else if (DojoUtil.getInstance(BalanceActivity.this).isValidPairingPayload(strResult.trim())) {
Intent intent = new Intent(BalanceActivity.this, NetworkDashboard.class);
intent.putExtra("params", strResult.trim());
startActivity(intent);
} else {
Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
intent.putExtra("uri", strResult.trim());
intent.putExtra("_account", account);
startActivity(intent);
}
} catch (Exception e) {
}
}
}
if (resultCode == Activity.RESULT_OK && requestCode == UTXO_REQUESTCODE) {
refreshTx(false, false, false);
progressBar.setVisibility(View.VISIBLE);
} else {
;
}
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method doBackup.
private void doBackup() {
try {
final String passphrase = HD_WalletFactory.getInstance(BalanceActivity.this).get().getPassphrase();
final String[] export_methods = new String[2];
export_methods[0] = getString(R.string.export_to_clipboard);
export_methods[1] = getString(R.string.export_to_email);
new AlertDialog.Builder(BalanceActivity.this).setTitle(R.string.options_export).setSingleChoiceItems(export_methods, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
PayloadUtil.getInstance(BalanceActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(BalanceActivity.this).getGUID() + AccessFactory.getInstance(BalanceActivity.this).getPIN()));
} catch (IOException ioe) {
;
} catch (JSONException je) {
;
} catch (DecryptionException de) {
;
} catch (MnemonicException.MnemonicLengthException mle) {
;
}
String encrypted = null;
try {
encrypted = AESUtil.encrypt(PayloadUtil.getInstance(BalanceActivity.this).getPayload().toString(), new CharSequenceX(passphrase), AESUtil.DefaultPBKDF2Iterations);
} catch (Exception e) {
Toast.makeText(BalanceActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
if (encrypted == null) {
Toast.makeText(BalanceActivity.this, R.string.encryption_error, Toast.LENGTH_SHORT).show();
return;
}
}
JSONObject obj = PayloadUtil.getInstance(BalanceActivity.this).putPayload(encrypted, true);
if (which == 0) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(android.content.Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = null;
clip = android.content.ClipData.newPlainText("Wallet backup", obj.toString());
clipboard.setPrimaryClip(clip);
Toast.makeText(BalanceActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
} else {
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_SUBJECT, "Samourai Wallet backup");
email.putExtra(Intent.EXTRA_TEXT, obj.toString());
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, BalanceActivity.this.getText(R.string.choose_email_client)));
}
dialog.dismiss();
}
}).show();
} catch (IOException ioe) {
ioe.printStackTrace();
Toast.makeText(BalanceActivity.this, "HD wallet error", Toast.LENGTH_SHORT).show();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
Toast.makeText(BalanceActivity.this, "HD wallet error", Toast.LENGTH_SHORT).show();
}
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method onBackPressed.
@Override
public void onBackPressed() {
if (account == 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.ask_you_sure_exit);
AlertDialog alert = builder.create();
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), (dialog, id) -> {
try {
PayloadUtil.getInstance(BalanceActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(BalanceActivity.this).getGUID() + AccessFactory.getInstance(BalanceActivity.this).getPIN()));
} catch (MnemonicException.MnemonicLengthException mle) {
} catch (JSONException je) {
} catch (IOException ioe) {
} catch (DecryptionException de) {
}
// disconnect Whirlpool on app back key exit
WhirlpoolNotificationService.stopService(getApplicationContext());
if (TorManager.getInstance(getApplicationContext()).isRequired()) {
Intent startIntent = new Intent(getApplicationContext(), TorService.class);
startIntent.setAction(TorService.STOP_SERVICE);
startIntent.putExtra("KILL_TOR", true);
startService(startIntent);
}
TimeOutUtil.getInstance().reset();
finishAffinity();
finish();
super.onBackPressed();
});
alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), (dialog, id) -> dialog.dismiss());
alert.show();
} else {
super.onBackPressed();
}
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class PayNymDetailsActivity method doSync.
private void doSync() {
progressBar.setVisibility(View.VISIBLE);
Disposable disposable = Observable.fromCallable(() -> {
PaymentCode payment_code = new PaymentCode(pcode);
int idx = 0;
boolean loop = true;
ArrayList<String> addrs = new ArrayList<String>();
while (loop) {
addrs.clear();
for (int i = idx; i < (idx + 20); i++) {
// Log.i("PayNymDetailsActivity", "sync receive from " + i + ":" + BIP47Util.getInstance(PayNymDetailsActivity.this).getReceivePubKey(payment_code, i));
BIP47Meta.getInstance().getIdx4AddrLookup().put(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i), i);
BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i), payment_code.toString());
addrs.add(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i));
// Log.i("PayNymDetailsActivity", "p2pkh " + i + ":" + BIP47Util.getInstance(PayNymDetailsActivity.this).getReceiveAddress(payment_code, i).getReceiveECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
}
String[] s = addrs.toArray(new String[addrs.size()]);
int nb = APIFactory.getInstance(this).syncBIP47Incoming(s);
// Log.i("PayNymDetailsActivity", "sync receive idx:" + idx + ", nb == " + nb);
if (nb == 0) {
loop = false;
}
idx += 20;
}
idx = 0;
loop = true;
BIP47Meta.getInstance().setOutgoingIdx(pcode, 0);
while (loop) {
addrs.clear();
for (int i = idx; i < (idx + 20); i++) {
PaymentAddress sendAddress = BIP47Util.getInstance(this).getSendAddress(payment_code, i);
// Log.i("PayNymDetailsActivity", "sync send to " + i + ":" + sendAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
// BIP47Meta.getInstance().setOutgoingIdx(payment_code.toString(), i);
BIP47Meta.getInstance().getIdx4AddrLookup().put(BIP47Util.getInstance(this).getSendPubKey(payment_code, i), i);
BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(this).getSendPubKey(payment_code, i), payment_code.toString());
addrs.add(BIP47Util.getInstance(this).getSendPubKey(payment_code, i));
}
String[] s = addrs.toArray(new String[addrs.size()]);
int nb = APIFactory.getInstance(this).syncBIP47Outgoing(s);
// Log.i("PayNymDetailsActivity", "sync send idx:" + idx + ", nb == " + nb);
if (nb == 0) {
loop = false;
}
idx += 20;
}
BIP47Meta.getInstance().pruneIncoming();
PayloadUtil.getInstance(this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(this).getGUID() + AccessFactory.getInstance(this).getPIN()));
return true;
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
progressBar.setVisibility(View.INVISIBLE);
setPayNym();
}, error -> {
error.printStackTrace();
progressBar.setVisibility(View.INVISIBLE);
});
disposables.add(disposable);
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class PayNymDetailsActivity method onDestroy.
@Override
protected void onDestroy() {
disposables.dispose();
try {
PayloadUtil.getInstance(getApplicationContext()).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(getApplicationContext()).getGUID() + AccessFactory.getInstance(getApplicationContext()).getPIN()));
} catch (MnemonicException.MnemonicLengthException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (DecryptionException e) {
e.printStackTrace();
}
super.onDestroy();
}
Aggregations