forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Customization.cs
347 lines (302 loc) · 11.5 KB
/
Customization.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#region Copyright Syncfusion Inc. 2001-2022.
// Copyright Syncfusion Inc. 2001-2022. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.Collections.Generic;
using Syncfusion.SfSchedule.iOS;
using System.Collections.ObjectModel;
#if __UNIFIED__
using Foundation;
using UIKit;
using CoreGraphics;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using CGRect = System.Drawing.RectangleF;
using CGPoint = System.Drawing.PointF;
using CGSize = System.Drawing.SizeF;
using nfloat = System.Single;
using System.Drawing;
#endif
namespace SampleBrowser
{
public class Customization : SampleView
{
private SFSchedule schedule;
private readonly IList<string> scheduleTypes = new List<string>();
private string selectedType;
private UIPickerView scheduleTypePicker = new UIPickerView();
private UILabel label = new UILabel();
private UIButton button = new UIButton();
private UIButton textbutton = new UIButton();
private UISegmentedControl customizationSegment = new UISegmentedControl();
private HeaderStyle headerStyle;
private SFViewHeaderStyle viewHeaderStyle;
public Customization()
{
schedule = new SFSchedule();
label.Text = "Select the Schedule Type";
label.TextColor = UIColor.Black;
headerStyle = new HeaderStyle();
viewHeaderStyle = new SFViewHeaderStyle();
schedule.HeaderHeight = 30;
schedule.MonthCellLoaded += Schedule_MonthCellLoaded;
schedule.AppointmentLoaded += Schedule_AppointmentLoaded;
textbutton.SetTitle("Day View", UIControlState.Normal);
textbutton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
textbutton.BackgroundColor = UIColor.Clear;
textbutton.SetTitleColor(UIColor.Black, UIControlState.Normal);
textbutton.Hidden = false;
textbutton.Layer.BorderColor = UIColor.FromRGB(246, 246, 246).CGColor;
textbutton.Layer.BorderWidth = 4;
textbutton.Layer.CornerRadius = 8;
textbutton.TouchUpInside += ShowPicker;
button.SetTitle("Done\t", UIControlState.Normal);
button.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
button.BackgroundColor = UIColor.FromRGB(240, 240, 240);
button.SetTitleColor(UIColor.Black, UIControlState.Normal);
button.Hidden = true;
button.TouchUpInside += HidePicker;
schedule.ItemsSource = CreateAppointments();
schedule.ScheduleView = SFScheduleView.SFScheduleViewDay;
schedule.DayViewSettings = new DayViewSettings();
schedule.DayViewSettings.TimeTextColor = UIColor.FromRGB(168, 168, 173);
schedule.DayViewSettings.TimeSlotBorderColor = UIColor.FromRGB(219, 219, 219);
schedule.DayViewSettings.NonWorkingHourTimeSlotBorderColor = UIColor.FromRGB(219, 219, 219);
UIButton selectionView = new UIButton();
selectionView.BackgroundColor = UIColor.FromRGB(0, 122, 255);
selectionView.SetTitle("+ New Event", UIControlState.Normal);
schedule.SelectionView = selectionView;
viewHeaderStyle.BackgroundColor = UIColor.FromRGB(247, 247, 247);
viewHeaderStyle.DayTextStyle = UIFont.SystemFontOfSize(18);
viewHeaderStyle.DayTextColor = UIColor.FromRGB(3, 3, 3);
headerStyle.TextPosition = UITextAlignment.Center;
headerStyle.TextColor = UIColor.FromRGB(3, 3, 3);
schedule.HeaderStyle = headerStyle;
schedule.DayHeaderStyle = viewHeaderStyle;
schedule.AppointmentViewLayout = SFViewLayoutOptions.Overlay;
this.scheduleTypes.Add((NSString)"Day View");
this.scheduleTypes.Add((NSString)"Month View");
Localization.SchedulePickerModel model = new Localization.SchedulePickerModel(this.scheduleTypes);
model.PickerChanged += (sender, e) =>
{
this.selectedType = e.SelectedValue;
textbutton.SetTitle(selectedType, UIControlState.Normal);
if (selectedType == "Day View")
{
schedule.ScheduleView = SFScheduleView.SFScheduleViewDay;
}
else if (selectedType == "Month View")
{
schedule.ScheduleView = SFScheduleView.SFScheduleViewMonth;
}
};
scheduleTypePicker.ShowSelectionIndicator = true;
scheduleTypePicker.Hidden = true;
scheduleTypePicker.Model = model;
scheduleTypePicker.BackgroundColor = UIColor.White;
}
private void Schedule_AppointmentLoaded(object sender, AppointmentLoadedEventArgs e)
{
if (e.Appointment.Subject == "Checkup")
{
UIImageView hospitalImage = new UIImageView();
hospitalImage.Image = UIImage.FromFile("Images/Hospital.png");
hospitalImage.Frame = new CGRect(50, 35, 50.0f, 50.0f);
UIStackView stackPanel = new UIStackView();
stackPanel.Frame = new CGRect(0, 0, 100, 50);
stackPanel.Add(hospitalImage);
e.AppointmentStyle.TextStyle = UIFont.FromName(@"Arial", 16);
e.AppointmentStyle.TextColor = UIColor.White;
e.View = stackPanel;
}
else
{
UIImageView familyImage = new UIImageView();
familyImage.Image = UIImage.FromFile("Images/family.png");
familyImage.Frame = new CGRect(50, 35, 50.0f, 30.0f);
UIStackView stackPanel = new UIStackView();
stackPanel.Frame = new CGRect(0, 0, 100, 30);
stackPanel.Add(familyImage);
e.AppointmentStyle.TextStyle = UIFont.FromName(@"Arial", 16);
e.AppointmentStyle.TextColor = UIColor.White;
e.View = stackPanel;
}
}
private void Schedule_MonthCellLoaded(object sender, MonthCellLoadedEventArgs e)
{
NSDate date = e.Date;
NSDateFormatter dateFormat = new NSDateFormatter();
dateFormat.DateFormat = "EEEE";
string monthName = dateFormat.ToString(date);
if (e.IsToday)
{
e.CellStyle.TextColor = UIColor.FromRGB(238, 199, 43);
}
if ((monthName == "Sunday") || (monthName == "Saturday"))
{
e.CellStyle.TextColor = UIColor.Red;
}
if (e.IsPreviousMonthDate)
{
e.CellStyle.TextColor = UIColor.White;
}
if (e.IsNextMonthDate)
{
e.CellStyle.TextColor = UIColor.White;
}
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (textbutton != null)
{
textbutton.TouchUpInside -= ShowPicker;
textbutton.Dispose();
textbutton = null;
}
if (button != null)
{
button.TouchUpInside -= HidePicker;
button.Dispose();
button = null;
}
if (schedule != null)
{
schedule.MonthCellLoaded -= Schedule_MonthCellLoaded;
schedule.AppointmentLoaded -= Schedule_AppointmentLoaded;
this.schedule.Dispose();
this.schedule = null;
}
if(scheduleTypePicker != null)
{
scheduleTypePicker.Dispose();
scheduleTypePicker = null;
}
if (label != null)
{
label.Dispose();
label = null;
}
if (customizationSegment != null)
{
customizationSegment.Dispose();
customizationSegment = null;
}
}
base.Dispose(disposing);
}
private void ShowPicker(object sender, EventArgs e)
{
button.Hidden = false;
scheduleTypePicker.Hidden = false;
this.BecomeFirstResponder();
}
private void HidePicker(object sender, EventArgs e)
{
button.Hidden = true;
scheduleTypePicker.Hidden = true;
this.BecomeFirstResponder();
}
public override void LayoutSubviews()
{
string deviceType = UIDevice.CurrentDevice.Model;
if (deviceType == "iPhone" || deviceType == "iPod touch")
{
label.Frame = new CGRect(15, 10, this.Frame.Size.Width - 20, 40);
textbutton.Frame = new CGRect(10, 50, this.Frame.Size.Width - 20, 40);
button.Frame = new CGRect(this.Frame.X + 10, 90, this.Frame.Size.Width - 20, 30);
scheduleTypePicker.Frame = new CGRect(0, 120, this.Frame.Size.Width - 20, 150);
}
else
{
schedule.DayViewSettings.WorkStartHour = 7;
schedule.DayViewSettings.WorkEndHour = 18;
label.Frame = new CGRect(15, 10, this.Frame.Size.Width - 20, 40);
textbutton.Frame = new CGRect(10, 60, this.Frame.Size.Width / 2.5, 40);
button.Frame = new CGRect(this.Frame.X + 10, 100, this.Frame.Size.Width / 2.5, 30);
scheduleTypePicker.Frame = new CGRect(0, 120, this.Frame.Size.Width / 2.5, 120);
}
customizationSegment.InsertSegment("Day", 0, false);
customizationSegment.InsertSegment("Month", 1, false);
customizationSegment.SelectedSegment = 0;
customizationSegment.ValueChanged += (sender, e) =>
{
var selectedSegmentId = (sender as UISegmentedControl).SelectedSegment;
if (selectedSegmentId == 0)
{
schedule.ScheduleView = SFScheduleView.SFScheduleViewDay;
}
else if (selectedSegmentId == 1)
{
schedule.ScheduleView = SFScheduleView.SFScheduleViewMonth;
}
};
this.AddSubview(customizationSegment);
schedule.Frame = new CGRect(0, 0, this.Frame.Size.Width, this.Frame.Size.Height);
this.AddSubview(schedule);
}
private void CreateOptionView()
{
this.OptionView.AddSubview(label);
this.OptionView.AddSubview(textbutton);
this.OptionView.AddSubview(scheduleTypePicker);
this.OptionView.AddSubview(button);
}
private ObservableCollection<ScheduleAppointment> CreateAppointments()
{
NSDate today = new NSDate();
NSCalendar calendar = NSCalendar.CurrentCalendar;
// Get the year, month, day from the date
NSDateComponents components = calendar.Components(
NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
// Set the hour, minute, second
components.Hour = 10;
components.Minute = 0;
components.Second = 0;
NSDate startDate = calendar.DateFromComponents(components);
// Get the year, month, day from the date
NSDateComponents endDateComponents = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
// Set the hour, minute, second
endDateComponents.Hour = 12;
endDateComponents.Minute = 0;
endDateComponents.Second = 0;
NSDate endDate = calendar.DateFromComponents(endDateComponents);
ScheduleAppointment appointment = new ScheduleAppointment();
appointment.StartTime = startDate;
appointment.EndTime = endDate;
appointment.Subject = new NSString("Jeni's B'Day Celebration");
appointment.AppointmentBackground = UIColor.FromRGB(0xA2, 0xC1, 0x39);
NSDateComponents components1 = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
// Set the hour, minute, second
components1.Hour = 11;
components1.Minute = 0;
components1.Second = 0;
components1.Day = components1.Day + 1;
NSDate startDate1 = calendar.DateFromComponents(components1);
// Get the year, month, day from the date
NSDateComponents endDateComponents1 = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
// Set the hour, minute, second
endDateComponents1.Hour = 13;
endDateComponents1.Minute = 30;
endDateComponents1.Second = 0;
endDateComponents1.Day = endDateComponents1.Day + 1;
NSDate endDate1 = calendar.DateFromComponents(endDateComponents1);
ScheduleAppointment appointment1 = new ScheduleAppointment();
appointment1.StartTime = startDate1;
appointment1.EndTime = endDate1;
appointment1.Subject = new NSString("Checkup");
appointment1.AppointmentBackground = UIColor.FromRGB(0xD8, 0x00, 0x73);
ObservableCollection<ScheduleAppointment> appCollection = new ObservableCollection<ScheduleAppointment>();
appCollection.Add(appointment);
appCollection.Add(appointment1);
return appCollection;
}
}
}