예제 #1
0
        /// <summary>
        /// Move calendar to the specified date.
        /// </summary>
        /// <param name="dateTime">Date time.</param>
        public void MoveToDate(DateTime dateTime)
        {
            var dayOfMonthFirst = new DateTime(_year, _month, 1);
            var dayOfMonthLast  = new DateTime(_year, _month, DateTime.DaysInMonth(_year, _month));

            // Calendar swipe left when dateTime is in the past
            if (dateTime.Date < dayOfMonthFirst)
            {
                var firstDayOfNextMonth = CalendarHelper.FirstDateTimeOfNextMonth(dateTime);
                var item = _infiniteDateViewPager.CurrentItem;

                _datePageChangeListener.CurrentDateTime = firstDayOfNextMonth;
                _datePageChangeListener.UpdateAdapters(item);

                _infiniteDateViewPager.CurrentItem = item - 1;
            }
            else if (dateTime.Date > dayOfMonthLast)
            {
                var firstDayOfPrevMonth = CalendarHelper.FirstDateTimeOfPreviousMonth(dateTime);
                var item = _infiniteDateViewPager.CurrentItem;

                _datePageChangeListener.CurrentDateTime = firstDayOfPrevMonth;
                _datePageChangeListener.UpdateAdapters(item);

                _infiniteDateViewPager.CurrentItem = item + 1;
            }
        }
예제 #2
0
        public override Java.Lang.Object GetItem(int position)
        {
            var dateTime = DateTimes[position];
            var date     = CalendarHelper.ConvertDateTimeToDate(dateTime);

            return(date);
        }
예제 #3
0
        public void SetAdapterDateTime(DateTime dateTime)
        {
            _year  = dateTime.Year;
            _month = dateTime.Month;

            DateTimes = CalendarHelper.GetFullWeeks(_year, _month, StartDayOfWeek, IsMaxWeekPerMonth);
        }
예제 #4
0
        private DateTime?ArgumentDateTime(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(null);
            }

            return(CalendarHelper.ConvertStringToDateTime(value, null));
        }
예제 #5
0
        public void SetMaxDate(string maxDate, string dateFormat)
        {
            var dateTime = default(DateTime?);

            if (!string.IsNullOrWhiteSpace(maxDate))
            {
                dateTime = CalendarHelper.ConvertStringToDateTime(maxDate, dateFormat);
            }

            MaxDate = dateTime;
        }
예제 #6
0
        /// <summary>
        /// Setup 4 pages contain date grid views. These pages are recycled to use
        /// memory efficient.
        /// </summary>
        /// <param name="view">View.</param>
        private void SetupDateGridPages(View view)
        {
            var currentDateTime = new DateTime(_year, _month, 1);

            _datePageChangeListener = new DatePageChangeListener(this);
            _datePageChangeListener.CurrentDateTime = currentDateTime;

            var currentMonthGridAdapter = CreateCalendarGridAdapter(currentDateTime.Year, currentDateTime.Month);

            _daysInMonths = currentMonthGridAdapter.DateTimes;

            var nextMonthDateTime    = CalendarHelper.LastDateTimeOfNextMonth(currentDateTime);
            var nextMonthGridAdapter = CreateCalendarGridAdapter(nextMonthDateTime.Year, nextMonthDateTime.Month);

            var secondNextMonthDateTime    = CalendarHelper.LastDateTimeOfNextMonth(nextMonthDateTime);
            var secondNextMonthGridAdapter = CreateCalendarGridAdapter(secondNextMonthDateTime.Year, secondNextMonthDateTime.Month);

            var prevMonthDateTime    = CalendarHelper.LastDateTimeOfPreviousMonth(currentDateTime);
            var prevMonthGridAdapter = CreateCalendarGridAdapter(prevMonthDateTime.Year, prevMonthDateTime.Month);

            _calendarGridAdapters.Add(currentMonthGridAdapter);
            _calendarGridAdapters.Add(nextMonthGridAdapter);
            _calendarGridAdapters.Add(secondNextMonthGridAdapter);
            _calendarGridAdapters.Add(prevMonthGridAdapter);

            _datePageChangeListener.CalendarGridAdapters = _calendarGridAdapters;

            _infiniteDateViewPager                   = view.FindViewById <InfiniteViewPager>(Resource.Id.months_infinite_pager);
            _infiniteDateViewPager.IsEnabled         = _isSwipeEnabled;
            _infiniteDateViewPager.IsMaxWeekPerMonth = _isMaxWeekPerMonth;
            _infiniteDateViewPager.DaysInMonth       = _daysInMonths;

            var monthPagerAdapter = new MonthPagerAdapter(ChildFragmentManager);

            _dateGridFragments = monthPagerAdapter.DateGridFragmentList;

            for (var i = 0; i < NUMBER_OF_PAGES; i++)
            {
                var dateGridFragment    = _dateGridFragments[i];
                var calendarGridAdapter = _calendarGridAdapters[i];

                dateGridFragment.GridViewResource    = ResourceGridView();
                dateGridFragment.CalendarGridAdapter = calendarGridAdapter;

                dateGridFragment.OnItemClickEvent     += OnDateGridFragmentItemClicked;
                dateGridFragment.OnItemLongClickEvent += OnDateGridFragmentItemLongClicked;
            }

            var infinitePagerAdapter = new InfinitePagerAdapter(monthPagerAdapter);

            _infiniteDateViewPager.Adapter = infinitePagerAdapter;
            _infiniteDateViewPager.AddOnPageChangeListener(_datePageChangeListener);
        }
