commit 67624ae1795e5730028767ecf72d4db64fdba204 Author: Ray Date: Sun Oct 6 20:41:25 2019 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c7473d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bin +/obj diff --git a/ClockViewModel.cs b/ClockViewModel.cs new file mode 100644 index 0000000..6b0d693 --- /dev/null +++ b/ClockViewModel.cs @@ -0,0 +1,60 @@ +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace TizenWatchfaceApp1 +{ + public class ClockViewModel : INotifyPropertyChanged + { + protected DateTime time = DateTime.MinValue; + protected int heartRate = 0; + protected int battery = 0; + + public DateTime Time + { + get => time; + set + { + if (time == value) return; + + time = value; + + OnPropertyChanged(); + } + } + + public int HeartRate + { + get => heartRate; + set + { + if (heartRate == value) return; + + heartRate = value; + + OnPropertyChanged(); + } + } + + public int Battery + { + get => battery; + set + { + if (battery == value) return; + + battery = value; + + OnPropertyChanged(); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected void OnPropertyChanged([CallerMemberName] string propertyName = "") + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + } +} diff --git a/TizenWatchfaceApp1.cs b/TizenWatchfaceApp1.cs new file mode 100644 index 0000000..aae0b5c --- /dev/null +++ b/TizenWatchfaceApp1.cs @@ -0,0 +1,65 @@ +using System; +using Tizen.Applications; +using Tizen.System; +using Tizen.Wearable.CircularUI.Forms.Renderer.Watchface; + +namespace TizenWatchfaceApp1 +{ + class Program : FormsWatchface + { + protected WatchFaceApplication mainApplication = null; + + protected override void OnCreate() + { + base.OnCreate(); + + mainApplication = new WatchFaceApplication(); + mainApplication.ViewModel.Battery = Battery.Percent; + mainApplication.ViewModel.Time = DateTime.Now; + + Battery.ChargingStateChanged += battery_ChargingStateChanged; + + LoadWatchface(mainApplication); + } + + protected override void OnTick(TimeEventArgs time) + { + base.OnTick(time); + + if (mainApplication != null) + { + mainApplication.ViewModel.Time = new DateTime(time.Time.Year, time.Time.Month, time.Time.Day, time.Time.Hour24, time.Time.Minute, time.Time.Second, time.Time.Millisecond); + } + } + + protected void battery_ChargingStateChanged(object sender, BatteryChargingStateChangedEventArgs e) + { + if (mainApplication != null) + { + mainApplication.ViewModel.Battery = Battery.Percent; + } + } + + + //protected override void OnAmbientChanged(AmbientEventArgs mode) + //{ + // base.OnAmbientChanged(mode); + //} + + //protected override void OnAmbientTick(TimeEventArgs time) + //{ + // base.OnAmbientTick(time); + //} + + static void Main(string[] args) + { + var app = new Program(); + + global::Xamarin.Forms.Platform.Tizen.Forms.Init(app); + global::Tizen.Wearable.CircularUI.Forms.Renderer.FormsCircularUI.Init(); + + app.Run(args); + } + + } +} diff --git a/TizenWatchfaceApp1.csproj b/TizenWatchfaceApp1.csproj new file mode 100644 index 0000000..de6455b --- /dev/null +++ b/TizenWatchfaceApp1.csproj @@ -0,0 +1,31 @@ + + + + Exe + tizen40 + + + + portable + + + None + + + + + + + + + + + + + + WatchFaceApplication.xaml + + + + + diff --git a/TizenWatchfaceApp1.csproj.user b/TizenWatchfaceApp1.csproj.user new file mode 100644 index 0000000..3852296 --- /dev/null +++ b/TizenWatchfaceApp1.csproj.user @@ -0,0 +1,6 @@ + + + + TizenWatchfaceApp1 + + \ No newline at end of file diff --git a/TizenWatchfaceApp1.sln b/TizenWatchfaceApp1.sln new file mode 100644 index 0000000..d77b602 --- /dev/null +++ b/TizenWatchfaceApp1.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.779 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TizenWatchfaceApp1", "TizenWatchfaceApp1.csproj", "{C1F90E16-FFC1-407F-8242-768D925325B3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C1F90E16-FFC1-407F-8242-768D925325B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1F90E16-FFC1-407F-8242-768D925325B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1F90E16-FFC1-407F-8242-768D925325B3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1F90E16-FFC1-407F-8242-768D925325B3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8BCDA13E-6821-4FC8-BD71-4BFF290BE0DE} + EndGlobalSection +EndGlobal diff --git a/WatchFaceApplication.xaml b/WatchFaceApplication.xaml new file mode 100644 index 0000000..130106b --- /dev/null +++ b/WatchFaceApplication.xaml @@ -0,0 +1,82 @@ + + + + 5.5 + 8.5 + #535355 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WatchFaceApplication.xaml.cs b/WatchFaceApplication.xaml.cs new file mode 100644 index 0000000..02981dd --- /dev/null +++ b/WatchFaceApplication.xaml.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tizen.Security; +using Tizen.Sensor; +using Tizen.System; +using Xamarin.Forms; +using Xamarin.Forms.Xaml; + +namespace TizenWatchfaceApp1 +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + public partial class WatchFaceApplication : Application + { + private const string heartRatePrivilege = "http://tizen.org/privilege/healthinfo"; + + private HeartRateMonitor heartRateMonitor = null; + + public ClockViewModel ViewModel { get; set; } = null; + + public WatchFaceApplication() + { + InitializeComponent(); + + setupPrivilegeHandler(); + checkPrivilegeHandler(); + + this.ViewModel = new ClockViewModel(); + + this.BindingContext = this.ViewModel; + } + + protected override void OnSleep() + { + base.OnSleep(); + + if (heartRateMonitor != null) + { + heartRateMonitor.Stop(); + } + } + + protected override void OnResume() + { + base.OnResume(); + + setupPrivilegeHandler(); + + if (heartRateMonitor != null) + { + heartRateMonitor.Start(); + } + } + + private void heartRateMonitor_DataUpdated(object sender, HeartRateMonitorDataUpdatedEventArgs e) + { + if (this.ViewModel != null) this.ViewModel.HeartRate = e.HeartRate; + } + + private void setupPrivilegeHandler() + { + PrivacyPrivilegeManager.ResponseContext context = null; + if (PrivacyPrivilegeManager.GetResponseContext(heartRatePrivilege).TryGetTarget(out context)) + { + context.ResponseFetched += privilege_ResponseFetched; + } + } + + private void privilege_ResponseFetched(object sender, RequestResponseEventArgs e) + { + if (e.cause == CallCause.Error) + { + return; + } + + switch (e.result) + { + case RequestResult.AllowForever: + if (HeartRateMonitor.IsSupported) + { + heartRateMonitor = new HeartRateMonitor(); + heartRateMonitor.DataUpdated += heartRateMonitor_DataUpdated; + heartRateMonitor.Start(); + } + + break; + case RequestResult.DenyForever: + case RequestResult.DenyOnce: + break; + } + } + + private void checkPrivilegeHandler() + { + CheckResult rs = PrivacyPrivilegeManager.CheckPermission(heartRatePrivilege); + switch (rs) + { + case CheckResult.Allow: + if (HeartRateMonitor.IsSupported) + { + heartRateMonitor = new HeartRateMonitor(); + heartRateMonitor.DataUpdated += heartRateMonitor_DataUpdated; + } + + break; + case CheckResult.Deny: + // do nothing + break; + case CheckResult.Ask: + PrivacyPrivilegeManager.RequestPermission(heartRatePrivilege); + break; + } + } + + } +} \ No newline at end of file diff --git a/shared/res/TizenWatchfaceApp1.png b/shared/res/TizenWatchfaceApp1.png new file mode 100644 index 0000000..9f3cb98 Binary files /dev/null and b/shared/res/TizenWatchfaceApp1.png differ diff --git a/tizen-manifest.xml b/tizen-manifest.xml new file mode 100644 index 0000000..7a7df55 --- /dev/null +++ b/tizen-manifest.xml @@ -0,0 +1,18 @@ + + + + + + TizenWatchfaceApp1.png + + + + + + http://tizen.org/privilege/alarm.set + http://tizen.org/privilege/healthinfo + + + true + true +