cd5eb193e23d4e4014a49d4ee4a7b7f0788d3472
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.ComponentApplication / NUIComponentApplication / NUIComponentApplication.cs
1 using System;
2 using System.Collections.Generic;
3 using Tizen.Applications;
4 using Tizen.NUI;
5 using Tizen.NUI.BaseComponents;
6
7 namespace NUIComponentApplicationSample
8 {
9     public class Program : NUIComponentApplication
10     {
11         public static MyFrameComponent myFrame1 = null;
12         public static MyFrameComponent2 myFrame2 = null;
13
14         public Program(IDictionary<Type, string> typeInfo) : base(typeInfo)
15         {
16         }
17
18         public class MyFrameComponent : NUIFrameComponent
19         {
20             private TextLabel text;
21             private Animation animation;
22
23             public override bool OnCreate()
24             {
25                 myFrame1 = this;
26                 Tizen.Log.Error("MYLOG", "MyFrameComponent OnCreate");
27
28                 Window.BackgroundColor = Color.White;
29                 text = new TextLabel("First Frame");
30                 text.HorizontalAlignment = HorizontalAlignment.Center;
31                 text.VerticalAlignment = VerticalAlignment.Bottom;
32                 text.TextColor = Color.Blue;
33                 text.PointSize = 12.0f;
34                 text.HeightResizePolicy = ResizePolicyType.FillToParent;
35                 text.WidthResizePolicy = ResizePolicyType.FillToParent;
36                 Window.Add(text);
37
38                 animation = new Animation(2000);
39                 animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
40                 animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
41                 animation.Looping = true;
42                 animation.Play();
43                 return true;
44             }
45
46             
47             public override void OnDestroy()
48             {
49                 Tizen.Log.Error("MYLOG", "MyFrameComponent OnDestroy");
50                 text.Dispose();
51                 animation.Dispose();
52             }
53
54             public override void OnPause()
55             {
56                 Tizen.Log.Error("MYLOG", "MyFrameComponent OnPause");
57             }
58
59             public override void OnResume()
60             {
61                 Tizen.Log.Error("MYLOG", "MyFrameComponent OnResume");
62             }
63
64             public override void OnStart(AppControl appControl, bool restarted)
65             {
66                 Tizen.Log.Error("MYLOG", "MyFrameComponent OnStart");
67             }
68
69             public override void OnStop()
70             {
71                 Tizen.Log.Error("MYLOG", "MyFrameComponent OnStop");
72             }
73
74             public void ChangeSharedText(string strText)
75             {
76                 text.Text = strText;
77             }
78
79         }
80         public class MyFrameComponent2 : NUIFrameComponent
81         {
82             private TextLabel text;
83             private Animation animation;
84
85             public override bool OnCreate()
86             {
87                 myFrame2 = this;
88                 Tizen.Log.Error("MYLOG", "MyFrameComponent2 OnCreate");
89                 Window.BackgroundColor = Color.Red;
90                 Window.WindowSize = new Size(360, 180);
91                 Window.Instance.TouchEvent += Instance_TouchEvent;
92                 text = new TextLabel("Second Frame");
93                 text.HorizontalAlignment = HorizontalAlignment.Center;
94                 text.VerticalAlignment = VerticalAlignment.Center;
95                 text.TextColor = Color.Blue;
96                 text.PointSize = 12.0f;
97                 text.HeightResizePolicy = ResizePolicyType.FillToParent;
98                 text.WidthResizePolicy = ResizePolicyType.FillToParent;
99                 Window.Add(text);
100                 return true;
101             }
102
103             private void Instance_TouchEvent(object sender, Window.TouchEventArgs e)
104             {
105                 if(e.Touch.GetState(0) == PointStateType.Up)
106                 {
107                     myFrame1?.ChangeSharedText("Change - text");
108                 }
109             }
110
111             public override void OnDestroy()
112             {
113                 Tizen.Log.Error("MYLOG", "MyFrameComponent2 OnDestroy");
114                 text.Dispose();
115                 animation.Dispose();
116             }
117
118             public override void OnPause()
119             {
120                 Tizen.Log.Error("MYLOG", "MyFrameComponent2 OnPause");
121             }
122
123             public override void OnResume()
124             {
125                 Tizen.Log.Error("MYLOG", "MyFrameComponent2 OnResume");
126             }
127
128             public override void OnStart(AppControl appControl, bool restarted)
129             {
130                 Tizen.Log.Error("MYLOG", "MyFrameComponent2 OnStart");
131             }
132
133             public override void OnStop()
134             {
135                 Tizen.Log.Error("MYLOG", "MyFrameComponent2 OnStop");
136             }
137         }
138
139         static void Main(string[] args)
140         {
141             Dictionary<Type, string> dict = new Dictionary<Type, string>();
142             dict.Add(typeof(MyFrameComponent), "csharp_frame");
143             dict.Add(typeof(MyFrameComponent2), "csharp_frame2");
144             var app = new Program(dict);
145
146             app.Run(args);
147             app.Dispose();
148         }
149     }
150 }