Last active
January 9, 2019 12:22
-
-
Save caneryilmaz/ee27c9502d622f1bd2195d2a5ebd8138 to your computer and use it in GitHub Desktop.
Add your blink effect color to object background or textColor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.animation.ArgbEvaluator; | |
import android.animation.ObjectAnimator; | |
import android.animation.ValueAnimator; | |
import android.annotation.SuppressLint; | |
import android.content.Context; | |
public final class BlinkEffectUtils { | |
private static BlinkEffectUtils blinkEffect; | |
public enum PROPERTY_TYPE { | |
BACKGROUND_COLOR, | |
TEXT_COLOR | |
} | |
private BlinkEffectUtils() { | |
} | |
public static BlinkEffectUtils getInstance(Context context) { | |
if (blinkEffect == null) { | |
blinkEffect = new BlinkEffectUtils(); | |
} | |
return blinkEffect; | |
} | |
public void setBlinkEffect(Object targetView, PROPERTY_TYPE property_type, int duration, int defaultColor, int effectColor) { | |
String propertyName = ""; | |
switch (property_type) { | |
case TEXT_COLOR: | |
propertyName = "textColor"; | |
break; | |
case BACKGROUND_COLOR: | |
propertyName = "backgroundColor"; | |
break; | |
} | |
@SuppressLint("ObjectAnimatorBinding") | |
ObjectAnimator anim = ObjectAnimator.ofInt(targetView, propertyName, | |
effectColor, | |
defaultColor); | |
anim.setDuration(duration); | |
anim.setEvaluator(new ArgbEvaluator()); | |
anim.setRepeatMode(ValueAnimator.REVERSE); | |
anim.setRepeatCount(ValueAnimator.INFINITE); | |
anim.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment