[NUI] Add RiveAnimationView Tizen Music Application Samples
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / RiveMusicApp.cs
1 using Tizen.NUI.BaseComponents;
2 using Tizen.NUI.Extension;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class RiveMusicApp : IExample
8     {
9         private Window window;
10         private Layer defaultLayer;
11
12         Tizen.NUI.Extension.RiveAnimationView rav;
13         Button playButton, stopButton;
14         public void Activate()
15         {
16             window = NUIApplication.GetDefaultWindow();
17             defaultLayer = window.GetDefaultLayer();
18
19             rav = new Tizen.NUI.Extension.RiveAnimationView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "rive/music.riv")
20             {
21                 Size = new Size(500, 500),
22                 ParentOrigin = ParentOrigin.Center,
23                 PivotPoint = PivotPoint.Center,
24                 PositionUsesPivotPoint = true,
25             };
26
27             rav.Play();
28
29             playButton = new Button()
30             {
31                 Size = new Size(200, 100),
32                 Position = new Position(0, 0),
33                 Text = "Start Music"
34             };
35             playButton.Clicked += (object source, ClickedEventArgs args) =>
36             {
37                 rav.EnableAnimation("Loop", true);
38                 rav.EnableAnimation("Start", true);
39                 rav.EnableAnimation("Stop", false);
40             };
41
42             stopButton = new Button()
43             {
44                 Size = new Size(200, 100),
45                 Position = new Position(200, 0),
46                 Text = "Stop Music"
47             };
48             stopButton.Clicked += (object source, ClickedEventArgs args) =>
49             {
50                 rav.EnableAnimation("Loop", false);
51                 rav.EnableAnimation("Start", false);
52                 rav.EnableAnimation("Stop", true);
53             };
54
55             defaultLayer.Add(rav);
56             defaultLayer.Add(playButton);
57             defaultLayer.Add(stopButton);
58         }
59         public void Deactivate()
60         {
61             defaultLayer.Remove(rav);
62             defaultLayer.Remove(playButton);
63             defaultLayer.Remove(stopButton);
64         }
65     }
66 }