Example usage for java.util Currency getCurrencyCode

List of usage examples for java.util Currency getCurrencyCode

Introduction

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

Prototype

public String getCurrencyCode() 

Source Link

Document

Gets the ISO 4217 currency code of this currency.

Usage

From source file:com.money.manager.ex.database.MmxOpenHelper.java

private void initBaseCurrency(SQLiteDatabase db) {
    // currencies
    CurrencyService currencyService = new CurrencyService(getContext());
    Currency systemCurrency = currencyService.getSystemDefaultCurrency();
    if (systemCurrency == null)
        return;//from   w ww .  j  a  v  a2 s  .  co m

    InfoService infoService = new InfoService(getContext());

    // todo: try query generator.
    //        String sql = new Select()
    //                .select()
    //                .from(InfoRepositorySql.TABLE_NAME)
    //                .where(Info.INFONAME + "=?", InfoKeys.BASECURRENCYID)
    //                .toString();

    Cursor currencyCursor = db.rawQuery(
            "SELECT * FROM " + InfoRepositorySql.TABLE_NAME + " WHERE " + Info.INFONAME + "=?",
            new String[] { InfoKeys.BASECURRENCYID });
    if (currencyCursor == null)
        return;

    // Get id of the base currency record.
    int recordId = Constants.NOT_SET;
    boolean recordExists = currencyCursor.moveToFirst();
    if (recordExists) {
        recordId = currencyCursor.getInt(currencyCursor.getColumnIndex(Info.INFOID));
    }
    currencyCursor.close();

    // Use the system default currency.
    int currencyId = currencyService.loadCurrencyIdFromSymbolRaw(db, systemCurrency.getCurrencyCode());
    if (currencyId == Constants.NOT_SET) {
        // Use Euro by default.
        currencyId = 2;
    }

    UIHelper uiHelper = new UIHelper(getContext());

    // Insert/update base currency record into info table.
    if (!recordExists) {
        long newId = infoService.insertRaw(db, InfoKeys.BASECURRENCYID, currencyId);
        if (newId <= 0) {
            uiHelper.showToast("error inserting base currency on init");
        }
    } else {
        // Update the (by default empty) record to the default currency.
        long updatedRecords = infoService.updateRaw(db, recordId, InfoKeys.BASECURRENCYID, currencyId);
        if (updatedRecords <= 0) {
            uiHelper.showToast("error updating base currency on init");
        }
    }

    // Can't use provider here as the database is not ready.
    //            int currencyId = currencyService.loadCurrencyIdFromSymbol(systemCurrency.getCurrencyCode());
    //            String baseCurrencyId = infoService.getInfoValue(InfoService.BASECURRENCYID);
    //            if (!StringUtils.isEmpty(baseCurrencyId)) return;
    //            infoService.setInfoValue(InfoService.BASECURRENCYID, Integer.toString(currencyId));
}

From source file:com.TagFu.facebook.AppEventsLogger.java

/**
 * Logs a purchase event with Facebook, in the specified amount and with the specified currency. Additional detail
 * about the purchase can be passed in through the parameters bundle.
 *
 * @param purchaseAmount Amount of purchase, in the currency specified by the 'currency' parameter. This value will
 *            be rounded to the thousandths place (e.g., 12.34567 becomes 12.346).
 * @param currency Currency used to specify the amount.
 * @param parameters Arbitrary additional information for describing this event. Should have no more than 10
 *            entries, and keys should be mostly consistent from one purchase event to the next.
 */// w  w w.  ja va  2  s  .  c o m
public void logPurchase(final BigDecimal purchaseAmount, final Currency currency, Bundle parameters) {

    if (purchaseAmount == null) {
        notifyDeveloperError("purchaseAmount cannot be null");
        return;
    } else if (currency == null) {
        notifyDeveloperError("currency cannot be null");
        return;
    }

    if (parameters == null) {
        parameters = new Bundle();
    }
    parameters.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, currency.getCurrencyCode());

    this.logEvent(AppEventsConstants.EVENT_NAME_PURCHASED, purchaseAmount.doubleValue(), parameters);
    eagerFlush();
}

