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:nl.terr.tabweave.TabWeave.java

public void fillData(List<JSONObject> lTabs) {
    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[] { SyncWeave.KEY_TITLE, SyncWeave.KEY_URL, SyncWeave.KEY_ROWID };

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[] { R.id.title, R.id.url };

    int iBrowserInstances = lTabs.size();
    MatrixCursor matrixCursor = new MatrixCursor(from);

    int iTabId = 0;

    // Show "No tabs" message
    TextView tvNoTabs = (TextView) findViewById(R.id.no_tabs);
    tvNoTabs.setVisibility(View.VISIBLE);

    try {//from  w  ww . j  ava 2 s.c om
        for (int iWeaveBrowserInstance = 0; iWeaveBrowserInstance < iBrowserInstances; iWeaveBrowserInstance++) {
            int iNumberTabs = lTabs.get(iWeaveBrowserInstance).getJSONArray("tabs").length();

            // Hide "No tabs" message
            if (iNumberTabs > 0) {
                tvNoTabs.setVisibility(View.INVISIBLE);
            }

            for (int iWeaveTab = 0; iWeaveTab < iNumberTabs; iWeaveTab++) {
                matrixCursor.newRow()
                        .add(lTabs.get(iWeaveBrowserInstance).getJSONArray("tabs").getJSONObject(iWeaveTab)
                                .getString("title"))
                        .add(lTabs.get(iWeaveBrowserInstance).getJSONArray("tabs").getJSONObject(iWeaveTab)
                                .getJSONArray("urlHistory").getString(0))
                        .add(iTabId);

                iTabId++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();

        AlertDialog alert = createAlertDialog(this, e.getClass().toString(), e.getMessage());
        alert.show();
    }

    ListAdapter listAdapter = new SimpleCursorAdapter(this, // Context
            R.layout.tab_row, // Specify the row template to use (here, two columns bound to the two retrieved cursor rows).
            matrixCursor, from, to);

    setListAdapter(listAdapter);
}

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

private void addModelToCursor(Long modelId, HashMap<Long, JSONObject> models, MatrixCursor rv,
        String[] columns) {/* w ww .j  a  v  a2 s. c  o m*/
    JSONObject jsonObject = models.get(modelId);
    MatrixCursor.RowBuilder rb = rv.newRow();
    try {
        for (String column : columns) {
            if (column.equals(FlashCardsContract.Model._ID)) {
                rb.add(modelId);
            } else if (column.equals(FlashCardsContract.Model.NAME)) {
                rb.add(jsonObject.getString("name"));
            } else if (column.equals(FlashCardsContract.Model.FIELD_NAMES)) {
                JSONArray flds = jsonObject.getJSONArray("flds");
                String[] allFlds = new String[flds.length()];
                for (int idx = 0; idx < flds.length(); idx++) {
                    allFlds[idx] = flds.getJSONObject(idx).optString("name", "");
                }
                rb.add(Utils.joinFields(allFlds));
            } else if (column.equals(FlashCardsContract.Model.NUM_CARDS)) {
                rb.add(jsonObject.getJSONArray("tmpls").length());
            } else if (column.equals(FlashCardsContract.Model.CSS)) {
                rb.add(jsonObject.getString("css"));
            } else if (column.equals(FlashCardsContract.Model.DECK_ID)) {
                rb.add(jsonObject.getLong("did"));
            } else {
                throw new UnsupportedOperationException("Column \"" + column + "\" is unknown");
            }
        }
    } catch (JSONException e) {
        Timber.e(e, "Error parsing JSONArray");
        throw new IllegalArgumentException("Model " + modelId + " is malformed", e);
    }
}

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

/**
 * Add a cursor entry for the account root.
 *
 * We don't know much about it.//from w w w .  j  a v a  2 s.c  om
 *
 * @param result the cursor to write the row into.
 * @param account the account to add.
 */
private void includeRoot(MatrixCursor result, Account account) {
    String docId = DocumentIdParser.buildId(account, null, null);
    String rootId = DocumentIdParser.buildRootId(account);

    final MatrixCursor.RowBuilder row = result.newRow();

    row.add(Root.COLUMN_ROOT_ID, rootId);
    row.add(Root.COLUMN_DOCUMENT_ID, docId);
    row.add(Root.COLUMN_ICON, R.drawable.ic_launcher);
    row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_TITLE, account.getServerHost());
    row.add(Root.COLUMN_SUMMARY, account.getEmail());
}

From source file:cm.aptoide.pt.LatestLikesComments.java

public Cursor getComments() {
    endPointComments = String.format(endPointComments, repoName);
    MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "apkid", "name", "text", "username", "time" });

    try {/*from ww  w.  j av  a 2 s  .  c  o m*/
        NetworkUtils utils = new NetworkUtils();
        JSONObject respJSON = utils.getJsonObject(endPointComments, context);
        JSONArray array = respJSON.getJSONArray("listing");

        for (int i = 0; i != array.length(); i++) {
            String apkid = ((JSONObject) array.get(i)).getString("apkid");
            String name = ((JSONObject) array.get(i)).getString("name");
            String text = ((JSONObject) array.get(i)).getString("text");
            String timestamp = ((JSONObject) array.get(i)).getString("timestamp");
            Date date = Configs.TIME_STAMP_FORMAT.parse(timestamp);
            String time = DateTimeUtils.getInstance(context).getTimeDiffString(date.getTime());
            String username = ((JSONObject) array.get(i)).getString("username");
            if (username.equals("NOT_SIGNED_UP")) {
                username = "";
            }
            cursor.newRow().add(i).add(apkid).add(name).add(text).add(username).add(time);
        }

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return cursor;
}

