List of usage examples for java.text NumberFormat getCurrencyInstance
public static final NumberFormat getCurrencyInstance()
From source file:net.kjmaster.cookiemom.editor.EditDataActivity.java
private void populateTable(final List<CookieTransactions> cookieTransactionsList, Context mContext) { edit_data_table.setShrinkAllColumns(true); for (final CookieTransactions cookieTransactions : cookieTransactionsList) { if ((cookieTransactions.getTransBoxes() != 0) || (cookieTransactions.getTransCash() != 0)) { TableRow tr = new TableRow(mContext); tr.setTag(cookieTransactions); TextView textView = new TextView(mContext); textView.setText(java.text.DateFormat.getInstance().format(cookieTransactions.getTransDate())); textView.setEnabled(false);/*from ww w .j av a 2 s . c om*/ tr.addView(textView); TextView textView2 = new TextView(mContext); try { if (cookieTransactions.getTransScoutId() < 0) { if (cookieTransactions.getTransBoothId() > 0) { textView2.setText(cookieTransactions.getBooth().getBoothLocation()); } else { textView2.setText("Cupboard"); } } else { textView2.setText(cookieTransactions.getScout().getScoutName()); } } catch (Exception e) { textView2.setText(""); } textView2.setEnabled(false); tr.addView(textView2); TextView textView1 = new TextView(mContext); textView1.setText(cookieTransactions.getCookieType()); textView1.setEnabled(false); tr.addView(textView1); EditText textView3 = new EditText(mContext); textView3.setText(cookieTransactions.getTransBoxes().toString()); textView3.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { if (mActionMode == null) { startActionMode(actionCall); } } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { try { cookieTransactions.setTransBoxes(Integer.valueOf(editable.toString())); cookieTransactionsList.add(cookieTransactions); //Main.daoSession.getCookieTransactionsDao().update(cookieTransactions); } catch (Exception ignored) { } } }); tr.addView(textView3); EditText textView4 = new EditText(mContext); textView4.setText( NumberFormat.getCurrencyInstance().format(cookieTransactions.getTransCash().floatValue())); textView4.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { if (mActionMode == null) { startActionMode(actionCall); } } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { try { cookieTransactions.setTransCash(Double.valueOf(editable.toString())); cookieTransactionsList.add(cookieTransactions); } catch (Exception ignored) { } } }); tr.addView(textView4); edit_data_table.addView(tr); } } }
From source file:ro.expectations.expenses.ui.accounts.AccountsAdapter.java
@Override public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position);// w ww .j a v a2 s . c o m // Set the row background ListHelper.setItemBackground(mContext, holder.itemView, isItemSelected(position), holder.mAccountIconBackground, holder.mSelectedIconBackground); // Set the icon String type = mCursor.getString(mCursor.getColumnIndex(ExpensesContract.Accounts.TYPE)); AccountType accountType = AccountType.valueOf(type); if (accountType == AccountType.CREDIT_CARD || accountType == AccountType.DEBIT_CARD) { String issuer = mCursor.getString(mCursor.getColumnIndex(ExpensesContract.Accounts.SUBTYPE)); CardIssuer cardIssuer; if (issuer == null) { cardIssuer = CardIssuer.OTHER; } else { try { cardIssuer = CardIssuer.valueOf(issuer); } catch (final IllegalArgumentException ex) { cardIssuer = CardIssuer.OTHER; } } holder.mAccountIcon .setImageDrawable(DrawableHelper.tint(mContext, cardIssuer.iconId, R.color.colorWhite)); } else if (accountType == AccountType.ELECTRONIC) { String paymentType = mCursor.getString(mCursor.getColumnIndex(ExpensesContract.Accounts.SUBTYPE)); ElectronicPaymentType electronicPaymentType; if (paymentType == null) { electronicPaymentType = ElectronicPaymentType.OTHER; } else { try { electronicPaymentType = ElectronicPaymentType.valueOf(paymentType); } catch (IllegalArgumentException ex) { electronicPaymentType = ElectronicPaymentType.OTHER; } } holder.mAccountIcon.setImageDrawable( DrawableHelper.tint(mContext, electronicPaymentType.iconId, R.color.colorWhite)); } else { holder.mAccountIcon .setImageDrawable(DrawableHelper.tint(mContext, accountType.iconId, R.color.colorWhite)); } // Set the icon background color GradientDrawable bgShape = (GradientDrawable) holder.mAccountIconBackground.getBackground(); bgShape.setColor(0xFF000000 | ContextCompat.getColor(mContext, accountType.colorId)); // Set the description holder.mAccountDescription.setText(accountType.titleId); // Set the title String title = mCursor.getString(mCursor.getColumnIndex(ExpensesContract.Accounts.TITLE)); holder.mAccountTitle.setText(title); // Set the date long now = System.currentTimeMillis(); long lastTransactionAt = mCursor .getLong(mCursor.getColumnIndex(ExpensesContract.Accounts.LAST_TRANSACTION_AT)); if (lastTransactionAt == 0) { lastTransactionAt = mCursor.getLong(mCursor.getColumnIndex(ExpensesContract.Accounts.CREATED_AT)); } holder.mAccountLastTransactionAt .setText(DateUtils.getRelativeTimeSpanString(lastTransactionAt, now, DateUtils.DAY_IN_MILLIS)); // Set the account balance double balance = NumberUtils.roundToTwoPlaces( mCursor.getLong(mCursor.getColumnIndex(ExpensesContract.Accounts.BALANCE)) / 100.0); String currencyCode = mCursor.getString(mCursor.getColumnIndex(ExpensesContract.Accounts.CURRENCY)); Currency currency = Currency.getInstance(currencyCode); NumberFormat format = NumberFormat.getCurrencyInstance(); format.setCurrency(currency); format.setMaximumFractionDigits(currency.getDefaultFractionDigits()); holder.mAccountBalance.setText(format.format(balance)); if (balance > 0) { holder.mAccountBalance.setTextColor(ContextCompat.getColor(mContext, R.color.colorGreen700)); } else if (balance < 0) { holder.mAccountBalance.setTextColor(ContextCompat.getColor(mContext, R.color.colorRed700)); } }
From source file:org.oscarehr.managers.BillingONManager.java
public void sendInvoiceEmailNotification(Integer invoiceNo, Locale locale) { BillingONCHeader1 billingONCHeader1 = billingONCHeader1Dao.find(invoiceNo); if (billingONCHeader1 != null) { Integer demoNo = billingONCHeader1.getDemographicNo(); Demographic demographic = demographicDao.getDemographic(String.valueOf(demoNo)); String emailAddress = demographic.getEmail(); if (EmailUtilsOld.isValidEmailAddress(emailAddress)) { Clinic clinic = clinicDAO.getClinic(); //Get Due Date of Invoice String dueDateStr = ""; if (OscarProperties.getInstance().hasProperty("invoice_due_date")) { BillingONExt dueDateExt = billingONExtDao.getDueDate(billingONCHeader1); if (dueDateExt != null) { dueDateStr = dueDateExt.getValue(); } else { Integer numDaysTilDue = Integer .parseInt(OscarProperties.getInstance().getProperty("invoice_due_date", "0")); Date serviceDate = billingONCHeader1.getBillingDate(); dueDateStr = DateUtils.sumDate(serviceDate, numDaysTilDue, locale); }/* w w w. java2 s . c o m*/ } BillingONService billingONService = (BillingONService) SpringUtils.getBean("billingONService"); BigDecimal bdBalance = billingONService.calculateBalanceOwing(invoiceNo); //Compile email VelocityContext velocityContext = VelocityUtils.createVelocityContextWithTools(); velocityContext.put("clinic", clinic); velocityContext.put("demographic", demographic); velocityContext.put("billingONCHeader1", billingONCHeader1); String startHour = emailProperties.getProperty("clinic_open_hour", ""); velocityContext.put("start_hour", startHour); String endHour = emailProperties.getProperty("clinic_close_hour", ""); velocityContext.put("end_hour", endHour); velocityContext.put("date_due", dueDateStr); velocityContext.put("balance_owing", NumberFormat.getCurrencyInstance().format(bdBalance)); InputStream is = null; String emailTemplate = null; try { is = BillingInvoiceAction.class.getResourceAsStream(BILLING_INVOICE_EMAIL_TEMPLATE_FILE); emailTemplate = IOUtils.toString(is); } catch (java.io.IOException e) { MiscUtils.getLogger().error("Cannot read billing invoices email template:", e); } finally { try { if (is != null) is.close(); } catch (java.io.IOException e) { MiscUtils.getLogger().error("Cannot close billing invoice email template:", e); } } String fromAddress = emailProperties.getProperty("from_address", ""); String emailSubject = emailProperties.getProperty("billing_invoice_subject", ""); String mergedSubject = VelocityUtils.velocityEvaluate(velocityContext, emailSubject); String mergedBody = VelocityUtils.velocityEvaluate(velocityContext, emailTemplate); try { EmailUtilsOld.sendEmail(emailAddress, demographic.getFormattedName(), fromAddress, clinic.getClinicName(), mergedSubject, mergedBody, null); } catch (EmailException e) { MiscUtils.getLogger().error("Unexpected error.", e); } } else { MiscUtils.getLogger().warn("Email Address is invalid:" + emailAddress + " for DemoNo:" + demographic.getDemographicNo()); } } else { MiscUtils.getLogger().error( "Cannot find BillingONCHeader1 JPA entity for Invoice No." + invoiceNo + ". Email not sent"); } }
From source file:com.jaxzin.iraf.forecast.swing.JForecaster.java
@SuppressWarnings({ "FieldRepeatedlyAccessedInMethod" }) private void customizeChart(final JFreeChart chart) { // Set the transparency of the histogram bars // chart.getXYPlot().setForegroundAlpha(0.5f); // Lock the y-axis to 0.0->0.5 // Customize the y-logAxis logAxis = new LogarithmicAxis("Account Value"); logAxis.setAutoRange(true);/*from ww w. j a v a2 s. c o m*/ logAxis.setAllowNegativesFlag(true); logAxis.setNumberFormatOverride(NumberFormat.getCurrencyInstance()); linearAxis = new NumberAxis("Account Value"); linearAxis.setAutoRange(true); linearAxis.setNumberFormatOverride(NumberFormat.getCurrencyInstance()); //noinspection ConditionalExpression chart.getXYPlot().setRangeAxis(controlPanel.isLogScale() ? logAxis : linearAxis); // Customize the legend (add title, reverse order, attach to right side) final BlockContainer legendWrap = new BlockContainer(); final Block title = new LabelBlock("Percentiles"); legendWrap.setArrangement(new ColumnArrangement()); legendWrap.add(title); final LegendTitle legendTitle = new LegendTitle(new ReversedLegendItemSource(chart.getXYPlot()), new ColumnArrangement(), new ColumnArrangement()); legendWrap.add(legendTitle); chart.getLegend().setWrapper(legendWrap); chart.getLegend().setPosition(RectangleEdge.RIGHT); // Customize the format of the tooltips chart.getXYPlot().getRenderer().setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("yyyy"), NumberFormat.getCurrencyInstance())); }
From source file:br.com.OCTur.view.GraficoController.java
private void produtosMaisAntigos() { DefaultCategoryDataset dcdDados = new DefaultCategoryDataset(); for (EntidadeGrafico<Produto> entidadeGrafico : produto) { if (entidadeGrafico.getValue() >= slMeta.getValue()) { dcdDados.addValue(entidadeGrafico.getValue(), "Dias/Acima do esperado", entidadeGrafico.toString()); } else {//from ww w. j av a2 s .c om dcdDados.addValue(entidadeGrafico.getValue(), "Dias", entidadeGrafico.toString()); } } JFreeChart jFreeChart = ChartFactory.createBarChart(ControlTranducao.traduzirPalavra("PRODUTOSMAISANTIGOS"), "", "", dcdDados, PlotOrientation.VERTICAL, false, false, false); jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{0}", NumberFormat.getCurrencyInstance())); jFreeChart.getCategoryPlot() .addRangeMarker(new ValueMarker(slMeta.getValue(), Color.CYAN, new BasicStroke(1.0f))); ChartPanel chartPanel = new ChartPanel(jFreeChart); snProdutosMaisAntigos.setContent(chartPanel); }
From source file:com.formkiq.core.form.service.FormCalculatorServiceImpl.java
/** * Formats the value of a field./*from w ww . ja v a 2s.c o m*/ * * @param field {@link FormJSONField} * @return {@link String} */ private String applyFormatter(final FormJSONField field) { String value = field.getValue(); String format = field.getFormatter(); if (hasText(value)) { if (FormJSONFormatType.CURRENCY.eq(format)) { NumberFormat formatter = NumberFormat.getCurrencyInstance(); Matcher m = CURRENCY_TEXT_PATTERN.matcher(value); if (m.find()) { value = m.group(1); } value = formatter.format(Double.valueOf(value)); } } return value; }
From source file:com.dgsd.android.ShiftTracker.Fragment.WeekFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { switch (loader.getId()) { case LOADER_ID_TEMPLATES: mHasTemplates = cursor != null && cursor.getCount() > 0; break;// ww w . j av a2 s. c o m case LOADER_ID_SHIFTS: mAdapter.swapCursor(cursor); break; case LOADER_ID_TOTAL: if ((mShowHoursPref || mShowIncomePref) && cursor != null && cursor.moveToFirst()) { PayAndDuration pad = PayAndDuration.from(cursor); String payText = mShowIncomePref && pad.pay > 0 ? NumberFormat.getCurrencyInstance().format(pad.pay) : null; String hoursText = mShowHoursPref ? UIUtils.getDurationAsHours(pad.mins) : null; if (TextUtils.isEmpty(payText)) { if (TextUtils.isEmpty(hoursText)) { mStatsWrapper.setVisibility(View.GONE); } else { mStatsWrapper.setVisibility(View.VISIBLE); mTotalText.setText(hoursText); } } else { mStatsWrapper.setVisibility(View.VISIBLE); if (TextUtils.isEmpty(hoursText)) { mTotalText.setText(payText); } else { mTotalText.setText(payText + " / " + hoursText); } } } else { mTotalText.setText(BLANK_TOTAL_TEXT); if (!mShowHoursPref) { mStatsWrapper.setVisibility(View.GONE); } else { mStatsWrapper.setVisibility(View.VISIBLE); } } break; } }
From source file:ro.expectations.expenses.ui.transactions.TransactionsAdapter.java
private void processTransfer(ViewHolder holder, int position) { mCursor.moveToPosition(position);//from ww w . j av a2 s. c o m // Set the account String fromAccount = mCursor.getString(TransactionsFragment.COLUMN_FROM_ACCOUNT_TITLE); String toAccount = mCursor.getString(TransactionsFragment.COLUMN_TO_ACCOUNT_TITLE); holder.mAccount.setText(mContext.getResources().getString(R.string.breadcrumbs, fromAccount, toAccount)); // Set the amount NumberFormat format = NumberFormat.getCurrencyInstance(); String fromCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_FROM_CURRENCY); String toCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_TO_CURRENCY); if (fromCurrencyCode.equals(toCurrencyCode)) { double amount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT) / 100.0); Currency currency = Currency.getInstance(fromCurrencyCode); format.setCurrency(currency); format.setMaximumFractionDigits(currency.getDefaultFractionDigits()); holder.mAmount.setText(format.format(amount)); double fromBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_BALANCE) / 100.0); String fromBalanceFormatted = format.format(fromBalance); double toBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_BALANCE) / 100.0); holder.mRunningBalance.setText(mContext.getResources().getString(R.string.breadcrumbs, fromBalanceFormatted, format.format(toBalance))); } else { Currency fromCurrency = Currency.getInstance(fromCurrencyCode); format.setCurrency(fromCurrency); format.setMaximumFractionDigits(fromCurrency.getDefaultFractionDigits()); double fromAmount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT) / 100.0); String fromAmountFormatted = format.format(fromAmount); double fromBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_BALANCE) / 100.0); String fromBalanceFormatted = format.format(fromBalance); Currency toCurrency = Currency.getInstance(toCurrencyCode); format.setCurrency(toCurrency); format.setMaximumFractionDigits(toCurrency.getDefaultFractionDigits()); double toAmount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_AMOUNT) / 100.0); double toBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_BALANCE) / 100.0); holder.mAmount.setText(mContext.getResources().getString(R.string.breadcrumbs, fromAmountFormatted, format.format(toAmount))); holder.mRunningBalance.setText(mContext.getResources().getString(R.string.breadcrumbs, fromBalanceFormatted, format.format(toBalance))); } // Set the color for the amount and the transaction type icon if (mSelectedAccountId == 0) { holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorOrange700)); holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_swap_horiz_black_24dp, R.color.colorOrange700)); } else { long fromAccountId = mCursor.getLong(TransactionsFragment.COLUMN_FROM_ACCOUNT_ID); long toAccountId = mCursor.getLong(TransactionsFragment.COLUMN_TO_ACCOUNT_ID); if (mSelectedAccountId == fromAccountId) { holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorRed700)); holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_call_made_black_24dp, R.color.colorRed700)); } else if (mSelectedAccountId == toAccountId) { holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorGreen700)); holder.mTypeIcon.setImageDrawable(DrawableHelper.tint(mContext, R.drawable.ic_call_received_black_24dp, R.color.colorGreen700)); } } }
From source file:net.kjmaster.cookiemom.scout.ScoutFragment.java
private String getNumberFormatAsCash(Double amt) { NumberFormat fmt = NumberFormat.getCurrencyInstance(); fmt.setMaximumFractionDigits(0);/* ww w.j a v a 2 s . c om*/ fmt.setMinimumFractionDigits(0); return fmt.format(amt); }
From source file:com.concursive.connect.web.modules.login.utils.UserUtils.java
public static User createGuestUser() { User user = new User(); user.setId(-2);/*from w ww.j a v a 2 s.co m*/ user.setIdRange("-2"); user.setGroupId(1); user.setFirstName("Guest"); user.setEnabled(true); // @todo Use applicationPrefs for the correct defaults // Set a default time zone for user if (user.getTimeZone() == null) { user.setTimeZone(TimeZone.getDefault().getID()); } // Set a default currency for user if (user.getCurrency() == null) { user.setCurrency(NumberFormat.getCurrencyInstance().getCurrency().getCurrencyCode()); } // Set default locale: language, country if (user.getLanguage() == null) { user.setLanguage("en_US"); } return user; }