Merge "[Telephony] Sample App implementation."
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / EcoreTimerTest1.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
19 namespace ElmSharp.Test
20 {
21     class EcoreTimerTest1 : TestCaseBase
22     {
23         public override string TestName => "EcoreTimerTest1";
24         public override string TestDescription => "To timer operation of EcoreMainLoop";
25
26         public override void Run(Window window)
27         {
28             Background bg = new Background(window)
29             {
30                 AlignmentX = -1,
31                 AlignmentY = -1,
32                 WeightX = 1,
33                 WeightY = 1,
34                 Color = Color.White
35             };
36             bg.Show();
37             window.AddResizeObject(bg);
38
39             Conformant conformant = new Conformant(window);
40             conformant.Show();
41
42
43             int number = 0;
44             bool bReturn = true;
45             Label label1 = new Label(window);
46             label1.Move(150, 150);
47             label1.Resize(300, 100);
48
49             Button btnTimerSwitch = new Button(window);
50             btnTimerSwitch.Text = "Timer : On";
51             btnTimerSwitch.Move(0, 300);
52             btnTimerSwitch.Resize(300, 100);
53
54             Func<bool> handler = () =>
55             {
56                 label1.Text = (++number).ToString();
57                 label1.EdjeObject["elm.text"].TextStyle = "DEFAULT='color=#000000 font_size=64 align=left valign=bottom wrap=word'";
58                 return bReturn;
59             };
60             IntPtr prevId = EcoreMainloop.AddTimer(1.0, handler);
61             btnTimerSwitch.Clicked += (s, e) =>
62              {
63                  if(bReturn)
64                  {
65                      bReturn = false;
66                      btnTimerSwitch.Text = "Timer : Off";
67                  }
68                  else
69                  {
70                      bReturn = true;
71                      btnTimerSwitch.Text = "Timer : On";
72                      EcoreMainloop.RemoveTimer(prevId);
73                      prevId = EcoreMainloop.AddTimer(1.0, handler);
74                  }
75              };
76
77             window.BackButtonPressed += (s, e) =>
78             {
79                 EcoreMainloop.RemoveTimer(prevId);
80             };
81
82             label1.Show();
83             btnTimerSwitch.Show();
84         }
85     }
86 }