Search in sources :

Example 1 with MergeCursor

use of android.database.MergeCursor in project Signal-Android by WhisperSystems.

the class ContactsCursorLoader method loadInBackground.

@Override
public Cursor loadInBackground() {
    ContactsDatabase contactsDatabase = DatabaseFactory.getContactsDatabase(getContext());
    ArrayList<Cursor> cursorList = new ArrayList<>(3);
    if (mode != MODE_OTHER_ONLY) {
        cursorList.add(contactsDatabase.queryTextSecureContacts(filter));
    }
    if (mode == MODE_ALL) {
        cursorList.add(contactsDatabase.querySystemContacts(filter));
    } else if (mode == MODE_OTHER_ONLY) {
        cursorList.add(filterNonPushContacts(contactsDatabase.querySystemContacts(filter)));
    }
    if (!TextUtils.isEmpty(filter) && NumberUtil.isValidSmsOrEmail(filter)) {
        MatrixCursor newNumberCursor = new MatrixCursor(new String[] { ContactsDatabase.ID_COLUMN, ContactsDatabase.NAME_COLUMN, ContactsDatabase.NUMBER_COLUMN, ContactsDatabase.NUMBER_TYPE_COLUMN, ContactsDatabase.LABEL_COLUMN, ContactsDatabase.CONTACT_TYPE_COLUMN }, 1);
        newNumberCursor.addRow(new Object[] { -1L, getContext().getString(R.string.contact_selection_list__unknown_contact), filter, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM, "⇢", ContactsDatabase.NEW_TYPE });
        cursorList.add(newNumberCursor);
    }
    return new MergeCursor(cursorList.toArray(new Cursor[0]));
}
Also used : ArrayList(java.util.ArrayList) MergeCursor(android.database.MergeCursor) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor)

Example 2 with MergeCursor

use of android.database.MergeCursor in project robolectric by robolectric.

the class ShadowMergeCursorTest method testMoveToPositionEmptyCursor.

@Test
public void testMoveToPositionEmptyCursor() throws Exception {
    Cursor[] cursors = new Cursor[2];
    cursors[0] = null;
    cursors[1] = null;
    cursor = new MergeCursor(cursors);
    assertThat(cursor.getCount()).isEqualTo(0);
    assertThat(cursor.getColumnNames()).isNotNull();
    cursor.moveToPosition(0);
    assertThat(cursor.getColumnNames()).isNotNull();
}
Also used : MergeCursor(android.database.MergeCursor) MergeCursor(android.database.MergeCursor) Cursor(android.database.Cursor) SQLiteCursor(android.database.sqlite.SQLiteCursor) Test(org.junit.Test)

Example 3 with MergeCursor

use of android.database.MergeCursor in project robolectric by robolectric.

the class ShadowMergeCursorTest method testColumnNamesSingleCursor.

@Test
public void testColumnNamesSingleCursor() throws Exception {
    Cursor[] cursors = new Cursor[1];
    cursors[0] = dbCursor1;
    cursor = new MergeCursor(cursors);
    for (int i = 0; i < TABLE_1_INSERTS.length; i++) {
        cursor.moveToPosition(i);
        String[] columnNames = cursor.getColumnNames();
        assertColumnNamesCursor1(columnNames);
    }
}
Also used : MergeCursor(android.database.MergeCursor) MergeCursor(android.database.MergeCursor) Cursor(android.database.Cursor) SQLiteCursor(android.database.sqlite.SQLiteCursor) Test(org.junit.Test)

Example 4 with MergeCursor

use of android.database.MergeCursor in project robolectric by robolectric.

the class ShadowMergeCursorTest method testGetDataSingleCursor.

@Test
public void testGetDataSingleCursor() throws Exception {
    Cursor[] cursors = new Cursor[1];
    cursors[0] = dbCursor1;
    cursor = new MergeCursor(cursors);
    cursor.moveToFirst();
    assertDataCursor1();
}
Also used : MergeCursor(android.database.MergeCursor) MergeCursor(android.database.MergeCursor) Cursor(android.database.Cursor) SQLiteCursor(android.database.sqlite.SQLiteCursor) Test(org.junit.Test)

Example 5 with MergeCursor

use of android.database.MergeCursor in project platform_frameworks_base by android.

the class Model method updateModelData.

/**
     * Scan over the incoming cursor data, generate Model IDs for each row, and sort the IDs
     * according to the current sort order.
     */
private void updateModelData() {
    int[] positions = new int[mCursorCount];
    mIds = new String[mCursorCount];
    boolean[] isDirs = new boolean[mCursorCount];
    String[] displayNames = null;
    long[] longValues = null;
    switch(mSortOrder) {
        case SORT_ORDER_DISPLAY_NAME:
            displayNames = new String[mCursorCount];
            break;
        case SORT_ORDER_LAST_MODIFIED:
        case SORT_ORDER_SIZE:
            longValues = new long[mCursorCount];
            break;
    }
    String mimeType;
    mCursor.moveToPosition(-1);
    for (int pos = 0; pos < mCursorCount; ++pos) {
        if (!mCursor.moveToNext()) {
            Log.e(TAG, "Fail to move cursor to next pos: " + pos);
            return;
        }
        positions[pos] = pos;
        // with the authority to avoid collisions.
        if (mCursor instanceof MergeCursor) {
            mIds[pos] = getCursorString(mCursor, RootCursorWrapper.COLUMN_AUTHORITY) + "|" + getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
        } else {
            mIds[pos] = getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
        }
        mimeType = getCursorString(mCursor, Document.COLUMN_MIME_TYPE);
        isDirs[pos] = Document.MIME_TYPE_DIR.equals(mimeType);
        switch(mSortOrder) {
            case SORT_ORDER_DISPLAY_NAME:
                final String displayName = getCursorString(mCursor, Document.COLUMN_DISPLAY_NAME);
                displayNames[pos] = displayName;
                break;
            case SORT_ORDER_LAST_MODIFIED:
                longValues[pos] = getLastModified(mCursor);
                break;
            case SORT_ORDER_SIZE:
                longValues[pos] = getCursorLong(mCursor, Document.COLUMN_SIZE);
                break;
        }
    }
    switch(mSortOrder) {
        case SORT_ORDER_DISPLAY_NAME:
            binarySort(displayNames, isDirs, positions, mIds);
            break;
        case SORT_ORDER_LAST_MODIFIED:
        case SORT_ORDER_SIZE:
            binarySort(longValues, isDirs, positions, mIds);
            break;
    }
    // Populate the positions.
    mPositions.clear();
    for (int i = 0; i < mCursorCount; ++i) {
        mPositions.put(mIds[i], positions[i]);
    }
}
Also used : MergeCursor(android.database.MergeCursor) DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString)

Aggregations

MergeCursor (android.database.MergeCursor)31 Cursor (android.database.Cursor)25 MatrixCursor (android.database.MatrixCursor)13 SQLiteCursor (android.database.sqlite.SQLiteCursor)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Bundle (android.os.Bundle)5 DirectoryResult (com.android.documentsui.DirectoryResult)5 DocumentInfo.getCursorString (com.android.documentsui.model.DocumentInfo.getCursorString)5 RootInfo (com.android.documentsui.model.RootInfo)5 IOException (java.io.IOException)5 BitSet (java.util.BitSet)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ExecutionException (java.util.concurrent.ExecutionException)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 LinkedList (java.util.LinkedList)2 Intent (android.content.Intent)1 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)1 Uri (android.net.Uri)1 List (java.util.List)1