An Android library that tries to do cool stuff with colors.
Add this to your gradle file:
implementation 'com.simmorsal.recolor:recolor:1.1.0'
stable: * setViewBackgroundColor() * setCardViewColor() * setTextViewColor() * setImageButtonColorFilter() * setImageViewColorFilter() * setStatusBarColor() * setNavigationBarColor() * pulseStatusBar() * pulseNavigationBar() * stop() * getColorIntArray() * getColorHEXList() * setOnReColorFinish() experimental: * setMenuIconColor()
changes the background color of any View
you 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);
changes CardView
color:
new ReColor(context).setCardViewColor(cardView, startingColor, endingColor, duration);
// usage:
new ReColor(context).setCardViewColor(cardView, "FFFFFF", "000000", 300);
changes TextView
color:
new ReColor(context).setTextViewColor(textView, startingColor, endingColor, duration);
// usage:
new ReColor(context).setTextViewColor(textView, "FFFFFF", "000000", 300);
changes ImageButton
's color filter:
new ReColor(context).setImageButtonColorFilter(imageButton, startingColor, endingColor, duration);
// usage:
new ReColor(context).setImageButtonColorFilter(imageButton, "FFFFFF", "000000", 300);
changes ImageView
's color filter:
new ReColor(context).setImageViewColorFilter(imageView, startingColor, endingColor, duration);
// usage:
new ReColor(context).setImageViewColorFilter(imageView, "FFFFFF", "000000", 300);
changes Status Bar
color. you can pass null
as
startingColor
so 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);
changes Navigation Bar
color. like the status bar,
you can pass null
as startingColor
so 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 the pulseColor
,
pulseCount
times, each pulse taking pulseSpeed
milliseconds:
new ReColor(context).pulseStatusBar(pulseColor, pulseSpeed, pulseCount);
//usage:
new ReColor(context).pulseStatusBar("FFFFFF", 100, 4);
just like 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:
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 a List<String>
of HEX color values between startingColor
and endingColor
with a List length of listLength
, 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 an int[]
of color-int values between startingColor
and endingColor
with a List length of listLength
, 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:
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");
}
});
changes MenuIcon
of a MenuItem
color:
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);
}
});
}
});
}
};
}
-
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"