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