List of usage examples for android.graphics Paint SUBPIXEL_TEXT_FLAG
int SUBPIXEL_TEXT_FLAG
To view the source code for android.graphics Paint SUBPIXEL_TEXT_FLAG.
Click Source Link
From source file:com.benlinskey.greekreference.GreekTextView.java
/** * Class constructor.//from w w w. ja v a 2 s . c om * * @param context * @param attrs */ @SuppressWarnings("JavaDoc") public GreekTextView(Context context, AttributeSet attrs) { super(context, attrs); if (!isInEditMode() && !TextUtils.isEmpty(TYPEFACE_NAME)) { Typeface typeface = sTypefaceCache.get(TYPEFACE_NAME); if (typeface == null) { typeface = Typeface.createFromAsset(context.getAssets(), "fonts/" + TYPEFACE_NAME); // Cache the Typeface object sTypefaceCache.put(TYPEFACE_NAME, typeface); } setTypeface(typeface); int textColor = getResources() .getColor(android.support.v7.appcompat.R.color.primary_text_default_material_light); setTextColor(textColor); // Note: This flag is required for proper typeface rendering setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); } }
From source file:com.aniruddhc.acemusic.player.MusicLibraryEditorActivity.MusicLibraryEditorAlbumsMultiselectAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final Cursor c = (Cursor) getItem(position); SongsListViewHolder holder = null;/*from w w w .j av a 2 s. c o m*/ if (convertView == null) { convertView = LayoutInflater.from(mContext).inflate(R.layout.music_library_editor_albums_layout, parent, false); holder = new SongsListViewHolder(); holder.image = (ImageView) convertView.findViewById(R.id.albumThumbnailMusicLibraryEditor); holder.title = (TextView) convertView.findViewById(R.id.albumNameMusicLibraryEditor); holder.checkBox = (CheckBox) convertView.findViewById(R.id.albumCheckboxMusicLibraryEditor); holder.subText = (TextView) convertView.findViewById(R.id.albumArtistNameMusicLibraryEditor); convertView.setTag(holder); } else { holder = (SongsListViewHolder) convertView.getTag(); } final View finalConvertView = convertView; final String songId = c.getString(c.getColumnIndex(DBAccessHelper._ID)); final String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST)); final String songAlbum = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM)); final String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH)); //Set the album's name and artist as the row's tag. convertView.setTag(R.string.album, songAlbum); convertView.setTag(R.string.artist, songArtist); holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); holder.subText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); holder.subText .setPaintFlags(holder.subText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); //Set the song title. holder.title.setText(songAlbum); holder.subText.setText(songArtist); mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image, MusicLibraryEditorActivity.displayImageOptions); //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status. if (MusicLibraryEditorActivity.songDBIdsList.contains(songId)) { holder.checkBox.setChecked(true); convertView.setBackgroundColor(0xCC0099CC); } else { convertView.setBackgroundColor(0x00000000); holder.checkBox.setChecked(false); } holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) { if (isChecked == true) { //Only receive inputs by the user and ignore any system-made changes to the checkbox state. if (checkbox.isPressed()) { finalConvertView.setBackgroundColor(0xCC0099CC); AsyncGetAlbumSongIds task = new AsyncGetAlbumSongIds(songAlbum, songArtist); task.execute(new String[] { "ADD" }); } } else if (isChecked == false) { //Only receive inputs by the user and ignore any system-made changes to the checkbox state. if (checkbox.isPressed()) { finalConvertView.setBackgroundColor(0x00000000); AsyncGetAlbumSongIds task = new AsyncGetAlbumSongIds(songAlbum, songArtist); task.execute(new String[] { "REMOVE" }); } } } }); return convertView; }
From source file:com.netpace.expressit.android.ui.TypefaceTextView.java
public TypefaceTextView(Context context, AttributeSet attrs) { super(context, attrs); // Get our custom attributes TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TypefaceTextView, 0, 0); try {/*from ww w . j a v a 2 s . c o m*/ String typefaceName = a.getString(R.styleable.TypefaceTextView_typeface); if (!isInEditMode() && !TextUtils.isEmpty(typefaceName)) { Typeface typeface = sTypefaceCache.get(typefaceName); if (typeface == null) { typeface = Typeface.createFromAsset(context.getAssets(), String.format("fonts/%s_0.otf", typefaceName)); // Cache the Typeface object sTypefaceCache.put(typefaceName, typeface); } setTypeface(typeface); // Note: This flag is required for proper typeface rendering setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); } } finally { a.recycle(); } }
From source file:com.aniruddhc.acemusic.player.BlacklistManagerActivity.BlacklistedAlbumsMultiselectAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final Cursor c = (Cursor) getItem(position); SongsListViewHolder holder = null;/*w w w . j ava 2s . c o m*/ if (convertView == null) { convertView = LayoutInflater.from(mContext).inflate(R.layout.music_library_editor_albums_layout, parent, false); holder = new SongsListViewHolder(); holder.image = (ImageView) convertView.findViewById(R.id.albumThumbnailMusicLibraryEditor); holder.title = (TextView) convertView.findViewById(R.id.albumNameMusicLibraryEditor); holder.checkBox = (CheckBox) convertView.findViewById(R.id.albumCheckboxMusicLibraryEditor); holder.subText = (TextView) convertView.findViewById(R.id.albumArtistNameMusicLibraryEditor); convertView.setTag(holder); } else { holder = (SongsListViewHolder) convertView.getTag(); } final View finalConvertView = convertView; final String songId = c.getString(c.getColumnIndex(DBAccessHelper._ID)); final String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST)); final String songAlbum = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM)); final String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH)); final String songBlacklistStatus = c.getString(c.getColumnIndex(DBAccessHelper.BLACKLIST_STATUS)); //Set the album's name and artist as the row's tag. convertView.setTag(R.string.album, songAlbum); convertView.setTag(R.string.artist, songArtist); holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); holder.subText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); holder.subText .setPaintFlags(holder.subText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); //Set the song title. holder.title.setText(songAlbum); holder.subText.setText(songArtist); mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image, BlacklistManagerActivity.displayImageOptions); //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status. if (BlacklistManagerActivity.songIdBlacklistStatusPair.get(songId).equals("TRUE")) { holder.checkBox.setChecked(true); convertView.setBackgroundColor(0xCCFF4444); } else { convertView.setBackgroundColor(0x00000000); holder.checkBox.setChecked(false); } holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) { if (isChecked == true) { //Only receive inputs by the user and ignore any system-made changes to the checkbox state. if (checkbox.isPressed()) { finalConvertView.setBackgroundColor(0xCCFF4444); AsyncBlacklistAlbumTask task = new AsyncBlacklistAlbumTask(songAlbum, songArtist); task.execute(new String[] { "ADD" }); } } else if (isChecked == false) { //Only receive inputs by the user and ignore any system-made changes to the checkbox state. if (checkbox.isPressed()) { finalConvertView.setBackgroundColor(0x00000000); AsyncBlacklistAlbumTask task = new AsyncBlacklistAlbumTask(songAlbum, songArtist); task.execute(new String[] { "REMOVE" }); } } } }); return convertView; }
From source file:com.aniruddhc.acemusic.player.NowPlayingActivity.PlaylistPagerFlippedFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_playlist_pager_flipped, container, false);//w ww . j a va 2s. co m mContext = getActivity().getApplicationContext(); mApp = (Common) mContext; ratingBar = (RatingBar) rootView.findViewById(R.id.playlist_pager_flipped_rating_bar); lyricsRelativeLayout = (RelativeLayout) rootView.findViewById(R.id.lyricsRelativeLayout); lyricsTextView = (TextView) rootView.findViewById(R.id.playlist_pager_flipped_lyrics); headerTextView = (TextView) rootView.findViewById(R.id.playlist_pager_flipped_title); noLyricsFoundText = (TextView) rootView.findViewById(R.id.no_embedded_lyrics_found_text); lyricsTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); lyricsTextView .setPaintFlags(lyricsTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); headerTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); headerTextView .setPaintFlags(headerTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); noLyricsFoundText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); noLyricsFoundText.setPaintFlags( noLyricsFoundText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); lyricsRelativeLayout.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { //Fire a broadcast that notifies the PlaylistPager to update flip back to the album art. Intent intent = new Intent(broadcastMessage); intent.putExtra("MESSAGE", broadcastMessage); //Initialize the local broadcast manager. localBroadcastManager = LocalBroadcastManager.getInstance(mContext); localBroadcastManager.sendBroadcast(intent); return true; } }); //Get the file path of the current song. String updatedSongTitle = ""; String updatedSongArtist = ""; String songFilePath = ""; String songId = ""; MediaMetadataRetriever mmdr = new MediaMetadataRetriever(); tempCursor = mApp.getService().getCursor(); tempCursor.moveToPosition( mApp.getService().getPlaybackIndecesList().get(mApp.getService().getCurrentSongIndex())); if (tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) { //Retrieve the info from the file's metadata. songFilePath = tempCursor.getString(tempCursor.getColumnIndex(null)); mmdr.setDataSource(songFilePath); updatedSongTitle = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); updatedSongArtist = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); } else { /* Check if the cursor has the SONG_FILE_PATH column. If it does, we're dealing * with the SONGS table. If not, we're dealing with the PLAYLISTS table. We'll * retrieve data from the appropriate columns using this info. */ if (tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) { //We're dealing with the Playlists table. songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.PLAYLIST_FILE_PATH)); mmdr.setDataSource(songFilePath); updatedSongTitle = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); updatedSongArtist = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); } else { //We're dealing with the songs table. songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH)); updatedSongTitle = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_TITLE)); updatedSongArtist = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)); songId = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ID)); } } headerTextView.setText(updatedSongTitle + " - " + updatedSongArtist); ratingBar.setStepSize(1); int rating = mApp.getDBAccessHelper().getSongRating(songId); ratingBar.setRating(rating); //Get the rating value for the song. AudioFile audioFile = null; File file = null; try { audioFile = null; file = new File(songFilePath); try { audioFile = AudioFileIO.read(file); } catch (CannotReadException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (org.jaudiotagger.tag.TagException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ReadOnlyFileException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InvalidAudioFrameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } try { final AudioFile finalizedAudioFile = audioFile; final String finalSongFilePath = songFilePath; final String finalSongId = songId; ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { //Change the rating in the DB and the actual audio file itself. Log.e("DEBUG", ">>>>>RATING: " + rating); try { Tag tag = finalizedAudioFile.getTag(); tag.addField(FieldKey.RATING, "" + ((int) rating)); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); Log.e("DEBUG", ">>>>>>>RATING FIELD NOT FOUND"); } try { finalizedAudioFile.commit(); } catch (CannotWriteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } mApp.getDBAccessHelper().setSongRating(finalSongId, (int) rating); } }); //Check if the audio file has any embedded lyrics. String lyrics = null; try { Tag tag = audioFile.getTag(); lyrics = tag.getFirst(FieldKey.LYRICS); if (lyrics == null || lyrics.isEmpty()) { lyricsTextView.setVisibility(View.GONE); noLyricsFoundText.setVisibility(View.VISIBLE); return rootView; } //Since the song has embedded lyrics, display them in the layout. lyricsTextView.setVisibility(View.VISIBLE); noLyricsFoundText.setVisibility(View.GONE); lyricsTextView.setText(lyrics); } catch (Exception e) { e.printStackTrace(); lyricsTextView.setVisibility(View.GONE); noLyricsFoundText.setVisibility(View.VISIBLE); return rootView; } } catch (Exception e) { e.printStackTrace(); //Can't do much here. } return rootView; }
From source file:com.aniruddhc.acemusic.player.Drawers.InnerNavigationDrawerFragment.java
@SuppressLint("NewApi") @Override/*ww w .j a va 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.navigation_drawer_layout, null); mApp = (Common) getActivity().getApplicationContext(); browsersListView = (ListView) rootView.findViewById(R.id.browsers_list_view); librariesListView = (ListView) rootView.findViewById(R.id.libraries_list_view); browsersHeaderText = (TextView) rootView.findViewById(R.id.browsers_header_text); librariesHeaderText = (TextView) rootView.findViewById(R.id.libraries_header_text); librariesColorTagImageView = (ImageView) rootView.findViewById(R.id.library_color_tag); librariesIcon = (ImageView) rootView.findViewById(R.id.libraries_icon); librariesIcon.setImageResource(UIElementsHelper.getIcon(getActivity(), "libraries")); Drawable backgroundDrawable; if (mApp.getCurrentTheme() == Common.DARK_THEME) { backgroundDrawable = new ColorDrawable(0x191919); } else { backgroundDrawable = getResources().getDrawable(R.drawable.holo_white_selector); } int currentAPI = android.os.Build.VERSION.SDK_INT; if (currentAPI < android.os.Build.VERSION_CODES.JELLY_BEAN) { rootView.setBackgroundDrawable(backgroundDrawable); } else { rootView.setBackground(backgroundDrawable); } //Set the header text fonts/colors. browsersHeaderText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light")); librariesHeaderText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light")); browsersHeaderText.setPaintFlags(browsersHeaderText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG); librariesHeaderText.setPaintFlags(librariesHeaderText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG); //Apply the Browser ListView's adapter. List<String> titles = Arrays .asList(getActivity().getResources().getStringArray(R.array.sliding_menu_array)); NavigationDrawerAdapter slidingMenuAdapter = new NavigationDrawerAdapter(getActivity(), new ArrayList<String>(titles)); browsersListView.setAdapter(slidingMenuAdapter); browsersListView.setOnItemClickListener(browsersClickListener); setListViewHeightBasedOnChildren(browsersListView); /*//Apply the Libraries ListView's adapter. userLibrariesDBHelper = new DBAccessHelper(getActivity().getApplicationContext()); cursor = userLibrariesDBHelper.getAllUniqueLibraries(); NavigationDrawerLibrariesAdapter slidingMenuLibrariesAdapter = new NavigationDrawerLibrariesAdapter(getActivity(), cursor); librariesListView.setAdapter(slidingMenuLibrariesAdapter); setListViewHeightBasedOnChildren(librariesListView);*/ librariesListView.setVisibility(View.GONE); librariesHeaderText.setVisibility(View.GONE); librariesIcon.setVisibility(View.GONE); return rootView; }
From source file:org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper.java
public CollapsingTextHelper(View view) { mView = view;//from www .j a va 2 s. c om mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); mCollapsedBounds = new Rect(); mExpandedBounds = new Rect(); mCurrentBounds = new RectF(); }
From source file:android.support.design.widget.CollapsingTextHelper.java
public CollapsingTextHelper(View view) { mView = view;//from w ww . j a v a 2s.co m mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); mCollapsedBounds = new Rect(); mExpandedBounds = new Rect(); mCurrentBounds = new RectF(); }
From source file:com.aniruddhc.acemusic.player.ListViewFragment.ListViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_list_view, container, false); mContext = getActivity().getApplicationContext(); mApp = (Common) mContext;/*from w w w . j ava 2s. co m*/ mFragment = this; //Set the background. We're using getGridViewBackground() since the list doesn't have card items. mRootView.setBackgroundColor(UIElementsHelper.getGridViewBackground(mContext)); //Grab the fragment. This will determine which data to load into the cursor. mFragmentId = getArguments().getInt(Common.FRAGMENT_ID); mFragmentTitle = getArguments().getString(MainActivity.FRAGMENT_HEADER); mDBColumnsMap = new HashMap<Integer, String>(); //Init the search fields. mSearchLayout = (RelativeLayout) mRootView.findViewById(R.id.search_layout); mSearchEditText = (EditText) mRootView.findViewById(R.id.search_field); mSearchEditText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Regular")); mSearchEditText .setPaintFlags(mSearchEditText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); mSearchEditText.setTextColor(UIElementsHelper.getThemeBasedTextColor(mContext)); mSearchEditText.setFocusable(true); mSearchEditText.setCursorVisible(true); mQuickScroll = (QuickScroll) mRootView.findViewById(R.id.quickscroll); mListView = (ListView) mRootView.findViewById(R.id.generalListView); mListView.setVerticalScrollBarEnabled(false); //Apply the ListViews' dividers. if (mApp.getCurrentTheme() == Common.DARK_THEME) { mListView.setDivider(mContext.getResources().getDrawable(R.drawable.icon_list_divider)); } else { mListView.setDivider(mContext.getResources().getDrawable(R.drawable.icon_list_divider_light)); } mListView.setDividerHeight(1); //KitKat translucent navigation/status bar. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int topPadding = Common.getStatusBarHeight(mContext); //Calculate navigation bar height. int navigationBarHeight = 0; int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { navigationBarHeight = getResources().getDimensionPixelSize(resourceId); } mListView.setClipToPadding(false); mListView.setPadding(0, topPadding, 0, navigationBarHeight); mQuickScroll.setPadding(0, topPadding, 0, navigationBarHeight); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mListView.getLayoutParams(); layoutParams = (RelativeLayout.LayoutParams) mSearchLayout.getLayoutParams(); layoutParams.setMargins(15, topPadding + 15, 15, 0); mSearchLayout.setLayoutParams(layoutParams); } //Set the empty views. mEmptyTextView = (TextView) mRootView.findViewById(R.id.empty_view_text); mEmptyTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Light")); mEmptyTextView .setPaintFlags(mEmptyTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); //Create a set of options to optimize the bitmap memory usage. final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; options.inJustDecodeBounds = false; options.inPurgeable = true; mHandler.postDelayed(queryRunnable, 400); return mRootView; }
From source file:com.aniruddhc.acemusic.player.Dialogs.BlacklistedElementsDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mApp = (Common) getActivity().getApplicationContext(); final BlacklistedElementsDialog dialog = this; MANAGER_TYPE = getArguments().getString("MANAGER_TYPE"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); //Get a cursor with a list of blacklisted elements. if (MANAGER_TYPE.equals("ARTISTS")) { builder.setTitle(R.string.blacklisted_artists); cursor = mApp.getDBAccessHelper().getBlacklistedArtists(); } else if (MANAGER_TYPE.equals("ALBUMS")) { builder.setTitle(R.string.blacklisted_albums); cursor = mApp.getDBAccessHelper().getBlacklistedAlbums(); } else if (MANAGER_TYPE.equals("SONGS")) { builder.setTitle(R.string.blacklisted_songs); cursor = mApp.getDBAccessHelper().getAllBlacklistedSongs(); } else if (MANAGER_TYPE.equals("PLAYLISTS")) { builder.setTitle(R.string.blacklisted_playlists); /*DBAccessHelper playlistsDBHelper = new DBAccessHelper(getActivity()); cursor = playlistsDBHelper.getAllBlacklistedPlaylists();*/ } else {//from w ww . j av a2 s . c o m Toast.makeText(getActivity(), R.string.error_occurred, Toast.LENGTH_LONG).show(); return builder.create(); } //Dismiss the dialog if there are no blacklisted elements. if (cursor.getCount() == 0) { Toast.makeText(getActivity(), R.string.no_blacklisted_items_found, Toast.LENGTH_LONG).show(); return builder.create(); } //Loop through checkboxStatuses and insert "TRUE" at every position by default. for (int i = 0; i < cursor.getCount(); i++) { checkboxStatuses.add(true); } View rootView = this.getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_blacklist_manager, null); TextView blacklistManagerInfoText = (TextView) rootView.findViewById(R.id.blacklist_manager_info_text); ListView blacklistManagerListView = (ListView) rootView.findViewById(R.id.blacklist_manager_list); blacklistManagerInfoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light")); blacklistManagerInfoText.setPaintFlags( blacklistManagerInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); blacklistManagerListView.setFastScrollEnabled(true); BlacklistedElementsAdapter adapter = new BlacklistedElementsAdapter(getActivity(), cursor); blacklistManagerListView.setAdapter(adapter); builder.setView(rootView); builder.setNegativeButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { dialog.dismiss(); } }); builder.setPositiveButton(R.string.done, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Loop through checkboxStatuses and unblacklist the elements that have been unchecked. for (int i = 0; i < checkboxStatuses.size(); i++) { cursor.moveToPosition(i); if (checkboxStatuses.get(i) == true) { //The item is still blacklisted. continue; } else { //The item has been unblacklisted. if (MANAGER_TYPE.equals("ARTISTS")) { mApp.getDBAccessHelper().setBlacklistForArtist( cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)), false); } else if (MANAGER_TYPE.equals("ALBUMS")) { mApp.getDBAccessHelper().setBlacklistForAlbum( cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ALBUM)), cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)), false); } else if (MANAGER_TYPE.equals("SONGS")) { mApp.getDBAccessHelper().setBlacklistForSong( cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH)), false); } else if (MANAGER_TYPE.equals("PLAYLISTS")) { /*DBAccessHelper playlistsDBHelper = new DBAccessHelper(getActivity()); playlistsDBHelper.unBlacklistPlaylist(cursor.getString(cursor.getColumnIndex(DBAccessHelper.PLAYLIST_BLACKLIST_STATUS)));*/ } } } dialog.dismiss(); } }); return builder.create(); }