/** * Returns the Id for an artist. * * @param context The {@link Context} to use. * @param name The name of the artist. * @return The ID for an artist. */ public static final long getIdForArtist(final Context context, final String name) { Cursor cursor = context.getContentResolver().query( MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, new String[]{ BaseColumns._ID }, ArtistColumns.ARTIST + "=?", new String[]{ name }, ArtistColumns.ARTIST); int id = -1; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); cursor = null; } return id; }
/** * Create a Search Chooser */ public static void doSearch(Context mContext, Cursor mCursor, String Type) { CharSequence title = null; Intent i = new Intent(); i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); String query = ""; if ( Type == TYPE_ALBUM ){ query = mCursor.getString(mCursor.getColumnIndexOrThrow(AlbumColumns.ALBUM)); } else if( Type == TYPE_ARTIST ){ query = mCursor.getString(mCursor.getColumnIndexOrThrow(ArtistColumns.ARTIST)); } else if( Type == TYPE_GENRE || Type == TYPE_PLAYLIST || Type == TYPE_SONG ){ query = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaColumns.TITLE)); } title = ""; i.putExtra("", query); title = title + " " + query; title = "Search " + title; i.putExtra(SearchManager.QUERY, query); mContext.startActivity(Intent.createChooser(i, title)); }
/** * Returns the Id for an artist. * * @param context The {@link Context} to use. * @param name The name of the artist. * @return The ID for an artist. */ public static long getIdForArtist(final Context context, final String name) { Cursor cursor = context.getContentResolver().query( MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, ArtistColumns.ARTIST + "=?", new String[] { name }, ArtistColumns.ARTIST); int id = -1; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); cursor = null; } return id; }
/** * Returns the Id for an artist. * * @param context The {@link Context} to use. * @param name The name of the artist. * @return The ID for an artist. */ public static final long getIdForArtist(final Context context, final String name) { Cursor cursor = context.getContentResolver().query( MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, ArtistColumns.ARTIST + "=?", new String[] { name }, ArtistColumns.ARTIST); int id = -1; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); cursor = null; } return id; }
/** * @return A custom ContextMenu header */ public static View setHeaderLayout(String Type, Cursor cursor, Activity activity) { LayoutInflater inflater = activity.getLayoutInflater(); View header = inflater.inflate(R.layout.music_context_menu_header, null, false); // Artist image final ImageView mHanderImage = (ImageView)header.findViewById(R.id.header_image); String albumId="",artistName="",albumName=""; if(Type == TYPE_ALBUM){ albumName = cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ALBUM)); artistName = cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ARTIST)); albumId = cursor.getString(cursor.getColumnIndexOrThrow(BaseColumns._ID)); } else{ artistName = cursor.getString(cursor.getColumnIndexOrThrow(ArtistColumns.ARTIST)); } ImageInfo mInfo = new ImageInfo(); mInfo.type = Type; mInfo.size = SIZE_THUMB; mInfo.source = SRC_FIRST_AVAILABLE; mInfo.data = (Type == TYPE_ALBUM ? new String[]{ albumId , artistName, albumName } : new String[]{ artistName}); ImageProvider.getInstance(activity).loadImage( mHanderImage, mInfo ); // Set artist name TextView headerText = (TextView)header.findViewById(R.id.header_text); headerText.setText( (Type == TYPE_ALBUM ? albumName : artistName)); headerText.setBackgroundColor((activity).getResources().getColor(R.color.transparent_black)); return header; }
/** * @return number of albums from Bundle */ public String getNumSongs() { String[] projection = { BaseColumns._ID, ArtistColumns.ARTIST, ArtistColumns.NUMBER_OF_TRACKS }; Uri uri = Audio.Artists.EXTERNAL_CONTENT_URI; Long id = ApolloUtils.getArtistId(getArtist(), ARTIST_ID, this); Cursor cursor = null; try{ cursor = this.getContentResolver().query(uri, projection, BaseColumns._ID+ "=" + DatabaseUtils.sqlEscapeString(String.valueOf(id)), null, null); } catch(Exception e){ e.printStackTrace(); } if(cursor == null) return String.valueOf(0); int mArtistNumAlbumsIndex = cursor.getColumnIndexOrThrow(ArtistColumns.NUMBER_OF_TRACKS); if(cursor.getCount()>0){ cursor.moveToFirst(); String numAlbums = cursor.getString(mArtistNumAlbumsIndex); cursor.close(); if(numAlbums != null){ return numAlbums; } } return String.valueOf(0); }
/** * @return number of albums from Bundle */ public String getNumAlbums() { if (bundle.getString(NUMALBUMS) != null) return bundle.getString(NUMALBUMS); String[] projection = { BaseColumns._ID, ArtistColumns.ARTIST, ArtistColumns.NUMBER_OF_ALBUMS }; Uri uri = Audio.Artists.EXTERNAL_CONTENT_URI; Long id = ApolloUtils.getArtistId(getArtist(), ARTIST_ID, this); Cursor cursor = null; try{ cursor = this.getContentResolver().query(uri, projection, BaseColumns._ID+ "=" + DatabaseUtils.sqlEscapeString(String.valueOf(id)), null, null); } catch(Exception e){ e.printStackTrace(); } if(cursor == null) return String.valueOf(0); int mArtistNumAlbumsIndex = cursor.getColumnIndexOrThrow(ArtistColumns.NUMBER_OF_ALBUMS); if(cursor.getCount()>0){ cursor.moveToFirst(); String numAlbums = cursor.getString(mArtistNumAlbumsIndex); cursor.close(); if(numAlbums != null){ return numAlbums; } } return String.valueOf(0); }
public void setupFragmentData(){ mAdapter = new ArtistAdapter(getActivity(), R.layout.music_gridview_items, null, new String[] {}, new int[] {}, 0); mProjection = new String []{ BaseColumns._ID, ArtistColumns.ARTIST, ArtistColumns.NUMBER_OF_ALBUMS }; mUri = Audio.Artists.EXTERNAL_CONTENT_URI; mSortOrder = Audio.Artists.DEFAULT_SORT_ORDER; mFragmentGroupId = 1; mType = TYPE_ARTIST; }
public void setupViewData(Cursor mCursor){ mLineOneText = mCursor.getString(mCursor.getColumnIndexOrThrow(ArtistColumns.ARTIST)); int albums_plural = mCursor.getInt(mCursor.getColumnIndexOrThrow(ArtistColumns.NUMBER_OF_ALBUMS)); boolean unknown = mLineOneText == null || mLineOneText.equals(MediaStore.UNKNOWN_STRING); mLineTwoText = MusicUtils.makeAlbumsLabel(mContext, albums_plural, 0, unknown); mGridType = TYPE_ARTIST; mImageData = new String[]{mLineOneText}; mPlayingId = MusicUtils.getCurrentArtistId(); mCurrentId = mCursor.getLong(mCursor.getColumnIndexOrThrow(BaseColumns._ID)); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { super.onItemClick(parent, view, position, id); albumsView.query(Albums.EXTERNAL_CONTENT_URI, ArtistColumns.ARTIST_KEY + " = '" + getLastSelectedName() + "'"); getFlipper().setInAnimation(getContext(), R.anim.slide_in_left); getFlipper().setOutAnimation(getContext(), R.anim.slide_out_left); getFlipper().showNext(); }
/** * @return A custom ContextMenu header */ public static View setHeaderLayout(String Type, Cursor cursor, Activity activity) { LayoutInflater inflater = activity.getLayoutInflater(); View header = inflater.inflate(R.layout.context_menu_header, null, false); // Artist image final ImageView mHanderImage = (ImageView)header.findViewById(R.id.header_image); String albumId="",artistName="",albumName=""; if(Type == TYPE_ALBUM){ albumName = cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ALBUM)); artistName = cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ARTIST)); albumId = cursor.getString(cursor.getColumnIndexOrThrow(BaseColumns._ID)); } else{ artistName = cursor.getString(cursor.getColumnIndexOrThrow(ArtistColumns.ARTIST)); } ImageInfo mInfo = new ImageInfo(); mInfo.type = Type; mInfo.size = SIZE_THUMB; mInfo.source = SRC_FIRST_AVAILABLE; mInfo.data = (Type == TYPE_ALBUM ? new String[]{ albumId , artistName, albumName } : new String[]{ artistName}); ImageProvider.getInstance(activity).loadImage( mHanderImage, mInfo ); // Set artist name TextView headerText = (TextView)header.findViewById(R.id.header_text); headerText.setText( (Type == TYPE_ALBUM ? albumName : artistName)); headerText.setBackgroundColor((activity).getResources().getColor(R.color.transparent_black)); return header; }
public static String getArtistName(Context mContext, long artist_id, boolean default_name) { String where = BaseColumns._ID + "=" + artist_id; String[] cols = new String[] { ArtistColumns.ARTIST }; Uri uri = Audio.Artists.EXTERNAL_CONTENT_URI; Cursor cursor = mContext.getContentResolver().query(uri, cols, where, null, null); if (cursor == null){ return MediaStore.UNKNOWN_STRING; } if (cursor.getCount() <= 0) { if (default_name) return mContext.getString(R.string.unknown); else return MediaStore.UNKNOWN_STRING; } else { cursor.moveToFirst(); String name = cursor.getString(0); cursor.close(); if (name == null || MediaStore.UNKNOWN_STRING.equals(name)) { if (default_name) return mContext.getString(R.string.unknown); else return MediaStore.UNKNOWN_STRING; } return name; } }
public void setupFragmentData(){ mAdapter = new ArtistAdapter(getActivity(), R.layout.gridview_items, null, new String[] {}, new int[] {}, 0); mProjection = new String []{ BaseColumns._ID, ArtistColumns.ARTIST, ArtistColumns.NUMBER_OF_ALBUMS }; mUri = Audio.Artists.EXTERNAL_CONTENT_URI; mSortOrder = Audio.Artists.DEFAULT_SORT_ORDER; mFragmentGroupId = 1; mType = TYPE_ARTIST; }
/** * @return number of albums from Bundle */ public String getNumAlbums() { if (bundle.getString(NUMALBUMS) != null) return bundle.getString(NUMALBUMS); String[] projection = { BaseColumns._ID, ArtistColumns.ARTIST, ArtistColumns.NUMBER_OF_ALBUMS }; Uri uri = Audio.Artists.EXTERNAL_CONTENT_URI; Long id = ApolloUtils.getArtistId(getArtist(), ARTIST_ID, this); Cursor cursor = null; try{ cursor = this.getContentResolver().query(uri, projection, BaseColumns._ID+ "=" + DatabaseUtils.sqlEscapeString(String.valueOf(id)), null, null); } catch(Exception e){ e.printStackTrace(); } if(cursor == null) return String.valueOf(0); int mArtistNumAlbumsIndex = cursor.getColumnIndexOrThrow(ArtistColumns.NUMBER_OF_ALBUMS); if(cursor.getCount()>0){ cursor.moveToFirst(); String numAlbums = cursor.getString(mArtistNumAlbumsIndex); if(numAlbums != null){ return numAlbums; } } return String.valueOf(0); }
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { String[] projection = { BaseColumns._ID, ArtistColumns.ARTIST, ArtistColumns.NUMBER_OF_ALBUMS }; Uri uri = Audio.Artists.EXTERNAL_CONTENT_URI; String sortOrder = Audio.Artists.DEFAULT_SORT_ORDER; return new CursorLoader(getActivity(), uri, projection, null, null, sortOrder); }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Check for database errors if (data == null) { return; } mArtistIdIndex = data.getColumnIndexOrThrow(BaseColumns._ID); mArtistNameIndex = data.getColumnIndexOrThrow(ArtistColumns.ARTIST); mArtistNumAlbumsIndex = data.getColumnIndexOrThrow(ArtistColumns.NUMBER_OF_ALBUMS); mArtistAdapter.changeCursor(data); mCursor = data; }
/** * Creates the {@link Cursor} used to run the query. * * @param context The {@link Context} to use. * @return The {@link Cursor} used to run the artist query. */ public static final Cursor makeArtistCursor(final Context context) { return context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, new String[] { /* 0 */ BaseColumns._ID, /* 1 */ ArtistColumns.ARTIST, /* 2 */ ArtistColumns.NUMBER_OF_ALBUMS, /* 3 */ ArtistColumns.NUMBER_OF_TRACKS }, null, null, PreferenceUtils.getInstace(context).getArtistSortOrder()); }
public void query(Uri contentUri, String selection) { super.query(contentUri, ArtistColumns.ARTIST_KEY, selection, R.layout.media_picker_row, artistsColumns, artistsResIDs); }