package com.alexstyl.specialdates.upcoming.widget.today;

import android.graphics.Color;
import android.support.annotation.ColorInt;

import com.alexstyl.specialdates.date.Date;

class WidgetColorCalculator {

    private static final int modifier = 15;
    private static final double max = 100.00;
    @ColorInt
    private static final int highlightColor = Color.RED;
    @ColorInt
    private final int baseColor;

    WidgetColorCalculator(int baseColor) {
        this.baseColor = baseColor;
    }

    public int getColor(Date today, Date nextEvent) {

        int dayDiff = today.daysDifferenceTo(nextEvent);
        if (dayDiff <= 3) {
            return getColorForDaysDifference(dayDiff);
        }
        return baseColor;
    }

    private int getColorForDaysDifference(int dayDiff) {
        float modifier = getModifier(dayDiff);
        return blend(baseColor, highlightColor, modifier);
    }

    private float getModifier(int dif) {
        return (float) ((max - (dif + 1) * modifier) / max);
    }

    private static int blend(@ColorInt int background, @ColorInt int foreground, float ratio) {
        if (ratio > 1f) {
            ratio = 1f;
        } else if (ratio < 0f) {
            ratio = 0f;
        }
        float iRatio = 1.0f - ratio;

        int aA = (background >> 24 & 0xff);
        int aR = ((background & 0xff0000) >> 16);
        int aG = ((background & 0xff00) >> 8);
        int aB = (background & 0xff);

        int bA = (foreground >> 24 & 0xff);
        int bR = ((foreground & 0xff0000) >> 16);
        int bG = ((foreground & 0xff00) >> 8);
        int bB = (foreground & 0xff);

        int A = (int) ((aA * iRatio) + (bA * ratio));
        int R = (int) ((aR * iRatio) + (bR * ratio));
        int G = (int) ((aG * iRatio) + (bG * ratio));
        int B = (int) ((aB * iRatio) + (bB * ratio));

        return A << 24 | R << 16 | G << 8 | B;
    }

}

@@ -232,24 +232,24 @@
 nal int 
-modifier
+MODIFIER
  = 15;%0A 
@@ -279,19 +279,19 @@
  double 
-max
+MAX
  = 100.0
@@ -340,35 +340,128 @@
 int 
-highlightColor = Color.RED;
+HIGHLIGHT_COLOR = Color.RED;%0A    private static final int DAYS_THRESHOLD = 3;%0A    private static final int ONE_DAY = 1;%0A
 %0A   
@@ -726,17 +726,30 @@
 Diff %3C= 
-3
+DAYS_THRESHOLD
 ) %7B%0A    
@@ -982,22 +982,23 @@
 or, 
-highlightColor
+HIGHLIGHT_COLOR
 , mo
@@ -1079,19 +1079,19 @@
 loat) ((
-max
+MAX
  - (dif 
@@ -1096,28 +1096,34 @@
 f + 
-1) * modifier
+ONE_DAY) * MODIFIER
 ) / 
-max
+MAX
 );%0A 
@@ -1120,32 +1120,124 @@
  / MAX);%0A    %7D%0A%0A
+    //Check:OFF%0A    // disable checkstyle checks due to the loaded of magic stuff happening%0A
     private stat
@@ -2100,12 +2100,27 @@
 B;%0A    %7D
+%0A    //Check:ON
 %0A%0A%7D%0A

Remove magic numbers and disable magic voodo inspection