An Android library that tries to do cool stuff with colors.
Add this to your gradle file:
implementation 'com.simmorsal.recolor:recolor:1.0.1'
stable: * setViewBackgroundColor() * setCardViewColor() * setTextViewColor() * setImageButtonColorFilter() * setImageViewColorFilter() * setStatusBarColor() * setNavigationBarColor() * pulseStatusBar() * pulseNavigationBar() * stop() * getColorList() * setOnReColorFinish() experimental: * setMenuIconColor()
setViewBackgroundColor()
: changes the background color of anyView
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);
setCardViewColor()
: changesCardView
color:
new ReColor(context).setCardViewColor(cardView, startingColor, endingColor, duration);
// usage:
new ReColor(context).setCardViewColor(cardView, "FFFFFF", "000000", 300);
setTextViewColor()
: changesTextView
color:
new ReColor(context).setTextViewColor(textView, startingColor, endingColor, duration);
// usage:
new ReColor(context).setTextViewColor(textView, "FFFFFF", "000000", 300);
setImageButtonColorFilter()
: changesImageButton
's color filter:
new ReColor(context).setImageButtonColorFilter(imageButton, startingColor, endingColor, duration);
// usage:
new ReColor(context).setImageButtonColorFilter(imageButton, "FFFFFF", "000000", 300);
setImageViewColorFilter()
: changesImageView
's color filter:
new ReColor(context).setImageViewColorFilter(imageView, startingColor, endingColor, duration);
// usage:
new ReColor(context).setImageViewColorFilter(imageView, "FFFFFF", "000000", 300);
setStatusBarColor()
: changesStatus Bar
color. you can passnull
asstartingColor
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);
setNavigationBarColor()
: changesNavigation Bar
color. like the status bar, you can passnull
asstartingColor
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);
pulseStatusBar()
: this method pulses the status bar color to thepulseColor
,pulseCount
times, each pulse takingpulseSpeed
milliseconds:
new ReColor(context).pulseStatusBar(pulseColor, pulseSpeed, pulseCount);
//usage:
new ReColor(context).pulseStatusBar("FFFFFF", 100, 4);
pulseNavigationBar()
: just likepulseStatusBar()
, but on Navigation Bar:
new ReColor(context).pulseNavigationBar(pulseColor, pulseSpeed, palseCount);
//usage:
new ReColor(context).pulseNavigationBar("FFFFFF", 150, 5);
stop()
: 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);
}
getColorList()
: returns aList<String>
of colors betweenstartingColor
andendingColor
with a List length oflistLength
, so you can use it in your code:
new ReColor(context).getColorList(startingColor, endingColor, listLength);
// usage:
List<String> colorList = new ReColor(context)
.getColorList("FFFFFF", "000000", 100);
setOnReColorFinish()
: 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");
}
});
setMenuIconColor()
: changesMenuIcon
of aMenuItem
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"
My bitcoin address: 15NkTxJMdZinU2rUnENfjt62uHtxXCcpEU
Copyright 2018 Soheil Mohammad Hoseini
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.