2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
20 using Tizen.Applications;
23 namespace Tizen.Applications.WatchfaceComplication
26 /// Represents the Complication class for the watch application which using watchface complication.
28 /// <since_tizen> 6 </since_tizen>
29 public abstract class Complication : IEditable, IDisposable
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;
45 /// Initializes the Complication class.
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>
61 /// public class MyComplication : Complication
63 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
64 /// ComplicationTypes defaultType)
65 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
68 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
72 /// _complication = new MyComplication(_complicationId, (int)(ComplicationTypes.ShortText | ComplicationTypes.Image),
73 /// (int) EventTypes.EventNone, _complicationProviderId, ComplicationTypes.ShortText, _complicationBtn);
77 /// <since_tizen> 6 </since_tizen>
78 protected Complication(int complicationId, ComplicationTypes supportTypes, EventTypes supportEvents, string defaultProviderId, ComplicationTypes defaultType)
80 _complicationId = complicationId;
81 _supportTypes = supportTypes;
82 _supportEvents = supportEvents;
83 _defaultProviderId = defaultProviderId;
84 _defaultType = defaultType;
86 ComplicationError ret = Interop.WatchfaceComplication.CreateComplication(complicationId, defaultProviderId, defaultType, (int)supportTypes, (int)supportEvents, out _handle);
87 if (ret != ComplicationError.None)
89 ErrorFactory.ThrowException(ret, "Fail to create complication");
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)
97 ErrorFactory.ThrowException(ret, "Fail to add update callback");
102 /// Destructor of the complication class.
110 /// Gets the support types.
112 /// <since_tizen> 6 </since_tizen>
113 public ComplicationTypes SupportTypes
117 return _supportTypes;
122 /// Gets the support event types.
124 /// <since_tizen> 6 </since_tizen>
125 public EventTypes SupportEvents
129 return _supportEvents;
134 /// The information of the editable's highlight.
136 /// <since_tizen> 6 </since_tizen>
137 Highlight IEditable.Highlight
151 /// The information of specific allowed provider id, support types list for complication
153 /// <since_tizen> 6 </since_tizen>
154 public IEnumerable<(string allowedProviderId, ComplicationTypes supportTypes)> AllowedList
162 _allowedList = value;
163 if (_allowedList == null || _allowedList.Count() == 0)
165 Interop.WatchfaceComplication.ClearAllowedList(_handle);
170 Interop.WatchfaceComplication.CreateAllowedList(out listRaw);
171 List<(string allowedProviderId, ComplicationTypes supportTypes)> list = _allowedList.ToList();
172 foreach (var item in list)
174 Interop.WatchfaceComplication.AddAllowedList(listRaw, item.allowedProviderId, (int)item.supportTypes);
176 Interop.WatchfaceComplication.ApplyAllowedList(_handle, listRaw);
177 Interop.WatchfaceComplication.DestroyAllowedList(listRaw);
184 /// The information of the complication's highlight.
186 /// <since_tizen> 6 </since_tizen>
187 public Highlight Highlight
200 /// The information of complication ID.
202 /// <since_tizen> 6 </since_tizen>
203 public int ComplicationId
207 return _complicationId;
212 /// The information of editable ID.
214 /// <since_tizen> 6 </since_tizen>
215 int IEditable.EditableId
228 /// The information of editable name.
230 /// <since_tizen> 6 </since_tizen>
231 string IEditable.Name
235 string editableName = "";
236 Interop.WatchfaceComplication.GetEditableName(_handle, out editableName);
241 Interop.WatchfaceComplication.SetEditableName(_handle, value);
246 /// Gets the editable's current data index.
248 /// <returns>The index of current data</returns>
249 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
252 /// MyComplication comp = new MyComplication();
253 /// Bundle curData = comp.GetCurrentDataIndex();
256 /// <since_tizen> 6 </since_tizen>
257 int IEditable.GetCurrentDataIndex()
260 ComplicationError ret = Interop.WatchfaceComplication.GetCurrentIdx(_handle, out curIdx);
261 if (ret != ComplicationError.None)
263 ErrorFactory.ThrowException(ret, "Fail to get current idx");
269 /// Gets the editable's current data.
271 /// <returns>The current data</returns>
272 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
275 /// MyComplication comp = new MyComplication();
276 /// Bundle curData = comp.GetCurrentData();
279 /// <since_tizen> 6 </since_tizen>
280 Bundle IEditable.GetCurrentData()
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);
291 /// Gets the current provider ID.
293 /// <returns>The current provider ID</returns>
294 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
297 /// MyComplication comp = new MyComplication();
298 /// string providerId = comp.GetCurrentProviderId();
301 /// <since_tizen> 6 </since_tizen>
302 public string GetCurrentProviderId()
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");
312 /// Gets the current complication type.
314 /// <returns>The current complication type</returns>
315 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
318 /// MyComplication comp = new MyComplication();
319 /// ComplicationTypes type = comp.GetCurrentType();
322 /// <since_tizen> 6 </since_tizen>
323 public ComplicationTypes GetCurrentType()
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");
332 private void ComplicationUpdatedCallback(int complicationId,
333 string providerId, ComplicationTypes type, IntPtr data, IntPtr userData)
335 if (_complicationId == complicationId)
336 OnComplicationUpdated(providerId, type, new Bundle(new SafeBundleHandle(data, false)));
339 private void ComplicationErrorCallback(int complicationId,
340 string providerId, ComplicationTypes type, ComplicationError error, IntPtr userData)
342 if (_complicationId == complicationId)
343 OnComplicationError(providerId, type, error);
347 /// Sends the complication update requests.
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>
355 /// MyComplication comp = new MyComplication();
356 /// ComplicationError err = comp.SendUpdateRequest();
359 /// <since_tizen> 6 </since_tizen>
360 public void SendUpdateRequest()
362 ComplicationError ret = Interop.WatchfaceComplication.SendUpdateRequest(_handle);
363 if (ret != ComplicationError.None)
364 ErrorFactory.ThrowException(ret, "Fail to get send request");
368 /// Transfers event to the provider.
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>
378 /// void OnButtonClicked()
380 /// comp.TransferEvent(EventTypes.EventTap);
384 /// <since_tizen> 6 </since_tizen>
385 public void TransferEvent(EventTypes eventType)
387 ComplicationError ret = Interop.WatchfaceComplication.TransferEvent(_handle, eventType);
388 if (ret != ComplicationError.None)
389 ErrorFactory.ThrowException(ret, "Fail to transfer event");
393 /// Gets the complication data type.
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>
402 /// ComplicationTypes type = Complication.GetType(dupData);
405 /// <since_tizen> 6 </since_tizen>
406 public static ComplicationTypes GetType(Bundle data)
408 ComplicationTypes type;
410 ComplicationError err = Interop.WatchfaceComplication.GetDataType(data.SafeBundleHandle, out type);
411 if (err != ComplicationError.None)
412 ErrorFactory.ThrowException(err, "fail to get data type");
417 /// Gets the short text.
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>
427 /// public class MyComplication : Complication
429 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
430 /// ComplicationTypes defaultType)
431 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
434 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
436 /// if (type == ComplicationTypes.ShortText)
438 /// string shortText = Complication.GetShortText(data);
439 /// layout.Text = shortText;
446 /// <since_tizen> 6 </since_tizen>
447 public static string GetShortText(Bundle data)
451 ComplicationError err = Interop.WatchfaceComplication.GetShortText(data.SafeBundleHandle, out shortText);
452 if (err != ComplicationError.None)
453 ErrorFactory.ThrowException(err, "fail to get short text");
458 /// Gets the long text.
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>
468 /// public class MyComplication : Complication
470 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
471 /// ComplicationTypes defaultType)
472 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
475 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
477 /// if (type == ComplicationTypes.LongText)
479 /// string longText = Complication.GetLongText(data);
480 /// layout.Text = longText;
487 /// <since_tizen> 6 </since_tizen>
488 public static string GetLongText(Bundle data)
492 ComplicationError err = Interop.WatchfaceComplication.GetLongText(data.SafeBundleHandle, out longText);
493 if (err != ComplicationError.None)
494 ErrorFactory.ThrowException(err, "fail to get long text");
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>
509 /// public class MyComplication : Complication
511 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
512 /// ComplicationTypes defaultType)
513 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
516 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
518 /// if (type == ComplicationTypes.ShortText)
520 /// string title = Complication.GetTitle(data);
521 /// layout.Text = title;
528 /// <since_tizen> 6 </since_tizen>
529 public static string GetTitle(Bundle data)
533 ComplicationError err = Interop.WatchfaceComplication.GetTitle(data.SafeBundleHandle, out title);
534 if (err != ComplicationError.None)
535 ErrorFactory.ThrowException(err, "fail to get title");
540 /// Gets the timestamp.
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>
550 /// public class MyComplication : Complication
552 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
553 /// ComplicationTypes defaultType)
554 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
557 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
559 /// if (type == ComplicationTypes.Time)
561 /// long time = Complication.GetTimestamp(data);
562 /// layout.Text = time;
569 /// <since_tizen> 6 </since_tizen>
570 public static long GetTimestamp(Bundle data)
574 ComplicationError err = Interop.WatchfaceComplication.GetTimestamp(data.SafeBundleHandle, out timestamp);
575 if (err != ComplicationError.None)
576 ErrorFactory.ThrowException(err, "fail to get timestamp");
581 /// Gets the image path.
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>
591 /// public class MyComplication : Complication
593 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
594 /// ComplicationTypes defaultType)
595 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
598 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
600 /// if (type == ComplicationTypes.Image)
602 /// string imagePath = Complication.GetImagePath(data);
603 /// layout.Text = imagePath;
610 /// <since_tizen> 6 </since_tizen>
611 public static string GetImagePath(Bundle data)
615 ComplicationError err = Interop.WatchfaceComplication.GetImagePath(data.SafeBundleHandle, out imagePath);
616 if (err != ComplicationError.None)
617 ErrorFactory.ThrowException(err, "fail to get image path");
622 /// Gets the current value of ranged type data.
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>
632 /// public class MyComplication : Complication
634 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
635 /// ComplicationTypes defaultType)
636 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
639 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
641 /// if (type == ComplicationTypes.RangedValue)
643 /// double currentValue = Complication.GetCurrentValueOfRange(data);
644 /// layout.Text = currentValue;
651 /// <since_tizen> 6 </since_tizen>
652 public static double GetCurrentValueOfRange(Bundle data)
654 double curVal, minVal, maxVal;
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");
663 /// Gets the minimum value of ranged type data.
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>
673 /// public class MyComplication : Complication
675 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
676 /// ComplicationTypes defaultType)
677 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
680 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
682 /// if (type == ComplicationTypes.RangedValue)
684 /// double currentValue = Complication.GetMinValueOfRange(data);
685 /// layout.Text = currentValue;
692 /// <since_tizen> 6 </since_tizen>
693 public static double GetMinValueOfRange(Bundle data)
695 double curVal, minVal, maxVal;
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");
704 /// Gets the max value of ranged type data.
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>
714 /// public class MyComplication : Complication
716 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
717 /// ComplicationTypes defaultType)
718 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
721 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
723 /// if (type == ComplicationTypes.RangedValue)
725 /// double maxValue = Complication.GetMaxValueOfRange(data);
726 /// layout.Text = maxValue;
733 /// <since_tizen> 6 </since_tizen>
734 public static double GetMaxValueOfRange(Bundle data)
736 double curVal, minVal, maxVal;
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");
745 /// Gets the icon path.
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>
755 /// public class MyComplication : Complication
757 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
758 /// ComplicationTypes defaultType)
759 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
762 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
764 /// if (type == ComplicationTypes.Icon)
766 /// string iconPath = Complication.GetIconPath(data);
767 /// layout.Text = iconPath;
774 /// <since_tizen> 6 </since_tizen>
775 public static string GetIconPath(Bundle data)
779 ComplicationError err = Interop.WatchfaceComplication.GetIconPath(data.SafeBundleHandle, out iconPath);
780 if (err != ComplicationError.None)
781 ErrorFactory.ThrowException(err, "fail to get icon path");
786 /// Gets the extra data.
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>
796 /// public class MyComplication : Complication
798 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
799 /// ComplicationTypes defaultType)
800 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
803 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
805 /// if (type == ComplicationTypes.Icon)
807 /// string extraData = Complication.GetExtraData(data);
808 /// layout.Text = extraData;
815 /// <since_tizen> 6 </since_tizen>
816 public static string GetExtraData(Bundle data)
820 ComplicationError err = Interop.WatchfaceComplication.GetExtraData(data.SafeBundleHandle, out extraData);
821 if (err != ComplicationError.None)
822 ErrorFactory.ThrowException(err, "fail to get extra data");
827 /// Gets the screen reader text.
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>
837 /// public class MyComplication : Complication
839 /// public MyComplication(int complicationId, int supportTypes, int supportEvents, string defaultProviderId,
840 /// ComplicationTypes defaultType)
841 /// : base(complicationId, supportTypes, supportEvents, defaultProviderId, defaultType)
844 /// protected override void OnComplicationUpdated(string providerId, ComplicationTypes type, Bundle data)
846 /// if (type == ComplicationTypes.LongText)
848 /// string screenReaderText = Complication.GetScreenReaderText(data);
849 /// layout.Text = screenReaderText;
856 /// <since_tizen> 6 </since_tizen>
857 public static string GetScreenReaderText(Bundle data)
859 string screenReaderText;
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;
868 /// Overrides this method to handle the behavior when the complication update event comes.
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);
877 /// Overrides this method to handle the behavior when the complication error occurs.
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)
888 /// Releases the unmanaged resources used by the Complication class specifying whether to perform a normal dispose operation.
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)
896 Interop.WatchfaceComplication.Destroy(_handle);
897 Interop.WatchfaceComplication.RemoveUpdatedCallback(_handle, _updatedCallback);
903 /// Releases all resources used by the Complication class.
905 /// <since_tizen> 3 </since_tizen>
906 public void Dispose()
909 GC.SuppressFinalize(this);