3

I would like to see different colors in my DateChooser / CalendarLayout for weekdays and weekend days. I would also like to achieve this using a custom stylename (for example: "weekColor" and "weekendColor".

Any idea how this can be achieved?

Cheer, Rick

2 Answers2

3

It took me a couple of days but I found it out. So for future reference: here is my solution:

I extended the DateChooser and added an override on the function updateDisplayList(w:Number, h:Number) (In this function the SMTWTFS day names have been set).

In the updateDisplayList you can get the mx_internal::dateGrid.dayBlockArrays[column][row] Containing all the values for the CalendarLayout. In that array / array the first row on each column is the one of the SMTWTFS days. The other rows are the dayNumbers. Once I found that out it is a matter of determining what a weekend day was and adjust the colors accordingly. As I show below:

override protected function updateDisplayList(w:Number, h:Number):void
    {
        super.updateDisplayList(w, h);



        // Now the dayBlocksArray has been filled. The Array looks as follows 
        // dayBlocksArray["rows"]["columns] .... therefor [i][0 (zero)] will always get the dayNames (SMTWTFS)
        // Compare the dayNames with the set this.dayNames (which always start with sunday) and find the weekend days
        var colIndex:uint = 0;
        var rowIndex:uint = 1; // The first row (SMTWTFS) is handled seperately
        var currentColumn:Array;
        var dayName:UITextField;
        var backgroundColor:uint = this.getStyle("dayNamesBackgroundColor");
        var isWeekendCol:Boolean = false;
        var currentTextFormat:TextFormat;

        // When the style is not found the default of white will be used.
        if (!backgroundColor)
        {
            backgroundColor = 0xFFFFFF;
        }

        for (colIndex; colIndex < 7; colIndex++)
        {
            // First determine if the first item in this row (SMTWTFS) is a week/weekend day
            currentColumn = mx_internal::dateGrid.dayBlocksArray[colIndex];
            dayName = currentColumn[0];

            // Determine if this is a weekend row
            // The dayNames array is fixed in the order of index 0 = sunday and index 6 = saturday. 
            // Therefor check of the text value of the current dayName is equal to either of 
            // those two. If it is we are dealing with a weekend column
            isWeekendCol = dayName.text == this.dayNames[0] || dayName.text == this.dayNames[6];

            if (isWeekendCol)
            {
                // Set the color
                currentTextFormat = dayName.getTextFormat();
                currentTextFormat.color = getStyle("weekendHeaderColor");
                dayName.setTextFormat(currentTextFormat);

                // Set the background color
                dayName.background = true;
                dayName.backgroundColor = backgroundColor;
            }
            else
            {
                currentTextFormat = dayName.getTextFormat();
                currentTextFormat.color = getStyle("weekHeaderColor");
                dayName.setTextFormat(currentTextFormat);

                // Set the background color
                dayName.background = true;
                dayName.backgroundColor = backgroundColor;
            }

            // Reset the rowIndex
            rowIndex = 1;

            // Now go through all the other rows of this column
            for (rowIndex; rowIndex < currentColumn.length; rowIndex++)
            {
                dayName = currentColumn[rowIndex];

                if (isWeekendCol)
                {
                    dayName.setColor(getStyle("weekendColor"));
                }
                else
                {
                    dayName.setColor(getStyle("weekColor"));
                }
            }
        } 
}

In the CSS file I added the following styles:

DateChooser {

cornerRadius: 0; headerColors: #FFFFFF, #FFFFFF; todayColor: #00448c; border-style:none; dropShadowEnabled: false; fontFamily: myGeorgia; dayNamesBackgroundColor: #ECECEC; weekHeaderColor:#444444; weekendHeaderColor:#DDDDDD; weekColor:#00317F; weekendColor: #DDDDDD; headerStyleName: "dateChooserHeaderStyle";
comboBoxStyleName: "comboBoxStyleName"; }

The most interesting styles here are the custom style "dayNamesBackgroundColor" (which is used to give a background color to the SMTWTFS set) and the custom styles "weekendHeaderColor", "weekHeaderColor", "weekColor", "weekendColor"

I read these colors in the method above to get full control for the difference in week/weekend colors where the SMTWTFS set could get different colors than the day number

Hope this will help other people in the future. Took me a lot of time to figure it out :)

2

I did something similar for a client. The approach is to extend the CalendarLayout class to accept those styles and modify the styling on the relevant days. Then extend the DateChooser to accept those same styles and pass them on to your new CalendarLayout class.

It's tedious; and you'll most likely run into private variable issues; but it is doable.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • It is tedious indeed .... it almost looks like Adobe doesn't want you to touch the CalendarLayout, almost everything is private in that class. At least I'm glad to hear I was on the right track. – Rick Veenstra May 06 '11 at 06:45