From source file:com.example.android.vault.VaultProvider.java

/**
 * Include metadata for a document in the given result cursor.
 *//*from www  .  j av a 2  s  .c  o  m*/
private void includeDocument(MatrixCursor result, long docId) throws IOException, GeneralSecurityException {
    final EncryptedDocument doc = getDocument(docId);
    if (!doc.getFile().exists()) {
        throw new FileNotFoundException("Missing document " + docId);
    }

    final JSONObject meta = doc.readMetadata();

    int flags = 0;

    final String mimeType = meta.optString(Document.COLUMN_MIME_TYPE);
    if (Document.MIME_TYPE_DIR.equals(mimeType)) {
        flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
    } else {
        flags |= Document.FLAG_SUPPORTS_WRITE;
    }
    flags |= Document.FLAG_SUPPORTS_DELETE;

    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, meta.optLong(Document.COLUMN_DOCUMENT_ID));
    row.add(Document.COLUMN_DISPLAY_NAME, meta.optString(Document.COLUMN_DISPLAY_NAME));
    row.add(Document.COLUMN_SIZE, meta.optLong(Document.COLUMN_SIZE));
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    row.add(Document.COLUMN_FLAGS, flags);
    row.add(Document.COLUMN_LAST_MODIFIED, meta.optLong(Document.COLUMN_LAST_MODIFIED));
}

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

/**
 * Add a seafile repo to the cursor.//from ww  w . j  ava 2 s  .c  om
 *
 * @param result the cursor to write the row into.
 * @param account the account that contains the repo.
 * @param repo the repo to add.
 */
private void includeRepo(MatrixCursor result, Account account, SeafRepo repo) {
    String docId = DocumentIdParser.buildId(account, repo.getID(), null);

    int flags = 0;
    if (repo.hasWritePermission()) {
        flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
    }

    final MatrixCursor.RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME, repo.getTitle());
    row.add(Document.COLUMN_SUMMARY, null);
    row.add(Document.COLUMN_LAST_MODIFIED, repo.mtime * 1000);
    row.add(Document.COLUMN_FLAGS, flags);
    row.add(Document.COLUMN_ICON, repo.getIcon());
    row.add(Document.COLUMN_SIZE, repo.size);

    if (repo.encrypted || !reachableAccounts.contains(account)) {
        row.add(Document.COLUMN_MIME_TYPE, null); // undocumented: will grey out the entry
    } else {
        row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
    }
}

From source file:cm.aptoide.pt.LatestLikesComments.java

public Cursor getLikes() {
    endPointLikes = String.format(endPointLikes, repoName);
    MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "apkid", "name", "like", "username" });

    try {/*from   w  w  w .j av  a  2 s  . c om*/
        HttpURLConnection connection = (HttpURLConnection) new URL(endPointLikes).openConnection();
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line + "\n");
        }
        br.close();

        JSONObject respJSON = new JSONObject(sb.toString());
        JSONArray array = respJSON.getJSONArray("listing");

        for (int i = 0; i != array.length(); i++) {

            String apkid = ((JSONObject) array.get(i)).getString("apkid");
            String name = ((JSONObject) array.get(i)).getString("name");
            String like = ((JSONObject) array.get(i)).getString("like");
            String username = ((JSONObject) array.get(i)).getString("username");
            if (username.equals("NOT_SIGNED_UP")) {
                username = "";
            }
            cursor.newRow().add(i).add(apkid).add(name).add(like).add(username);

        }

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return cursor;
}

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

