AnimationBetween() parameter changed and more
[platform/core/csapi/nui.git] / NUISamples / NUISamples.TizenTV / examples / hello-test.cs
1 /*
2  * Copyright (c) 2016 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
18 using System;
19 using Tizen.NUI;
20
21 namespace HelloTestExample
22 {
23     class Example : NUIApplication
24     {
25         private void LOG(string _str)
26         {
27             Tizen.Log.Debug("NUI-APP", _str);
28             //Console.WriteLine("[NUI-APP]" + _str);
29         }
30
31         private Animation _animation;
32         private TextLabel _text;
33         private Stage _stage;
34
35         public Example() : base()
36         {
37         }
38
39         public Example(string stylesheet) : base(stylesheet)
40         {
41         }
42
43         public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
44         {
45         }
46
47         private void Initialize()
48         {
49             LOG("Customized Application Initialize event handler");
50             _stage = Stage.Instance;
51             _stage.Touch += OnStageTouched;
52             _stage.Key += OnStageKeyEvent;
53
54             // Add a _text label to the stage
55             _text = new TextLabel("Hello NUI World");
56             _text.ParentOrigin = ParentOrigin.Center;
57             _text.AnchorPoint = AnchorPoint.Center;
58             _text.HorizontalAlignment = "CENTER";
59             _text.PointSize = 32.0f;
60             _text.TextColor = Color.Magenta;
61             _stage.GetDefaultLayer().Add(_text);
62
63             _animation = new Animation
64             {
65                 Duration = 2000
66             };
67
68             LOG("[1]_text PositionX =" + _text.PositionX + "  SizeHeight=" + _text.SizeHeight);
69
70             _animation.AnimateTo(_text, "PositionX", _text.PositionX + 200.0f);
71             _animation.AnimateTo(_text, "SizeHeight", _text.SizeHeight + 200.0f);
72
73             LOG("[2]_text PositionX =" + _text.PositionX + "  SizeHeight=" + _text.SizeHeight);
74
75             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), Vector3.XAxis), 0, 500);
76             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), Vector3.XAxis), 500, 1000);
77             _animation.EndAction = Animation.EndActions.Discard;
78         }
79
80         public void OnStageKeyEvent(object sender, Stage.KeyEventArgs e)
81         {
82             if (e.Key.State == Key.StateType.Down)
83             {
84                 if (e.Key.KeyPressedName == "Up")
85                 {
86                     if (_animation)
87                     {
88                         _animation.Finished += AnimationFinished;
89                         LOG("AnimationFinished added!");
90                     }
91                 }
92                 else if (e.Key.KeyPressedName == "Down")
93                 {
94                     if (_animation)
95                     {
96                         _animation.Finished -= AnimationFinished;
97                         LOG("AnimationFinished removed!");
98                     }
99                 }
100             }
101         }
102
103         // Callback for _animation finished signal handling
104         public void AnimationFinished(object sender, EventArgs e)
105         {
106             LOG("AnimationFinished()!");
107             if (_animation)
108             {
109                 LOG("Duration= " + _animation.Duration);
110                 LOG("EndAction= " + _animation.EndAction);
111             }
112             LOG("[4]_text PositionX =" + _text.PositionX + "  SizeHeight=" + _text.SizeHeight);
113         }
114
115         // Callback for stage touched signal handling
116         public void OnStageTouched(object sender, Stage.TouchEventArgs e)
117         {
118             // Only animate the _text label when touch down happens
119             if (e.Touch.GetState(0) == PointStateType.Down)
120             {
121                 LOG("Customized Stage Touch event handler");
122
123                 // Play the _animation
124                 _animation.Play();
125
126                 LOG("[3]_text PositionX =" + _text.PositionX + "  SizeHeight=" + _text.SizeHeight);
127             }
128         }
129
130         protected override void OnCreate()
131         {
132             base.OnCreate();
133             Initialize();
134         }
135
136         [STAThread]
137         static void Main(string[] args)
138         {
139             Example example = new Example();
140             example.Run(args);
141         }
142     }
143 }