Example usage for android.database MergeCursor MergeCursor

List of usage examples for android.database MergeCursor MergeCursor

Introduction

In this page you can find the example usage for android.database MergeCursor MergeCursor.

Prototype

public MergeCursor(Cursor[] cursors) 

Source Link

Usage

From source file:com.laevatein.internal.loader.AlbumLoader.java

@Override
public Cursor loadInBackground() {
    Cursor albums = super.loadInBackground();
    MatrixCursor allAlbum = new MatrixCursor(PROJECTION);
    allAlbum.addRow(new String[] { Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, MEDIA_ID_DUMMY });

    return new MergeCursor(new Cursor[] { allAlbum, albums });
}

From source file:com.tingtingapps.securesms.contacts.ContactsCursorLoader.java

@Override
public Cursor loadInBackground() {
    ContactsDatabase contactsDatabase = DatabaseFactory.getContactsDatabase(getContext());
    ArrayList<Cursor> cursorList = new ArrayList<>(3);

    cursorList.add(contactsDatabase.queryTextSecureContacts(filter));

    if (includeSmsContacts) {
        cursorList.add(contactsDatabase.querySystemContacts(filter));
    }/*from   w ww.j  a v  a 2  s .c o  m*/

    if (!TextUtils.isEmpty(filter) && NumberUtil.isValidSmsOrEmail(filter)) {
        cursorList.add(contactsDatabase.getNewNumberCursor(filter));
    }

    return new MergeCursor(cursorList.toArray(new Cursor[0]));
}

From source file:org.smssecure.smssecure.contacts.ContactsCursorLoader.java

@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));
    }//w  w  w  .jav a2s.c  o m

    if (!TextUtils.isEmpty(filter) && NumberUtil.isValidSmsOrEmail(filter)) {
        cursorList.add(contactsDatabase.getNewNumberCursor(filter));
    }

    return new MergeCursor(cursorList.toArray(new Cursor[0]));
}

From source file:com.abcvoipsip.ui.favorites.FavLoader.java

@Override
public Cursor loadInBackground() {
    // First of all, get all active accounts
    ArrayList<SipProfile> accounts = SipProfile.getAllProfiles(getContext(), true);

    Cursor[] cursorsToMerge = new Cursor[2 * accounts.size()];
    int i = 0;/*  w w  w.  j a v a  2  s . c  o m*/
    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;
    }
}

From source file:com.csipsimple.ui.favorites.FavLoader.java

@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;//from w  w w . ja v  a  2 s.c  o  m
    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;
    }
}

From source file:com.laevatein.internal.loader.AlbumPhotoLoader.java

@Override
public Cursor loadInBackground() {
    Cursor result = super.loadInBackground();
    if (!mEnableCapture || !MediaStoreCompat.hasCameraFeature(getContext())) {
        return result;
    }//  w  w  w  . ja v  a2 s .  co m
    MatrixCursor dummy = new MatrixCursor(PROJECTION);
    dummy.addRow(new Object[] { Item.ITEM_ID_CAPTURE, Item.ITEM_DISPLAY_NAME_CAPTURE });
    return new MergeCursor(new Cursor[] { dummy, result });
}

From source file:io.valuesfeng.picker.loader.AlbumLoader.java

@Override
public Cursor loadInBackground() {
    Cursor albums = super.loadInBackground();
    MatrixCursor allAlbum = new MatrixCursor(PROJECTION);

    long count = 0;
    if (albums.getCount() > 0) {
        while (albums.moveToNext()) {
            count += albums.getLong(3);//www . j  a v  a 2s . c  o m
        }
    }
    allAlbum.addRow(new String[] { Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, MEDIA_ID_DUMMY, count + "" });

    return new MergeCursor(new Cursor[] { allAlbum, albums });
}

From source file:io.valuesfeng.picker.loader.PictureLoader.java

@Override
public Cursor loadInBackground() {
    Cursor result = super.loadInBackground();
    if (!mEnableCapture || !MediaStoreCompat.hasCameraFeature(getContext())) {
        return result;
    }/*ww  w  .j a v  a2 s . c o  m*/
    MatrixCursor dummy = new MatrixCursor(PROJECTION);
    dummy.addRow(new Object[] { Picture.ITEM_ID_CAPTURE, Picture.ITEM_DISPLAY_NAME_CAPTURE });
    return new MergeCursor(new Cursor[] { dummy, result });
}

