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.
20 namespace Tizen.Applications
23 /// The abstract class for widget instances.
25 /// <since_tizen> 3 </since_tizen>
26 public abstract class WidgetBase
28 internal IntPtr Handle;
29 private const string LogTag = "Tizen.Applications.WidgetBase";
32 /// Window object for this widget instance.
33 /// It will be created after OnCreate method is invoked.
35 /// <since_tizen> 3 </since_tizen>
36 protected Window Window;
41 /// <since_tizen> 3 </since_tizen>
42 public enum WidgetDestroyType
45 /// User deleted this widget from the viewer.
50 /// Widget is deleted because of other reasons. (For example, widget process is terminated temporarily by the system)
58 /// <since_tizen> 3 </since_tizen>
64 /// ID for this widget instance.
65 /// It will be created after OnCreate method is invoked.
67 /// <since_tizen> 6 </since_tizen>
68 public string Id { get; private set; }
71 /// Sets the content information to the widget.
73 /// <param name="info">The data set to save.</param>
74 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
75 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
76 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
77 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
78 /// <since_tizen> 3 </since_tizen>
79 public void SetContent(Bundle info)
81 Interop.Widget.ErrorCode err = Interop.Widget.SetContent(Handle, info.SafeBundleHandle);
83 if (err != Interop.Widget.ErrorCode.None)
85 Log.Error(LogTag, "Failed to set content. Err = " + err);
89 case Interop.Widget.ErrorCode.InvalidParameter:
90 throw new ArgumentException("Invalid parameter of SetContent()");
92 case Interop.Widget.ErrorCode.NotSupported:
93 throw new NotSupportedException();
95 case Interop.Widget.ErrorCode.OutOfMemory:
96 case Interop.Widget.ErrorCode.Fault:
97 throw new InvalidOperationException();
104 /// Sends the title to the widget.
106 /// <param name="title">When an accessibility mode is turned on, this string will be read.</param>
107 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
108 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
109 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
110 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
111 /// <since_tizen> 3 </since_tizen>
112 public void SetTitle(string title)
114 Interop.Widget.ErrorCode err = Interop.Widget.SetTitle(Handle, title);
116 if (err != Interop.Widget.ErrorCode.None)
118 Log.Error(LogTag, "Failed to set title. Err = " + err);
122 case Interop.Widget.ErrorCode.InvalidParameter:
123 throw new ArgumentException("Invalid parameter of SetContent()");
125 case Interop.Widget.ErrorCode.NotSupported:
126 throw new NotSupportedException();
128 case Interop.Widget.ErrorCode.OutOfMemory:
129 case Interop.Widget.ErrorCode.Fault:
130 throw new InvalidOperationException();
136 /// Finishes the context for the widget instance.
138 /// <feature>http://tizen.org/feature/shell.appwidget</feature>
139 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
140 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
141 /// <since_tizen> 3 </since_tizen>
144 Interop.Widget.ErrorCode err = Interop.Widget.TerminateContext(Handle);
146 if (err != Interop.Widget.ErrorCode.None)
148 Log.Error(LogTag, "Failed to terminate context. Err = " + err);
152 case Interop.Widget.ErrorCode.NotSupported:
153 throw new NotSupportedException();
155 case Interop.Widget.ErrorCode.InvalidParameter:
156 case Interop.Widget.ErrorCode.Fault:
157 throw new InvalidOperationException();
162 internal void Bind(IntPtr handle, string id)
169 /// Overrides this method if want to handle the behavior when the widget instance is started.
171 /// <param name="content">The data set for the previous status.</param>
172 /// <param name="w">The pixel value for the widget width.</param>
173 /// <param name="h">The pixel value for the widget height.</param>
174 /// <since_tizen> 3 </since_tizen>
175 public virtual void OnCreate(Bundle content, int w, int h)
179 Interop.Widget.GetWin(Handle, out win);
180 Window = new WidgetWindow(win);
186 /// Overrides this method if want to handle the behavior when the widget instance is destroyed.
188 /// <param name="reason">The reason for destruction.</param>
189 /// <param name="content">The data set to save.</param>
190 /// <since_tizen> 3 </since_tizen>
191 public virtual void OnDestroy(WidgetDestroyType reason, Bundle content)
196 /// Overrides this method if want to handle the behavior when the widget instance is paused.
198 /// <since_tizen> 3 </since_tizen>
199 public virtual void OnPause()
204 /// Overrides this method if want to handle the behavior when the widget instance is resumed.
206 /// <since_tizen> 3 </since_tizen>
207 public virtual void OnResume()
212 /// Overrides this method if want to handle the behavior when the widget instance is resized.
214 /// <param name="w">Widget width.</param>
215 /// <param name="h">Widget height.</param>
216 /// <since_tizen> 3 </since_tizen>
217 public virtual void OnResize(int w, int h)
222 /// Overrides this method if want to handle the behavior when the widget instance is updated.
224 /// <param name="content">The data set for updating this widget will be provided by the requester.</param>
225 /// <param name="isForce">Although the widget is paused, if it is true, the widget can be updated.</param>
226 /// <since_tizen> 3 </since_tizen>
227 public virtual void OnUpdate(Bundle content, bool isForce)