Search in sources :

Example 66 with MatrixCursor

use of android.database.MatrixCursor in project newsrob by marianokamp.

the class DB method findByFullText.

public Cursor findByFullText(String query) {
    Timing t = new Timing("DB.findByFullText " + query + ".", context);
    // 1.6 version
    /*
         * StringBuilder sb = new StringBuilder("SELECT _id, title AS " +
         * SearchManager.SUGGEST_COLUMN_TEXT_1 + ", feed_title AS " +
         * SearchManager.SUGGEST_COLUMN_TEXT_2 + ", atom_id AS " +
         * SearchManager.SUGGEST_COLUMN_INTENT_DATA +
         * ", \"com.newsrob.VIEW\" AS " +
         * SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ", \"" +
         * SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT + "\" AS " +
         * SearchManager.SUGGEST_COLUMN_SHORTCUT_ID +
         * " FROM entries_view WHERE ");
         */
    StringBuilder sb = new StringBuilder("SELECT _id, title AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ", feed_title AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ", atom_id AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA + ", \"com.newsrob.VIEW\" AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + " FROM entries_view WHERE ");
    sb.append(processFullTextQueryString(query) + " LIMIT 10");
    // if (readOnlyDB == null)
    // readOnlyDB = getReadableDatabase();
    Cursor cursor = readOnlyDB.rawQuery(sb.toString(), null);
    MatrixCursor mc = new MatrixCursor(SearchProvider.COLUMNS);
    while (cursor.moveToNext()) {
        String[] values = new String[SearchProvider.COLUMNS.length];
        for (int i = 0; i < values.length; i++) {
            values[i] = cursor.getString(i);
        }
        mc.addRow(values);
    }
    cursor.close();
    // readOnlyDB.close();
    t.stop();
    return mc;
}
Also used : Timing(com.newsrob.util.Timing) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor)

Example 67 with MatrixCursor

use of android.database.MatrixCursor in project AndroidChromium by JackyAndroid.

the class ChromeFileProvider method query.

@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);
    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;
}
Also used : MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) Uri(android.net.Uri) MatrixCursor(android.database.MatrixCursor)

Example 68 with MatrixCursor

use of android.database.MatrixCursor in project UltimateAndroid by cymcsg.

the class CursorDSLV method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drag_sort_listview_cursor_main);
    String[] cols = { "name" };
    int[] ids = { R.id.text };
    adapter = new MAdapter(this, R.layout.drag_sort_listview_list_item_click_remove, null, cols, ids, 0);
    DragSortListView dslv = (DragSortListView) findViewById(android.R.id.list);
    dslv.setAdapter(adapter);
    // build a cursor from the String array
    MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "name" });
    String[] artistNames = getResources().getStringArray(R.array.jazz_artist_names);
    for (int i = 0; i < artistNames.length; i++) {
        cursor.newRow().add(i).add(artistNames[i]);
    }
    adapter.changeCursor(cursor);
}
Also used : DragSortListView(com.marshalchen.common.uimodule.dragSortListView.DragSortListView) MatrixCursor(android.database.MatrixCursor)

Example 69 with MatrixCursor

use of android.database.MatrixCursor in project android_frameworks_base by DirtyUnicorns.

the class ModelTest method testSort_time.

public void testSort_time() {
    final int DL_COUNT = 3;
    MatrixCursor c = new MatrixCursor(COLUMNS);
    Set<String> currentDownloads = new HashSet<>();
    // Add some files
    for (int i = 0; i < ITEM_COUNT; i++) {
        MatrixCursor.RowBuilder row = c.newRow();
        row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY);
        row.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
        row.add(Document.COLUMN_LAST_MODIFIED, System.currentTimeMillis());
    }
    // Add some current downloads (no timestamp)
    for (int i = ITEM_COUNT; i < ITEM_COUNT + DL_COUNT; i++) {
        MatrixCursor.RowBuilder row = c.newRow();
        String id = Integer.toString(i);
        row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY);
        row.add(Document.COLUMN_DOCUMENT_ID, id);
        currentDownloads.add(id);
    }
    DirectoryResult r = new DirectoryResult();
    r.cursor = c;
    r.sortOrder = State.SORT_ORDER_LAST_MODIFIED;
    model.update(r);
    String[] ids = model.getModelIds();
    // Check that all items were accounted for
    assertEquals(ITEM_COUNT + DL_COUNT, ids.length);
    // Check that active downloads are sorted to the top.
    for (int i = 0; i < DL_COUNT; i++) {
        assertTrue(currentDownloads.contains(ids[i]));
    }
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) MatrixCursor(android.database.MatrixCursor) HashSet(java.util.HashSet)

Example 70 with MatrixCursor

use of android.database.MatrixCursor in project android_frameworks_base by DirtyUnicorns.

the class SectionBreakDocumentsAdapterWrapperTest method testItemCount_allDirs.

// Tests that the item count is correct for a directory containing only subdirs.
public void testItemCount_allDirs() {
    MatrixCursor c = new MatrixCursor(TestModel.COLUMNS);
    for (int i = 0; i < 5; ++i) {
        MatrixCursor.RowBuilder row = c.newRow();
        row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY);
        row.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
        row.add(Document.COLUMN_SIZE, i);
        row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
    }
    DirectoryResult r = new DirectoryResult();
    r.cursor = c;
    r.sortOrder = State.SORT_ORDER_SIZE;
    mModel.update(r);
    assertEquals(mModel.getItemCount(), mAdapter.getItemCount());
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) MatrixCursor(android.database.MatrixCursor)

Aggregations

MatrixCursor (android.database.MatrixCursor)259 Cursor (android.database.Cursor)37 DirectoryResult (com.android.documentsui.DirectoryResult)35 RowBuilder (android.database.MatrixCursor.RowBuilder)30 File (java.io.File)30 MergeCursor (android.database.MergeCursor)18 Uri (android.net.Uri)18 Test (org.junit.Test)17 Setting (com.android.providers.settings.SettingsState.Setting)15 FileNotFoundException (java.io.FileNotFoundException)15 ArrayList (java.util.ArrayList)13 Bundle (android.os.Bundle)10 BitSet (java.util.BitSet)10 Random (java.util.Random)10 IOException (java.io.IOException)7 LinkedList (java.util.LinkedList)7 ContentValues (android.content.ContentValues)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)5