2 using System.Threading.Tasks;
3 using System.Collections.Generic;
7 using Tizen.CallManager;
9 namespace XamarinForTizen.Tizen
11 public class MainPage : ContentPage
15 var initBtn = new Button
18 VerticalOptions = LayoutOptions.Start,
19 HorizontalOptions = LayoutOptions.FillAndExpand
21 initBtn.Clicked += initBtn_Clicked;
23 var dialBtn = new Button
25 Text = "Dial & end voice call",
26 VerticalOptions = LayoutOptions.Start,
27 HorizontalOptions = LayoutOptions.FillAndExpand
29 dialBtn.Clicked += dialBtn_Clicked;
31 var holdBtn = new Button
33 Text = "Hold & unhold voice call",
34 VerticalOptions = LayoutOptions.Start,
35 HorizontalOptions = LayoutOptions.FillAndExpand
37 holdBtn.Clicked += holdBtn_Clicked;
39 var answerBtn = new Button
41 Text = "Answer incoming call",
42 VerticalOptions = LayoutOptions.Start,
43 HorizontalOptions = LayoutOptions.FillAndExpand
45 answerBtn.Clicked += answerBtn_Clicked;
47 var alertBtn = new Button
49 Text = "Start & Stop alert",
50 VerticalOptions = LayoutOptions.Start,
51 HorizontalOptions = LayoutOptions.FillAndExpand
53 alertBtn.Clicked += alertBtn_Clicked;
55 var rejectBtn = new Button
57 Text = "Reject incoming call",
58 VerticalOptions = LayoutOptions.Start,
59 HorizontalOptions = LayoutOptions.FillAndExpand
61 rejectBtn.Clicked += rejectBtn_Clicked;
63 var swapBtn = new Button
66 VerticalOptions = LayoutOptions.Start,
67 HorizontalOptions = LayoutOptions.FillAndExpand
69 swapBtn.Clicked += swapBtn_Clicked;
71 var joinBtn = new Button
74 VerticalOptions = LayoutOptions.Start,
75 HorizontalOptions = LayoutOptions.FillAndExpand
77 joinBtn.Clicked += joinBtn_Clicked;
79 var splitBtn = new Button
82 VerticalOptions = LayoutOptions.Start,
83 HorizontalOptions = LayoutOptions.FillAndExpand
85 splitBtn.Clicked += splitBtn_Clicked;
87 var getAllCallListBtn = new Button
89 Text = "Get all call list",
90 VerticalOptions = LayoutOptions.Start,
91 HorizontalOptions = LayoutOptions.FillAndExpand
93 getAllCallListBtn.Clicked += getAllCallListBtn_Clicked;
95 var getConfCallListBtn = new Button
97 Text = "Get conf call list",
98 VerticalOptions = LayoutOptions.Start,
99 HorizontalOptions = LayoutOptions.FillAndExpand
101 getConfCallListBtn.Clicked += getConfCallListBtn_Clicked;
103 var getCallDataBtn = new Button
105 Text = "Get all call data",
106 VerticalOptions = LayoutOptions.Start,
107 HorizontalOptions = LayoutOptions.FillAndExpand
109 getCallDataBtn.Clicked += getCallDataBtn_Clicked;
111 var statusBtn = new Button
113 Text = "Get call status",
114 VerticalOptions = LayoutOptions.Start,
115 HorizontalOptions = LayoutOptions.FillAndExpand
117 statusBtn.Clicked += statusBtn_Clicked;
119 var deinitBtn = new Button
121 Text = "Deinitialize",
122 VerticalOptions = LayoutOptions.Start,
123 HorizontalOptions = LayoutOptions.FillAndExpand
125 deinitBtn.Clicked += deinitBtn_Clicked;
127 Content = new StackLayout
129 VerticalOptions = LayoutOptions.Center,
131 initBtn, dialBtn, holdBtn, answerBtn, alertBtn, rejectBtn, swapBtn, joinBtn, splitBtn,
132 getAllCallListBtn, getConfCallListBtn, getCallDataBtn, statusBtn, deinitBtn
137 private void getCallDataBtn_Clicked(object sender, EventArgs e)
141 if (Globals.cmHandle == null)
143 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
147 Globals.cmHandle.GetAllCallData(out CallData incoming, out CallData active, out CallData held);
148 if (incoming == null)
150 Log.Debug(Globals.LogTag, "No incoming call");
155 Log.Debug(Globals.LogTag, "Incoming call Id: " + incoming.Id);
156 Log.Debug(Globals.LogTag, "Incoming call number: " + incoming.CallNumber);
161 Log.Debug(Globals.LogTag, "No active calls");
166 Log.Debug(Globals.LogTag, "Active call Id: " + active.Id);
167 Log.Debug(Globals.LogTag, "Active call number: " + active.CallNumber);
172 Log.Debug(Globals.LogTag, "No held calls");
177 Log.Debug(Globals.LogTag, "Held call Id: " + held.Id);
178 Log.Debug(Globals.LogTag, "Held call number: " + held.CallNumber);
184 Log.Debug(Globals.LogTag, "Get all call data exception: " + ex.ToString());
188 private void getConfCallListBtn_Clicked(object sender, EventArgs e)
192 if (Globals.cmHandle == null)
194 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
198 List<ConferenceCallData> confCallList = Globals.cmHandle.AllConferenceCalls.ToList();
199 if (confCallList.Count == 0)
201 Log.Debug(Globals.LogTag, "Conf call list is empty");
205 for (int i = 0; i < confCallList.Count; i++)
207 Log.Debug(Globals.LogTag, "ID[" + i + "]: " + confCallList[i].Id);
208 Log.Debug(Globals.LogTag, "Number[" + i + "]: " + confCallList[i].CallNumber);
209 Log.Debug(Globals.LogTag, "PersonId[" + i + "]: " + confCallList[i].PersonId);
210 Log.Debug(Globals.LogTag, "Mode[" + i + "]: " + confCallList[i].Mode);
216 Log.Debug(Globals.LogTag, "Get all conf call list exception: " + ex.ToString());
220 private void getAllCallListBtn_Clicked(object sender, EventArgs e)
224 if (Globals.cmHandle == null)
226 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
230 List<CallData> callDataList = Globals.cmHandle.AllCalls.ToList();
231 if (callDataList.Count == 0)
233 Log.Debug(Globals.LogTag, "Call data list is empty");
237 for (int i = 0; i < callDataList.Count; i++)
239 Log.Debug(Globals.LogTag, "Call ID[" + i +"]: " + callDataList[i].Id);
240 Log.Debug(Globals.LogTag, "Number[" + i + "]: " + callDataList[i].CallNumber);
241 Log.Debug(Globals.LogTag, "Call direction[" + i + "]: " + callDataList[i].Direction);
242 Log.Debug(Globals.LogTag, "Name[" + i + "]: " + callDataList[i].CallingName);
243 Log.Debug(Globals.LogTag, "Call type[" + i + "]: " + callDataList[i].Type);
244 Log.Debug(Globals.LogTag, "Call state[" + i + "]: " + callDataList[i].State);
245 Log.Debug(Globals.LogTag, "Member count[" + i + "]: " + callDataList[i].MemberCount);
246 Log.Debug(Globals.LogTag, "Is Ecc[" + i + "]: " + callDataList[i].IsEmergency);
247 Log.Debug(Globals.LogTag, "Call domain[" + i + "]: " + callDataList[i].Domain);
248 Log.Debug(Globals.LogTag, "Start time[" + i + "]: " + callDataList[i].StartTime);
254 Log.Debug(Globals.LogTag, "Get all call list exception: " + ex.ToString());
258 private void splitBtn_Clicked(object sender, EventArgs e)
262 if (Globals.cmHandle == null)
264 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
268 Globals.cmHandle.SplitCall(1);
273 Log.Debug(Globals.LogTag, "Split call exception: " + ex.ToString());
277 private void joinBtn_Clicked(object sender, EventArgs e)
281 if (Globals.cmHandle == null)
283 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
287 Globals.cmHandle.JoinCall();
292 Log.Debug(Globals.LogTag, "Join call exception: " + ex.ToString());
296 private void swapBtn_Clicked(object sender, EventArgs e)
300 if (Globals.cmHandle == null)
302 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
306 Globals.cmHandle.SwapCall();
311 Log.Debug(Globals.LogTag, "Swap call exception: " + ex.ToString());
315 private void statusBtn_Clicked(object sender, EventArgs e)
319 if (Globals.cmHandle == null)
321 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
325 Log.Debug(Globals.LogTag, "Call status: " + Globals.cmHandle.CallStatus);
330 Log.Debug(Globals.LogTag, "Get call status exception: " + ex.ToString());
334 private void rejectBtn_Clicked(object sender, EventArgs e)
338 if (Globals.cmHandle == null)
340 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
344 Globals.cmHandle.RejectCall();
349 Log.Debug(Globals.LogTag, "Reject call exception: " + ex.ToString());
353 private async void alertBtn_Clicked(object sender, EventArgs e)
357 if (Globals.cmHandle == null)
359 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
363 Globals.cmHandle.CallStatusChanged += CmHandle_CallStatusChanged;
364 Globals.cmHandle.StopAlert();
365 await Task.Delay(5000);
366 Globals.cmHandle.StartAlert();
371 Log.Debug(Globals.LogTag, "Call alert exception: " + ex.ToString());
375 private void CmHandle_CallStatusChanged(object sender, CallStatusChangedEventArgs e)
377 Log.Debug(Globals.LogTag, "Call status changed: " + e.CallNumber + e.Status);
380 private void answerBtn_Clicked(object sender, EventArgs e)
384 if (Globals.cmHandle == null)
386 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
390 Globals.cmHandle.AnswerCall(CallAnswerType.Normal);
395 Log.Debug(Globals.LogTag, "Answer call exception: " + ex.ToString());
399 private async void holdBtn_Clicked(object sender, EventArgs e)
403 if (Globals.cmHandle == null)
405 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
409 Globals.HoldTest = true;
410 Globals.cmHandle.DialCall(Globals.Number, CallType.Voice, MultiSimSlot.Default);
411 await Task.Delay(20000);
412 Globals.cmHandle.HoldCall();
413 await Task.Delay(8000);
414 Globals.cmHandle.UnholdCall();
415 await Task.Delay(8000);
416 Globals.cmHandle.EndCall(1, CallReleaseType.AllActiveCalls);
421 Log.Debug(Globals.LogTag, "Hold call exception: " + ex.ToString());
425 private async void dialBtn_Clicked(object sender, EventArgs e)
429 if (Globals.cmHandle == null)
431 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
435 Globals.cmHandle.DialCall(Globals.Number, CallType.Voice, MultiSimSlot.Default);
436 await Task.Delay(20000);
437 Globals.cmHandle.EndCall(1, CallReleaseType.AllCalls);
442 Log.Debug(Globals.LogTag, "Dial call exception: " + ex.ToString());
446 private void deinitBtn_Clicked(object sender, EventArgs e)
450 if (Globals.cmHandle == null)
452 Log.Debug(Globals.LogTag, "Not initialized!!!!!");
456 CallManager.DeinitCm(Globals.cmHandle);
457 Globals.cmHandle = null;
458 Log.Debug(Globals.LogTag, "Callmanager deinitialized successfully");
463 Log.Debug(Globals.LogTag, "Callmanager deinit exception: " + ex.ToString());
467 private void initBtn_Clicked(object sender, EventArgs e)
471 if (Globals.cmHandle != null)
473 Log.Debug(Globals.LogTag, "Already initialized!!!!!");
477 Globals.cmHandle = CallManager.InitCm();
478 Globals.cmHandle.EnableRecovery("Tizen.CallManager.Test");
479 Log.Debug(Globals.LogTag, "Callmanager initialization is successful");
484 Log.Debug(Globals.LogTag, "Callmanager init exception: " + ex.ToString());
488 private async void CmHandle_CallEventChangedAsync(object sender, CallEventEventArgs e)
492 Log.Debug(Globals.LogTag, "Call event changed handler, CallEvent: " + e.Event);
493 if (e.EventData != null)
495 Log.Debug(Globals.LogTag, "Call ID: " + e.EventData.Id);
496 Log.Debug(Globals.LogTag, "Sim slot: " + e.EventData.SimSlot);
497 Log.Debug(Globals.LogTag, "Call end cause: " + e.EventData.EndCause);
500 if (Globals.DialTest && e.Event == CallEvent.Active)
502 Globals.DialTest = false;
503 await Task.Delay(3000);
504 Globals.cmHandle.EndCall(e.EventData.Id, CallReleaseType.ByCallHandle);
507 if (Globals.HoldTest && e.Event == CallEvent.Active)
509 await Task.Delay(3000);
510 Globals.cmHandle.HoldCall();
513 if (Globals.HoldTest && e.Event == CallEvent.Held)
515 Globals.HoldTest = false;
516 await Task.Delay(8000);
517 Globals.cmHandle.UnholdCall();
518 await Task.Delay(8000);
519 Globals.cmHandle.EndCall(e.EventData.Id, CallReleaseType.AllActiveCalls);
525 Log.Debug(Globals.LogTag, "End call exception: " + ex.ToString());
531 if (Globals.cmHandle != null)
533 CallManager.DeinitCm(Globals.cmHandle);
534 Globals.cmHandle = null;