From 2e965f088f4ef5721a59974e41f4b4488c5a39b9 Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Sun, 28 Jul 2019 02:25:53 +0200 Subject: [PATCH] =?UTF-8?q?Page=20d=C3=A9mo=20d=C3=A9s=20ok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AideDeJeu/AideDeJeu/Views/DicesPage.xaml | 4 +++- AideDeJeu/AideDeJeu/Views/DicesPage.xaml.cs | 22 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/AideDeJeu/AideDeJeu/Views/DicesPage.xaml b/AideDeJeu/AideDeJeu/Views/DicesPage.xaml index cefb639d..6b29075f 100644 --- a/AideDeJeu/AideDeJeu/Views/DicesPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/DicesPage.xaml @@ -4,7 +4,9 @@ xmlns:skviews="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms" xmlns:pickers="clr-namespace:AideDeJeu.Views.Pickers" xmlns:urho="clr-namespace:Urho.Forms;assembly=UrhoSharp.Forms" - x:Class="AideDeJeu.Views.DicesPage" Appearing="ContentPage_Appearing"> + x:Class="AideDeJeu.Views.DicesPage" + Appearing="ContentPage_Appearing" + Disappearing="ContentPage_Disappearing" Title="Dés" Visual="Material"> diff --git a/AideDeJeu/AideDeJeu/Views/DicesPage.xaml.cs b/AideDeJeu/AideDeJeu/Views/DicesPage.xaml.cs index d2d170f8..2d9c016a 100644 --- a/AideDeJeu/AideDeJeu/Views/DicesPage.xaml.cs +++ b/AideDeJeu/AideDeJeu/Views/DicesPage.xaml.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Urho; +using Xamarin.Essentials; using Xamarin.Forms; using Xamarin.Forms.Internals; using Xamarin.Forms.Xaml; @@ -88,14 +89,33 @@ namespace AideDeJeu.Views Charts charts = null; private async void ContentPage_Appearing(object sender, EventArgs e) { - //await HelloWorldUrhoSurface.Show(new Urho.ApplicationOptions(assetsFolder: null)); charts = await HelloWorldUrhoSurface.Show(new Urho.ApplicationOptions(assetsFolder: null)); + if (!Accelerometer.IsMonitoring) + { + Accelerometer.ShakeDetected += Accelerometer_ShakeDetected; + Accelerometer.Start(SensorSpeed.Game); + } + + } + + private void Accelerometer_ShakeDetected(object sender, EventArgs e) + { + charts.Bars.ForEach(b => b.SetValueWithAnimation((new Dice()).Roll("3d6", new RandomDieRoller()).Value)); } private void Button_Clicked(object sender, EventArgs e) { charts.Bars.ForEach(b => b.SetValueWithAnimation((new Dice()).Roll("3d6", new RandomDieRoller()).Value)); } + + private void ContentPage_Disappearing(object sender, EventArgs e) + { + if (Accelerometer.IsMonitoring) + { + Accelerometer.Stop(); + Accelerometer.ShakeDetected -= Accelerometer_ShakeDetected; + } + } } public class HelloWorld : Urho.Application {