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;
25 using Tizen.Applications.Messages;
27 namespace WidgetTemplate
29 class RedWidget : Widget
31 string rcvPort = "my_widget_port";
33 protected override void OnCreate(string contentInfo, Window window)
35 Tizen.Log.Info("NUI", "OnCreate(RedWidget) \n");
36 Bundle bundle = Bundle.Decode(contentInfo);
37 mRootView = new View();
38 mRootView.BackgroundColor = Color.Red;
39 mRootView.Size2D = window.Size;
40 window.GetDefaultLayer().Add(mRootView);
42 TextLabel sampleLabel = new TextLabel("Red Widget ");
43 sampleLabel.FontFamily = "SamsungOneUI 500";
44 sampleLabel.PointSize = 8;
45 sampleLabel.TextColor = Color.Black;
46 sampleLabel.SizeWidth = 300;
47 sampleLabel.PivotPoint = PivotPoint.Center;
48 mRootView.Add(sampleLabel);
50 // Create receive port
51 _rcvPort = new MessagePort(rcvPort, false);
52 Tizen.Log.Info("NUI", "ReceivePort Create: " + _rcvPort.PortName + "Trusted: " + _rcvPort.Trusted);
53 _rcvPort.MessageReceived += MessageReceived_Callback;
56 // For testing send to bundle data from widget to widgetViewer, pleaes enable this code.
57 //timer = new Timer(5000);
58 //timer.Tick += TimerTick;
62 private void MessageReceived_Callback(object sender, MessageReceivedEventArgs e)
64 Tizen.Log.Info("NUI", "Message Received");
65 Tizen.Log.Info("NUI", "App ID: " + e.Remote.AppId);
66 Tizen.Log.Info("NUI", "PortName: " + e.Remote.PortName);
67 Tizen.Log.Info("NUI", "Trusted: " + e.Remote.Trusted);
68 Tizen.Log.Info("NUI", "message: " + e.Message.GetItem <string> ("message"));
71 protected override void OnPause()
76 protected override void OnResume()
81 protected override void OnResize(Window window)
83 mRootView.Size2D = window.Size;
84 base.OnResize(window);
87 protected override void OnTerminate(string contentInfo, TerminationType type)
89 base.OnTerminate(contentInfo, type);
92 protected override void OnUpdate(string contentInfo, int force)
94 base.OnUpdate(contentInfo, force);
98 private bool TimerTick(object source, Timer.TickEventArgs e)
100 Bundle bundle = new Bundle();
101 bundle.AddItem("COUNT", "1");
102 String encodedBundle = bundle.Encode();
103 SetContentInfo(encodedBundle);
108 private static MessagePort _rcvPort;
110 private View mRootView;
111 private Animation mAnimation;
115 class BlueWidget : Widget
117 protected override void OnCreate(string contentInfo, Window window)
119 Tizen.Log.Info("NUI", "OnCreate(BlueWidget) \n");
120 Bundle bundle = Bundle.Decode(contentInfo);
121 mRootView = new View();
122 mRootView.BackgroundColor = Color.Blue;
123 mRootView.Size2D = window.Size;
124 window.GetDefaultLayer().Add(mRootView);
126 TextLabel sampleLabel = new TextLabel("Blue Widget ");
127 sampleLabel.FontFamily = "SamsungOneUI 500";
128 sampleLabel.PointSize = 8;
129 sampleLabel.TextColor = Color.Black;
130 sampleLabel.SizeWidth = 300;
131 sampleLabel.PivotPoint = PivotPoint.Center;
132 mRootView.Add(sampleLabel);
135 protected override void OnPause()
140 protected override void OnResume()
145 protected override void OnResize(Window window)
147 base.OnResize(window);
150 protected override void OnTerminate(string contentInfo, TerminationType type)
152 base.OnTerminate(contentInfo, type);
155 protected override void OnUpdate(string contentInfo, int force)
157 base.OnUpdate(contentInfo, force);
160 private View mRootView;
161 private Animation mAnimation;
164 class Program : NUIWidgetApplication
166 public Program(Dictionary<System.Type, string> widgetSet) : base(widgetSet)
171 protected override void OnCreate()
181 public void OnKeyEvent(object sender, Window.KeyEventArgs e)
183 if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
189 static void Main(string[] args)
191 Dictionary<System.Type, string> widgetSet = new Dictionary<Type, string>();
192 widgetSet.Add(typeof(RedWidget), "class1@Tizen.NUI.WidgetTest");
193 widgetSet.Add(typeof(BlueWidget), "class2@Tizen.NUI.WidgetTest");
194 var app = new Program(widgetSet);