List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTint
public static void setTint(Drawable drawable, int i)
From source file:com.ekumen.tangobot.application.ModuleStatusIndicator.java
/** * Look for the resource according to the case and apply it with its respective color. * Note: This function does not perform any checks as assumes the xml file is correct. * It should have one array for each state, and each array should have a drawable resource and a color resource (in that order). *//*from ww w. java2 s.c om*/ private void switchStatusDisplay() { mActivity.runOnUiThread(new Runnable() { @Override public void run() { TypedArray img = null; switch (mStatus) { case PAUSED: img = mActivity.getResources().obtainTypedArray(R.array.status_paused); break; case OK: img = mActivity.getResources().obtainTypedArray(R.array.status_running); break; case LOADING: img = mActivity.getResources().obtainTypedArray(R.array.status_loading); break; case ERROR: img = mActivity.getResources().obtainTypedArray(R.array.status_error); break; } int color = img.getColor(COLOR_INDEX, mActivity.getResources().getColor(android.R.color.black)); Drawable drawable = img.getDrawable(RESOURCE_INDEX); mImageView.setImageDrawable(drawable); drawable = DrawableCompat.wrap(mImageView.getDrawable().mutate()); DrawableCompat.setTint(drawable, color); img.recycle(); } }); }
From source file:im.ene.ribbon.MiscUtils.java
static void setDrawableColor(@NonNull final Drawable drawable, final int color) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof RippleDrawable) { ((RippleDrawable) drawable).setColor(ColorStateList.valueOf(color)); } else {//from w ww . ja v a 2s.com DrawableCompat.setTint(drawable, color); } }
From source file:com.grarak.kerneladiutor.views.recyclerview.downloads.DownloadKernelView.java
@Override public void onCreateView(View view) { super.onCreateView(view); if (mDownloadDrawable == null) { mDownloadDrawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_download); DrawableCompat.setTint(mDownloadDrawable, Color.WHITE); }//from w w w . j ava2 s.c o m if (mCancelDrawable == null) { mCancelDrawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_cancel); DrawableCompat.setTint(mCancelDrawable, Color.WHITE); } final TextView title = (TextView) view.findViewById(R.id.title); TextView summary = (TextView) view.findViewById(R.id.summary); TextView changelog = (TextView) view.findViewById(R.id.changelog); mDownloadSection = view.findViewById(R.id.downloadSection); mProgressParent = view.findViewById(R.id.progressParent); mProgressText = (TextView) view.findViewById(R.id.progressText); mProgressBar = (ProgressBar) view.findViewById(R.id.progressbar); mFabButton = (FloatingActionButton) view.findViewById(R.id.fab_button); mCheckMD5 = view.findViewById(R.id.checkmd5); mMismatchMD5 = view.findViewById(R.id.md5_mismatch); mInstallButton = view.findViewById(R.id.install); final CharSequence titleText = Utils.htmlFrom(mDownload.getName()); title.setText(titleText); title.setMovementMethod(LinkMovementMethod.getInstance()); String description = mDownload.getDescription(); if (description != null) { summary.setText(Utils.htmlFrom(description)); summary.setMovementMethod(LinkMovementMethod.getInstance()); } else { summary.setVisibility(View.GONE); } List<String> changelogs = mDownload.getChangelogs(); if (changelogs.size() > 0) { StringBuilder stringBuilder = new StringBuilder(); for (String change : changelogs) { if (stringBuilder.length() == 0) { stringBuilder.append("\u2022").append(" ").append(change); } else { stringBuilder.append("<br>").append("\u2022").append(" ").append(change); } } changelog.setText(Utils.htmlFrom(stringBuilder.toString())); changelog.setMovementMethod(LinkMovementMethod.getInstance()); } else { changelog.setVisibility(View.GONE); } mMismatchMD5.setVisibility(View.GONE); mInstallButton.setVisibility(View.GONE); if (mCheckMD5Task == null) { mDownloadSection.setVisibility(View.VISIBLE); mCheckMD5.setVisibility(View.GONE); } mProgressParent.setVisibility(mDownloadTask == null ? View.INVISIBLE : View.VISIBLE); mFabButton.setImageDrawable(mDownloadTask == null ? mDownloadDrawable : mCancelDrawable); mFabButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { if (mDownloadTask == null) { mFabButton.setImageDrawable(mCancelDrawable); mProgressParent.setVisibility(View.VISIBLE); mMismatchMD5.setVisibility(View.GONE); mInstallButton.setVisibility(View.GONE); mProgressBar.setProgress(0); mProgressText.setText(""); mProgressBar.setIndeterminate(true); mDownloadTask = new DownloadTask(mActvity, new DownloadTask.OnDownloadListener() { private int mPercentage; @Override public void onUpdate(int currentSize, int totalSize) { int percentage = Math.round(currentSize * 100f / totalSize); if (mPercentage != percentage) { mPercentage = percentage; mProgressBar.setIndeterminate(false); double current = Utils.roundTo2Decimals(currentSize / 1024D / 1024D); double total = Utils.roundTo2Decimals(totalSize / 1024D / 1024D); mProgressBar.setProgress(mPercentage); mProgressText.setText(view.getContext().getString(R.string.downloading_counting, String.valueOf(current), String.valueOf(total)) + view.getContext().getString(R.string.mb)); } } @Override public void onSuccess(String path) { mFabButton.setImageDrawable(mDownloadDrawable); mProgressParent.setVisibility(View.INVISIBLE); mDownloadTask = null; checkMD5(mDownload.getMD5sum(), path, mDownload.getInstallMethod()); } @Override public void onCancel() { mFabButton.setImageDrawable(mDownloadDrawable); mProgressParent.setVisibility(View.INVISIBLE); mMismatchMD5.setVisibility(View.GONE); mDownloadTask = null; } @Override public void onFailure(String error) { Utils.toast(view.getContext().getString(R.string.download_error, titleText), view.getContext()); mFabButton.setImageDrawable(mDownloadDrawable); mProgressParent.setVisibility(View.INVISIBLE); mDownloadTask = null; } }, Utils.getInternalDataStorage() + "/downloads/" + titleText.toString() + ".zip"); mDownloadTask.execute(mDownload.getUrl()); } else { mFabButton.setImageDrawable(mDownloadDrawable); mProgressParent.setVisibility(View.INVISIBLE); mDownloadTask.cancel(); mDownloadTask = null; } } }); }
From source file:io.github.hidroh.materialistic.widget.TintableTextView.java
private Drawable tint(@Nullable Drawable drawable) { if (drawable == null) { return null; }/* w w w .j ava 2s . com*/ drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, mTextColor); return drawable; }
From source file:com.ruesga.rview.misc.BindingAdapters.java
@BindingAdapter("bindBackgroundTint") public static void bindBackgroundTint(View v, int color) { final Drawable dw = v.getBackground(); DrawableCompat.setTint(dw, color); v.setBackground(dw);// ww w.j a v a 2 s . com }
From source file:com.google.samples.apps.iosched.ui.SearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); mSearchView = (SearchView) findViewById(R.id.search_view); setupSearchView();//from w w w .j a v a2 s.c om mSearchResults = (ListView) findViewById(R.id.search_results); mResultsAdapter = new SimpleCursorAdapter(this, R.layout.list_item_search_result, null, new String[] { ScheduleContract.SearchTopicSessionsColumns.SEARCH_SNIPPET }, new int[] { R.id.search_result }, 0); mSearchResults.setAdapter(mResultsAdapter); mSearchResults.setOnItemClickListener(this); Toolbar toolbar = getActionBarToolbar(); Drawable up = DrawableCompat.wrap(ContextCompat.getDrawable(this, R.drawable.ic_up)); DrawableCompat.setTint(up, getResources().getColor(R.color.app_body_text_2)); toolbar.setNavigationIcon(up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { navigateUpOrBack(SearchActivity.this, null); } }); String query = getIntent().getStringExtra(SearchManager.QUERY); query = query == null ? "" : query; mQuery = query; if (mSearchView != null) { mSearchView.setQuery(query, false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { doEnterAnim(); } overridePendingTransition(0, 0); }
From source file:com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter.java
public SearchSuggestionsAdapter(Context context, int suggestionTextSize, Listener listener) { this.mContext = context; this.mListener = listener; this.mBodyTextSizePx = suggestionTextSize; mSearchSuggestions = new ArrayList<>(); mRightIconDrawable = mContext.getResources().getDrawable(R.drawable.ic_arrow_back_black_24dp); mRightIconDrawable = DrawableCompat.wrap(mRightIconDrawable); DrawableCompat.setTint(mRightIconDrawable, mContext.getResources().getColor(R.color.gray_active_icon)); }
From source file:com.facebook.samples.loginsample.accountkit.ReverbBodyFragment.java
private void updateIcon(final View view) { final View progressSpinner = view.findViewById(R.id.reverb_progress_spinner); if (progressSpinner != null) { progressSpinner.setVisibility(showProgressSpinner ? View.VISIBLE : View.GONE); }//from w ww. j a va 2s. com final ImageView iconView = (ImageView) view.findViewById(R.id.reverb_icon); if (iconView != null) { if (iconResourceId > 0) { /* * Api levels lower than 21 do not support android:tint in xml drawables. Tint can * be applied with DrawableCompat */ Drawable icon = getResources().getDrawable(iconResourceId); if (iconTintResourceId > 0) { icon = DrawableCompat.wrap(icon); DrawableCompat.setTint(icon, ContextCompat.getColor(view.getContext(), R.color.reverb_dark)); } iconView.setImageDrawable(icon); iconView.setVisibility(View.VISIBLE); } else { iconView.setVisibility(View.GONE); } } }
From source file:eu.faircode.netguard.AccessAdapter.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values int version = cursor.getInt(colVersion); int protocol = cursor.getInt(colProtocol); String daddr = cursor.getString(colDaddr); int dport = cursor.getInt(colDPort); long time = cursor.getLong(colTime); int allowed = cursor.getInt(colAllowed); int block = cursor.getInt(colBlock); // Get views//from ww w. ja v a2s. co m TextView tvTime = (TextView) view.findViewById(R.id.tvTime); ImageView ivBlock = (ImageView) view.findViewById(R.id.ivBlock); final TextView tvDest = (TextView) view.findViewById(R.id.tvDest); // Set values tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time)); if (block < 0) ivBlock.setImageDrawable(null); else { ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable()); DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn); } } tvDest.setText( Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? ":" + dport : "")); if (allowed < 0) tvDest.setTextColor(colorText); else if (allowed > 0) tvDest.setTextColor(colorOn); else tvDest.setTextColor(colorOff); }
From source file:ezy.ui.view.NoticeView.java
private void initWithContext(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NoticeView); mIcon = a.getDrawable(R.styleable.NoticeView_nvIcon); mIconPadding = (int) a.getDimension(R.styleable.NoticeView_nvIconPadding, 0); boolean hasIconTint = a.hasValue(R.styleable.NoticeView_nvIconTint); if (hasIconTint) { mIconTint = a.getColor(R.styleable.NoticeView_nvIconTint, 0xff999999); }//from www . j a v a 2s .c om mInterval = a.getInteger(R.styleable.NoticeView_nvInterval, 4000); mDuration = a.getInteger(R.styleable.NoticeView_nvDuration, 900); mDefaultFactory.resolve(a); a.recycle(); if (mIcon != null) { mPaddingLeft = getPaddingLeft(); int realPaddingLeft = mPaddingLeft + mIconPadding + mIcon.getIntrinsicWidth(); setPadding(realPaddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom()); if (hasIconTint) { mIcon = mIcon.mutate(); DrawableCompat.setTint(mIcon, mIconTint); } } }