UNPKG

nativescript-ui-calendar

Version:

Month, year, week and day views. Single, multiple and range date Selection. Special and disabled dates.

1,270 lines (1,269 loc) 94.3 kB
import { Color, Utils, Application, ObservableArray, Enums } from '@nativescript/core'; import * as commonModule from './common'; function getSdkApiLevel() { return android.os.Build.VERSION.SDK_INT; } export * from './common'; export class CalendarEvent extends commonModule.CalendarEvent { get android() { if (!this._android) { this._android = new com.telerik.widget.calendar.events.Event('default', new Date(1990, 0, 1).getTime(), new Date(1990, 0, 2).getTime()); } return this._android; } _setIsAllDay(value) { this.android.setAllDay(value); } _getIsAllDay() { return this.android.isAllDay(); } _setEndDate(date) { this.android.setEndDate(date.getTime()); } _getEndDate() { return new Date(this.android.getEndDate()); } _setStartDate(date) { this.android.setStartDate(date.getTime()); } _getStartDate() { return new Date(this.android.getStartDate()); } _setTitle(value) { this.android.setTitle(value); } _getTitle() { return this.android.getTitle(); } _setEventColor(value) { this.android.setEventColor(value.argb); } _getEventColor() { return new Color(this.android.getEventColor()); } } /** * Helper methods */ class Tool { static createTypeface(name, style) { let fontStyle = android.graphics.Typeface.NORMAL; if (style) { switch (style) { case commonModule.CalendarFontStyle.Bold: fontStyle = android.graphics.Typeface.BOLD; break; case commonModule.CalendarFontStyle.Italic: fontStyle = android.graphics.Typeface.ITALIC; break; case commonModule.CalendarFontStyle.BoldItalic: fontStyle = android.graphics.Typeface.BOLD_ITALIC; break; } } if (name) { return android.graphics.Typeface.create(name, fontStyle); } return android.graphics.Typeface.create(android.graphics.Typeface.DEFAULT, fontStyle); } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // STYLES FOR DIFFERENT CELL TYPES ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Enum values identify to what type of cells is related the style object */ export var CellStyleType; (function (CellStyleType) { CellStyleType[CellStyleType["RegularDayStyle"] = 0] = "RegularDayStyle"; CellStyleType[CellStyleType["SelectedDayStyle"] = 1] = "SelectedDayStyle"; CellStyleType[CellStyleType["TodayStyle"] = 2] = "TodayStyle"; CellStyleType[CellStyleType["WeekNumberStyle"] = 3] = "WeekNumberStyle"; CellStyleType[CellStyleType["WeekendStyle"] = 4] = "WeekendStyle"; CellStyleType[CellStyleType["DayNameStyle"] = 5] = "DayNameStyle"; CellStyleType[CellStyleType["TitleStyle"] = 6] = "TitleStyle"; CellStyleType[CellStyleType["MonthNameStyle"] = 7] = "MonthNameStyle"; // cell for month name in compact Year view mode })(CellStyleType || (CellStyleType = {})); export class CellStyleInitializer { applyStyle(value) { this.changeCellBorderWidth(value.cellBorderWidth, value); this.changeCellBorderColor(value.cellBorderColor, value); this.changeCellBackgroundColor(value.cellBackgroundColor, value); this.changeCellAlignment(value.cellAlignment, value); this.changeCellPaddingHorizontal(value.cellPaddingHorizontal, value); this.changeCellPaddingVertical(value.cellPaddingVertical, value); this.changeCellTextColor(value.cellTextColor, value); this.changeCellTextFontName(value.cellTextFontName, value); this.changeCellTextFontStyle(value.cellTextFontStyle, value); this.changeCellTextSize(value.cellTextSize, value); value.onStyleChanged(); } changeCellBorderWidth(value, style) { if (isNaN(value)) { return; } let borderWidth = new java.lang.Float(value * Utils.layout.getDisplayDensity()); style.android.setBorderWidth(borderWidth); } onCellBorderWidthChanged(value, style) { this.changeCellBorderWidth(value, style); style.onStyleChanged(); } changeCellBorderColor(value, style) { if (!value) { return; } let color = value.argb; let borderColor = new java.lang.Integer(color); style.android.setBorderColor(borderColor); } onCellBorderColorChanged(value, style) { this.changeCellBorderColor(value, style); style.onStyleChanged(); } changeCellBackgroundColor(value, style) { if (!value) { return; } let color = value.argb; let backgroundColor = new java.lang.Integer(color); style.android.setBackgroundColor(backgroundColor); } onCellBackgroundColorChanged(value, style) { this.changeCellBackgroundColor(value, style); style.onStyleChanged(); } changeCellAlignment(value, style) { if (!value) { return; } let position; switch (value) { case commonModule.CalendarCellAlignment.Bottom: position = com.telerik.widget.calendar.CalendarElement.BOTTOM; break; case commonModule.CalendarCellAlignment.Top: position = com.telerik.widget.calendar.CalendarElement.TOP; break; case commonModule.CalendarCellAlignment.Left: position = com.telerik.widget.calendar.CalendarElement.LEFT; break; case commonModule.CalendarCellAlignment.Right: position = com.telerik.widget.calendar.CalendarElement.RIGHT; break; case commonModule.CalendarCellAlignment.HorizontalCenter: position = com.telerik.widget.calendar.CalendarElement.CENTER_HORIZONTAL; break; case commonModule.CalendarCellAlignment.VerticalCenter: position = com.telerik.widget.calendar.CalendarElement.CENTER_VERTICAL; break; case commonModule.CalendarCellAlignment.Center: position = com.telerik.widget.calendar.CalendarElement.CENTER; break; default: position = com.telerik.widget.calendar.CalendarElement.CENTER; } let positionValue = new java.lang.Integer(position); style.android.setTextPosition(positionValue); } onCellAlignmentChanged(value, style) { this.changeCellAlignment(value, style); style.onStyleChanged(); } changeCellPaddingHorizontal(value, style) { if (isNaN(value)) { return; } let paddingVal = value * Utils.layout.getDisplayDensity(); let padding = new java.lang.Integer(paddingVal); style.android.setPaddingHorizontal(padding); } onCellPaddingHorizontalChanged(value, style) { this.changeCellPaddingHorizontal(value, style); style.onStyleChanged(); } changeCellPaddingVertical(value, style) { if (isNaN(value)) { return; } let paddingVal = value * Utils.layout.getDisplayDensity(); let padding = new java.lang.Integer(paddingVal); style.android.setPaddingVertical(padding); } onCellPaddingVerticalChanged(value, style) { this.changeCellPaddingVertical(value, style); style.onStyleChanged(); } changeCellTextColor(value, style) { if (!value) { return; } let color = value.argb; let textColor = new java.lang.Integer(color); style.android.setTextColor(textColor); } onCellTextColorChanged(value, style) { this.changeCellTextColor(value, style); style.onStyleChanged(); } changeCellTextFontName(value, style) { if (!value) { return; } let font = Tool.createTypeface(value, style.cellTextFontStyle); style.android.setFontName(value); } onCellTextFontNameChanged(value, style) { this.changeCellTextFontName(value, style); style.onStyleChanged(); } changeCellTextFontStyle(value, style) { if (!value) { return; } let font = Tool.createTypeface(style.cellTextFontName, value); let fontStyle = new java.lang.Integer(font.getStyle()); style.android.setFontStyle(fontStyle); } onCellTextFontStyleChanged(value, style) { this.changeCellTextFontStyle(value, style); style.onStyleChanged(); } changeCellTextSize(value, style) { if (isNaN(value)) { return; } let size = value * Utils.layout.getDisplayDensity(); let textSize = new java.lang.Float(size); style.android.setTextSize(textSize); } onCellTextSizeChanged(value, style) { this.changeCellTextSize(value, style); style.onStyleChanged(); } makeDayCellFilter(cellStyleType, displayMode) { let cellFilter = new com.telerik.widget.calendar.CalendarDayCellFilter(); let positiveFilter = new java.lang.Boolean(true); switch (cellStyleType) { case CellStyleType.TodayStyle: cellFilter.setIsToday(positiveFilter); case CellStyleType.RegularDayStyle: cellFilter.setCellType(com.telerik.widget.calendar.CalendarCellType.Date); break; case CellStyleType.WeekendStyle: cellFilter.setIsWeekend(positiveFilter); cellFilter.setCellType(com.telerik.widget.calendar.CalendarCellType.Date); break; case CellStyleType.DayNameStyle: cellFilter.setCellType(com.telerik.widget.calendar.CalendarCellType.DayName); break; case CellStyleType.WeekNumberStyle: cellFilter.setCellType(com.telerik.widget.calendar.CalendarCellType.WeekNumber); break; case CellStyleType.TitleStyle: cellFilter.setCellType(com.telerik.widget.calendar.CalendarCellType.Title); break; case CellStyleType.SelectedDayStyle: cellFilter.setCellType(com.telerik.widget.calendar.CalendarCellType.Date); cellFilter.setIsSelected(positiveFilter); break; } if (displayMode) { cellFilter.setCalendarDisplayMode(displayMode); } return cellFilter; } makeMonthCellFilter() { let cellFilter = new com.telerik.widget.calendar.CalendarMonthCellFilter(); let positiveFilter = new java.lang.Boolean(true); cellFilter.setMonthIsCompact(positiveFilter); return cellFilter; } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// export class CellStyle extends commonModule.CellStyle { constructor() { super(...arguments); this._nativeIsYear = false; } set nativeIsYear(value) { if (this._nativeIsYear !== value) { this._nativeIsYear = value; this._android = null; } } // @ts-ignore set owner(value) { this._owner = value; } get initializer() { if (!this._initializer) { this._initializer = new CellStyleInitializer(); } return this._initializer; } get android() { if (!this._android) { if (this._nativeIsYear) { this._android = new com.telerik.widget.calendar.CalendarMonthCellStyle(); this.initializer.applyStyle(this); } else { this._android = new com.telerik.widget.calendar.CalendarDayCellStyle(); } } return this._android; } updateNativeStyleFilters(cellStyleType, displayMode) { if (!this._owner) { return; } if (this._nativeIsYear) { let filter = this.initializer.makeMonthCellFilter(); this.android.setFilter(filter); } else { let filter = this.initializer.makeDayCellFilter(cellStyleType, displayMode); this.android.setFilter(filter); } } onStyleChanged() { if (this._owner) { this._owner.updateCalendar(); } } onCellBorderWidthChanged(oldValue, newValue) { this.initializer.onCellBorderWidthChanged(newValue, this); } onCellBorderColorChanged(oldValue, newValue) { this.initializer.onCellBorderColorChanged(newValue, this); } onCellBackgroundColorChanged(oldValue, newValue) { this.initializer.onCellBackgroundColorChanged(newValue, this); } onCellTextColorChanged(oldValue, newValue) { this.initializer.onCellTextColorChanged(newValue, this); } onCellTextFontNameChanged(oldValue, newValue) { this.initializer.onCellTextFontNameChanged(newValue, this); } onCellTextFontStyleChanged(oldValue, newValue) { this.initializer.onCellTextFontStyleChanged(newValue, this); } onCellTextSizeChanged(oldValue, newValue) { this.initializer.onCellTextSizeChanged(newValue, this); } onCellPaddingHorizontalChanged(oldValue, newValue) { this.initializer.onCellPaddingHorizontalChanged(newValue, this); } onCellPaddingVerticalChanged(oldValue, newValue) { this.initializer.onCellPaddingVerticalChanged(newValue, this); } onCellAlignmentChanged(oldValue, newValue) { this.initializer.onCellAlignmentChanged(newValue, this); } } export class DayEventsViewStyle extends commonModule.DayEventsViewStyle { // @ts-ignore set owner(value) { this._owner = value; this.applyStyles(); } get android() { if (!this._owner) { return null; } return this._owner.getDayView().getDayEventsViewStyle(); } applyStyles() { if (this.backgroundColor) { this.changeBackgroundColor(null, this.backgroundColor); } if (this.timeLabelFormat) { this.changeTimeLabelFormat(null, this.timeLabelFormat); } if (this.timeLabelTextColor) { this.changeTimeLabelTextColor(null, this.timeLabelTextColor); } if (this.timeLabelTextSize) { this.changeTimeLabelTextSize(null, this.timeLabelTextSize); } if (this.timeLinesWidth) { this.changeTimeLinesWidth(null, this.timeLinesWidth); } if (this.timeLinesColor) { this.changeTimeLinesColor(null, this.timeLinesColor); } } onBackgroundColorChanged(oldValue, newValue) { this.changeBackgroundColor(oldValue, newValue); } changeBackgroundColor(oldValue, newValue) { if (newValue && this.android) { this.android.setBackgroundColor(newValue.android); } } onTimeLabelFormatChanged(oldValue, newValue) { this.changeTimeLabelFormat(oldValue, newValue); } changeTimeLabelFormat(oldValue, newValue) { if (this.android) { this.android.setTimeLabelFormat(new java.text.SimpleDateFormat(newValue)); } } onTimeLabelTextColorChanged(oldValue, newValue) { this.changeTimeLabelTextColor(oldValue, newValue); } changeTimeLabelTextColor(oldValue, newValue) { if (newValue && this.android) { this.android.setTimeLabelColor(newValue.android); } } onTimeLabelTextSizeChanged(oldValue, newValue) { this.changeTimeLabelTextSize(oldValue, newValue); } changeTimeLabelTextSize(oldValue, newValue) { if (this.android) { this.android.setTimeLabelTextSize(newValue * Utils.layout.getDisplayDensity()); } } onTimeLinesWidthChanged(oldValue, newValue) { this.changeTimeLinesWidth(oldValue, newValue); } changeTimeLinesWidth(oldValue, newValue) { if (this.android) { this.android.setTimeLinesWidth(newValue * Utils.layout.getDisplayDensity()); } } onTimeLinesColorChanged(oldValue, newValue) { this.changeTimeLinesColor(oldValue, newValue); } changeTimeLinesColor(oldValue, newValue) { if (newValue && this.android) { this.android.setTimeLinesColor(newValue.android); } } } export class AllDayEventsViewStyle extends commonModule.AllDayEventsViewStyle { // @ts-ignore set owner(value) { this._owner = value; this.applyStyles(); } get android() { if (!this._owner) { return null; } return this._owner.getDayView().getAllDayEventsViewStyle(); } applyStyles() { if (this.backgroundColor) { this.changeBackgroundColor(null, this.backgroundColor); } if (this.allDayText !== AllDayEventsViewStyle.ALL_DAY_TEXT) { this.changeAllDayText(AllDayEventsViewStyle.ALL_DAY_TEXT, this.allDayText); } if (this.allDayTextIsVisible !== undefined) { this.changeAllDayTextIsVisible(null, this.allDayTextIsVisible); } } onBackgroundColorChanged(oldValue, newValue) { this.changeBackgroundColor(oldValue, newValue); } changeBackgroundColor(oldValue, newValue) { if (newValue && this.android) { this.android.setBackgroundColor(newValue.android); } } onAllDayTextChanged(oldValue, newValue) { this.changeAllDayText(oldValue, newValue); } changeAllDayText(oldValue, newValue) { if (this.android) { this.android.setAllDayText(newValue); } } onAllDayTextIsVisibleChanged(oldValue, newValue) { this.changeAllDayTextIsVisible(oldValue, newValue); } changeAllDayTextIsVisible(oldValue, newValue) { if (this.android) { this.android.setAllDayTextIsVisible(newValue); } } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// export class DayCellStyle extends commonModule.DayCellStyle { // @ts-ignore set owner(value) { this._owner = value; } set eventAdapter(value) { this._eventAdapter = value; } get initializer() { if (!this._initializer) { this._initializer = new CellStyleInitializer(); } return this._initializer; } get android() { if (!this._android) { this._android = new com.telerik.widget.calendar.CalendarDayCellStyle(); } return this._android; } updateNativeStyleFilters(cellStyleType, displayMode) { if (!this._owner) { return; } let filter = this.initializer.makeDayCellFilter(cellStyleType, displayMode); this.android.setFilter(filter); } onCellBorderWidthChanged(oldValue, newValue) { this.initializer.onCellBorderWidthChanged(newValue, this); } onCellBorderColorChanged(oldValue, newValue) { this.initializer.onCellBorderColorChanged(newValue, this); } onCellBackgroundColorChanged(oldValue, newValue) { this.initializer.onCellBackgroundColorChanged(newValue, this); } onCellTextColorChanged(oldValue, newValue) { this.initializer.onCellTextColorChanged(newValue, this); } onCellTextFontNameChanged(oldValue, newValue) { this.initializer.onCellTextFontNameChanged(newValue, this); } onCellTextFontStyleChanged(oldValue, newValue) { this.initializer.onCellTextFontStyleChanged(newValue, this); } onCellTextSizeChanged(oldValue, newValue) { this.initializer.onCellTextSizeChanged(newValue, this); } onCellPaddingHorizontalChanged(oldValue, newValue) { this.initializer.onCellPaddingHorizontalChanged(newValue, this); } onCellPaddingVerticalChanged(oldValue, newValue) { this.initializer.onCellPaddingVerticalChanged(newValue, this); } onCellAlignmentChanged(oldValue, newValue) { this.initializer.onCellAlignmentChanged(newValue, this); } onStyleChanged() { if (this._owner) { this._owner.updateCalendar(); } } // day cell specific properties onShowEventsTextChanged(oldValue, newValue) { if (newValue === undefined || newValue == null || !this.eventAdapter) { return; } this.eventAdapter.getRenderer().setEventRenderMode(newValue ? com.telerik.widget.calendar.events.EventRenderMode.Shape_And_Text : com.telerik.widget.calendar.events.EventRenderMode.Shape); } onEventTextColorChanged(oldValue, newValue) { if (!newValue || !this.eventAdapter) { return; } // TODO: Event text color property not supported in Android. } onEventFontNameChanged(oldValue, newValue) { if (!newValue || !this.eventAdapter) { return; } // TODO: Event font name property not supported in Android. } onEventFontStyleChanged(oldValue, newValue) { if (!newValue || !this.eventAdapter) { return; } // TODO: Event font style property not supported in Android. } onEventTextSizeChanged(oldValue, newValue) { if (isNaN(newValue) || !this.eventAdapter) { return; } this.eventAdapter.getRenderer().setEventTextSize(newValue * Utils.layout.getDisplayDensity()); } } /** * Cell style class for months in year view mode */ export class MonthCellStyle extends commonModule.MonthCellStyle { get regularDayStyle() { if (!this._regularDayStyle) { this._regularDayStyle = new com.telerik.widget.calendar.CalendarMonthCellStyle(); let dateMonthCellFilter = new com.telerik.widget.calendar.CalendarMonthCellFilter(); let positiveFilter = new java.lang.Boolean(true); dateMonthCellFilter.setTextIsDate(positiveFilter); this._regularDayStyle.setFilter(dateMonthCellFilter); } return this._regularDayStyle; } get weekendStyle() { if (!this._weekendStyle) { this._weekendStyle = new com.telerik.widget.calendar.CalendarMonthCellStyle(); let weekendMonthCellFilter = new com.telerik.widget.calendar.CalendarMonthCellFilter(); let positiveFilter = new java.lang.Boolean(true); weekendMonthCellFilter.setTextIsWeekend(positiveFilter); this._weekendStyle.setFilter(weekendMonthCellFilter); } return this._weekendStyle; } get todayStyle() { if (!this._todayStyle) { this._todayStyle = new com.telerik.widget.calendar.CalendarMonthCellStyle(); let todayMonthCellFilter = new com.telerik.widget.calendar.CalendarMonthCellFilter(); let positiveFilter = new java.lang.Boolean(true); todayMonthCellFilter.setTextIsToday(positiveFilter); this._todayStyle.setFilter(todayMonthCellFilter); } return this._todayStyle; } get dayNameStyle() { if (!this._dayNameStyle) { this._dayNameStyle = new com.telerik.widget.calendar.CalendarMonthCellStyle(); let dayNameMonthCellFilter = new com.telerik.widget.calendar.CalendarMonthCellFilter(); let positiveFilter = new java.lang.Boolean(true); dayNameMonthCellFilter.setTextIsDayName(positiveFilter); this._dayNameStyle.setFilter(dayNameMonthCellFilter); } return this._dayNameStyle; } get monthNameStyle() { if (!this._monthNameStyle) { this._monthNameStyle = new com.telerik.widget.calendar.CalendarMonthCellStyle(); let monthNameMonthCellFilter = new com.telerik.widget.calendar.CalendarMonthCellFilter(); let positiveFilter = new java.lang.Boolean(true); monthNameMonthCellFilter.setTextIsMonthName(positiveFilter); this._monthNameStyle.setFilter(monthNameMonthCellFilter); } return this._monthNameStyle; } get monthCellStyle() { if (!this._monthCellStyle) { this._monthCellStyle = new com.telerik.widget.calendar.CalendarMonthCellStyle(); } return this._monthCellStyle; } onStyleChanged() { if (this.owner && this.owner.getDisplayMode() === com.telerik.widget.calendar.CalendarDisplayMode.Year) { this.owner.updateCalendar(); } } onWeekendTextColorChanged(oldValue, newValue) { if (newValue) { let color = newValue.argb; let textColor = new java.lang.Integer(color); this.weekendStyle.setTextColor(textColor); this.onStyleChanged(); } } onTodayTextColorChanged(oldValue, newValue) { if (newValue) { let color = newValue.argb; let textColor = new java.lang.Integer(color); this.todayStyle.setTextColor(textColor); this.onStyleChanged(); } } onDayTextColorChanged(oldValue, newValue) { if (newValue) { let color = newValue.argb; let textColor = new java.lang.Integer(color); this.regularDayStyle.setTextColor(textColor); this.onStyleChanged(); } } onDayFontNameChanged(oldValue, newValue) { if (newValue) { this.regularDayStyle.setFontName(newValue); this.onStyleChanged(); } } onDayFontStyleChanged(oldValue, newValue) { if (newValue) { let font = Tool.createTypeface(this.dayFontName, newValue); let fontStyle = new java.lang.Integer(font.getStyle()); this.regularDayStyle.setFontStyle(fontStyle); this.onStyleChanged(); } } onDayTextSizeChanged(oldValue, newValue) { if (!isNaN(+newValue)) { let size = newValue * Utils.layout.getDisplayDensity(); let sizeValue = new java.lang.Float(size); this.regularDayStyle.setTextSize(sizeValue); this.onStyleChanged(); } } onDayNameTextColorChanged(oldValue, newValue) { if (newValue) { let color = newValue.argb; let colorValue = new java.lang.Integer(color); this.dayNameStyle.setTextColor(colorValue); this.onStyleChanged(); } } onDayNameFontNameChanged(oldValue, newValue) { if (newValue) { this.dayNameStyle.setFontName(newValue); this.onStyleChanged(); } } onDayNameFontStyleChanged(oldValue, newValue) { if (newValue) { let font = Tool.createTypeface(this.dayNameFontName, newValue); let fontStyle = new java.lang.Integer(font.getStyle()); this.dayNameStyle.setFontStyle(fontStyle); this.onStyleChanged(); } } onDayNameTextSizeChanged(oldValue, newValue) { if (!isNaN(+newValue)) { let size = newValue * Utils.layout.getDisplayDensity(); let sizeValue = new java.lang.Float(size); this.dayNameStyle.setTextSize(sizeValue); this.onStyleChanged(); } } onMonthNameTextColorChanged(oldValue, newValue) { if (newValue) { let color = newValue.argb; let colorValue = new java.lang.Integer(color); this.monthNameStyle.setTextColor(colorValue); this.onStyleChanged(); } } onMonthNameFontNameChanged(oldValue, newValue) { if (newValue) { this.monthNameStyle.setFontName(newValue); this.onStyleChanged(); } } onMonthNameFontStyleChanged(oldValue, newValue) { if (newValue) { let font = Tool.createTypeface(this.monthNameFontName, newValue); let fontStyle = new java.lang.Integer(font.getStyle()); this.monthNameStyle.setFontStyle(fontStyle); this.onStyleChanged(); } } onMonthNameTextSizeChanged(oldValue, newValue) { if (!isNaN(+newValue)) { let size = newValue * Utils.layout.getDisplayDensity(); let sizeValue = new java.lang.Float(size); this.monthNameStyle.setTextSize(sizeValue); this.onStyleChanged(); } } } /** * Cell style class for inline events cells in month view */ export class InlineEventCellStyle extends commonModule.InlineEventCellStyle { apply(adapter) { if (!adapter) { return; } this._adapter = adapter; let color; if (this.cellBackgroundColor) { color = this.cellBackgroundColor.argb; this._adapter.setInlineEventsBackgroundColor(color); } if (this.eventTextColor) { // TODO: Text color for inline event is not supported for Android calendar. } if (this.eventFontName) { // TODO: Font name property for inline event text is not supported for Android calendar. } if (this.eventFontStyle) { // TODO: Font style property for inline event text is not supported for Android calendar. } if (!isNaN(this.eventTextSize)) { this._adapter.setInlineEventTitleTextSize(this.eventTextSize); } if (this.timeTextColor) { let color = this.timeTextColor.argb; this._adapter.setInlineEventTimeStartTextColor(color); this._adapter.setInlineEventTimeEndTextColor(color); } if (this.timeFontName) { // TODO: Font name property for for inline event date/time is not supported for Android calendar. } if (this.timeFontStyle) { // TODO: Font style property for for inline event date/time is not supported for Android calendar. } if (this.timeTextSize) { if (!isNaN(+this.timeTextSize)) { // NOTE: these methods don't require display density to be taken account this._adapter.setInlineEventTimeEndTextSize(this.timeTextSize); this._adapter.setInlineEventTimeStartTextSize(this.timeTextSize); } } } onCellBackgroundColorChanged(oldValue, newValue) { if (newValue && this._adapter) { let color = newValue.argb; this._adapter.setInlineEventsBackgroundColor(color); } } onEventTextColorChanged(oldValue, newValue) { // TODO: console.log("WARNING: Text color for inline event is not supported for Android calendar.") } onEventFontNameChanged(oldValue, newValue) { // TODO: console.log("WARNING: Font name property for inline event text is not supported for Android calendar.") } onEventFontStyleChanged(oldValue, newValue) { // TODO: console.log("WARNING: Font style property for inline event text is not supported for Android calendar.") } onEventTextSizeChanged(oldValue, newValue) { if (!isNaN(+newValue) && this._adapter) { this._adapter.setInlineEventTitleTextSize(newValue); } } onTimeTextColorChanged(oldValue, newValue) { if (newValue && this._adapter) { let color = newValue.argb; this._adapter.setInlineEventTimeStartTextColor(color); this._adapter.setInlineEventTimeEndTextColor(color); } } onTimeFontNameChanged(oldValue, newValue) { // TODO: console.log("WARNING: Font name property for for inline event date/time is not supported for Android calendar.") } onTimeFontStyleChanged(oldValue, newValue) { // TODO: console.log("WARNING: Font style property for for inline event date/time is not supported for Android calendar.") } onTimeTextSizeChanged(oldValue, newValue) { if (!isNaN(+newValue) && this._adapter) { // NOTE: these methods don't require display density to be taken account this._adapter.setInlineEventTimeEndTextSize(newValue); this._adapter.setInlineEventTimeStartTextSize(newValue); } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // STYLES FOR DIFFERENT VIEW MODES ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// export class CalendarStyleInitializer { updateNativeStyles(style) { if (!style._owner || !style._owner._nativeView) { return; } if (style.backgroundColor) { let color = style.backgroundColor.argb; style._owner._nativeView.setBackgroundColor(color); } if (style.showDayNames !== undefined && style.showDayNames != null) { style._owner._nativeView.setShowDayNames(style.showDayNames); } if (style.showTitle !== undefined && style.showTitle != null) { style._owner._nativeView.setShowTitle(style.showTitle); } if (style.showWeekNumbers !== undefined && style.showWeekNumbers != null) { style._owner._nativeView.setWeekNumbersDisplayMode(style.showWeekNumbers ? com.telerik.widget.calendar.WeekNumbersDisplayMode.Block : com.telerik.widget.calendar.WeekNumbersDisplayMode.None); } if (style.dayCellStyle) { style.prepareNativeStyle(style.dayCellStyle, CellStyleType.RegularDayStyle); style._owner._nativeView.addDayCellStyle(style.dayCellStyle.android); } if (style.weekendCellStyle) { style.prepareNativeStyle(style.weekendCellStyle, CellStyleType.WeekendStyle); style._owner._nativeView.addDayCellStyle(style.weekendCellStyle.android); } if (style.todayCellStyle) { style.prepareNativeStyle(style.todayCellStyle, CellStyleType.TodayStyle); style._owner._nativeView.addDayCellStyle(style.todayCellStyle.android); } if (style.dayNameCellStyle) { style.prepareNativeStyle(style.dayNameCellStyle, CellStyleType.DayNameStyle); style._owner._nativeView.addDayCellStyle(style.dayNameCellStyle.android); } if (style.weekNumberCellStyle) { style.prepareNativeStyle(style.weekNumberCellStyle, CellStyleType.WeekNumberStyle); style._owner._nativeView.addDayCellStyle(style.weekNumberCellStyle.android); } if (style.titleCellStyle) { style.prepareNativeStyle(style.titleCellStyle, CellStyleType.TitleStyle); style._owner._nativeView.addDayCellStyle(style.titleCellStyle.android); } if (style.selectedDayCellStyle) { style.prepareNativeStyle(style.selectedDayCellStyle, CellStyleType.SelectedDayStyle); style._owner._nativeView.addDayCellStyle(style.selectedDayCellStyle.android); } if (style.inlineEventCellStyle) { style.prepareNativeStyle(style.inlineEventCellStyle, null); } this.syncSelectionShape(style); } onShowWeekNumbersChanged(oldValue, newValue, style) { this.changeShowWeekNumbers(newValue, style); } changeShowWeekNumbers(newValue, style) { if (style._owner && style._owner._nativeView) { style._owner._nativeView.setWeekNumbersDisplayMode(newValue ? com.telerik.widget.calendar.WeekNumbersDisplayMode.Block : com.telerik.widget.calendar.WeekNumbersDisplayMode.None); } } onShowTitleChanged(oldValue, newValue, style) { this.changeShowTitle(newValue, style); } changeShowTitle(newValue, style) { if (style._owner && style._owner._nativeView) { style._owner._nativeView.setShowTitle(newValue); } } onShowDayNamesChanged(oldValue, newValue, style) { this.changeShowDayNames(newValue, style); } changeShowDayNames(newValue, style) { if (style._owner && style._owner._nativeView) { style._owner._nativeView.setShowDayNames(newValue); } } onBackgroundColorChanged(oldValue, newValue, style) { this.changeBackgroundColor(newValue, style); } changeBackgroundColor(newValue, style) { if (newValue && style._owner && style._owner._nativeView) { let color = newValue.argb; style._owner._nativeView.setBackgroundColor(color); } } onDayCellStyleChanged(oldValue, newValue, style) { this.changeDayCellStyle(oldValue, newValue, style); } changeDayCellStyle(oldValue, newValue, style) { if (style._owner && style._owner._nativeView) { if (oldValue) { style._owner._nativeView.removeDayCellStyle(oldValue.android); } if (newValue) { style.prepareNativeStyle(newValue, CellStyleType.RegularDayStyle); style._owner._nativeView.addDayCellStyle(newValue.android); } } } onSelectedDayCellStyleChanged(oldValue, newValue, style) { this.changeSelectedDayCellStyle(oldValue, newValue, style); } changeSelectedDayCellStyle(oldValue, newValue, style) { if (style._owner && style._owner._nativeView) { if (oldValue) { style._owner._nativeView.removeDayCellStyle(oldValue.android); } if (newValue) { style.prepareNativeStyle(newValue, CellStyleType.SelectedDayStyle); style._owner._nativeView.addDayCellStyle(newValue.android); } } } onTodayCellStyleChanged(oldValue, newValue, style) { this.changeTodayCellStyle(oldValue, newValue, style); } changeTodayCellStyle(oldValue, newValue, style) { if (style._owner && style._owner._nativeView) { if (oldValue) { style._owner._nativeView.removeDayCellStyle(oldValue.android); } if (newValue) { style.prepareNativeStyle(newValue, CellStyleType.TodayStyle); style._owner._nativeView.addDayCellStyle(newValue.android); } } } onWeekNumberCellStyleChanged(oldValue, newValue, style) { this.changeWeekNumberCellStyle(oldValue, newValue, style); } changeWeekNumberCellStyle(oldValue, newValue, style) { if (style._owner && style._owner._nativeView) { if (oldValue) { // TODO: See if this was working as the removeDayCellStyle requires 'CalendarDayCellStyle' style._owner._nativeView.removeDayCellStyle(oldValue.android); } if (newValue) { style.prepareNativeStyle(newValue, CellStyleType.WeekNumberStyle); // TODO: See if this was working as the addDayCellStyle requires 'CalendarDayCellStyle' style._owner._nativeView.addDayCellStyle(newValue.android); } } } onWeekendCellStyleChanged(oldValue, newValue, style) { this.changeWeekendCellStyle(oldValue, newValue, style); } changeWeekendCellStyle(oldValue, newValue, style) { if (style._owner && style._owner._nativeView) { if (oldValue) { // TODO: See if this was working as the removeDayCellStyle requires 'CalendarDayCellStyle' style._owner._nativeView.removeDayCellStyle(oldValue.android); } if (newValue) { style.prepareNativeStyle(newValue, CellStyleType.WeekendStyle); // TODO: See if this was working as the removeDayCellStyle requires 'CalendarDayCellStyle' style._owner._nativeView.addDayCellStyle(newValue.android); } } } onDayNameCellStyleChanged(oldValue, newValue, style) { this.changeDayNameCellStyle(oldValue, newValue, style); } changeDayNameCellStyle(oldValue, newValue, style) { if (style._owner && style._owner._nativeView) { if (oldValue) { // TODO: See if this was working as the removeDayCellStyle requires 'CalendarDayCellStyle' style._owner._nativeView.removeDayCellStyle(oldValue.android); } if (newValue) { style.prepareNativeStyle(newValue, CellStyleType.DayNameStyle); // TODO: See if this was working as the removeDayCellStyle requires 'CalendarDayCellStyle' style._owner._nativeView.addDayCellStyle(newValue.android); } } } onTitleCellStyleChanged(oldValue, newValue, style) { this.changeTitleCellStyle(oldValue, newValue, style); } changeTitleCellStyle(oldValue, newValue, style) { if (style._owner && style._owner._nativeView) { if (oldValue) { // TODO: See if this was working as the removeDayCellStyle requires 'CalendarDayCellStyle' style._owner._nativeView.removeDayCellStyle(oldValue.android); } if (newValue) { style.prepareNativeStyle(newValue, CellStyleType.TitleStyle); // TODO: See if this was working as the removeDayCellStyle requires 'CalendarDayCellStyle' style._owner._nativeView.addDayCellStyle(newValue.android); } } } syncSelectionShape(style) { if (style._owner) { style._owner._syncSelectionShape(); } } } /** * Class for month view style */ export class CalendarMonthViewStyle extends commonModule.CalendarMonthViewStyle { get initializer() { if (!this._initializer) { this._initializer = new CalendarStyleInitializer(); } return this._initializer; } // @ts-ignore set owner(value) { this._owner = value; this.initializer.updateNativeStyles(this); } updateNativeStyles() { this.initializer.updateNativeStyles(this); } prepareNativeStyle(style, cellType) { if (!style || !this._owner || !this._owner._nativeView) { return; } style.owner = this._owner._nativeView; if (style instanceof DayCellStyle) { style.eventAdapter = this._owner._nativeView.getEventAdapter(); } if (cellType != null) { this.updateNativeStyleFilters(style, cellType); } else { style.apply(this._owner._nativeView.getAdapter()); } } updateNativeStyleFilters(style, cellType) { style.updateNativeStyleFilters(cellType, com.telerik.widget.calendar.CalendarDisplayMode.Month); } onShowWeekNumbersChanged(oldValue, newValue) { this.initializer.onShowWeekNumbersChanged(oldValue, newValue, this); } onSelectionShapeChanged(oldValue, newValue) { this.initializer.syncSelectionShape(this); } onSelectionShapeSizeChanged(oldValue, newValue) { this.initializer.syncSelectionShape(this); } onSelectionShapeColorChanged(oldValue, newValue) { this.initializer.syncSelectionShape(this); } onShowTitleChanged(oldValue, newValue) { this.initializer.onShowTitleChanged(oldValue, newValue, this); } onShowDayNamesChanged(oldValue, newValue) { this.initializer.onShowDayNamesChanged(oldValue, newValue, this); } onBackgroundColorChanged(oldValue, newValue) { this.initializer.onBackgroundColorChanged(oldValue, newValue, this); } onDayCellStyleChanged(oldValue, newValue) { this.initializer.onDayCellStyleChanged(oldValue, newValue, this); } onSelectedDayCellStyleChanged(oldValue, newValue) { this.initializer.onSelectedDayCellStyleChanged(oldValue, newValue, this); } onTodayCellStyleChanged(oldValue, newValue) { this.initializer.onTodayCellStyleChanged(oldValue, newValue, this); } onWeekNumberCellStyleChanged(oldValue, newValue) { this.initializer.onWeekNumberCellStyleChanged(oldValue, newValue, this); } onWeekendCellStyleChanged(oldValue, newValue) { this.initializer.onWeekendCellStyleChanged(oldValue, newValue, this); } onDayNameCellStyleChanged(oldValue, newValue) { this.initializer.onDayNameCellStyleChanged(oldValue, newValue, this); } onTitleCellStyleChanged(oldValue, newValue) { this.initializer.onTitleCellStyleChanged(oldValue, newValue, this); } onInlineEventCellStyleChanged(oldValue, newValue) { this.prepareNativeStyle(newValue, null); } } /** * The style class for week mode. * NOTE: we should consider if we need an explicit class that is the same as the base one */ export class CalendarWeekViewStyle extends CalendarMonthViewStyle { updateNativeStyleFilters(style, cellType) { style.updateNativeStyleFilters(cellType, com.telerik.widget.calendar.CalendarDisplayMode.Week); } } /** * The style class for day mode. */ export class CalendarDayViewStyle extends commonModule.CalendarDayViewStyle { get initializer() { if (!this._initializer) { this._initializer = new CalendarStyleInitializer(); } return this._initializer; } // @ts-ignore set owner(value) { this._owner = value; this.updateNativeStyles(); } updateNativeStyles() { this.initializer.updateNativeStyles(this); this.updateNativeDayStyles(); } updateNativeDayStyles() { this.changeShowWeek(null, this.showWeek); if (this.dayEventsViewStyle) { this.changeDayEventsViewStyle(null, this.dayEventsViewStyle); } if (this.allDayEventsViewStyle) { this.changeAllDayEventsViewStyle(null, this.allDayEventsViewStyle); } } prepareNativeStyle(style, cellType) { if (!style || !this._owner || !this._owner._nativeView) { return; } style.owner = this._owner._nativeView; if (style instanceof DayCellStyle) { style.eventAdapter = this._owner._nativeView.getEventAdapter(); } if (cellType != null) { this.updateNativeStyleFilters(style, cellType); } else { style.apply(this._owner._nativeView.getAdapter()); } } updateNativeStyleFilters(style, cellType) { style.updateNativeStyleFilters(cellType, com.telerik.widget.calendar.CalendarDisplayMode.Day); } onShowWeekNumbersChanged(oldValue, newValue) { this.initializer.onShowWeekNumbersChanged(oldValue, newValue, this); } onSelectionShapeChanged(oldValue, newValue) { this.initializer.syncSelectionShape(this); } onSelectionShapeSizeChanged(oldValue, newValue) { this.initializer.syncSelectionShape(this); } onSelectionShapeColorChanged(oldValue, newValue) { this.initializer.syncSelectionShape(this); } onShowTitleChanged(oldValue, newValue) { this.initializer.onShowTitleChanged(oldValue, newValue, this); } onShowDayNamesChanged(oldValue, newValue) { this.initializer.onShowDayNamesChanged(oldValue, newValue, this); } onBackgroundColorChanged(oldValue, newValue) { this.initializer.onBackgroundColorChanged(oldValue, newValue, this); } onDayCellStyleChanged(oldValue, newValue) { this.initializer.onDayCellStyleChanged(oldValue, newValue, this); } onSelectedDayCellStyleChanged(oldValue, newValue) { this.initializer.onSelectedDayCellStyleChanged(oldValue, newValue, this); } onTodayCellStyleChanged(oldValue, newValue) { this.initializer.onTodayCellStyleChanged(oldValue, newValue, this); } onWeekNumberCellStyleChanged(oldValue, newValue) { this.initializer.onWeekNumberCellStyleChanged(oldValue, newValue, this); } onWeekendCellStyleChanged(oldValue, newValue) { this.initializer.onWeekendCellStyleChanged(oldValue, newValue, this); } onDayNameCellStyleChanged(oldValue, newValue) { this.initializer.onDayNameCellStyleChanged(oldValue, newValue, this); } onTitleCellStyleChanged(oldValue, newValue) { this.initializer.onTitleCellStyleChanged(oldValue, newValue, this); } onDayEventsViewStyleChanged(oldValue, newValue) { this.changeDayEventsViewStyle(oldValue, newValue); } changeDayEventsViewStyle(oldValue, newValue) { if (oldValue) { oldValue.owner = null; } if (newValue && this._owner) { newValue.owner = this._owner._nativeView; } } onAllDayEventsViewStyleChanged(oldValue, newValue) { this.changeAllDayEventsViewStyle(oldValue, newValue); } changeAllDayEventsViewStyle(oldValue, newValue) { if (oldValue) { oldValue.owner = null; } if (newValue && this._owner) { newValue.owner = this._owner._nativeView; } } onInlineEventCellStyleChanged(oldValue, newValue) { this.prepareNativeStyle(newValue, null); } onShowWeekChanged(oldValue, newValue) { this.changeShowWeek(oldValue, newValue); } changeShowWeek(oldValue, newValue) { if (!this._owner || !this._owner._nativeView) { return; } this._owner._nativeView.setShowWeekInDayMode(newValue); } } /** * The year mode style class */ export class CalendarYearViewStyle extends commonModule.CalendarYearViewStyle { constructor() { super(); } // @ts-ignore set owner(value) {