Example usage for java.util Currency getInstance

List of usage examples for java.util Currency getInstance

Introduction

In this page you can find the example usage for java.util Currency getInstance.

Prototype

public static Currency getInstance(Locale locale) 

Source Link

Document

Returns the Currency instance for the country of the given locale.

Usage

From source file:org.gnucash.android.ui.transaction.dialog.SplitEditorDialogFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);

    getDialog().setTitle("Transaction splits");

    initArgs();//from  w w  w  .  ja va 2  s.  c  o m
    mSplitItemViewList = new ArrayList<View>();
    mSplitsDbAdapter = new SplitsDbAdapter(getActivity());

    //we are editing splits for a new transaction.
    // But the user may have already created some splits before. Let's check
    List<Split> splitList = ((TransactionFormFragment) getTargetFragment()).getSplitList();
    if (!splitList.isEmpty()) {
        //aha! there are some splits. Let's load those instead
        loadSplitViews(splitList);
    } else {
        final Currency currency = Currency.getInstance(mAccountsDbAdapter.getCurrencyCode(mAccountUID));
        Split split = new Split(new Money(mBaseAmount, currency), mAccountUID);
        AccountType accountType = mAccountsDbAdapter.getAccountType(mAccountUID);
        TransactionType transactionType = Transaction.getTypeForBalance(accountType, mBaseAmount.signum() < 0);
        split.setType(transactionType);
        View view = addSplitView(split);
        view.findViewById(R.id.input_accounts_spinner).setEnabled(false);
        view.findViewById(R.id.btn_remove_split).setVisibility(View.GONE);
    }

    setListeners();
    updateTotal();
}

From source file:com.aoindustries.creditcards.TransactionRequest.java

/**
 * Creates a TransactionRequest providing all of the details.
 *
 * @throws  IllegalArgumentException  if anything not valid
 *//*from ww  w. j a v  a 2  s .c o  m*/
public TransactionRequest(boolean testMode, String customerIp, int duplicateWindow, String orderNumber,
        Currency currency, BigDecimal amount, BigDecimal taxAmount, boolean taxExempt,
        BigDecimal shippingAmount, BigDecimal dutyAmount, String shippingFirstName, String shippingLastName,
        String shippingCompanyName, String shippingStreetAddress1, String shippingStreetAddress2,
        String shippingCity, String shippingState, String shippingPostalCode, String shippingCountryCode,
        boolean emailCustomer, String merchantEmail, String invoiceNumber, String purchaseOrderNumber,
        String description) {
    setTestMode(testMode);
    setCustomerIp(customerIp);
    setDuplicateWindow(duplicateWindow);
    setOrderNumber(orderNumber);
    if (currency == null)
        setCurrency(Currency.getInstance(accessor.getMessage("TransactionRequest.currency.default")));
    else
        setCurrency(currency);
    setAmount(amount);
    setTaxAmount(taxAmount);
    setTaxExempt(taxExempt);
    setShippingAmount(shippingAmount);
    setDutyAmount(dutyAmount);
    setShippingFirstName(shippingFirstName);
    setShippingLastName(shippingLastName);
    setShippingCompanyName(shippingCompanyName);
    setShippingStreetAddress1(shippingStreetAddress1);
    setShippingStreetAddress2(shippingStreetAddress2);
    setShippingCity(shippingCity);
    setShippingState(shippingState);
    setShippingPostalCode(shippingPostalCode);
    setShippingCountryCode(shippingCountryCode);
    setEmailCustomer(emailCustomer);
    setMerchantEmail(merchantEmail);
    setInvoiceNumber(invoiceNumber);
    setPurchaseOrderNumber(purchaseOrderNumber);
    setDescription(description);
}

