Java Code Examples for androidx.core.graphics.drawable.DrawableCompat#setTint()
The following examples show how to use
androidx.core.graphics.drawable.DrawableCompat#setTint() .
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: FilterOnTest.java From WiFiAnalyzer with GNU General Public License v3.0 | 6 votes |
@Test public void testApplyWithFilterActive() { // setup int colorResult = 100; when(filterAdapter.isActive()).thenReturn(true); when(ContextCompat.getColor(mainActivity, R.color.selected)).thenReturn(colorResult); withMenuItem(); // execute fixture.apply(mainActivity); // validate verifyMenuItem(); verifyStatic(ContextCompat.class); ContextCompat.getColor(mainActivity, R.color.selected); verifyStatic(DrawableCompat.class); DrawableCompat.setTint(drawable, colorResult); }
Example 2
Source File: AlbumTracksFragment.java From odyssey with GNU General Public License v3.0 | 6 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_album_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_album).getIcon(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, tintColor); menu.findItem(R.id.action_add_album).setIcon(drawable); super.onCreateOptionsMenu(menu, menuInflater); }
Example 3
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 4
Source File: BaseActivity.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 6 votes |
@SuppressLint("RestrictedApi") protected boolean applyMenuItemTheme(Menu menu) { if (customThemeWrapper != null) { int size = Math.min(menu.size(), 2); for (int i = 0; i < size; i++) { MenuItem item = menu.getItem(i); if (((MenuItemImpl) item).requestsActionButton()) { Drawable drawable = item.getIcon(); if (drawable != null) { DrawableCompat.setTint(drawable, customThemeWrapper.getToolbarPrimaryTextAndIconColor()); item.setIcon(drawable); } } } } return true; }
Example 5
Source File: BorderCircleView.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 6 votes |
public BorderCircleView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (isClickable()) { setForeground(ViewUtils.getSelectableBackground(context)); } mCheck = ContextCompat.getDrawable(context, R.drawable.ic_done); DrawableCompat.setTint(mCheck, Color.WHITE); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintBorder = new Paint(Paint.ANTI_ALIAS_FLAG); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BorderCircleView, defStyleAttr, 0); int primaryColor = ViewUtils.getColorPrimaryColor(getContext()); int accentColor = ViewUtils.getThemeAccentColor(getContext()); mPaint.setColor(a.getColor(R.styleable.BorderCircleView_circlecolor, accentColor)); mPaintBorder.setColor(a.getColor(R.styleable.BorderCircleView_bordercolor, primaryColor)); a.recycle(); mPaintBorder.setStrokeWidth((int) getResources().getDimension(R.dimen.circleview_border)); mPaintBorder.setStyle(Paint.Style.STROKE); setWillNotDraw(false); }
Example 6
Source File: AppFilterActivity.java From Daedalus with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { if (Daedalus.isDarkTheme()) { setTheme(R.style.AppTheme_Dark_NoActionBar); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_app_filter); Toolbar toolbar = findViewById(R.id.toolbar_filter); Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_clear); RecyclerView recyclerView = findViewById(R.id.recyclerView_app_filter_list); LinearLayoutManager manager = new LinearLayoutManager(this); recyclerView.setLayoutManager(manager); Drawable wrappedDrawable = DrawableCompat.wrap(Objects.requireNonNull(drawable)); DrawableCompat.setTint(wrappedDrawable, Color.WHITE); toolbar.setNavigationIcon(drawable); toolbar.setNavigationOnClickListener(v -> onBackPressed()); toolbar.setTitle(R.string.settings_app_filter); adapter = new RecyclerViewAdapter(); recyclerView.setAdapter(adapter); new Thread(() -> adapter.updateList(getAppList())).start(); }
Example 7
Source File: ScanShapeView.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 重置线条颜色 ( 进行着色 ) */ private void refLineColorToSquare() { if (mBitmapToSquare != null && mLineColorToSquare != 0) { try { // 转换 Drawable Drawable drawable = new BitmapDrawable(getContext().getResources(), mBitmapToSquare); Drawable tintDrawable = DrawableCompat.wrap(drawable); // 进行着色 DrawableCompat.setTint(tintDrawable, mLineColorToSquare); // 保存着色后的 Bitmap // mBitmapToSquare = ((BitmapDrawable) tintDrawable).getBitmap(); // 临时 Bitmap Bitmap bitmap; // 创建新的 Bitmap if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { bitmap = Bitmap.createBitmap(1, 1, drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); // 保存着色后的 Bitmap mBitmapToSquare = bitmap; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "refLineColorToSquare"); } } }
Example 8
Source File: ClearAutoCompleteTextView.java From Daedalus with GNU General Public License v3.0 | 5 votes |
private void init(final Context context) { final Drawable drawable = ContextCompat.getDrawable(context, R.drawable.ic_clear); final Drawable wrappedDrawable = DrawableCompat.wrap(drawable); //Wrap the drawable so that it can be tinted pre Lollipop DrawableCompat.setTint(wrappedDrawable, getCurrentHintTextColor()); mClearTextIcon = wrappedDrawable; mClearTextIcon.setBounds(0, 0, mClearTextIcon.getIntrinsicHeight(), mClearTextIcon.getIntrinsicHeight()); setClearIconVisible(false); super.setOnTouchListener(this); super.setOnFocusChangeListener(this); addTextChangedListener(this); }
Example 9
Source File: UiUtils.java From PopularMovies with MIT License | 5 votes |
public static void tintMenuIcon(Context context, MenuItem item, @ColorRes int color) { Drawable itemIcon = item.getIcon(); Drawable iconWrapper = DrawableCompat.wrap(itemIcon); DrawableCompat.setTint(iconWrapper, context.getResources().getColor(color)); item.setIcon(iconWrapper); }
Example 10
Source File: EditorActivity.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_save); DrawableCompat.setTint(drawable, Color.WHITE); menu.add(0, Menu.FIRST, Menu.FIRST, getString(R.string.save)).setIcon(drawable) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); return super.onCreateOptionsMenu(menu); }
Example 11
Source File: BrowserActivity.java From EFRConnect-android with Apache License 2.0 | 5 votes |
private void setToolbarItemsNotClicked() { logTV.setTextColor(ContextCompat.getColor(this, R.color.silabs_primary_text)); DrawableCompat.setTint(logIV.getDrawable(), ContextCompat.getColor(this, R.color.silabs_primary_text)); filterTV.setTextColor(ContextCompat.getColor(this, R.color.silabs_primary_text)); DrawableCompat.setTint(filterIV.getDrawable(), ContextCompat.getColor(this, R.color.silabs_primary_text)); connectionsTV.setTextColor(ContextCompat.getColor(this, R.color.silabs_primary_text)); DrawableCompat.setTint(connectionsIV.getDrawable(), ContextCompat.getColor(this, R.color.silabs_primary_text)); }
Example 12
Source File: ThemePreferencesManager.java From material-components-android with Apache License 2.0 | 5 votes |
@SuppressWarnings("RestrictTo") public void showChooseThemePopup(View anchor) { PopupMenu popupMenu = new PopupMenu(context, anchor); popupMenu.inflate(R.menu.mtrl_choose_theme_menu); if (popupMenu.getMenu() instanceof MenuBuilder) { MenuBuilder menuBuilder = (MenuBuilder) popupMenu.getMenu(); menuBuilder.setOptionalIconsVisible(true); ColorStateList defaultColor = AppCompatResources.getColorStateList( context, R.color.material_on_surface_emphasis_medium); int selectedColor = MaterialColors.getColor(anchor, resourceProvider.getPrimaryColor()); int currentThemeId = getCurrentThemeId(); for (int i = 0; i < menuBuilder.size(); i++) { MenuItem item = menuBuilder.getItem(i); if (item.getItemId() == currentThemeId) { DrawableCompat.setTint(item.getIcon(), selectedColor); SpannableString s = new SpannableString(item.getTitle()); s.setSpan(new ForegroundColorSpan(selectedColor), 0, s.length(), 0); item.setTitle(s); } else { DrawableCompat.setTintList(item.getIcon(), defaultColor); } } } popupMenu.setOnMenuItemClickListener( item -> { saveAndApplyTheme(item.getItemId()); return false; }); popupMenu.show(); }
Example 13
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 14
Source File: DrawableWrapper.java From EhViewer with Apache License 2.0 | 4 votes |
public void setTint(int tint) { DrawableCompat.setTint(this.mDrawable, tint); }
Example 15
Source File: CreateFragment.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 4 votes |
@Override protected Drawable getBottomFabDrawable() { Drawable drawable = ContextCompat.getDrawable(getActivity(), R.drawable.ic_done); DrawableCompat.setTint(drawable, Color.WHITE); return drawable; }
Example 16
Source File: FastScroller.java From HaoReader with GNU General Public License v3.0 | 4 votes |
private void setHandleSelected(boolean selected) { handleView.setSelected(selected); DrawableCompat.setTint(handleImage, selected ? bubbleColor : handleColor); }
Example 17
Source File: TurbolinksToolbar.java From react-native-turbolinks with MIT License | 4 votes |
private ImageSpan dropDownIcon() { ImageSpan imageSpan = new ImageSpan(getContext(), R.drawable.ic_caret); DrawableCompat.setTint(imageSpan.getDrawable(), getThemeAttrColor(getContext(), R.attr.colorControlNormal)); return imageSpan; }
Example 18
Source File: AdapterAccess.java From tracker-control-android 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))); }
Example 19
Source File: PeopleCursorAdapter.java From mage-android with Apache License 2.0 | 4 votes |
@Override public void bindView(View v, final Context context, Cursor cursor) { try { Location location = query.mapRow(new AndroidDatabaseResults(cursor, null, false)); User user = location.getUser(); if (user == null) { return; } ImageView avatarView = v.findViewById(R.id.avatarImageView); Drawable defaultPersonIcon = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_person_white_24dp)); DrawableCompat.setTint(defaultPersonIcon, ContextCompat.getColor(context, R.color.icon)); DrawableCompat.setTintMode(defaultPersonIcon, PorterDuff.Mode.SRC_ATOP); avatarView.setImageDrawable(defaultPersonIcon); GlideApp.with(context) .load(Avatar.Companion.forUser(user)) .fallback(defaultPersonIcon) .error(defaultPersonIcon) .circleCrop() .into(avatarView); final ImageView iconView = v.findViewById(R.id.iconImageView); GlideApp.with(context) .load(user.getUserLocal().getLocalIconPath()) .centerCrop() .into(iconView); TextView name = v.findViewById(R.id.name); name.setText(user.getDisplayName()); TextView date = v.findViewById(R.id.date); String timeText = new PrettyTime().format(location.getTimestamp()); date.setText(timeText); Collection<Team> userTeams = teamHelper.getTeamsByUser(user); userTeams.retainAll(eventTeams); Collection<String> teamNames = Collections2.transform(userTeams, new Function<Team, String>() { @Override public String apply(Team team) { return team.getName(); } }); TextView teamsView = v.findViewById(R.id.teams); teamsView.setText(StringUtils.join(teamNames, ", ")); } catch (SQLException sqle) { Log.e(LOG_NAME, "Could not set location view information.", sqle); } }
Example 20
Source File: ThemeUtils.java From TwistyTimer with GNU General Public License v3.0 | 3 votes |
/** * Fetches a drawable from a resource id (can be a vector drawable), * tints with {@param colorAttrRes} and returns it. * @param context {@link Context} * @param drawableRes resource id for the drawable * @param colorAttrRes attr res id for the tint * @return a tinted drawable */ public static Drawable fetchTintedDrawable(Context context, @DrawableRes int drawableRes, @AttrRes int colorAttrRes) { Drawable drawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, drawableRes)).mutate(); DrawableCompat.setTint(drawable, ThemeUtils.fetchAttrColor(context, colorAttrRes)); drawable.invalidateSelf(); return drawable; }