List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTint
public static void setTint(Drawable drawable, int i)
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./* w w w .j a v a 2s. co 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:com.dimelo.sampleapp.google.IconSlidingTabLayout.java
private void updateIcon(ImageView iconImageView, int position) { if (mViewPager == null) { return;/*from w ww . j a v a 2 s.co m*/ } int icon_id; ViewPagerIconAndTextAdapter adapter = (ViewPagerIconAndTextAdapter) mViewPager.getAdapter(); if (position == mViewPager.getCurrentItem()) { icon_id = adapter.getSelectedPageIconId(position); } else { icon_id = adapter.getPageIconId(position); } Resources resources = getContext().getResources(); Drawable icon = DrawableCompat.wrap(resources.getDrawable(icon_id)); DrawableCompat.setTint(icon, resources.getColor(R.color.accent)); iconImageView.setImageDrawable(icon); }
From source file:com.todoroo.astrid.tags.TagsControlSet.java
@Nullable @Override/*from w ww .j ava 2s .c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); ArrayList<String> newTags; if (savedInstanceState != null) { selectedTags = savedInstanceState.getParcelableArrayList(EXTRA_SELECTED_TAGS); newTags = savedInstanceState.getStringArrayList(EXTRA_NEW_TAGS); } else { selectedTags = tagService.getTagDataForTask(taskId); newTags = newArrayList(); } allTags = tagService.getTagList(); dialogView = inflater.inflate(R.layout.control_set_tag_list, null); newTagLayout = (LinearLayout) dialogView.findViewById(R.id.newTags); tagListView = (ListView) dialogView.findViewById(R.id.existingTags); tagListView.setAdapter(new ArrayAdapter<TagData>(getActivity(), R.layout.simple_list_item_multiple_choice_themed, allTags) { @NonNull @SuppressLint("NewApi") @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) { CheckedTextView view = (CheckedTextView) super.getView(position, convertView, parent); TagData tagData = allTags.get(position); ThemeColor themeColor = themeCache.getThemeColor(tagData.getColor() >= 0 ? tagData.getColor() : 19); view.setText(tagData.getName()); Drawable original = ContextCompat.getDrawable(getContext(), R.drawable.ic_label_24dp); Drawable wrapped = DrawableCompat.wrap(original.mutate()); DrawableCompat.setTint(wrapped, themeColor.getPrimaryColor()); if (atLeastJellybeanMR1()) { view.setCompoundDrawablesRelativeWithIntrinsicBounds(wrapped, null, null, null); } else { view.setCompoundDrawablesWithIntrinsicBounds(wrapped, null, null, null); } return view; } }); for (String newTag : newTags) { addTag(newTag); } addTag(""); for (TagData tag : selectedTags) { setTagSelected(tag); } refreshDisplayView(); return view; }
From source file:org.gateshipone.odyssey.fragments.PlaylistTracksFragment.java
/** * Initialize the options menu.// ww w .j ava 2 s . com * Be sure to call {@link #setHasOptionsMenu} before. * * @param menu The container for the custom options menu. * @param menuInflater The inflater to instantiate the layout. */ @Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { // Inflate the menu; this adds items to the action bar if it is present. menuInflater.inflate(R.menu.options_menu_playlist_tracks_fragment, menu); // get tint color int tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent); Drawable drawable = menu.findItem(R.id.action_add_playlist_tracks).getIcon(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, tintColor); menu.findItem(R.id.action_add_playlist_tracks).setIcon(drawable); super.onCreateOptionsMenu(menu, menuInflater); }
From source file:com.google.samples.apps.topeka.adapter.CategoryAdapter.java
private Drawable wrapAndTint(Drawable done, @ColorRes int color) { Drawable compatDrawable = DrawableCompat.wrap(done); DrawableCompat.setTint(compatDrawable, getColor(color)); return compatDrawable; }
From source file:com.github.andrewlord1990.materialandroid.component.textfield.PasswordEditText.java
private Drawable tintDrawable(Drawable drawable) { if (tintColor != 0) { Drawable wrapper = DrawableCompat.wrap(drawable); DrawableCompat.setTint(wrapper, tintColor); return wrapper; }//ww w.j a va2 s . c o m return drawable; }
From source file:org.gateshipone.malp.application.fragments.serverfragments.MyMusicTabsFragment.java
/** * Initialize the options menu.// ww w. ja v a 2 s . co m * Be sure to call {@link #setHasOptionsMenu} before. * * @param menu The container for the custom options menu. * @param menuInflater The inflater to instantiate the layout. */ @Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { // Inflate the menu; this adds items to the action bar if it is present. menuInflater.inflate(R.menu.fragment_menu_library, menu); mOptionMenu = menu; // get tint color int tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.malp_color_text_accent); Drawable drawable = menu.findItem(R.id.action_search).getIcon(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, tintColor); menu.findItem(R.id.action_search).setIcon(drawable); mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); // Check if a search string is saved from before if (mSearchString != null) { // Expand the view mSearchView.setIconified(false); menu.findItem(R.id.action_search).expandActionView(); // Set the query string mSearchView.setQuery(mSearchString, false); GenericMPDFragment fragment = mMyMusicPagerAdapter.getRegisteredFragment(mViewPager.getCurrentItem()); // Notify the adapter fragment.applyFilter(mSearchString); } mSearchView.setOnQueryTextListener(new SearchTextObserver()); super.onCreateOptionsMenu(menu, menuInflater); }
From source file:com.freshdigitable.udonroad.StatusViewBase.java
protected void setTint(ImageView view, @ColorRes int color) { // Log.d(TAG, "setTint: " + color); DrawableCompat.setTint(view.getDrawable(), ContextCompat.getColor(getContext(), color)); }
From source file:com.l4digital.fastscroll.FastScroller.java
/** * Set the color of the scroll track./*from w w w . j a v a 2 s . co m*/ * * @param color The color for the scroll track */ public void setTrackColor(@ColorInt int color) { @ColorInt int trackColor = color; if (mTrackImage == null) { mTrackImage = DrawableCompat.wrap(ContextCompat.getDrawable(getContext(), R.drawable.fastscroll_track)); mTrackImage.mutate(); } DrawableCompat.setTint(mTrackImage, trackColor); mTrackView.setImageDrawable(mTrackImage); }
From source file:com.master.metehan.filtereagle.AdapterLog.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values final long id = cursor.getLong(colID); long time = cursor.getLong(colTime); int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion)); int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol)); String flags = cursor.getString(colFlags); String saddr = cursor.getString(colSAddr); int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort)); String daddr = cursor.getString(colDAddr); int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort)); String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName)); int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid)); String data = cursor.getString(colData); int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed)); int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection)); int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive)); // Get views//from w w w. jav a 2 s.c om TextView tvTime = (TextView) view.findViewById(R.id.tvTime); TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol); TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags); TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr); TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort); final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr); TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort); final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization); ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon); TextView tvUid = (TextView) view.findViewById(R.id.tvUid); TextView tvData = (TextView) view.findViewById(R.id.tvData); ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection); ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive); // Show time tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time)); // Show connection type if (connection <= 0) ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked); else { if (allowed > 0) ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on); else ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable()); DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff); } // Show if screen on if (interactive <= 0) ivInteractive.setImageDrawable(null); else { ivInteractive.setImageResource(R.drawable.screen_on); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable()); DrawableCompat.setTint(wrap, colorOn); } } // Show protocol name tvProtocol.setText(Util.getProtocolName(protocol, version, false)); // SHow TCP flags tvFlags.setText(flags); tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE); // Show source and destination port if (protocol == 6 || protocol == 17) { tvSPort.setText(sport < 0 ? "" : getKnownPort(sport)); tvDPort.setText(dport < 0 ? "" : getKnownPort(dport)); } else { tvSPort.setText(sport < 0 ? "" : Integer.toString(sport)); tvDPort.setText(dport < 0 ? "" : Integer.toString(dport)); } // Application icon ApplicationInfo info = null; PackageManager pm = context.getPackageManager(); String[] pkg = pm.getPackagesForUid(uid); if (pkg != null && pkg.length > 0) try { info = pm.getApplicationInfo(pkg[0], 0); } catch (PackageManager.NameNotFoundException ignored) { } if (info == null) ivIcon.setImageDrawable(null); else if (info.icon == 0) Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon); else { Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon); Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon); } // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h uid = uid % 100000; // strip off user ID if (uid == -1) tvUid.setText(""); else if (uid == 0) tvUid.setText(context.getString(R.string.title_root)); else if (uid == 9999) tvUid.setText("-"); // nobody else tvUid.setText(Integer.toString(uid)); // Show source address tvSAddr.setText(getKnownAddress(saddr)); // Show destination address if (resolve && !isKnownAddress(daddr)) if (dname == null) { if (tvDaddr.getTag() == null) { tvDaddr.setText(daddr); new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { tvDaddr.setTag(id); } @Override protected String doInBackground(String... args) { try { return InetAddress.getByName(args[0]).getHostName(); } catch (UnknownHostException ignored) { return args[0]; } } @Override protected void onPostExecute(String name) { Object tag = tvDaddr.getTag(); if (tag != null && (Long) tag == id) tvDaddr.setText(">" + name); tvDaddr.setTag(null); } }.execute(daddr); } } else tvDaddr.setText(dname); else tvDaddr.setText(getKnownAddress(daddr)); // Show organization tvOrganization.setVisibility(View.GONE); if (organization) { if (!isKnownAddress(daddr) && tvOrganization.getTag() == null) new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { tvOrganization.setTag(id); } @Override protected String doInBackground(String... args) { try { return Util.getOrganization(args[0]); } catch (Throwable ex) { Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); return null; } } @Override protected void onPostExecute(String organization) { Object tag = tvOrganization.getTag(); if (organization != null && tag != null && (Long) tag == id) { tvOrganization.setText(organization); tvOrganization.setVisibility(View.VISIBLE); } tvOrganization.setTag(null); } }.execute(daddr); } // Show extra data if (TextUtils.isEmpty(data)) { tvData.setText(""); tvData.setVisibility(View.GONE); } else { tvData.setText(data); tvData.setVisibility(View.VISIBLE); } }