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:com.example.android.vault.VaultProvider.java

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    final RowBuilder row = result.newRow();
    row.add(Root.COLUMN_ROOT_ID, DEFAULT_ROOT_ID);
    row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY);
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_label));
    row.add(Root.COLUMN_DOCUMENT_ID, DEFAULT_DOCUMENT_ID);
    row.add(Root.COLUMN_ICON, R.drawable.ic_lock_lock);

    // Notify user in storage UI when key isn't hardware-backed
    if (!mHardwareBacked) {
        row.add(Root.COLUMN_SUMMARY, getContext().getString(R.string.info_software));
    }/*  www .  j a v  a2 s.  co m*/

    return result;
}

From source file:com.feathercoin.wallet.feathercoin.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 = getFeathercoinCharts();
        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getBlockchainInfo();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//  www .j  av a2  s.  c  o  m
        }
    }

    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("Feathercoin", "Unable to add an exchange rate.  NullPointerException.");
        }
    }

    return cursor;
}

From source file:de.schildbach.wallet.worldcoin.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 = getworldcoinCharts();
        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getBlockchainInfo();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//w w w  . ja  va  2  s .  c  o  m
        }
    }

    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("worldcoin", "Unable to add an exchange rate.  NullPointerException.");
        }
    }

    return cursor;
}

From source file:org.sufficientlysecure.privacybox.VaultProvider.java

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    final RowBuilder row = result.newRow();
    row.add(Root.COLUMN_ROOT_ID, DEFAULT_ROOT_ID);
    row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY);
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_label));
    row.add(Root.COLUMN_DOCUMENT_ID, DEFAULT_DOCUMENT_ID);
    row.add(Root.COLUMN_ICON, R.drawable.ic_launcher);

    row.add(Root.COLUMN_SUMMARY, "todo: display user id?");

    return result;
}

