Example usage for android.database MatrixCursor MatrixCursor

List of usage examples for android.database MatrixCursor MatrixCursor

Introduction

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

Prototype

public MatrixCursor(String[] columnNames) 

Source Link

Document

Constructs a new cursor.

Usage

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 www  . 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, 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.roamprocess1.roaming4world.ui.favorites.FavLoader.java

/**
 * Creates a cursor that contains a single row and maps the section to the
 * given value.//w  ww. j  a v  a2s .c om
 */
private Cursor createHeaderCursorFor(SipProfile account) {
    MatrixCursor matrixCursor = new MatrixCursor(
            new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE, SipProfile.FIELD_DISPLAY_NAME,
                    SipProfile.FIELD_WIZARD, SipProfile.FIELD_ANDROID_GROUP, SipProfile.FIELD_PUBLISH_ENABLED,
                    SipProfile.FIELD_REG_URI, SipProfile.FIELD_PROXY, SipProfile.FIELD_ACC_ID });
    String proxies = "";
    if (account.proxies != null) {
        proxies = TextUtils.join(SipProfile.PROXIES_SEPARATOR, account.proxies);
    }
    matrixCursor
            .addRow(new Object[] { account.id, ContactsWrapper.TYPE_GROUP, account.display_name, account.wizard,
                    account.android_group, account.publish_enabled, account.reg_uri, proxies, account.acc_id });

    return matrixCursor;
}

From source file:com.andremion.louvre.data.MediaLoader.java

/**
 * Add "All Media" item as the first row of bucket items.
 *
 * @param cursor The original data of all bucket items
 * @return The data with "All Media" item added
 *//*from   w w w.  j a  va 2  s .  co  m*/
private Cursor addAllMediaBucketItem(@Nullable Cursor cursor) {
    if (cursor == null || !cursor.moveToPosition(0)) {
        return null;
    }
    ensureActivityAttached();
    long id = ALL_MEDIA_BUCKET_ID;
    String label = mActivity.getString(R.string.activity_gallery_bucket_all_media);
    String data = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
    MatrixCursor allMediaRow = new MatrixCursor(BUCKET_PROJECTION);
    allMediaRow.newRow().add(id).add(label).add(data);
    return new MergeCursor(new Cursor[] { allMediaRow, cursor });
}

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

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {

    String[] netProjection = netProjection(projection, SUPPORTED_ROOT_PROJECTION);
    MatrixCursor result = new MatrixCursor(netProjection);

    Log.d(DEBUG_TAG, "queryRoots()");

    // add a Root for every signed in Seafile account we have.
    for (Account a : accountManager.getAccountList()) {
        includeRoot(result, a);/*from w ww .  j  av a2  s  .c  o m*/
    }

    // notification uri for the event, that the account list has changed
    result.setNotificationUri(getContext().getContentResolver(), NOTIFICATION_URI);

    return result;
}

From source file:org.sufficientlysecure.keychain.ui.MultiUserIdsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    MatrixCursor matrix = new MatrixCursor(new String[] { "_id", "user_data", "grouped" }) {
        @Override/*from  w  ww  .j ava2s .c  o m*/
        public byte[] getBlob(int column) {
            return super.getBlob(column);
        }
    };
    data.moveToFirst();

    long lastMasterKeyId = 0;
    String lastName = "";
    ArrayList<String> uids = new ArrayList<>();

    boolean header = true;

    // Iterate over all rows
    while (!data.isAfterLast()) {
        long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
        String userId = data.getString(INDEX_USER_ID);
        OpenPgpUtils.UserId pieces = KeyRing.splitUserId(userId);

        // Two cases:

        boolean grouped = masterKeyId == lastMasterKeyId;
        boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces.name);
        // Remember for next loop
        lastName = pieces.name;

        Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped"));

        if (!subGrouped) {
            // 1. This name should NOT be grouped with the previous, so we flush the buffer

            Parcel p = Parcel.obtain();
            p.writeStringList(uids);
            byte[] d = p.marshall();
            p.recycle();

            matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 });
            // indicate that we have a header for this masterKeyId
            header = false;

            // Now clear the buffer, and add the new user id, for the next round
            uids.clear();

        }

        // 2. This name should be grouped with the previous, just add to buffer
        uids.add(userId);
        lastMasterKeyId = masterKeyId;

        // If this one wasn't grouped, the next one's gotta be a header
        if (!grouped) {
            header = true;
        }

        // Regardless of the outcome, move to next entry
        data.moveToNext();

    }

    // If there is anything left in the buffer, flush it one last time
    if (!uids.isEmpty()) {

        Parcel p = Parcel.obtain();
        p.writeStringList(uids);
        byte[] d = p.marshall();
        p.recycle();

        matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 });

    }

    mUserIdsAdapter.swapCursor(matrix);
}

From source file:ro.expectations.expenses.widget.dialog.CategoryPickerDialogFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    MatrixCursor matrixCursor = new MatrixCursor(
            new String[] { ExpensesContract.Accounts._ID, ExpensesContract.Accounts.TITLE });
    matrixCursor.addRow(new Object[] { "0", getString(R.string.no_category) });
    MergeCursor mergeCursor = new MergeCursor(new Cursor[] { matrixCursor, data });

    mAdapter.swapCursor(mergeCursor);//from   w w w. j  a  v a 2  s .co m
}

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;//from ww w . j av 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:com.xbm.android.matisse.internal.loader.AlbumMediaLoader.java

@Override
public Cursor loadInBackground() {
    Cursor result = super.loadInBackground();
    if (!mEnableCapture || !MediaStoreCompat.hasCameraFeature(getContext())) {
        return result;
    }/*from  w  w  w  .  ja v  a  2 s  . co m*/
    MatrixCursor dummy = new MatrixCursor(PROJECTION);
    dummy.addRow(new Object[] { Item.ITEM_ID_CAPTURE, Item.ITEM_DISPLAY_NAME_CAPTURE, "", 0, 0 });
    return new MergeCursor(new Cursor[] { dummy, result });
}

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   ww w.ja v  a  2s.c  om*/

            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.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;/*  w w  w .j a  v  a2 s. c  om*/

            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;
}