2 * Copyright (c) 2016 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;
19 using Tizen.Applications;
20 using System.Runtime.InteropServices;
22 namespace Tizen.Applications
25 /// The class for receiving widget events and sending data to the widget.
27 /// <since_tizen> 3 </since_tizen>
28 public class WidgetControl : IDisposable
30 private const string LogTag = "Tizen.Applications.WidgetControl";
31 private static Interop.WidgetService.LifecycleCallback _onLifecycleCallback;
33 /// Class for the widget instance.
35 /// <since_tizen> 3 </since_tizen>
38 private string _widgetId;
40 internal Instance(string widgetId)
48 /// <since_tizen> 3 </since_tizen>
49 public string Id { get; internal set; }
52 /// Gets the widget content.
54 /// <returns>The bundle containing widget content.</returns>
55 /// <since_tizen> 3 </since_tizen>
56 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
57 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
58 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
59 public Bundle GetContent()
63 Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetContent(_widgetId, Id, out h);
67 case Interop.WidgetService.ErrorCode.InvalidParameter:
68 throw new InvalidOperationException("Invalid parameter at unmanaged code");
69 case Interop.WidgetService.ErrorCode.IoError:
70 throw new InvalidOperationException("Failed to access DB");
71 case Interop.WidgetService.ErrorCode.NotSupported:
72 throw new NotSupportedException("Not supported");
75 return new Bundle(new SafeBundleHandle(h, true));
79 /// Changes the content for the widget instance.
81 /// <since_tizen> 3 </since_tizen>
82 /// <param name="content">Content to be changed.</param>
83 /// <param name="force"> True if you want to update your widget even if the provider is paused, otherwise false.</param>
84 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
85 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
86 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
87 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
88 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
89 public void ChangeContent(Bundle content, bool force)
91 Interop.WidgetService.ErrorCode err = Interop.WidgetService.UpdateContent(_widgetId, Id, content.SafeBundleHandle, force ? 1 : 0);
95 case Interop.WidgetService.ErrorCode.InvalidParameter:
96 throw new ArgumentException("Invalid parameter");
98 case Interop.WidgetService.ErrorCode.Canceled:
99 throw new InvalidOperationException("Provider is paused, so this update request is canceld");
101 case Interop.WidgetService.ErrorCode.OutOfMemory:
102 throw new InvalidOperationException("Out-of-memory at unmanaged code");
104 case Interop.WidgetService.ErrorCode.Fault:
105 throw new InvalidOperationException("Failed to create a request packet");
107 case Interop.WidgetService.ErrorCode.PermissionDenied:
108 throw new UnauthorizedAccessException();
110 case Interop.WidgetService.ErrorCode.NotSupported:
111 throw new NotSupportedException("Not supported");
116 /// Changes the update period for the widget instance.
118 /// <since_tizen> 3 </since_tizen>
119 /// <param name="period">The period to be changed.</param>
120 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
121 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
122 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
123 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
124 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
125 public void ChangePeriod(double period)
127 Interop.WidgetService.ErrorCode err = Interop.WidgetService.ChangePeriod(_widgetId, Id, period);
131 case Interop.WidgetService.ErrorCode.InvalidParameter:
132 throw new ArgumentException("Invalid parameter");
134 case Interop.WidgetService.ErrorCode.OutOfMemory:
135 throw new InvalidOperationException("Out-of-memory at unmanaged code");
137 case Interop.WidgetService.ErrorCode.Fault:
138 throw new InvalidOperationException("Failed to create a request packet");
140 case Interop.WidgetService.ErrorCode.PermissionDenied:
141 throw new UnauthorizedAccessException();
143 case Interop.WidgetService.ErrorCode.NotSupported:
144 throw new NotSupportedException("Not supported");
150 /// The class for the widget size information.
152 /// <since_tizen> 3 </since_tizen>
161 /// Enumeration for the types of widget size.
163 /// <since_tizen> 3 </since_tizen>
164 public enum SizeType : int
167 /// 175x175 based on 720x1280 resolution.
172 /// 354x175 based on 720x1280 resolution.
177 /// 354x354 based on 720x1280 resolution.
182 /// 712x175 based on 720x1280 resolution.
187 /// 712x354 based on 720x1280 resolution.
192 /// 712x533 based on 720x1280 resolution.
197 /// 712x712 based on 720x1280 resolution.
202 /// 712x891 based on 720x1280 resolution.
207 /// 712x1070 based on 720x1280 resolution.
213 /// 224x215 based on 720x1280 resolution.
218 /// 680x215 based on 720x1280 resolution.
223 /// 680x653 based on 720x1280 resolution.
228 /// 720x1280 based on 720x1280 resolution.
236 /// <since_tizen> 3 </since_tizen>
237 public int Width { get; internal set; }
242 /// <since_tizen> 3 </since_tizen>
243 public int Height { get; internal set; }
246 /// The path for the widget preview image file.
248 /// <since_tizen> 3 </since_tizen>
249 public string PreviewImagePath { get; internal set; }
252 /// The size type of the widget.
254 /// <since_tizen> 3 </since_tizen>
255 public SizeType Type { get; internal set; }
258 private event EventHandler<WidgetLifecycleEventArgs> _created;
259 private event EventHandler<WidgetLifecycleEventArgs> _resumed;
260 private event EventHandler<WidgetLifecycleEventArgs> _paused;
261 private event EventHandler<WidgetLifecycleEventArgs> _destroyed;
262 private bool _disposedValue = false;
263 private static IDictionary<string, int> s_lifecycleEventRefCnt = new Dictionary<string, int>();
264 private static IList<WidgetControl> s_eventObjects = new List<WidgetControl>();
267 /// Factory method for the WidgetControl.
268 /// It will create all the objects of WidgetControl based on the package ID.
270 /// <since_tizen> 3 </since_tizen>
271 /// <param name="pkgId">Package ID.</param>
272 /// <returns>The widget control array.</returns>
273 /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
274 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
275 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
276 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
277 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
278 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
279 public static WidgetControl[] CreateAll(string pkgId)
281 List<WidgetControl> list = new List<WidgetControl>();
283 Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetWidgetListByPkgId(pkgId, (widgetId, isPrime, userData) =>
285 list.Add(new WidgetControl(widgetId));
290 case Interop.WidgetService.ErrorCode.InvalidParameter:
291 throw new ArgumentException("Invalid parameter");
293 case Interop.WidgetService.ErrorCode.IoError:
294 throw new InvalidOperationException("Failed to access DB");
296 case Interop.WidgetService.ErrorCode.PermissionDenied:
297 throw new UnauthorizedAccessException();
299 case Interop.WidgetService.ErrorCode.NotSupported:
300 throw new NotSupportedException("Not supported");
303 return list.ToArray();
307 /// Gets all the widget IDs by the package ID.
309 /// <since_tizen> 3 </since_tizen>
310 /// <param name="pkgId">Package ID.</param>
311 /// <returns>The widget id array.</returns>
312 /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
313 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
314 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
315 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
316 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
317 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
318 public static string[] GetWidgetIds(string pkgId)
320 List<string> list = new List<string>();
322 Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetWidgetListByPkgId(pkgId, (widgetId, isPrime, userData) =>
329 case Interop.WidgetService.ErrorCode.InvalidParameter:
330 throw new ArgumentException("Invalid parameter");
332 case Interop.WidgetService.ErrorCode.IoError:
333 throw new InvalidOperationException("Failed to access DB");
335 case Interop.WidgetService.ErrorCode.PermissionDenied:
336 throw new UnauthorizedAccessException();
338 case Interop.WidgetService.ErrorCode.NotSupported:
339 throw new NotSupportedException("Not supported");
342 return list.ToArray();
346 /// Gets main appid of the widget.
348 /// <since_tizen> 6 </since_tizen>
349 /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
350 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
351 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
352 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
353 public string MainAppId
357 string str = Interop.WidgetService.GetWidgetMainAppId(Id);
358 Interop.WidgetService.ErrorCode err =
359 (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
362 case Interop.WidgetService.ErrorCode.PermissionDenied:
363 throw new UnauthorizedAccessException();
365 case Interop.WidgetService.ErrorCode.NotSupported:
366 throw new NotSupportedException("Not supported");
374 /// Gets package ID of the widget.
376 /// <since_tizen> 6 </since_tizen>
377 /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
378 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
379 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
380 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
381 public string PackageId
385 string str = Interop.WidgetService.GetWidgetPackageId(Id);
386 Interop.WidgetService.ErrorCode err =
387 (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
390 case Interop.WidgetService.ErrorCode.PermissionDenied:
391 throw new UnauthorizedAccessException();
393 case Interop.WidgetService.ErrorCode.NotSupported:
394 throw new NotSupportedException("Not supported");
404 /// <since_tizen> 3 </since_tizen>
405 public string Id { get; internal set; }
408 /// The flag value for "nodisplay".
410 /// <since_tizen> 3 </since_tizen>
411 /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
412 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
413 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
414 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
415 public bool IsNoDisplay
419 int ret = Interop.WidgetService.GetNoDisplay(Id);
420 Interop.WidgetService.ErrorCode err =
421 (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
424 case Interop.WidgetService.ErrorCode.PermissionDenied:
425 throw new UnauthorizedAccessException();
427 case Interop.WidgetService.ErrorCode.NotSupported:
428 throw new NotSupportedException("Not supported");
439 /// The event handler for a created widget instance.
441 /// <since_tizen> 3 </since_tizen>
442 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
443 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
444 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
445 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
446 public event EventHandler<WidgetLifecycleEventArgs> Created
450 RegisterLifecycleEvent();
456 UnregisterLifecycleEvent();
461 /// The event handler for a resumed widget instance.
463 /// <since_tizen> 3 </since_tizen>
464 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
465 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
466 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
467 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
468 public event EventHandler<WidgetLifecycleEventArgs> Resumed
472 RegisterLifecycleEvent();
478 UnregisterLifecycleEvent();
483 /// The event handler for a paused widget instance.
485 /// <since_tizen> 3 </since_tizen>
486 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
487 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
488 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
489 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
490 public event EventHandler<WidgetLifecycleEventArgs> Paused
494 RegisterLifecycleEvent();
500 UnregisterLifecycleEvent();
505 /// The event handler for a destroyed widget instance.
507 /// <since_tizen> 3 </since_tizen>
508 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
509 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
510 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
511 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
512 public event EventHandler<WidgetLifecycleEventArgs> Destroyed
516 RegisterLifecycleEvent();
522 UnregisterLifecycleEvent();
527 /// The constructor of the WidgetControl object.
529 /// <since_tizen> 3 </since_tizen>
530 /// <param name="widgetId">Widget ID.</param>
531 public WidgetControl(string widgetId)
537 /// Finalizer of the WidgetControl class.
545 /// Gets the objects for widget instance information.
547 /// <returns>The instances list.</returns>
548 /// <since_tizen> 3 </since_tizen>
549 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
550 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
551 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
552 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
553 public IEnumerable<Instance> GetInstances()
555 IList<Instance> instances = new List<Instance>();
556 Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetInstances(Id, (widgetId, instanceId, userData) =>
558 instances.Add(new Instance(widgetId) { Id = instanceId });
563 case Interop.WidgetService.ErrorCode.InvalidParameter:
564 throw new InvalidOperationException("Invalid parameter at unmanaged code");
566 case Interop.WidgetService.ErrorCode.NotSupported:
567 throw new NotSupportedException();
569 case Interop.WidgetService.ErrorCode.PermissionDenied:
570 throw new UnauthorizedAccessException();
577 /// Gets the objects for widget scale information.
579 /// <returns>The scales list.</returns>
580 /// <since_tizen> 3 </since_tizen>
581 /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
582 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
583 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
584 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
585 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
586 public IEnumerable<Scale> GetScales()
596 IList<Scale> scales = new List<Scale>();
597 Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetSupportedSizes(Id, ref cnt1, out wPtr, out hPtr);
601 Log.Error(LogTag, "No supported size :" + Id);
607 case Interop.WidgetService.ErrorCode.InvalidParameter:
608 throw new InvalidOperationException("Invalid parameter at unmanaged code");
610 case Interop.WidgetService.ErrorCode.IoError:
611 throw new InvalidOperationException("Failed to access DB");
613 case Interop.WidgetService.ErrorCode.PermissionDenied:
614 throw new UnauthorizedAccessException();
616 case Interop.WidgetService.ErrorCode.NotSupported:
617 throw new NotSupportedException();
620 Marshal.Copy(wPtr, w, 0, cnt1);
621 Interop.Libc.Free(wPtr);
624 Marshal.Copy(hPtr, h, 0, cnt1);
625 Interop.Libc.Free(hPtr);
627 err = Interop.WidgetService.GetSupportedSizeTypes(Id, ref cnt2, out typesPtr);
630 case Interop.WidgetService.ErrorCode.InvalidParameter:
631 throw new InvalidOperationException("Invalid parameter at unmanaged code");
633 case Interop.WidgetService.ErrorCode.IoError:
634 throw new InvalidOperationException("Failed to access DB");
636 case Interop.WidgetService.ErrorCode.PermissionDenied:
637 throw new UnauthorizedAccessException();
642 Log.Error(LogTag, "Count not match cnt1 :" + cnt1 + ", cnt2 :" + cnt2);
646 types = new int[cnt2];
647 Marshal.Copy(typesPtr, types, 0, cnt2);
648 Interop.Libc.Free(typesPtr);
650 for (int i = 0; i < cnt1; i++)
652 string prev = Interop.WidgetService.GetPreviewImagePath(Id, types[i]);
654 scales.Add(new Scale()
658 PreviewImagePath = prev,
659 Type = (Scale.SizeType)types[i]
666 /// Gets the widget name.
668 /// <since_tizen> 3 </since_tizen>
669 /// <param name="lang">Language.</param>
670 /// <returns>The widget name.</returns>
671 /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
672 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
673 /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
674 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
675 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
676 public string GetName(string lang)
679 throw new ArgumentNullException();
681 string str = Interop.WidgetService.GetName(Id, lang);
682 Interop.WidgetService.ErrorCode err =
683 (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
687 case Interop.WidgetService.ErrorCode.PermissionDenied:
688 throw new UnauthorizedAccessException();
690 case Interop.WidgetService.ErrorCode.NotSupported:
691 throw new NotSupportedException();
698 /// Gets the widget icon path.
700 /// <since_tizen> 3 </since_tizen>
701 /// <param name="lang">Language.</param>
702 /// <returns>The widget icon path.</returns>
703 /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
704 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
705 /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
706 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
707 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
708 public string GetIconPath(string lang)
711 throw new ArgumentNullException();
713 string pkgId = Interop.WidgetService.GetPkgId(Id);
714 string str = Interop.WidgetService.GetIcon(pkgId, lang);
715 Interop.WidgetService.ErrorCode err =
716 (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
720 case Interop.WidgetService.ErrorCode.PermissionDenied:
721 throw new UnauthorizedAccessException();
723 case Interop.WidgetService.ErrorCode.NotSupported:
724 throw new NotSupportedException();
731 /// Releases all the resources used by the WidgetControl class.
733 /// <since_tizen> 3 </since_tizen>
734 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
735 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
736 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
737 /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
738 public void Dispose()
741 GC.SuppressFinalize(this);
744 private void Dispose(bool disposing)
756 UnregisterLifecycleEvent();
758 _disposedValue = true;
762 private void RegisterLifecycleEvent()
764 if (!s_lifecycleEventRefCnt.ContainsKey(Id))
765 s_lifecycleEventRefCnt[Id] = 0;
767 if (_created != null || _paused != null || _resumed != null || _destroyed != null)
770 if (s_lifecycleEventRefCnt[Id] == 0)
772 if (_onLifecycleCallback == null)
773 _onLifecycleCallback = new Interop.WidgetService.LifecycleCallback(OnLifecycleEvent);
775 Interop.WidgetService.ErrorCode err = Interop.WidgetService.SetLifecycleEvent(Id, _onLifecycleCallback, IntPtr.Zero);
778 case Interop.WidgetService.ErrorCode.InvalidParameter:
779 throw new InvalidOperationException("Invalid parameter at unmanaged code");
781 case Interop.WidgetService.ErrorCode.PermissionDenied:
782 throw new UnauthorizedAccessException();
784 case Interop.WidgetService.ErrorCode.NotSupported:
785 throw new NotSupportedException();
789 s_lifecycleEventRefCnt[Id]++;
790 s_eventObjects.Add(this);
791 Log.Debug(LogTag, "register lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]");
794 private void UnregisterLifecycleEvent()
796 if (!s_lifecycleEventRefCnt.ContainsKey(Id))
799 if (s_lifecycleEventRefCnt[Id] <= 0)
802 if (_created != null || _paused != null || _resumed != null || _destroyed != null)
805 if (s_lifecycleEventRefCnt[Id] == 1)
807 Interop.WidgetService.ErrorCode err = Interop.WidgetService.UnsetLifecycleEvent(Id, IntPtr.Zero);
811 case Interop.WidgetService.ErrorCode.InvalidParameter:
812 throw new InvalidOperationException("Invalid parameter at unmanaged code");
814 case Interop.WidgetService.ErrorCode.PermissionDenied:
815 throw new UnauthorizedAccessException();
817 case Interop.WidgetService.ErrorCode.NotExist:
818 throw new InvalidOperationException("Event handler is not exist");
820 case Interop.WidgetService.ErrorCode.NotSupported:
821 throw new NotSupportedException();
823 _onLifecycleCallback = null;
826 s_eventObjects.Remove(this);
827 s_lifecycleEventRefCnt[Id]--;
828 Log.Debug(LogTag, "unregister lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]");
831 private static int OnLifecycleEvent(string widgetId, Interop.WidgetService.LifecycleEvent e, string instanceId, IntPtr userData)
833 Log.Debug(LogTag, "Lifecycle event : " + instanceId + " [" + e + "]");
836 case Interop.WidgetService.LifecycleEvent.Created:
837 foreach (WidgetControl c in s_eventObjects)
839 if (c.Id.CompareTo(widgetId) == 0)
841 c._created?.Invoke(null, new WidgetLifecycleEventArgs()
844 InstanceId = instanceId,
845 Type = WidgetLifecycleEventArgs.EventType.Created
851 case Interop.WidgetService.LifecycleEvent.Resumed:
852 foreach (WidgetControl c in s_eventObjects)
854 if (c.Id.CompareTo(widgetId) == 0)
856 c._resumed?.Invoke(null, new WidgetLifecycleEventArgs()
859 InstanceId = instanceId,
860 Type = WidgetLifecycleEventArgs.EventType.Resumed
866 case Interop.WidgetService.LifecycleEvent.Paused:
867 foreach (WidgetControl c in s_eventObjects)
869 if (c.Id.CompareTo(widgetId) == 0)
871 c._paused?.Invoke(null, new WidgetLifecycleEventArgs()
874 InstanceId = instanceId,
875 Type = WidgetLifecycleEventArgs.EventType.Paused
881 case Interop.WidgetService.LifecycleEvent.Destroyed:
882 foreach (WidgetControl c in s_eventObjects)
884 if (c.Id.CompareTo(widgetId) == 0)
886 c._destroyed?.Invoke(null, new WidgetLifecycleEventArgs()
889 InstanceId = instanceId,
890 Type = WidgetLifecycleEventArgs.EventType.Destroyed