From source file:com.facebook.appevents.AppEventsLogger.java

/**
 * Logs a purchase event with Facebook, in the specified amount and with the specified currency.
 * Additional detail about the purchase can be passed in through the parameters bundle.
 *
 * @param purchaseAmount Amount of purchase, in the currency specified by the 'currency'
 *                       parameter. This value will be rounded to the thousandths place (e.g.,
 *                       12.34567 becomes 12.346).
 * @param currency       Currency used to specify the amount.
 * @param parameters     Arbitrary additional information for describing this event. This should
 *                       have no more than 10 entries, and keys should be mostly consistent from
 *                       one purchase event to the next.
 */// w  w  w. ja va  2  s .c  o  m
public void logPurchase(BigDecimal purchaseAmount, Currency currency, Bundle parameters) {

    if (purchaseAmount == null) {
        notifyDeveloperError("purchaseAmount cannot be null");
        return;
    } else if (currency == null) {
        notifyDeveloperError("currency cannot be null");
        return;
    }

    if (parameters == null) {
        parameters = new Bundle();
    }
    parameters.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, currency.getCurrencyCode());

    logEvent(AppEventsConstants.EVENT_NAME_PURCHASED, purchaseAmount.doubleValue(), parameters);
    eagerFlush();
}

From source file:org.openestate.io.idx.IdxRecord.java

public void setCurrency(Currency value) {
    this.set(FIELD_CURRENCY, (value != null) ? value.getCurrencyCode() : null);
}

From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data == null) {
        return;//from  w w  w  .  j a  va  2s  .c o m
    }
    int id = loader.getId();
    switch (id) {
    case METHODS_CURSOR:
        mMethodsCursor = data;
        View methodContainer = findViewById(R.id.MethodRow);
        if (mMethodsAdapter == null || !data.moveToFirst()) {
            methodContainer.setVisibility(View.GONE);
        } else {
            methodContainer.setVisibility(View.VISIBLE);
            MatrixCursor extras = new MatrixCursor(new String[] { KEY_ROWID, KEY_LABEL, KEY_IS_NUMBERED });
            extras.addRow(new String[] { "0", "- - - -", "0" });
            mMethodsAdapter.swapCursor(new MergeCursor(new Cursor[] { extras, data }));
            if (mSavedInstance) {
                mTransaction.methodId = mMethodId;
            }
            if (mTransaction.methodId != null) {
                while (data.isAfterLast() == false) {
                    if (data.getLong(data.getColumnIndex(KEY_ROWID)) == mTransaction.methodId) {
                        mMethodSpinner.setSelection(data.getPosition() + 1);
                        break;
                    }
                    data.moveToNext();
                }
            } else {
                mMethodSpinner.setSelection(0);
            }
        }
        break;
    case ACCOUNTS_CURSOR:
        mAccountsAdapter.swapCursor(data);
        mAccounts = new Account[data.getCount()];
        if (mSavedInstance) {
            mTransaction.accountId = mAccountId;
            mTransaction.transfer_account = mTransferAccountId;
        }
        data.moveToFirst();
        boolean selectionSet = false;
        String currencyExtra = getIntent().getStringExtra(KEY_CURRENCY);
        while (data.isAfterLast() == false) {
            int position = data.getPosition();
            Account a = Account.fromCacheOrFromCursor(data);
            mAccounts[position] = a;
            if (!selectionSet && (a.currency.getCurrencyCode().equals(currencyExtra)
                    || (currencyExtra == null && a.getId().equals(mTransaction.accountId)))) {
                mAccountSpinner.setSelection(position);
                setAccountLabel(a);
                selectionSet = true;
            }
            data.moveToNext();
        }
        //if the accountId we have been passed does not exist, we select the first entry
        if (mAccountSpinner.getSelectedItemPosition() == android.widget.AdapterView.INVALID_POSITION) {
            mAccountSpinner.setSelection(0);
            mTransaction.accountId = mAccounts[0].getId();
            setAccountLabel(mAccounts[0]);
        }
        if (mOperationType == MyExpenses.TYPE_TRANSFER) {
            mTransferAccountCursor = new FilterCursorWrapper(data);
            int selectedPosition = setTransferAccountFilterMap();
            mTransferAccountsAdapter.swapCursor(mTransferAccountCursor);
            mTransferAccountSpinner.setSelection(selectedPosition);
            mTransaction.transfer_account = mTransferAccountSpinner.getSelectedItemId();
            configureTransferInput();
            if (!mNewInstance && !(mTransaction instanceof Template)) {
                isProcessingLinkedAmountInputs = true;
                mTransferAmountText.setAmount(mTransaction.getTransferAmount().getAmountMajor().abs());
                updateExchangeRates();
                isProcessingLinkedAmountInputs = false;
            }
        } else {
            //the methods cursor is based on the current account,
            //hence it is loaded only after the accounts cursor is loaded
            if (!(mTransaction instanceof SplitPartCategory)) {
                mManager.initLoader(METHODS_CURSOR, null, this);
            }
        }
        mTypeButton.setEnabled(true);
        configureType();
        configureStatusSpinner();
        if (mIsResumed)
            setupListeners();
        break;
    case LAST_EXCHANGE_CURSOR:
        if (data.moveToFirst()) {
            final Currency currency1 = getCurrentAccount().currency;
            final Currency currency2 = Account
                    .getInstanceFromDb(mTransferAccountSpinner.getSelectedItemId()).currency;
            if (currency1.getCurrencyCode().equals(data.getString(0))
                    && currency2.getCurrencyCode().equals(data.getString(1))) {
                BigDecimal amount = new Money(currency1, data.getLong(2)).getAmountMajor();
                BigDecimal transferAmount = new Money(currency2, data.getLong(3)).getAmountMajor();
                BigDecimal exchangeRate = amount.compareTo(nullValue) != 0
                        ? transferAmount.divide(amount, EXCHANGE_RATE_FRACTION_DIGITS, RoundingMode.DOWN)
                        : nullValue;
                if (exchangeRate.compareTo(nullValue) != 0) {
                    mExchangeRate1Text.setAmount(exchangeRate);
                }
            }
        }
    }
}

