Java Code Examples for androidx.core.graphics.drawable.DrawableCompat#wrap()
The following examples show how to use
androidx.core.graphics.drawable.DrawableCompat#wrap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchResultFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
private void setupTheme() { if (viewModel != null && storeThemeExists(viewModel.getStoreTheme())) { String storeTheme = viewModel.getStoreTheme(); themeManager.setTheme(storeTheme); toolbar.setBackgroundResource( themeManager.getAttributeForTheme(storeTheme, R.attr.toolbarBackground).resourceId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrapDrawable = DrawableCompat.wrap(progressBar.getIndeterminateDrawable()); DrawableCompat.setTint(wrapDrawable, themeManager.getAttributeForTheme(R.attr.colorPrimary).data); progressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable)); } else { progressBar.getIndeterminateDrawable() .setColorFilter(themeManager.getAttributeForTheme(R.attr.colorPrimary).data, PorterDuff.Mode.SRC_IN); } } }
Example 2
Source File: Utils.java From butterknife with Apache License 2.0 | 6 votes |
@UiThread // Implicit synchronization for use of shared resource VALUE. public static Drawable getTintedDrawable(Context context, @DrawableRes int id, @AttrRes int tintAttrId) { boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true); if (!attributeFound) { throw new Resources.NotFoundException("Required tint color attribute with name " + context.getResources().getResourceEntryName(tintAttrId) + " and attribute ID " + tintAttrId + " was not found."); } Drawable drawable = ContextCompat.getDrawable(context, id); drawable = DrawableCompat.wrap(drawable.mutate()); int color = ContextCompat.getColor(context, VALUE.resourceId); DrawableCompat.setTint(drawable, color); return drawable; }
Example 3
Source File: DrawableHelper.java From GetApk with MIT License | 5 votes |
public static Drawable tintDrawable(@NonNull Drawable drawable, ColorStateList tintList, PorterDuff.Mode tintMode) { if (tintList != null) { // First mutate the Drawable, then wrap it and set the tint list if (DrawableUtils.canSafelyMutateDrawable(drawable)) { drawable = drawable.mutate(); } drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTintList(drawable, tintList); if (tintMode != null) { DrawableCompat.setTintMode(drawable, tintMode); } } return drawable; }
Example 4
Source File: DrawableHelper.java From GetApk with MIT License | 5 votes |
@Nullable public static Drawable getTintDrawable(@NonNull Context context, @DrawableRes int resId) { Drawable drawable = ContextCompat.getDrawable(context, resId); if (drawable != null) { if (DrawableUtils.canSafelyMutateDrawable(drawable)) { drawable = drawable.mutate(); } drawable = DrawableCompat.wrap(drawable); } return drawable; }
Example 5
Source File: AwesomeToolbar.java From AndroidNavigation with MIT License | 5 votes |
private Drawable drawableFromBarButtonItem(ToolbarButtonItem barButtonItem) { if (getContext() == null) { return null; } Drawable drawable = null; if (barButtonItem.iconUri != null) { drawable = DrawableUtils.fromUri(getContext(), barButtonItem.iconUri); } else if (barButtonItem.iconRes != 0) { drawable = ContextCompat.getDrawable(getContext(), barButtonItem.iconRes); } if (drawable != null) { drawable = DrawableCompat.wrap(drawable.mutate()); } return drawable; }
Example 6
Source File: PagerBullet.java From PagerBullet with MIT License | 5 votes |
public static Drawable wrapTintDrawable(Drawable sourceDrawable, int color) { if (color != 0) { final Drawable wrapDrawable = DrawableCompat.wrap(sourceDrawable); DrawableCompat.setTint(wrapDrawable, color); wrapDrawable.setBounds( 0, 0, wrapDrawable.getIntrinsicWidth(), wrapDrawable.getIntrinsicHeight() ); return wrapDrawable; } else { return sourceDrawable; } }
Example 7
Source File: MultiSlider.java From MultiSlider with Apache License 2.0 | 5 votes |
private Drawable getTintedDrawable(Drawable drawable, int tintColor) { if (drawable != null && tintColor != 0) { Drawable wrappedDrawable = DrawableCompat.wrap(drawable.mutate()); DrawableCompat.setTint(wrappedDrawable, tintColor); return wrappedDrawable; } return drawable; }
Example 8
Source File: MyMusicFragment.java From odyssey with GNU General Public License v3.0 | 5 votes |
/** * Initialize the options menu. * 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(@NonNull Menu menu, @NonNull MenuInflater menuInflater) { // Inflate the menu; this adds items to the action bar if it is present. menuInflater.inflate(R.menu.options_menu_my_music, menu); mOptionMenu = menu; // get tint color int tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent); Drawable drawable = menu.findItem(R.id.action_search).getIcon(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, tintColor); mOptionMenu.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); OdysseyFragment fragment = mMyMusicPagerAdapter.getRegisteredFragment(mMyMusicViewPager.getCurrentItem()); // Notify the adapter fragment.applyFilter(mSearchString); } mSearchView.setOnQueryTextListener(new SearchTextObserver()); // show recents options only for the albums fragment menu.findItem(R.id.action_show_recent_albums).setVisible(mMyMusicViewPager.getCurrentItem() == 1); super.onCreateOptionsMenu(menu, menuInflater); }
Example 9
Source File: Slider.java From EhViewer with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") public BubbleView(Context context, Paint paint) { super(context); setImageResource(R.drawable.v_slider_bubble); mDrawable = DrawableCompat.wrap(getDrawable()); setImageDrawable(mDrawable); mTextPaint = paint; }
Example 10
Source File: ImageMarkersActivity.java From GestureViews with Apache License 2.0 | 5 votes |
/** * Returns tinted icon. */ private Drawable getIcon(@ColorRes int colorId) { Drawable icon = ContextCompat.getDrawable(this, R.drawable.ic_place_white_24dp); if (icon == null) { throw new NullPointerException(); } icon = DrawableCompat.wrap(icon); DrawableCompat.setTint(icon, ContextCompat.getColor(this, colorId)); return icon; }
Example 11
Source File: BottomNavigationView.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Set the background of our menu items to be a ripple with the given colors. * * @param itemRippleColor The {@link ColorStateList} for the ripple. This will create a ripple * background for menu items, replacing any background previously set by {@link * #setItemBackground(Drawable)}. * @attr ref R.styleable#BottomNavigationView_itemRippleColor */ public void setItemRippleColor(@Nullable ColorStateList itemRippleColor) { if (this.itemRippleColor == itemRippleColor) { // Clear the item background when setItemRippleColor(null) is called for consistency. if (itemRippleColor == null && menuView.getItemBackground() != null) { menuView.setItemBackground(null); } return; } this.itemRippleColor = itemRippleColor; if (itemRippleColor == null) { menuView.setItemBackground(null); } else { ColorStateList rippleDrawableColor = RippleUtils.convertToRippleDrawableColor(itemRippleColor); if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { menuView.setItemBackground(new RippleDrawable(rippleDrawableColor, null, null)); } else { GradientDrawable rippleDrawable = new GradientDrawable(); // TODO: Find a workaround for this. Currently on certain devices/versions, LayerDrawable // will draw a black background underneath any layer with a non-opaque color, // (e.g. ripple) unless we set the shape to be something that's not a perfect rectangle. rippleDrawable.setCornerRadius(0.00001F); Drawable rippleDrawableCompat = DrawableCompat.wrap(rippleDrawable); DrawableCompat.setTintList(rippleDrawableCompat, rippleDrawableColor); menuView.setItemBackground(rippleDrawableCompat); } } }
Example 12
Source File: PreviewSeekBar.java From PreviewSeekBar with Apache License 2.0 | 5 votes |
@Override public void setPreviewThumbTint(int color) { Drawable drawable = DrawableCompat.wrap(getThumb()); DrawableCompat.setTint(drawable, color); setThumb(drawable); scrubberColor = color; }
Example 13
Source File: ConfigActivity.java From Daedalus with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { if (Daedalus.isDarkTheme()) { setTheme(R.style.AppTheme_Dark_NoActionBar); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_config); ConfigFragment fragment; switch (getIntent().getIntExtra(LAUNCH_ACTION_FRAGMENT, LAUNCH_FRAGMENT_DNS_SERVER)) { case LAUNCH_FRAGMENT_RULE: fragment = new RuleConfigFragment(); break; case LAUNCH_FRAGMENT_DNS_SERVER: default://should never reach this fragment = new DnsServerConfigFragment(); break; } Toolbar toolbar = findViewById(R.id.toolbar_config); Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_clear); Drawable wrappedDrawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(wrappedDrawable, Color.WHITE); toolbar.setNavigationIcon(drawable); toolbar.setNavigationOnClickListener(v -> onBackPressed()); toolbar.setOnMenuItemClickListener(fragment); toolbar.inflateMenu(R.menu.custom_config); FragmentManager manager = getSupportFragmentManager(); fragment.setIntent(getIntent()); FragmentTransaction fragmentTransaction = manager.beginTransaction(); fragmentTransaction.replace(R.id.id_config, fragment); fragmentTransaction.commit(); }
Example 14
Source File: DataSharingFragment.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 5 votes |
@Override protected Drawable getBottomFabDrawable() { Drawable drawable = DrawableCompat.wrap( ContextCompat.getDrawable(getActivity(), R.drawable.ic_search)); DrawableCompat.setTint(drawable, Color.WHITE); return drawable; }
Example 15
Source File: EditText.java From Carbon with Apache License 2.0 | 5 votes |
@Override public void setCompoundDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) { super.setCompoundDrawables( left != null ? DrawableCompat.wrap(left) : null, top != null ? DrawableCompat.wrap(top) : null, right != null ? DrawableCompat.wrap(right) : null, bottom != null ? DrawableCompat.wrap(bottom) : null); updateTint(); }
Example 16
Source File: FastScroller.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
/** * Set the color for the scroll handle. * * @param color The color for the scroll handle */ public void setHandleColor(@ColorInt int color) { mHandleColor = color; if (mHandleImage == null) { Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.fastscroll_handle); if (drawable != null) { mHandleImage = DrawableCompat.wrap(drawable); } } DrawableCompat.setTint(mHandleImage, mHandleColor); mHandleView.setImageDrawable(mHandleImage); }
Example 17
Source File: SchemeSelectDialogMain.java From TwistyTimer with GNU General Public License v3.0 | 5 votes |
private void setColor(View view, int color) { Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.square); Drawable wrap = DrawableCompat.wrap(drawable); DrawableCompat.setTint(wrap, color); DrawableCompat.setTintMode(wrap, PorterDuff.Mode.MULTIPLY); wrap = wrap.mutate(); view.setBackground(wrap); }
Example 18
Source File: PreviewMorphAnimator.java From PreviewSeekBar with Apache License 2.0 | 5 votes |
private void tintViews(PreviewBar previewBar, View morphView, View frameView) { int color = previewBar.getScrubberColor(); if (morphView.getBackgroundTintList() == null || morphView.getBackgroundTintList().getDefaultColor() != color) { Drawable drawable = DrawableCompat.wrap(morphView.getBackground()); DrawableCompat.setTint(drawable, color); morphView.setBackground(drawable); frameView.setBackgroundColor(color); } }
Example 19
Source File: StoryView.java From materialistic with Apache License 2.0 | 4 votes |
public StoryView(Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.StoryView); mIsLocal = ta.getBoolean(R.styleable.StoryView_local, false); TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{ android.R.attr.textColorTertiary, android.R.attr.textColorSecondary, R.attr.colorCardBackground, R.attr.colorCardHighlight }); mTertiaryTextColorResId = ContextCompat.getColor(context, a.getResourceId(0, 0)); mSecondaryTextColorResId = ContextCompat.getColor(context, a.getResourceId(1, 0)); mBackgroundColor = ContextCompat.getColor(context, a.getResourceId(2, 0)); mHighlightColor = ContextCompat.getColor(context, a.getResourceId(3, 0)); mPromotedColorResId = ContextCompat.getColor(context, R.color.greenA700); mHotColorResId = ContextCompat.getColor(context, R.color.orange500); mAccentColorResId = ContextCompat.getColor(getContext(), AppUtils.getThemedResId(getContext(), R.attr.colorAccent)); mCommentDrawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_comment_white_24dp).mutate()); DrawableCompat.setTint(mCommentDrawable, mAccentColorResId); inflate(context, mIsLocal ? R.layout.local_story_view : R.layout.story_view, this); mBackground = findViewById(R.id.background); mBackground.setBackgroundColor(mBackgroundColor); mVoteSwitcher = (ViewSwitcher) findViewById(R.id.vote_switcher); mRankTextView = (TextView) findViewById(R.id.rank); mScoreTextView = (TextView) findViewById(R.id.score); mBookmarked = findViewById(R.id.bookmarked); mPostedTextView = (TextView) findViewById(R.id.posted); mTitleTextView = (TextView) findViewById(R.id.title); mSourceTextView = (TextView) findViewById(R.id.source); mCommentButton = (TextView) findViewById(R.id.comment); mCommentButton.setCompoundDrawablesWithIntrinsicBounds(mCommentDrawable, null, null, null); mMoreButton = findViewById(R.id.button_more); // replace with bounded ripple as unbounded ripple requires container bg // http://b.android.com/155880 mMoreButton.setBackgroundResource(AppUtils.getThemedResId(context, R.attr.selectableItemBackground)); ta.recycle(); a.recycle(); }
Example 20
Source File: AdapterAccess.java From NetGuard with GNU General Public License v3.0 | 4 votes |
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values final int version = cursor.getInt(colVersion); final int protocol = cursor.getInt(colProtocol); final String daddr = cursor.getString(colDaddr); final int dport = cursor.getInt(colDPort); long time = cursor.getLong(colTime); int allowed = cursor.getInt(colAllowed); int block = cursor.getInt(colBlock); int count = cursor.getInt(colCount); long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent); long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived); int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections); // Get views TextView tvTime = view.findViewById(R.id.tvTime); ImageView ivBlock = view.findViewById(R.id.ivBlock); final TextView tvDest = view.findViewById(R.id.tvDest); LinearLayout llTraffic = view.findViewById(R.id.llTraffic); TextView tvConnections = view.findViewById(R.id.tvConnections); TextView tvTraffic = view.findViewById(R.id.tvTraffic); // 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); } } String dest = Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : "") + (count > 1 ? " ?" + count : ""); SpannableString span = new SpannableString(dest); span.setSpan(new UnderlineSpan(), 0, dest.length(), 0); tvDest.setText(span); if (Util.isNumericAddress(daddr)) new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { ViewCompat.setHasTransientState(tvDest, true); } @Override protected String doInBackground(String... args) { try { return InetAddress.getByName(args[0]).getHostName(); } catch (UnknownHostException ignored) { return args[0]; } } @Override protected void onPostExecute(String addr) { tvDest.setText( Util.getProtocolName(protocol, version, true) + " >" + addr + (dport > 0 ? "/" + dport : "")); ViewCompat.setHasTransientState(tvDest, false); } }.execute(daddr); if (allowed < 0) tvDest.setTextColor(colorText); else if (allowed > 0) tvDest.setTextColor(colorOn); else tvDest.setTextColor(colorOff); llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE); if (connections > 0) tvConnections.setText(context.getString(R.string.msg_count, connections)); if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L) tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0), (received > 0 ? received / (1024 * 1024 * 1024f) : 0))); else if (sent > 1204 * 1024L || received > 1024 * 1024L) tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0), (received > 0 ? received / (1024 * 1024f) : 0))); else tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0), (received > 0 ? received / 1024f : 0))); }