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