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.rightscale.provider.rest.ServerSettingsResource.java

private Cursor buildCursor(String serverId, JSONObject object) throws JSONException {
    int nServerId = Integer.parseInt(serverId);
    MatrixCursor result = new MatrixCursor(COLUMNS);
    MatrixCursor.RowBuilder row = result.newRow();
    buildRow(nServerId, row, object);//  w  w  w .  j  a  va2  s. c om
    return result;
}

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

private Cursor buildCursor(JSONObject object) throws JSONException {
    MatrixCursor result = new MatrixCursor(COLUMNS);
    MatrixCursor.RowBuilder row = result.newRow();
    buildRow(row, object);/*  ww  w  .j a  v  a 2s . c  om*/
    return result;
}

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
 *///  ww w . java 2s  .c  o  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.android.messaging.datamodel.MediaScratchFileProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    if (projection != null && projection.length > 0
            && TextUtils.equals(projection[0], OpenableColumns.DISPLAY_NAME) && isMediaScratchSpaceUri(uri)) {
        // Retrieve the display name associated with a temp file. This is used by the Contacts
        // ImportVCardActivity to retrieve the name of the contact(s) being imported.
        String displayName;/*from  w w w  .j a  va  2  s.c o  m*/
        synchronized (sUriToDisplayNameMap) {
            displayName = sUriToDisplayNameMap.get(uri);
        }
        if (!TextUtils.isEmpty(displayName)) {
            MatrixCursor cursor = new MatrixCursor(new String[] { OpenableColumns.DISPLAY_NAME });
            RowBuilder row = cursor.newRow();
            row.add(displayName);
            return cursor;
        }
    }
    return null;
}

From source file:org.chromium.chrome.browser.util.CompatibilityFileProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Cursor source = super.query(uri, 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 a v  a2s  . c  o  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:com.rightscale.provider.rest.ServerTemplatesResource.java

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

    for (int i = 0; i < array.length(); i++) {
        JSONObject object = array.getJSONObject(i);
        MatrixCursor.RowBuilder row = result.newRow();
        buildRow(row, object);/*from  w w w . ja  v a2 s .c o m*/
    }

    return result;
}

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

private Cursor buildCursor(String serverTemplateId, JSONArray array) throws JSONException, ProtocolError {
    int nServerTemplateId = Integer.parseInt(serverTemplateId);

    MatrixCursor result = new MatrixCursor(COLUMNS);
    for (int i = 0; i < array.length(); i++) {
        JSONObject object = array.getJSONObject(i);
        MatrixCursor.RowBuilder row = result.newRow();
        buildRow(nServerTemplateId, row, object);
    }/*  w ww.j  a  v a2  s. c  o  m*/

    return result;
}

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

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

    int nServerId = Integer.parseInt(serverId);

    for (int i = 0; i < array.length(); i++) {
        JSONObject object = array.getJSONObject(i);
        MatrixCursor.RowBuilder row = result.newRow();
        buildRow(nServerId, row, object);
    }// w ww  .  j a  va2 s  . c om

    return result;
}

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

public Cursor show(String id) throws RestException {
    try {/*from w  w w.ja  v a  2  s .  co  m*/
        MatrixCursor result = new MatrixCursor(COLUMNS);
        JSONObject deployment = getJsonObject("deployments/" + id + ".js");
        String href = deployment.getString("href");
        String nickname = deployment.getString("nickname");

        MatrixCursor.RowBuilder row = result.newRow();
        row.add(id);
        row.add(href);
        row.add(nickname);

        return result;
    } catch (JSONException e) {
        throw new ProtocolError(e);
    }
}

From source file:io.nuclei.cyto.share.CytoFileProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Cursor source = super.query(uri, projection, selection, selectionArgs, sortOrder);
    if (source == null)
        return null;
    try {/* ww  w. j a va 2s .  c o  m*/
        final String[] columnNames = source.getColumnNames();

        String[] names = columnNames;
        List<String> missingNames = getMissingColumns(columnNames);
        int mimeTypeIndex = -1;

        if (missingNames.size() > 0) {
            String[] newColumnNames = Arrays.copyOf(columnNames, columnNames.length + missingNames.size());
            int ix = columnNames.length;
            for (String missingName : missingNames) {
                newColumnNames[ix] = missingName;
                if (MediaStore.MediaColumns.MIME_TYPE.equals(missingName))
                    mimeTypeIndex = ix;
                ix++;
            }
            names = newColumnNames;
        }

        MatrixCursor cursor = new MatrixCursor(names, source.getCount());
        source.moveToPosition(-1);
        int columnLength = columnNames.length;
        while (source.moveToNext()) {
            MatrixCursor.RowBuilder row = cursor.newRow();
            for (int i = 0; i < names.length; i++) {
                if (i < columnLength)
                    row.add(source.getString(i));
                else if (i == mimeTypeIndex) {
                    // populate the MIME_TYPE column with a guess as to the mime type of the file
                    final int lastDot = uri.getPath().lastIndexOf('.');
                    if (lastDot >= 0) {
                        String extension = uri.getPath().substring(lastDot + 1);
                        String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
                        if (mimeType != null)
                            row.add(mimeType);
                        else
                            row.add("application/octet");
                    } else
                        row.add("application/octet");
                } else
                    row.add(null);
            }
        }

        return cursor;
    } finally {
        source.close();
    }
}