/// <summary> /// Gets the objects for widget instance information. /// </summary> /// <returns>The instances list.</returns> /// <since_tizen> 3 </since_tizen> /// <feature>http://tizen.org/feature/shell.appwidget</feature> /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception> /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception> public IEnumerable <Instance> GetInstances() { IList <Instance> instances = new List <Instance>(); Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetInstances(Id, (widgetId, instanceId, userData) => { instances.Add(new Instance(widgetId) { Id = instanceId }); }, IntPtr.Zero); switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new InvalidOperationException("Invalid parameter at unmanaged code"); case Interop.WidgetService.ErrorCode.NotSupported: throw new NotSupportedException(); case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); } return(instances); }
/// <summary> /// Changes the content for the widget instance. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="content">Content to be changed.</param> /// <param name="force"> True if you want to update your widget even if the provider is paused, otherwise false.</param> /// <feature>http://tizen.org/feature/shell.appwidget</feature> /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception> /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception> /// <exception cref="NotSupportedException">Thrown in case of feature not supported.</exception> public void ChangeContent(Bundle content, bool force) { Interop.WidgetService.ErrorCode err = Interop.WidgetService.UpdateContent(_widgetId, Id, content.SafeBundleHandle, force ? 1 : 0); switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new ArgumentException("Invalid parameter"); case Interop.WidgetService.ErrorCode.Canceled: throw new InvalidOperationException("Provider is paused, so this update request is canceld"); case Interop.WidgetService.ErrorCode.OutOfMemory: throw new InvalidOperationException("Out-of-memory at unmanaged code"); case Interop.WidgetService.ErrorCode.Fault: throw new InvalidOperationException("Failed to create a request packet"); case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); case Interop.WidgetService.ErrorCode.NotSupported: throw new NotSupportedException("Not supported"); } }
/// <summary> /// Gets all the widget IDs by the package ID. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="pkgId">Package ID.</param> /// <returns>The widget id array.</returns> /// <privilege>http://tizen.org/privilege/widget.viewer</privilege> /// <feature>http://tizen.org/feature/shell.appwidget</feature> /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception> /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception> /// <exception cref="NotSupportedException">Thrown in case of feature not supported.</exception> public static string[] GetWidgetIds(string pkgId) { List <string> list = new List <string>(); Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetWidgetListByPkgId(pkgId, (widgetId, isPrime, userData) => { list.Add(widgetId); }, IntPtr.Zero); switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new ArgumentException("Invalid parameter"); case Interop.WidgetService.ErrorCode.IoError: throw new InvalidOperationException("Failed to access DB"); case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); case Interop.WidgetService.ErrorCode.NotSupported: throw new NotSupportedException("Not supported"); } return(list.ToArray()); }
private void RegisterLifecycleEvent() { if (!s_lifecycleEventRefCnt.ContainsKey(Id)) { s_lifecycleEventRefCnt[Id] = 0; } if (_created != null || _paused != null || _resumed != null || _destroyed != null) { return; } if (s_lifecycleEventRefCnt[Id] == 0) { if (_onLifecycleCallback == null) { _onLifecycleCallback = new Interop.WidgetService.LifecycleCallback(OnLifecycleEvent); } Interop.WidgetService.ErrorCode err = Interop.WidgetService.SetLifecycleEvent(Id, _onLifecycleCallback, IntPtr.Zero); switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new InvalidOperationException("Invalid parameter at unmanaged code"); case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); } } s_lifecycleEventRefCnt[Id]++; s_eventObjects.Add(this); Log.Debug(LogTag, "register lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]"); }
/// <summary> /// Gets the widget content. /// </summary> /// <since_tizen> 3 </since_tizen> /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception> public Bundle GetContent() { IntPtr h; Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetContent(_widgetId, Id, out h); switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new InvalidOperationException("Invalid parameter at unmanaged code"); case Interop.WidgetService.ErrorCode.IoError: throw new InvalidOperationException("Failed to access DB"); } return(new Bundle(new SafeBundleHandle(h, true))); }
/// <summary> /// Changes the update period for the widget instance. /// </summary> /// <since_tizen> 3 </since_tizen> /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception> /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception> public void ChangePeriod(double period) { Interop.WidgetService.ErrorCode err = Interop.WidgetService.ChangePeriod(_widgetId, Id, period); switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new ArgumentException("Invalid parameter"); case Interop.WidgetService.ErrorCode.OutOfMemory: throw new InvalidOperationException("Out-of-memory at unmanaged code"); case Interop.WidgetService.ErrorCode.Fault: throw new InvalidOperationException("Failed to create a request packet"); case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); } }
private void UnregisterLifecycleEvent() { if (!s_lifecycleEventRefCnt.ContainsKey(Id)) { return; } if (s_lifecycleEventRefCnt[Id] <= 0) { return; } if (_created != null || _paused != null || _resumed != null || _destroyed != null) { return; } if (s_lifecycleEventRefCnt[Id] == 1) { Interop.WidgetService.ErrorCode err = Interop.WidgetService.UnsetLifecycleEvent(Id, IntPtr.Zero); switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new InvalidOperationException("Invalid parameter at unmanaged code"); case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); case Interop.WidgetService.ErrorCode.NotExist: throw new InvalidOperationException("Event handler is not exist"); case Interop.WidgetService.ErrorCode.NotSupported: throw new NotSupportedException(); } _onLifecycleCallback = null; } s_eventObjects.Remove(this); s_lifecycleEventRefCnt[Id]--; Log.Debug(LogTag, "unregister lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]"); }
/// <summary> /// Gets the widget name. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="lang">Language.</param> /// <returns>The widget name.</returns> /// <privilege>http://tizen.org/privilege/widget.viewer</privilege> /// <feature>http://tizen.org/feature/shell.appwidget</feature> /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception> /// <exception cref="NotSupportedException">Thrown in case of feature not supported.</exception> public string GetName(string lang) { if (lang == null) { throw new ArgumentNullException(); } string str = Interop.WidgetService.GetName(Id, lang); Interop.WidgetService.ErrorCode err = (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult(); switch (err) { case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); case Interop.WidgetService.ErrorCode.NotSupported: throw new NotSupportedException(); } return(str); }
/// <summary> /// Gets the objects for widget scale information. /// </summary> /// <returns>The scales list.</returns> /// <since_tizen> 3 </since_tizen> /// <privilege>http://tizen.org/privilege/widget.viewer</privilege> /// <feature>http://tizen.org/feature/shell.appwidget</feature> /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception> /// <exception cref="NotSupportedException">Thrown in case of feature not supported.</exception> public IEnumerable <Scale> GetScales() { IntPtr wPtr; IntPtr hPtr; IntPtr typesPtr; int[] w; int[] h; int[] types; int cnt1 = 100; int cnt2 = 100; IList <Scale> scales = new List <Scale>(); Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetSupportedSizes(Id, ref cnt1, out wPtr, out hPtr); if (cnt1 == 0) { Log.Error(LogTag, "No supported size :" + Id); return(null); } switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new InvalidOperationException("Invalid parameter at unmanaged code"); case Interop.WidgetService.ErrorCode.IoError: throw new InvalidOperationException("Failed to access DB"); case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); case Interop.WidgetService.ErrorCode.NotSupported: throw new NotSupportedException(); } w = new int[cnt1]; Marshal.Copy(wPtr, w, 0, cnt1); Interop.Libc.Free(wPtr); h = new int[cnt1]; Marshal.Copy(hPtr, h, 0, cnt1); Interop.Libc.Free(hPtr); err = Interop.WidgetService.GetSupportedSizeTypes(Id, ref cnt2, out typesPtr); switch (err) { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new InvalidOperationException("Invalid parameter at unmanaged code"); case Interop.WidgetService.ErrorCode.IoError: throw new InvalidOperationException("Failed to access DB"); case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); } if (cnt1 != cnt2) { Log.Error(LogTag, "Count not match cnt1 :" + cnt1 + ", cnt2 :" + cnt2); return(null); } types = new int[cnt2]; Marshal.Copy(typesPtr, types, 0, cnt2); Interop.Libc.Free(typesPtr); for (int i = 0; i < cnt1; i++) { string prev = Interop.WidgetService.GetPreviewImagePath(Id, types[i]); scales.Add(new Scale() { Width = w[i], Height = h[i], PreviewImagePath = prev, Type = (Scale.SizeType)types[i] }); } return(scales); }