use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method doClipboardCheck.
private void doClipboardCheck() {
final android.content.ClipboardManager clipboard = (android.content.ClipboardManager) BalanceActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
if (clipboard.hasPrimaryClip()) {
final ClipData clip = clipboard.getPrimaryClip();
ClipData.Item item = clip.getItemAt(0);
if (item.getText() != null) {
String text = item.getText().toString();
String[] s = text.split("\\s+");
try {
for (int i = 0; i < s.length; i++) {
PrivKeyReader privKeyReader = new PrivKeyReader(new CharSequenceX(s[i]));
if (privKeyReader.getFormat() != null && (privKeyReader.getFormat().equals(PrivKeyReader.WIF_COMPRESSED) || privKeyReader.getFormat().equals(PrivKeyReader.WIF_UNCOMPRESSED) || privKeyReader.getFormat().equals(PrivKeyReader.BIP38))) {
new AlertDialog.Builder(BalanceActivity.this).setTitle(R.string.app_name).setMessage(R.string.privkey_clipboard).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
clipboard.setPrimaryClip(ClipData.newPlainText("", ""));
}
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
}
}
} catch (Exception e) {
;
}
}
}
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method onKeyDown.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.ask_you_sure_exit).setCancelable(false);
AlertDialog alert = builder.create();
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int 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) {
;
}
Intent intent = new Intent(BalanceActivity.this, ExodusActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_SINGLE_TOP);
BalanceActivity.this.startActivity(intent);
}
});
alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
if (!isFinishing()) {
alert.show();
}
return true;
} else {
;
}
return false;
}
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));
try {
if (privKeyReader.getFormat() != null) {
doPrivKey(strResult);
} else {
Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
intent.putExtra("uri", strResult);
startActivity(intent);
}
} catch (Exception e) {
;
}
}
} else if (resultCode == Activity.RESULT_CANCELED && requestCode == SCAN_QR) {
;
} else {
;
}
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method doPrivKey.
private void doPrivKey(final String data) {
PrivKeyReader privKeyReader = null;
String format = null;
try {
privKeyReader = new PrivKeyReader(new CharSequenceX(data), null);
format = privKeyReader.getFormat();
} catch (Exception e) {
Toast.makeText(BalanceActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
if (format != null) {
if (format.equals(PrivKeyReader.BIP38)) {
final PrivKeyReader pvr = privKeyReader;
final EditText password38 = new EditText(BalanceActivity.this);
AlertDialog.Builder dlg = new AlertDialog.Builder(BalanceActivity.this).setTitle(R.string.app_name).setMessage(R.string.bip38_pw).setView(password38).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String password = password38.getText().toString();
ProgressDialog progress = new ProgressDialog(BalanceActivity.this);
progress.setCancelable(false);
progress.setTitle(R.string.app_name);
progress.setMessage(getString(R.string.decrypting_bip38));
progress.show();
boolean keyDecoded = false;
try {
BIP38PrivateKey bip38 = new BIP38PrivateKey(SamouraiWallet.getInstance().getCurrentNetworkParams(), data);
final ECKey ecKey = bip38.decrypt(password);
if (ecKey != null && ecKey.hasPrivKey()) {
if (progress != null && progress.isShowing()) {
progress.cancel();
}
pvr.setPassword(new CharSequenceX(password));
keyDecoded = true;
Toast.makeText(BalanceActivity.this, pvr.getFormat(), Toast.LENGTH_SHORT).show();
Toast.makeText(BalanceActivity.this, pvr.getKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(BalanceActivity.this, R.string.bip38_pw_error, Toast.LENGTH_SHORT).show();
}
if (progress != null && progress.isShowing()) {
progress.cancel();
}
if (keyDecoded) {
SweepUtil.getInstance(BalanceActivity.this).sweep(pvr, false);
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(BalanceActivity.this, R.string.bip38_pw_error, Toast.LENGTH_SHORT).show();
}
});
if (!isFinishing()) {
dlg.show();
}
} else if (privKeyReader != null) {
SweepUtil.getInstance(BalanceActivity.this).sweep(privKeyReader, false);
} else {
;
}
} else {
Toast.makeText(BalanceActivity.this, R.string.cannot_recognize_privkey, Toast.LENGTH_SHORT).show();
}
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class UTXODetailsActivity method saveWalletState.
private void saveWalletState() {
Disposable disposable = Completable.fromCallable(() -> {
try {
PayloadUtil.getInstance(getApplicationContext()).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(getApplicationContext()).getGUID() + AccessFactory.getInstance().getPIN()));
} catch (MnemonicException.MnemonicLengthException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (DecryptionException e) {
e.printStackTrace();
}
return true;
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe();
compositeDisposable.add(disposable);
}
Aggregations