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])); }
@Override public Cursor loadInBackground() { Cursor albums = super.loadInBackground(); MatrixCursor allAlbum = new MatrixCursor(COLUMNS); int totalCount = 0; String allAlbumCoverPath = ""; if (albums != null) { while (albums.moveToNext()) { totalCount += albums.getInt(albums.getColumnIndex(COLUMN_COUNT)); } if (albums.moveToFirst()) { allAlbumCoverPath = albums.getString(albums.getColumnIndex(MediaStore.MediaColumns.DATA)); } } allAlbum.addRow(new String[]{Album.ALBUM_ID_ALL, Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, allAlbumCoverPath, String.valueOf(totalCount)}); return new MergeCursor(new Cursor[]{allAlbum, albums}); }
private MergeCursor mergeDates(long nextId, Map<Long, MatrixCursor> agenda) { List<Cursor> allCursors = new ArrayList<>(); for (long dateMilli: agenda.keySet()) { DateTime date = new DateTime(dateMilli); MatrixCursor dateCursor = new MatrixCursor(Columns.AGENDA_SEPARATOR_COLS); MatrixCursor.RowBuilder dateRow = dateCursor.newRow(); dateRow.add(nextId++); dateRow.add(userTimeFormatter.formatDate(AgendaUtils.buildOrgDateTimeFromDate(date, null))); dateRow.add(1); // Separator allCursors.add(dateCursor); allCursors.add(agenda.get(dateMilli)); } return new MergeCursor(allCursors.toArray(new Cursor[allCursors.size()])); }
@Override public Cursor loadInBackground() { Cursor albums = super.loadInBackground(); MatrixCursor allAlbum = new MatrixCursor(COLUMNS); int totalCount = 0; while (albums.moveToNext()) { totalCount += albums.getInt(albums.getColumnIndex(COLUMN_COUNT)); } String allAlbumCoverPath; if (albums.moveToFirst()) { allAlbumCoverPath = albums.getString(albums.getColumnIndex(MediaStore.MediaColumns.DATA)); } else { allAlbumCoverPath = ""; } allAlbum.addRow(new String[]{Album.ALBUM_ID_ALL, Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, allAlbumCoverPath, String.valueOf(totalCount)}); return new MergeCursor(new Cursor[]{allAlbum, albums}); }
public final Cursor o() { hqr localhqr = new hqr(lna.a); Object[] arrayOfObject = new Object[2]; arrayOfObject[0] = Integer.valueOf(0); arrayOfObject[1] = Integer.valueOf(2); localhqr.a(arrayOfObject); Cursor localCursor1 = this.t.a(this.s, lnc.c, this.r); if (localCursor1 != null) { localCursor1.registerContentObserver(this.u); } if ((localCursor1 == null) || (localCursor1.getCount() == 0)) { return localCursor1; } Cursor localCursor2 = this.t.b(this.s, lnd.a, this.r); if (localCursor2 != null) { localCursor2.registerContentObserver(this.u); } return new MergeCursor(new Cursor[] { localhqr, localCursor1, localCursor2 }); }
public final Cursor o() { Cursor localCursor = DreamSettingsActivity.a(this.l, aau.ft); isv[] arrayOfisv = efj.c(this.l, 0, 5); MatrixCursor localMatrixCursor = new MatrixCursor(DreamSettingsActivity.d); Object[] arrayOfObject = new Object[DreamSettingsActivity.d.length]; int i = arrayOfisv.length; for (int j = 0; j < i; j++) { isv localisv = arrayOfisv[j]; Arrays.fill(arrayOfObject, null); arrayOfObject[0] = Integer.valueOf(0); arrayOfObject[3] = Integer.valueOf(1); arrayOfObject[1] = localisv.a; arrayOfObject[2] = localisv.b; localMatrixCursor.addRow(arrayOfObject); } return new MergeCursor(new Cursor[] { localCursor, localMatrixCursor }); }
public void testIteratorWithMergeCursor() { MatrixCursor cursor1 = new MatrixCursor(new String[]{"_id"}); cursor1.addRow(new Object[]{1L}); MatrixCursor cursor2 = new MatrixCursor(new String[]{"_id", "stringProperty"}); cursor2.addRow(new Object[]{2L, "Test"}); MergeCursor mergeCursor = new MergeCursor(new Cursor[]{cursor1, cursor2}); mergeCursor.moveToPosition(-1); QueryResultIterable<TestEntity> iterable = new QueryResultIterable<TestEntity>(mergeCursor, mStore.getEntityConverter(TestEntity.class)); TestEntity te = iterable.get(); assertEquals(1L, te._id.longValue()); assertEquals(null, te.stringProperty); mergeCursor.moveToPosition(1); iterable = new QueryResultIterable<TestEntity>(mergeCursor, mStore.getEntityConverter(TestEntity.class)); te = iterable.get(); assertEquals(2L, te._id.longValue()); assertEquals("Test", te.stringProperty); }
@Override public Cursor loadInBackground() { ContactsDatabase contactsDatabase = DatabaseFactory.getContactsDatabase(getContext()); ArrayList<Cursor> cursorList = new ArrayList<>(3); cursorList.add(contactsDatabase.querySilenceContacts(filter)); if (includeSmsContacts) { cursorList.add(contactsDatabase.querySystemContacts(filter)); } if (!TextUtils.isEmpty(filter) && NumberUtil.isValidSmsOrEmail(filter)) { cursorList.add(contactsDatabase.getNewNumberCursor(filter)); } return new MergeCursor(cursorList.toArray(new Cursor[0])); }
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.LAST_SEEN}, 1); switchToArchiveCursor.addRow(new Object[] {-1L, System.currentTimeMillis(), archivedCount, "-1", null, 1, ThreadDatabase.DistributionTypes.ARCHIVE, 0, null, 0, -1, 0}); cursorList.add(switchToArchiveCursor); } return new MergeCursor(cursorList.toArray(new Cursor[0])); }
Cursor getAllMediasCursor() { String where = null; final SharedPreferences prefs = getDefaultSharedPreferences(PBApplication.getApp()); final Set<String> bucketIds = prefs.getStringSet(PBConstants.PREF_PICTURE_FOLDER_LIST, null); if (bucketIds != null && !bucketIds.isEmpty()) { final String bucketString = TextUtils.join(", ", bucketIds); where = "bucket_id in (" + bucketString + ")"; } final boolean backupVideos = prefs.getBoolean(PBConstants.PREF_MEDIA_BACKUP_VIDEO, false); final ContentResolver cr = PBApplication.getApp().getContentResolver(); final Cursor[] cursors = new Cursor[backupVideos ? 2 : 1]; cursors[0] = cr.query(imagesUri, imagesProjection, where, null, DATE_ADDED_DESC); if (backupVideos) { cursors[1] = cr.query(videosUri, imagesProjection, where, null, DATE_ADDED_DESC); } if (cursors[0] == null) { Log.d(LOG_TAG, "Media cursor is null."); return null; } return new MergeCursor(cursors); }
@Override protected void onPostExecute(Cursor cursor) { super.onPostExecute(cursor); // Reset as late as possible, otherwise the idiotic "empty view" is shown if (params.reset) { log.fine("Reset flag, clearing and closing existing cursors"); cursors.clear(); Cursor current = getWrappedAdapter().swapCursor(null); if (current != null) current.close(); requiresRefresh.set(false); } if (cursor != null) { log.fine("Merging query result cursor with existing cursors"); cursors.add(cursor); getWrappedAdapter().swapCursor(new MergeCursor(cursors.toArray(new Cursor[cursors.size()]))); } onPostExecuteQuery(params); }
@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(); }
@Override public Cursor loadInBackground() { // First load the profile, if enabled. List<Cursor> cursors = new ArrayList<Cursor>(); if (mLoadProfile) { cursors.add(loadProfile()); } final Cursor contactsCursor = super.loadInBackground(); cursors.add(contactsCursor); return new MergeCursor(cursors.toArray(new Cursor[cursors.size()])) { @Override public Bundle getExtras() { // Need to get the extras from the contacts cursor. return contactsCursor.getExtras(); } }; }
/** Creates the merged cursor representing the data to show in the call log. */ /* TODO @GuardedBy("this") */ private Cursor createMergedCursor() { try { final boolean hasNewCalls = mNewCallsCursor.getCount() != 0; final boolean hasOldCalls = mOldCallsCursor.getCount() != 0; if (!hasNewCalls) { Closeables.closeQuietly(mNewCallsCursor); // Return only the old calls, without the header. return mOldCallsCursor; } if (!hasOldCalls) { Closeables.closeQuietly(mOldCallsCursor); // Return only the new calls. return new MergeCursor(new Cursor[]{ createNewCallsHeaderCursor(), mNewCallsCursor }); } return new MergeCursor(new Cursor[]{ createNewCallsHeaderCursor(), mNewCallsCursor, createOldCallsHeaderCursor(), mOldCallsCursor}); } finally { // Any cursor still open is now owned, directly or indirectly, by the caller. mNewCallsCursor = null; mOldCallsCursor = null; } }
public static synchronized Cursor getCursor(final Context context, boolean isStranger) { if (isStranger) { return getDB(context).query(RandoDBHelper.RandoTable.NAME, null, RandoDBHelper.RandoTable.COLUMN_RANDO_STATUS + " = '" + Rando.Status.IN.name() + "'", null, null, null, RandoDBHelper.RandoTable.COLUMN_USER_RANDO_DATE + " DESC", null); } else { // randos to upload Cursor cursor1 = getDB(context).query(RandoDBHelper.RandoUploadTable.NAME, RandoDBHelper.RandoUploadTable.ALL_COLUMNS, null, null, null, null, RandoDBHelper.RandoUploadTable.COLUMN_DATE + " " + "DESC", null); // uploaded randos Cursor cursor2 = getDB(context).query(RandoDBHelper.RandoTable.NAME, null, RandoDBHelper.RandoTable.COLUMN_RANDO_STATUS + " = '" + Rando.Status.OUT.name() + "'", null, null, null, RandoDBHelper.RandoTable.COLUMN_USER_RANDO_DATE + " DESC", null); return new MergeCursor(new Cursor[] {cursor1, cursor2}); } }
private Cursor addEmptyItem(Cursor cursor) { MatrixCursor matrixCursor = null; try { matrixCursor = new MatrixCursor(new String[] { Database.SHADERS_ID, Database.SHADERS_THUMB, Database.SHADERS_NAME, Database.SHADERS_MODIFIED }); matrixCursor.addRow(new Object[] { 0, null, getString(R.string.no_shader_selected), null }); return new MergeCursor(new Cursor[] { matrixCursor, cursor }); } finally { if (matrixCursor != null) { matrixCursor.close(); } } }
@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, "\u21e2", ContactsDatabase.NEW_TYPE}); cursorList.add(newNumberCursor); } return new MergeCursor(cursorList.toArray(new Cursor[0])); }
@Override public Cursor loadInBackground() { // First of all, get all active accounts ArrayList<SipProfile> accounts = SipProfile.getAllProfiles(getContext(), true, new String[] { SipProfile.FIELD_ID, SipProfile.FIELD_ACC_ID, SipProfile.FIELD_ACTIVE, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD, SipProfile.FIELD_PRIORITY, SipProfile.FIELD_ANDROID_GROUP, SipProfile.FIELD_PUBLISH_ENABLED, SipProfile.FIELD_REG_URI, SipProfile.FIELD_PROXY }); Cursor[] cursorsToMerge = new Cursor[2 * accounts.size()]; int i = 0; for (SipProfile acc : accounts) { cursorsToMerge[i++] = createHeaderCursorFor(acc); cursorsToMerge[i++] = createContentCursorFor(acc); } getContext().getContentResolver().registerContentObserver(SipProfile.ACCOUNT_STATUS_URI, true, loaderObserver); if(cursorsToMerge.length > 0) { MergeCursor mg = new MergeCursor(cursorsToMerge); mg.registerContentObserver(loaderObserver); return mg; }else { return null; } }
@Override public Cursor loadInBackground() { Cursor result = super.loadInBackground(); if (!mEnableCapture || !MediaStoreCompat.hasCameraFeature(getContext())) { return result; } MatrixCursor dummy = new MatrixCursor(PROJECTION); dummy.addRow(new Object[]{Item.ITEM_ID_CAPTURE, Item.ITEM_DISPLAY_NAME_CAPTURE, "", 0, 0}); return new MergeCursor(new Cursor[]{dummy, result}); }
@Override protected Observable<Gallery> create(final String query) { final Observable<GeraltWomenCursor> avatarObservable = womenRepository.getWoman(id); final Observable<GeraltWomanPhotoCursor> photosObservable = repository.getPhotos(id); return Observable.combineLatest(avatarObservable, photosObservable, (womenCursor, photos) -> { final GeraltWomanPhotoCursor avatar = new GeraltWomanPhotoCursorFromWoman(womenCursor); womenCursor.moveToFirst(); return new Gallery(womenCursor.getPhotoCount() + 1, new GeraltWomanPhotoCursor(new MergeCursor(new Cursor[]{avatar, photos}))); }); }
@Nullable @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String order) { int match = matcher.match(uri); if (match != DASHBOARD) return super.query(uri, projection, selection, selectionArgs, order); MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "id", "display_name", "is_team", "color"}); ProjectTeams teams = new ProjectTeams(getContext()); ProjectProject projectProject = new ProjectProject(getContext()); // loading personal projects List<ListRow> personalProjects = projectProject.select("team_id is NULL", null); if (!personalProjects.isEmpty()) { matrixCursor.addRow(new Object[]{"-99", "-1", "Personal", true, null}); addProjects(personalProjects, matrixCursor); } for (ListRow row : teams.select()) { matrixCursor.addRow(new Object[]{row.getInt("_id"), row.getInt("id"), row.getString("name"), true, null}); addProjects(projectProject.select("team_id = ?", new String[]{row.getString("_id")}), matrixCursor); } return new MergeCursor(new Cursor[]{matrixCursor}); }
@Override public Cursor loadInBackground() { ContactsDatabase contactsDatabase = DatabaseFactory.getContactsDatabase(getContext()); ArrayList<Cursor> cursorList = new ArrayList<>(3); if (mode != MODE_SMS_ONLY) { cursorList.add(contactsDatabase.queryTextSecureContacts(filter)); } if (mode == MODE_ALL) { cursorList.add(contactsDatabase.querySystemContacts(filter)); } else if (mode == MODE_SMS_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, "\u21e2", ContactsDatabase.NEW_TYPE}); cursorList.add(newNumberCursor); } return new MergeCursor(cursorList.toArray(new Cursor[0])); }
private void swapTargetCursor() { if (receivingAddressBookCursor == null && receivingAddressNameCursor == null) targetAdapter.swapCursor(null); else if (receivingAddressBookCursor != null && receivingAddressNameCursor == null) targetAdapter.swapCursor(receivingAddressBookCursor); else if (receivingAddressBookCursor == null && receivingAddressNameCursor != null) targetAdapter.swapCursor(receivingAddressNameCursor); else targetAdapter.swapCursor( new MergeCursor(new Cursor[] { receivingAddressBookCursor, receivingAddressNameCursor })); }
@Override public Cursor loadInBackground() { Cursor result = super.loadInBackground(); if (!mEnableCapture || !VanConfig.getInstance().hasCameraFeature(getContext())) { return result; } MatrixCursor dummy = new MatrixCursor(PROJECTION); dummy.addRow(new Object[]{MediaInfo.ITEM_ID_CAPTURE, MediaInfo.ITEM_DISPLAY_NAME_CAPTURE, "", 0, 0}); return new MergeCursor(new Cursor[]{dummy, result}); }
/** Devuelve las todas canciones correspondientes al string @nombre */ public Cursor searchSongs(String nombre){ Cursor cursor1 = mDb.rawQuery("select _id, titulo from canciones where titulo LIKE '%"+ nombre+ "%';",null); Cursor cursor2 = mDb.rawQuery("select _id, nombre as titulo from artistas where nombre LIKE '%"+ nombre+ "%';",null); Cursor cursor3 = mDb.rawQuery("select _id, titulo from albums where titulo LIKE '%"+ nombre+ "%';",null); return new MergeCursor(new Cursor[]{cursor1,cursor2,cursor3}); // return mDb.query(DATABASE_TABLE_CANCIONES, // new String[] {"_id","titulo","duracion","valoracion","album","genero"} // , "titulo LIKE '%"+ nombre+ "%'",null,null,null,"titulo"); }
public final Cursor o() { if (this.r == -1) { return null; } Cursor localCursor = DreamSettingsActivity.a(this.l, aau.iH); SQLiteDatabase localSQLiteDatabase = bqj.a(this.l, this.r).getReadableDatabase(); MatrixCursor localMatrixCursor = new MatrixCursor(DreamSettingsActivity.e); if (DatabaseUtils.longForQuery(localSQLiteDatabase, "SELECT count(*) FROM all_photos WHERE is_primary = 1 AND media_attr & 32 = 0 AND media_attr & 128 = 0 AND media_attr & 64 = 0", null) > 0L) { Object[] arrayOfObject2 = new Object[4]; arrayOfObject2[0] = Integer.valueOf(0); arrayOfObject2[1] = null; arrayOfObject2[2] = this.l.getString(aau.fr); arrayOfObject2[3] = Integer.valueOf(3); localMatrixCursor.addRow(arrayOfObject2); } String[] arrayOfString = new String[1]; arrayOfString[0] = this.s; String str = jrf.a(0, arrayOfString); if (DatabaseUtils.longForQuery(localSQLiteDatabase, "SELECT count(*) FROM all_tiles WHERE view_id = ? AND media_attr & 512 == 0 AND type == 4 AND media_attr & 32 = 0 AND media_attr & 128 = 0 AND media_attr & 64 = 0", new String[] { str }) > 0L) { Object[] arrayOfObject1 = new Object[4]; arrayOfObject1[0] = Integer.valueOf(0); arrayOfObject1[1] = str; arrayOfObject1[2] = this.l.getString(aau.fs); arrayOfObject1[3] = Integer.valueOf(2); localMatrixCursor.addRow(arrayOfObject1); } if (DatabaseUtils.longForQuery(localSQLiteDatabase, "SELECT count(*) FROM all_tiles WHERE view_id = ?", this.t) == 0L) { new bmt(this.l, this.r, this.s, null, false).i(); } return new MergeCursor(new Cursor[] { localCursor, localMatrixCursor, localSQLiteDatabase.query("all_tiles", DreamSettingsActivity.e, "view_id = ?", this.t, null, null, null) }); }
public final Cursor o() { hhh localhhh = (hhh)mbb.a(this.l, hhh.class); ArrayList localArrayList = new ArrayList(4); Cursor localCursor; if (this.u) { localCursor = localhhh.a(this.s); if (localCursor == null) { break label170; } } label170: for (Object localObject = new hmq(localCursor, -1 + r.length);; localObject = localCursor) { if (this.u) { MatrixCursor localMatrixCursor = new MatrixCursor(r); int i = localMatrixCursor.getColumnIndexOrThrow("profileItemType"); String[] arrayOfString = new String[r.length]; arrayOfString[i] = "1"; localMatrixCursor.addRow(arrayOfString); localArrayList.add(localMatrixCursor); } if (localObject != null) { localArrayList.add(localObject); } return new MergeCursor((Cursor[])localArrayList.toArray(new Cursor[localArrayList.size()])); localCursor = localhhh.b(this.s, this.t); break; } }
private void a(Cursor paramCursor) { ArrayList localArrayList = new ArrayList(); if (this.af) { MatrixCursor localMatrixCursor1 = new MatrixCursor(ab); localMatrixCursor1.addRow(a(-101L)); localArrayList.add(localMatrixCursor1); } if ((this.aa) || (!this.Z)) { MatrixCursor localMatrixCursor2 = new MatrixCursor(ab); localMatrixCursor2.addRow(a(-102L)); localArrayList.add(localMatrixCursor2); } if (paramCursor != null) { localArrayList.add(paramCursor); } if (localArrayList.size() > 0) { Cursor[] arrayOfCursor = new Cursor[localArrayList.size()]; localArrayList.toArray(arrayOfCursor); MergeCursor localMergeCursor = new MergeCursor(arrayOfCursor); this.ae.b(localMergeCursor); if (this.a != -1) { this.c.setSelection(this.a); } } }
public final Cursor o() { Cursor[] arrayOfCursor = new Cursor[2]; arrayOfCursor[0] = p(); arrayOfCursor[1] = r(); return new MergeCursor(arrayOfCursor); }
@Override public Cursor swapCursor(Cursor newCursor) { checkPhotonCapable(); if (newCursor == null) { mCursorDataCount = 0; return super.swapCursor(newCursor); } mCursorDataCount = newCursor.getCount(); // to mimic the infinite the notification's infinite scroll ui // (with a progress spinner on the bottom of the list), we'll need to add // extra cells in the gridview: // - spacer cells as fillers to place the progress spinner on the first cell (_id < 0) // - progress spinner cell (_id = Integer.MIN_VALUE) // use a matrix cursor to create the extra rows MatrixCursor matrixCursor = new MatrixCursor(new String[] { "_id" }); // add spacer cells int columnCount = getColumnCount(mContext); int remainder = newCursor.getCount() % columnCount; if (remainder > 0) { int spaceCount = columnCount - remainder; for (int i = 0; i < spaceCount; i++ ) { int id = i - spaceCount; matrixCursor.addRow(new Object[] {id + ""}); } } // add progress spinner cell matrixCursor.addRow(new Object[] { Integer.MIN_VALUE }); // use a merge cursor to place merge the extra rows at the bottom of the newly swapped cursor MergeCursor mergeCursor = new MergeCursor(new Cursor[] { newCursor, matrixCursor }); return super.swapCursor(mergeCursor); }
public Cursor query(String filter, boolean pushOnly) { // FIXME: This doesn't make sense to me. You pass in pushOnly, but then // conditionally check to see whether other contacts should be included // in the query method itself? I don't think this method should have any // understanding of that stuff. final boolean includeAndroidContacts = !pushOnly && TextSecurePreferences.isSmsEnabled(context); final Cursor localCursor = queryLocalDb(filter); final Cursor androidCursor; final MatrixCursor newNumberCursor; if (includeAndroidContacts) { androidCursor = queryAndroidDb(filter); } else { androidCursor = null; } if (!TextUtils.isEmpty(filter) && NumberUtil.isValidSmsOrEmail(filter)) { newNumberCursor = new MatrixCursor(CONTACTS_PROJECTION, 1); newNumberCursor.addRow(new Object[]{-1L, context.getString(R.string.contact_selection_list__unknown_contact), ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM, "\u21e2", filter, NORMAL_TYPE}); } else { newNumberCursor = null; } List<Cursor> cursors = new ArrayList<Cursor>(); if (localCursor != null) cursors.add(localCursor); if (androidCursor != null) cursors.add(androidCursor); if (newNumberCursor != null) cursors.add(newNumberCursor); switch (cursors.size()) { case 0: return null; case 1: return cursors.get(0); default: return new MergeCursor(cursors.toArray(new Cursor[]{})); } }
@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(); }
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(); }
@Test public void testGetDataSingleCursor() throws Exception { Cursor[] cursors = new Cursor[1]; cursors[0] = dbCursor1; cursor = new MergeCursor( cursors ); cursor.moveToFirst(); assertDataCursor1(); }
@Test public void testGetDataMultipleCursor() throws Exception { Cursor[] cursors = new Cursor[2]; cursors[0] = dbCursor1; cursors[1] = dbCursor2; cursor = new MergeCursor( cursors ); cursor.moveToFirst(); assertDataCursor1(); cursor.moveToNext(); assertDataCursor2(); }
@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); } }
public final Cursor getFeedMediaCursorByItemID(String... mediaIds) { int length = mediaIds.length; if (length > IN_OPERATOR_MAXIMUM) { Log.w(TAG, "Length of id array is larger than " + IN_OPERATOR_MAXIMUM + ". Creating multiple cursors"); int numCursors = (int) (((double) length) / (IN_OPERATOR_MAXIMUM)) + 1; Cursor[] cursors = new Cursor[numCursors]; for (int i = 0; i < numCursors; i++) { int neededLength = 0; String[] parts = null; final int elementsLeft = length - i * IN_OPERATOR_MAXIMUM; if (elementsLeft >= IN_OPERATOR_MAXIMUM) { neededLength = IN_OPERATOR_MAXIMUM; parts = Arrays.copyOfRange(mediaIds, i * IN_OPERATOR_MAXIMUM, (i + 1) * IN_OPERATOR_MAXIMUM); } else { neededLength = elementsLeft; parts = Arrays.copyOfRange(mediaIds, i * IN_OPERATOR_MAXIMUM, (i * IN_OPERATOR_MAXIMUM) + neededLength); } cursors[i] = db.rawQuery("SELECT * FROM " + TABLE_NAME_FEED_MEDIA + " WHERE " + KEY_FEEDITEM + " IN " + buildInOperator(neededLength), parts); } return new MergeCursor(cursors); } else { return db.query(TABLE_NAME_FEED_MEDIA, null, KEY_FEEDITEM + " IN " + buildInOperator(length), mediaIds, null, null, null); } }