I am using CaldroidFragment for my application. Now I am trying to set the background color of a specific date using
CaldroidFragment.setBackgroundResourceForDate(int backgroundRes,
java.util.Date date);
function. Now if I pass resource from xml, like R.color.blue as first parameter then it works, but I have to pass dynamic color value as background in runtime. I generate color dynamically within a range (something like interpolation). Now I am trying getResources().getColor() function to convert my color to resource.
private static final int COLOR_END = Color.parseColor("#BD4141");
private static final int COLOR_START = Color.parseColor("#69A864");
mCaldroidFragment.setBackgroundResourceForDate(
getResources().getColor(getInterPolateColor(2)),
new Date());
private int getInterPolateColor(int value) {
return Utility.interpolateColor(COLOR_START, COLOR_END, value / (float) 15);
}
public static int interpolateColor(final int startColor, final int endColor, final float proportion) {
final float[] hsva = new float[3];
final float[] hsvb = new float[3];
Color.colorToHSV(startColor, hsva);
Color.colorToHSV(endColor, hsvb);
for (int i = 0; i < 3; i++) {
hsvb[i] = interpolate(hsva[i], hsvb[i], proportion);
}
return Color.HSVToColor(hsvb);
}
private static float interpolate(final float a, final float b, final float proportion) {
return (a + ((b - a) * proportion));
}
But it shows following error
android.content.res.Resources$NotFoundException: Resource ID #0xff79ab60
at android.content.res.Resources.getValue(Resources.java:1123)
at android.content.res.Resources.getColor(Resources.java:805)
Now is it possible to create background resource from color value which will act like R.color.xxx, or any solution to solve my problem.