From source file:org.gnucash.android.ui.report.LineChartFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(R.string.title_line_chart);
    setHasOptionsMenu(true);/*from w w w  . j ava 2s.c o  m*/

    mCurrency = Currency.getInstance(GnuCashApplication.getDefaultCurrencyCode());

    ReportsActivity reportsActivity = (ReportsActivity) getActivity();
    mReportStartTime = reportsActivity.getReportStartTime();
    mReportEndTime = reportsActivity.getReportEndTime();

    mChart.setOnChartValueSelectedListener(this);
    mChart.setDescription("");
    mChart.getXAxis().setDrawGridLines(false);
    mChart.getAxisRight().setEnabled(false);
    mChart.getAxisLeft().enableGridDashedLine(4.0f, 4.0f, 0);
    mChart.getAxisLeft().setValueFormatter(new LargeValueFormatter(mCurrency.getSymbol(Locale.getDefault())));

    // below we can add/remove displayed account's types
    mChart.setData(getData(new ArrayList<>(Arrays.asList(AccountType.INCOME, AccountType.EXPENSE))));

    Legend legend = mChart.getLegend();
    legend.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);
    legend.setTextSize(16);
    legend.setForm(Legend.LegendForm.CIRCLE);

    if (!mChartDataPresent) {
        mChart.getAxisLeft().setAxisMaxValue(10);
        mChart.getAxisLeft().setDrawLabels(false);
        mChart.getXAxis().setDrawLabels(false);
        mChart.setTouchEnabled(false);
        mChartSliceInfo.setText(getResources().getString(R.string.label_chart_no_data));
    } else {
        mChart.animateX(ANIMATION_DURATION);
    }
    mChart.invalidate();
}

From source file:ymanv.forex.web.RateController.java

private void addCurrenciesInfo(Page<? extends RateEntity> page) {
    for (RateEntity lr : page) {
        lr.setCountryCodeFrom(CurrencyUtils.codeForCurrency(lr.getFromcur()));

        if (CurrencyUtils.isValidCode(lr.getFromcur())) {
            String fromName = Currency.getInstance(lr.getFromcur()).getDisplayName(Locale.ENGLISH);
            lr.setFromName(fromName);// ww w .j  av a2s  .  c om
        }

        lr.setCountryCodeTo(CurrencyUtils.codeForCurrency(lr.getTocur()));

        if (CurrencyUtils.isValidCode(lr.getTocur())) {
            String toName = Currency.getInstance(lr.getTocur()).getDisplayName(Locale.ENGLISH);
            lr.setToName(toName);
        }
    }
}

From source file:org.gnucash.android.ui.report.BarChartFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(R.string.title_bar_chart);
    setHasOptionsMenu(true);//from  ww w.  j  a v a  2s  .c  om

    mUseAccountColor = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getBoolean(getString(R.string.key_use_account_color), false);

    mCurrency = Currency.getInstance(GnuCashApplication.getDefaultCurrencyCode());

    ReportsActivity reportsActivity = (ReportsActivity) getActivity();
    mReportStartTime = reportsActivity.getReportStartTime();
    mReportEndTime = reportsActivity.getReportEndTime();
    mAccountType = reportsActivity.getAccountType();

    mChart.setOnChartValueSelectedListener(this);
    mChart.setDescription("");
    //        mChart.setDrawValuesForWholeStack(false);
    mChart.getXAxis().setDrawGridLines(false);
    mChart.getAxisRight().setEnabled(false);
    mChart.getAxisLeft().enableGridDashedLine(4.0f, 4.0f, 0);
    mChart.getAxisLeft().setValueFormatter(new LargeValueFormatter(mCurrency.getSymbol(Locale.getDefault())));
    Legend chartLegend = mChart.getLegend();
    chartLegend.setForm(Legend.LegendForm.CIRCLE);
    chartLegend.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);
    chartLegend.setWordWrapEnabled(true);

    mChart.setData(getData());
    displayChart();
}

From source file:com.trenako.entities.Money.java

@Override
public String toString() {
    if (this == EMPTY_VALUE) {
        return "-";
    }/*from w  w w . j  a  v a 2  s .c  o m*/

    BigDecimal v = BigDecimal.valueOf(getValue()).divide(MONEY_VALUE_FACTOR);

    NumberFormat nf = NumberFormat.getCurrencyInstance();

    // the user may have selected a different currency than the default
    Currency currency = Currency.getInstance(getCurrency());
    nf.setCurrency(currency);
    nf.setMinimumFractionDigits(2);

    return nf.format(v);
}

From source file:org.mytms.common.web.RequestContext.java

/**
 * Returns the java.util.Currency constructed from the org.broadleafcommerce.common.currency.domain.BroadleafCurrency.
 * If there is no BroadleafCurrency specified this will return the currency based on the JVM locale
 *
 * @return/*from  w  w w  . jav  a2 s. c  o m*/
 */
public Currency getJavaCurrency() {
    if (javaCurrency == null) {
        try {
            javaCurrency = Currency.getInstance(getLocale());
        } catch (IllegalArgumentException e) {
            LOG.warn(
                    "There was an error processing the configured locale into the java currency. This is likely because the default"
                            + " locale is set to something like 'en' (which is NOT apart of ISO 3166 and does not have a currency"
                            + " associated with it) instead of 'en_US' (which IS apart of ISO 3166 and has a currency associated"
                            + " with it). Because of this, the currency is now set to the default locale of the JVM");
            LOG.warn(
                    "To fully resolve this, update the default entry in the BLC_LOCALE table to take into account the"
                            + " country code as well as the language. Alternatively, you could also update the BLC_CURRENCY table"
                            + " to contain a default currency.");
            javaCurrency = Currency.getInstance(Locale.getDefault());
        }
    }
    return javaCurrency;
}

