Search in sources :

Example 16 with MergeCursor

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

the class ShadowMergeCursorTest method assertBounds.

private void assertBounds(Cursor[] cursors, int expectedLength) {
    cursor = new MergeCursor(cursors);
    assertThat(cursor.getCount()).isEqualTo(expectedLength);
    assertThat(cursor.moveToFirst()).isTrue();
    for (int i = 0; i < expectedLength; i++) {
        assertThat(cursor.moveToPosition(i)).isTrue();
        assertThat(cursor.isAfterLast()).isFalse();
    }
    assertThat(cursor.moveToNext()).isFalse();
    assertThat(cursor.isAfterLast()).isTrue();
    assertThat(cursor.moveToPosition(expectedLength)).isFalse();
}
Also used : MergeCursor(android.database.MergeCursor)

Example 17 with MergeCursor

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

the class ShadowMergeCursorTest method testCloseCursors.

@Test
public void testCloseCursors() throws Exception {
    Cursor[] cursors = new Cursor[2];
    cursors[0] = dbCursor1;
    cursors[1] = dbCursor2;
    cursor = new MergeCursor(cursors);
    assertThat(cursor.isClosed()).isFalse();
    assertThat(dbCursor1.isClosed()).isFalse();
    assertThat(dbCursor2.isClosed()).isFalse();
    cursor.close();
    assertThat(cursor.isClosed()).isTrue();
    assertThat(dbCursor1.isClosed()).isTrue();
    assertThat(dbCursor2.isClosed()).isTrue();
}
Also used : MergeCursor(android.database.MergeCursor) MergeCursor(android.database.MergeCursor) Cursor(android.database.Cursor) SQLiteCursor(android.database.sqlite.SQLiteCursor) Test(org.junit.Test)

Example 18 with MergeCursor

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

the class ShadowMergeCursorTest method testColumnNamesMultipleCursors.

@Test
public void testColumnNamesMultipleCursors() throws Exception {
    Cursor[] cursors = new Cursor[2];
    cursors[0] = dbCursor1;
    cursors[1] = dbCursor2;
    cursor = new MergeCursor(cursors);
    for (int i = 0; i < TABLE_1_INSERTS.length; i++) {
        cursor.moveToPosition(i);
        String[] columnNames = cursor.getColumnNames();
        assertColumnNamesCursor1(columnNames);
    }
    for (int i = 0; i < TABLE_2_INSERTS.length; i++) {
        cursor.moveToPosition(i + TABLE_1_INSERTS.length);
        String[] columnNames = cursor.getColumnNames();
        assertColumnNamesCursor2(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 19 with MergeCursor

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

the class ContactAccessor method getCursorForRecipientFilter.

/***
   * If the code below looks shitty to you, that's because it was taken
   * directly from the Android source, where shitty code is all you get.
   */
public Cursor getCursorForRecipientFilter(CharSequence constraint, ContentResolver mContentResolver) {
    final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," + Contacts.DISPLAY_NAME + "," + Contacts.Data.IS_SUPER_PRIMARY + " DESC," + Phone.TYPE;
    final String[] PROJECTION_PHONE = { // 0
    Phone._ID, // 1
    Phone.CONTACT_ID, // 2
    Phone.TYPE, // 3
    Phone.NUMBER, // 4
    Phone.LABEL, // 5
    Phone.DISPLAY_NAME };
    String phone = "";
    String cons = null;
    if (constraint != null) {
        cons = constraint.toString();
        if (RecipientsAdapter.usefulAsDigits(cons)) {
            phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons);
            if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) {
                phone = "";
            } else {
                phone = phone.trim();
            }
        }
    }
    Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons));
    String selection = String.format("%s=%s OR %s=%s OR %s=%s", Phone.TYPE, Phone.TYPE_MOBILE, Phone.TYPE, Phone.TYPE_WORK_MOBILE, Phone.TYPE, Phone.TYPE_MMS);
    Cursor phoneCursor = mContentResolver.query(uri, PROJECTION_PHONE, null, null, SORT_ORDER);
    if (phone.length() > 0) {
        ArrayList result = new ArrayList();
        // ID
        result.add(Integer.valueOf(-1));
        // CONTACT_ID
        result.add(Long.valueOf(-1));
        // TYPE
        result.add(Integer.valueOf(Phone.TYPE_CUSTOM));
        // NUMBER
        result.add(phone);
        /*
    * The " " keeps Phone.getDisplayLabel() from deciding
    * to display the default label ("Home") next to the transformation
    * of the letters into numbers.
    */
        // LABEL
        result.add(" ");
        // NAME
        result.add(cons);
        ArrayList<ArrayList> wrap = new ArrayList<ArrayList>();
        wrap.add(result);
        ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap);
        return new MergeCursor(new Cursor[] { translated, phoneCursor });
    } else {
        return phoneCursor;
    }
}
Also used : ArrayList(java.util.ArrayList) MergeCursor(android.database.MergeCursor) MergeCursor(android.database.MergeCursor) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 20 with MergeCursor

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

the class ConversationListLoader method getUnarchivedConversationList.

private Cursor getUnarchivedConversationList() {
    List<Cursor> cursorList = new LinkedList<>();
    cursorList.add(DatabaseFactory.getThreadDatabase(context).getConversationList());
    int archivedCount = DatabaseFactory.getThreadDatabase(context).getArchivedConversationListCount();
    if (archivedCount > 0) {
        MatrixCursor switchToArchiveCursor = new MatrixCursor(new String[] { ThreadDatabase.ID, ThreadDatabase.DATE, ThreadDatabase.MESSAGE_COUNT, ThreadDatabase.RECIPIENT_IDS, ThreadDatabase.SNIPPET, ThreadDatabase.READ, ThreadDatabase.TYPE, ThreadDatabase.SNIPPET_TYPE, ThreadDatabase.SNIPPET_URI, ThreadDatabase.ARCHIVED, ThreadDatabase.STATUS, ThreadDatabase.RECEIPT_COUNT, ThreadDatabase.EXPIRES_IN, ThreadDatabase.LAST_SEEN }, 1);
        switchToArchiveCursor.addRow(new Object[] { -1L, System.currentTimeMillis(), archivedCount, "-1", null, 1, ThreadDatabase.DistributionTypes.ARCHIVE, 0, null, 0, -1, 0, 0, 0 });
        cursorList.add(switchToArchiveCursor);
    }
    return new MergeCursor(cursorList.toArray(new Cursor[0]));
}
Also used : MergeCursor(android.database.MergeCursor) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) MatrixCursor(android.database.MatrixCursor)

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