/// <summary>
        /// Gets the month cells.
        /// </summary>
        /// <param name="month">The month.</param>
        /// <param name="startCal">The start cal.</param>
        /// <returns>List&lt;List&lt;MonthCellDescriptor&gt;&gt;.</returns>
        internal List <List <MonthCellDescriptor> > GetMonthCells(MonthDescriptor month, DateTime startCal)
        {
            var cells          = new List <List <MonthCellDescriptor> >();
            var cal            = new DateTime(startCal.Year, startCal.Month, 1);
            var firstDayOfWeek = (int)cal.DayOfWeek;

            cal = cal.AddDays((int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - firstDayOfWeek);

            var minSelectedCal = GetMinDate(SelectedCals);
            var maxSelectedCal = GetMaxDate(SelectedCals);

            var numWeeks = 0;

            while (((cal.Month < month.Month + 1 || cal.Year < month.Year) &&
                    cal.Year <= month.Year) || numWeeks < 5)
            {
                Logr.D("Building week row starting at {0}", cal);
                var weekCells = new List <MonthCellDescriptor>();
                cells.Add(weekCells);
                for (int i = 0; i < 7; i++)
                {
                    var  date                  = cal;
                    bool isCurrentMonth        = cal.Month == month.Month;
                    bool isSelected            = isCurrentMonth && ContatinsDate(SelectedCals, cal);
                    bool isSelectable          = isCurrentMonth && IsBetweenDates(cal, MinDate, MaxDate);
                    bool isToday               = IsSameDate(cal, Today);
                    bool isHighlighted         = ContatinsDate(_highlightedCals, cal) || _hlighlightedDaysOfWeek[(int)cal.DayOfWeek];
                    int  value                 = cal.Day;
                    bool isSelectedDatesMarked = false;
                    if (SelectedDatesItems != null)
                    {
                        isSelectedDatesMarked = SelectedDatesItems.Any(x => x.Equals(date));
                    }

                    var rangeState = RangeState.None;
                    if (SelectedCals.Count > 1)
                    {
                        if (IsSameDate(minSelectedCal, cal))
                        {
                            rangeState = RangeState.First;
                        }
                        else if (IsSameDate(maxSelectedCal, cal))
                        {
                            rangeState = RangeState.Last;
                        }
                        else if (IsBetweenDates(cal, minSelectedCal, maxSelectedCal))
                        {
                            rangeState = RangeState.Middle;
                        }
                    }

                    weekCells.Add(new MonthCellDescriptor(date, isCurrentMonth, isSelectable, isSelected,
                                                          isToday, isHighlighted, value, rangeState, _styleDescriptor, isSelectedDatesMarked));
                    cal = cal.AddDays(1);
                }
                numWeeks++;
            }
            return(cells);
        }
示例#2
0
        /// <summary>
        /// Initializes the specified minimum date.
        /// </summary>
        /// <param name="minDate">The minimum date.</param>
        /// <param name="maxDate">The maximum date.</param>
        /// <param name="highlightedDaysOfWeek">The highlighted days of week.</param>
        /// <returns>FluentInitializer.</returns>
        /// <exception cref="Java.Lang.IllegalArgumentException">
        /// minDate and maxDate must be non-zero.  +
        ///                 Debug(minDate, maxDate)
        /// or
        /// minDate must be before maxDate.  +
        ///                 Debug(minDate, maxDate)
        /// </exception>
        public FluentInitializer Init(DateTime minDate, DateTime maxDate, DayOfWeek[] highlightedDaysOfWeek)
        {
            if (minDate == DateTime.MinValue || maxDate == DateTime.MinValue)
            {
                throw new IllegalArgumentException("minDate and maxDate must be non-zero. " +
                                                   Debug(minDate, maxDate));
            }
            if (minDate.CompareTo(maxDate) > 0)
            {
                throw new IllegalArgumentException("minDate must be before maxDate. " +
                                                   Debug(minDate, maxDate));
            }

            HighlighDaysOfWeeks(highlightedDaysOfWeek);

            Mode = SelectionMode.Single;
            //Clear out any previously selected dates/cells.
            SelectedCals.Clear();
            SelectedCells.Clear();
            _highlightedCals.Clear();
            _highlightedCells.Clear();

            //Clear previous state.
            Cells.Clear();
            Months.Clear();
            MinDate = minDate;
            MaxDate = maxDate;
            MinDate = SetMidnight(MinDate);
            MaxDate = SetMidnight(MaxDate);

            // maxDate is exclusive: bump back to the previous day so if maxDate is the first of a month,
            // We don't accidentally include that month in the view.
            if (MaxDate.Day == 1)
            {
                MaxDate = MaxDate.AddMinutes(-1);
            }

            //Now iterate between minCal and maxCal and build up our list of months to show.
            _monthCounter = MinDate;
            int maxMonth = MaxDate.Month;
            int maxYear  = MaxDate.Year;

            while ((_monthCounter.Month <= maxMonth ||
                    _monthCounter.Year < maxYear) &&
                   _monthCounter.Year < maxYear + 1)
            {
                var month = new MonthDescriptor(_monthCounter.Month, _monthCounter.Year, _monthCounter,
                                                _monthCounter.ToString(MonthNameFormat), _styleDescriptor);
                Cells.Add(GetMonthCells(month, _monthCounter));
                Logr.D("Adding month {0}", month);
                Months.Add(month);
                _monthCounter = _monthCounter.AddMonths(1);
            }

            ValidateAndUpdate();
            return(new FluentInitializer(this));
        }
示例#3
0
        /// <summary>
        /// Initializes the specified month.
        /// </summary>
        /// <param name="month">The month.</param>
        /// <param name="cells">The cells.</param>
        public void Init(MonthDescriptor month, List <List <MonthCellDescriptor> > cells)
        {
            Logr.D("Initializing MonthView ({0:d}) for {1}", GetHashCode(), month);
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            _title.Text = month.Label;
            if (_title.Typeface != null)
            {
                _title.Typeface = month.Style.MonthTitleFont;
            }
            _title.SetTextColor(month.Style.TitleForegroundColor);
            _title.SetBackgroundColor(month.Style.TitleBackgroundColor);

            _grid.DividerColor = month.Style.DateSeparatorColor;

            var headerRow = (CalendarRowView)_grid.GetChildAt(0);

            if (headerRow != null)
            {
                headerRow.SetBackgroundColor(month.Style.DayOfWeekLabelBackgroundColor);
                var week = cells[0];
                for (int c = 0; c <= 6; c++)
                {
                    var headerText = (TextView)headerRow.GetChildAt(c);
                    if (month.Style.ShouldHighlightDaysOfWeekLabel && week[c].IsHighlighted)
                    {
                        headerText.SetBackgroundColor(month.Style.HighlightedDateBackgroundColor);
                    }
                    headerText.SetTextColor(month.Style.DayOfWeekLabelForegroundColor);
                }
            }

            int numOfRows = cells.Count;

            _grid.NumRows = numOfRows;
            for (int i = 0; i < 6; i++)
            {
                var weekRow = (CalendarRowView)_grid.GetChildAt(i + 1);
                weekRow.ClickHandler = _clickHandler;
                if (i < numOfRows)
                {
                    weekRow.Visibility = ViewStates.Visible;
                    var week = cells[i];
                    for (int c = 0; c < week.Count; c++)
                    {
                        var cell     = week[c];
                        var cellView = (CalendarCellView)weekRow.GetChildAt(c);

                        cellView.Text           = cell.Value.ToString();
                        cellView.Enabled        = cell.IsCurrentMonth;
                        cellView.Selectable     = cell.IsSelectable;
                        cellView.Selected       = cell.IsSelected;
                        cellView.IsCurrentMonth = cell.IsCurrentMonth;
                        cellView.IsToday        = cell.IsToday;
                        cellView.IsHighlighted  = cell.IsHighlighted;
                        cellView.RangeState     = cell.RangeState;
                        cellView.Tag            = cell;
                        cellView.SetStyle(month.Style);
                        //Logr.D("Setting cell at {0} ms", stopWatch.ElapsedMilliseconds);
                    }
                }
                else
                {
                    weekRow.Visibility = ViewStates.Gone;
                }
            }
            stopWatch.Stop();
            Logr.D("MonthView.Init took {0} ms", stopWatch.ElapsedMilliseconds);
        }
示例#4
0
 /// <summary>
 /// Determines whether [is same month] [the specified cal].
 /// </summary>
 /// <param name="cal">The cal.</param>
 /// <param name="month">The month.</param>
 /// <returns><c>true</c> if [is same month] [the specified cal]; otherwise, <c>false</c>.</returns>
 internal static bool IsSameMonth(DateTime cal, MonthDescriptor month)
 {
     return(cal.Month == month.Month && cal.Year == month.Year);
 }
		/// <summary>
		/// Determines whether [is same month] [the specified cal].
		/// </summary>
		/// <param name="cal">The cal.</param>
		/// <param name="month">The month.</param>
		/// <returns><c>true</c> if [is same month] [the specified cal]; otherwise, <c>false</c>.</returns>
		internal static bool IsSameMonth(DateTime cal, MonthDescriptor month)
		{
			return (cal.Month == month.Month && cal.Year == month.Year);
		}
		/// <summary>
		/// Gets the month cells.
		/// </summary>
		/// <param name="month">The month.</param>
		/// <param name="startCal">The start cal.</param>
		/// <returns>List&lt;List&lt;MonthCellDescriptor&gt;&gt;.</returns>
		internal List<List<MonthCellDescriptor>> GetMonthCells(MonthDescriptor month, DateTime startCal)
		{
			var cells = new List<List<MonthCellDescriptor>>();
			var cal = new DateTime(startCal.Year, startCal.Month, 1);
			var firstDayOfWeek = (int)cal.DayOfWeek;
			cal = cal.AddDays((int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - firstDayOfWeek);

			var minSelectedCal = GetMinDate(SelectedCals);
			var maxSelectedCal = GetMaxDate(SelectedCals);

			while((cal.Month < month.Month + 1 || cal.Year < month.Year)
				   && cal.Year <= month.Year) {
				Logr.D("Building week row starting at {0}", cal);
				var weekCells = new List<MonthCellDescriptor>();
				cells.Add(weekCells);
				for(int i = 0; i < 7; i++) {
					var date = cal;
					bool isCurrentMonth = cal.Month == month.Month;
					bool isSelected = isCurrentMonth && ContatinsDate(SelectedCals, cal);
					bool isSelectable = isCurrentMonth && IsBetweenDates(cal, MinDate, MaxDate);
					bool isToday = IsSameDate(cal, Today);
					bool isHighlighted = ContatinsDate(_highlightedCals, cal) || _hlighlightedDaysOfWeek[(int)cal.DayOfWeek];
					int value = cal.Day;

					var rangeState = RangeState.None;
					if(SelectedCals.Count > 1) {
						if(IsSameDate(minSelectedCal, cal)) {
							rangeState = RangeState.First;
						} else if(IsSameDate(maxSelectedCal, cal)) {
							rangeState = RangeState.Last;
						} else if(IsBetweenDates(cal, minSelectedCal, maxSelectedCal)) {
							rangeState = RangeState.Middle;
						}
					}

					weekCells.Add(new MonthCellDescriptor(date, isCurrentMonth, isSelectable, isSelected,
						isToday, isHighlighted, value, rangeState, _styleDescriptor));
					cal = cal.AddDays(1);
				}
			}
			return cells;
		}
		/// <summary>
		/// Initializes the specified minimum date.
		/// </summary>
		/// <param name="minDate">The minimum date.</param>
		/// <param name="maxDate">The maximum date.</param>
		/// <param name="highlightedDaysOfWeek">The highlighted days of week.</param>
		/// <returns>FluentInitializer.</returns>
		/// <exception cref="Java.Lang.IllegalArgumentException">
		/// minDate and maxDate must be non-zero.  +
		/// 				Debug(minDate, maxDate)
		/// or
		/// minDate must be before maxDate.  +
		/// 				Debug(minDate, maxDate)
		/// </exception>
		public FluentInitializer Init(DateTime minDate, DateTime maxDate, DayOfWeek[] highlightedDaysOfWeek)
		{
			if(minDate == DateTime.MinValue || maxDate == DateTime.MinValue) {
				throw new IllegalArgumentException("minDate and maxDate must be non-zero. " +
				Debug(minDate, maxDate));
			}
			if(minDate.CompareTo(maxDate) > 0) {
				throw new IllegalArgumentException("minDate must be before maxDate. " +
				Debug(minDate, maxDate));
			}

			HighlighDaysOfWeeks(highlightedDaysOfWeek);

			Mode = SelectionMode.Single;
			//Clear out any previously selected dates/cells.
			SelectedCals.Clear();
			SelectedCells.Clear();
			_highlightedCals.Clear();
			_highlightedCells.Clear();

			//Clear previous state.
			Cells.Clear();
			Months.Clear();
			MinDate = minDate;
			MaxDate = maxDate;
			MinDate = SetMidnight(MinDate);
			MaxDate = SetMidnight(MaxDate);

			// maxDate is exclusive: bump back to the previous day so if maxDate is the first of a month,
			// We don't accidentally include that month in the view.
			if(MaxDate.Day == 1) {
				MaxDate = MaxDate.AddMinutes(-1);
			}

			//Now iterate between minCal and maxCal and build up our list of months to show.
			_monthCounter = MinDate;
			int maxMonth = MaxDate.Month;
			int maxYear = MaxDate.Year;
			while((_monthCounter.Month <= maxMonth
				   || _monthCounter.Year < maxYear)
				   && _monthCounter.Year < maxYear + 1) {
				var month = new MonthDescriptor(_monthCounter.Month, _monthCounter.Year, _monthCounter,
								_monthCounter.ToString(MonthNameFormat), _styleDescriptor);
				Cells.Add(GetMonthCells(month, _monthCounter));
				Logr.D("Adding month {0}", month);
				Months.Add(month);
				_monthCounter = _monthCounter.AddMonths(1);
			}

			ValidateAndUpdate();
			return new FluentInitializer(this);
		}
示例#8
0
		/// <summary>
		/// Initializes the specified month.
		/// </summary>
		/// <param name="month">The month.</param>
		/// <param name="cells">The cells.</param>
		public void Init(MonthDescriptor month, List<List<MonthCellDescriptor>> cells)
		{
			Logr.D("Initializing MonthView ({0:d}) for {1}", GetHashCode(), month);
			var stopWatch = new Stopwatch();
			stopWatch.Start();
			
			_title.Text = month.Label;
			if(_title.Typeface != null)
			{
				_title.Typeface = month.Style.MonthTitleFont;
			}
			_title.SetTextColor(month.Style.TitleForegroundColor);
			_title.SetBackgroundColor(month.Style.TitleBackgroundColor);

			_grid.DividerColor = month.Style.DateSeparatorColor;

			var headerRow = (CalendarRowView)_grid.GetChildAt(0);
			if(headerRow != null)
			{
				headerRow.SetBackgroundColor(month.Style.DayOfWeekLabelBackgroundColor);
				var week = cells[0];
				for(int c = 0; c <= 6; c++)
				{

					var headerText = (TextView)headerRow.GetChildAt(c);
					if(month.Style.ShouldHighlightDaysOfWeekLabel && week[c].IsHighlighted)
					{
						headerText.SetBackgroundColor(month.Style.HighlightedDateBackgroundColor);
					}
					headerText.SetTextColor(month.Style.DayOfWeekLabelForegroundColor);
				}
			}

			int numOfRows = cells.Count;
			_grid.NumRows = numOfRows;
			for(int i = 0; i < 6; i++)
			{
				var weekRow = (CalendarRowView)_grid.GetChildAt(i + 1);
				weekRow.ClickHandler = _clickHandler;
				if(i < numOfRows)
				{
					weekRow.Visibility = ViewStates.Visible;
					var week = cells[i];
					for(int c = 0; c < week.Count; c++)
					{
						var cell = week[c];
						var cellView = (CalendarCellView)weekRow.GetChildAt(c);

						cellView.Text = cell.Value.ToString();
						cellView.Enabled = cell.IsCurrentMonth;
						cellView.Selectable = cell.IsSelectable;
						cellView.Selected = cell.IsSelected;
						cellView.IsCurrentMonth = cell.IsCurrentMonth;
						cellView.IsToday = cell.IsToday;
						cellView.IsHighlighted = cell.IsHighlighted;
						cellView.RangeState = cell.RangeState;
						cellView.Tag = cell;
						cellView.SetStyle(month.Style);
						//Logr.D("Setting cell at {0} ms", stopWatch.ElapsedMilliseconds);
					}
				} else
				{
					weekRow.Visibility = ViewStates.Gone;
				}
			}
			stopWatch.Stop();
			Logr.D("MonthView.Init took {0} ms", stopWatch.ElapsedMilliseconds);
		}