From source file:com.myee.tarot.core.web.RequestContext.java

/**
 * Returns the java.util.Currency constructed from the org.broadleafcommerce.common.currency.domain.BroadleafCurrency.
 * If there is no BroadleafCurrency specified this will return the currency based on the JVM locale
 *
 * @return//  w  ww .ja  v  a2 s . c o m
 */
public Currency getJavaCurrency() {
    if (javaCurrency == null) {
        try {
            javaCurrency = Currency.getInstance(getLocale());
        } catch (IllegalArgumentException e) {
            LOG.warn(
                    "There was an error processing the configured locale into the java currency. This is likely because the default"
                            + " locale is set to something like 'en' (which is NOT apart of ISO 3166 and does not have a currency"
                            + " associated with it) instead of 'en_US' (which IS apart of ISO 3166 and has a currency associated"
                            + " with it). Because of this, the currency is now set to the default locale of the JVM");
            LOG.warn(
                    "To fully resolve this, update the default entry in the BLC_LOCALE table to take into account the"
                            + " country code as well as the language. Alternatively, you could also update the BLC_CURRENCY table"
                            + " to contain a default currency.");
            javaCurrency = Currency.getInstance(java.util.Locale.getDefault());
        }
    }
    return javaCurrency;
}

From source file:de.hybris.platform.integration.cis.payment.commands.DefaultCisSubscriptionAuthorizationCommandTest.java

@Test
public void shouldAuthorizeAndGetRejected() throws Exception {
    final RestResponse hpfUrl = this.paymentClient.pspUrl("http://test.cybersouce.com");
    final String testClientRef = "JUNIT-TEST-CLIENT";

    //here we create a profile through Cybersource SOP, this profile will be used for the test authorizations
    final List<BasicNameValuePair> validFormData = CisPaymentIntegrationTestHelper.getValidFormDataMap();
    final Map<String, String> profileCreationResponse = CisPaymentIntegrationTestHelper
            .createNewProfile(hpfUrl.getLocation().toASCIIString(), validFormData);
    final CreateSubscriptionResult subscriptionResult = getCreateSubscriptionResult(testClientRef,
            profileCreationResponse);/*from w  ww.  ja  v a 2  s . c o  m*/

    final BillingInfo billingInfo = createBillingInfo();
    final SubscriptionAuthorizationRequest request = new SubscriptionAuthorizationRequest(
            String.valueOf(System.currentTimeMillis()),
            subscriptionResult.getSubscriptionInfoData().getSubscriptionID(), Currency.getInstance("USD"),
            BigDecimal.valueOf(1500D), billingInfo, "cisCybersource");

    final CommandFactory commandFactory = commandFactoryRegistry.getFactory("cisCybersource");
    final SubscriptionAuthorizationCommand command = commandFactory
            .createCommand(SubscriptionAuthorizationCommand.class);

    final AuthorizationResult authResult;
    try {
        TestUtils.disableFileAnalyzer(
                "expected exception com.hybris.cis.api.exception.ServiceRequestException: 4015");
        authResult = command.perform(request);
    } finally {
        TestUtils.enableFileAnalyzer();
    }
    Assert.assertEquals(TransactionStatus.REJECTED, authResult.getTransactionStatus());
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static Currency getLocalCurrency() {
    Currency result = null;//ww w  . j a  v a  2  s.co  m
    TelephonyManager telephonyManager = (TelephonyManager) MyApplication.getInstance()
            .getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        try {
            String userCountry = telephonyManager.getNetworkCountryIso();
            if (TextUtils.isEmpty(userCountry)) {
                userCountry = telephonyManager.getSimCountryIso();
            }
            if (!TextUtils.isEmpty(userCountry)) {
                result = getSaveInstance(Currency.getInstance(new Locale("", userCountry)));
            }
        } catch (Exception e) {
            //fall back to currency from locale
        }
    }
    if (result == null) {
        try {
            //makeSure we know about the currency
            result = getSaveInstance(Currency.getInstance(Locale.getDefault()));
        } catch (IllegalArgumentException e) {
            result = Currency.getInstance("EUR");
        }
    }
    return result;
}