android.provider.MediaStore.Audio.Genres Java Examples

The following examples show how to use android.provider.MediaStore.Audio.Genres. 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: GenreLoader.java    From Music-Player with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private static List<Genre> getGenresFromCursor(@NonNull final Context context, @Nullable final Cursor cursor) {
    final List<Genre> genres = new ArrayList<>();
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                Genre genre = getGenreFromCursor(context, cursor);
                if (genre.songCount > 0) {
                    genres.add(genre);
                } else {
                    // try to remove the empty genre from the media store
                    try {
                        context.getContentResolver().delete(Genres.EXTERNAL_CONTENT_URI, Genres._ID + " == " + genre.id, null);
                    } catch (Exception e) {
                        e.printStackTrace();
                        // nothing we can do then
                    }
                }
            } while (cursor.moveToNext());
        }
        cursor.close();
    }
    return genres;
}
 
Example #2
Source File: GenreLoader.java    From MusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private static ArrayList<Genre> getGenresFromCursor(@NonNull final Context context, @Nullable final Cursor cursor) {
    final ArrayList<Genre> genres = new ArrayList<>();
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                Genre genre = getGenreFromCursor(context, cursor);
                if (genre.songCount > 0) {
                    genres.add(genre);
                } else {
                    // try to remove the empty genre from the media store
                    try {
                        context.getContentResolver().delete(Genres.EXTERNAL_CONTENT_URI, Genres._ID + " == " + genre.id, null);
                    } catch (Exception e) {
                        e.printStackTrace();
                        // nothing we can do then
                    }
                }
            } while (cursor.moveToNext());
        }
        cursor.close();
    }
    return genres;
}
 
Example #3
Source File: GenreLoader.java    From VinylMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private static ArrayList<Genre> getGenresFromCursor(@NonNull final Context context, @Nullable final Cursor cursor) {
    final ArrayList<Genre> genres = new ArrayList<>();
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                Genre genre = getGenreFromCursor(context, cursor);
                if (genre.songCount > 0) {
                    genres.add(genre);
                } else {
                    // try to remove the empty genre from the media store
                    try {
                        context.getContentResolver().delete(Genres.EXTERNAL_CONTENT_URI, Genres._ID + " == " + genre.id, null);
                    } catch (Exception e) {
                        e.printStackTrace();
                        // nothing we can do then
                    }
                }
            } while (cursor.moveToNext());
        }
        cursor.close();
    }
    return genres;
}
 
Example #4
Source File: GenreListFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
public void setupFragmentData(){
    mAdapter = new GenreListAdapter(getActivity(), R.layout.music_listview_items, null,
            								new String[] {}, new int[] {}, 0);
	mProjection = new String[] {
            BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM,
            AudioColumns.ARTIST
    };
    StringBuilder where = new StringBuilder();
    where.append(AudioColumns.IS_MUSIC + "=1").append(
            				" AND " + MediaColumns.TITLE + " != ''");
    mWhere = where.toString();        
    mSortOrder = Genres.Members.DEFAULT_SORT_ORDER;
    mUri = Genres.Members.getContentUri(EXTERNAL, getArguments().getLong(BaseColumns._ID));
    mFragmentGroupId = 3;
    mType = TYPE_GENRE;
    mTitleColumn = MediaColumns.TITLE; 
}
 
Example #5
Source File: GenreLoader.java    From Phonograph with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private static List<Genre> getGenresFromCursor(@NonNull final Context context, @Nullable final Cursor cursor) {
    final List<Genre> genres = new ArrayList<>();
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                Genre genre = getGenreFromCursor(context, cursor);
                if (genre.songCount > 0) {
                    genres.add(genre);
                } else {
                    // try to remove the empty genre from the media store
                    try {
                        context.getContentResolver().delete(Genres.EXTERNAL_CONTENT_URI, Genres._ID + " == " + genre.id, null);
                    } catch (Exception e) {
                        e.printStackTrace();
                        // nothing we can do then
                    }
                }
            } while (cursor.moveToNext());
        }
        cursor.close();
    }
    return genres;
}
 
Example #6
Source File: GenreLoader.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static Cursor makeGenreSongCursor(@NonNull final Context context, int genreId) {
    try {
        return context.getContentResolver().query(
                Genres.Members.getContentUri("external", genreId),
                SongLoader.BASE_PROJECTION, SongLoader.BASE_SELECTION, null, PreferenceUtil.getInstance(context).getSongSortOrder());
    } catch (SecurityException e) {
        return null;
    }
}
 
Example #7
Source File: GenreLoader.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static Cursor makeGenreCursor(@NonNull final Context context) {
    final String[] projection = new String[]{
            Genres._ID,
            Genres.NAME
    };

    try {
        return context.getContentResolver().query(
                Genres.EXTERNAL_CONTENT_URI,
                projection, null, null, PreferenceUtil.getInstance(context).getGenreSortOrder());
    } catch (SecurityException e) {
        return null;
    }
}
 
Example #8
Source File: GenreLoader.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static Cursor makeGenreSongCursor(@NonNull final Context context, int genreId) {
    try {
        return context.getContentResolver().query(
                Genres.Members.getContentUri("external", genreId),
                SongLoader.BASE_PROJECTION, SongLoader.BASE_SELECTION, null, PreferenceUtil.getInstance(context).getSongSortOrder());
    } catch (SecurityException e) {
        return null;
    }
}
 
Example #9
Source File: GenreLoader.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static Cursor makeGenreCursor(@NonNull final Context context) {
    final String[] projection = new String[]{
            Genres._ID,
            Genres.NAME
    };

    try {
        return context.getContentResolver().query(
                Genres.EXTERNAL_CONTENT_URI,
                projection, null, null, PreferenceUtil.getInstance(context).getGenreSortOrder());
    } catch (SecurityException e) {
        return null;
    }
}
 