private void addCardToCursor(Card currentCard, MatrixCursor rv, Collection col, String[] columns) {
    String cardName;// ww  w  . j  a  v a 2  s .  com
    try {
        cardName = currentCard.template().getString("name");
    } catch (JSONException je) {
        throw new IllegalArgumentException("Card is using an invalid template", je);
    }
    String question = currentCard.q();
    String answer = currentCard.a();

    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.Card.CARD_ORD)) {
            rb.add(currentCard.getOrd());
        } else if (column.equals(FlashCardsContract.Card.CARD_NAME)) {
            rb.add(cardName);
        } else if (column.equals(FlashCardsContract.Card.DECK_ID)) {
            rb.add(currentCard.getDid());
        } else if (column.equals(FlashCardsContract.Card.QUESTION)) {
            rb.add(question);
        } else if (column.equals(FlashCardsContract.Card.ANSWER)) {
            rb.add(answer);
        } else if (column.equals(FlashCardsContract.Card.QUESTION_SIMPLE)) {
            rb.add(currentCard.qSimple());
        } else if (column.equals(FlashCardsContract.Card.ANSWER_SIMPLE)) {
            rb.add(currentCard._getQA(false).get("a"));
        } else if (column.equals(FlashCardsContract.Card.ANSWER_PURE)) {
            rb.add(currentCard.getPureAnswer());
        } else {
            throw new UnsupportedOperationException("Column \"" + column + "\" is unknown");
        }
    }
}

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

/**
 * add a dirent to the cursor.// w ww .ja  va 2s .c o m
 *
 * @param result the cursor to write the row into.
 * @param dm the dataMamager that belongs to the repo.
 * @param entry the seafile dirent to add
 */
private void includeStarredFileDirent(MatrixCursor result, DataManager dm, SeafStarredFile entry) {
    String docId = DocumentIdParser.buildId(dm.getAccount(), entry.getRepoID(), entry.getPath());

    String mimeType;
    if (entry.isDir())
        mimeType = DocumentsContract.Document.MIME_TYPE_DIR;
    else
        mimeType = Utils.getFileMimeType(docId);

    int flags = 0;
    // only offer a thumbnail if the file is an image
    if (mimeType.startsWith("image/")) {
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    }

    final MatrixCursor.RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME, entry.getTitle());
    row.add(Document.COLUMN_SIZE, entry.getSize());
    row.add(Document.COLUMN_SUMMARY, null);
    row.add(Document.COLUMN_LAST_MODIFIED, entry.getMtime() * 1000);
    row.add(Document.COLUMN_FLAGS, flags);

    if (!reachableAccounts.contains(dm.getAccount())) {
        row.add(Document.COLUMN_MIME_TYPE, null); // undocumented: will grey out the entry
    } else {
        row.add(Document.COLUMN_MIME_TYPE, mimeType);
    }

}

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

/**
 * add a dirent to the cursor.//from  w  ww  .  ja  v  a  2 s  .  c o m
 *
 * @param result the cursor to write the row into.
 * @param dm the dataMamager that belongs to the repo.
 * @param repoId the repoId of the seafile repo
 * @param parentPath the path of the parent directory
 * @param entry the seafile dirent to add
 */
private void includeDirent(MatrixCursor result, DataManager dm, String repoId, String parentPath,
        SeafDirent entry) {
    String fullPath = Utils.pathJoin(parentPath, entry.getTitle());

    String docId = DocumentIdParser.buildId(dm.getAccount(), repoId, fullPath);

    String mimeType;
    if (entry.isDir())
        mimeType = DocumentsContract.Document.MIME_TYPE_DIR;
    else
        mimeType = Utils.getFileMimeType(docId);

    int flags = 0;
    // only offer a thumbnail if the file is an image
    if (mimeType.startsWith("image/")) {
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    }

    SeafRepo repo = dm.getCachedRepoByID(repoId);
    if (repo != null && repo.hasWritePermission()) {
        if (entry.isDir()) {
            flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
        } else {
            flags |= Document.FLAG_SUPPORTS_WRITE;
        }
    }

    final MatrixCursor.RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME, entry.getTitle());
    row.add(Document.COLUMN_SIZE, entry.size);
    row.add(Document.COLUMN_SUMMARY, null);
    row.add(Document.COLUMN_LAST_MODIFIED, entry.mtime * 1000);
    row.add(Document.COLUMN_FLAGS, flags);

    if (!reachableAccounts.contains(dm.getAccount())) {
        row.add(Document.COLUMN_MIME_TYPE, null); // undocumented: will grey out the entry
    } else {
        row.add(Document.COLUMN_MIME_TYPE, mimeType);
    }

}