예제 #7
0
        public void SetTextColorForDates(Dictionary <Date, int> colorTextForDateMap)
        {
            if (colorTextForDateMap == null || colorTextForDateMap.Count == 0)
            {
                return;
            }

            _colorTextForDate.Clear();

            foreach (var item in colorTextForDateMap)
            {
                var dateTime = CalendarHelper.ConvertDateToDateTime(item.Key);

                _colorTextForDate.Add(dateTime, item.Value);
            }
        }
예제 #8
0
        private List <DateTime> ArgumentDateTimeList(IList <string> values)
        {
            var dateTimes = new List <DateTime>();

            if (values != null && values.Count > 0)
            {
                foreach (var item in values)
                {
                    var dateTime = CalendarHelper.ConvertStringToDateTime(item, null);

                    dateTimes.Add(dateTime);
                }
            }

            return(dateTimes);
        }
예제 #9
0
        public void SetBackgroundDrawableForDates(Dictionary <Date, Drawable> backgroundForDateMap)
        {
            if (backgroundForDateMap == null || backgroundForDateMap.Count == 0)
            {
                return;
            }

            _backgroundForDate.Clear();

            foreach (var item in backgroundForDateMap)
            {
                var dateTime = CalendarHelper.ConvertDateToDateTime(item.Key);

                _backgroundForDate.Add(dateTime, item.Value);
            }
        }
예제 #10
0
        public void SetDisabledDate(List <Date> disableDates)
        {
            if (disableDates == null || disableDates.Count == 0)
            {
                return;
            }

            var dateTimes = new List <DateTime>();

            foreach (var item in disableDates)
            {
                var dateTime = CalendarHelper.ConvertDateToDateTime(item);

                dateTimes.Add(dateTime);
            }

            DisabledDate = dateTimes;
        }
예제 #11
0
        public void SetSelectedDate(List <Date> selectedDates)
        {
            if (selectedDates == null || selectedDates.Count == 0)
            {
                return;
            }

            var dateTimes = new List <DateTime>();

            foreach (var item in selectedDates)
            {
                var dateTime = CalendarHelper.ConvertDateToDateTime(item);

                dateTimes.Add(dateTime);
            }

            SelectedDate = dateTimes;
        }
예제 #12
0
        /// <summary>
        /// To display the week day title
        /// </summary>
        /// <returns>SUN, MON, TUE, WED, THU, FRI, SAT</returns>
        protected List <string> DaysOfWeekTitles()
        {
            var daysOfWeek = new List <string>();
            var formatter  = new SimpleDateFormat("EEE", Locale.Default);

            var weekdaySunday = (int)System.DayOfWeek.Sunday;
            var daySunday     = new DateTime(2000, 10, 1);
            var day           = daySunday.AddDays(_startDayOfWeek - weekdaySunday);

            for (var i = 0; i < 7; i++)
            {
                var date         = CalendarHelper.ConvertDateTimeToDate(day);
                var dayFormatted = formatter.Format(date).ToLower();

                daysOfWeek.Add(dayFormatted);
                day = day.AddDays(1);
            }

            return(daysOfWeek);
        }
