[NUI][TEST] add widget sample for sending message
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.WidgetViewTest / 0.Template / Tizen.NUI.WidgetTest / SimpleWidgetApp.cs
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using System.Diagnostics;
20 using System.Collections.Generic; // for Dictionary
21 using Tizen.NUI;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Components;
24 using Tizen.Applications;
25
26 namespace WidgetTemplate
27 {
28     class RedWidget : Widget
29     {
30         protected override void OnCreate(string contentInfo, Window window)
31         {
32             Tizen.Log.Info("NUI", "OnCreate(RedWidget) \n");
33             Bundle bundle = Bundle.Decode(contentInfo);
34             mRootView = new View();
35             mRootView.BackgroundColor = Color.Red;
36             mRootView.Size2D = window.Size;
37             window.GetDefaultLayer().Add(mRootView);
38
39             TextLabel sampleLabel = new TextLabel("Red Widget ");
40             sampleLabel.FontFamily = "SamsungOneUI 500";
41             sampleLabel.PointSize = 8;
42             sampleLabel.TextColor = Color.Black;
43             sampleLabel.SizeWidth = 300;
44             sampleLabel.PivotPoint = PivotPoint.Center;
45             mRootView.Add(sampleLabel);
46
47             mAnimation = new Animation(1000);
48             mAnimation.AnimateTo(sampleLabel, "PositionX", 300.0f);
49             mAnimation.Looping = true;
50             mAnimation.Play();
51         }
52
53         protected override void OnPause()
54         {
55             base.OnPause();
56         }
57
58         protected override void OnResume()
59         {
60             base.OnResume();
61         }
62
63         protected override void OnResize(Window window)
64         {
65             mRootView.Size2D = window.Size;
66             base.OnResize(window);
67         }
68
69         protected override void OnTerminate(string contentInfo, TerminationType type)
70         {
71             base.OnTerminate(contentInfo, type);
72         }
73
74         protected override void OnUpdate(string contentInfo, int force)
75         {
76             base.OnUpdate(contentInfo, force);
77         }
78
79         private View mRootView;
80         private Animation mAnimation;
81     }
82
83     class BlueWidget : Widget
84     {
85         protected override void OnCreate(string contentInfo, Window window)
86         {
87             Tizen.Log.Info("NUI", "OnCreate(BlueWidget) \n");
88             Bundle bundle = Bundle.Decode(contentInfo);
89             mRootView = new View();
90             mRootView.BackgroundColor = Color.Blue;
91             mRootView.Size2D = window.Size;
92             window.GetDefaultLayer().Add(mRootView);
93
94             TextLabel sampleLabel = new TextLabel("Blue Widget ");
95             sampleLabel.FontFamily = "SamsungOneUI 500";
96             sampleLabel.PointSize = 8;
97             sampleLabel.TextColor = Color.Black;
98             sampleLabel.SizeWidth = 300;
99             sampleLabel.PivotPoint = PivotPoint.Center;
100             mRootView.Add(sampleLabel);
101
102             mAnimation = new Animation(1000);
103             mAnimation.AnimateTo(sampleLabel, "PositionX", 400.0f);
104             mAnimation.Looping = true;
105             mAnimation.Play();
106         }
107
108         protected override void OnPause()
109         {
110             base.OnPause();
111         }
112
113         protected override void OnResume()
114         {
115             base.OnResume();
116         }
117
118         protected override void OnResize(Window window)
119         {
120             base.OnResize(window);
121         }
122
123         protected override void OnTerminate(string contentInfo, TerminationType type)
124         {
125             base.OnTerminate(contentInfo, type);
126         }
127
128         protected override void OnUpdate(string contentInfo, int force)
129         {
130             base.OnUpdate(contentInfo, force);
131         }
132
133         private View mRootView;
134         private Animation mAnimation;
135     }
136
137     class Program : NUIWidgetApplication
138     {
139         public Program(Dictionary<System.Type, string> widgetSet) : base(widgetSet)
140         {
141
142         }
143
144         protected override void OnCreate()
145         {
146             base.OnCreate();
147             Initialize();
148         }
149
150         void Initialize()
151         {
152         }
153
154         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
155         {
156             if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
157             {
158                 Exit();
159             }
160         }
161
162         static void Main(string[] args)
163         {
164             Dictionary<System.Type, string> widgetSet = new Dictionary<Type, string>();
165             widgetSet.Add(typeof(RedWidget), "class1@Tizen.NUI.WidgetTest");
166             widgetSet.Add(typeof(BlueWidget), "class2@Tizen.NUI.WidgetTest");
167             var app = new Program(widgetSet);
168             app.Run(args);
169         }
170     }
171 }
172