List of usage examples for android.database MergeCursor MergeCursor
public MergeCursor(Cursor[] cursors)
From source file:com.silentcircle.contacts.list.ProfileAndContactsLoader.java
@Override public Cursor loadInBackground() { // First load the profile, if enabled. List<Cursor> cursors = new ArrayList<Cursor>(); if (mLoadProfile) { cursors.add(loadProfile());//from w w w . j a v a2 s . com } 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(); } }; }
From source file:ro.expectations.expenses.ui.overview.OverviewActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { MatrixCursor matrixCursor = new MatrixCursor( new String[] { ExpensesContract.Accounts._ID, ExpensesContract.Accounts.TITLE }); matrixCursor.addRow(new Object[] { "0", getString(R.string.all_accounts) }); MergeCursor mergeCursor = new MergeCursor(new Cursor[] { matrixCursor, data }); mSectionsPagerAdapter.swapCursor(mergeCursor); mTabLayout.setupWithViewPager(mViewPager); }
From source file:org.totschnig.myexpenses.dialog.SelectMainCategoryDialogFragment.java
@Override public void onLoadFinished(Loader<Cursor> arg0, Cursor data) { if (getArguments().getBoolean(KEY_WITH_ROOT)) { MatrixCursor extras = new MatrixCursor(projection); extras.addRow(new String[] { "0", getString(R.string.transform_subcategory_to_main), }); mCursor = new MergeCursor(new Cursor[] { extras, data }); } else {// ww w. ja va2 s. c o m mCursor = data; } mAdapter.swapCursor(mCursor); }
From source file:org.sufficientlysecure.keychain.ui.adapter.KeySectionedListAdapter.java
@Override public KeyListCursor swapCursor(KeyListCursor cursor) { if (cursor != null && (mQuery == null || TextUtils.isEmpty(mQuery))) { boolean isSecret = cursor.moveToFirst() && cursor.isSecret(); if (!isSecret) { MatrixCursor headerCursor = new MatrixCursor(KeyListCursor.PROJECTION); Long[] row = new Long[KeyListCursor.PROJECTION.length]; row[cursor.getColumnIndex(KeychainContract.KeyRings.HAS_ANY_SECRET)] = 1L; row[cursor.getColumnIndex(KeychainContract.KeyRings.MASTER_KEY_ID)] = 0L; headerCursor.addRow(row);//from w ww.j a va 2 s.c o m Cursor[] toMerge = { headerCursor, cursor.getWrappedCursor() }; cursor = KeyListCursor.wrap(new MergeCursor(toMerge)); } } return super.swapCursor(cursor); }
From source file:com.xbm.android.matisse.internal.loader.AlbumLoader.java
@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)); }/*from w ww . j av a2s .co m*/ 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 }); }
From source file:fr.s13d.photobackup.media.PBMediaStore.java
Cursor getAllMediasCursor() { String where = null;/* ww w . j av a 2 s.c om*/ 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 String[] projection = new String[] { "_id", "_data", "date_added" }; final ContentResolver cr = PBApplication.getApp().getContentResolver(); final Cursor[] cursors = new Cursor[backupVideos ? 2 : 1]; cursors[0] = cr.query(imagesUri, projection, where, null, DATE_ADDED_DESC); if (backupVideos) { cursors[1] = cr.query(videosUri, projection, where, null, DATE_ADDED_DESC); } if (cursors[0] == null) { Log.d(LOG_TAG, "Media cursor is null."); return null; } return new MergeCursor(cursors); }
From source file:org.thoughtcrime.securesms.contacts.ContactAccessorNewApi.java
@Override public Cursor getCursorForRecipientFilter(CharSequence constraint, ContentResolver mContentResolver) { String phone = ""; String cons = null;/*from ww w . j a va 2 s . c om*/ if (constraint != null) { cons = constraint.toString(); if (RecipientsAdapter.usefulAsDigits(cons)) { phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons); if (phone.equals(cons)) { 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(); result.add(Integer.valueOf(-1)); // ID result.add(Long.valueOf(-1)); // CONTACT_ID result.add(Integer.valueOf(Phone.TYPE_CUSTOM)); // TYPE result.add(phone); // NUMBER /* * The "\u00A0" keeps Phone.getDisplayLabel() from deciding * to display the default label ("Home") next to the transformation * of the letters into numbers. */ result.add("\u00A0"); // LABEL result.add(cons); // NAME 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; } }
From source file:ro.expectations.expenses.ui.transactions.TransactionsActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { MatrixCursor matrixCursor = new MatrixCursor( new String[] { ExpensesContract.Accounts._ID, ExpensesContract.Accounts.TITLE }); matrixCursor.addRow(new Object[] { "0", getString(R.string.all_accounts) }); MergeCursor mergeCursor = new MergeCursor(new Cursor[] { matrixCursor, data }); ((AccountsSpinnerAdapter) mAccountsSpinner.getAdapter()).swapCursor(mergeCursor); setSpinnerItemById(mSelectedAccountId); }
From source file:io.github.carlorodriguez.alarmon.MediaListView.java
protected void query(Uri contentUri, String nameColumn, String selection, int rowResId, String[] displayColumns, int[] resIDs) { this.nameColumn = nameColumn; final ArrayList<String> queryColumns = new ArrayList<>(displayColumns.length + 1); queryColumns.addAll(Arrays.asList(displayColumns)); // The ID column is required for the SimpleCursorAdapter. Make sure to // add it if it's not already there. if (!queryColumns.contains(BaseColumns._ID)) { queryColumns.add(BaseColumns._ID); }/*from w w w. jav a2 s. c om*/ Cursor dbCursor; if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { dbCursor = getContext().getContentResolver().query(contentUri, queryColumns.toArray(new String[queryColumns.size()]), selection, null, sortOrder); } else { dbCursor = new MatrixCursor(queryColumns.toArray(new String[queryColumns.size()])); } if (staticCursor != null) { Cursor[] cursors = new Cursor[] { staticCursor, dbCursor }; cursor = new MergeCursor(cursors); } else { cursor = dbCursor; } manageCursor(cursor); this.contentUri = contentUri; final SimpleCursorAdapter adapter = new SimpleCursorAdapter(getContext(), rowResId, cursor, displayColumns, resIDs, 1); // Use a custom binder to highlight the selected element. adapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getVisibility() == View.VISIBLE && view instanceof TextView) { TextView text = (TextView) view; if (isItemChecked(cursor.getPosition())) { text.setTypeface(Typeface.DEFAULT_BOLD); } else { text.setTypeface(Typeface.DEFAULT); } } // Let the default binder do the real work. return false; } }); setAdapter(adapter); setOnItemClickListener(this); }
From source file:com.andremion.louvre.data.MediaLoader.java
/** * Add "All Media" item as the first row of bucket items. * * @param cursor The original data of all bucket items * @return The data with "All Media" item added *///from w ww .j a v a 2 s. c o m private Cursor addAllMediaBucketItem(@Nullable Cursor cursor) { if (cursor == null || !cursor.moveToPosition(0)) { return null; } ensureActivityAttached(); long id = ALL_MEDIA_BUCKET_ID; String label = mActivity.getString(R.string.activity_gallery_bucket_all_media); String data = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); MatrixCursor allMediaRow = new MatrixCursor(BUCKET_PROJECTION); allMediaRow.newRow().add(id).add(label).add(data); return new MergeCursor(new Cursor[] { allMediaRow, cursor }); }