List of usage examples for android.content Context getDrawable
@Nullable public final Drawable getDrawable(@DrawableRes int id)
From source file:org.gateshipone.malp.application.listviewitems.FileListItem.java
/** * Derived constructor to increase speed by directly selecting the right methods for the need of the using adapter. * * Generic Track Item constructor//w w w .j a va2 s. c o m * * @param context Context used for creation of View * @param file Track that is used for this view * @param showIcon If left file/dir icon should be shown. It is not changeable after creation. */ public FileListItem(Context context, MPDTrack file, boolean showIcon) { this(context, showIcon); setTrack(file, context); if (showIcon) { Drawable icon = context.getDrawable(R.drawable.ic_file_48dp); if (icon != null) { // get tint color int tintColor = ThemeUtils.getThemeColor(context, android.R.attr.textColor); // tint the icon DrawableCompat.setTint(icon, tintColor); } mItemIcon.setImageDrawable(icon); } }
From source file:org.gateshipone.malp.application.listviewitems.FileListItem.java
/** * Extracts the information from a MPDPlaylist * @param playlist Playlist to show the view for. * @param context Context used for image extraction *///from w w w . j a v a2 s . c om public void setPlaylist(MPDPlaylist playlist, Context context) { mTitleView.setText(playlist.getSectionTitle()); mAdditionalInfoView.setText(playlist.getLastModified()); if (mShowIcon) { Drawable icon = context.getDrawable(R.drawable.ic_queue_music_black_48dp); if (icon != null) { // get tint color int tintColor = ThemeUtils.getThemeColor(context, android.R.attr.textColor); // tint the icon DrawableCompat.setTint(icon, tintColor); } mItemIcon.setImageDrawable(icon); } }
From source file:org.gateshipone.malp.application.listviewitems.FileListItem.java
/** * Extracts the information from a MPDDirectory * @param directory Directory to show the view for. * @param context Context used for image extraction *//*from w w w .j ava 2s . c o m*/ public void setDirectory(MPDDirectory directory, Context context) { mTitleView.setText(directory.getSectionTitle()); mAdditionalInfoView.setText(directory.getLastModified()); if (mShowIcon) { Drawable icon = context.getDrawable(R.drawable.ic_folder_48dp); if (icon != null) { // get tint color int tintColor = ThemeUtils.getThemeColor(context, android.R.attr.textColor); // tint the icon DrawableCompat.setTint(icon, tintColor); } mItemIcon.setImageDrawable(icon); } }
From source file:org.gateshipone.odyssey.viewitems.ListViewItem.java
/** * Extracts the information from a playlist model. * * @param context The current context./* ww w . ja va2s .c o m*/ * @param playlist The current playlist model. */ public void setPlaylist(final Context context, final PlaylistModel playlist) { // title String playlistTitle = playlist.getPlaylistName(); // get icon Drawable icon = context.getDrawable(R.drawable.ic_queue_music_48dp); if (icon != null) { // get tint color int tintColor = ThemeUtils.getThemeColor(context, R.attr.odyssey_color_text_background_secondary); // tint the icon DrawableCompat.setTint(icon, tintColor); } setTitle(playlistTitle); setIcon(icon); }
From source file:com.android.tv.settings.MainFragment.java
public void updateGoogleSettings() { final Preference googleSettingsPref = findPreference(KEY_GOOGLE_SETTINGS); if (googleSettingsPref != null) { final ResolveInfo info = systemIntentIsHandled(googleSettingsPref.getIntent()); googleSettingsPref.setVisible(info != null); if (info != null) { try { final Context targetContext = getContext() .createPackageContext(info.resolvePackageName != null ? info.resolvePackageName : info.activityInfo.packageName, 0); googleSettingsPref.setIcon(targetContext.getDrawable(info.iconResourceId)); } catch (Resources.NotFoundException | PackageManager.NameNotFoundException | SecurityException e) { Log.e(TAG, "Google settings icon not found", e); }/*w w w .j a v a 2 s. c o m*/ } } }
From source file:org.gateshipone.malp.application.listviewitems.FileListItem.java
/** * Derived constructor to increase speed by directly selecting the right methods for the need of the using adapter. * * Constructor that shows a item for a track, overrides the track number (useful for playlists) and shows a section * header./*from w w w .j av a 2 s. c o m*/ * * @param context Context used for creation of View * @param track Track to show the view for * @param showIcon If left file/dir icon should be shown. It is not changeable after creation. * @param sectionTitle Title of the section (album title for example) */ public FileListItem(Context context, MPDTrack track, boolean showIcon, String sectionTitle, ScrollSpeedAdapter adapter) { this(context, sectionTitle, false, adapter); setTrack(track, context); if (showIcon) { Drawable icon = context.getDrawable(R.drawable.ic_file_48dp); if (icon != null) { // get tint color int tintColor = ThemeUtils.getThemeColor(context, android.R.attr.textColor); // tint the icon DrawableCompat.setTint(icon, tintColor); } mItemIcon.setImageDrawable(icon); } }
From source file:org.gateshipone.odyssey.viewitems.ListViewItem.java
/** * Extracts the information from a file model. * * @param context The current context.//from w w w . j a va 2 s . c om * @param file The current file model. */ public void setFile(final Context context, final FileModel file) { // title String title = file.getName(); // get icon for filetype Drawable icon; if (file.isDirectory()) { // choose directory icon icon = context.getDrawable(R.drawable.ic_folder_48dp); } else { // choose file icon icon = context.getDrawable(R.drawable.ic_file_48dp); } if (icon != null) { // get tint color int tintColor = ThemeUtils.getThemeColor(context, R.attr.odyssey_color_text_background_secondary); // tint the icon DrawableCompat.setTint(icon, tintColor); } // last modified String lastModifiedDateString = FormatHelper.formatTimeStampToString(context, file.getLastModified()); setTitle(title); setSubtitle(lastModifiedDateString); setIcon(icon); }
From source file:org.gateshipone.malp.application.listviewitems.FileListItem.java
/** * Derived constructor to increase speed by directly selecting the right methods for the need of the using adapter. * * Constructor that shows a item for a track, overrides the track number (useful for playlists) and shows a section * header.//from w w w . j a v a 2 s .c o m * * @param context Context used for creation of View * @param track Track to show the view for * @param trackNo Overridden track number * @param showIcon If left file/dir icon should be shown. It is not changeable after creation. * @param sectionTitle Title of the section (album title for example) */ public FileListItem(Context context, MPDTrack track, int trackNo, boolean showIcon, String sectionTitle, ScrollSpeedAdapter adapter) { this(context, sectionTitle, false, adapter); setTrack(track, context); mNumberView.setText(String.valueOf(trackNo)); if (showIcon) { Drawable icon = context.getDrawable(R.drawable.ic_file_48dp); if (icon != null) { // get tint color int tintColor = ThemeUtils.getThemeColor(context, android.R.attr.textColor); // tint the icon DrawableCompat.setTint(icon, tintColor); } mItemIcon.setImageDrawable(icon); } }
From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java
/** * Checks whether a drawable with a resoure id is a small grayscale icon. * Grayscale here means "very close to a perfect gray"; icon means "no larger than 64dp". * * @param context The context to load the drawable from. * @return True if the bitmap is grayscale; false if it is color or too large to examine. *//* ww w . ja va 2s .co m*/ public boolean isGrayscaleIcon(Context context, int drawableResId) { if (drawableResId != 0) { try { return isGrayscaleIcon(context.getDrawable(drawableResId)); } catch (Resources.NotFoundException ex) { Log.e(TAG, "Drawable not found: " + drawableResId); return false; } } else { return false; } }
From source file:org.gateshipone.odyssey.viewitems.ListViewItem.java
/** * Extracts the information from a bookmark model. * * @param context The current context./* w w w . j a v a 2 s .co m*/ * @param bookmark The current bookmark model. */ public void setBookmark(final Context context, final BookmarkModel bookmark) { // title String bookmarkTitle = bookmark.getTitle(); // number of tracks int numberOfTracks = bookmark.getNumberOfTracks(); String numberOfTracksString = ""; if (numberOfTracks > 0) { // set number of tracks only if this bookmark contains tracks numberOfTracksString = Integer.toString(bookmark.getNumberOfTracks()) + " " + context.getString(R.string.fragment_bookmarks_tracks); } // get date string long id = bookmark.getId(); String dateString = ""; if (id > 0) { // set date string only if id of this bookmark is valid dateString = FormatHelper.formatTimeStampToString(context, bookmark.getId()); } // get icon Drawable icon = context.getDrawable(R.drawable.ic_bookmark_black_48dp); if (icon != null) { // get tint color int tintColor = ThemeUtils.getThemeColor(context, R.attr.odyssey_color_text_background_secondary); // tint the icon DrawableCompat.setTint(icon, tintColor); } setTitle(bookmarkTitle); setSubtitle(dateString); setAddtionalSubtitle(numberOfTracksString); setIcon(icon); }