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