From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java

private void configureTransferInput() {
    final Account transferAccount = Account.getInstanceFromDb(mTransferAccountSpinner.getSelectedItemId());
    final Currency currency = getCurrentAccount().currency;
    final boolean isSame = currency.equals(transferAccount.currency);
    findViewById(R.id.TransferAmountRow).setVisibility(isSame ? View.GONE : View.VISIBLE);
    findViewById(R.id.ExchangeRateRow)/*from ww w.j a  va 2  s.c  o  m*/
            .setVisibility(isSame || (mTransaction instanceof Template) ? View.GONE : View.VISIBLE);
    final String symbol2 = transferAccount.currency.getSymbol();
    //noinspection SetTextI18n
    addCurrencyToLabel((TextView) findViewById(R.id.TransferAmountLabel), symbol2);
    mTransferAmountText.setFractionDigits(Money.getFractionDigits(transferAccount.currency));
    final String symbol1 = currency.getSymbol();
    ((TextView) findViewById(R.id.ExchangeRateLabel_1_1)).setText(String.format("1 %s =", symbol1));
    ((TextView) findViewById(R.id.ExchangeRateLabel_1_2)).setText(symbol2);
    ((TextView) findViewById(R.id.ExchangeRateLabel_2_1)).setText(String.format("1 %s =", symbol2));
    ((TextView) findViewById(R.id.ExchangeRateLabel_2_2)).setText(symbol1);

    Bundle bundle = new Bundle(2);
    bundle.putStringArray(KEY_CURRENCY,
            new String[] { currency.getCurrencyCode(), transferAccount.currency.getCurrencyCode() });
    if (!isSame && !mSavedInstance && (mNewInstance || mPlanInstanceId == -1)
            && !(mTransaction instanceof Template)) {
        mManager.restartLoader(LAST_EXCHANGE_CURSOR, bundle, this);
    }
}