internal enum NativeComponentType
{
Frame = 0,
- Service
+ Service,
+ Widget
}
internal enum NativeDisplayStatus {
public ServiceSuspendedStateCallback OnSuspendedState;
}
+ internal delegate IntPtr WidgetCreateCallback(IntPtr context, int width, int height, IntPtr userData);
+ internal delegate void WidgetStartCallback(IntPtr context, bool restarted, IntPtr userData);
+ internal delegate void WidgetResumeCallback(IntPtr context, IntPtr userData);
+ internal delegate void WidgetPauseCallback(IntPtr context, IntPtr userData);
+ internal delegate void WidgetStopCallback(IntPtr context, IntPtr userData);
+ internal delegate void WidgetDestroyCallback(IntPtr context, bool permanent, IntPtr userData);
+ internal delegate void WidgetRestoreCallback(IntPtr context, IntPtr content, IntPtr userData);
+ internal delegate void WidgetSaveCallback(IntPtr context, IntPtr content, IntPtr userData);
+ internal delegate void WidgetDeviceOrientationChangedCallback(IntPtr context, int orientation, IntPtr userData);
+ internal delegate void WidgetLanguageChangedCallback(IntPtr context, string language, IntPtr userData);
+ internal delegate void WidgetRegionFormatChangedCallback(IntPtr context, string region, IntPtr userData);
+ internal delegate void WidgetLowBatteryCallback(IntPtr context, int status, IntPtr userData);
+ internal delegate void WidgetLowMemoryCallback(IntPtr context, int status, IntPtr userData);
+ internal delegate void WidgetSuspendedStateCallback(IntPtr context, int state, IntPtr userData);
+
+ internal struct WidgetLifecycleCallbacks
+ {
+ public WidgetCreateCallback OnCreate;
+ public WidgetStartCallback OnStart;
+ public WidgetResumeCallback OnResume;
+ public WidgetPauseCallback OnPause;
+ public WidgetStopCallback OnStop;
+ public WidgetDestroyCallback OnDestroy;
+ public WidgetRestoreCallback OnRestore;
+ public WidgetSaveCallback OnSave;
+ public WidgetDeviceOrientationChangedCallback OnDeviceOrientationChanged;
+ public WidgetLanguageChangedCallback OnLanguageChanged;
+ public WidgetRegionFormatChangedCallback OnRegionFormatChanged;
+ public WidgetLowBatteryCallback OnLowBattery;
+ public WidgetLowMemoryCallback OnLowMemory;
+ public WidgetSuspendedStateCallback OnSuspendedState;
+ }
+
internal delegate IntPtr BaseCreateCallback(IntPtr context, IntPtr userData);
internal delegate void BaseDestroyCallback(IntPtr context, IntPtr userData);
internal delegate void BaseRestoreCallback(IntPtr context, IntPtr content, IntPtr userData);
[DllImport(Libraries.CompCoreBase, EntryPoint = "component_based_app_base_add_service_component")]
internal static extern IntPtr BaseAddServiceComponent(IntPtr comp_class, string compId, ref ServiceLifecycleCallbacks callback, IntPtr userData);
+ [DllImport(Libraries.WidgetCompCoreBase, EntryPoint = "component_based_app_base_add_widget_component")]
+ internal static extern IntPtr BaseAddWidgetComponent(IntPtr comp_class, string compId, ref WidgetLifecycleCallbacks callback, IntPtr userData);
+
[DllImport(Libraries.CompCoreBase, EntryPoint = "base_frame_create_window")]
internal static extern IntPtr BaseFrameCreateWindow(out IntPtr winHandle, int winId, IntPtr raw);
[DllImport(Libraries.CompCoreBase, EntryPoint = "base_frame_get_display_status")]
internal static extern ErrorCode BaseFrameGetDisplayStatus(IntPtr context, out NativeDisplayStatus status);
+ [DllImport(Libraries.WidgetCompCoreBase, EntryPoint = "base_widget_create_window")]
+ internal static extern IntPtr BaseWidgetCreateWindow(out IntPtr winHandle, int winId, IntPtr raw);
+
+ [DllImport(Libraries.WidgetCompCoreBase, EntryPoint = "base_widget_window_get_id")]
+ internal static extern IntPtr BaseWidgetWindowGetId(IntPtr winHandle, out int winId);
+
+ [DllImport(Libraries.WidgetCompCoreBase, EntryPoint = "base_widget_window_get_raw")]
+ internal static extern IntPtr BaseWidgetWindowGetRaw(IntPtr winHandle, out IntPtr raw);
+
[DllImport(Libraries.CompCoreBase, EntryPoint = "component_get_instance_id")]
internal static extern ErrorCode GetInstanceId(IntPtr context, out string instanceId);
internal static partial class Libraries
{
public const string CompCoreBase = "libcomponent-based-core-base.so.1";
+ public const string WidgetCompCoreBase = "libcomponent-based-core-widget-base.so.1";
public const string CompApplication = "libcomponent-based-application.so.1";
+ public const string WidgetEflComp = "libcomponent-based-efl-widget.so.1";
public const string CompAppControl = "libcomponent-based-app-control.so.1";
public const string CompUri = "libcomponent-based-uri.so.1";
public const string AppControl = "libcapi-appfw-app-control.so.0";
Log.Info(LogTag, "Add service component");
_componentFactories.Add(compType, new ServiceComponentStateManager(compType, compId, this));
}
+ else if (typeof(WidgetComponent).IsAssignableFrom(compType))
+ {
+ Log.Info(LogTag, "Add widget component");
+ _componentFactories.Add(compType, new WidgetComponentStateManager(compType, compId, this));
+ }
else
{
throw new ArgumentException("compType must be sub type of FrameComponent or ServiceComponent", "compType");
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Applications.ComponentBased.Common
+{
+ /// <summary>
+ /// Proxy for window
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public interface IWindowProxy : IWindowInfo
+ {
+ /// <summary>
+ /// Initialize window
+ /// </summary>
+ /// <param name="width">The width of the window</param>
+ /// <param name="height">The height of the window</param>
+ void InitializeWindow(int width, int height);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Applications.ComponentBased.Common
+{
+ /// <summary>
+ /// The class for showing UI module
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public abstract class WidgetComponent : BaseComponent
+ {
+
+ /// <summary>
+ /// Override this method to handle behavior when the component is launched.
+ /// </summary>
+ /// <param name="width">The width of the widget component instance</param>
+ /// <param name="height">The height of the widget component instance</param>
+ /// <returns>True if a service component is successfully created</returns>
+ /// <since_tizen> 9 </since_tizen>
+ public abstract bool OnCreate(int width, int height);
+
+ /// <summary>
+ /// Override this method to create window. It will be called before OnCreate method.
+ /// </summary>
+ /// <param name="width">The width of the widget window</param>
+ /// <param name="height">The height of the widget window</param>
+ /// <returns>Window object to use</returns>
+ /// <since_tizen> 9 </since_tizen>
+ public abstract IWindowProxy CreateWindowInfo(int width, int height);
+
+ /// <summary>
+ /// Overrid this method if want to handle behavior when the component is started.
+ /// </summary>
+ /// <param name="restarted">True if it was restarted</param>
+ /// <since_tizen> 9 </since_tizen>
+ public virtual void OnStart(bool restarted)
+ {
+ }
+
+ /// <summary>
+ /// Override this method if you want to handle the behavior when the component is resumed.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public virtual void OnResume()
+ {
+ }
+
+ /// <summary>
+ /// Override this method if you want to handle the behavior when the component is paused.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public virtual void OnPause()
+ {
+ }
+
+ /// <summary>
+ /// Override this method if you want to handle the behavior when the component is stopped.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public virtual void OnStop()
+ {
+ }
+
+ /// <summary>
+ /// Override this method if want to handle behavior when the component is destroyed.
+ /// </summary>
+ /// <param name="permanent">True if the instance is permanent</param>
+ /// <since_tizen> 9 </since_tizen>
+ public virtual void OnDestroy(bool permanent)
+ {
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+
+namespace Tizen.Applications.ComponentBased.Common
+{
+ internal class WidgetComponentStateManager : ComponentStateManger
+ {
+ private Interop.CBApplication.WidgetLifecycleCallbacks _callbacks;
+ private const string LogTag = "Tizen.Applications";
+ private IDictionary<string, IWindowProxy> _winDic = new Dictionary<string, IWindowProxy>();
+
+ internal WidgetComponentStateManager(Type ctype, string id, ComponentBasedApplication parent) : base(ctype, id, parent)
+ {
+ _callbacks.OnDeviceOrientationChanged = new Interop.CBApplication.WidgetDeviceOrientationChangedCallback(OnDeviceOrientationChangedCallback);
+ _callbacks.OnLanguageChanged = new Interop.CBApplication.WidgetLanguageChangedCallback(OnLanguageChangedCallback);
+ _callbacks.OnLowBattery = new Interop.CBApplication.WidgetLowBatteryCallback(OnLowBatteryCallback);
+ _callbacks.OnLowMemory = new Interop.CBApplication.WidgetLowMemoryCallback(OnLowMemoryCallback);
+ _callbacks.OnRegionFormatChanged = new Interop.CBApplication.WidgetRegionFormatChangedCallback(OnRegionFormatChangedCallback);
+ _callbacks.OnRestore = new Interop.CBApplication.WidgetRestoreCallback(OnRestoreCallback);
+ _callbacks.OnSave = new Interop.CBApplication.WidgetSaveCallback(OnSaveCallback);
+ _callbacks.OnSuspendedState = new Interop.CBApplication.WidgetSuspendedStateCallback(OnSuspendedStateCallback);
+ _callbacks.OnCreate = new Interop.CBApplication.WidgetCreateCallback(OnCreateCallback);
+ _callbacks.OnDestroy = new Interop.CBApplication.WidgetDestroyCallback(OnDestroyCallback);
+ _callbacks.OnPause = new Interop.CBApplication.WidgetPauseCallback(OnPauseCallback);
+ _callbacks.OnResume = new Interop.CBApplication.WidgetResumeCallback(OnResumeCallback);
+ _callbacks.OnStart = new Interop.CBApplication.WidgetStartCallback(OnStartCallback);
+ _callbacks.OnStop = new Interop.CBApplication.WidgetStopCallback(OnStopCallback);
+ Parent = parent;
+ }
+
+ private IntPtr OnCreateCallback(IntPtr context, int width, int height, IntPtr userData)
+ {
+ WidgetComponent fc = Activator.CreateInstance(ComponentClassType) as WidgetComponent;
+ if (fc == null)
+ {
+ Log.Error(LogTag, "Fail to create instance");
+ return IntPtr.Zero;
+ }
+
+ string id;
+ Interop.CBApplication.GetInstanceId(context, out id);
+ fc.Bind(context, ComponentId, id, Parent);
+
+ IntPtr winHandle;
+ IWindowProxy win = fc.CreateWindowInfo(width, height);
+ if (win == null)
+ return IntPtr.Zero;
+
+ win.InitializeWindow(width, height);
+ _winDic.Add(id, win);
+ if (!fc.OnCreate(width, height))
+ {
+ Log.Error(LogTag, "OnCreate fail");
+ return IntPtr.Zero;
+ }
+ Interop.CBApplication.BaseWidgetCreateWindow(out winHandle, win.ResourceId, IntPtr.Zero);
+
+ AddComponent(fc);
+ return winHandle;
+ }
+
+ private void OnStartCallback(IntPtr context, bool restarted, IntPtr userData)
+ {
+ foreach (WidgetComponent fc in Instances)
+ {
+ if (fc.Handle == context)
+ {
+ fc.OnStart(restarted);
+ break;
+ }
+ }
+ }
+
+ private void OnResumeCallback(IntPtr context, IntPtr userData)
+ {
+ foreach (WidgetComponent fc in Instances)
+ {
+ if (fc.Handle == context)
+ {
+ fc.OnResume();
+ break;
+ }
+ }
+ }
+
+ private void OnPauseCallback(IntPtr context, IntPtr userData)
+ {
+ foreach (WidgetComponent fc in Instances)
+ {
+ if (fc.Handle == context)
+ {
+ fc.OnPause();
+ break;
+ }
+ }
+ }
+
+ private void OnStopCallback(IntPtr context, IntPtr userData)
+ {
+ foreach (WidgetComponent fc in Instances)
+ {
+ if (fc.Handle == context)
+ {
+ fc.OnStop();
+ break;
+ }
+ }
+ }
+
+ private void OnDestroyCallback(IntPtr context, bool permanent, IntPtr userData)
+ {
+ foreach (WidgetComponent fc in Instances)
+ {
+ if (fc.Handle == context)
+ {
+ fc.OnDestroy(permanent);
+ _winDic[fc.Id].Dispose();
+ RemoveComponent(fc);
+ break;
+ }
+ }
+ return;
+ }
+
+ internal override IntPtr Bind(IntPtr h)
+ {
+ return Interop.CBApplication.BaseAddWidgetComponent(h, ComponentId, ref _callbacks, IntPtr.Zero);
+ }
+ }
+}