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:org.chromium.chrome.browser.util.ChromeFileProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Uri fileUri = getFileUriWhenReady(uri);
    if (fileUri == null)
        return null;

    // Workaround for a bad assumption that particular MediaStore columns exist by certain third
    // party applications.
    // http://crbug.com/467423.
    Cursor source = super.query(fileUri, projection, selection, selectionArgs, sortOrder);

    String[] columnNames = source.getColumnNames();
    String[] newColumnNames = columnNamesWithData(columnNames);
    if (columnNames == newColumnNames)
        return source;

    MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount());

    source.moveToPosition(-1);//from  w  w w .  j av a  2  s .co  m
    while (source.moveToNext()) {
        MatrixCursor.RowBuilder row = cursor.newRow();
        for (int i = 0; i < columnNames.length; i++) {
            switch (source.getType(i)) {
            case Cursor.FIELD_TYPE_INTEGER:
                row.add(source.getInt(i));
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                row.add(source.getFloat(i));
                break;
            case Cursor.FIELD_TYPE_STRING:
                row.add(source.getString(i));
                break;
            case Cursor.FIELD_TYPE_BLOB:
                row.add(source.getBlob(i));
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                row.add(null);
                break;
            }
        }
    }

    source.close();
    return cursor;
}

From source file:piuk.blockchain.android.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    if (exchangeRates == null) {
        exchangeRates = getExchangeRates();

        if (exchangeRates == null)
            return null;
    }//from   ww  w .  j a va  2s  . c om

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

    if (selection == null) {
        for (final Map.Entry<String, Double> entry : exchangeRates.entrySet())
            cursor.newRow().add(entry.getKey().hashCode()).add(entry.getKey()).add(entry.getValue());
    } else if (selection.equals(KEY_CURRENCY_CODE)) {

        if (selectionArgs == null)
            return null;

        final String code = selectionArgs[0];
        final Double rate = exchangeRates.get(code);
        cursor.newRow().add(code.hashCode()).add(code).add(rate);
    }

    return cursor;
}

From source file:com.raspi.chatapp.util.storage.file.LocalStorageProvider.java

private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException {
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath());
    row.add(Document.COLUMN_DISPLAY_NAME, file.getName());
    String mimeType = getDocumentType(file.getAbsolutePath());
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    int flags = file.canWrite()
            ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE | Document.FLAG_SUPPORTS_RENAME
                    | (mimeType.equals(Document.MIME_TYPE_DIR) ? Document.FLAG_DIR_SUPPORTS_CREATE : 0)
            : 0;/*from  ww w.  j  a v  a 2 s  .  com*/
    // We only show thumbnails for image files - expect a call to openDocumentThumbnail for each file that has
    // this flag set
    if (mimeType.startsWith("image/"))
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    row.add(Document.COLUMN_FLAGS, flags);
    // COLUMN_SIZE is required, but can be null
    row.add(Document.COLUMN_SIZE, file.length());
    // These columns are optional
    row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified());
    // Document.COLUMN_ICON can be a resource id identifying a custom icon. The system provides default icons
    // based on mime type
    // Document.COLUMN_SUMMARY is optional additional information about the file
}

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

private void addRow(MatrixCursor cursor, ExchangeRate exchangeRate) {
    final ExchangeRateBase rate = exchangeRate.rate;
    final String codeId = exchangeRate.currencyCodeId;
    cursor.newRow().add(codeId.hashCode()).add(codeId).add(rate.value1.value).add(rate.value1.type.getSymbol())
            .add(rate.value2.value).add(rate.value2.type.getSymbol()).add(exchangeRate.source);
}

From source file:com.example.android.notepad.CMNotesProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    String[] keys = null;//from  w  ww  . j a v a 2s  .co  m

    switch (sUriMatcher.match(uri)) {
    case NOTES:
        //qb.setProjectionMap(sNotesProjectionMap);
        break;

    case NOTE_ID:
        //qb.setProjectionMap(sNotesProjectionMap);
        //qb.appendWhere(Notes._ID + "=" + uri.getPathSegments().get(1));
        keys = new String[] { uri.getPathSegments().get(1) };
        break;

    case LIVE_FOLDER_NOTES:
        //qb.setProjectionMap(sLiveFolderProjectionMap);
        break;

    default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    // Get the database and run the query
    //SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    //Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);

    CMAdapter cmadapter = new CMAdapter();
    JSONObject objects = cmadapter.getValues(keys);
    MatrixCursor c = new MatrixCursor(projection);

    // objects is a map of key => value mappings, where key is the _id
    Iterator<String> note_ids = objects.keys();
    while (note_ids.hasNext()) {
        String id = note_ids.next();
        RowBuilder row = c.newRow();
        for (String field : projection) {
            if (field.equals(Notes._ID)) {
                row.add(id);
            } else {
                String val = "bad entry";
                try {
                    val = objects.getJSONObject(id).getString(field);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                row.add(val);
            }
        }
    }

    // Tell the cursor what uri to watch, so it knows when its source data changes
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}

From source file:com.rightscale.provider.rest.ServersResource.java

private Cursor buildCursor(JSONArray array) throws JSONException {
    MatrixCursor result = new MatrixCursor(COLUMNS);

    for (Integer i : sortJsonArray(array, "nickname")) {
        JSONObject object = array.getJSONObject(i);

        /* /*www. j ava  2  s.com*/
         * The API is glitchy for non-EC2 servers and returns an incomplete JSON object.
         * If the object lacks an href property, it is one of these and we skip it...
         */
        if (object.has("href")) {
            MatrixCursor.RowBuilder row = result.newRow();
            buildRow(row, object);
        }
    }

    return result;
}

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

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//from  w ww  . j  a 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("Elysium", "Unable to add an exchange rate.  NullPointerException.");
        }
    }

    return cursor;
}

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

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//from   www .j  a  v  a 2 s  .  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(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("marscoin", "Unable to add an exchange rate.  NullPointerException.");
        }
    }

    return cursor;
}

From source file:de.schildbach.wallet.litecoin.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) {
        LycBtcRate = getLycBtcRate();/*from w ww  . jav a2s.  co  m*/
        if (LycBtcRate == null)
            return null;

        Map<String, ExchangeRate> newExchangeRates = getBlockchainInfo();
        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getLycancoinCharts();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;
        }
    }

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

    return cursor;
}

From source file:com.rightscale.provider.rest.DeploymentsResource.java

public Cursor index() throws RestException {
    MatrixCursor result = new MatrixCursor(COLUMNS);
    JSONArray response = getJsonArray("deployments.js");

    for (Integer i : sortJsonArray(response, "nickname")) {
        try {/*from w w w. j ava  2s.  c  o  m*/
            JSONObject deployment = response.getJSONObject(i);

            String href = deployment.getString("href");
            int id = Integer.valueOf(href.substring(href.lastIndexOf('/') + 1)).intValue(); //TODO error handling         
            String nickname = deployment.getString("nickname");

            MatrixCursor.RowBuilder row = result.newRow();
            row.add(id);
            row.add(href);
            row.add(nickname);
        } catch (JSONException e) {
            throw new ProtocolError(e);
        }
    }

    return result;
}