Example #10
Source File: GenreLoader.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static Cursor getGenreCursorForArtist(final  Context context, long artistId) {
    String query = " _id in (select genre_id from audio_genres_map where audio_id in (select _id from audio_meta where "+SongLoader.BASE_SELECTION+" AND artist_id = "+artistId+"))" ;
    final String[] projection = new String[]{
            Genres._ID,
            Genres.NAME
    };
    try {
        return context.getContentResolver().query(
                Genres.EXTERNAL_CONTENT_URI,
                projection, query, null, SortOrder.GenreSortOrder.GENRE_A_Z/*PreferenceUtil.getInstance(context).getGenreSortOrder()*/);
    } catch (SecurityException e) {
        return null;
    }
}
 
Example #11
Source File: GenreLoader.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static Cursor makeGenreSongCursor(@NonNull final Context context, int genreId) {
    try {
        return context.getContentResolver().query(
                Genres.Members.getContentUri("external", genreId),
                SongLoader.BASE_PROJECTION, SongLoader.BASE_SELECTION, null, PreferenceUtil.getInstance().getSongSortOrder());
    } catch (SecurityException e) {
        return null;
    }
}
 
Example #12
Source File: GenreLoader.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static Cursor makeGenreCursor(@NonNull final Context context) {
    final String[] projection = new String[]{
            Genres._ID,
            Genres.NAME
    };

    try {
        return context.getContentResolver().query(
                Genres.EXTERNAL_CONTENT_URI,
                projection, null, null, PreferenceUtil.getInstance().getGenreSortOrder());
    } catch (SecurityException e) {
        return null;
    }
}
 
Example #13
Source File: TracksBrowser.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
/**
 * Initiate ViewPager and PagerAdapter
 */
private void initPager() {
    // Initiate PagerAdapter
    PagerAdapter mPagerAdapter = new PagerAdapter(getSupportFragmentManager());
    if (ApolloUtils.isArtist(mimeType))
        // Show all albums for an artist
        mPagerAdapter.addFragment(new ArtistAlbumsFragment(bundle));
    // Show the tracks for an artist or album
    if(Playlists.CONTENT_TYPE.equals(mimeType)){
        mPagerAdapter.addFragment(new PlaylistListFragment(bundle));
    }
    else if(Genres.CONTENT_TYPE.equals(mimeType)){
    	mPagerAdapter.addFragment(new GenreListFragment(bundle));
    }
    else if(ApolloUtils.isArtist(mimeType)){
    	mPagerAdapter.addFragment(new ArtistListFragment(bundle));
    }
    else if(Audio.Albums.CONTENT_TYPE.equals(mimeType)){
    	mPagerAdapter.addFragment(new AlbumListFragment(bundle));
    }

    // Set up ViewPager
    mViewPager = (ViewPager)findViewById(R.id.viewPager);
    mViewPager.setPageMargin(getResources().getInteger(R.integer.viewpager_margin_width));
    mViewPager.setPageMarginDrawable(R.drawable.music_viewpager_margin);
    mViewPager.setOffscreenPageLimit(mPagerAdapter.getCount());
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setOnPageChangeListener(new PageListener());
}
 
Example #14
Source File: TracksBrowser.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
/**
 * Set the correct title
 */
private void setTitle() {
    String name;
    long id;
    if (Playlists.CONTENT_TYPE.equals(mimeType)) {
        id = bundle.getLong(BaseColumns._ID);
        switch ((int)id) {
            case (int)PLAYLIST_QUEUE:
                setTitle(R.string.nowplaying);
                return;
            case (int)PLAYLIST_FAVORITES:
                setTitle(R.string.favorite);
                return;
            default:
                if (id < 0) {
                    setTitle(R.string.app_name);
                    return;
                }
        }
        name = MusicUtils.getPlaylistName(this, id);
    } else if (Audio.Artists.CONTENT_TYPE.equals(mimeType)) {
        id = bundle.getLong(BaseColumns._ID);
        name =  getString (R.string.artist_page_title)+MusicUtils.getArtistName(this, id, true);
    } else if (Audio.Albums.CONTENT_TYPE.equals(mimeType)) {
        id = bundle.getLong(BaseColumns._ID);
        name =  getString (R.string.album_page_title)+MusicUtils.getAlbumName(this, id, true);
    } else if (Genres.CONTENT_TYPE.equals(mimeType)) {
        id = bundle.getLong(BaseColumns._ID);
        name = MusicUtils.parseGenreName(this, MusicUtils.getGenreName(this, id, true));
    } else {
        setTitle(R.string.app_name);
        return;
    }
    setTitle(name);
}
 
Example #15
Source File: GenreLoader.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static Cursor makeGenreSongCursor(@NonNull final Context context, int genreId) {
    try {
        return context.getContentResolver().query(
                Genres.Members.getContentUri("external", genreId),
                SongLoader.BASE_PROJECTION, SongLoader.BASE_SELECTION, null, PreferenceUtil.getInstance(context).getSongSortOrder());
    } catch (SecurityException e) {
        return null;
    }
}
 
Example #16
Source File: GenreLoader.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static Cursor makeGenreCursor(@NonNull final Context context) {
    final String[] projection = new String[]{
            Genres._ID,
            Genres.NAME
    };

    try {
        return context.getContentResolver().query(
                Genres.EXTERNAL_CONTENT_URI,
                projection, null, null, PreferenceUtil.getInstance(context).getGenreSortOrder());
    } catch (SecurityException e) {
        return null;
    }
}