diff --git a/build.gradle b/build.gradle index c8ad886..eab564b 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' + classpath 'com.android.tools.build:gradle:1.0.1' } } diff --git a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedDrawable.java b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedDrawable.java index 371921a..2d359ed 100644 --- a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedDrawable.java +++ b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedDrawable.java @@ -1,5 +1,5 @@ /* -* Copyright (C) 2014 Vincent Mi +* Copyright (C) 2015 Vincent Mi * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -292,12 +292,20 @@ public int getOpacity() { return PixelFormat.TRANSLUCENT; } + @Override public int getAlpha() { + return mBitmapPaint.getAlpha(); + } + @Override public void setAlpha(int alpha) { mBitmapPaint.setAlpha(alpha); invalidateSelf(); } + @Override public ColorFilter getColorFilter() { + return mBitmapPaint.getColorFilter(); + } + @Override public void setColorFilter(ColorFilter cf) { mBitmapPaint.setColorFilter(cf); diff --git a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedImageView.java b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedImageView.java index 871c1ac..825b0b7 100644 --- a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedImageView.java +++ b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedImageView.java @@ -1,5 +1,5 @@ /* -* Copyright (C) 2014 Vincent Mi +* Copyright (C) 2015 Vincent Mi * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; +import android.graphics.ColorFilter; import android.graphics.Shader; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; @@ -62,6 +63,10 @@ public class RoundedImageView extends ImageView { private Shader.TileMode tileModeX = DEFAULT_TILE_MODE; private Shader.TileMode tileModeY = DEFAULT_TILE_MODE; + private ColorFilter mColorFilter = null; + private boolean mHasColorFilter = false; + private boolean mColorMod = false; + private int mResource; private Drawable mDrawable; private Drawable mBackgroundDrawable; @@ -262,6 +267,31 @@ private void updateBackgroundDrawableAttrs(boolean convert) { } } + @Override public void setColorFilter(ColorFilter cf) { + if (mColorFilter != cf) { + mColorFilter = cf; + mHasColorFilter = true; + mColorMod = true; + applyColorMod(); + invalidate(); + } + } + + private void applyColorMod() { + // Only mutate and apply when modifications have occurred. This should + // not reset the mColorMod flag, since these filters need to be + // re-applied if the Drawable is changed. + if (mDrawable != null && mColorMod) { + mDrawable = mDrawable.mutate(); + if (mHasColorFilter) { + mDrawable.setColorFilter(mColorFilter); + } + // TODO: support, eventually... + //mDrawable.setXfermode(mXfermode); + //mDrawable.setAlpha(mAlpha * mViewAlphaScale >> 8); + } + } + private void updateAttrs(Drawable drawable) { if (drawable == null) { return; } @@ -274,6 +304,7 @@ private void updateAttrs(Drawable drawable) { .setOval(isOval) .setTileModeX(tileModeX) .setTileModeY(tileModeY); + applyColorMod(); } else if (drawable instanceof LayerDrawable) { // loop through layers to and set drawable attrs LayerDrawable ld = ((LayerDrawable) drawable); diff --git a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedTransformationBuilder.java b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedTransformationBuilder.java index 4af2d49..7b8341e 100644 --- a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedTransformationBuilder.java +++ b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedTransformationBuilder.java @@ -1,5 +1,5 @@ /* -* Copyright (C) 2014 Vincent Mi +* Copyright (C) 2015 Vincent Mi * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.