Release 10.0.0.17841
[platform/core/csapi/tizenfx.git] / test / DigitalHumanLayer / DigitalHumanLayer.cs
1 using System;
2 using Tizen.NUI;
3 using Tizen.NUI.Components;
4 using Tizen.NUI.BaseComponents;
5
6 namespace DigitalHumanLayer
7 {
8     class Program : NUIApplication
9     {
10         private const string USER_AGENT = "Mozilla/5.0 (SMART-TV; Linux; Tizen 6.0) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/4.0 Chrome/76.0.3809.146 TV Safari/537.36";
11         private static string[] runtimeArgs = { "org.tizen.example.DigitalHumanLayer", "--enable-dali-window", "--enable-spatial-navigation" };
12
13         //Define WebView Variable as Member Variable
14         WebView webView;
15
16         //Control Position Animation for WebView
17         Animation moveAnimation;
18         AlphaFunction alphaFunction;
19         Button moveTopButton, moveBottomButton, moveLeftButton, moveCenterButton, moveRightButton;
20         protected override void OnCreate()
21         {
22             base.OnCreate();
23             Initialize();
24         }
25
26         protected override void OnTerminate()
27         {
28             base.OnTerminate();
29             Destory();
30         }
31
32         void ResetMoveAnimation()
33         {
34             //Reset previous moving animation
35             if (moveAnimation)
36             {
37                 moveAnimation.Stop();
38                 moveAnimation.Dispose();
39
40                 moveAnimation = new Animation(600);
41                 alphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine);
42                 moveAnimation.DefaultAlphaFunction = alphaFunction;
43             }
44         }
45
46         void Initialize()
47         {
48             Window.Instance.WindowSize = new Size(1920, 1080);
49
50             //Make Window Transparency
51             Window.Instance.BackgroundColor = Color.Transparent;
52             Window.Instance.SetTransparency(true);
53
54             //Ignore Key Events for Receiving remote controller event
55             Window.Instance.SetAcceptFocus(false);
56
57             //Set Window Notification Type
58             Window.Instance.Type = WindowType.Notification;
59
60             //Make Window Notification Level Top
61             Window.Instance.SetNotificationLevel(NotificationLevel.Top);
62
63             //Create NUI WebView
64             webView = new WebView(runtimeArgs)
65             {
66                 Size = new Size(500, 500),
67                 Position = new Position(750, 300),
68                 UserAgent = USER_AGENT,
69                 Focusable = true,
70                 VideoHoleEnabled = true,
71             };
72
73             webView.LoadUrl("https://www.youtube.com");
74
75             //Initialize Move Animation for WebView
76             moveAnimation = new Animation(600);
77             alphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseInOut);
78             moveAnimation.DefaultAlphaFunction = alphaFunction;
79
80             moveTopButton = new Button()
81             {
82                 Size = new Size(200, 100),
83                 Position = new Position(210, 220),
84                 Text = "Move Bottom"
85             };
86             moveTopButton.Clicked += (object source, ClickedEventArgs args) =>
87             {
88                 //Move Position 750, 0 (Pivot is LeftTop of WebView)
89                 ResetMoveAnimation();
90                 moveAnimation.AnimateTo(webView, "PositionX", 750);
91                 moveAnimation.AnimateTo(webView, "PositionY", 0);
92                 moveAnimation.Play();
93             };
94
95             moveBottomButton = new Button()
96             {
97                 Size = new Size(200, 100),
98                 Position = new Position(210, 440),
99                 Text = "Move Bottom"
100             };
101             moveBottomButton.Clicked += (object source, ClickedEventArgs args) =>
102             {
103                 //Move Position 750, 600 (Pivot is LeftTop of WebView)
104                 ResetMoveAnimation();
105                 moveAnimation.AnimateTo(webView, "PositionX", 750);
106                 moveAnimation.AnimateTo(webView, "PositionY", 600);
107                 moveAnimation.Play();
108             };
109
110             moveLeftButton = new Button()
111             {
112                 Size = new Size(200, 100),
113                 Position = new Position(0, 330),
114                 Text = "Move Left"
115             };
116             moveLeftButton.Clicked += (object source, ClickedEventArgs args) =>
117             {
118                 //Move Position 300, 300 (Pivot is LeftTop of WebView)
119                 ResetMoveAnimation();
120                 moveAnimation.AnimateTo(webView, "PositionX", 300);
121                 moveAnimation.AnimateTo(webView, "PositionY", 300);
122                 moveAnimation.Play();
123             };
124
125             moveCenterButton = new Button()
126             {
127                 Size = new Size(200, 100),
128                 Position = new Position(210, 330),
129                 Text = "Move Center"
130             };
131             moveCenterButton.Clicked += (object source, ClickedEventArgs args) =>
132             {
133                 //Move Position 750, 300 (Pivot is LeftTop of WebView)
134                 ResetMoveAnimation();
135                 moveAnimation.AnimateTo(webView, "PositionX", 750);
136                 moveAnimation.AnimateTo(webView, "PositionY", 300);
137                 moveAnimation.Play();
138             };
139
140             moveRightButton = new Button()
141             {
142                 Size = new Size(200, 100),
143                 Position = new Position(420, 330),
144                 Text = "Move Right"
145             };
146             moveRightButton.Clicked += (object source, ClickedEventArgs args) =>
147             {
148                 //Move Position 1400, 300 (Pivot is LeftTop of WebView)
149                 ResetMoveAnimation();
150                 moveAnimation.AnimateTo(webView, "PositionX", 1400);
151                 moveAnimation.AnimateTo(webView, "PositionY", 300);
152                 moveAnimation.Play();
153             };
154
155             //Add WebView and NUI Buttons to Main Window
156             Window.Instance.GetDefaultLayer().Add(moveTopButton);
157             Window.Instance.GetDefaultLayer().Add(moveBottomButton);
158             Window.Instance.GetDefaultLayer().Add(moveLeftButton);
159             Window.Instance.GetDefaultLayer().Add(moveCenterButton);
160             Window.Instance.GetDefaultLayer().Add(moveRightButton);
161             Window.Instance.GetDefaultLayer().Add(webView);
162         }
163
164         void Destory()
165         {
166             //Remove WebView and NUI Buttons from Main Window
167             Window.Instance.GetDefaultLayer().Remove(moveTopButton);
168             Window.Instance.GetDefaultLayer().Remove(moveBottomButton);
169             Window.Instance.GetDefaultLayer().Remove(moveLeftButton);
170             Window.Instance.GetDefaultLayer().Remove(moveCenterButton);
171             Window.Instance.GetDefaultLayer().Remove(moveRightButton);
172             Window.Instance.GetDefaultLayer().Remove(webView);
173         }
174
175         static void Main(string[] args)
176         {
177             var app = new Program();
178             app.Run(args);
179         }
180     }
181 }