List of usage examples for android.support.v4.content CursorLoader loadInBackground
@Override
public Cursor loadInBackground()
From source file:com.arcusapp.soundbox.data.MediaProvider.java
/** * Returns the name ({@linkplain MediaStore.Audio.Artists.ARTIST}) of all the Artists in the MediaStore. * /*from w w w .ja v a2s.c om*/ * @return list with the names */ public List<String> getAllArtists() { List<String> artists = new ArrayList<String>(); String[] projection = { "DISTINCT " + MediaStore.Audio.Artists.ARTIST }; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND " + MediaStore.Audio.Artists.ARTIST + " not null "; String sortOrder = MediaStore.Audio.Artists.ARTIST; CursorLoader cl = new CursorLoader(SoundBoxApplication.getContext(), defaultDirectoryUri, projection, selection, null, sortOrder); myCursor = cl.loadInBackground(); while (myCursor.moveToNext()) { artists.add(myCursor.getString(0)); } myCursor.close(); return artists; }
From source file:com.example.user.lstapp.CreatePlaceFragment.java
private String getRealPathFromURI(Context mContext, Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; CursorLoader loader = new CursorLoader(mContext, contentUri, proj, null, null, null); Cursor cursor = loader.loadInBackground(); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();/*from w w w .j av a 2 s. c o m*/ return cursor.getString(column_index); }
From source file:com.arcusapp.soundbox.data.MediaProvider.java
/** * Returns the id of all the Songs in the MediaStore. * //from w ww . j a v a2 s.c o m * @return list with the ids */ public List<String> getAllSongs() { List<String> songs = new ArrayList<String>(); String[] cursorProjection = new String[] { MediaStore.Audio.Media._ID }; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 "; String sortOrder = MediaStore.Audio.Media.TITLE; CursorLoader cl = new CursorLoader(SoundBoxApplication.getContext(), defaultDirectoryUri, cursorProjection, selection, null, sortOrder); myCursor = cl.loadInBackground(); while (myCursor.moveToNext()) { songs.add(myCursor.getString(0)); } myCursor.close(); return songs; }
From source file:liqui.droid.activity.ContactListCached.java
@Override public Cursor runQuery(CharSequence constraint) { CursorLoader cursorLoader = new CursorLoader(this, CONTENT_URI, null, "name NOTNULL AND name LIKE ?", new String[] { "%" + constraint.toString() + "%" }, mSortOrder + " " + mSortDir); return cursorLoader.loadInBackground(); }
From source file:com.arcusapp.soundbox.data.MediaProvider.java
/** * Returns a list of SongEntries for the specified Songs. * //from www. j a v a2s.c om * @param songsID list of ids ({@linkplain MediaStore.Audio.Media._ID}) * @param projection one key from {@linkplain MediaStore.Audio.Media} to associate on the SongEntry's value * @return a list of SongEntries */ public List<SongEntry> getValueFromSongs(List<String> songsID, String projection) { List<SongEntry> songs = new ArrayList<SongEntry>(); String[] ids = new String[songsID.size()]; ids = songsID.toArray(ids); String[] cursorProjection = new String[] { MediaStore.Audio.Media._ID, projection, MediaStore.Audio.Media.DATA }; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND " + MediaStore.Audio.Media._ID + " IN ("; for (int i = 0; i < songsID.size() - 1; i++) { selection += "?, "; } selection += "?)"; CursorLoader cl = new CursorLoader(SoundBoxApplication.getContext(), defaultDirectoryUri, cursorProjection, selection, ids, null); myCursor = cl.loadInBackground(); while (myCursor.moveToNext()) { songs.add(new SongEntry(myCursor.getString(0), myCursor.getString(1))); } Collections.sort(songs); myCursor.close(); return songs; }
From source file:com.arcusapp.soundbox.data.MediaProvider.java
/** * Returns the name ({@linkplain MediaStore.Audio.Albums.ALBUM}) of all the Albums of the specified Artist in the MediaStore. * //from w ww.j av a 2 s . co m * @param artist the name of the Artist ({@linkplain MediaStore.Audio.Artists.ARTIST}) * @return list with the names */ public List<String> getAlbumsFromArtist(String artist) { List<String> albums = new ArrayList<String>(); String[] projection = { "DISTINCT " + MediaStore.Audio.Artists.Albums.ALBUM }; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND " + MediaStore.Audio.Artists.ARTIST + " = ?"; String sortOrder = MediaStore.Audio.Artists.Albums.ALBUM; String[] selectionArgs = new String[] { artist }; CursorLoader cl = new CursorLoader(SoundBoxApplication.getContext(), defaultDirectoryUri, projection, selection, selectionArgs, sortOrder); myCursor = cl.loadInBackground(); while (myCursor.moveToNext()) { albums.add(myCursor.getString(0)); } myCursor.close(); return albums; }
From source file:com.arcusapp.soundbox.data.MediaProvider.java
/** * Returns the id ({@linkplain MediaStore.Audio.Media._ID}) of all the Songs of the specified Artist in the MediaStore. * //from ww w. j a va2 s .com * @param artist the name of the Artist ({@linkplain MediaStore.Audio.Artists.ARTIST}) * @return list with the ids */ public List<String> getSongsFromArtist(String artist) { List<String> ids = new ArrayList<String>(); String[] projection = { MediaStore.Audio.Media._ID }; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND " + MediaStore.Audio.Artists.ARTIST + " = ?"; String sortOrder = MediaStore.Audio.Media.TITLE; String[] selectionArgs = new String[] { artist }; CursorLoader cl = new CursorLoader(SoundBoxApplication.getContext(), defaultDirectoryUri, projection, selection, selectionArgs, sortOrder); myCursor = cl.loadInBackground(); while (myCursor.moveToNext()) { ids.add(myCursor.getString(0)); } myCursor.close(); return ids; }
From source file:com.arcusapp.soundbox.data.MediaProvider.java
/** * Returns the id ({@linkplain MediaStore.Audio.Media._ID}) of all the Songs of the specified Album in the MediaStore. * /*from w ww .j av a2 s . co m*/ * @param album the name of the Album ({@linkplain MediaStore.Audio.Albums.ALBUM}) * @return list with the ids */ public List<String> getSongsFromAlbum(String album) { List<String> ids = new ArrayList<String>(); String[] projection = { MediaStore.Audio.Media._ID }; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND " + MediaStore.Audio.Artists.Albums.ALBUM + " = ?"; String sortOrder = MediaStore.Audio.Media.TITLE; String[] selectionArgs = new String[] { album }; CursorLoader cl = new CursorLoader(SoundBoxApplication.getContext(), defaultDirectoryUri, projection, selection, selectionArgs, sortOrder); myCursor = cl.loadInBackground(); while (myCursor.moveToNext()) { ids.add(myCursor.getString(0)); } myCursor.close(); return ids; }
From source file:com.arcusapp.soundbox.data.MediaProvider.java
public Song getSongFromID(String songID) { Song song;/*from w w w. j a v a 2 s . co m*/ List<String> values = new ArrayList<String>(); String[] projection = { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.DATA }; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND " + MediaStore.Audio.Media._ID + " = ?"; String[] selectionArgs = new String[] { songID }; CursorLoader cl = new CursorLoader(SoundBoxApplication.getContext(), defaultDirectoryUri, projection, selection, selectionArgs, null); myCursor = cl.loadInBackground(); try { myCursor.moveToNext(); for (int i = 0; i < myCursor.getColumnCount(); i++) values.add(myCursor.getString(i)); if (values.size() > 0) { song = new Song(values.get(0), values.get(1), values.get(2), values.get(3), values.get(4)); } else { song = new Song(); } } catch (Exception ignored) { song = new Song(); } myCursor.close(); return song; }
From source file:com.arcusapp.soundbox.data.MediaProvider.java
/** * Returns a list of PlaylistEntries for all the Playlists in the MediaStore. * //from w w w .j ava2 s . co m * @return a list of PlaylistEntries. The value associated is the name of the Playlist ({@linkplain MediaStore.Audio.Playlists.NAME}) */ public List<PlaylistEntry> getAllPlayLists() { List<PlaylistEntry> playLists = new ArrayList<PlaylistEntry>(); String[] projection = new String[] { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME }; CursorLoader cl = new CursorLoader(SoundBoxApplication.getContext(), MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, null, null, null); myCursor = cl.loadInBackground(); while (myCursor.moveToNext()) { playLists.add(new PlaylistEntry(myCursor.getString(0), myCursor.getString(1))); } Collections.sort(playLists); myCursor.close(); return playLists; }