From 38b197532dc271214e01e67c78d9bc4fef6ef475 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Fri, 13 Jan 2017 18:21:41 +0900 Subject: [PATCH] Add watch-application initial Code Change-Id: I558fcf8a314ea5910b4d3fe1d790d82f66f41b66 Signed-off-by: Junghoon Park --- LICENSE | 202 ++++++++++++ .../Interop/Interop.Libraries.cs | 24 ++ .../Interop/Interop.Watch.cs | 158 ++++++++++ .../Properties/AssemblyInfo.cs | 36 +++ .../WatchCoreBackend.cs | 300 ++++++++++++++++++ .../WatchEventType.cs | 59 ++++ ...izen.Applications.WatchApplication.Net45.csproj | 80 +++++ ...pplications.WatchApplication.Net45.project.json | 13 + .../Tizen.Applications.WatchApplication.csproj | 89 ++++++ .../Tizen.Applications.WatchApplication.nuspec | 23 ++ ...izen.Applications.WatchApplication.project.json | 11 + .../Tizen.Applications.WatchApplication.snk | Bin 0 -> 596 bytes .../Tizen.Applications/AmbientEventArgs.cs | 36 +++ .../Tizen.Applications/AmbientTickType.cs | 67 ++++ .../Tizen.Applications/SafeWatchTimeHandle.cs | 45 +++ .../Tizen.Applications/TimeEventArgs.cs | 35 +++ .../Tizen.Applications/TimeTickResolution.cs | 39 +++ .../Tizen.Applications/WatchApplication.cs | 342 +++++++++++++++++++++ .../Tizen.Applications/WatchTime.cs | 234 ++++++++++++++ .../Tizen.Applications/WatchWindow.cs | 37 +++ packaging/csapi-watch-application.manifest | 5 + packaging/csapi-watch-application.spec | 46 +++ 22 files changed, 1881 insertions(+) create mode 100755 LICENSE create mode 100755 Tizen.Applications.WatchApplication/Interop/Interop.Libraries.cs create mode 100755 Tizen.Applications.WatchApplication/Interop/Interop.Watch.cs create mode 100755 Tizen.Applications.WatchApplication/Properties/AssemblyInfo.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications.CoreBackend/WatchCoreBackend.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications.CoreBackend/WatchEventType.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.Net45.csproj create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.Net45.project.json create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.csproj create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.nuspec create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.project.json create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.snk create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications/AmbientEventArgs.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications/AmbientTickType.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications/SafeWatchTimeHandle.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications/TimeEventArgs.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications/TimeTickResolution.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications/WatchApplication.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications/WatchTime.cs create mode 100755 Tizen.Applications.WatchApplication/Tizen.Applications/WatchWindow.cs create mode 100755 packaging/csapi-watch-application.manifest create mode 100755 packaging/csapi-watch-application.spec diff --git a/LICENSE b/LICENSE new file mode 100755 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/Tizen.Applications.WatchApplication/Interop/Interop.Libraries.cs b/Tizen.Applications.WatchApplication/Interop/Interop.Libraries.cs new file mode 100755 index 0000000..77c0b48 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Interop/Interop.Libraries.cs @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2016 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. + */ + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string AppCommon = "libcapi-appfw-app-common.so.0"; + public const string AppCoreWatch = "libappcore-watch.so.1"; + } +} \ No newline at end of file diff --git a/Tizen.Applications.WatchApplication/Interop/Interop.Watch.cs b/Tizen.Applications.WatchApplication/Interop/Interop.Watch.cs new file mode 100755 index 0000000..b4ffa33 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Interop/Interop.Watch.cs @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2016 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.Runtime.InteropServices; +using Tizen.Applications; + +internal static partial class Interop +{ + internal static partial class Watch + { + internal enum AppEventType + { + LowMemory = 0, + LowBattery, + LanguageChanged, + DeviceOrientationChanged, + RegionFormatChanged, + SuspendedStateChanged + } + + internal enum ErrorCode + { + None = Tizen.Internals.Errors.ErrorCode.None, + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + InvalidContext = -0x01100000 | 0x01, + NoSuchFile = Tizen.Internals.Errors.ErrorCode.NoSuchFile, + AlreadyRunning = Tizen.Internals.Errors.ErrorCode.AlreadyInProgress + } + + internal delegate void AppEventCallback(IntPtr handle, IntPtr data); + + internal delegate bool WatchAppCreateCallback(int width, int height, IntPtr userData); + + internal delegate void WatchAppPauseCallback(IntPtr userData); + + internal delegate void WatchAppResumeCallback(IntPtr userData); + + internal delegate void WatchAppTerminateCallback(IntPtr userData); + + internal delegate void WatchAppControlCallback(IntPtr appControl, IntPtr userData); + + internal delegate void WatchAppTimeTickCallback(IntPtr watchTime, IntPtr userData); + + internal delegate void WatchAppAmbientTickCallback(IntPtr watchTime, IntPtr userData); + + internal delegate void WatchAppAmbientChangedCallback(bool ambientMode, IntPtr userData); + + [StructLayout(LayoutKind.Sequential)] + internal struct WatchAppLifecycleCallbacks + { + public WatchAppCreateCallback OnCreate; + public WatchAppControlCallback OnAppControl; + public WatchAppPauseCallback OnPause; + public WatchAppResumeCallback OnResume; + public WatchAppTerminateCallback OnTerminate; + public WatchAppTimeTickCallback OnTick; + public WatchAppAmbientTickCallback OnAmbientTick; + public WatchAppAmbientChangedCallback OnAmbientChanged; + } + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_app_main")] + internal static extern ErrorCode Main(int argc, string[] argv, ref WatchAppLifecycleCallbacks callback, IntPtr userData); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_app_exit")] + internal static extern void Exit(); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_app_add_event_handler")] + internal static extern ErrorCode AddEventHandler(out IntPtr handle, AppEventType eventType, AppEventCallback callback, IntPtr userData); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_app_remove_event_handler")] + internal static extern ErrorCode RemoveEventHandler(IntPtr handle); + + // tizen 3.0 + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_app_set_time_tick_frequency")] + internal static extern ErrorCode SetTimeTickFrequency(int ticks, TimeTickResolution type); + + // tizen 3.0 + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_app_get_time_tick_frequency")] + internal static extern ErrorCode GetTimeTickFrequency(out int ticks, out TimeTickResolution type); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_app_set_ambient_tick_type")] + internal static extern ErrorCode SetAmbientTickType(AmbientTickType type); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_app_get_ambient_tick_type")] + internal static extern ErrorCode GetAmbientTickType(out AmbientTickType type); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_delete")] + internal static extern ErrorCode WatchTimeDelete(IntPtr watchTime); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_year")] + internal static extern ErrorCode WatchTimeGetYear(SafeWatchTimeHandle handle, out int year); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_month")] + internal static extern ErrorCode WatchTimeGetMonth(SafeWatchTimeHandle handle, out int month); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_day")] + internal static extern ErrorCode WatchTimeGetDay(SafeWatchTimeHandle handle, out int day); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_day_of_week")] + internal static extern ErrorCode WatchTimeGetDayOfWeek(SafeWatchTimeHandle handle, out int day_of_week); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_hour")] + internal static extern ErrorCode WatchTimeGetHour(SafeWatchTimeHandle handle, out int hour); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_hour24")] + internal static extern ErrorCode WatchTimeGetHour24(SafeWatchTimeHandle handle, out int hour24); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_minute")] + internal static extern ErrorCode WatchTimeGetMinute(SafeWatchTimeHandle handle, out int minute); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_second")] + internal static extern ErrorCode WatchTimeGetSecond(SafeWatchTimeHandle handle, out int second); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_millisecond")] + internal static extern ErrorCode WatchTimeGetMillisecond(SafeWatchTimeHandle handle, out int millisecond); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_app_get_elm_win")] + internal static extern ErrorCode GetWin(out IntPtr win); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_utc_timestamp")] + internal static extern ErrorCode WatchTimeGetUtcTimestamp(SafeWatchTimeHandle handle, out long utc_timestamp); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_time_zone")] + internal static extern ErrorCode WatchTimeGetTimeZone(SafeWatchTimeHandle handle, out string time_zone_id); + + [DllImport(Libraries.AppCoreWatch, EntryPoint = "watch_time_get_current_time")] + internal static extern ErrorCode WatchTimeGetCurrentTime(out SafeWatchTimeHandle handle); + + // app common + [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); + + } +} diff --git a/Tizen.Applications.WatchApplication/Properties/AssemblyInfo.cs b/Tizen.Applications.WatchApplication/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..6aa4d54 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tizen.Applications.WatchApplication")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tizen.Applications.WatchApplication")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cc2aa967-232a-4a16-9b46-45f3fdb44e0d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications.CoreBackend/WatchCoreBackend.cs b/Tizen.Applications.WatchApplication/Tizen.Applications.CoreBackend/WatchCoreBackend.cs new file mode 100755 index 0000000..01f0bc1 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications.CoreBackend/WatchCoreBackend.cs @@ -0,0 +1,300 @@ +/* + * Copyright (c) 2016 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; +using Tizen.Internals.Errors; + +namespace Tizen.Applications.CoreBackend +{ + internal class WatchCoreBackend : ICoreBackend + { + private const string LOGTAG = "Tizen.Applications.WatchApplication"; + + private Dictionary _handlers = new Dictionary(); + + private bool _disposedValue = false; + + private Interop.Watch.AppEventCallback _lowMemoryCallback; + private Interop.Watch.AppEventCallback _lowBatteryCallback; + private Interop.Watch.AppEventCallback _localeChangedCallback; + private Interop.Watch.AppEventCallback _regionChnagedCallback; + + private IntPtr _lowMemoryEventHandle = IntPtr.Zero; + private IntPtr _lowBatteryEventHandle = IntPtr.Zero; + private IntPtr _localeChangedEventHandle = IntPtr.Zero; + private IntPtr _regionChnagedEventHandle = IntPtr.Zero; + + private Interop.Watch.WatchAppLifecycleCallbacks _callbacks; + + public WatchCoreBackend() + { + _lowMemoryCallback = new Interop.Watch.AppEventCallback(OnLowMemoryNative); + _lowBatteryCallback = new Interop.Watch.AppEventCallback(OnLowBatteryNative); + _localeChangedCallback = new Interop.Watch.AppEventCallback(OnLocaleChangedNative); + _regionChnagedCallback = new Interop.Watch.AppEventCallback(OnRegionChangedNative); + + _callbacks.OnCreate = new Interop.Watch.WatchAppCreateCallback(OnCreateNative); + _callbacks.OnTerminate = new Interop.Watch.WatchAppTerminateCallback(OnTerminateNative); + _callbacks.OnResume = new Interop.Watch.WatchAppResumeCallback(OnResumeNative); + _callbacks.OnPause = new Interop.Watch.WatchAppPauseCallback(OnPauseNative); + _callbacks.OnAppControl = new Interop.Watch.WatchAppControlCallback(OnAppControlNative); + + _callbacks.OnTick = new Interop.Watch.WatchAppTimeTickCallback(OnTimeTickNative); + _callbacks.OnAmbientTick = new Interop.Watch.WatchAppAmbientTickCallback(OnAmbientTickNative); + _callbacks.OnAmbientChanged = new Interop.Watch.WatchAppAmbientChangedCallback(OnAmbientChangedNative); + } + + ~WatchCoreBackend() + { + Dispose(false); + } + + 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); + } + + 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.Watch.RemoveEventHandler(_lowMemoryEventHandle); + } + if (_lowBatteryEventHandle != IntPtr.Zero) + { + Interop.Watch.RemoveEventHandler(_lowBatteryEventHandle); + } + if (_localeChangedEventHandle != IntPtr.Zero) + { + Interop.Watch.RemoveEventHandler(_localeChangedEventHandle); + } + if (_regionChnagedEventHandle != IntPtr.Zero) + { + Interop.Watch.RemoveEventHandler(_regionChnagedEventHandle); + } + + _disposedValue = true; + } + } + + public void Exit() + { + Interop.Watch.Exit(); + } + + public void Run(string[] args) + { + Interop.Watch.ErrorCode err = Interop.Watch.ErrorCode.None; + + err = Interop.Watch.AddEventHandler(out _lowMemoryEventHandle, Interop.Watch.AppEventType.LowMemory, _lowMemoryCallback, IntPtr.Zero); + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to add event handler for LowMemory event, Err = " + err); + } + + err = Interop.Watch.AddEventHandler(out _lowBatteryEventHandle, Interop.Watch.AppEventType.LowBattery, _lowBatteryCallback, IntPtr.Zero); + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to add event handler for LowBattery event, Err = " + err); + } + + err = Interop.Watch.AddEventHandler(out _localeChangedEventHandle, Interop.Watch.AppEventType.LanguageChanged, _localeChangedCallback, IntPtr.Zero); + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to add event handler for LocaleChanged event, Err = " + err); + } + + err = Interop.Watch.AddEventHandler(out _regionChnagedEventHandle, Interop.Watch.AppEventType.RegionFormatChanged, _regionChnagedCallback, IntPtr.Zero); + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to add event handler for RegionFormatChanged event, Err = " + err); + } + + err = Interop.Watch.Main(args.Length, args, ref _callbacks, IntPtr.Zero); + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to run the Watch application, Err = " + err); + } + } + + private void OnLowMemoryNative(IntPtr infoHandle, IntPtr data) + { + LowMemoryStatus status = LowMemoryStatus.None; + ErrorCode err = Interop.Watch.AppEventGetLowMemoryStatus(infoHandle, out status); + if (err != ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get memory status, Err = " + err); + } + if (_handlers.ContainsKey(WatchEventType.LowMemory)) + { + var handler = _handlers[WatchEventType.LowMemory] as Action; + handler?.Invoke(new LowMemoryEventArgs(status)); + } + } + + private void OnLowBatteryNative(IntPtr infoHandle, IntPtr data) + { + LowBatteryStatus status = LowBatteryStatus.None; + ErrorCode err = Interop.Watch.AppEventGetLowBatteryStatus(infoHandle, out status); + if (err != Tizen.Internals.Errors.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get battery status, Err = " + err); + } + if (_handlers.ContainsKey(WatchEventType.LowBattery)) + { + var handler = _handlers[WatchEventType.LowBattery] as Action; + handler?.Invoke(new LowBatteryEventArgs(status)); + } + } + private void OnLocaleChangedNative(IntPtr infoHandle, IntPtr data) + { + string lang; + ErrorCode err = Interop.Watch.AppEventGetLanguage(infoHandle, out lang); + if (err != ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get changed language. Err = " + err); + } + if (_handlers.ContainsKey(WatchEventType.LocaleChanged)) + { + var handler = _handlers[WatchEventType.LocaleChanged] as Action; + handler?.Invoke(new LocaleChangedEventArgs(lang)); + } + } + private void OnRegionChangedNative(IntPtr infoHandle, IntPtr data) + { + string region; + ErrorCode err = Interop.Watch.AppEventGetRegionFormat(infoHandle, out region); + if (err != ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get changed region format. Err = " + err); + } + if (_handlers.ContainsKey(WatchEventType.RegionFormatChanged)) + { + var handler = _handlers[WatchEventType.RegionFormatChanged] as Action; + handler?.Invoke(new RegionFormatChangedEventArgs(region)); + } + } + private bool OnCreateNative(int width, int height, IntPtr data) + { + if (_handlers.ContainsKey(WatchEventType.PreCreated)) + { + var handler = _handlers[WatchEventType.PreCreated] as Action; + handler?.Invoke(); + } + + if (_handlers.ContainsKey(WatchEventType.Created)) + { + var handler = _handlers[WatchEventType.Created] as Action; + handler?.Invoke(); + } + return true; + } + + private void OnTerminateNative(IntPtr data) + { + if (_handlers.ContainsKey(WatchEventType.Terminated)) + { + var handler = _handlers[WatchEventType.Terminated] as Action; + handler?.Invoke(); + } + } + + private void OnAppControlNative(IntPtr appControlHandle, IntPtr data) + { + if (_handlers.ContainsKey(WatchEventType.AppControlReceived)) + { + SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false); + + var handler = _handlers[WatchEventType.AppControlReceived] as Action; + + handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(safeHandle))); + } + } + + private void OnResumeNative(IntPtr data) + { + if (_handlers.ContainsKey(WatchEventType.Resumed)) + { + var handler = _handlers[WatchEventType.Resumed] as Action; + handler?.Invoke(); + } + } + + private void OnPauseNative(IntPtr data) + { + if (_handlers.ContainsKey(WatchEventType.Paused)) + { + var handler = _handlers[WatchEventType.Paused] as Action; + handler?.Invoke(); + } + } + + private void OnTimeTickNative(IntPtr watchTime, IntPtr userData) + { + if (_handlers.ContainsKey(WatchEventType.TimeTick)) + { + var handler = _handlers[WatchEventType.TimeTick] as Action; + handler?.Invoke(new TimeEventArgs() + { + Time = new WatchTime(new SafeWatchTimeHandle(watchTime, false)) + }); + } + } + + private void OnAmbientTickNative(IntPtr watchTime, IntPtr userData) + { + if (_handlers.ContainsKey(WatchEventType.AmbientTick)) + { + var handler = _handlers[WatchEventType.AmbientTick] as Action; + handler?.Invoke(new TimeEventArgs() + { + Time = new WatchTime(new SafeWatchTimeHandle(watchTime, false)) + }); + } + } + + private void OnAmbientChangedNative(bool ambientMode, IntPtr userData) + { + if (_handlers.ContainsKey(WatchEventType.AmbientChanged)) + { + var handler = _handlers[WatchEventType.AmbientChanged] as Action; + handler?.Invoke(new AmbientEventArgs() + { + Enabled = ambientMode + }); + } + } + } +} diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications.CoreBackend/WatchEventType.cs b/Tizen.Applications.WatchApplication/Tizen.Applications.CoreBackend/WatchEventType.cs new file mode 100755 index 0000000..c996029 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications.CoreBackend/WatchEventType.cs @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016 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; +using Tizen.Applications.CoreBackend; + +namespace Tizen.Applications.CoreBackend +{ + /// + /// Class that represents the type of event for backends. This class can be converted from string type. + /// + public class WatchEventType : EventType + { + /// + /// Pre-defined event type. "Created" + /// + public static readonly WatchEventType TimeTick = "TimeTick"; + + /// + /// Pre-defined event type. "AmbientTick" + /// + public static readonly WatchEventType AmbientTick = "AmbientTick"; + + /// + /// Pre-defined event type. "AmbientChanged" + /// + public static readonly WatchEventType AmbientChanged = "AmbientChanged"; + + /// + /// Initializes the WatchEventType class. + /// + /// The name of watch event type. + public WatchEventType(string name) : base(name) + { + } + + /// + /// Converts a string to WatchEventType instance. + /// + public static implicit operator WatchEventType(string value) + { + return new WatchEventType(value); + } + } +} diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.Net45.csproj b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.Net45.csproj new file mode 100755 index 0000000..f43184f --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.Net45.csproj @@ -0,0 +1,80 @@ + + + + Debug + AnyCPU + {07A0D110-3092-4A09-BF85-95555C7E7DFF} + Library + Properties + + + Tizen.Applications.WatchApplication + 512 + v4.5 + + + true + full + false + bin\Debug\Net45\ + DEBUG;TRACE + prompt + 4 + true + bin\Debug\Tizen.Applications.WatchApplication.XML + ExtendedDesignGuidelineRules.ruleset + + + pdbonly + true + bin\Release\Net45\ + TRACE + prompt + 4 + true + + + true + + + Tizen.Applications.WatchApplication.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.Net45.project.json b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.Net45.project.json new file mode 100755 index 0000000..8fb6582 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.Net45.project.json @@ -0,0 +1,13 @@ +{ + "dependencies": { + "Tizen": "1.0.2", + "Tizen.Applications.Common": "1.2.0", + "ElmSharp": "1.1.0-*" + }, + "frameworks": { + "net45": {} + }, + "runtimes": { + "win": {} + } +} diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.csproj b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.csproj new file mode 100755 index 0000000..0ed5bbc --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.csproj @@ -0,0 +1,89 @@ + + + + 14.0 + Debug + AnyCPU + 8.0.30703 + 2.0 + {CC2AA967-232A-4A16-9B46-45F3FDB44E0D} + Library + Properties + Tizen.Applications.WatchApplication + Tizen.Applications.WatchApplication + 512 + en-US + + + .NETStandard + v1.3 + .NETStandard,Version=v1.3 + false + true + $(NoWarn);1701 + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + + + Tizen.Applications.WatchApplication.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) + true + + diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.nuspec b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.nuspec new file mode 100755 index 0000000..836400c --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.nuspec @@ -0,0 +1,23 @@ + + + + Tizen.Applications.WatchApplication + $version$ + Samsung Electronics + false + https://www.apache.org/licenses/LICENSE-2.0 + https://www.tizen.org/ + https://developer.tizen.org/sites/default/files/images/tizen-pinwheel-on-light-rgb_64_64.png + © Samsung Electronics Co., Ltd All Rights Reserved + Provides the Watch Application API for Tizen.Net + + + + + + + + + + + diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.project.json b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.project.json new file mode 100755 index 0000000..07c1a4f --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.project.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "ElmSharp": "1.1.0-*", + "NETStandard.Library": "1.6.0", + "Tizen": "1.0.2", + "Tizen.Applications.Common": "1.2.0" + }, + "frameworks": { + "netstandard1.3": {} + } +} diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.snk b/Tizen.Applications.WatchApplication/Tizen.Applications.WatchApplication.snk new file mode 100755 index 0000000000000000000000000000000000000000..7ac1b002b5c0f81a5b5194224843bb744535469c GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50096S12Rh1DXm4>qRQE|Fs044$*e zEyJbLiSRL%Y#NVHY@M>K{9%``de=>mN4`TL|e33wl+OPc%mFqo0y5WXHq`9 zzb|ZJ4h&Bj6c_rG!7}`~i6%VYa##vxfyTV;!iBSG^crc_ZYFA#CU>3g9K5*jw~)Or zz!4Uw+aAT)FC3}nr!?kwh{M_Fq-Ii# z;Z*f_6NQu>yLa!^q~UAJ4yGN@`X9e*X}`7`c+Gny`pNGz9top#4Q7JitBDF~xjM?Yfw<8!w;k;&3kd6H; zc_m-w)0fvjmhV3!9a-U}J|vpk3}J!NNm;rFiy-#L)B-O5r)DkHSl_1`RKo~T`Ns1k zmW}ASU5<(A0WV&H#e}2kJfoL8I2fWqOreJRffWl&M2k)LE`<1N9254nJHy%AHN8vk zfcM~VsKgn7%Zd27DtZ~=pm20An|4X6Bx6v%A0yctfr={tz_&?S4$cPy|G@GzJ&^)7 iFLJDP0G>I0;>GMWh@X3wz0E^RqQ6^4@1FSr|AKP?HYIHU literal 0 HcmV?d00001 diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications/AmbientEventArgs.cs b/Tizen.Applications.WatchApplication/Tizen.Applications/AmbientEventArgs.cs new file mode 100755 index 0000000..aa9e7b5 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications/AmbientEventArgs.cs @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016 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 ElmSharp; +using System; + +namespace Tizen.Applications +{ + /// + /// Arguments for the event that reaised when the device enters or exits the ambient mode. + /// + public class AmbientEventArgs : EventArgs + { + /// + /// The received Ambient mode + /// + public bool Enabled { get; internal set; } + + internal AmbientEventArgs() + { + } + } +} \ No newline at end of file diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications/AmbientTickType.cs b/Tizen.Applications.WatchApplication/Tizen.Applications/AmbientTickType.cs new file mode 100755 index 0000000..c82656e --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications/AmbientTickType.cs @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2016 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 +{ + /// + /// Enumeration for Ambient tick type. + /// + public enum AmbientTickType + { + /// + /// No peridoic ambient tick. + /// + NoTick, + /// + /// Every minute. + /// + EveryMinute, + /// + /// Every 5 minutes. + /// + EveryFiveMinutes, + /// + /// Every 15 minutes. + /// + EveryFiftenMinutes, + /// + /// Every 30 minutes. + /// + EveryThirtyMinutes, + /// + /// Every hour. + /// + EveryHour, + /// + /// Every 3 hours. + /// + EveryThreeHours, + /// + /// Every 6 hours. + /// + EverySixHours, + /// + /// Every 12 hours. + /// + EveryTwelveHours, + /// + /// Every day. + /// + EveryDay + } +} diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications/SafeWatchTimeHandle.cs b/Tizen.Applications.WatchApplication/Tizen.Applications/SafeWatchTimeHandle.cs new file mode 100755 index 0000000..f87501c --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications/SafeWatchTimeHandle.cs @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 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.Runtime.InteropServices; + +namespace Tizen.Applications +{ + internal sealed class SafeWatchTimeHandle : SafeHandle + { + internal SafeWatchTimeHandle() : base(IntPtr.Zero, true) + { + } + + internal SafeWatchTimeHandle(IntPtr existingHandle, bool ownHandle) : base(IntPtr.Zero, ownHandle) + { + SetHandle(existingHandle); + } + + public override bool IsInvalid + { + get { return this.handle == IntPtr.Zero; } + } + + protected override bool ReleaseHandle() + { + Interop.Watch.WatchTimeDelete(this.handle); + this.SetHandle(IntPtr.Zero); + return true; + } + } +} \ No newline at end of file diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications/TimeEventArgs.cs b/Tizen.Applications.WatchApplication/Tizen.Applications/TimeEventArgs.cs new file mode 100755 index 0000000..1d100fe --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications/TimeEventArgs.cs @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 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 +{ + /// + /// Arguments for the event that reaised when the time tick comes. + /// + public class TimeEventArgs : EventArgs + { + /// + /// The received WatchTime. + /// + public WatchTime Time { get; internal set; } + + internal TimeEventArgs() + { + } + } +} diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications/TimeTickResolution.cs b/Tizen.Applications.WatchApplication/Tizen.Applications/TimeTickResolution.cs new file mode 100755 index 0000000..79c1b29 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications/TimeTickResolution.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 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 +{ + /// + /// Enumeration for Time tick resolution. + /// + public enum TimeTickResolution + { + /// + /// 1 ~ 60 ticks per second. + /// + TimeTicksPerSecond, + /// + /// 1 ~ 60 ticks per minute. + /// + TimeTicksPerMinute, + /// + /// 1 ~ 60 ticks per hour. + /// + TimeTicksPerHour + } +} diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications/WatchApplication.cs b/Tizen.Applications.WatchApplication/Tizen.Applications/WatchApplication.cs new file mode 100755 index 0000000..01939fb --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications/WatchApplication.cs @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2016 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 Tizen.Applications.CoreBackend; +using ElmSharp; + +namespace Tizen.Applications +{ + /// + /// The class that represents a Tizen watch application. + /// + public class WatchApplication : CoreApplication + { + /// + /// Initialize the WatchApplication class + /// + /// + /// Default backend for Watch application will be used. + /// + public WatchApplication() : base(new WatchCoreBackend()) + { + } + + /// + /// Initialize the WatchApplication class + /// + /// + /// If want to change the backend , use this constructor + /// + /// The backend instance implementing ICoreBackend interface. + public WatchApplication(ICoreBackend backend) : base(backend) + { + } + + /// + /// Instance for the window + /// + protected Widget Window; + + /// + /// Occurs whenever the application is resumed. + /// + public event EventHandler Resumed; + + /// + /// Occurs whenever the application is paused. + /// + public event EventHandler Paused; + + /// + /// Occurs whenever the time tick comes. + /// + public event EventHandler TimeTick; + + /// + /// Occurs whenever the time tick comes in ambient mode. + /// + public event EventHandler AmbientTick; + + /// + /// Occurs when the ambient mode is changed. + /// + public event EventHandler AmbientChanged; + + /// + /// Runs the UI applications' main loop. + /// + /// Arguments from commandline. + public override void Run(string[] args) + { + Backend.AddEventHandler(EventType.Resumed, OnResume); + Backend.AddEventHandler(EventType.Paused, OnPause); + + Backend.AddEventHandler(WatchEventType.TimeTick, OnTick); + Backend.AddEventHandler(WatchEventType.AmbientTick, OnAmbientTick); + Backend.AddEventHandler(WatchEventType.AmbientChanged, OnAmbientChanged); + + base.Run(args); + } + + /// + /// Overrides this method if want to handle behavior when the application is launched. + /// If base.OnCreate() is not called, the event 'Created' will not be emitted. + /// + protected override void OnCreate() + { + base.OnCreate(); + IntPtr win; + + Interop.Watch.GetWin(out win); + Window = new WatchWindow(win); + } + + /// + /// Overrides this method if want to handle behavior when the application is resumed. + /// If base.OnResume() is not called, the event 'Resumed' will not be emitted. + /// + protected virtual void OnResume() + { + Resumed?.Invoke(this, EventArgs.Empty); + } + + /// + /// Overrides this method if want to handle behavior when the application is paused. + /// If base.OnPause() is not called, the event 'Paused' will not be emitted. + /// + protected virtual void OnPause() + { + Paused?.Invoke(this, EventArgs.Empty); + } + + /// + /// Overrides this method if want to handle behavior when the time tick event comes. + /// If base.OnTick() is not called, the event 'TimeTick' will not be emitted. + /// + /// The received TimeEventArgs to get time information. + protected virtual void OnTick(TimeEventArgs time) + { + TimeTick?.Invoke(this, time); + } + + /// + /// Overrides this method if want to handle behavior when the time tick event comes in ambient mode. + /// If base.OnAmbientTick() is not called, the event 'AmbientTick' will not be emitted. + /// + /// The received TimeEventArgs to get time information. + /// http://tizen.org/privilege/alarm.set + protected virtual void OnAmbientTick(TimeEventArgs time) + { + AmbientTick?.Invoke(this, time); + } + + /// + /// Overrides this method if want to handle behavior when the ambient mode is changed. + /// If base.OnAmbientChanged() is not called, the event 'AmbientChanged' will not be emitted. + /// + /// The received AmbientEventArgs + protected virtual void OnAmbientChanged(AmbientEventArgs mode) + { + AmbientChanged?.Invoke(this, mode); + } + + /// + /// Gets the current time + /// + /// WatchTime + /// Thrown when failed to get current time because of invalid parameter. + /// Thrown when failed to get current time because memory is not enough. + /// + /// + /// class MyApp : WatchApplication + /// { + /// ... + /// public void TestMethod() + /// { + /// WatchTime wt; + /// try + /// { + /// wt = GetCurrentTime(); + /// } + /// catch + /// { + /// } + /// } + /// } + /// + /// + protected WatchTime GetCurrentTime() + { + SafeWatchTimeHandle handle; + + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetCurrentTime(out handle); + if (err != Interop.Watch.ErrorCode.None) + { + if (err == Interop.Watch.ErrorCode.InvalidParameter) + throw new InvalidOperationException("Failed to get current time. err : " + err); + else if (err == Interop.Watch.ErrorCode.OutOfMemory) + throw new OutOfMemoryException("Failed to get current time. err : " + err); + } + return new WatchTime(handle); + } + + /// + /// Gets the type of periodic ambient tick. + /// + /// AmbientTickType + /// Thrown when failed to get ambient tick type. + /// + /// + /// class MyApp : WatchApplication + /// { + /// ... + /// public void TestMethod() + /// { + /// AmbientTickType atType; + /// try + /// { + /// atType = GetAmbientTickType(); + /// } + /// catch + /// { + /// } + /// } + /// } + /// + /// + protected AmbientTickType GetAmbientTickType() + { + AmbientTickType ambientTickType; + + Interop.Watch.ErrorCode err = Interop.Watch.GetAmbientTickType(out ambientTickType); + + if(err != Interop.Watch.ErrorCode.None) + { + throw new InvalidOperationException("Failed to get ambient tick type. err : " + err); + } + + return ambientTickType; + } + + /// + /// Sets the type of periodic ambient tick. + /// OnAmbientTick will be called following settings. + /// If SetAmbientTickType is not called, OnAmbientTick will be called every minute. + /// + /// the type of ambient tick + /// Thrown when failed to set ambient tick type. + /// + /// + /// class MyApp : WatchApplication + /// { + /// ... + /// public void TestMethod() + /// { + /// try + /// { + /// SetAmbientTickType(AmbientTickType.EveryMinute); + /// } + /// catch + /// { + /// } + /// } + /// } + /// + /// + protected void SetAmbientTickType(AmbientTickType ambientTickType) + { + Interop.Watch.ErrorCode err = Interop.Watch.SetAmbientTickType(ambientTickType); + + if(err != Interop.Watch.ErrorCode.None) + { + throw new InvalidOperationException("Failed to set ambient tick type. err : " + err); + } + } + + /// + /// Sets the frequency of time tick. + /// OnTick will be called following settings. + /// If SetTimeTickFrequency is not called, OnTick will be called every second. + /// + /// Ticks the number of ticks per given resolution type + /// Type of the resolution type + /// Thrown when failed to set time tick frequency. + /// + /// + /// class MyApp : WatchApplication + /// { + /// ... + /// public void TestMethod() + /// { + /// try + /// { + /// SetTimeTickFrequency(1, TimeTickResolution.TimeTicksPerMinute); + /// } + /// catch + /// { + /// } + /// } + /// } + /// + /// + protected void SetTimeTickFrequency(int ticks, TimeTickResolution type) + { + Interop.Watch.ErrorCode err = Interop.Watch.SetTimeTickFrequency(ticks, type); + + if (err != Interop.Watch.ErrorCode.None) + { + throw new InvalidOperationException("Failed to set time tick frequency. err : " + err); + } + } + + /// + /// Gets the frequency fo time tick. + /// + /// Ticks the number of ticks per given resolution type + /// Type of the resolution type + /// Thrown when failed to get time tick frequency. + /// + /// + /// class MyApp : WatchApplication + /// { + /// ... + /// public void TestMethod() + /// { + /// int tick; + /// TimeTickResolution tType; + /// try + /// { + /// GetTimeTickFrequency(out tick, out tType); + /// } + /// catch + /// { + /// } + /// } + /// } + /// + /// + protected void GetTimeTickFrequency(out int ticks, out TimeTickResolution type) + { + Interop.Watch.ErrorCode err = Interop.Watch.GetTimeTickFrequency(out ticks, out type); + + if (err != Interop.Watch.ErrorCode.None) + { + throw new InvalidOperationException("Failed to get time tick frequency. err : " + err); + } + } + } +} diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications/WatchTime.cs b/Tizen.Applications.WatchApplication/Tizen.Applications/WatchTime.cs new file mode 100755 index 0000000..94ce435 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications/WatchTime.cs @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2016 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 +{ + /// + /// The information of Watch Time + /// + public class WatchTime + { + private readonly SafeWatchTimeHandle _handle; + private static readonly string LOGTAG = "Tizen.Applications.WatchApplication"; + + internal WatchTime(SafeWatchTimeHandle handle) + { + _handle = handle; + } + + /// + /// The information of year + /// + public int Year + { + get + { + int year; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetYear(_handle, out year); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Year err : " + err); + } + return year; + } + } + + /// + /// The information fo month + /// + public int Month + { + get + { + int month; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetMonth(_handle, out month); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Month err : " + err); + } + return month; + } + } + + /// + /// The information of day + /// + public int Day + { + get + { + int day; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetDay(_handle, out day); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Day err : " + err); + } + return day; + } + } + + /// + /// The information of day of week + /// + public int DayOfWeek + { + get + { + int dayOfWeek; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetDayOfWeek(_handle, out dayOfWeek); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Second err : " + err); + } + return dayOfWeek; + } + } + + /// + /// The information of hour + /// + public int Hour + { + get + { + int hour; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetHour(_handle, out hour); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Hour err : " + err); + } + return hour; + } + } + + /// + /// The information of hour for 24 hour form + /// + public int Hour24 + { + get + { + int hour24; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetHour24(_handle, out hour24); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Hour24 err : " + err); + } + return hour24; + } + } + + /// + /// The information of Minute + /// + public int Minute + { + get + { + int minute; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetMinute(_handle, out minute); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Minute err : " + err); + } + return minute; + } + } + + /// + /// The information of second + /// + public int Second + { + get + { + int second; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetSecond(_handle, out second); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Second err : " + err); + } + return second; + } + } + + /// + /// The information of millisecond + /// + public int Millisecond + { + get + { + int ms; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetMillisecond(_handle, out ms); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Second err : " + err); + } + return ms; + } + } + + /// + /// The information of timezone + /// + public string TimeZone + { + get + { + string zone; + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetTimeZone(_handle, out zone); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get Second err : " + err); + } + return zone; + } + } + + /// + /// The information of UTC time stamp + /// + public DateTime UtcTimestamp + { + get + { + long ts = 0; + + Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetUtcTimestamp(_handle, out ts); + + if (err != Interop.Watch.ErrorCode.None) + { + Log.Error(LOGTAG, "Failed to get UtcTimestamp err : " + err); + } + + return (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(ts).ToLocalTime(); + } + } + } +} diff --git a/Tizen.Applications.WatchApplication/Tizen.Applications/WatchWindow.cs b/Tizen.Applications.WatchApplication/Tizen.Applications/WatchWindow.cs new file mode 100755 index 0000000..2d751d5 --- /dev/null +++ b/Tizen.Applications.WatchApplication/Tizen.Applications/WatchWindow.cs @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 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 ElmSharp; +using System; + +namespace Tizen.Applications +{ + internal class WatchWindow : Widget + { + private IntPtr _handle; + + internal WatchWindow(IntPtr handle) : base() + { + _handle = handle; + Realize(null); + } + + protected override IntPtr CreateHandle(EvasObject parent) + { + return _handle; + } + } +} \ No newline at end of file diff --git a/packaging/csapi-watch-application.manifest b/packaging/csapi-watch-application.manifest new file mode 100755 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-watch-application.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/csapi-watch-application.spec b/packaging/csapi-watch-application.spec new file mode 100755 index 0000000..c045bcf --- /dev/null +++ b/packaging/csapi-watch-application.spec @@ -0,0 +1,46 @@ +Name: csapi-watch-application +Summary: Tizen Watch 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 + +AutoReqProv: no +ExcludeArch: aarch64 + +BuildRequires: dotnet-build-tools + +# C# API Requires +BuildRequires: csapi-tizen-nuget +BuildRequires: csapi-application-common-nuget +BuildRequires: elm-sharp-nuget + +%define Assemblies Tizen.Applications.WatchApplication + +%description +%{summary} + +%dotnet_import_sub_packages + +%prep +%setup -q +cp %{SOURCE1} . + +%build +for ASM in %{Assemblies}; do +%dotnet_build $ASM +%dotnet_pack $ASM/$ASM.nuspec %{version} +done + +%install +for ASM in %{Assemblies}; do +%dotnet_install $ASM +done + +%files +%manifest %{name}.manifest +%license LICENSE +%attr(644,root,root) %{dotnet_assembly_files} -- 2.7.4