Example usage for android.database MatrixCursor newRow

List of usage examples for android.database MatrixCursor newRow

Introduction

In this page you can find the example usage for android.database MatrixCursor newRow.

Prototype

public RowBuilder newRow() 

Source Link

Document

Adds a new row to the end and returns a builder for that row.

Usage

From source file:de.schildbach.wallet.data.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null;

    if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS)) {
        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;/*from   ww  w .  j av  a  2  s .  co  m*/

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE_COIN, KEY_RATE_FIAT, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(QUERY_PARAM_Q)) {
        final String selectionArg = selectionArgs[0].toLowerCase(Locale.US);
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            final String currencySymbol = GenericUtils.currencySymbol(currencyCode);
            if (currencyCode.toLowerCase(Locale.US).contains(selectionArg)
                    || currencySymbol.toLowerCase(Locale.US).contains(selectionArg))
                cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                        .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate exchangeRate = bestExchangeRate(selectionArg);
        if (exchangeRate != null) {
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    }

    return cursor;
}

From source file:de.schildbach.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null;

    if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS)) {
        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, userAgent, BITCOINAVERAGE_SOURCE,
                    BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, userAgent, BLOCKCHAININFO_SOURCE,
                    BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//from ww  w.  j  a  v  a 2s . c  o  m

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE_COIN, KEY_RATE_FIAT, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(QUERY_PARAM_Q)) {
        final String selectionArg = selectionArgs[0].toLowerCase(Locale.US);
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            final String currencySymbol = GenericUtils.currencySymbol(currencyCode);
            if (currencyCode.toLowerCase(Locale.US).contains(selectionArg)
                    || currencySymbol.toLowerCase(Locale.US).contains(selectionArg))
                cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                        .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate exchangeRate = bestExchangeRate(selectionArg);
        if (exchangeRate != null) {
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    }

    return cursor;
}

From source file:com.cannabiscoin.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) {
        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, userAgent, BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, userAgent, BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//from  w w  w .j  a v  a2  s  .  com

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(QUERY_PARAM_Q)) {
        final String selectionArg = selectionArgs[0].toLowerCase(Locale.US);
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            final String currencyCode = rate.currencyCode;
            final String currencySymbol = GenericUtils.currencySymbol(currencyCode);
            if (currencyCode.toLowerCase(Locale.US).contains(selectionArg)
                    || currencySymbol.toLowerCase(Locale.US).contains(selectionArg))
                cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.rate.longValue())
                        .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate rate = bestExchangeRate(selectionArg);
        if (rate != null)
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
    }

    return cursor;
}

From source file:de.langerhans.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();
    int provider = config.getExchangeProvider();
    boolean forceRefresh = config.getExchangeForceRefresh();
    if (forceRefresh) {
        config.setExchangeForceRefresh(false);
    }/*  www  . j a  v  a2  s. c om*/

    final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null;

    if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) || forceRefresh) {
        double newDogeBtcConversion = -1;
        if ((dogeBtcConversion == -1 && newDogeBtcConversion == -1) || forceRefresh)
            newDogeBtcConversion = requestDogeBtcConversion(provider);

        if (newDogeBtcConversion != -1)
            dogeBtcConversion = newDogeBtcConversion;

        if (dogeBtcConversion == -1)
            return null;

        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, dogeBtcConversion, userAgent,
                    BITCOINAVERAGE_SOURCE, BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, dogeBtcConversion, userAgent,
                    BLOCKCHAININFO_SOURCE, BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            String providerUrl;
            switch (provider) {
            case 0:
                providerUrl = "http://www.cryptsy.com";
                break;
            case 1:
                providerUrl = "http://www.bter.com";
                break;
            default:
                providerUrl = "";
                break;
            }
            double mBTCRate = dogeBtcConversion * 1000;
            String strmBTCRate = String.format(Locale.US, "%.4f", mBTCRate).replace(',', '.');
            newExchangeRates.put("mBTC",
                    new ExchangeRate(
                            new com.dogecoin.dogecoinj.utils.ExchangeRate(Fiat.parseFiat("mBTC", strmBTCRate)),
                            providerUrl));
            newExchangeRates.put("DOGE",
                    new ExchangeRate(new com.dogecoin.dogecoinj.utils.ExchangeRate(Fiat.parseFiat("DOGE", "1")),
                            "priceofdoge.com"));
            exchangeRates = newExchangeRates;
            lastUpdated = now;

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null || dogeBtcConversion == -1)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE_COIN, KEY_RATE_FIAT, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final com.dogecoin.dogecoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(QUERY_PARAM_Q)) {
        final String selectionArg = selectionArgs[0].toLowerCase(Locale.US);
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final com.dogecoin.dogecoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            final String currencySymbol = GenericUtils.currencySymbol(currencyCode);
            if (currencyCode.toLowerCase(Locale.US).contains(selectionArg)
                    || currencySymbol.toLowerCase(Locale.US).contains(selectionArg))
                cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                        .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate exchangeRate = bestExchangeRate(selectionArg);
        if (exchangeRate != null) {
            final com.dogecoin.dogecoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    }

    return cursor;
}

From source file:com.seafile.seadroid2.provider.SeafileProvider.java

/**
 * Add a cursor entry for the account base document_id.
 *
 * @param result the cursor to write the row into.
 * @param account the account to add.//from   w  w  w.j av  a 2 s.  c  o m
 */
