1

How do I find the text color for an event, when querying through CalendarContract? I see there's a column DISPLAY_COLOR, which appears to reliably provide the background color. I do not see any column for the text color anywhere in the plethora of CalendarContract tables.

Judging by the palette choices in the stock calendar, white text should work for all. However, it seems wrong to hard code "white".

Any better ideas?

Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
  • Have you tried with CalendarContract.Colors Class? It seems like there is a field TYPE_EVENT: This indicates a color that can be used for events. – AADProgramming Jan 12 '15 at 15:55

2 Answers2

1

I don't think there is a way to set and recall the text color. What I ended up doing, which seems to work well, is to use a luminance algorithm. The one I used is very simple:

  // from CalendarContract.Instances.CONTENT_URI;
  int backgroundColor = cursor.getInt (getColumnIndexInstances.DISPLAY_COLOR));
  int b = backgroundColor & 0xFF;
  int g = (backgroundColor >> 8) & 0xFF;
  int r = (backgroundColor >> 16) & 0xFF;
  int a = (backgroundColor >> 24) & 0xFF;
  int y = (3*r + 6*g + 2*b) / 11;
  int textColor = (y < 128) ? Color.WHITE : Color.BLACK;
Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
0

Ideally, the displayed color for the CalenderContract is white by default. If you want to adjust the column color you will need to hard code it within the query. You can google the html/css color code to help decide what color you want to use.

Houston909
  • 11
  • 3