Add WatchfaceComplication.dll and fix some bugs (#703)
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.WatchfaceComplication / Tizen.Applications / Complication.cs
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20
21
22 namespace Tizen.Applications.WatchfaceComplication
23 {
24     /// <summary>
25     /// Represents the Complication class for the watch application which using watchface complication.
26     /// </summary>
27     /// <since_tizen> 6 </since_tizen>
28     public abstract class Complication : IEditable, IDisposable
29     {
30         private int _complicationId;
31         private ComplicationTypes _supportTypes;
32         private string _defaultProviderId;
33         private ComplicationTypes _defaultType;
34         private EventTypes _supportEvents;
35         private Highlight _highlight;
36         internal IntPtr _handle;
37         private Interop.WatchfaceComplication.ComplicationUpdatedCallback _updatedCallback;
38         private Interop.WatchfaceComplication.ComplicationErrorCallback _errorCallback;
39         private IEnumerable<(string allowedProviderId, ComplicationTypes supportTypes)> _allowedList;
40         private int _editableId;
41         private bool _disposed = false;
42
43         /// <summary>
44         /// Initializes the Complication class.
45         /// </summary>
46         /// <param name="complicationId">The id of the complication.</param>
47         /// <param name="supportTypes">The complication support types.</param>
48         /// <param name="supportEvents">The complication's support events.</param>
49         /// <param name="defaultProviderId">The complication's default provider ID.</param>
50         /// <param name="defaultType">The complication's default type.</param>
51         /// <privilege>http://tizen.org/privilege/datasharing</privilege>
52         /// <privilege>http://tizen.org/privilege/packagemanager.info</privilege>
53         /// <exception cref="ArgumentException">Thrown when the invalid parameter is passed.</exception>
54         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
55         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
56         /// <exception cref="UnauthorizedAccessException">Thrown when the application does not have privilege to access this method.</exception>
57         /// <example>
58         /// <code>
59         ///
60         /// public class MyComplication : Complication
61         /// {
62         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
63         ///        ComplicationTypes defaultType)
64         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
65         ///    {
66         ///    }
67         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
68         ///    {
69         ///    }
70         /// }
71         /// _complication = new MyComplication(_complicationId, (int)(ComplicationTypes.ShortText | ComplicationTypes.Image),
72         ///       (int) EventTypes.EventNone, _complicationProviderId, ComplicationTypes.ShortText, _complicationBtn);
73         ///
74         /// </code>
75         /// </example>
76         /// <since_tizen> 6 </since_tizen>
77         protected Complication(int complicationId, ComplicationTypes supportTypes, EventTypes supportEvents, string defaultProviderId, ComplicationTypes defaultType)
78         {
79             _complicationId = complicationId;
80             _supportTypes = supportTypes;
81             _supportEvents = supportEvents;
82             _defaultProviderId = defaultProviderId;
83             _defaultType = defaultType;
84
85             ComplicationError ret = Interop.WatchfaceComplication.CreateComplication(complicationId, defaultProviderId, defaultType, (int)supportTypes, (int)supportEvents, out _handle);
86             if (ret != ComplicationError.None)
87             {
88                 ErrorFactory.ThrowException(ret, "Fail to create complication");
89             }
90             _updatedCallback = new Interop.WatchfaceComplication.ComplicationUpdatedCallback(ComplicationUpdatedCallback);
91             _errorCallback = new Interop.WatchfaceComplication.ComplicationErrorCallback(ComplicationErrorCallback);
92             ret = Interop.WatchfaceComplication.AddUpdatedCallback(_handle, _updatedCallback, _errorCallback, IntPtr.Zero);
93             if (ret != ComplicationError.None)
94             {
95
96                 ErrorFactory.ThrowException(ret, "Fail to add update callback");
97             }
98         }
99
100         /// <summary>
101         /// Destructor of the complication class.
102         /// </summary>
103         ~Complication()
104         {
105             Dispose(true);
106         }
107
108         /// <summary>
109         /// Gets the support types.
110         /// </summary>
111         /// <since_tizen> 6 </since_tizen>
112         public ComplicationTypes SupportTypes
113         {
114             get
115             {
116                 return _supportTypes;
117             }
118         }
119
120         /// <summary>
121         /// Gets the support event types.
122         /// </summary>
123         /// <since_tizen> 6 </since_tizen>
124         public EventTypes SupportEvents
125         {
126             get
127             {
128                 return _supportEvents;
129             }
130         }
131
132         /// <summary>
133         /// The information of the editable's highlight.
134         /// </summary>
135         /// <since_tizen> 6 </since_tizen>
136         Highlight IEditable.Highlight
137         {
138             get
139             {
140                 return _highlight;
141             }
142             set
143             {
144                 _highlight = value;
145             }
146         }
147
148
149         /// <summary>
150         /// The information of specific allowed provider id, support types list for complication
151         /// </summary>
152         /// <since_tizen> 6 </since_tizen>
153         public IEnumerable<(string allowedProviderId, ComplicationTypes supportTypes)> AllowedList
154         {
155             get
156             {
157                 return _allowedList;
158             }
159             set
160             {
161                 _allowedList = value;
162                 if (_allowedList == null || _allowedList.Count() == 0)
163                 {
164                     Interop.WatchfaceComplication.ClearAllowedList(_handle);
165                 }
166                 else
167                 {
168                     IntPtr listRaw;
169                     Interop.WatchfaceComplication.CreateAllowedList(out listRaw);
170                     List<(string allowedProviderId, ComplicationTypes supportTypes)> list = _allowedList.ToList();
171                     foreach (var item in list)
172                     {
173                         Interop.WatchfaceComplication.AddAllowedList(listRaw, item.allowedProviderId, (int)item.supportTypes);
174                     }
175                     Interop.WatchfaceComplication.ApplyAllowedList(_handle, listRaw);
176                     Interop.WatchfaceComplication.DestroyAllowedList(listRaw);
177                 }
178
179             }
180         }
181
182         /// <summary>
183         /// The information of the complication's highlight.
184         /// </summary>
185         /// <since_tizen> 6 </since_tizen>
186         public Highlight Highlight
187         {
188             get
189             {
190                 return _highlight;
191             }
192             set
193             {
194                 _highlight = value;
195             }
196         }
197
198         /// <summary>
199         /// The information of complication ID.
200         /// </summary>
201         /// <since_tizen> 6 </since_tizen>
202         public int ComplicationId
203         {
204             get
205             {
206                 return _complicationId;
207             }
208         }
209
210         /// <summary>
211         /// The information of editable ID.
212         /// </summary>
213         /// <since_tizen> 6 </since_tizen>
214         int IEditable.EditableId
215         {
216             get
217             {
218                 return _editableId;
219             }
220             set
221             {
222                 _editableId = value;
223             }
224         }
225
226         /// <summary>
227         /// The information of editable name.
228         /// </summary>
229         /// <since_tizen> 6 </since_tizen>
230         string IEditable.Name
231         {
232             get
233             {
234                 string editableName = "";
235                 Interop.WatchfaceComplication.GetEditableName(_handle, out editableName);
236                 return editableName;
237             }
238             set
239             {
240                 Interop.WatchfaceComplication.SetEditableName(_handle, value);
241             }
242         }
243
244         /// <summary>
245         /// Gets the editable's current data index.
246         /// </summary>
247         /// <returns>The index of current data</returns>
248         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
249         /// <example>
250         /// <code>
251         /// MyComplication comp = new MyComplication();
252         /// Bundle curData = comp.GetCurrentDataIndex();
253         /// </code>
254         /// </example>
255         /// <since_tizen> 6 </since_tizen>
256         int IEditable.GetCurrentDataIndex()
257         {
258             int curIdx;
259             ComplicationError ret = Interop.WatchfaceComplication.GetCurrentIdx(_handle, out curIdx);
260             if (ret != ComplicationError.None)
261             {
262                 ErrorFactory.ThrowException(ret, "Fail to get current idx");
263             }
264             return curIdx;
265         }
266
267         /// <summary>
268         /// Gets the editable's current data.
269         /// </summary>
270         /// <returns>The current data</returns>
271         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
272         /// <example>
273         /// <code>
274         /// MyComplication comp = new MyComplication();
275         /// Bundle curData = comp.GetCurrentData();
276         /// </code>
277         /// </example>
278         /// <since_tizen> 6 </since_tizen>
279         Bundle IEditable.GetCurrentData()
280         {
281             SafeBundleHandle bundleHandle;
282             ComplicationError err = Interop.WatchfaceComplication.GetCurrentData(_handle, out bundleHandle);
283             if (err != ComplicationError.None)
284                 ErrorFactory.ThrowException(err, "Can not get current data");
285             Bundle data = new Bundle(bundleHandle);
286             return data;
287         }
288
289         /// <summary>
290         /// Gets the current provider ID.
291         /// </summary>
292         /// <returns>The current provider ID</returns>
293         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
294         /// <example>
295         /// <code>
296         /// MyComplication comp = new MyComplication();
297         /// string providerId = comp.GetCurrentProviderId();
298         /// </code>
299         /// </example>
300         /// <since_tizen> 6 </since_tizen>
301         public string GetCurrentProviderId()
302         {
303             string providerId = "";
304             ComplicationError err = Interop.WatchfaceComplication.GetCurrentProviderId(_handle, out providerId);
305             if (err != ComplicationError.None)
306                 ErrorFactory.ThrowException(err, "Can not get current provider id");
307             return providerId;
308         }
309
310         /// <summary>
311         /// Gets the current complication type.
312         /// </summary>
313         /// <returns>The current complication type</returns>
314         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
315         /// <example>
316         /// <code>
317         /// MyComplication comp = new MyComplication();
318         /// ComplicationTypes type = comp.GetCurrentType();
319         /// </code>
320         /// </example>
321         /// <since_tizen> 6 </since_tizen>
322         public ComplicationTypes GetCurrentType()
323         {
324             ComplicationTypes type;
325             ComplicationError err = Interop.WatchfaceComplication.GetCurrentType(_handle, out type);
326             if (err != ComplicationError.None)
327                 ErrorFactory.ThrowException(err, "Can not get current provider type");
328             return type;
329         }
330
331         private void ComplicationUpdatedCallback(int complicationId,
332             string providerId, ComplicationTypes type, IntPtr data, IntPtr userData)
333         {
334             if (_complicationId == complicationId)
335                 OnComplicationUpdated(providerId, type, new Bundle(new SafeBundleHandle(data, false)));
336         }
337
338         private void ComplicationErrorCallback(int complicationId,
339             string providerId, ComplicationTypes type, ComplicationError error, IntPtr userData)
340         {
341             if (_complicationId == complicationId)
342                 OnComplicationError(providerId, type, error);
343         }
344
345         /// <summary>
346         /// Sends the complication update requests.
347         /// </summary>
348         /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
349         /// <privilege>http://tizen.org/privilege/datasharing</privilege>
350         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
351         /// <exception cref="UnauthorizedAccessException">Thrown when the application does not have privilege to access this method.</exception>
352         /// <example>
353         /// <code>
354         /// MyComplication comp = new MyComplication();
355         /// ComplicationError err = comp.SendUpdateRequest();
356         /// </code>
357         /// </example>
358         /// <since_tizen> 6 </since_tizen>
359         public void SendUpdateRequest()
360         {
361             ComplicationError ret = Interop.WatchfaceComplication.SendUpdateRequest(_handle);
362             if (ret != ComplicationError.None)
363                 ErrorFactory.ThrowException(ret, "Fail to get send request");
364         }
365
366         /// <summary>
367         /// Transfers event to the provider.
368         /// </summary>
369         /// <param name="eventType">The complication event type.</param>
370         /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
371         /// <privilege>http://tizen.org/privilege/datasharing</privilege>
372         /// <exception cref="UnauthorizedAccessException">Thrown when the application does not have privilege to access this method.</exception>
373         /// <exception cref="ArgumentException">Thrown when the invalid argument is passed.</exception>
374         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
375         /// <example>
376         /// <code>
377         /// void OnButtonClicked()
378         /// {
379         ///     comp.TransferEvent(EventTypes.EventTap);
380         /// }
381         /// </code>
382         /// </example>
383         /// <since_tizen> 6 </since_tizen>
384         public void TransferEvent(EventTypes eventType)
385         {
386             ComplicationError ret = Interop.WatchfaceComplication.TransferEvent(_handle, eventType);
387             if (ret != ComplicationError.None)
388                 ErrorFactory.ThrowException(ret, "Fail to transfer event");
389         }
390
391         /// <summary>
392         /// Gets the complication data type.
393         /// </summary>
394         /// <param name="data">The data from OnComplicationUpdate callback.</param>
395         /// <returns>The complication type of data</returns>
396         /// <exception cref="ArgumentException">Thrown when the invalid argument is passed.</exception>
397         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
398         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
399         /// <example>
400         /// <code>
401         /// ComplicationTypes type = Complication.GetType(dupData);
402         /// </code>
403         /// </example>
404         /// <since_tizen> 6 </since_tizen>
405         public static ComplicationTypes GetType(Bundle data)
406         {
407             ComplicationTypes type;
408
409             ComplicationError err = Interop.WatchfaceComplication.GetDataType(data.SafeBundleHandle, out type);
410             if (err != ComplicationError.None)
411                 ErrorFactory.ThrowException(err, "fail to get data type");
412             return type;
413         }
414
415         /// <summary>
416         /// Gets the short text.
417         /// </summary>
418         /// <param name="data">The data from OnComplicationUpdate callback.</param>
419         /// <returns>The short text data</returns>
420         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
421         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
422         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
423         /// <example>
424         /// <code>
425         ///
426         /// public class MyComplication : Complication
427         /// {
428         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
429         ///        ComplicationTypes defaultType)
430         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
431         ///    {
432         ///    }
433         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
434         ///    {
435         ///        if (type == ComplicationTypes.ShortText)
436         ///        {
437         ///            string shortText = Complication.GetShortText(data);
438         ///            layout.Text = shortText;
439         ///        }
440         ///    }
441         /// }
442         ///
443         /// </code>
444         /// </example>
445         /// <since_tizen> 6 </since_tizen>
446         public static string GetShortText(Bundle data)
447         {
448             string shortText;
449
450             ComplicationError err = Interop.WatchfaceComplication.GetShortText(data.SafeBundleHandle, out shortText);
451             if (err != ComplicationError.None)
452                 ErrorFactory.ThrowException(err, "fail to get short text");
453             return shortText;
454         }
455
456         /// <summary>
457         /// Gets the long text.
458         /// </summary>
459         /// <param name="data">The data from OnComplicationUpdate callback.</param>
460         /// <returns>The long text data</returns>
461         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
462         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
463         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
464         /// <example>
465         /// <code>
466         ///
467         /// public class MyComplication : Complication
468         /// {
469         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
470         ///        ComplicationTypes defaultType)
471         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
472         ///    {
473         ///    }
474         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
475         ///    {
476         ///        if (type == ComplicationTypes.LongText)
477         ///        {
478         ///            string longText = Complication.GetLongText(data);
479         ///            layout.Text = longText;
480         ///        }
481         ///    }
482         /// }
483         ///
484         /// </code>
485         /// </example>
486         /// <since_tizen> 6 </since_tizen>
487         public static string GetLongText(Bundle data)
488         {
489             string longText;
490
491             ComplicationError err = Interop.WatchfaceComplication.GetLongText(data.SafeBundleHandle, out longText);
492             if (err != ComplicationError.None)
493                 ErrorFactory.ThrowException(err, "fail to get long text");
494             return longText;
495         }
496
497         /// <summary>
498         /// Gets the title.
499         /// </summary>
500         /// <param name="data">The data from OnComplicationUpdate callback.</param>
501         /// <returns>The title data</returns>
502         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
503         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
504         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
505         /// <example>
506         /// <code>
507         ///
508         /// public class MyComplication : Complication
509         /// {
510         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
511         ///        ComplicationTypes defaultType)
512         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
513         ///    {
514         ///    }
515         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
516         ///    {
517         ///        if (type == ComplicationTypes.ShortText)
518         ///        {
519         ///            string title = Complication.GetTitle(data);
520         ///            layout.Text = title;
521         ///        }
522         ///    }
523         /// }
524         ///
525         /// </code>
526         /// </example>
527         /// <since_tizen> 6 </since_tizen>
528         public static string GetTitle(Bundle data)
529         {
530             string title;
531
532             ComplicationError err = Interop.WatchfaceComplication.GetTitle(data.SafeBundleHandle, out title);
533             if (err != ComplicationError.None)
534                 ErrorFactory.ThrowException(err, "fail to get title");
535             return title;
536         }
537
538         /// <summary>
539         /// Gets the timestamp.
540         /// </summary>
541         /// <returns>The timestamp data in long value</returns>
542         /// <param name="data">The data from OnComplicationUpdate callback.</param>
543         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
544         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
545         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
546         /// <example>
547         /// <code>
548         ///
549         /// public class MyComplication : Complication
550         /// {
551         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
552         ///        ComplicationTypes defaultType)
553         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
554         ///    {
555         ///    }
556         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
557         ///    {
558         ///        if (type == ComplicationTypes.Time)
559         ///        {
560         ///            long time = Complication.GetTimestamp(data);
561         ///            layout.Text = time;
562         ///        }
563         ///    }
564         /// }
565         ///
566         /// </code>
567         /// </example>
568         /// <since_tizen> 6 </since_tizen>
569         public static long GetTimestamp(Bundle data)
570         {
571             long timestamp;
572
573             ComplicationError err = Interop.WatchfaceComplication.GetTimestamp(data.SafeBundleHandle, out timestamp);
574             if (err != ComplicationError.None)
575                 ErrorFactory.ThrowException(err, "fail to get timestamp");
576             return timestamp;
577         }
578
579         /// <summary>
580         /// Gets the image path.
581         /// </summary>
582         /// <param name="data">The data from OnComplicationUpdate callback.</param>
583         /// <returns>The image path data</returns>
584         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
585         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
586         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
587         /// <example>
588         /// <code>
589         ///
590         /// public class MyComplication : Complication
591         /// {
592         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
593         ///        ComplicationTypes defaultType)
594         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
595         ///    {
596         ///    }
597         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
598         ///    {
599         ///        if (type == ComplicationTypes.Image)
600         ///        {
601         ///            string imagePath = Complication.GetImagePath(data);
602         ///            layout.Text = imagePath;
603         ///        }
604         ///    }
605         /// }
606         ///
607         /// </code>
608         /// </example>
609         /// <since_tizen> 6 </since_tizen>
610         public static string GetImagePath(Bundle data)
611         {
612             string imagePath;
613
614             ComplicationError err = Interop.WatchfaceComplication.GetImagePath(data.SafeBundleHandle, out imagePath);
615             if (err != ComplicationError.None)
616                 ErrorFactory.ThrowException(err, "fail to get image path");
617             return imagePath;
618         }
619
620         /// <summary>
621         /// Gets the current value of ranged type data.
622         /// </summary>
623         /// <returns>The current value of range type data</returns>
624         /// <param name="data">The data from OnComplicationUpdate callback.</param>
625         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
626         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
627         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
628         /// <example>
629         /// <code>
630         ///
631         /// public class MyComplication : Complication
632         /// {
633         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
634         ///        ComplicationTypes defaultType)
635         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
636         ///    {
637         ///    }
638         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
639         ///    {
640         ///        if (type == ComplicationTypes.RangedValue)
641         ///        {
642         ///            double currentValue = Complication.GetCurrentValueOfRange(data);
643         ///            layout.Text = currentValue;
644         ///        }
645         ///    }
646         /// }
647         ///
648         /// </code>
649         /// </example>
650         /// <since_tizen> 6 </since_tizen>
651         public static double GetCurrentValueOfRange(Bundle data)
652         {
653             double curVal, minVal, maxVal;
654
655             ComplicationError err = Interop.WatchfaceComplication.GetRangedValue(data.SafeBundleHandle, out curVal, out minVal, out maxVal);
656             if (err != ComplicationError.None)
657                 ErrorFactory.ThrowException(err, "fail to get value");
658             return curVal;
659         }
660
661         /// <summary>
662         /// Gets the minimum value of ranged type data.
663         /// </summary>
664         /// <param name="data">The data from OnComplicationUpdate callback.</param>
665         /// <returns>The minimum value of range type data</returns>
666         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
667         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
668         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
669         /// <example>
670         /// <code>
671         ///
672         /// public class MyComplication : Complication
673         /// {
674         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
675         ///        ComplicationTypes defaultType)
676         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
677         ///    {
678         ///    }
679         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
680         ///    {
681         ///        if (type == ComplicationTypes.RangedValue)
682         ///        {
683         ///            double currentValue = Complication.GetMinValueOfRange(data);
684         ///            layout.Text = currentValue;
685         ///        }
686         ///    }
687         /// }
688         ///
689         /// </code>
690         /// </example>
691         /// <since_tizen> 6 </since_tizen>
692         public static double GetMinValueOfRange(Bundle data)
693         {
694             double curVal, minVal, maxVal;
695
696             ComplicationError err = Interop.WatchfaceComplication.GetRangedValue(data.SafeBundleHandle, out curVal, out minVal, out maxVal);
697             if (err != ComplicationError.None)
698                 ErrorFactory.ThrowException(err, "fail to get value");
699             return minVal;
700         }
701
702         /// <summary>
703         /// Gets the max value of ranged type data.
704         /// </summary>
705         /// <param name="data">The data from OnComplicationUpdate callback.</param>
706         /// <returns>The maximum value of range type data</returns>
707         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
708         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
709         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
710         /// <example>
711         /// <code>
712         ///
713         /// public class MyComplication : Complication
714         /// {
715         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
716         ///        ComplicationTypes defaultType)
717         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
718         ///    {
719         ///    }
720         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
721         ///    {
722         ///        if (type == ComplicationTypes.RangedValue)
723         ///        {
724         ///            double maxValue = Complication.GetMaxValueOfRange(data);
725         ///            layout.Text = maxValue;
726         ///        }
727         ///    }
728         /// }
729         ///
730         /// </code>
731         /// </example>
732         /// <since_tizen> 6 </since_tizen>
733         public static double GetMaxValueOfRange(Bundle data)
734         {
735             double curVal, minVal, maxVal;
736
737             ComplicationError err = Interop.WatchfaceComplication.GetRangedValue(data.SafeBundleHandle, out curVal, out minVal, out maxVal);
738             if (err != ComplicationError.None)
739                 ErrorFactory.ThrowException(err, "fail to get value");
740             return maxVal;
741         }
742
743         /// <summary>
744         /// Gets the icon path.
745         /// </summary>
746         /// <param name="data">The data from OnComplicationUpdate callback.</param>
747         /// <returns>The icon path data</returns>
748         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
749         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
750         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
751         /// <example>
752         /// <code>
753         ///
754         /// public class MyComplication : Complication
755         /// {
756         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
757         ///        ComplicationTypes defaultType)
758         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
759         ///    {
760         ///    }
761         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
762         ///    {
763         ///        if (type == ComplicationTypes.Icon)
764         ///        {
765         ///            string iconPath = Complication.GetIconPath(data);
766         ///            layout.Text = iconPath;
767         ///        }
768         ///    }
769         /// }
770         ///
771         /// </code>
772         /// </example>
773         /// <since_tizen> 6 </since_tizen>
774         public static string GetIconPath(Bundle data)
775         {
776             string iconPath;
777
778             ComplicationError err = Interop.WatchfaceComplication.GetIconPath(data.SafeBundleHandle, out iconPath);
779             if (err != ComplicationError.None)
780                 ErrorFactory.ThrowException(err, "fail to get icon path");
781             return iconPath;
782         }
783
784         /// <summary>
785         /// Gets the extra data.
786         /// </summary>
787         /// <param name="data">The data from OnComplicationUpdate callback.</param>
788         /// <returns>The extra string data</returns>
789         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
790         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
791         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
792         /// <example>
793         /// <code>
794         ///
795         /// public class MyComplication : Complication
796         /// {
797         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
798         ///        ComplicationTypes defaultType)
799         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
800         ///    {
801         ///    }
802         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
803         ///    {
804         ///        if (type == ComplicationTypes.Icon)
805         ///        {
806         ///            string extraData = Complication.GetExtraData(data);
807         ///            layout.Text = extraData;
808         ///        }
809         ///    }
810         /// }
811         ///
812         /// </code>
813         /// </example>
814         /// <since_tizen> 6 </since_tizen>
815         public static string GetExtraData(Bundle data)
816         {
817             string extraData;
818
819             ComplicationError err = Interop.WatchfaceComplication.GetExtraData(data.SafeBundleHandle, out extraData);
820             if (err != ComplicationError.None)
821                 ErrorFactory.ThrowException(err, "fail to get extra data");
822             return extraData;
823         }
824
825         /// <summary>
826         /// Gets the screen reader text.
827         /// </summary>
828         /// <param name="data">The data from OnComplicationUpdate callback.</param>
829         /// <returns>The screen reader text data</returns>
830         /// <exception cref="ArgumentException">Thrown when data is invalid.</exception>
831         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
832         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
833         /// <example>
834         /// <code>
835         ///
836         /// public class MyComplication : Complication
837         /// {
838         ///    public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
839         ///        ComplicationTypes defaultType)
840         ///        : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
841         ///    {
842         ///    }
843         ///    protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
844         ///    {
845         ///        if (type == ComplicationTypes.LongText)
846         ///        {
847         ///            string screenReaderText = Complication.GetScreenReaderText(data);
848         ///            layout.Text = screenReaderText;
849         ///        }
850         ///    }
851         /// }
852         ///
853         /// </code>
854         /// </example>
855         /// <since_tizen> 6 </since_tizen>
856         public static string GetScreenReaderText(Bundle data)
857         {
858             string screenReaderText;
859
860             ComplicationError err = Interop.WatchfaceComplication.GetScreenReaderText(data.SafeBundleHandle, out screenReaderText);
861             if (err != ComplicationError.None)
862                 ErrorFactory.ThrowException(err, "fail to get text");
863             return screenReaderText;
864         }
865
866         /// <summary>
867         /// Overrides this method to handle the behavior when the complication update event comes.
868         /// </summary>
869         /// <param name="providerId">The updated provider's ID.</param>
870         /// <param name="type">The updated type.</param>
871         /// <param name="data">The updated data.</param>
872         /// <since_tizen> 6 </since_tizen>
873         protected abstract void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data);
874
875         /// <summary>
876         /// Overrides this method to handle the behavior when the complication error occurs.
877         /// </summary>
878         /// <param name="providerId">The updated provider's ID.</param>
879         /// <param name="type">The updated type.</param>
880         /// <param name="errorReason">The occured error.</param>
881         /// <since_tizen> 6 </since_tizen>
882         protected virtual void OnComplicationError(string providerId, ComplicationTypes type, ComplicationError errorReason)
883         {
884         }
885
886         /// <summary>
887         /// Releases the unmanaged resources used by the Complication class specifying whether to perform a normal dispose operation.
888         /// </summary>
889         /// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
890         /// <since_tizen> 3 </since_tizen>
891         protected virtual void Dispose(bool disposing)
892         {
893             if (!_disposed)
894             {
895                 Interop.WatchfaceComplication.RemoveUpdatedCallback(_handle, _updatedCallback);
896                 Interop.WatchfaceComplication.Destroy(_handle);
897                 _disposed = true;
898             }
899         }
900
901         /// <summary>
902         /// Releases all resources used by the Complication class.
903         /// </summary>
904         /// <since_tizen> 3 </since_tizen>
905         public void Dispose()
906         {
907             Dispose(true);
908             GC.SuppressFinalize(this);
909         }
910     }
911 }