From source file:com.securecomcode.voice.contacts.ContactsCursorLoader.java

private Cursor queryAndroidDb(String filter) {
    Uri baseUri;// w w  w.  j a v  a  2 s  . c o m
    Cursor cursor;
    List<Cursor> cursors = new ArrayList<Cursor>();

    if (filter != null) {
        baseUri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI,
                Uri.encode(filter));

        cursor = context.getContentResolver().query(baseUri, null, null, null, CONTACT_LIST_SORT);
        cursors.add(cursor);
        baseUri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Email.CONTENT_FILTER_URI,
                Uri.encode(filter));
        cursor = context.getContentResolver().query(baseUri, null, null, null, CONTACT_LIST_SORT);
        cursors.add(cursor);
        return new MergeCursor(cursors.toArray(new Cursor[] {}));

    } else {
        baseUri = ContactsContract.Data.CONTENT_URI;

        cursor = context.getContentResolver().query(baseUri, null,
                ContactsContract.Data.IN_VISIBLE_GROUP + "!=0 AND (" + ContactsContract.Data.MIMETYPE + "=? OR "
                        + ContactsContract.Data.MIMETYPE + "=?)",
                new String[] { ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,
                        ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE },
                CONTACT_LIST_SORT);
        return cursor;
    }

}

From source file:com.aniruddhc.acemusic.player.Dialogs.AddToPlaylistDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    mContext = getActivity().getApplicationContext();

    //Retrieve the arguments.
    ADD_TYPE = getArguments().getString("ADD_TYPE");

    if (ADD_TYPE.equals("ARTIST")) {
        ARTIST = getArguments().getString("ARTIST");
    } else if (ADD_TYPE.equals("ALBUM_ARTIST")) {
        ALBUM_ARTIST = getArguments().getString("ALBUM_ARTIST");
    } else if (ADD_TYPE.equals("ALBUM")) {
        ARTIST = getArguments().getString("ARTIST");
        ALBUM = getArguments().getString("ALBUM");
    } else if (ADD_TYPE.equals("SONG")) {
        ARTIST = getArguments().getString("ARTIST");
        ALBUM = getArguments().getString("ALBUM");
        SONG = getArguments().getString("SONG");
    } else if (ADD_TYPE.equals("GENRE")) {
        GENRE = getArguments().getString("GENRE");
    } else if (ADD_TYPE.equals("ALBUM_BY_ALBUM_ARTIST")) {
        ALBUM = getArguments().getString("ALBUM");
        ALBUM_ARTIST = getArguments().getString("ALBUM_ARTIST");
    }/* w  w w . ja v  a 2 s .  c  o m*/

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    String columns[] = { DBAccessHelper.PLAYLIST_NAME, DBAccessHelper._ID, DBAccessHelper.PLAYLIST_FILE_PATH,
            DBAccessHelper.PLAYLIST_SOURCE, DBAccessHelper.PLAYLIST_ID };
    MatrixCursor matrixCursor = new MatrixCursor(columns);
    matrixCursor.addRow(
            new String[] { getActivity().getResources().getString(R.string.new_playlist), "0", "0", "0", "0" });

    DBAccessHelper playlistsDBHelper = new DBAccessHelper(getActivity().getApplicationContext());
    Cursor userPlaylistsCursor = playlistsDBHelper.getAllSongsInAlbum(null, null);
    final MergeCursor mergeCursor = new MergeCursor(new Cursor[] { matrixCursor, userPlaylistsCursor });

    //Set the dialog title.
    builder.setTitle(R.string.add_to_playlist);
    builder.setCursor(mergeCursor, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Index 0 is the dummy playlist that will open the "New Playlist" dialog.
            if (which == 0) {
                showNewPlaylistDialog();
            } else {
                mergeCursor.moveToPosition(which);
                String playlistName = mergeCursor
                        .getString(mergeCursor.getColumnIndex(DBAccessHelper.PLAYLIST_NAME));
                String playlistId = mergeCursor
                        .getString(mergeCursor.getColumnIndex(DBAccessHelper.PLAYLIST_ID));

                AsyncAddSongsToPlaylistTask task = new AsyncAddSongsToPlaylistTask(mContext, playlistName,
                        playlistId, ARTIST, ALBUM, SONG, GENRE, ALBUM_ARTIST, ADD_TYPE);
                task.execute();

            }

        }

    }, DBAccessHelper.PLAYLIST_NAME);

    return builder.create();
}