protected BigDecimal validateAmountInput(AmountEditText input, boolean showToUser) { String strAmount = input.getText().toString(); if (strAmount.equals("")) { if (showToUser) input.setError(getString(R.string.no_amount_given)); return null; } BigDecimal amount = Utils.validateNumber(input.getNumberFormat(), strAmount); if (amount == null) { if (showToUser) input.setError( getString(R.string.invalid_number_format, input.getNumberFormat().format(11.11))); return null; } return amount; }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK && requestCode == CALCULATOR_REQUEST && intent != null) { try { AmountEditText input = (AmountEditText) findViewById(intent.getIntExtra(CalculatorInput.EXTRA_KEY_INPUT_ID, 0)); input.setAmount(new BigDecimal(intent.getStringExtra(KEY_AMOUNT))); input.setError(null); } catch (Exception e) { AcraHelper.report(e); } } }
protected void showCalculatorInternal(AmountEditText input) { Intent intent = new Intent(this, CalculatorInput.class); forwardDataEntryFromWidget(intent); BigDecimal amount = validateAmountInput(input, false); if (amount != null) { intent.putExtra(KEY_AMOUNT, amount); } intent.putExtra(CalculatorInput.EXTRA_KEY_INPUT_ID, input.getId()); startActivityForResult(intent, CALCULATOR_REQUEST); }
protected void setupListeners() { mAmountText.addTextChangedListener(this); mTypeButton.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { onTypeChanged(isChecked); } }); }