5f7cef3d2e74f60e4cad4ccb5bac23992078a581
[test/tct/csharp/api.git] /
1 using System;
2 using Tizen.NUI;
3 using Tizen.NUI.BaseComponents;
4 using Tizen.Applications;
5 using Tizen;
6
7 namespace WidgetApplicationSample
8 {
9     class MyWidget : Widget
10     {
11         private TextLabel _textLabel;
12         private Animation _animation;
13         private float _pointSize = 5.0f;
14         private Bundle _content;
15
16         protected override void OnCreate(string contentInfo, Window window)
17         {
18             Tizen.Log.Fatal("NUIWidget", "Widget Instance is OnCreate! " + contentInfo);
19             _content = Bundle.Decode(contentInfo);
20             string imageIdx = Convert.ToString(_content.GetItem("ImageIdx"));
21             Tizen.Log.Fatal("NUIWidget", "Widget Instance content info is " + imageIdx);
22
23             window.BackgroundColor = Color.White;
24             _textLabel = new TextLabel("Hello Widget");
25             _textLabel.TextColor = Color.Black;
26             _textLabel.Size2D = new Size2D(360, 130);
27             _textLabel.ParentOrigin = ParentOrigin.TopLeft;
28             _textLabel.PivotPoint = PivotPoint.TopLeft;
29             _textLabel.HorizontalAlignment = HorizontalAlignment.Center;
30             _textLabel.VerticalAlignment = VerticalAlignment.Center;
31             _textLabel.PositionUsesPivotPoint = true;
32             _textLabel.PointSize = _pointSize;
33             _textLabel.Position2D = new Position2D(0, 0);
34             window.Add(_textLabel);
35             Tizen.Log.Fatal("NUIWidget", "text width: " + _textLabel.NaturalSize2D.Width + ", height: " + _textLabel.NaturalSize2D.Height);
36
37             _animation = new Animation(2000);
38             _animation.AnimateTo(_textLabel, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.Y), 0, 500);
39             _animation.AnimateTo(_textLabel, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.Y), 500, 1000);
40             _animation.Looping = true;
41             _animation.EndAction = Animation.EndActions.Discard;
42             Log.Debug("TCT", "[TestCase][OnCreate][Widget] Pass");
43             base.OnCreate(contentInfo, window);
44         }
45
46         private bool IsEmulator()
47         {
48             string value;
49             var result = Tizen.System.Information.TryGetValue("tizen.org/system/model_name", out value);
50             if (result && value.Equals("Emulator"))
51             {
52                 return true;
53             }
54
55             return false;
56         }
57
58         protected override void OnPause()
59         {
60             Tizen.Log.Fatal("NUIWidget", "Widget Instance OnPause!");
61             _animation.Stop();
62             Log.Debug("TCT", "[TestCase][OnPause][Widget] Pass");
63             base.OnPause();
64         }
65
66         protected override void OnResume()
67         {
68             OnUpdate(_content.Encode(), 1);
69             Tizen.Log.Fatal("NUIWidget", "Widget Instance OnResume!");
70             Log.Debug("TCT", "[TestCase][OnResume][Widget] Pass");
71             base.OnResume();
72         }
73
74         protected override void OnResize(Window window)
75         {
76             Tizen.Log.Fatal("NUIWidget", "Widget Instance OnResize!");
77             Log.Debug("TCT", "[TestCase][OnResize][Widget] Pass");
78             base.OnResize(window);
79         }
80
81         protected override void OnTerminate(string contentInfo, TerminationType type)
82         {
83             Tizen.Log.Fatal("NUIWidget", "Widget Instance OnTerminate!");
84             Log.Debug("TCT", "[TestCase][OnTerminate][Widget] Pass");
85             base.OnTerminate(contentInfo, type);
86         }
87
88         protected override void OnUpdate(string contentInfo, int force)
89         {
90             Tizen.Log.Fatal("NUIWidget", "Widget Instance OnUpdate! " + contentInfo);
91             Bundle content = Bundle.Decode(contentInfo);
92             string imageIdx = Convert.ToString(content.GetItem("ImageIdx"));
93
94             Tizen.Log.Fatal("NUIWidget", "Widget Instance content info is " + imageIdx);
95             Log.Debug("TCT", "[TestCase][OnUpdate][Widget] Pass");
96             base.OnUpdate(contentInfo, force);
97         }
98     }
99
100     class Program : NUIWidgetApplication
101     {
102         public Program(System.Type type) : base(type)
103         {
104         }
105
106         protected override void OnCreate()
107         {
108             base.OnCreate();
109             Log.Debug("TCT", "[TestCase][OnCreate][NUIWidgetApplication] Pass");
110         }
111
112         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
113         {
114             Log.Debug("TCT", "NUIWidgetApplication::OnLocaleChanged()");
115             if (e.Locale != null)
116             {
117                 Log.Debug("TCT", "[Test_Properties] Locale properties is not null");
118                 Log.Debug("TCT", "[Test_Properties] Current value of Locale : " + e.Locale);
119                 Log.Debug("TCT", "[Test_Properties] Locale type: " + e.Locale.GetType());
120             }
121
122             Log.Debug("TCT", "[TestCase][OnLocaleChanged][NUIWidgetApplication] Pass");
123             base.OnLocaleChanged(e);
124         }
125
126         protected override void OnLowBattery(LowBatteryEventArgs e)
127         {
128             Log.Debug("TCT", "NUIWidgetApplication::OnLowBattery()");
129             if (e.LowBatteryStatus != LowBatteryStatus.None)
130             {
131                 Log.Debug("TCT", "[Test_Properties] LowBatteryStatus properties is not null");
132                 Log.Debug("TCT", "[Test_Properties] Current value of LowBatteryStatus : " + e.LowBatteryStatus.ToString());
133                 Log.Debug("TCT", "[Test_Properties] LowBatteryStatus type: " + e.LowBatteryStatus.GetType());
134             }
135
136             Log.Debug("TCT", "[TestCase][OnLowBattery][NUIWidgetApplication] Pass");
137
138             base.OnLowBattery(e);
139         }
140
141         protected override void OnLowMemory(LowMemoryEventArgs e)
142         {
143             Log.Debug("TCT", "NUIWidgetApplication::OnLowMemory()");
144             if (e.LowMemoryStatus != LowMemoryStatus.None)
145             {
146                 Log.Debug("TCT", "[Test_Properties] LowMemoryStatus properties is not null");
147                 Log.Debug("TCT", "[Test_Properties] Current value of LowMemoryStatus : " + e.LowMemoryStatus.ToString());
148                 Log.Debug("TCT", "[Test_Properties] LowMemoryStatus type: " + e.LowMemoryStatus.GetType());
149             }
150             //logBuilder.AppendLine("TCT [TestCase][OnLowMemory] Pass");
151             Log.Debug("TCT", "[TestCase][OnLowMemory][NUIWidgetApplication] Pass");
152
153             base.OnLowMemory(e);
154         }
155
156         protected override void OnPreCreate()
157         {
158             Log.Debug("TCT", "[TestCase][OnPreCreate][NUIWidgetApplication] Pass");
159             base.OnPreCreate();
160         }
161
162         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
163         {
164             Log.Debug("TCT", "NUIWidgetApplication::OnRegionFormatChanged()");
165             if (e != null)
166             {
167                 Log.Debug("TCT", "[Test_Properties] Region properties is not null");
168                 Log.Debug("TCT", "[Test_Properties] Current value of Region : " + e.Region);
169                 Log.Debug("TCT", "[Test_Properties] Region type: " + e.Region.GetType());
170             }
171
172             Log.Debug("TCT", "[TestCase][OnRegionFormatChanged][NUIWidgetApplication] Pass");
173             base.OnRegionFormatChanged(e);
174         }
175
176         protected override void OnTerminate()
177         {
178             Log.Debug("TCT", "NUIWidgetApplication::OnTerminate()");
179             Log.Debug("TCT", "[TestCase][OnTerminate][NUIWidgetApplication] Pass");
180             base.OnTerminate();
181         }
182
183         public override void Run(string[] args)
184         {
185             //Created += Created_Event_Test;
186             //AppControlReceived += AppControlReceived_Event_Test;
187             //LocaleChanged += LocaleChanged_Event_Test;
188             //LowMemory += LowMemory_Event_Test;
189             //LowBattery += LowBattery_Event_Test;
190             //Terminated += Terminated_Event_Test;
191             //Paused += EventHandlerPaused;
192             //Resumed += EventHandlerResumed;
193             //DeviceOrientationChanged += DeviceOrientationCHanged_Event_Test;
194             //RegionFormatChanged += RegionFormatChanged_Event_Test;
195
196             Log.Debug("TCT", "[TestCase][Run][NUIWidgetApplication] Pass");
197             base.Run(args);
198         }
199
200         public override void Exit()
201         {
202             Log.Debug("TCT", "[TestCase][Exit][NUIWidgetApplication] Pass");
203             base.Exit();
204         }
205
206         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
207         {
208             if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
209             {
210                 Exit();
211             }
212         }
213
214         static void Main(string[] args)
215         {
216             var app = new Program(typeof(MyWidget));
217             app.Run(args);
218             app.Exit();
219         }
220     }
221 }