예제 #13
0
        /// <summary>
        /// GresourceThemeved sates of the Calendar Extended. Useful for handling rotation.
        /// It does not need to save state of SQUARE_TEXT_VIEW_CELL because this
        /// may change on orientation change.
        /// </summary>
        /// <returns>The saved states.</returns>
        public Bundle CreateBundle()
        {
            var bundle = new Bundle();

            bundle.PutInt(YEAR, _year);
            bundle.PutInt(MONTH, _month);

            if (_minDateTime != null)
            {
                bundle.PutString(MIN_DATE, _minDateTime.Value.ToString(CalendarHelper.DEFAULT_TIME_FORMAT));
            }

            if (_maxDateTime != null)
            {
                bundle.PutString(MAX_DATE, _maxDateTime.Value.ToString(CalendarHelper.DEFAULT_TIME_FORMAT));
            }

            if (_selectedDates != null && _selectedDates.Count > 0)
            {
                bundle.PutStringArrayList(SELECTED_DATES, CalendarHelper.ConvertDateTimeToString(_selectedDates));
            }

            if (_disabledDates != null && _disabledDates.Count > 0)
            {
                bundle.PutStringArrayList(DISABLED_DATES, CalendarHelper.ConvertDateTimeToString(_disabledDates));
            }

            bundle.PutBoolean(ENABLE_SWIPE, _isSwipeEnabled);
            bundle.PutBoolean(MAX_WEEK_PER_MONTH, _isMaxWeekPerMonth);
            bundle.PutBoolean(SHOW_NAVIGATION_ARROWS, _showNavigationArrows);
            bundle.PutBoolean(SQUARE_TEXT_VIEW_CELL, _isSquareTextViewCell);
            bundle.PutInt(START_DAY_OF_WEEK, _startDayOfWeek);
            bundle.PutInt(THEME_RESOURCE, _resourceTheme);

            if (_dialogTitle != null)
            {
                bundle.PutString(DIALOG_TITLE, _dialogTitle);
            }

            return(bundle);
        }
예제 #14
0
            public void UpdateAdapters(int position)
            {
                var currentAdapter = CalendarGridAdapters[Current(position)];
                var prevAdapter    = CalendarGridAdapters[Previous(position)];
                var nextAdapter    = CalendarGridAdapters[Next(position)];

                if (position == CurrentPage)
                {
                    currentAdapter.SetAdapterDateTime(_dateTime);
                    currentAdapter.NotifyDataSetChanged();

                    var prevDateTime = CalendarHelper.LastDateTimeOfPreviousMonth(_dateTime);
                    prevAdapter.SetAdapterDateTime(prevDateTime);
                    prevAdapter.NotifyDataSetChanged();

                    var nextDateTime = CalendarHelper.LastDateTimeOfNextMonth(_dateTime);
                    nextAdapter.SetAdapterDateTime(nextDateTime);
                    nextAdapter.NotifyDataSetChanged();
                }
                // Swipe right
                else if (position > CurrentPage)
                {
                    _dateTime = CalendarHelper.LastDateTimeOfNextMonth(_dateTime);

                    var nextDateTime = CalendarHelper.LastDateTimeOfNextMonth(_dateTime);
                    nextAdapter.SetAdapterDateTime(nextDateTime);
                    nextAdapter.NotifyDataSetChanged();
                }
                // Swipe left
                else
                {
                    _dateTime = CalendarHelper.LastDateTimeOfPreviousMonth(_dateTime);

                    var prevDateTime = CalendarHelper.LastDateTimeOfPreviousMonth(_dateTime);
                    prevAdapter.SetAdapterDateTime(prevDateTime);
                    prevAdapter.NotifyDataSetChanged();
                }

                CurrentPage = position;
            }
예제 #15
0
        public void ClearBackgroundDrawableForDate(Date date)
        {
            var dateTime = CalendarHelper.ConvertDateToDateTime(date);

            _backgroundForDate.Remove(dateTime);
        }
예제 #16
0
        private void LoadDateTime()
        {
            _shouldUpdateDateTime = false;

            DateTimes = CalendarHelper.GetFullWeeks(_year, _month, StartDayOfWeek, IsMaxWeekPerMonth);
        }
예제 #17
0
        public void SetBackgroundDrawableForDate(Drawable drawable, Date date)
        {
            var dateTime = CalendarHelper.ConvertDateToDateTime(date);

            _backgroundForDate.Add(dateTime, drawable);
        }
예제 #18
0
        public void ClearTextColorForDate(Date date)
        {
            var dateTime = CalendarHelper.ConvertDateToDateTime(date);

            _colorTextForDate.Remove(dateTime);
        }
예제 #19
0
 public void SetMaxDate(Date maxDate)
 {
     MaxDate = maxDate == null ? default(DateTime?) : CalendarHelper.ConvertDateToDateTime(maxDate);
 }
예제 #20
0
        public void SetTextColorForDate(int resourceTextColor, Date date)
        {
            var dateTime = CalendarHelper.ConvertDateToDateTime(date);

            _colorTextForDate.Add(dateTime, resourceTextColor);
        }
예제 #21
0
        public void SetCalendarDate(Date date)
        {
            var dateTime = CalendarHelper.ConvertDateToDateTime(date);

            SetCalendarDate(dateTime);
        }
예제 #22
0
        public void MoveToDate(Date date)
        {
            var dateTime = CalendarHelper.ConvertDateToDateTime(date);

            MoveToDate(dateTime);
        }