From: Junghoon Park Date: Thu, 25 Aug 2016 06:57:34 +0000 (+0900) Subject: Initial update X-Git-Tag: submit/trunk/20170823.075128~64^2~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb5e638d11bbb764c269352a89b7dd339abb5f06;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Initial update Change-Id: I34307b34284e05a33a38a63ff2ee8e3a772dfb61 Signed-off-by: Junghoon Park --- diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/packaging/csapi-widget-application.manifest b/packaging/csapi-widget-application.manifest new file mode 100755 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-widget-application.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/csapi-widget-application.spec b/packaging/csapi-widget-application.spec new file mode 100755 index 0000000..05502b0 --- /dev/null +++ b/packaging/csapi-widget-application.spec @@ -0,0 +1,66 @@ +%{!?dotnet_assembly_path: %define dotnet_assembly_path %{_datadir}/assembly} +%{!?dotnet_core_path: %define dotnet_core_path %{_datadir}/tizen.net/ref} + +%if 0%{?tizen_build_devel_mode} +%define BUILDCONF Debug +%else +%define BUILDCONF Release +%endif + +Name: csapi-widget-application +Summary: Tizen Widget Application API for C# +Version: 1.0.0 +Release: 1 +Group: Development/Libraries +License: Apache-2.0 +URL: https://www.tizen.org +Source0: %{name}-%{version}.tar.gz +Source1: %{name}.manifest + +# Mono +BuildRequires: mono-compiler +BuildRequires: mono-devel + +# .NETCore +%if 0%{?_with_corefx} +AutoReqProv: no +BuildRequires: corefx-managed-32b-ref +%endif + +# C# API Requries +BuildRequires: csapi-tizen +BuildRequires: csapi-uifw +BuildRequires: csapi-application + +%description +Tizen Widget Application API for C# + +%prep +%setup -q +cp %{SOURCE1} . + +%define Assemblies Tizen.Applications.WidgetApplication + +%build +for ASM in %{Assemblies}; do +xbuild $ASM/$ASM.csproj \ +%if 0%{?_with_corefx} + /p:NoStdLib=True \ + /p:TargetFrameworkVersion=v5.0 \ + /p:AddAdditionalExplicitAssemblyReferences=False \ + /p:CoreFxPath=%{dotnet_core_path} \ +%endif + /p:Configuration=%{BUILDCONF} \ + /p:ReferencePath=%{dotnet_assembly_path} +done + +%install +mkdir -p %{buildroot}%{dotnet_assembly_path} +for ASM in %{Assemblies}; do +install -p -m 644 $ASM/bin/%{BUILDCONF}/$ASM.dll %{buildroot}%{dotnet_assembly_path} +done + +%files +%manifest %{name}.manifest +%license LICENSE +%attr(644,root,root) %{dotnet_assembly_path}/*.dll diff --git a/src/Tizen.Applications.WidgetApplication/CoreFx.References.targets b/src/Tizen.Applications.WidgetApplication/CoreFx.References.targets new file mode 100644 index 0000000..dab29ec --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/CoreFx.References.targets @@ -0,0 +1,265 @@ + + + + + False + $(CoreFxPath)/Microsoft.Win32.Primitives.dll + + + False + $(CoreFxPath)/System.AppContext.dll + + + False + $(CoreFxPath)/System.Collections.Concurrent.dll + + + False + $(CoreFxPath)/System.Collections.dll + + + False + $(CoreFxPath)/System.ComponentModel.Annotations.dll + + + False + $(CoreFxPath)/System.ComponentModel.dll + + + False + $(CoreFxPath)/System.Console.dll + + + False + $(CoreFxPath)/System.Diagnostics.Debug.dll + + + False + $(CoreFxPath)/System.Diagnostics.Process.dll + + + False + $(CoreFxPath)/System.Diagnostics.Tools.dll + + + False + $(CoreFxPath)/System.Diagnostics.TraceSource.dll + + + False + $(CoreFxPath)/System.Diagnostics.Tracing.dll + + + False + $(CoreFxPath)/System.Dynamic.Runtime.dll + + + False + $(CoreFxPath)/System.Globalization.Calendars.dll + + + False + $(CoreFxPath)/System.Globalization.dll + + + False + $(CoreFxPath)/System.Globalization.Extensions.dll + + + False + $(CoreFxPath)/System.IO.Compression.dll + + + False + $(CoreFxPath)/System.IO.Compression.ZipFile.dll + + + False + $(CoreFxPath)/System.IO.dll + + + False + $(CoreFxPath)/System.IO.FileSystem.dll + + + False + $(CoreFxPath)/System.IO.FileSystem.Primitives.dll + + + False + $(CoreFxPath)/System.IO.FileSystem.Watcher.dll + + + False + $(CoreFxPath)/System.IO.MemoryMappedFiles.dll + + + False + $(CoreFxPath)/System.IO.UnmanagedMemoryStream.dll + + + False + $(CoreFxPath)/System.Linq.dll + + + False + $(CoreFxPath)/System.Linq.Expressions.dll + + + False + $(CoreFxPath)/System.Linq.Parallel.dll + + + False + $(CoreFxPath)/System.Linq.Queryable.dll + + + False + $(CoreFxPath)/System.Net.Http.dll + + + False + $(CoreFxPath)/System.Net.NameResolution.dll + + + False + $(CoreFxPath)/System.Net.Primitives.dll + + + False + $(CoreFxPath)/System.Net.Requests.dll + + + False + $(CoreFxPath)/System.Net.Security.dll + + + False + $(CoreFxPath)/System.Net.Sockets.dll + + + False + $(CoreFxPath)/System.Net.WebHeaderCollection.dll + + + False + $(CoreFxPath)/System.Numerics.Vectors.dll + + + False + $(CoreFxPath)/System.ObjectModel.dll + + + False + $(CoreFxPath)/System.Reflection.DispatchProxy.dll + + + False + $(CoreFxPath)/System.Reflection.dll + + + False + $(CoreFxPath)/System.Reflection.Extensions.dll + + + False + $(CoreFxPath)/System.Reflection.Primitives.dll + + + False + $(CoreFxPath)/System.Reflection.TypeExtensions.dll + + + False + $(CoreFxPath)/System.Resources.ResourceManager.dll + + + False + $(CoreFxPath)/System.Runtime.dll + + + False + $(CoreFxPath)/System.Runtime.Extensions.dll + + + False + $(CoreFxPath)/System.Runtime.Handles.dll + + + False + $(CoreFxPath)/System.Runtime.InteropServices.dll + + + False + $(CoreFxPath)/System.Runtime.InteropServices.RuntimeInformation.dll + + + False + $(CoreFxPath)/System.Runtime.Loader.dll + + + False + $(CoreFxPath)/System.Runtime.Numerics.dll + + + False + $(CoreFxPath)/System.Security.Cryptography.Algorithms.dll + + + False + $(CoreFxPath)/System.Security.Cryptography.Encoding.dll + + + False + $(CoreFxPath)/System.Security.Cryptography.Primitives.dll + + + False + $(CoreFxPath)/System.Security.Cryptography.X509Certificates.dll + + + False + $(CoreFxPath)/System.Text.Encoding.dll + + + False + $(CoreFxPath)/System.Text.Encoding.Extensions.dll + + + False + $(CoreFxPath)/System.Text.RegularExpressions.dll + + + False + $(CoreFxPath)/System.Threading.dll + + + False + $(CoreFxPath)/System.Threading.Tasks.dll + + + False + $(CoreFxPath)/System.Threading.Tasks.Parallel.dll + + + False + $(CoreFxPath)/System.Threading.Thread.dll + + + False + $(CoreFxPath)/System.Threading.ThreadPool.dll + + + False + $(CoreFxPath)/System.Threading.Timer.dll + + + False + $(CoreFxPath)/System.Xml.ReaderWriter.dll + + + False + $(CoreFxPath)/System.Xml.XDocument.dll + + + \ No newline at end of file diff --git a/src/Tizen.Applications.WidgetApplication/CustomDictionary.xml b/src/Tizen.Applications.WidgetApplication/CustomDictionary.xml new file mode 100755 index 0000000..8b13789 --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/CustomDictionary.xml @@ -0,0 +1 @@ + diff --git a/src/Tizen.Applications.WidgetApplication/GlobalSuppressions.cs b/src/Tizen.Applications.WidgetApplication/GlobalSuppressions.cs new file mode 100755 index 0000000..cceb7cd Binary files /dev/null and b/src/Tizen.Applications.WidgetApplication/GlobalSuppressions.cs differ diff --git a/src/Tizen.Applications.WidgetApplication/Interop/Interop.Libraries.cs b/src/Tizen.Applications.WidgetApplication/Interop/Interop.Libraries.cs new file mode 100755 index 0000000..c68cba5 --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/Interop/Interop.Libraries.cs @@ -0,0 +1,17 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string AppCommon = "libcapi-appfw-app-common.so.0"; + public const string AppcoreWidget = "libcapi-appfw-widget-application.so.1"; + public const string WidgetService = "libwidget_service.so.1"; + } +} diff --git a/src/Tizen.Applications.WidgetApplication/Interop/Interop.Widget.cs b/src/Tizen.Applications.WidgetApplication/Interop/Interop.Widget.cs new file mode 100755 index 0000000..8e3eb7c --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/Interop/Interop.Widget.cs @@ -0,0 +1,132 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Runtime.InteropServices; + +using Tizen.Applications; + +internal static partial class Interop +{ + internal static partial class Widget + { + internal enum WidgetAppDestroyType + { + Permanent = 0, + Temporary + } + + internal enum AppEventType + { + LowMemory = 0, + LowBattery, + LanguageChanged, + DeviceOrientationChanged, + RegionFormatChanged, + SuspendedStateChanged + } + + internal enum ErrorCode : int + { + None = Tizen.Internals.Errors.ErrorCode.None, + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + ResourceBusy = Tizen.Internals.Errors.ErrorCode.ResourceBusy, + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, + Canceled = Tizen.Internals.Errors.ErrorCode.Canceled, + IoError = Tizen.Internals.Errors.ErrorCode.IoError, + TimedOut = Tizen.Internals.Errors.ErrorCode.TimedOut, + NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, + FileNoSpaceOnDevice = Tizen.Internals.Errors.ErrorCode.FileNoSpaceOnDevice, + Fault = -0x02F40000 | 0x0001, + AlreadyExist = -0x02F40000 | 0x0002, + AlreadyStarted = -0x02F40000 | 0x0004, + NotExist = -0x02F40000 | 0x0008, + Disabled = -0x02F40000 | 0x0010, + MaxExceeded = -0x02F40000 | 0x0011, + } + + internal delegate void AppEventCallback(IntPtr handle, IntPtr data); + + internal delegate IntPtr WidgetAppCreateCallback(IntPtr userData); + + internal delegate void WidgetAppTerminateCallback(IntPtr userData); + + internal delegate int WidgetInstanceCreateCallback(IntPtr context, IntPtr content, int w, int h, IntPtr userData); + + internal delegate int WidgetInstanceDestroyCallback(IntPtr context, WidgetAppDestroyType reason, IntPtr content, IntPtr userData); + + internal delegate int WidgetInstancePauseCallback(IntPtr context, IntPtr userData); + + internal delegate int WidgetInstanceResumeCallback(IntPtr context, IntPtr userData); + + internal delegate int WidgetInstanceResizeCallback(IntPtr context, int w, int h, IntPtr userData); + + internal delegate int WidgetInstanceUpdateCallback(IntPtr context, IntPtr content, int force, IntPtr userData); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_main")] + internal static extern ErrorCode Main(int argc, string[] argv, ref WidgetAppLifecycleCallbacks callback, IntPtr userData); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_exit")] + internal static extern void Exit(); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_add_event_handler")] + internal static extern ErrorCode AddEventHandler(out IntPtr handle, AppEventType eventType, AppEventCallback callback, IntPtr data); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_remove_event_handler")] + internal static extern ErrorCode RemoveEventHandler(IntPtr handle); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_class_create")] + internal static extern IntPtr CreateClass(WidgetiInstanceLifecycleCallbacks callback, IntPtr userData); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_class_add")] + internal static extern IntPtr AddClass(IntPtr handle, string classId, WidgetiInstanceLifecycleCallbacks callback, IntPtr userData); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_terminate_context")] + internal static extern ErrorCode TerminateContext(IntPtr handle); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_set_content_info")] + internal static extern ErrorCode SetContent(IntPtr handle, SafeBundleHandle content); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_set_title")] + internal static extern ErrorCode SetTitle(IntPtr handle, string title); + + [DllImport(Libraries.AppcoreWidget, EntryPoint = "widget_app_get_elm_win")] + internal static extern ErrorCode GetWin(IntPtr handle, out IntPtr win); + + [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_low_memory_status")] + internal static extern Tizen.Internals.Errors.ErrorCode AppEventGetLowMemoryStatus(IntPtr handle, out LowMemoryStatus status); + + [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_low_battery_status")] + internal static extern Tizen.Internals.Errors.ErrorCode AppEventGetLowBatteryStatus(IntPtr handle, out LowBatteryStatus status); + + [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_language")] + internal static extern Tizen.Internals.Errors.ErrorCode AppEventGetLanguage(IntPtr handle, out string lang); + + [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_region_format")] + internal static extern Tizen.Internals.Errors.ErrorCode AppEventGetRegionFormat(IntPtr handle, out string region); + + [StructLayoutAttribute(LayoutKind.Sequential)] + internal struct WidgetAppLifecycleCallbacks + { + public WidgetAppCreateCallback OnCreate; + public WidgetAppTerminateCallback OnTerminate; + } + + [StructLayoutAttribute(LayoutKind.Sequential)] + internal struct WidgetiInstanceLifecycleCallbacks + { + public WidgetInstanceCreateCallback OnCreate; + public WidgetInstanceDestroyCallback OnDestroy; + public WidgetInstancePauseCallback OnPause; + public WidgetInstanceResumeCallback OnResume; + public WidgetInstanceResizeCallback OnResize; + public WidgetInstanceUpdateCallback OnUpdate; + } + } +} diff --git a/src/Tizen.Applications.WidgetApplication/Properties/AssemblyInfo.cs b/src/Tizen.Applications.WidgetApplication/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..837590a --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System; +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Tizen.Applications.WidgetApplication")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Samsung Electronics")] +[assembly: AssemblyProduct("Tizen.Applications")] +[assembly: AssemblyCopyright("Copyright (c) 2015 Samsung Electronics Co., Ltd")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] +[assembly: CLSCompliant(true)] + +[assembly: Guid("F796B662-DCD4-4C00-90F6-70FED00A2498")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Tizen.Applications.WidgetApplication/Tizen.Applications.CoreBackend/WidgetCoreBackend.cs b/src/Tizen.Applications.WidgetApplication/Tizen.Applications.CoreBackend/WidgetCoreBackend.cs new file mode 100755 index 0000000..4c9e7c2 --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/Tizen.Applications.CoreBackend/WidgetCoreBackend.cs @@ -0,0 +1,230 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Collections.Generic; +using Tizen.Internals.Errors; + +namespace Tizen.Applications.CoreBackend +{ + internal class WidgetCoreBackend : ICoreBackend + { + protected static readonly string LogTag = typeof(WidgetCoreBackend).Namespace; + + private Dictionary _handlers = new Dictionary(); + + private bool _disposedValue = false; + + private Interop.Widget.AppEventCallback _lowMemoryCallback; + private Interop.Widget.AppEventCallback _lowBatteryCallback; + private Interop.Widget.AppEventCallback _localeChangedCallback; + private Interop.Widget.AppEventCallback _regionChangedCallback; + + private IntPtr _lowMemoryEventHandle = IntPtr.Zero; + private IntPtr _lowBatteryEventHandle = IntPtr.Zero; + private IntPtr _localeChangedEventHandle = IntPtr.Zero; + private IntPtr _regionChangedEventHandle = IntPtr.Zero; + + private Interop.Widget.WidgetAppLifecycleCallbacks _callbacks; + + internal IList WidgetTypes = new List(); + + public WidgetCoreBackend() + { + _lowMemoryCallback = new Interop.Widget.AppEventCallback(OnLowMemoryNative); + _lowBatteryCallback = new Interop.Widget.AppEventCallback(OnLowBatteryNative); + _localeChangedCallback = new Interop.Widget.AppEventCallback(OnLocaleChangedNative); + _regionChangedCallback = new Interop.Widget.AppEventCallback(OnRegionChangedNative); + + _callbacks.OnCreate = new Interop.Widget.WidgetAppCreateCallback(OnCreateNative); + _callbacks.OnTerminate = new Interop.Widget.WidgetAppTerminateCallback(OnTerminateNative); + } + + ~WidgetCoreBackend() + { + Dispose(false); + } + + internal void CreateWidgetTypes(IDictionary typeInfo) + { + foreach (Type w in typeInfo.Keys) + { + WidgetTypes.Add(new WidgetType(w, typeInfo[w])); + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!_disposedValue) + { + if (disposing) + { + // Release disposable objects + } + + if (_lowMemoryEventHandle != IntPtr.Zero) + { + Interop.Widget.RemoveEventHandler(_lowMemoryEventHandle); + } + if (_lowBatteryEventHandle != IntPtr.Zero) + { + Interop.Widget.RemoveEventHandler(_lowBatteryEventHandle); + } + if (_localeChangedEventHandle != IntPtr.Zero) + { + Interop.Widget.RemoveEventHandler(_localeChangedEventHandle); + } + if (_regionChangedEventHandle != IntPtr.Zero) + { + Interop.Widget.RemoveEventHandler(_regionChangedEventHandle); + } + + _disposedValue = true; + } + } + + public void Exit() + { + Interop.Widget.Exit(); + } + + public void Run(string[] args) + { + Interop.Widget.ErrorCode err = Interop.Widget.ErrorCode.None; + err = Interop.Widget.AddEventHandler(out _lowMemoryEventHandle, Interop.Widget.AppEventType.LowMemory, _lowMemoryCallback, IntPtr.Zero); + if (err != Interop.Widget.ErrorCode.None) + { + Log.Error(LogTag, "Failed to add event handler for LowMemory event. Err = " + err); + } + err = Interop.Widget.AddEventHandler(out _lowBatteryEventHandle, Interop.Widget.AppEventType.LowBattery, _lowBatteryCallback, IntPtr.Zero); + if (err != Interop.Widget.ErrorCode.None) + { + Log.Error(LogTag, "Failed to add event handler for LowBattery event. Err = " + err); + } + + err = Interop.Widget.AddEventHandler(out _localeChangedEventHandle, Interop.Widget.AppEventType.LanguageChanged, _localeChangedCallback, IntPtr.Zero); + if (err != Interop.Widget.ErrorCode.None) + { + Log.Error(LogTag, "Failed to add event handler for LocaleChanged event. Err = " + err); + } + + err = Interop.Widget.AddEventHandler(out _regionChangedEventHandle, Interop.Widget.AppEventType.RegionFormatChanged, _regionChangedCallback, IntPtr.Zero); + if (err != Interop.Widget.ErrorCode.None) + { + Log.Error(LogTag, "Failed to add event handler for RegionFormatChanged event. Err = " + err); + } + + err = Interop.Widget.Main(args.Length, args, ref _callbacks, IntPtr.Zero); + if (err != Interop.Widget.ErrorCode.None) + { + Log.Error(LogTag, "Failed to run the application. Err = " + err); + } + } + + private IntPtr OnCreateNative(IntPtr data) + { + if (_handlers.ContainsKey(EventType.Created)) + { + var handler = _handlers[EventType.Created] as Action; + handler?.Invoke(); + } + + IntPtr h = IntPtr.Zero; + foreach (WidgetType type in WidgetTypes) + h = type.Bind(h); + + return h; + } + + private void OnTerminateNative(IntPtr data) + { + if (_handlers.ContainsKey(EventType.Terminated)) + { + var handler = _handlers[EventType.Terminated] as Action; + handler?.Invoke(); + } + } + + public void AddEventHandler(EventType evType, Action handler) + { + _handlers.Add(evType, handler); + } + + public void AddEventHandler(EventType evType, Action handler) where TEventArgs : EventArgs + { + _handlers.Add(evType, handler); + } + + private void OnLowMemoryNative(IntPtr infoHandle, IntPtr data) + { + LowMemoryStatus status = LowMemoryStatus.None; + ErrorCode err = Interop.Widget.AppEventGetLowMemoryStatus(infoHandle, out status); + if (err != ErrorCode.None) + { + Log.Error(LogTag, "Failed to get memory status. Err = " + err); + } + if (_handlers.ContainsKey(EventType.LowMemory)) + { + var handler = _handlers[EventType.LowMemory] as Action; + handler?.Invoke(new LowMemoryEventArgs(status)); + } + } + + private void OnLowBatteryNative(IntPtr infoHandle, IntPtr data) + { + LowBatteryStatus status = LowBatteryStatus.None; + ErrorCode err = Interop.Widget.AppEventGetLowBatteryStatus(infoHandle, out status); + if (err != ErrorCode.None) + { + Log.Error(LogTag, "Failed to get battery status. Err = " + err); + } + if (_handlers.ContainsKey(EventType.LowBattery)) + { + var handler = _handlers[EventType.LowBattery] as Action; + handler?.Invoke(new LowBatteryEventArgs(status)); + } + } + + private void OnLocaleChangedNative(IntPtr infoHandle, IntPtr data) + { + string lang; + ErrorCode err = Interop.Widget.AppEventGetLanguage(infoHandle, out lang); + if (err != ErrorCode.None) + { + Log.Error(LogTag, "Failed to get changed language. Err = " + err); + } + if (_handlers.ContainsKey(EventType.LocaleChanged)) + { + var handler = _handlers[EventType.LocaleChanged] as Action; + handler?.Invoke(new LocaleChangedEventArgs(lang)); + } + } + + private void OnRegionChangedNative(IntPtr infoHandle, IntPtr data) + { + string region; + ErrorCode err = Interop.Widget.AppEventGetRegionFormat(infoHandle, out region); + if (err != ErrorCode.None) + { + Log.Error(LogTag, "Failed to get changed region format. Err = " + err); + } + if (_handlers.ContainsKey(EventType.RegionFormatChanged)) + { + var handler = _handlers[EventType.RegionFormatChanged] as Action; + handler?.Invoke(new RegionFormatChangedEventArgs(region)); + } + } + + } +} diff --git a/src/Tizen.Applications.WidgetApplication/Tizen.Applications.WidgetApplication.csproj b/src/Tizen.Applications.WidgetApplication/Tizen.Applications.WidgetApplication.csproj new file mode 100755 index 0000000..6fda119 --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/Tizen.Applications.WidgetApplication.csproj @@ -0,0 +1,114 @@ + + + + + Debug + AnyCPU + {663C5A3D-E631-4987-AEE7-F498C56A40FC} + Library + Properties + + + Tizen.Applications.WidgetApplication + v4.5 + 512 + + + true + full + true + bin\Debug\ + DEBUG;TRACE + prompt + 4 + true + bin\Debug\Tizen.Applications.WidgetApplication.XML + ExtendedDesignGuidelineRules.ruleset + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + true + + + true + + + Tizen.Applications.WidgetApplication.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ..\..\tizen\Tizen\bin\Debug\Tizen.dll + + + ..\..\tizen\Tizen.Internals\bin\Debug\Tizen.Internals.dll + + + ..\..\uifw\Tizen.UI\bin\Debug\Tizen.UI.dll + + + ..\..\task\application\Tizen.Applications\obj\Debug\Tizen.Applications.dll + + + + + {b9aa1cb2-f72d-4a30-a33b-a20c850a38a0} + Tizen.Internals + + + {7659ca59-410d-41a1-9841-586e88bc78c9} + Tizen + + + {d34841f9-046b-4dbf-9698-143386c24f78} + Tizen.UI + + + {d2d1a3ce-000e-4ab3-81c4-a8a44a008989} + Tizen.Applications + + + + + + + + \ No newline at end of file diff --git a/src/Tizen.Applications.WidgetApplication/Tizen.Applications.WidgetApplication.sln b/src/Tizen.Applications.WidgetApplication/Tizen.Applications.WidgetApplication.sln new file mode 100755 index 0000000..715c3a5 --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/Tizen.Applications.WidgetApplication.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Applications.WidgetApplication", "Tizen.Applications.WidgetApplication.csproj", "{663C5A3D-E631-4987-AEE7-F498C56A40FC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {663C5A3D-E631-4987-AEE7-F498C56A40FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {663C5A3D-E631-4987-AEE7-F498C56A40FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {663C5A3D-E631-4987-AEE7-F498C56A40FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {663C5A3D-E631-4987-AEE7-F498C56A40FC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Tizen.Applications.WidgetApplication/Tizen.Applications.WidgetApplication.snk b/src/Tizen.Applications.WidgetApplication/Tizen.Applications.WidgetApplication.snk new file mode 100755 index 0000000..7ac1b00 Binary files /dev/null and b/src/Tizen.Applications.WidgetApplication/Tizen.Applications.WidgetApplication.snk differ diff --git a/src/Tizen.Applications.WidgetApplication/Tizen.Applications/WidgetApplication.cs b/src/Tizen.Applications.WidgetApplication/Tizen.Applications/WidgetApplication.cs new file mode 100755 index 0000000..08f159c --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/Tizen.Applications/WidgetApplication.cs @@ -0,0 +1,74 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Collections.Generic; +using Tizen.Applications.CoreBackend; + +namespace Tizen.Applications +{ + /// + /// Represents a widget application. + /// + public class WidgetApplication : CoreApplication + { + /// + /// Initializes WidgetApplication class. + /// + /// map structure for derived class type and widget id + public WidgetApplication(IDictionary typeInfo) : base(new WidgetCoreBackend()) + { + WidgetCoreBackend core = Backend as WidgetCoreBackend; + + core?.CreateWidgetTypes(typeInfo); + } + + /// + /// Initializes WidgetApplication class. + /// + /// Widget id will be replaced as application id + /// derived class type + public WidgetApplication(Type type) : base(new WidgetCoreBackend()) + { + WidgetCoreBackend core = Backend as WidgetCoreBackend; + + core?.CreateWidgetTypes(new Dictionary() { {type, ApplicationInfo.ApplicationId } }); + } + + /// + /// Gets all instances of the widget associated with the type + /// + /// Class type for the widget + public IEnumerable GetInstances(Type type) + { + WidgetCoreBackend core = Backend as WidgetCoreBackend; + + if (core == null) + return null; + + foreach (WidgetType w in core.WidgetTypes) + { + if (w.ClassType == type) + { + return w.WidgetInstances; + } + } + + return null; + } + + /// + /// Runs the widget application's main loop. + /// + /// Arguments from commandline. + public override void Run(string[] args) + { + base.Run(args); + } + } +} diff --git a/src/Tizen.Applications.WidgetApplication/Tizen.Applications/WidgetBase.cs b/src/Tizen.Applications.WidgetApplication/Tizen.Applications/WidgetBase.cs new file mode 100755 index 0000000..fc669aa --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/Tizen.Applications/WidgetBase.cs @@ -0,0 +1,199 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using Tizen.UI; + +namespace Tizen.Applications +{ + /// + /// Abstract class for widget instances + /// + public abstract class WidgetBase + { + internal IntPtr Handle; + internal string Id; + protected static readonly string LogTag = typeof(WidgetBase).Namespace; + + /// + /// The main window instance of the widget instance. + /// + public Window Window { get; private set; } + + /// + /// Delete type + /// + public enum WidgetDestroyType + { + /// + /// User deleted this widget from the viewer. + /// + Permanent = 0, + + /// + /// Widget is deleted because of other reasons. (e.g. widget process is terminated temporarily by the system) + /// + Temporary + } + + /// + /// Constructor + /// + public WidgetBase() + { + } + + /// + /// Sets the content info to the widget. + /// + /// The data set to save + /// Thrown when failed because of invalid argument + /// Thrown when API is not supported in this device + /// Thrown in case of unrecoverable error + public void SetContent(Bundle info) + { + Interop.Widget.ErrorCode err = Interop.Widget.SetContent(Handle, info.SafeBundleHandle); + + if (err != Interop.Widget.ErrorCode.None) + { + Log.Error(LogTag, "Failed to set content. Err = " + err); + + switch(err) + { + case Interop.Widget.ErrorCode.InvalidParameter: + throw new ArgumentException("Invalid parameter of SetContent()"); + + case Interop.Widget.ErrorCode.NotSupported: + throw new NotSupportedException(); + + case Interop.Widget.ErrorCode.OutOfMemory: + case Interop.Widget.ErrorCode.Fault: + throw new InvalidOperationException(); + } + + } + } + + /// + /// Sends the title to the widget. + /// + /// When an accessibility mode is turned on, this string will be read + /// Thrown when failed because of invalid argument + /// Thrown when API is not supported in this device + /// Thrown in case of unrecoverable error + public void SetTitle(string title) + { + Interop.Widget.ErrorCode err = Interop.Widget.SetTitle(Handle, title); + + if (err != Interop.Widget.ErrorCode.None) + { + Log.Error(LogTag, "Failed to set title. Err = " + err); + + switch (err) + { + case Interop.Widget.ErrorCode.InvalidParameter: + throw new ArgumentException("Invalid parameter of SetContent()"); + + case Interop.Widget.ErrorCode.NotSupported: + throw new NotSupportedException(); + + case Interop.Widget.ErrorCode.OutOfMemory: + case Interop.Widget.ErrorCode.Fault: + throw new InvalidOperationException(); + } + } + } + + /// + /// Finishes context for the widget instance. + /// + /// Thrown when API is not supported in this device + /// Thrown in case of unrecoverable error + public void Exit() + { + Interop.Widget.ErrorCode err = Interop.Widget.TerminateContext(Handle); + + if (err != Interop.Widget.ErrorCode.None) + { + Log.Error(LogTag, "Failed to terminate context. Err = " + err); + + switch (err) + { + case Interop.Widget.ErrorCode.NotSupported: + throw new NotSupportedException(); + + case Interop.Widget.ErrorCode.InvalidParameter: + case Interop.Widget.ErrorCode.Fault: + throw new InvalidOperationException(); + } + } + } + + internal void Bind(IntPtr handle, string id) + { + Handle = handle; + Id = id; + } + + /// + /// Overrides this method if want to handle behavior when the widget instance is started. + /// + /// The data set for the previous status + /// The pixel value for widget width + /// The pixel value for widget height + public virtual void OnCreate(Bundle content, int w, int h) + { + IntPtr win; + + Interop.Widget.GetWin(Handle, out win); + + //TODO: convert win to an instance of Window + } + + /// + /// Overrides this method if want to handle behavior when the widget instance is destroyed. + /// + /// The reason for destruction + /// The data set to save + public virtual void OnDestroy(WidgetDestroyType reason, Bundle content) + { + } + + /// + /// Overrides this method if want to handle behavior when the widget instance is paused. + /// + public virtual void OnPause() + { + } + + /// + /// Overrides this method if want to handle behavior when the widget instance is resumed. + /// + public virtual void OnResume() + { + } + + /// + /// Overrides this method if want to handle behavior when the widget instance is resized. + /// + /// Widget width + /// Widget height + public virtual void OnResize(int w, int h) + { + } + + /// + /// Overrides this method if want to handle behavior when the widget instance should be updated. + /// + /// The data set for updating this widget. It will be provided by requester. + /// Although the widget is paused, if it is TRUE, the widget can be updated + public virtual void OnUpdate(Bundle content, bool isForce) + { + } + } +} diff --git a/src/Tizen.Applications.WidgetApplication/Tizen.Applications/WidgetType.cs b/src/Tizen.Applications.WidgetApplication/Tizen.Applications/WidgetType.cs new file mode 100755 index 0000000..18e1521 --- /dev/null +++ b/src/Tizen.Applications.WidgetApplication/Tizen.Applications/WidgetType.cs @@ -0,0 +1,135 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Collections.Generic; + +namespace Tizen.Applications +{ + internal class WidgetType + { + internal readonly Type ClassType; + internal readonly string Id; + internal IList WidgetInstances = new List(); + + private Interop.Widget.WidgetiInstanceLifecycleCallbacks _callbacks; + + internal WidgetType(Type ctype, string id) + { + ClassType = ctype; + Id = id; + _callbacks.OnCreate = new Interop.Widget.WidgetInstanceCreateCallback(OnCreate); + _callbacks.OnDestroy = new Interop.Widget.WidgetInstanceDestroyCallback(OnDestroy); + _callbacks.OnPause = new Interop.Widget.WidgetInstancePauseCallback(OnPause); + _callbacks.OnResume = new Interop.Widget.WidgetInstanceResumeCallback(OnResume); + _callbacks.OnResize = new Interop.Widget.WidgetInstanceResizeCallback(OnResize); + _callbacks.OnUpdate = new Interop.Widget.WidgetInstanceUpdateCallback(OnUpdate); + } + + internal IntPtr Bind(IntPtr h) + { + return Interop.Widget.AddClass(h, Id, _callbacks, IntPtr.Zero); + } + + private int OnCreate(IntPtr context, IntPtr content, int w, int h, IntPtr userData) + { + WidgetBase b = Activator.CreateInstance(ClassType) as WidgetBase; + Bundle bundle = null; + + if (b == null) + return 0; + + b.Bind(context, Id); + WidgetInstances.Add(b); + if (content != IntPtr.Zero) + bundle = new Bundle(new SafeBundleHandle(content, false)); + b.OnCreate(bundle, w, h); + + return 0; + } + + private int OnDestroy(IntPtr context, Interop.Widget.WidgetAppDestroyType reason, IntPtr content, IntPtr userData) + { + foreach (WidgetBase w in WidgetInstances) + { + if(w.Handle == context) + { + Bundle bundle = null; + + if (content != IntPtr.Zero) + bundle = new Bundle(new SafeBundleHandle(content, false)); + + w.OnDestroy(reason == Interop.Widget.WidgetAppDestroyType.Permanent ? + WidgetBase.WidgetDestroyType.Permanent : + WidgetBase.WidgetDestroyType.Temporary, bundle); + WidgetInstances.Remove(w); + break; + } + } + + return 0; + } + + private int OnPause(IntPtr context, IntPtr userData) + { + foreach (WidgetBase w in WidgetInstances) + { + if (w.Handle == context) + { + w.OnPause(); + break; + } + } + return 0; + } + + private int OnResume(IntPtr context, IntPtr userData) + { + foreach (WidgetBase w in WidgetInstances) + { + if (w.Handle == context) + { + w.OnResume(); + break; + } + } + return 0; + } + + private int OnResize(IntPtr context, int w, int h, IntPtr userData) + { + foreach (WidgetBase o in WidgetInstances) + { + if (o.Handle == context) + { + o.OnResize(w, h); + break; + } + } + return 0; + } + + private int OnUpdate(IntPtr context, IntPtr content, int force, IntPtr userData) + { + foreach (WidgetBase o in WidgetInstances) + { + if (o.Handle == context) + { + Bundle bundle = null; + + if (content != IntPtr.Zero) + bundle = new Bundle(new SafeBundleHandle(content, false)); + o.OnUpdate(bundle, force != 0 ? true : false); + break; + } + } + return 0; + } + } +} +