forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScheduleGettingStarted.cs
420 lines (374 loc) · 14.3 KB
/
ScheduleGettingStarted.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#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 System.Collections.ObjectModel;
using Android.Content;
using Android.Graphics;
using Android.Views;
using Android.Widget;
using Java.Util;
using Com.Syncfusion.Schedule.Enums;
using Com.Syncfusion.Schedule;
using Android.Runtime;
namespace SampleBrowser
{
[Preserve(AllMembers = true)]
public class ScheduleGettingStarted : SamplePage, IDisposable
{
/// <summary>
/// Variable for Schedule
/// </summary>
private SfSchedule schedule;
/// <summary>
/// Custom appointment variable
/// </summary>
private Meeting meeting;
/// <summary>
/// Custom appointment collection
/// </summary>
private ObservableCollection<Meeting> appointmentCollection;
/// <summary>
/// Spinner to select schedule view
/// </summary>
private Spinner spinner;
/// <summary>
/// Option view to change schedule view
/// </summary>
private LinearLayout propertyLayout;
public ScheduleGettingStarted()
{
}
public override View GetSampleContent(Context context)
{
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.Orientation = Orientation.Vertical;
schedule = new SfSchedule(context);
propertyLayout = new LinearLayout(context);
propertyLayout = SetOptionPage(context);
// Schedule custom appointment mapping
AppointmentMapping mapping = new AppointmentMapping();
mapping.StartTime = "From";
mapping.EndTime = "To";
mapping.Subject = "EventName";
mapping.IsAllDay = "IsAllDay";
mapping.MinHeight = "MinimumHeight";
mapping.Color = "Color";
schedule.AppointmentMapping = mapping;
schedule.ScheduleView = ScheduleView.WeekView;
schedule.MonthViewSettings.ShowAppointmentsInline = true;
GetAppointments();
schedule.ItemsSource = appointmentCollection;
schedule.LayoutParameters = new FrameLayout.LayoutParams(
LinearLayout.LayoutParams.MatchParent,
LinearLayout.LayoutParams.MatchParent);
linearLayout.AddView(schedule);
return linearLayout;
}
/// <summary>
/// Custom appointment subject collection
/// </summary>
private List<string> eventCollection;
/// <summary>
/// Custom appointment start time collection
/// </summary>
private List<Calendar> fromCollection;
/// <summary>
/// Custom appointment end time collection
/// </summary>
private List<Calendar> toCollection;
/// <summary>
/// Custom appointment color collection
/// </summary>
private List<string> colorCollection;
/// <summary>
/// Collection of random numbers to get start time and end time
/// </summary>
private List<int> randomNumbers;
/// <summary>
/// Gets the appointments collection
/// </summary>
private void GetAppointments()
{
appointmentCollection = new ObservableCollection<Meeting>();
SetEventCollection();
RandomNumbers();
SetFromCollection();
SetToCollection();
SetColorCollection();
for (int i = 0; i < 15; i++)
{
meeting = new Meeting();
meeting.Color = Color.ParseColor(colorCollection[i]);
meeting.EventName = eventCollection[i];
meeting.From = fromCollection[i];
// To create all day appointments
if (i % 6 == 0 && i != 0)
{
meeting.IsAllDay = true;
}
// To create two days span appointment
if (i % 5 == 0 && i != 0)
{
toCollection[i] = (Calendar)fromCollection[i].Clone();
var date = toCollection[i].Get(CalendarField.DayOfMonth) + 2;
toCollection[i].Set(CalendarField.DayOfMonth, date);
}
// To create 24 hour span appointments
if (i % 7 == 0)
{
toCollection[i] = (Calendar)fromCollection[i].Clone();
var hour = toCollection[i].Get(CalendarField.Hour) + 23;
var min = toCollection[i].Get(CalendarField.Minute) + 59;
toCollection[i].Set(CalendarField.Hour, hour);
toCollection[i].Set(CalendarField.Minute, min);
}
// To create minimum height appointments
if (eventCollection[i].Contains("alert"))
{
toCollection[i] = (Calendar)fromCollection[i].Clone();
meeting.MinimumHeight = 50;
}
meeting.To = toCollection[i];
appointmentCollection.Add(meeting);
}
}
/// <summary>
/// Gets the random numbers to get start time and end time
/// </summary>
private void RandomNumbers()
{
randomNumbers = new List<int>();
Java.Util.Random rand = new Java.Util.Random();
for (int i = 0; i < 20; i++)
{
int randomNum = rand.NextInt((15 - 9) + 1) + 9;
randomNumbers.Add(randomNum);
}
}
/// <summary>
/// Sets the color collection for custom appointment
/// </summary>
private void SetColorCollection()
{
colorCollection = new List<string>();
colorCollection.Add("#FFA2C139");
colorCollection.Add("#FFD80073");
colorCollection.Add("#FF1BA1E2");
colorCollection.Add("#FFE671B8");
colorCollection.Add("#FFF09609");
colorCollection.Add("#FFA2C139");
colorCollection.Add("#FFD80073");
colorCollection.Add("#FF1BA1E2");
colorCollection.Add("#FFE671B8");
colorCollection.Add("#FFF09609");
colorCollection.Add("#FFA2C139");
colorCollection.Add("#FFD80073");
colorCollection.Add("#FF1BA1E2");
colorCollection.Add("#FFE671B8");
colorCollection.Add("#FFF09609");
colorCollection.Add("#FFA2C139");
colorCollection.Add("#FFD80073");
colorCollection.Add("#FF1BA1E2");
colorCollection.Add("#FFE671B8");
colorCollection.Add("#FFF09609");
colorCollection.Add("#FFA2C139");
colorCollection.Add("#FFD80073");
colorCollection.Add("#FF1BA1E2");
colorCollection.Add("#FFE671B8");
colorCollection.Add("#FFF09609");
colorCollection.Add("#FFA2C139");
colorCollection.Add("#FFD80073");
colorCollection.Add("#FF1BA1E2");
colorCollection.Add("#FFE671B8");
colorCollection.Add("#FFF09609");
}
/// <summary>
/// Sets the end time for custom appointments
/// </summary>
private void SetToCollection()
{
toCollection = new List<Calendar>();
Calendar currentDate = Calendar.Instance;
int count = 0;
for (int i = -10; i < 10; i++)
{
Calendar to = (Calendar)currentDate.Clone();
to.Set(
currentDate.Get(CalendarField.Year),
currentDate.Get(CalendarField.Month),
currentDate.Get(CalendarField.DayOfMonth) + i,
randomNumbers[count] + 2,
0,
0);
toCollection.Add(to);
count++;
}
}
/// <summary>
/// Sets the start time collection for custom appointments
/// </summary>
private void SetFromCollection()
{
fromCollection = new List<Calendar>();
Calendar currentDate = Calendar.Instance;
int count = 0;
for (int i = -10; i < 10; i++)
{
Calendar from = (Calendar)currentDate.Clone();
from.Set(
currentDate.Get(CalendarField.Year),
currentDate.Get(CalendarField.Month),
currentDate.Get(CalendarField.DayOfMonth) + i,
randomNumbers[count],
0,
0);
fromCollection.Add(from);
count++;
}
}
/// <summary>
/// Sets the subject collection for custom appointment
/// </summary>
private void SetEventCollection()
{
eventCollection = new List<string>();
eventCollection.Add("General Meeting");
eventCollection.Add("Plan Execution");
eventCollection.Add("Project Plan");
eventCollection.Add("Consulting");
eventCollection.Add("Performance Check");
eventCollection.Add("Yoga Therapy");
eventCollection.Add("Plan Execution");
eventCollection.Add("Project Plan");
eventCollection.Add("Consulting");
eventCollection.Add("Performance Check");
eventCollection.Add("Work log alert");
eventCollection.Add("Birthday wish alert");
eventCollection.Add("Task due date");
eventCollection.Add("Status mail");
eventCollection.Add("Start sprint alert");
}
/// <summary>
/// Sets the option page to change schedule view
/// </summary>
/// <param name="context">Context of this view</param>
/// <returns>Option layout</returns>
private LinearLayout SetOptionPage(Context context)
{
TextView scheduleType_txtBlock = new TextView(context);
scheduleType_txtBlock.Text = "Schedule View";
scheduleType_txtBlock.TextSize = 20;
scheduleType_txtBlock.SetPadding(0, 0, 0, 10);
scheduleType_txtBlock.SetTextColor(Color.Black);
LinearLayout layout = new LinearLayout(context);
layout.SetPadding(15, 15, 15, 20);
layout.Orientation = Android.Widget.Orientation.Vertical;
layout.SetBackgroundColor(Color.White);
spinner = new Spinner(context, SpinnerMode.Dialog);
spinner.SetMinimumHeight(60);
spinner.SetBackgroundColor(Color.Gray);
spinner.DropDownWidth = 500;
layout.AddView(scheduleType_txtBlock);
layout.AddView(spinner);
List<string> list = new List<string>();
list.Add("Week View");
list.Add("Day View");
list.Add("Work Week View");
list.Add("Month View");
ArrayAdapter<string> dataAdapter = new ArrayAdapter<string>(context, Android.Resource.Layout.SimpleSpinnerItem, list);
dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = dataAdapter;
spinner.ItemSelected += Spinner_ItemSelected;
return layout;
}
/// <summary>
/// Event occurs when item selected in the spinner to change schedule view
/// </summary>
/// <param name="sender">Sender of the event</param>
/// <param name="e">Arguments of the event</param>
private void Spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
if (e.Position == 0)
{
schedule.ScheduleView = ScheduleView.WeekView;
}
else if (e.Position == 1)
{
schedule.ScheduleView = ScheduleView.DayView;
}
else if (e.Position == 2)
{
schedule.ScheduleView = ScheduleView.WorkWeekView;
}
else if (e.Position == 3)
{
schedule.ScheduleView = ScheduleView.MonthView;
}
}
/// <summary>
/// Adds the property layout to the view
/// </summary>
/// <param name="context">Context of the view</param>
/// <returns>Property layout</returns>
public override View GetPropertyWindowLayout(Context context)
{
return propertyLayout;
}
public void Dispose()
{
if (schedule != null)
{
schedule.Dispose();
schedule = null;
}
if (propertyLayout != null)
{
propertyLayout.Dispose();
propertyLayout = null;
}
if (spinner != null)
{
spinner.ItemSelected -= Spinner_ItemSelected;
spinner.Dispose();
spinner = null;
}
}
}
/// <summary>
/// Custom appointment class
/// </summary>
[Preserve(AllMembers = true)]
public class Meeting
{
/// <summary>
/// Gets or sets the Event name for the meeting
/// </summary>
public string EventName { get; set; }
/// <summary>
/// Gets or sets the From time for the meeting
/// </summary>
public Calendar From { get; set; }
/// <summary>
/// Gets or sets the To time for the meeting
/// </summary>
public Calendar To { get; set; }
/// <summary>
/// Gets or sets the color for the meeting
/// </summary>
public int Color { get; set; }
/// <summary>
/// Gets or sets the minimum height for the meeting
/// </summary>
public double MinimumHeight { get; set; }
/// <summary>
/// Gets or sets a value to indicate whether the meeting is all day or not
/// </summary>
public bool IsAllDay { get; set; }
}
}