2 * Copyright (c) 2023 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.ComponentModel;
19 using Tizen.Applications;
20 using Tizen.NUI.BaseComponents;
25 /// This class represents a NUIGadget controlled lifecycles.
27 /// <since_tizen> 10 </since_tizen>
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public abstract class NUIGadget
32 /// Initializes the gadget.
34 /// /// <param name="type">The type of the NUIGadget.</param>
35 /// <since_tizen> 10 </since_tizen>
36 public NUIGadget(NUIGadgetType type)
39 State = NUIGadgetLifecycleState.Initialized;
42 internal event EventHandler<NUIGadgetLifecycleChangedEventArgs> LifecycleChanged;
45 /// Gets the class representing information of the current gadget.
47 /// <since_tizen> 10 </since_tizen>
48 public NUIGadgetInfo NUIGadgetInfo
57 /// <since_tizen> 10 </since_tizen>
58 public NUIGadgetType Type
65 /// Gets the class name.
67 /// <since_tizen> 10 </since_tizen>
68 public string ClassName
75 /// Gets the main view.
77 /// <since_tizen> 10 </since_tizen>
85 /// Gets the lifecycle state.
87 /// <since_tizen> 10 </since_tizen>
88 public NUIGadgetLifecycleState State
94 internal bool Create()
96 MainView = OnCreate();
105 internal void Resume()
107 if (State == NUIGadgetLifecycleState.Created || State == NUIGadgetLifecycleState.Paused)
111 internal void Pause()
113 if (State == NUIGadgetLifecycleState.Resumed)
117 internal void Destroy()
119 if (State == NUIGadgetLifecycleState.Created || State == NUIGadgetLifecycleState.Paused)
123 internal void HandleAppControlReceivedEvent(AppControlReceivedEventArgs args)
125 OnAppControlReceived(args);
128 internal void HandleEvents(NUIGadgetEventType eventType, EventArgs args)
132 case NUIGadgetEventType.LocaleChanged:
133 OnLocaleChanged((LocaleChangedEventArgs)args);
135 case NUIGadgetEventType.LowMemory:
136 OnLowMemory((LowMemoryEventArgs)args);
138 case NUIGadgetEventType.LowBattery:
139 OnLowBattery((LowBatteryEventArgs)args);
141 case NUIGadgetEventType.RegionFormatChanged:
142 OnRegionFormatChanged((RegionFormatChangedEventArgs)args);
144 case NUIGadgetEventType.DeviceORientationChanged:
145 OnDeviceOrientationChanged((DeviceOrientationEventArgs)args);
148 Log.Warn("Unknown Event Type: " + eventType);
153 private void NotifyLifecycleChanged()
155 var args = new NUIGadgetLifecycleChangedEventArgs();
158 LifecycleChanged?.Invoke(null, args);
162 /// Overrides this method if want to handle behavior when the gedget is started.
163 /// If 'base.OnCreate()' is not called, the event 'NUIGadgetLifecycleChanged' with the 'NUIGadgetLifecycleState.Created' state will not be emitted.
165 /// <returns>The main view object.</returns>
166 /// <since_tizen> 10 </since_tizen>
167 protected virtual Tizen.NUI.BaseComponents.View OnCreate()
169 State = NUIGadgetLifecycleState.Created;
170 NotifyLifecycleChanged();
175 /// Overrides this method if want to handle behavior when the gadget receives the appcontrol message.
177 /// <param name="e">The appcontrol received event argument.</param>
178 /// <since_tizen> 10 </since_tizen>
179 protected virtual void OnAppControlReceived(AppControlReceivedEventArgs e)
184 /// Overrides this method if want to handle behavior when the gadget is destroyed.
185 /// If 'base.OnDestroy()' is not called. the event 'NUIGadgetLifecycleChanged' with the 'NUIGadgetLifecycleState.Destroyed' state will not be emitted.
187 /// <since_tizen> 10 </since_tizen>
188 protected virtual void OnDestroy()
190 State = NUIGadgetLifecycleState.Destroyed;
191 NotifyLifecycleChanged();
195 /// Overrides this method if want to handle behavior when the gadget is paused.
196 /// If 'base.OnPause()' is not called. the event 'NUIGadgetLifecycleChanged' with the 'NUIGadgetLifecycleState.Paused' state will not be emitted.
198 /// <since_tizen> 10 </since_tizen>
199 protected virtual void OnPause()
201 State = NUIGadgetLifecycleState.Paused;
202 NotifyLifecycleChanged();
206 /// Overrides this method if want to handle behavior when the gadget is resumed.
207 /// If 'base.OnResume()' is not called. the event 'NUIGadgetLifecycleChanged' with the 'NUIGadgetLifecycleState.Resumed' state will not be emitted.
209 /// <since_tizen> 10 </since_tizen>
210 protected virtual void OnResume()
212 State = NUIGadgetLifecycleState.Resumed;
213 NotifyLifecycleChanged();
217 /// Overrides this method if want to handle behavior when the system language is changed.
219 /// <param name="e">The locale changed event argument.</param>
220 /// <since_tizen> 10 </since_tizen>
221 protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
226 /// Overrides this method if want to handle behavior when the system battery is low.
228 /// <param name="e">The low batter event argument.</param>
229 /// <since_tizen> 10 </since_tizen>
230 protected virtual void OnLowBattery(LowBatteryEventArgs e)
235 /// Overrides this method if want to handle behavior when the system memory is low.
237 /// <param name="e">The low memory event argument.</param>
238 /// <since_tizen> 10 </since_tizen>
239 protected virtual void OnLowMemory(LowMemoryEventArgs e)
244 /// Overrides this method if want to handle behavior when the region format is changed.
246 /// <param name="e">The region format changed event argument.</param>
247 /// <since_tizen> 10 </since_tizen>
248 protected virtual void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
253 /// Overrides this method if want to handle behavior when the device orientation is changed.
255 /// <param name="e">The device orientation changed event argument.</param>
256 /// <since_tizen> 10 </since_tizen>
257 protected virtual void OnDeviceOrientationChanged(DeviceOrientationEventArgs e)
262 /// Finishes the gadget.
264 /// <since_tizen> 10 </since_tizen>