use of com.samourai.wallet.util.DecimalDigitsInputFilter in project samourai-wallet-android by Samourai-Wallet.
the class BatchSendActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_batchsend);
setTitle(R.string.options_batch);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
BatchSendActivity.this.getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
data = new ArrayList<BatchSendUtil.BatchSend>();
listView = (ListView) findViewById(R.id.list);
adapter = new BatchAdapter();
listView.setAdapter(adapter);
AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
;
}
};
tvMaxPrompt = (TextView) findViewById(R.id.max_prompt);
tvMax = (TextView) findViewById(R.id.max);
try {
balance = APIFactory.getInstance(BatchSendActivity.this).getXpubAmounts().get(HD_WalletFactory.getInstance(BatchSendActivity.this).get().getAccount(0).xpubstr());
} catch (IOException ioe) {
balance = 0L;
} catch (MnemonicException.MnemonicLengthException mle) {
balance = 0L;
} catch (java.lang.NullPointerException npe) {
balance = 0L;
}
displayBalance = balance;
final NumberFormat nf = NumberFormat.getInstance(Locale.US);
nf.setMaximumFractionDigits(8);
nf.setMinimumFractionDigits(1);
nf.setMinimumIntegerDigits(1);
tvMax.setText(nf.format(displayBalance / 1e8) + " " + getDisplayUnits());
tvMaxPrompt.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
edAmountBTC.setText(nf.format(displayBalance / 1e8));
return false;
}
});
tvMax.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
edAmountBTC.setText(nf.format(displayBalance / 1e8));
return false;
}
});
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
defaultSeparator = Character.toString(symbols.getDecimalSeparator());
edAddress = (EditText) findViewById(R.id.destination);
textWatcherAddress = new TextWatcher() {
public void afterTextChanged(Editable s) {
if (_menu != null) {
if (edAddress.getText().toString().length() > 0) {
_menu.findItem(R.id.action_scan_qr).setVisible(false);
} else {
_menu.findItem(R.id.action_scan_qr).setVisible(true);
}
}
validateSpend();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
;
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
;
}
};
edAddress.addTextChangedListener(textWatcherAddress);
edAddress.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() >= (edAddress.getRight() - edAddress.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
final List<String> entries = new ArrayList<String>();
entries.addAll(BIP47Meta.getInstance().getSortedByLabels(false));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(BatchSendActivity.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(BatchSendActivity.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) {
// Toast.makeText(BatchSendActivity.this, BIP47Meta.getInstance().getDisplayLabel(entries.get(which)), Toast.LENGTH_SHORT).show();
// Toast.makeText(BatchSendActivity.this, entries.get(which), Toast.LENGTH_SHORT).show();
processPCode(entries.get(which), null);
}
});
dlg.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dlg.show();
return true;
}
return false;
}
});
edAmountBTC = (EditText) findViewById(R.id.amountBTC);
edAmountBTC.setFilters(new InputFilter[] { new DecimalDigitsInputFilter(8, 8) });
textWatcherBTC = new TextWatcher() {
public void afterTextChanged(Editable s) {
edAmountBTC.removeTextChangedListener(this);
int max_len = 8;
NumberFormat btcFormat = NumberFormat.getInstance(Locale.US);
btcFormat.setMaximumFractionDigits(max_len + 1);
btcFormat.setMinimumFractionDigits(0);
double d = 0.0;
try {
d = NumberFormat.getInstance(Locale.US).parse(s.toString()).doubleValue();
String s1 = btcFormat.format(d);
if (s1.indexOf(defaultSeparator) != -1) {
String dec = s1.substring(s1.indexOf(defaultSeparator));
if (dec.length() > 0) {
dec = dec.substring(1);
if (dec.length() > max_len) {
edAmountBTC.setText(s1.substring(0, s1.length() - 1));
edAmountBTC.setSelection(edAmountBTC.getText().length());
s = edAmountBTC.getEditableText();
}
}
}
} catch (NumberFormatException nfe) {
;
} catch (ParseException pe) {
;
}
if (d > 21000000.0) {
edAmountBTC.setText("0");
edAmountBTC.setSelection(edAmountBTC.getText().length());
Toast.makeText(BatchSendActivity.this, R.string.invalid_amount, Toast.LENGTH_SHORT).show();
}
edAmountBTC.addTextChangedListener(this);
validateSpend();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
;
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
;
}
};
edAmountBTC.addTextChangedListener(textWatcherBTC);
validateSpend();
if (BatchSendUtil.getInstance().getSends().size() > 0) {
List<BatchSendUtil.BatchSend> sends = BatchSendUtil.getInstance().getSends();
for (BatchSendUtil.BatchSend send : sends) {
data.add(send);
displayBalance -= send.amount;
}
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
String strAmount = nf.format(displayBalance / 1e8);
tvMax.setText(strAmount + " " + getDisplayUnits());
if (_menu != null) {
_menu.findItem(R.id.action_scan_qr).setVisible(true);
_menu.findItem(R.id.action_refresh).setVisible(true);
_menu.findItem(R.id.action_new).setVisible(false);
_menu.findItem(R.id.action_send).setVisible(true);
}
}
}, 1000L);
}
}
use of com.samourai.wallet.util.DecimalDigitsInputFilter in project samourai-wallet-android by Samourai-Wallet.
the class ReceiveActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_receive);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
setTitle("");
advanceOptionsContainer = findViewById(R.id.container_advance_options);
tvAddress = findViewById(R.id.receive_address);
tvPath = findViewById(R.id.path);
addressTypesSpinner = findViewById(R.id.address_type_spinner);
ivQR = findViewById(R.id.qr);
advancedButton = findViewById(R.id.advance_button);
edAmountBTC = findViewById(R.id.amountBTC);
edAmountSAT = findViewById(R.id.amountSAT);
populateSpinner();
edAmountBTC.setFilters(new InputFilter[] { new DecimalDigitsInputFilter(8, 8) });
edAmountBTC.addTextChangedListener(BTCWatcher);
edAmountSAT.addTextChangedListener(satWatcher);
Display display = (ReceiveActivity.this).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
imgWidth = Math.max(size.x - 460, 150);
ivQR.setMaxWidth(imgWidth);
useSegwit = PrefsUtil.getInstance(ReceiveActivity.this).getValue(PrefsUtil.USE_SEGWIT, true);
advancedButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransitionManager.beginDelayedTransition(advanceOptionsContainer, new AutoTransition());
int visibility = advanceOptionsContainer.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE;
advanceOptionsContainer.setVisibility(visibility);
}
});
idx84 = BIP84Util.getInstance(ReceiveActivity.this).getWallet().getAccount(0).getChain(0).getAddrIdx();
idx49 = BIP49Util.getInstance(ReceiveActivity.this).getWallet().getAccount(0).getChain(0).getAddrIdx();
try {
idx44 = HD_WalletFactory.getInstance(ReceiveActivity.this).get().getAccount(0).getChain(0).getAddrIdx();
} catch (IOException | MnemonicException.MnemonicLengthException e) {
;
}
addr84 = AddressFactory.getInstance(ReceiveActivity.this).getBIP84(AddressFactory.RECEIVE_CHAIN).getBech32AsString();
addr49 = AddressFactory.getInstance(ReceiveActivity.this).getBIP49(AddressFactory.RECEIVE_CHAIN).getAddressAsString();
addr44 = AddressFactory.getInstance(ReceiveActivity.this).get(AddressFactory.RECEIVE_CHAIN).getAddressString();
if (useSegwit && isBIP84Selected()) {
addr = addr84;
} else if (useSegwit && !isBIP84Selected()) {
addr = addr49;
} else {
addr = addr44;
}
addressTypesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position) {
case 0:
{
addr = addr49;
break;
}
case 1:
{
addr = addr84;
break;
}
case 2:
{
addr = addr44;
break;
}
default:
{
addr = addr49;
}
}
displayQRCode();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
;
}
});
if (useSegwit) {
addressTypesSpinner.setSelection(1);
} else {
addressTypesSpinner.setSelection(2);
}
tvAddress.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
new AlertDialog.Builder(ReceiveActivity.this).setTitle(R.string.app_name).setMessage(R.string.receive_address_to_clipboard).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ReceiveActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = null;
clip = android.content.ClipData.newPlainText("Receive address", addr);
clipboard.setPrimaryClip(clip);
Toast.makeText(ReceiveActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}).show();
return false;
}
});
ivQR.setOnTouchListener(new OnSwipeTouchListener(ReceiveActivity.this) {
@Override
public void onSwipeLeft() {
if (useSegwit && isBIP84Selected() && canRefresh84) {
addr84 = AddressFactory.getInstance(ReceiveActivity.this).getBIP84(AddressFactory.RECEIVE_CHAIN).getBech32AsString();
addr = addr84;
canRefresh84 = false;
_menu.findItem(R.id.action_refresh).setVisible(false);
displayQRCode();
} else if (useSegwit && !isBIP84Selected() && canRefresh49) {
addr49 = AddressFactory.getInstance(ReceiveActivity.this).getBIP49(AddressFactory.RECEIVE_CHAIN).getAddressAsString();
addr = addr49;
canRefresh49 = false;
_menu.findItem(R.id.action_refresh).setVisible(false);
displayQRCode();
} else if (!useSegwit && canRefresh44) {
addr44 = AddressFactory.getInstance(ReceiveActivity.this).get(AddressFactory.RECEIVE_CHAIN).getAddressString();
addr = addr44;
canRefresh44 = false;
_menu.findItem(R.id.action_refresh).setVisible(false);
displayQRCode();
} else {
;
}
}
});
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
defaultSeparator = Character.toString(symbols.getDecimalSeparator());
displayQRCode();
}
use of com.samourai.wallet.util.DecimalDigitsInputFilter in project samourai-wallet-android by Samourai-Wallet.
the class SendActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send);
setSupportActionBar(findViewById(R.id.toolbar_send));
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
setTitle("");
// CustomView for showing and hiding body of th UI
sendTransactionDetailsView = findViewById(R.id.sendTransactionDetailsView);
// ViewSwitcher Element for toolbar section of the UI.
// we can switch between Form and review screen with this element
amountViewSwitcher = findViewById(R.id.toolbar_view_switcher);
// Input elements from toolbar section of the UI
toAddressEditText = findViewById(R.id.edt_send_to);
btcEditText = findViewById(R.id.amountBTC);
satEditText = findViewById(R.id.amountSat);
tvToAddress = findViewById(R.id.to_address_review);
tvReviewSpendAmount = findViewById(R.id.send_review_amount);
tvReviewSpendAmountInSats = findViewById(R.id.send_review_amount_in_sats);
tvMaxAmount = findViewById(R.id.totalBTC);
// view elements from review segment and transaction segment can be access through respective
// methods which returns root viewGroup
btnReview = sendTransactionDetailsView.getTransactionView().findViewById(R.id.review_button);
cahootsSwitch = sendTransactionDetailsView.getTransactionView().findViewById(R.id.cahoots_switch);
ricochetHopsSwitch = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_hops_switch);
ricochetTitle = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_desc);
ricochetDesc = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_title);
ricochetStaggeredDelivery = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_staggered_option);
ricochetStaggeredOptionGroup = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_staggered_option_group);
tvSelectedFeeRate = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.selected_fee_rate);
tvSelectedFeeRateLayman = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.selected_fee_rate_in_layman);
tvTotalFee = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.total_fee);
btnSend = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.send_btn);
feeSeekBar = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.fee_seekbar);
tvEstimatedBlockWait = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.est_block_time);
feeSeekBar = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.fee_seekbar);
cahootsGroup = sendTransactionDetailsView.findViewById(R.id.cohoots_options);
cahootsStatusText = sendTransactionDetailsView.findViewById(R.id.cahoot_status_text);
totalMinerFeeLayout = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.total_miner_fee_group);
cahootsNotice = sendTransactionDetailsView.findViewById(R.id.cahoots_not_enabled_notice);
btcEditText.addTextChangedListener(BTCWatcher);
btcEditText.setFilters(new InputFilter[] { new DecimalDigitsInputFilter(8, 8) });
satEditText.addTextChangedListener(satWatcher);
toAddressEditText.addTextChangedListener(AddressWatcher);
btnReview.setOnClickListener(v -> review());
btnSend.setOnClickListener(v -> initiateSpend());
View.OnClickListener clipboardCopy = view -> {
ClipboardManager cm = (ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = android.content.ClipData.newPlainText("Miner fee", tvTotalFee.getText());
if (cm != null) {
cm.setPrimaryClip(clipData);
Toast.makeText(this, getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
}
};
tvTotalFee.setOnClickListener(clipboardCopy);
tvSelectedFeeRate.setOnClickListener(clipboardCopy);
SPEND_TYPE = SPEND_BOLTZMANN;
saveChangeIndexes();
setUpRicochet();
setUpCahoots();
setUpFee();
setBalance();
enableReviewButton(false);
setUpBoltzman();
validateSpend();
checkDeepLinks();
if (getIntent().getExtras().containsKey("preselected")) {
preselectedUTXOs = PreSelectUtil.getInstance().getPreSelected(getIntent().getExtras().getString("preselected"));
setBalance();
if (preselectedUTXOs != null && preselectedUTXOs.size() > 0) {
cahootsGroup.setVisibility(View.GONE);
ricochetHopsSwitch.setVisibility(View.GONE);
ricochetTitle.setVisibility(View.GONE);
ricochetDesc.setVisibility(View.GONE);
}
} else {
Disposable disposable = APIFactory.getInstance(getApplicationContext()).walletBalanceObserver.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(aLong -> {
if (balance == aLong) {
return;
}
setBalance();
}, Throwable::printStackTrace);
compositeDisposables.add(disposable);
// Update fee
Disposable feeDisposable = Observable.fromCallable(() -> APIFactory.getInstance(getApplicationContext()).getDynamicFees()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(t -> {
Log.i(TAG, "Fees : ".concat(t.toString()));
setUpFee();
}, Throwable::printStackTrace);
compositeDisposables.add(feeDisposable);
if (getIntent().getExtras() != null) {
if (!getIntent().getExtras().containsKey("balance")) {
return;
}
balance = getIntent().getExtras().getLong("balance");
}
}
}
Aggregations