private void includeDocIdRoot(MatrixCursor result, Account account) {
    String docId = DocumentIdParser.buildId(account, null, null);

    final MatrixCursor.RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME, account.getServerHost());
    row.add(Document.COLUMN_LAST_MODIFIED, null);
    row.add(Document.COLUMN_FLAGS, 0);
    row.add(Document.COLUMN_ICON, R.drawable.ic_launcher);
    row.add(Document.COLUMN_SIZE, null);
    row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
}

From source file:com.ichi2.anki.provider.CardContentProvider.java

private void addReviewInfoToCursor(Card currentCard, JSONArray nextReviewTimesJson, int buttonCount,
        MatrixCursor rv, Collection col, String[] columns) {
    MatrixCursor.RowBuilder rb = rv.newRow();
    for (String column : columns) {
        if (column.equals(FlashCardsContract.Card.NOTE_ID)) {
            rb.add(currentCard.note().getId());
        } else if (column.equals(FlashCardsContract.ReviewInfo.CARD_ORD)) {
            rb.add(currentCard.getOrd());
        } else if (column.equals(FlashCardsContract.ReviewInfo.BUTTON_COUNT)) {
            rb.add(buttonCount);//w w w  .j  ava  2  s  .  com
        } else if (column.equals(FlashCardsContract.ReviewInfo.NEXT_REVIEW_TIMES)) {
            rb.add(nextReviewTimesJson.toString());
        } else if (column.equals(FlashCardsContract.ReviewInfo.MEDIA_FILES)) {
            rb.add(new JSONArray(
                    col.getMedia().filesInStr(currentCard.note().getMid(), currentCard.q() + currentCard.a())));
        } else {
            throw new UnsupportedOperationException("Column \"" + column + "\" is unknown");
        }
    }
}

From source file:com.seafile.seadroid2.provider.SeafileProvider.java

private void includeStarredFilesRepo(MatrixCursor result, Account account) {
    String docId = DocumentIdParser.buildStarredFilesId(account);

    final MatrixCursor.RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);

    row.add(Document.COLUMN_DISPLAY_NAME,
            SeadroidApplication.getAppContext().getResources().getString(R.string.tabs_starred));
    row.add(Document.COLUMN_ICON, R.drawable.star_normal);
    row.add(Document.COLUMN_FLAGS, 0);

    if (!reachableAccounts.contains(account)) {
        row.add(Document.COLUMN_MIME_TYPE, null); // undocumented: will grey out the entry
    } else {/*from   w  w  w  .j a v a2  s . c  o  m*/
        row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
    }

}

From source file:de.schildbach.wallet.goldcoin.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    if (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) {
        Map<String, ExchangeRate> newExchangeRates = getBitcoinCharts();//getLitecoinCharts();

        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getBlockchainInfo();

        if (newExchangeRates == null)
            newExchangeRates = getLitecoinCharts();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//from   w w  w.  j a v a 2 s  .c  om
        }
    }

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(entry.getKey().hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String code = selectionArgs[0];
        final ExchangeRate rate = exchangeRates.get(code);
        try {
            cursor.newRow().add(code.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        } catch (NullPointerException e) {
            Log.e("GoldCoin", "Unable to add an exchange rate.  NullPointerException.");
        }
    }

    return cursor;
}

From source file:com.ichi2.anki.provider.CardContentProvider.java

private void addDeckToCursor(long id, String name, JSONArray deckCounts, MatrixCursor rv, Collection col,
        String[] columns) {//ww w .j av a2 s  .  c om
    MatrixCursor.RowBuilder rb = rv.newRow();
    for (String column : columns) {
        if (column.equals(FlashCardsContract.Deck.DECK_NAME)) {
            rb.add(name);
        } else if (column.equals(FlashCardsContract.Deck.DECK_ID)) {
            rb.add(id);
        } else if (column.equals(FlashCardsContract.Deck.DECK_COUNTS)) {
            rb.add(deckCounts);
        } else if (column.equals(FlashCardsContract.Deck.OPTIONS)) {
            String config = col.getDecks().confForDid(id).toString();
            rb.add(config);
        }
    }
}

From source file:com.ichi2.anki.provider.CardContentProvider.java

private void addTemplateToCursor(JSONObject tmpl, JSONObject model, int id, MatrixCursor rv, String[] columns) {
    try {//from  w ww.  j av a2  s  .c o  m
        MatrixCursor.RowBuilder rb = rv.newRow();
        for (String column : columns) {
            if (column.equals(CardTemplate._ID)) {
                rb.add(id);
            } else if (column.equals(CardTemplate.MODEL_ID)) {
                rb.add(model.getLong("id"));
            } else if (column.equals(CardTemplate.ORD)) {
                rb.add(tmpl.getInt("ord"));
            } else if (column.equals(CardTemplate.NAME)) {
                rb.add(tmpl.getString("name"));
            } else if (column.equals(CardTemplate.QUESTION_FORMAT)) {
                rb.add(tmpl.getString("qfmt"));
            } else if (column.equals(CardTemplate.ANSWER_FORMAT)) {
                rb.add(tmpl.getString("afmt"));
            } else if (column.equals(CardTemplate.BROWSER_QUESTION_FORMAT)) {
                rb.add(tmpl.getString("bqfmt"));
            } else if (column.equals(CardTemplate.BROWSER_ANSWER_FORMAT)) {
                rb.add(tmpl.getString("bafmt"));
            } else {
                throw new UnsupportedOperationException(
                        "Support for column \"" + column + "\" is not implemented");
            }
        }
    } catch (JSONException e) {
        Timber.e(e, "Error adding template to cursor");
        throw new IllegalArgumentException("Template is malformed", e);
    }
}