Ejemplo n.º 1
0
        /// <summary>
        /// Draws the cell
        /// </summary>
        /// <param name="rect">Rect.</param>
        private void DrawCell(RectangleF rect)
        {
            if (mCellInfo.IsFocus)
            {
                if (mTodayHeader == null)
                {
                    mTodayHeader = DSCalendarTheme.CurrentTheme.TodayCellHeaderView;
                }

                if (mTodayHeader != null)
                {
                    //set the frame
                    mTodayHeader.Frame = new RectangleF(0, 0, this.Frame.Width, 20).Integral();

                    if (mTodayHeader.Superview == null)
                    {
                        this.InsertSubviewBelow(mTodayHeader, mRightLabel);
                    }
                }
            }


            var context = UIGraphics.GetCurrentContext();

            UIColor fillColor = UIColor.White;

            var selectedColor = DSCalendarTheme.CurrentTheme.CellSelectedBackground;

            if (!IsSelected || selectedColor == null)
            {
                if (mCellInfo.IsFocus)
                {
                    fillColor = DSCalendarTheme.CurrentTheme.TodayCellBackground;
                }
                else if (IsWeekend)
                {
                    fillColor = (mCellInfo.IsCurrent) ? DSCalendarTheme.CurrentTheme.WeekendCellBackground : DSCalendarTheme.CurrentTheme.InActiveWeekendCellBackground;
                }
                else if (!mCellInfo.IsCurrent)
                {
                    fillColor = DSCalendarTheme.CurrentTheme.InActiveCellBackgrond;
                }
                else
                {
                    fillColor = DSCalendarTheme.CurrentTheme.CellBackground;
                }
            }
            else
            {
                fillColor = selectedColor;
            }

            fillColor.SetFill();
            context.FillRect(rect);

            context.SetStrokeColor(DSCalendarTheme.CurrentTheme.CellBorderColor.CGColor);
            context.SetLineWidth(DSCalendarTheme.CurrentTheme.GridBorderWidth);
            context.StrokeRect(rect);

            mRightLabel.Text = String.Empty;
            //mRightLabel.BackgroundColor = UIColor.Red;
            //
            if (mCellInfo.IsFirstRow && DSCalendarTheme.CurrentTheme.DayStyle == CalendarDayStyle.FirstRow)
            {
                //get the day string for this row
                var aDay = EnumHelper.ConvertToWeekDay(mCellInfo.Date.DayOfWeek);

                var aString = DSCalendarLanguage.CurrentLanguage.ShortStringForDay((int)aDay) + " ";

                mRightLabel.Text += aString;
            }
            mRightLabel.Text += mCellInfo.Date.Day.ToString();

            if (mCellInfo.ShowMonth)
            {
                mRightLabel.Text += " " + DSCalendarEnglish.CurrentLanguage.ShortStringForMonth(mCellInfo.Date.Month - 1);
            }

            if (!IsSelected || selectedColor == null)
            {
                mRightLabel.TextColor = (mCellInfo.IsFocus) ? DSCalendarTheme.CurrentTheme.TodayCellTextColor
                                : (mCellInfo.IsCurrent) ? DSCalendarTheme.CurrentTheme.CellTextColor : DSCalendarTheme.CurrentTheme.InActiveCellTextColor;
            }
            else
            {
                mRightLabel.TextColor = DSCalendarTheme.CurrentTheme.CellSelectedTextColor;
            }

            float aPos   = 0;
            float yPos   = 0;
            float offSet = 4;

            var fSize = this.StringSize(mRightLabel.Text, mRightLabel.Font, new SizeF(this.Frame.Width, 20));

            var fHeight = fSize.Height;

            //is weekend
            switch (DSCalendarTheme.CurrentTheme.DayLocation)
            {
            case CalendarDayLocation.TopRight:
            {
                aPos = offSet;
                yPos = offSet;
                mRightLabel.TextAlignment = UITextAlignment.Right;
            }
            break;

            case CalendarDayLocation.BottomRight:
            {
                aPos = offSet;
                yPos = this.Frame.Height - (fHeight + offSet);
                mRightLabel.TextAlignment = UITextAlignment.Right;
            }
            break;

            case CalendarDayLocation.TopLeft:
            {
                aPos = offSet;                        //mLeftLabel.Frame.Left + mLeftLabel.Frame.Width;
                yPos = offSet;
                mRightLabel.TextAlignment = UITextAlignment.Left;
            }
            break;

            case CalendarDayLocation.BottomLeft:
            {
                aPos = offSet;                        //mLeftLabel.Frame.Left + mLeftLabel.Frame.Width;
                yPos = this.Frame.Height - (fHeight + offSet);
                mRightLabel.TextAlignment = UITextAlignment.Left;
            }
            break;
            }


            mRightLabel.Frame = new RectangleF(aPos, yPos, fSize.Width, fHeight).Integral();

            RectangleF eventFrame;            // = null;

            if (yPos == offSet)
            {
                float top = ((mRightLabel.Frame.Top + mRightLabel.Frame.Height) + offSet) + 4;
                eventFrame = new RectangleF(0, top, this.Frame.Width, this.Frame.Height - (top + 2));
            }
            else
            {
                eventFrame = new RectangleF(0, offSet, this.Frame.Width, this.Frame.Height - (mRightLabel.Frame.Height + offSet));
            }

            mEventView.CellDate = mCellInfo.Date;
            mEventView.Events   = mEvents;
            mEventView.Frame    = eventFrame.Integral();

            if (DSCalendarTheme.CurrentTheme.MoreViewPosition == DSMoreEventsViewPositon.TopRight && MoreItems != 0)
            {
                if (mMoreEventsView != null)
                {
                    var width = (this.Frame.Width - mRightLabel.Frame.Left) - 4;

                    mMoreEventsView.IsToday        = mCellInfo.IsFocus;
                    mMoreEventsView.RemainingItems = MoreItems;
                    mMoreEventsView.Frame          = new RectangleF(mRightLabel.Frame.Left, 0, width, DSCalendarTheme.CurrentTheme.MoreEventsViewHeight).Integral();
                }
            }
        }