MatrixCursor extras = new MatrixCursor(new String[] { "_id", "title" }); extras.addRow(new String[] { "-1", "New Template" }); extras.addRow(new String[] { "-2", "Empty Template" }); Cursor[] cursors = { extras, cursor }; Cursor extendedCursor = new MergeCursor(cursors);
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { if (projection == null) { projection=OPENABLE_PROJECTION; } final MatrixCursor cursor=new MatrixCursor(projection, 1); MatrixCursor.RowBuilder b=cursor.newRow(); for (String col : projection) { if (OpenableColumns.DISPLAY_NAME.equals(col)) { b.add(getFileName(uri)); } else if (OpenableColumns.SIZE.equals(col)) { b.add(getDataLength(uri)); } else { // unknown, so just add null b.add(null); } } return(new LegacyCompatCursorWrapper(cursor)); }
@Test(expected = CursorIndexOutOfBoundsException.class) public void shouldThrowIndexOutOfBoundsExceptionForInvalidColumnLastRow() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(new Object[]{"foo", 10L, 0.1f}); cursor.moveToFirst(); cursor.moveToNext(); cursor.getString(0); }
private void updateCursor(final long trackId) { MusicInfo info = mPlaylistInfo.get(trackId); if (mPlaylistInfo.get(trackId) != null) { MatrixCursor cursor = new MatrixCursor(PROJECTION); cursor.addRow(new Object[]{info.songId, info.artist, info.albumName, info.musicName , info.data, info.albumData, info.albumId, info.artistId}); cursor.moveToFirst(); mCursor = cursor; cursor.close(); } }
String[] columns = new String[] { "_id", "item", "description" }; MatrixCursor matrixCursor= new MatrixCursor(columns); startManagingCursor(matrixCursor); matrixCursor.addRow(new Object[] { 1, "Item A", "...." }); SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.layout_row, matrixCursor, ...); setListAdapter(adapter);
@Test public void shouldAddIterablesAsRows() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(Arrays.asList(new Object[]{"foo", 10L, 0.1f})); cursor.addRow(Arrays.asList(new Object[]{"baz", 20L, null})); assertThat(cursor.getCount()).isEqualTo(2); assertTrue(cursor.moveToFirst()); assertThat(cursor.getString(0)).isEqualTo("foo"); assertThat(cursor.getLong(1)).isEqualTo(10L); assertThat(cursor.getFloat(2)).isEqualTo(0.1f); assertTrue(cursor.moveToNext()); assertThat(cursor.getString(0)).isEqualTo("baz"); assertThat(cursor.getLong(1)).isEqualTo(20L); assertTrue(cursor.isNull(2)); assertFalse(cursor.moveToNext()); }
public Cursor query(@NonNull Uri paramUri, String[] paramArrayOfString1, String paramString1, String[] paramArrayOfString2, String paramString2) { MatrixCursor cursor = new MatrixCursor(new String[]{"string"}); try { if (getContext() == null) return cursor; final String path = paramUri.getPath().substring(1); final String[] items = getContext().getAssets().list(path); for (String s : items) { cursor.newRow().add(s); cursor.moveToNext(); } cursor.moveToFirst(); } catch (Exception e) { cursor.close(); throw new RuntimeException(e); } return cursor; }
@Before public void setUp() throws Exception { singleColumnSingleNullValueMatrixCursor = new MatrixCursor(new String[]{"a"}); singleColumnSingleNullValueMatrixCursor.addRow(new Object[]{null}); singleColumnSingleNullValueMatrixCursor.moveToFirst(); }
private static MatrixCursor getRecordedProgramCursor(ContentValues contentValues) { String[] rows = RecordedProgram.PROJECTION; MatrixCursor cursor = new MatrixCursor(rows); MatrixCursor.RowBuilder builder = cursor.newRow(); for (String row : rows) { builder.add(row, contentValues.get(row)); } cursor.moveToFirst(); return cursor; } }
@Test public void shouldAllowTypeFlexibility() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(new Object[]{42, 3.3, 'a'}); assertTrue(cursor.moveToFirst()); assertThat(cursor.getString(0)).isEqualTo("42"); assertThat(cursor.getShort(0)).isEqualTo((short) 42); assertThat(cursor.getInt(0)).isEqualTo(42); assertThat(cursor.getLong(0)).isEqualTo(42L); assertThat(cursor.getFloat(0)).isEqualTo(42.0F); assertThat(cursor.getDouble(0)).isEqualTo(42.0); assertThat(cursor.getString(1)).isEqualTo("3.3"); assertThat(cursor.getShort(1)).isEqualTo((short) 3); assertThat(cursor.getInt(1)).isEqualTo(3); assertThat(cursor.getLong(1)).isEqualTo(3L); assertThat(cursor.getFloat(1)).isEqualTo(3.3F); assertThat(cursor.getDouble(1)).isEqualTo(3.3); assertThat(cursor.getString(2)).isEqualTo("a"); }
@Test public void shouldDefineGetBlob() throws Exception { byte[] blob = {1, 2, 3, 4}; MatrixCursor cursor = new MatrixCursor(new String[]{"a"}); cursor.addRow(new Object[]{blob}); assertTrue(cursor.moveToFirst()); assertThat(cursor.getBlob(0)).isEqualTo(blob); }
@Test(expected = CursorIndexOutOfBoundsException.class) public void shouldThrowIndexOutOfBoundsExceptionForInvalidColumn() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(new Object[]{"foo", 10L, 0.1f}); cursor.getString(3); }
@Test(expected = CursorIndexOutOfBoundsException.class) public void shouldThrowIndexOutOfBoundsExceptionWithoutData() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.getString(0); }
@Override public Cursor querySearchDocuments(String rootId, String query, String[] projection) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION); final File parent = getFileForDocId(rootId); while (!pending.isEmpty() && result.getCount() < MAX_SEARCH_RESULTS) { final File file = pending.removeFirst();
@Test public void shouldDefineColumnNames() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); assertThat(cursor.getColumnCount()).isEqualTo(3); assertThat(cursor.getColumnName(0)).isEqualTo("a"); assertThat(cursor.getColumnName(1)).isEqualTo("b"); assertThat(cursor.getColumnName(2)).isEqualTo("c"); assertThat(cursor.getColumnNames()).isEqualTo(new String[]{"a", "b", "c"}); assertThat(cursor.getColumnIndex("b")).isEqualTo(1); assertThat(cursor.getColumnIndex("z")).isEqualTo(-1); }
@Test(expected = IllegalArgumentException.class) public void shouldDefineGetColumnNameOrThrow() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.getColumnIndexOrThrow("z"); }
public Harness() { cursor.addRow(new String[] { file.getAbsolutePath() }); when(query.query(eq(uri))).thenReturn(cursor); when(service.get(eq(file.getAbsolutePath()))).thenReturn(file); when(service.exists(eq(file))).thenReturn(true); when(service.length(eq(file))).thenReturn(1L); }
private void addTemplateToCursor(JSONObject tmpl, JSONObject model, int id, Models models, MatrixCursor rv, String[] columns) { try { MatrixCursor.RowBuilder rb = rv.newRow(); for (String column : columns) { if (column.equals(CardTemplate._ID)) {
@Override public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION); includeFile(result, documentId, null); return result; }
@Test public void shouldAddObjectArraysAsRows() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(new Object[]{"foo", 10L, 0.1f}); cursor.addRow(new Object[]{"baz", 20L, null}); assertThat(cursor.getCount()).isEqualTo(2); assertTrue(cursor.moveToFirst()); assertThat(cursor.getString(0)).isEqualTo("foo"); assertThat(cursor.getLong(1)).isEqualTo(10L); assertThat(cursor.getFloat(2)).isEqualTo(0.1f); assertTrue(cursor.moveToNext()); assertThat(cursor.getString(0)).isEqualTo("baz"); assertThat(cursor.getLong(1)).isEqualTo(20L); assertTrue(cursor.isNull(2)); assertFalse(cursor.moveToNext()); }