From source file:ja.ohac.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_SOURCE,
                    BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, userAgent, BLOCKCHAININFO_SOURCE,
                    BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;/*  w w w .  j a v  a 2s .  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, 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:com.bushstar.htmlcoin_android_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(userAgent);

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//from  w  w  w  .j  a  va  2 s  . 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, 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:com.raspi.chatapp.util.storage.file.LocalStorageProvider.java

@Override
public Cursor queryRoots(final String[] projection) throws FileNotFoundException {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (getContext() == null || ContextCompat.checkSelfPermission(getContext(),
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            return null;
        }//from w  w w  . j a v a2s. c om
        // Create a cursor with either the requested fields, or the default projection if "projection" is null.
        final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
        // Add Home directory
        File homeDir = Environment.getExternalStorageDirectory();
        if (TextUtils.equals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED)) {
            final MatrixCursor.RowBuilder row = result.newRow();
            // These columns are required
            row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
            row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
            row.add(Root.COLUMN_TITLE, getContext().getString(R.string.home));
            row.add(Root.COLUMN_FLAGS,
                    Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD);
            row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);
            // These columns are optional
            row.add(Root.COLUMN_SUMMARY, homeDir.getAbsolutePath());
            row.add(Root.COLUMN_AVAILABLE_BYTES, new StatFs(homeDir.getAbsolutePath()).getAvailableBytes());
            // Root.COLUMN_MIME_TYPE is another optional column and useful if you have multiple roots with different
            // types of mime types (roots that don't match the requested mime type are automatically hidden)
        }
        // Add SD card directory
        File sdCard = new File("/storage/extSdCard");
        String storageState = EnvironmentCompat.getStorageState(sdCard);
        if (TextUtils.equals(storageState, Environment.MEDIA_MOUNTED)
                || TextUtils.equals(storageState, Environment.MEDIA_MOUNTED_READ_ONLY)) {
            final MatrixCursor.RowBuilder row = result.newRow();
            // These columns are required
            row.add(Root.COLUMN_ROOT_ID, sdCard.getAbsolutePath());
            row.add(Root.COLUMN_DOCUMENT_ID, sdCard.getAbsolutePath());
            row.add(Root.COLUMN_TITLE, getContext().getString(R.string.sd_card));
            // Always assume SD Card is read-only
            row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY);
            row.add(Root.COLUMN_ICON, R.drawable.ic_sd_card);
            row.add(Root.COLUMN_SUMMARY, sdCard.getAbsolutePath());
            row.add(Root.COLUMN_AVAILABLE_BYTES, new StatFs(sdCard.getAbsolutePath()).getAvailableBytes());
        }
        return result;
    } else
        return null;
}

From source file:hashengineering.digitalcoin.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 (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) {
        Map<String, ExchangeRate> newExchangeRates = getBitcoinCharts();
        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getBlockchainInfo();

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

    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(KEY_CURRENCY_CODE)) {
        final String selectedCode = selectionArgs[0];
        ExchangeRate rate = selectedCode != null ? exchangeRates.get(selectedCode) : null;

        if (rate == null) {
            final String defaultCode = defaultCurrencyCode();
            rate = defaultCode != null ? exchangeRates.get(defaultCode) : null;

            if (rate == null) {
                rate = exchangeRates.get(Constants.DEFAULT_EXCHANGE_CURRENCY);

                if (rate == null)
                    return null;
            }
        }

        cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                .add(rate.source);
    }

    return cursor;
}

From source file:com.dopecoin.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();
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
    int provider = Integer.parseInt(sp.getString(Constants.PREFS_KEY_EXCHANGE_PROVIDER, "0"));
    boolean forceRefresh = sp.getBoolean(Constants.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false);
    if (forceRefresh)
        sp.edit().putBoolean(Constants.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false).commit();

    if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) {
        float newDogeBtcConversion = -1;
        if ((leafBtcConversion == -1 && newDogeBtcConversion == -1) || forceRefresh)
            newDogeBtcConversion = requestDogeBtcConversion(provider);

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

        if (leafBtcConversion == -1)
            return null;

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

        if (newExchangeRates != null) {
            String providerUrl;/*from www .  j  a v  a 2  s.  c  o  m*/
            switch (provider) {
            case 0:
                providerUrl = "http://www.cryptsy.com";
                break;
            case 1:
                providerUrl = "http://www.vircurex.com";
                break;
            default:
                providerUrl = "";
                break;
            }
            float mBTCRate = leafBtcConversion * 1000;
            String strmBTCRate = String.format("%.5f", mBTCRate).replace(',', '.');
            newExchangeRates.put("mBTC", new ExchangeRate("mBTC",
                    new BigDecimal(GenericUtils.toNanoCoins(strmBTCRate, 0)).toBigInteger(), providerUrl));
            exchangeRates = newExchangeRates;
            lastUpdated = now;

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

    if (exchangeRates == null || leafBtcConversion == -1)
        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(KEY_CURRENCY_CODE)) {
        final ExchangeRate rate = bestExchangeRate(selectionArgs[0]);
        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.jdellay.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();
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
    int provider = Integer.parseInt(sp.getString(Configuration.PREFS_KEY_EXCHANGE_PROVIDER, "0"));
    boolean forceRefresh = sp.getBoolean(Configuration.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false);
    if (forceRefresh)
        sp.edit().putBoolean(Configuration.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false).commit();

    if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) {
        float newCcnBtcConversion = -1;
        if ((ccnBtcConversion == -1 && newCcnBtcConversion == -1) || forceRefresh)
            newCcnBtcConversion = requestCcnBtcConversion(provider);

        if (newCcnBtcConversion != -1)
            ccnBtcConversion = newCcnBtcConversion;

        if (CCNBtcConversion == -1)
            return null;

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

        if (newExchangeRates != null) {
            String providerUrl;/*w w  w. j  a  v  a 2 s.co  m*/
            switch (provider) {
            case 0:
                providerUrl = "http://www.cryptsy.com";
                break;
            case 1:
                providerUrl = "http://www.vircurex.com";
                break;
            default:
                providerUrl = "";
                break;
            }
            float mBTCRate = ccnBtcConversion * 1000;
            String strmBTCRate = String.format(Locale.US, "%.5f", mBTCRate).replace(',', '.');
            newExchangeRates.put("mBTC", new ExchangeRate("mBTC",
                    new BigDecimal(GenericUtils.toNanoCoins(strmBTCRate, 0)).toBigInteger(), providerUrl));
            newExchangeRates.put("CCN",
                    new ExchangeRate("CCN", BigInteger.valueOf(100000000), "priceofccn.com"));
            exchangeRates = newExchangeRates;
            lastUpdated = now;

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

    if (exchangeRates == null || ccnBtcConversion == -1)
        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(KEY_CURRENCY_CODE)) {
        final ExchangeRate rate = bestExchangeRate(selectionArgs[0]);
        if (rate != null)
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
    }

    return cursor;
}