2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
19 using System.Diagnostics;
20 using System.Collections.Generic; // for Dictionary
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Components;
24 using Tizen.Applications;
26 namespace WidgetTemplate
28 class RedWidget : Widget
30 protected override void OnCreate(string contentInfo, Window window)
32 Tizen.Log.Info("NUI", "OnCreate(RedWidget) \n");
33 Bundle bundle = Bundle.Decode(contentInfo);
34 mRootView = new View();
35 mRootView.BackgroundColor = Color.Red;
36 mRootView.Size2D = window.Size;
37 window.GetDefaultLayer().Add(mRootView);
39 TextLabel sampleLabel = new TextLabel("Red Widget ");
40 sampleLabel.FontFamily = "SamsungOneUI 500";
41 sampleLabel.PointSize = 8;
42 sampleLabel.TextColor = Color.Black;
43 sampleLabel.SizeWidth = 300;
44 sampleLabel.PivotPoint = PivotPoint.Center;
45 mRootView.Add(sampleLabel);
47 mAnimation = new Animation(1000);
48 mAnimation.AnimateTo(sampleLabel, "PositionX", 300.0f);
49 mAnimation.Looping = true;
53 protected override void OnPause()
58 protected override void OnResume()
63 protected override void OnResize(Window window)
65 mRootView.Size2D = window.Size;
66 base.OnResize(window);
69 protected override void OnTerminate(string contentInfo, TerminationType type)
71 base.OnTerminate(contentInfo, type);
74 protected override void OnUpdate(string contentInfo, int force)
76 base.OnUpdate(contentInfo, force);
79 private View mRootView;
80 private Animation mAnimation;
83 class BlueWidget : Widget
85 protected override void OnCreate(string contentInfo, Window window)
87 Tizen.Log.Info("NUI", "OnCreate(BlueWidget) \n");
88 Bundle bundle = Bundle.Decode(contentInfo);
89 mRootView = new View();
90 mRootView.BackgroundColor = Color.Blue;
91 mRootView.Size2D = window.Size;
92 window.GetDefaultLayer().Add(mRootView);
94 TextLabel sampleLabel = new TextLabel("Blue Widget ");
95 sampleLabel.FontFamily = "SamsungOneUI 500";
96 sampleLabel.PointSize = 8;
97 sampleLabel.TextColor = Color.Black;
98 sampleLabel.SizeWidth = 300;
99 sampleLabel.PivotPoint = PivotPoint.Center;
100 mRootView.Add(sampleLabel);
102 mAnimation = new Animation(1000);
103 mAnimation.AnimateTo(sampleLabel, "PositionX", 400.0f);
104 mAnimation.Looping = true;
108 protected override void OnPause()
113 protected override void OnResume()
118 protected override void OnResize(Window window)
120 base.OnResize(window);
123 protected override void OnTerminate(string contentInfo, TerminationType type)
125 base.OnTerminate(contentInfo, type);
128 protected override void OnUpdate(string contentInfo, int force)
130 base.OnUpdate(contentInfo, force);
133 private View mRootView;
134 private Animation mAnimation;
137 class Program : NUIWidgetApplication
139 public Program(Dictionary<System.Type, string> widgetSet) : base(widgetSet)
144 protected override void OnCreate()
154 public void OnKeyEvent(object sender, Window.KeyEventArgs e)
156 if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
162 static void Main(string[] args)
164 Dictionary<System.Type, string> widgetSet = new Dictionary<Type, string>();
165 widgetSet.Add(typeof(RedWidget), "class1@Tizen.NUI.WidgetTest");
166 widgetSet.Add(typeof(BlueWidget), "class2@Tizen.NUI.WidgetTest");
167 var app = new Program(widgetSet);