From: ChangGyu Choi Date: Mon, 8 Feb 2021 08:59:25 +0000 (+0900) Subject: [Tizen.Applications.ComponentBased][TCSACR-400] Add WidgetComponent API (#2604) X-Git-Tag: accepted/tizen/unified/20210219.040944~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cd188f01d41c186e9e8a282210d549da4e8738fc;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Tizen.Applications.ComponentBased][TCSACR-400] Add WidgetComponent API (#2604) * Add widget component * Fix tizen version in description * Remove unnecessary file * Remove unnecessary tag * Fix description Co-authored-by: hjhun <36876573+hjhun@users.noreply.github.com> --- diff --git a/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs b/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs index 5abc2ac..eaad727 100644 --- a/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs +++ b/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs @@ -60,7 +60,8 @@ internal static partial class Interop internal enum NativeComponentType { Frame = 0, - Service + Service, + Widget } internal enum NativeDisplayStatus { @@ -132,6 +133,39 @@ internal static partial class Interop 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); @@ -155,6 +189,9 @@ internal static partial class Interop [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); @@ -167,6 +204,15 @@ internal static partial class Interop [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); diff --git a/src/Tizen.Applications.ComponentBased/Interop/Interop.Libraries.cs b/src/Tizen.Applications.ComponentBased/Interop/Interop.Libraries.cs index 43a218d..f536eea 100755 --- a/src/Tizen.Applications.ComponentBased/Interop/Interop.Libraries.cs +++ b/src/Tizen.Applications.ComponentBased/Interop/Interop.Libraries.cs @@ -19,7 +19,9 @@ internal static partial class Interop 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"; diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentBasedApplication.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentBasedApplication.cs index 641817c..8b6cf70 100755 --- a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentBasedApplication.cs +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentBasedApplication.cs @@ -84,6 +84,11 @@ namespace Tizen.Applications.ComponentBased.Common 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"); diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/IWindowProxy.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/IWindowProxy.cs new file mode 100644 index 0000000..08551dc --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/IWindowProxy.cs @@ -0,0 +1,34 @@ +/* + * 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 +{ + /// + /// Proxy for window + /// + /// 9 + public interface IWindowProxy : IWindowInfo + { + /// + /// Initialize window + /// + /// The width of the window + /// The height of the window + void InitializeWindow(int width, int height); + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponent.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponent.cs new file mode 100644 index 0000000..6f69360 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponent.cs @@ -0,0 +1,88 @@ +/* + * 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 +{ + /// + /// The class for showing UI module + /// + /// 9 + public abstract class WidgetComponent : BaseComponent + { + + /// + /// Override this method to handle behavior when the component is launched. + /// + /// The width of the widget component instance + /// The height of the widget component instance + /// True if a service component is successfully created + /// 9 + public abstract bool OnCreate(int width, int height); + + /// + /// Override this method to create window. It will be called before OnCreate method. + /// + /// The width of the widget window + /// The height of the widget window + /// Window object to use + /// 9 + public abstract IWindowProxy CreateWindowInfo(int width, int height); + + /// + /// Overrid this method if want to handle behavior when the component is started. + /// + /// True if it was restarted + /// 9 + public virtual void OnStart(bool restarted) + { + } + + /// + /// Override this method if you want to handle the behavior when the component is resumed. + /// + /// 9 + public virtual void OnResume() + { + } + + /// + /// Override this method if you want to handle the behavior when the component is paused. + /// + /// 9 + public virtual void OnPause() + { + } + + /// + /// Override this method if you want to handle the behavior when the component is stopped. + /// + /// 9 + public virtual void OnStop() + { + } + + /// + /// Override this method if want to handle behavior when the component is destroyed. + /// + /// True if the instance is permanent + /// 9 + public virtual void OnDestroy(bool permanent) + { + } + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponentStateManager.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponentStateManager.cs new file mode 100644 index 0000000..8e6512c --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponentStateManager.cs @@ -0,0 +1,146 @@ +/* + * 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 _winDic = new Dictionary(); + + 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); + } + } +}