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();
}
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();
}
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);
}
}
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;
}
}
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]));
}
Aggregations