2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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.
17 using Tizen.Applications;
18 using Tizen.Applications.CoreBackend;
19 using System.Collections.Generic;
20 using System.ComponentModel;
21 using System.Threading;
27 /// Represents an application that have UI screen. The NUIWidgetApplication class has a default stage.
29 /// <since_tizen> 4 </since_tizen>
30 public class NUIWidgetApplication : CoreApplication
33 /// The default constructor.
35 /// <remarks>Widget ID will be replaced as the application ID.</remarks>
36 /// <param name="widgetType">Derived widget class type.</param>
37 public NUIWidgetApplication(System.Type widgetType) : base(new NUIWidgetCoreBackend())
39 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
40 NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
41 core?.RegisterWidgetInfo(new Dictionary<System.Type, string> { { widgetType, ApplicationInfo.ApplicationId } });
45 /// The constructor for multi widget class and instance.
47 /// <param name="widgetTypes">List of derived widget class type.</param>
48 public NUIWidgetApplication(Dictionary<System.Type, string> widgetTypes) : base(new NUIWidgetCoreBackend())
50 if (widgetTypes == null)
52 throw new InvalidOperationException("Dictionary is null");
56 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
57 NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
58 core?.RegisterWidgetInfo(widgetTypes);
63 /// The default constructor with stylesheet.
65 /// <remarks>Widget ID will be replaced as the application ID.</remarks>
66 /// <param name="widgetType">Derived widget class type.</param>
67 /// <param name="styleSheet">The styleSheet url.</param>
68 /// <since_tizen> 4 </since_tizen>
69 public NUIWidgetApplication(System.Type widgetType, string styleSheet) : base(new NUIWidgetCoreBackend(styleSheet))
71 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
72 NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
73 core?.RegisterWidgetInfo(new Dictionary<System.Type, string> { { widgetType, ApplicationInfo.ApplicationId } });
77 /// Add WidgetInfo in runtime
79 /// <param name="widgetType">Derived widget class type.</param>
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public void AddWidgetType(System.Type widgetType)
83 NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
84 core?.AddWidgetInfo(new Dictionary<System.Type, string> { { widgetType, ApplicationInfo.ApplicationId } });
88 /// Add WidgetInfo in runtime
90 /// <param name="widgetTypes">Derived widget class type.</param>
91 [EditorBrowsable(EditorBrowsableState.Never)]
92 public void AddWidgetType(Dictionary<System.Type, string> widgetTypes)
94 NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
95 core?.AddWidgetInfo(widgetTypes);
98 internal WidgetApplication ApplicationHandle
102 return ((NUIWidgetCoreBackend)this.Backend).WidgetApplicationHandle;
107 /// Run NUIWidgetApplication.
109 /// <param name="args">Arguments from commandline.</param>
110 /// <since_tizen> 4 </since_tizen>
111 public override void Run(string[] args)
113 Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
118 /// Exit NUIWidgetApplication.
120 /// <since_tizen> 4 </since_tizen>
121 public override void Exit()
123 Tizen.Log.Fatal("NUI", "### NUIWidgetApplication Exit called");
128 /// Overrides this method if want to handle OnLocaleChanged behavior.
130 /// <since_tizen> 4 </since_tizen>
131 protected override void OnLocaleChanged(LocaleChangedEventArgs e)
133 Log.Fatal("NUI", "OnLocaleChanged() is called!");
134 base.OnLocaleChanged(e);
138 /// Overrides this method if want to handle OnLowBattery behavior.
140 /// <since_tizen> 4 </since_tizen>
141 protected override void OnLowBattery(LowBatteryEventArgs e)
143 Log.Fatal("NUI", "OnLowBattery() is called!");
144 base.OnLowBattery(e);
148 /// Overrides this method if want to handle OnLowMemory behavior.
150 /// <since_tizen> 4 </since_tizen>
151 protected override void OnLowMemory(LowMemoryEventArgs e)
153 Log.Fatal("NUI", "OnLowMemory() is called!");
158 /// Overrides this method if want to handle OnRegionFormatChanged behavior.
160 /// <since_tizen> 4 </since_tizen>
161 protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
163 Log.Fatal("NUI", "OnRegionFormatChanged() is called!");
164 base.OnRegionFormatChanged(e);
168 /// Overrides this method if want to handle OnTerminate behavior.
170 /// <since_tizen> 4 </since_tizen>
171 protected override void OnTerminate()
173 Log.Fatal("NUI", "OnTerminate() is called!");
178 /// Overrides this method if want to handle OnPreCreate behavior.
180 /// <since_tizen> 4 </since_tizen>
181 protected virtual void OnPreCreate()
183 Log.Fatal("NUI", "OnPreCreate() is called!");
187 /// Overrides this method if want to handle OnCreate behavior.
189 /// <since_tizen> 4 </since_tizen>
190 protected override void OnCreate()
192 // This is also required to create DisposeQueue on main thread.
193 DisposeQueue disposeQ = DisposeQueue.Instance;
194 disposeQ.Initialize();
195 Log.Fatal("NUI", "OnCreate() is called!");