ReColor
Introduction: An Android library that tries to do cool things with colors.
Tags:
An Android library that tries to do cool stuff with colors.

Usage
Add this to your gradle file:
implementation 'com.simmorsal.recolor:recolor:1.1.0'
methods
stable: * setViewBackgroundColor() * setCardViewColor() * setTextViewColor() * setImageButtonColorFilter() * setImageViewColorFilter() * setStatusBarColor() * setNavigationBarColor() * pulseStatusBar() * pulseNavigationBar() * stop() * getColorIntArray() * getColorHEXList() * setOnReColorFinish() experimental: * setMenuIconColor()
#
Explanations:
changes the background color of anysetViewBackgroundColor():Viewyou give it:
setViewBackground(view, startingColor, endingColor, duration);
// usage:
ReColor reColor = new ReColor(context);
reColor.setViewBackgroundColor(view, "FFFFFF", "#AA000000", 400);
// or like this:
new ReColor(context).setViewBackgroundColor(view, "#FFFFFF", "AA000000", 400);
changessetCardViewColor():CardViewcolor:
new ReColor(context).setCardViewColor(cardView, startingColor, endingColor, duration);
// usage:
new ReColor(context).setCardViewColor(cardView, "FFFFFF", "000000", 300);
changessetTextViewColor():TextViewcolor:
new ReColor(context).setTextViewColor(textView, startingColor, endingColor, duration);
// usage:
new ReColor(context).setTextViewColor(textView, "FFFFFF", "000000", 300);
changessetImageButtonColorFilter():ImageButton's color filter:
new ReColor(context).setImageButtonColorFilter(imageButton, startingColor, endingColor, duration);
// usage:
new ReColor(context).setImageButtonColorFilter(imageButton, "FFFFFF", "000000", 300);
changessetImageViewColorFilter():ImageView's color filter:
new ReColor(context).setImageViewColorFilter(imageView, startingColor, endingColor, duration);
// usage:
new ReColor(context).setImageViewColorFilter(imageView, "FFFFFF", "000000", 300);
changessetStatusBarColor():Status Barcolor. you can passnullasstartingColorso it would be automatically retrieved from status bar itself:
new ReColor(context).setStatusBarColor(startingColor, endingColor, duration);
// usage:
new ReColor(context).setStatusBarColor(null, "000000", 300);
// or:
new ReColor(context).setStatusBarColor("FFFFFF", "000000", 300);
changessetNavigationBarColor():Navigation Barcolor. like the status bar, you can passnullasstartingColorso it would be retrieved automatically:
new ReColor(context).setNavigationBarColor(startingColor, endingColor, duration);
// usage:
new ReColor(context).setNavigationBarColor(null, "000000", 300);
// or
new ReColor(context).setNavigationBarColor("FFFFFF", "000000", 300);
this method pulses the status bar color to thepulseStatusBar():pulseColor,pulseCounttimes, each pulse takingpulseSpeedmilliseconds:
new ReColor(context).pulseStatusBar(pulseColor, pulseSpeed, pulseCount);
//usage:
new ReColor(context).pulseStatusBar("FFFFFF", 100, 4);
just likepulseNavigationBar():pulseStatusBar(), but on Navigation Bar:
new ReColor(context).pulseNavigationBar(pulseColor, pulseSpeed, palseCount);
//usage:
new ReColor(context).pulseNavigationBar("FFFFFF", 150, 5);
this method stops a reColoring on any of the above methods, and also returns the last color set by that particular ReColor object, in any of the above methods:stop():
ReColor reColor = new ReColor(context);
reColor.Stop();
// usage:
// Consider a LinearLayout's background being reColored
ReColor reColor = new ReColor(context)
.setViewBackgroundColor(linearLayout, "FFFFFF", "000000", 2000);
// now you want to stop reColoring when a button is clicked
// (i also store the returned value)
@OnClick{
String lastColor = reColor.stop();
// now i want to use the returned color to start reColoring to a new color
reColor.setViewBackgroundColor(linearLayout, lastColor, "9C27B0", 500);
}
returns agetColorHEXList():List<String>of HEX color values betweenstartingColorandendingColorwith a List length oflistLength, so you can use it in your code:
new ReColor(context).getColorHEXList(startingColor, endingColor, listLength);
// usage:
List<String> colorList = new ReColor(context)
.getColorHEXList("FFFFFF", "000000", 100);
returns angetColorIntArray():int[]of color-int values betweenstartingColorandendingColorwith a List length oflistLength, so you can use it in your code:
new ReColor(context).getColorIntArray(startingColor, endingColor, listLength);
// usage:
int[] colorList = new ReColor(context)
.getColorIntArray("FFFFFF", "000000", 100);
you can implement this on a ReColor object to get notified when reColoring finishes:setOnReColorFinish():
ReColor reColor = new ReColor(context);
reColor.setViewBackgroundColor(view, "FFFFFF", "000000", 1000);
reColor.setOnReColorFinish(new OnReColorFinish() {
@Override
public void onFinish() {
Log.i(TAG, "reColoring finished");
}
});
// or
new ReColor(context)
.setViewBackgroundColor(view, "FFFFFF", "000000", 1000)
.setOnReColorFinish(new OnReColorFinish() {
@Override
public void onFinish() {
Log.i(TAG, "reColoring finished");
}
});
#
Experimental methods:
changessetMenuIconColor():MenuIconof aMenuItemcolor:
new ReColor(context).setMenuIconColor(menuItem, startingColor, endingColor, duration);
this method is experimental because while it's reColoring
a MenuIcon, the menu becomes unresponsive to touch. So the best way to use it
is to give it a duration of 200 or less. and if you're simulating pulsing, wait
a bit before the next pulse begins. this is my implementation of pulsing:
MenuItem menuItem = navigationBarMenu.getItem(0);
final String startColor = "c60055", endColor = "40c4ff";
Handler handler = new Handler().post(new Runnable() {
@Override
public void run() {
new ReColor().setMenuIconColor(menuItem, startColor, endColor, 100)
.setOnReColorFinish(new OnReColorFinish() {
@Override
public void onFinish() {
new ReColor().setMenuIconColor(menuItem, endColor, startColor, 100)
.setOnReColorFinish(new OnReColorFinish() {
@Override
public void onFinish() {
handler.postDelayed(this, 1500);
}
});
}
});
}
};
}
Important notes
ONLY reColor one widget per object of ReColor class. In other words, DO NOT create one object of ReColor class and use it to reColor multiple widgets - at least at the same time.
you can pass color values in any of the following formats:
"RRGGBB"-"AARRGGBB"-"#RRGGBB"-"#AARRGGBB"
