List of usage examples for android.graphics.drawable Drawable setColorFilter
public abstract void setColorFilter(@Nullable ColorFilter colorFilter);
From source file:co.ceryle.segmentedbutton.SegmentedButton.java
/** * If button has any drawable, it sets drawable's tint color without changing drawable's position. * * @param color is used to set drawable's tint color *//*from w w w . jav a 2 s.c o m*/ public void setDrawableTint(int color) { int pos = 0; Drawable drawable = null; if (getCompoundDrawables().length > 0) { for (int i = 0; i < getCompoundDrawables().length; i++) { if (getCompoundDrawables()[i] != null) { pos = i; drawable = getCompoundDrawables()[i]; } } if (drawable != null) drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)); setDrawable(drawable, pos); } }
From source file:loader.ImageWorker.java
private Drawable setBlackAndWhite(Drawable bitmap) { float[] colorMatrix = { 0.33f, 0.33f, 0.33f, 0, 0, // red 0.33f, 0.33f, 0.33f, 0, 0, // green 0.33f, 0.33f, 0.33f, 0, 0, // blue 0, 0, 0, 1, 0 // alpha };//from w w w. java 2s. co m ColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix); bitmap.setColorFilter(colorFilter); return bitmap; }
From source file:com.waz.zclient.pages.main.profile.preferences.dialogs.AddPhoneNumberPreferenceDialogFragment.java
private void updateEditTextBackground(EditText editText) { ensureBackgroundDrawableStateWorkaround(editText); Drawable editTextBackground = editText.getBackground(); if (editTextBackground == null) { return;/* w w w . j a va2 s . c o m*/ } if (android.support.v7.widget.DrawableUtils.canSafelyMutateDrawable(editTextBackground)) { editTextBackground = editTextBackground.mutate(); } if (errorView != null && errorView.getVisibility() == View.VISIBLE) { // Set a color filter of the error color editTextBackground.setColorFilter(AppCompatDrawableManager .getPorterDuffColorFilter(errorView.getCurrentTextColor(), PorterDuff.Mode.SRC_IN)); } else { // Else reset the color filter and refresh the drawable state so that the // normal tint is used clearColorFilter(editTextBackground); editText.refreshDrawableState(); } }
From source file:com.waz.zclient.ui.audiomessage.AudioMessageRecordingView.java
public void setAccentColor(int color) { Drawable drawable = recordingSeekBar.getProgressDrawable(); if (drawable == null) { return;/*from ww w . j a v a 2 s . co m*/ } if (drawable instanceof LayerDrawable) { LayerDrawable layerDrawable = (LayerDrawable) drawable; Drawable progress = layerDrawable.findDrawableByLayerId(android.R.id.progress); if (progress != null) { drawable = progress; } } drawable.setColorFilter(new LightingColorFilter(0xFF000000, color)); drawable = recordingSeekBar.getThumb(); drawable.setColorFilter(new LightingColorFilter(0xFF000000, color)); }
From source file:org.mozilla.gecko.AwesomeBarTabs.java
private TabSpec addAwesomeTab(String id, int titleId, int contentId) { TabSpec tab = newTabSpec(id);//from w w w . j a v a2 s .c o m LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View indicatorView = inflater.inflate(R.layout.awesomebar_tab_indicator, null); Drawable background = indicatorView.getBackground(); try { background.setColorFilter( new LightingColorFilter(Color.WHITE, GeckoApp.mBrowserToolbar.getHighlightColor())); } catch (Exception e) { Log.d(LOGTAG, "background.setColorFilter failed " + e); } TextView title = (TextView) indicatorView.findViewById(R.id.title); title.setText(titleId); tab.setIndicator(indicatorView); tab.setContent(contentId); addTab(tab); return tab; }
From source file:android.support.v7ox.widget.AppCompatDrawableManager.java
private static boolean tintDrawableUsingColorFilter(@NonNull Context context, @DrawableRes final int resId, @NonNull Drawable drawable) { PorterDuff.Mode tintMode = DEFAULT_MODE; boolean colorAttrSet = false; int colorAttr = 0; int alpha = -1; if (arrayContains(COLORFILTER_TINT_COLOR_CONTROL_NORMAL, resId)) { colorAttr = R.attr.colorControlNormal_ox; colorAttrSet = true;/*ww w . j a va 2s . co m*/ } else if (arrayContains(COLORFILTER_COLOR_CONTROL_ACTIVATED, resId)) { colorAttr = R.attr.colorControlActivated_ox; colorAttrSet = true; } else if (arrayContains(COLORFILTER_COLOR_BACKGROUND_MULTIPLY, resId)) { colorAttr = android.R.attr.colorBackground; colorAttrSet = true; tintMode = PorterDuff.Mode.MULTIPLY; } else { colorAttr = android.R.attr.colorForeground; colorAttrSet = true; alpha = Math.round(0.16f * 255); } if (colorAttrSet) { if (DrawableUtils.canSafelyMutateDrawable(drawable)) { drawable = drawable.mutate(); } final int color = ThemeUtils.getThemeAttrColor(context, colorAttr); drawable.setColorFilter(getPorterDuffColorFilter(color, tintMode)); if (alpha != -1) { drawable.setAlpha(alpha); } if (DEBUG) { Log.d(TAG, "[tintDrawableUsingColorFilter] Tinted " + context.getResources().getResourceName(resId) + " with color: #" + Integer.toHexString(color)); } return true; } return false; }
From source file:com.koushikdutta.superuser.FragmentMain.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); context = getActivity();// ww w. j a va 2 s . c o m pref = PreferenceManager.getDefaultSharedPreferences(context); callback = (MainCallback) getActivity(); LocalBroadcastManager.getInstance(context).registerReceiver(receiver, new IntentFilter(Common.INTENT_FILTER_MAIN)); gridMode = pref.getBoolean("grid_mode", true); coordinatorLayout = (CoordinatorLayout) getActivity().findViewById(R.id.main_content); //tabLayout = (TabLayout) getActivity().findViewById(R.id.tabs); //viewPager = (ViewPager) getActivity().findViewById(R.id.container); int span = 0; if (gridMode) { layoutManager = new RecyclerViewSwipeable.LayoutManagerSwipeable(context, 1); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { span = pref.getInt("grid_size_port", 3); layoutManager.setSpanCount(span); } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { span = pref.getInt("grid_size_land", 4); layoutManager.setSpanCount(span); } Drawable divider = ContextCompat.getDrawable(context, R.drawable.divider_grid); divider.setColorFilter(new PorterDuffColorFilter(ATHUtil.resolveColor(context, R.attr.dividerGrid), PorterDuff.Mode.SRC_ATOP)); recycler.setLayoutManager(layoutManager); recycler.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(context, R.anim.grid_layout_animation)); recycler.addItemDecoration(new GridDividerItemDecoration(divider, divider, span)); recycler.addItemDecoration(new GridTopOffsetItemDecoration(Util.toPx(context, 5), span)); } else { recycler.setLayoutManager(new LinearLayoutManager(context)); recycler.addItemDecoration(new StartOffsetItemDecoration(Util.toPx(context, 10))); } //recycler.setListener(clickListener); //recycler.setViewPager(viewPager); //recycler.setFragment(this); setData(); }
From source file:eu.long1.spacetablayout.SpaceTabLayout.java
public void setTabColor(@ColorInt int backgroundColor) { PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(backgroundColor, PorterDuff.Mode.SRC_ATOP);/* w ww .j av a2s .com*/ Drawable image = ContextCompat.getDrawable(getContext(), R.drawable.background); Drawable image2 = ContextCompat.getDrawable(getContext(), R.drawable.background2); image.setColorFilter(porterDuffColorFilter); image2.setColorFilter(porterDuffColorFilter); backgroundImage.setImageDrawable(image); backgroundImage2.setImageDrawable(image2); }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
static boolean tintDrawableUsingColorFilter(@NonNull Context context, @DrawableRes final int resId, @NonNull Drawable drawable) { PorterDuff.Mode tintMode = DEFAULT_MODE; boolean colorAttrSet = false; int colorAttr = 0; int alpha = -1; if (arrayContains(COLORFILTER_TINT_COLOR_CONTROL_NORMAL, resId)) { colorAttr = R.attr.colorControlNormal; colorAttrSet = true;//from w w w.j a va 2 s.com } else if (arrayContains(COLORFILTER_COLOR_CONTROL_ACTIVATED, resId)) { colorAttr = R.attr.colorControlActivated; colorAttrSet = true; } else if (arrayContains(COLORFILTER_COLOR_BACKGROUND_MULTIPLY, resId)) { colorAttr = android.R.attr.colorBackground; colorAttrSet = true; tintMode = PorterDuff.Mode.MULTIPLY; } else if (resId == R.drawable.abc_list_divider_mtrl_alpha) { colorAttr = android.R.attr.colorForeground; colorAttrSet = true; alpha = Math.round(0.16f * 255); } else if (resId == R.drawable.abc_dialog_material_background) { colorAttr = android.R.attr.colorBackground; colorAttrSet = true; } if (colorAttrSet) { if (DrawableUtils.canSafelyMutateDrawable(drawable)) { drawable = drawable.mutate(); } final int color = getThemeAttrColor(context, colorAttr); drawable.setColorFilter(getPorterDuffColorFilter(color, tintMode)); if (alpha != -1) { drawable.setAlpha(alpha); } if (DEBUG) { Log.d(TAG, "[tintDrawableUsingColorFilter] Tinted " + context.getResources().getResourceName(resId) + " with color: #" + Integer.toHexString(color)); } return true; } return false; }
From source file:org.appcelerator.titanium.util.TiUIHelper.java
public static void setDrawableOpacity(final Drawable drawable, final float opacity) { if (drawable instanceof ColorDrawable || drawable instanceof TiBackgroundDrawable) { drawable.setAlpha(Math.round(opacity * 255)); } else if (drawable != null) { drawable.setColorFilter(createColorFilterForOpacity(opacity)); }// w w w . j ava 2 s. c om }