Incorporating theme colors into task views.

Change-Id: Ie7166d78dacabe4bff7afdade2d1da9d0651e403
diff --git a/packages/SystemUI/src/com/android/systemui/recents/Utilities.java b/packages/SystemUI/src/com/android/systemui/recents/Utilities.java
index 4a1b3b2..b602f84 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/Utilities.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/Utilities.java
@@ -16,6 +16,7 @@
 
 package com.android.systemui.recents;
 
+import android.graphics.Color;
 import android.graphics.Rect;
 
 /* Common code */
@@ -46,4 +47,19 @@
             r.offset(cx, cy);
         }
     }
+
+    /** Calculates the luminance-preserved greyscale of a given color. */
+    private static int colorToGreyscale(int color) {
+        return Math.round(0.2126f * Color.red(color) + 0.7152f * Color.green(color) +
+                0.0722f * Color.blue(color));
+    }
+
+    /** Returns the ideal text color to draw on top of a specified background color. */
+    public static int getIdealTextColorForBackgroundColor(int color) {
+        RecentsConfiguration configuration = RecentsConfiguration.getInstance();
+        int greyscale = colorToGreyscale(color);
+        return (greyscale < 128) ? configuration.taskBarViewLightTextColor :
+                configuration.taskBarViewDarkTextColor;
+
+    }
 }