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