android.database.MergeCursor Java Examples
The following examples show how to use
android.database.MergeCursor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContactRepository.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@WorkerThread public Cursor querySignalContacts(@NonNull String query, boolean includeSelf) { Cursor cursor = TextUtils.isEmpty(query) ? recipientDatabase.getSignalContacts(includeSelf) : recipientDatabase.querySignalContacts(query, includeSelf); if (includeSelf && noteToSelfTitle.toLowerCase().contains(query.toLowerCase())) { Recipient self = Recipient.self(); boolean nameMatch = self.getDisplayName(context).toLowerCase().contains(query.toLowerCase()); boolean numberMatch = self.getE164().isPresent() && self.requireE164().contains(query); boolean shouldAdd = !nameMatch && !numberMatch; if (shouldAdd) { MatrixCursor selfCursor = new MatrixCursor(RecipientDatabase.SEARCH_PROJECTION_NAMES); selfCursor.addRow(new Object[]{ self.getId().serialize(), noteToSelfTitle, null, self.getE164().or(""), self.getEmail().orNull(), null, -1, RecipientDatabase.RegisteredState.REGISTERED.getId(), noteToSelfTitle }); cursor = cursor == null ? selfCursor : new MergeCursor(new Cursor[]{ cursor, selfCursor }); } } return new SearchCursorWrapper(cursor, SEARCH_CURSOR_MAPPERS); }
Example #2
Source File: EssAlbumLoader.java From FilePicker with MIT License | 6 votes |
@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}); }
Example #3
Source File: EssAlbumLoader.java From AndroidDownload with Apache License 2.0 | 6 votes |
@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}); }
Example #4
Source File: AlbumLoader.java From AlbumCameraRecorder with MIT License | 6 votes |
@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}); }
Example #5
Source File: CursorAdapterListFragment.java From android-test with Apache License 2.0 | 6 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); listItemCursor = new MatrixCursor(COLUMN_NAMES); populateData(); // Throw in a row with different column names... for the sake of science (testing). MatrixCursor surprise = new MatrixCursor(new String[] {"surprise!", "columns", "are different"}); surprise.addRow(new Object[] {1, 2, 3}); MergeCursor mergeCursor = new MergeCursor(new MatrixCursor[] {listItemCursor, surprise}); final ListAdapter cursorAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, mergeCursor, new String[] { COLUMN_STR, COLUMN_LEN }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); setListAdapter(cursorAdapter); }
Example #6
Source File: PBMediaStore.java From client-android with GNU General Public License v2.0 | 6 votes |
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); }
Example #7
Source File: AlbumLoader.java From Matisse with Apache License 2.0 | 6 votes |
@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}); }
Example #8
Source File: ConversationListLoader.java From Silence with GNU General Public License v3.0 | 6 votes |
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])); }
Example #9
Source File: ContactsCursorLoader.java From Silence with GNU General Public License v3.0 | 6 votes |
@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])); }
Example #10
Source File: AlbumMediaLoader.java From Matisse with Apache License 2.0 | 5 votes |
@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}); }
Example #11
Source File: ManageDownloadsActivity.java From android-viewer-for-khan-academy with GNU General Public License v3.0 | 5 votes |
private Cursor getDisplayOptionsCursor(SQLiteOpenHelper helper) { SQLiteDatabase db = helper.getReadableDatabase(); String sql = "select distinct topic._id as _id, topic.title as title from topic, topicvideo, video where video.download_status>? and topicvideo.video_id=video.readable_id and topicvideo.topic_id=topic._id group by title"; String[] selectionArgs = {String.valueOf(Video.DL_STATUS_NOT_STARTED)}; Cursor mainCursor = db.rawQuery(sql, selectionArgs); sql = "select '-1' as _id, 'All Videos' as title"; Cursor headerCursor = db.rawQuery(sql, null); MergeCursor cursor = new MergeCursor(new Cursor[] {headerCursor, mainCursor}); return cursor; }
Example #12
Source File: StartActivity.java From EverMemo with MIT License | 5 votes |
@Override public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) { MatrixCursor matrixCursor = new MatrixCursor(new String[] { "_id" }); matrixCursor.addRow(new String[] { "0" }); Cursor c = new MergeCursor(new Cursor[] { matrixCursor, cursor }); mMemosAdapter.swapCursor(c); }
Example #13
Source File: BackBufferParametersView.java From ShaderEditor with MIT License | 5 votes |
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); Context context = getContext(); MatrixCursor matrixCursor = new MatrixCursor(new String[]{ Database.TEXTURES_ID, Database.TEXTURES_NAME, Database.TEXTURES_WIDTH, Database.TEXTURES_HEIGHT, Database.TEXTURES_THUMB }); matrixCursor.addRow(new Object[]{ -1, context.getString(R.string.no_preset), 0, 0, null }); MergeCursor mergeCursor = new MergeCursor(new Cursor[]{ matrixCursor, ShaderEditorApp.db.getTextures() }); adapter = new TextureSpinnerAdapter(context, mergeCursor); presetView = findViewById(R.id.backbuffer_preset); presetView.setAdapter(adapter); }
Example #14
Source File: MultiObjectCursor.java From MonsterHunter4UDatabase with MIT License | 5 votes |
private MultiObjectCursor(IdentifyingCursorWrapper[] cursors) { super(new MergeCursor(cursors)); for (IdentifyingCursorWrapper cursor : cursors) { cursor.setOwner(this); } moveToFirst(); }
Example #15
Source File: PodDBAdapter.java From AntennaPodSP with MIT License | 5 votes |
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); } }
Example #16
Source File: SongLoader.java From VinylMusicPlayer with GNU General Public License v3.0 | 5 votes |
@Nullable public static Cursor makeSongCursorFromPaths(@NonNull final Context context, @NonNull ArrayList<String> paths) { // Exclude blacklist paths.removeAll(BlacklistStore.getInstance(context).getPaths()); int remaining = paths.size(); int processed = 0; ArrayList<Cursor> cursors = new ArrayList<>(); final String sortOrder = PreferenceUtil.getInstance().getSongSortOrder(); while (remaining > 0) { final int currentBatch = Math.min(BATCH_SIZE, remaining); StringBuilder selection = new StringBuilder(); selection.append(BASE_SELECTION + " AND " + MediaStore.Audio.AudioColumns.DATA + " IN (?"); for (int i = 1; i < currentBatch; i++) { selection.append(",?"); } selection.append(")"); try { Cursor cursor = context.getContentResolver().query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, BASE_PROJECTION, selection.toString(), paths.subList(processed, processed + currentBatch).toArray(new String[currentBatch]), sortOrder ); if (cursor != null) {cursors.add(cursor);}; } catch (SecurityException ignored) { } remaining -= currentBatch; processed += currentBatch; } if (cursors.isEmpty()) {return null;} return new MergeCursor(cursors.toArray(new Cursor[cursors.size()])); }
Example #17
Source File: ContactsCursorLoader.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Override public Cursor loadInBackground() { List<Cursor> cursorList = TextUtils.isEmpty(filter) ? getUnfilteredResults() : getFilteredResults(); if (cursorList.size() > 0) { return new MergeCursor(cursorList.toArray(new Cursor[0])); } return null; }
Example #18
Source File: AlbumMediaLoader.java From Matisse with Apache License 2.0 | 5 votes |
@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}); }
Example #19
Source File: FavLoader.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
@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; } }
Example #20
Source File: AlbumMediaLoader.java From AlbumCameraRecorder with MIT License | 5 votes |
@Override public Cursor loadInBackground() { Cursor result = super.loadInBackground(); if (!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}); }
Example #21
Source File: EssMediaLoader.java From AndroidDownload with Apache License 2.0 | 5 votes |
@Override public Cursor loadInBackground() { Cursor result = super.loadInBackground(); if (!mEnableCapture || !MediaStoreCompat.hasCameraFeature(getContext())) { return result; } MatrixCursor dummy = new MatrixCursor(PROJECTION); dummy.addRow(new Object[]{"-1", "capture", "", 0, ""}); return new MergeCursor(new Cursor[]{dummy, result}); }
Example #22
Source File: FavoritesAndContactsLoader.java From call_manage with MIT License | 5 votes |
@Override public Cursor loadInBackground() { List<Cursor> cursors = new ArrayList<>(); int favoritesCount = 0; try { if (mLoadFavorites) { Cursor favoritesCursor = loadFavoritesContacts(); cursors.add(favoritesCursor); favoritesCount = favoritesCursor.getCount(); } } catch (NullPointerException e) { favoritesCount = 0; } final Cursor contactsCursor = loadContacts(); cursors.add(contactsCursor); final int finalFavoritesCount = favoritesCount; return new MergeCursor(cursors.toArray(new Cursor[0])) { @Override public Bundle getExtras() { // Need to get the extras from the contacts cursor. Bundle extras = contactsCursor == null ? new Bundle() : contactsCursor.getExtras(); extras.putInt(FAVORITES_COUNT, finalFavoritesCount); return extras; } }; }
Example #23
Source File: EssMediaLoader.java From FilePicker with MIT License | 5 votes |
@Override public Cursor loadInBackground() { Cursor result = super.loadInBackground(); if (!mEnableCapture || !MediaStoreCompat.hasCameraFeature(getContext())) { return result; } MatrixCursor dummy = new MatrixCursor(PROJECTION); dummy.addRow(new Object[]{"-1", "capture", "", 0, ""}); return new MergeCursor(new Cursor[]{dummy, result}); }
Example #24
Source File: ConversationListLoader.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
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_ID, ThreadDatabase.SNIPPET, ThreadDatabase.READ, ThreadDatabase.UNREAD_COUNT, ThreadDatabase.TYPE, ThreadDatabase.SNIPPET_TYPE, ThreadDatabase.SNIPPET_URI, ThreadDatabase.SNIPPET_CONTENT_TYPE, ThreadDatabase.SNIPPET_EXTRAS, ThreadDatabase.ARCHIVED, ThreadDatabase.STATUS, ThreadDatabase.DELIVERY_RECEIPT_COUNT, ThreadDatabase.EXPIRES_IN, ThreadDatabase.LAST_SEEN, ThreadDatabase.READ_RECEIPT_COUNT}, 1); if (cursorList.get(0).getCount() <= 0) { switchToArchiveCursor.addRow(new Object[] {-1L, System.currentTimeMillis(), archivedCount, "-1", null, 1, 0, ThreadDatabase.DistributionTypes.INBOX_ZERO, 0, null, null, null, 0, -1, 0, 0, 0, -1}); } switchToArchiveCursor.addRow(new Object[] {-1L, System.currentTimeMillis(), archivedCount, "-1", null, 1, 0, ThreadDatabase.DistributionTypes.ARCHIVE, 0, null, null, null, 0, -1, 0, 0, 0, -1}); cursorList.add(switchToArchiveCursor); } return new MergeCursor(cursorList.toArray(new Cursor[0])); }
Example #25
Source File: SongLoader.java From VinylMusicPlayer with GNU General Public License v3.0 | 4 votes |
@Nullable public static Cursor makeSongCursor(@NonNull final Context context, @Nullable String selection, String[] selectionValues, final String sortOrder) { if (selection != null && !selection.trim().equals("")) { selection = BASE_SELECTION + " AND " + selection; } else { selection = BASE_SELECTION; } // Blacklist final ArrayList<String> paths = BlacklistStore.getInstance(context).getPaths(); int remaining = paths.size(); int processed = 0; ArrayList<Cursor> cursors = new ArrayList<>(); while (remaining > 0) { final int currentBatch = Math.min(BATCH_SIZE, remaining); // Enrich the base selection with the current batch parameters String batchSelection = generateBlacklistSelection(selection, currentBatch); ArrayList<String> batchSelectionValues = addBlacklistSelectionValues(selectionValues, paths.subList(processed, processed + currentBatch)); try { Cursor cursor = context.getContentResolver().query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, BASE_PROJECTION, batchSelection, batchSelectionValues.toArray(new String[batchSelectionValues.size()]), sortOrder ); if (cursor != null) { cursors.add(cursor); } } catch (SecurityException ignored) { } remaining -= currentBatch; processed += currentBatch; } if (cursors.isEmpty()) {return null;} return new MergeCursor(cursors.toArray(new Cursor[cursors.size()])); }
Example #26
Source File: ContactAccessor.java From Silence with GNU General Public License v3.0 | 4 votes |
/*** * 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 = { Phone._ID, // 0 Phone.CONTACT_ID, // 1 Phone.TYPE, // 2 Phone.NUMBER, // 3 Phone.LABEL, // 4 Phone.DISPLAY_NAME, // 5 }; 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(); result.add(-1); // ID result.add((long) -1); // CONTACT_ID result.add(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; } }
Example #27
Source File: RingtonePreferenceDialogFragmentCompat.java From Silence with GNU General Public License v3.0 | 4 votes |
@NonNull private Cursor createCursor(Uri ringtoneUri) { RingtonePreference ringtonePreference = getRingtonePreference(); ringtoneManager = new RingtoneManager(getContext()); ringtoneManager.setType(ringtonePreference.getRingtoneType()); ringtoneManager.setStopPreviousRingtone(true); Cursor ringtoneCursor = ringtoneManager.getCursor(); String colId = ringtoneCursor.getColumnName(RingtoneManager.ID_COLUMN_INDEX); String colTitle = ringtoneCursor.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX); MatrixCursor extras = new MatrixCursor(new String[]{colId, colTitle}); final int ringtoneType = ringtonePreference.getRingtoneType(); final boolean showDefault = ringtonePreference.getShowDefault(); final boolean showSilent = ringtonePreference.getShowSilent(); if (showDefault) { switch (ringtoneType) { case RingtoneManager.TYPE_ALARM: extras.addRow(new String[]{CURSOR_DEFAULT_ID, getString(R.string.RingtonePreference_alarm_sound_default)}); break; case RingtoneManager.TYPE_NOTIFICATION: extras.addRow(new String[]{CURSOR_DEFAULT_ID, getString(R.string.RingtonePreference_notification_sound_default)}); break; case RingtoneManager.TYPE_RINGTONE: case RingtoneManager.TYPE_ALL: default: extras.addRow(new String[]{CURSOR_DEFAULT_ID, getString(R.string.RingtonePreference_ringtone_default)}); break; } } if (showSilent) { extras.addRow(new String[]{CURSOR_NONE_ID, getString(R.string.RingtonePreference_ringtone_silent)}); } selectedIndex = ringtoneManager.getRingtonePosition(ringtoneUri); if (selectedIndex >= 0) { selectedIndex += (showDefault ? 1 : 0) + (showSilent ? 1 : 0); } if (selectedIndex < 0 && showDefault) { if (RingtoneManager.getDefaultType(ringtoneUri) != -1) { selectedIndex = 0; } } if (selectedIndex < 0 && showSilent) { selectedIndex = showDefault ? 1 : 0; } Cursor[] cursors = {extras, ringtoneCursor}; return this.cursor = new MergeCursor(cursors); }
Example #28
Source File: ContactAccessor.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
/*** * 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 = { Phone._ID, // 0 Phone.CONTACT_ID, // 1 Phone.TYPE, // 2 Phone.NUMBER, // 3 Phone.LABEL, // 4 Phone.DISPLAY_NAME, // 5 }; 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(); 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; } }