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;
30 private const string LogTag = "Tizen.Applications.WidgetBase";
33 /// Window object for this widget instance.
34 /// It will be created after OnCreate method is invoked.
36 /// <since_tizen> 3 </since_tizen>
37 protected Window Window;
42 /// <since_tizen> 3 </since_tizen>
43 public enum WidgetDestroyType
46 /// User deleted this widget from the viewer.
51 /// Widget is deleted because of other reasons. (For example, widget process is terminated temporarily by the system)
59 /// <since_tizen> 3 </since_tizen>
65 /// Sets the content information to the widget.
67 /// <param name="info">The data set to save.</param>
68 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
69 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
70 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
71 /// <since_tizen> 3 </since_tizen>
72 public void SetContent(Bundle info)
74 Interop.Widget.ErrorCode err = Interop.Widget.SetContent(Handle, info.SafeBundleHandle);
76 if (err != Interop.Widget.ErrorCode.None)
78 Log.Error(LogTag, "Failed to set content. Err = " + err);
82 case Interop.Widget.ErrorCode.InvalidParameter:
83 throw new ArgumentException("Invalid parameter of SetContent()");
85 case Interop.Widget.ErrorCode.NotSupported:
86 throw new NotSupportedException();
88 case Interop.Widget.ErrorCode.OutOfMemory:
89 case Interop.Widget.ErrorCode.Fault:
90 throw new InvalidOperationException();
97 /// Sends the title to the widget.
99 /// <param name="title">When an accessibility mode is turned on, this string will be read.</param>
100 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
101 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
102 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
103 /// <since_tizen> 3 </since_tizen>
104 public void SetTitle(string title)
106 Interop.Widget.ErrorCode err = Interop.Widget.SetTitle(Handle, title);
108 if (err != Interop.Widget.ErrorCode.None)
110 Log.Error(LogTag, "Failed to set title. Err = " + err);
114 case Interop.Widget.ErrorCode.InvalidParameter:
115 throw new ArgumentException("Invalid parameter of SetContent()");
117 case Interop.Widget.ErrorCode.NotSupported:
118 throw new NotSupportedException();
120 case Interop.Widget.ErrorCode.OutOfMemory:
121 case Interop.Widget.ErrorCode.Fault:
122 throw new InvalidOperationException();
128 /// Finishes the context for the widget instance.
130 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
131 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
132 /// <since_tizen> 3 </since_tizen>
135 Interop.Widget.ErrorCode err = Interop.Widget.TerminateContext(Handle);
137 if (err != Interop.Widget.ErrorCode.None)
139 Log.Error(LogTag, "Failed to terminate context. Err = " + err);
143 case Interop.Widget.ErrorCode.NotSupported:
144 throw new NotSupportedException();
146 case Interop.Widget.ErrorCode.InvalidParameter:
147 case Interop.Widget.ErrorCode.Fault:
148 throw new InvalidOperationException();
153 internal void Bind(IntPtr handle, string id)
160 /// Overrides this method if want to handle the behavior when the widget instance is started.
162 /// <param name="content">The data set for the previous status.</param>
163 /// <param name="w">The pixel value for the widget width.</param>
164 /// <param name="h">The pixel value for the widget height.</param>
165 /// <since_tizen> 3 </since_tizen>
166 public virtual void OnCreate(Bundle content, int w, int h)
170 Interop.Widget.GetWin(Handle, out win);
171 Window = new WidgetWindow(win);
177 /// Overrides this method if want to handle the behavior when the widget instance is destroyed.
179 /// <param name="reason">The reason for destruction.</param>
180 /// <param name="content">The data set to save.</param>
181 /// <since_tizen> 3 </since_tizen>
182 public virtual void OnDestroy(WidgetDestroyType reason, Bundle content)
187 /// Overrides this method if want to handle the behavior when the widget instance is paused.
189 /// <since_tizen> 3 </since_tizen>
190 public virtual void OnPause()
195 /// Overrides this method if want to handle the behavior when the widget instance is resumed.
197 /// <since_tizen> 3 </since_tizen>
198 public virtual void OnResume()
203 /// Overrides this method if want to handle the behavior when the widget instance is resized.
205 /// <param name="w">Widget width.</param>
206 /// <param name="h">Widget height.</param>
207 /// <since_tizen> 3 </since_tizen>
208 public virtual void OnResize(int w, int h)
213 /// Overrides this method if want to handle the behavior when the widget instance is updated.
215 /// <param name="content">The data set for updating this widget will be provided by the requester.</param>
216 /// <param name="isForce">Although the widget is paused, if it is true, the widget can be updated.</param>
217 /// <since_tizen> 3 </since_tizen>
218 public virtual void OnUpdate(Bundle content, bool isForce)