@Override public void setColorFilter(ColorFilter cf) { if (placeholder != null) { placeholder.setColorFilter(cf); } super.setColorFilter(cf); }
@Implementation protected void setColorFilter(ColorFilter colorFilter) { this.colorFilter = colorFilter; directlyOn(realBitmapDrawable, BitmapDrawable.class).setColorFilter(colorFilter); }
@Test public void withColorFilterSet_draw_shouldCopyDescriptionToCanvas() throws Exception { BitmapDrawable drawable = (BitmapDrawable) resources.getDrawable(R.drawable.an_image); drawable.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix())); Canvas canvas = new Canvas(); drawable.draw(canvas); assertThat(shadowOf(canvas).getDescription()).isEqualTo("Bitmap for resource:org.robolectric:drawable/an_image with ColorMatrixColorFilter<1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0>"); }
ImageView imageView = (ImageView)findViewById(R.id.imageView); final BitmapDrawable drawable = (BitmapDrawable) getResources().getDrawable(R.drawable.image); imageView.setImageDrawable(drawable); AlphaSatColorMatrixEvaluator evaluator = new AlphaSatColorMatrixEvaluator (); final ColorMatrixColorFilter filter = new ColorMatrixColorFilter(evaluator.getColorMatrix()); drawable.setColorFilter(filter); ObjectAnimator animator = ObjectAnimator.ofObject(filter, "colorMatrix", evaluator, evaluator.getColorMatrix()); animator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { drawable.setColorFilter (filter); } }); animator.setDuration(1500); animator.start();
private void setUpTextCursors() { ColorFilter cf = new PorterDuffColorFilter(mColorControlActivated, PorterDuff.Mode.SRC_IN); BitmapDrawable left = (BitmapDrawable) getResources().getDrawable(R.drawable.text_select_handle_left_material); BitmapDrawable middle = (BitmapDrawable) getResources().getDrawable(R.drawable.text_select_handle_middle_material); BitmapDrawable right = (BitmapDrawable) getResources().getDrawable(R.drawable.text_select_handle_right_material); // NinePatchDrawable cursor = (NinePatchDrawable) getResources().getDrawable(R.drawable.text_cursor_material); left.setColorFilter(cf); right.setColorFilter(cf); middle.setColorFilter(cf); // cursor.setColorFilter(cf); this does not work: cursor still white! }
super(context); BitmapDrawable tiledBackground = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.background)); tiledBackground.setTileModeX(Shader.TileMode.REPEAT); //I determined the PorterDuff.Mode value mainly through trial and error tiledBackground.setColorFilter(0xaacceeff, PorterDuff.Mode.DARKEN); this.setBackgroundDrawable(tiledBackground)
private Bitmap getDarkerBitmap(Bitmap src) { final int COLOR = 0xAAFFFFFF; final int WIDTH = src.getWidth(); final int HEIGHT = src.getHeight(); final Bitmap result = Bitmap.createBitmap(WIDTH, HEIGHT, src.getConfig()); final BitmapDrawable drawable = new BitmapDrawable(src); drawable.setBounds(0, 0, WIDTH, HEIGHT); drawable.setColorFilter(COLOR, PorterDuff.Mode.DARKEN); drawable.draw(new Canvas(result)); return result; }
Button button = new Button(getContext()); Bitmap backgroundBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_button); BitmapDrawable backgroundDrawable = new BitmapDrawable(getResources(), backgroundBitmap); backgroundDrawable.setGravity(Gravity.CENTER); // also LEFT, CENTER_VERTICAL, etc. backgroundDrawable.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP)); button.setBackground(backgroundDrawable);
/** @return the icon, scaled and blended with the icon color, as specified in the IconStyle. * Assumes the icon is already loaded. */ public BitmapDrawable getFinalIcon(Context context){ if (mIcon == null) return null; int sizeX = Math.round(mIcon.getWidth() * mScale); int sizeY = Math.round(mIcon.getHeight() * mScale); if (sizeX == 0 || sizeY == 0) { Log.w(BonusPackHelper.LOG_TAG, "KML icon has size=0"); return null; } Bitmap scaledBitmap = Bitmap.createScaledBitmap(mIcon, sizeX, sizeY, true); BitmapDrawable marker = new BitmapDrawable(context.getResources(), scaledBitmap); int color = getFinalColor(); if (color != 0) //there is a real color to blend with: marker.setColorFilter(color, Mode.MULTIPLY); return marker; }
@Implementation protected void setColorFilter(ColorFilter colorFilter) { this.colorFilter = colorFilter; directlyOn(realBitmapDrawable, BitmapDrawable.class).setColorFilter(colorFilter); }
@Implementation public void setColorFilter(ColorFilter colorFilter) { this.colorFilter = colorFilter; directlyOn(realBitmapDrawable, BitmapDrawable.class).setColorFilter(colorFilter); }
@Implementation public void setColorFilter(ColorFilter colorFilter) { this.colorFilter = colorFilter; directlyOn(realBitmapDrawable, BitmapDrawable.class).setColorFilter(colorFilter); }
@Implementation public void setColorFilter(ColorFilter colorFilter) { this.colorFilter = colorFilter; directlyOn(realBitmapDrawable, BitmapDrawable.class).setColorFilter(colorFilter); }
public void setBackground(Activity activity) { if (mImageCache.size() != 0) { BitmapDrawable bd = new BitmapDrawable(activity.getResources(), mImageCache.get(KEY_CACHE_BLURRED_BACKGROUND_IMAGE)); bd.setAlpha(mAlpha); if (mFilterColor != -1) { bd.setColorFilter(mFilterColor, PorterDuff.Mode.DST_ATOP); } activity.getWindow().setBackgroundDrawable(bd); mImageCache.remove(KEY_CACHE_BLURRED_BACKGROUND_IMAGE); cacheBlurBehindAndExecuteTask = null; } }
@TargetApi(21) private void setBackgroundImage() { Resources.Theme theme = getContext().getTheme(); TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {R.attr.contentBackgroundColor}); int remoteBackgroundColor = styledAttributes.getColor(styledAttributes.getIndex(0), getResources().getColor(R.color.dark_content_background_dim_70pct)); styledAttributes.recycle(); // On ICS the remote background isn't shown as the tinting isn't supported //int backgroundResourceId = R.drawable.remote_background_square_black_alpha; int backgroundResourceId = R.drawable.remote_background_square_black; if (Utils.isLollipopOrLater()) { setBackgroundTintList(ColorStateList.valueOf(remoteBackgroundColor)); setBackgroundResource(backgroundResourceId); } else if (Utils.isJellybeanOrLater()) { BitmapDrawable background = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), backgroundResourceId)); background.setColorFilter(new PorterDuffColorFilter(remoteBackgroundColor, PorterDuff.Mode.SRC_IN)); setBackground(background); } }
public static Drawable getImageFiltered(Context context, int res, int color) { // load image: Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), res); BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap); // create matrix to convert to greyscale: ColorMatrix greyscaleMatrix = new ColorMatrix(); greyscaleMatrix.setSaturation(0); // create matrix to colorize and apply transluceny: ColorMatrix colorizeMatrix = new ColorMatrix(); color = context.getResources().getColor(color); colorizeMatrix.setScale(Color.red(color) / 255.0f, Color.green(color) / 255.0f, Color.blue(color) / 255.0f, Color.alpha(color) / 255.0f); // <- try setting this to 1.0f for no translucency // concatenate the two matrices and create a ColorMatrixColorFilter from the result: greyscaleMatrix.postConcat(colorizeMatrix); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(greyscaleMatrix); // apply the filter: drawable.setColorFilter(filter); return drawable; }
roundPaint.setColorFilter(null); } else { bitmapDrawable.setColorFilter(null); roundPaint.setColorFilter(selectedColorFilter); } else { bitmapDrawable.setColorFilter(selectedColorFilter); roundPaint.setColorFilter(colorFilter); } else { bitmapDrawable.setColorFilter(colorFilter);