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.Collections.Generic;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.Applications;
22 using Tizen.Applications.Messages;
24 namespace WidgetApplicationTemplate
26 class Program : NUIApplication
28 string widgetAppId = "Tizen.NUI.WidgetTest";
29 string rcvPort = "my_widget_port";
31 protected override void OnCreate()
38 Window window = GetDefaultWindow();
40 window.KeyEvent += OnKeyEvent;
41 window.TouchEvent += OnTouchEvent;
43 rootView = new View();
44 rootView.BackgroundColor = Color.White;
45 rootView.Size = Window.Instance.Size;
46 rootView.PivotPoint = PivotPoint.Center;
47 window.GetDefaultLayer().Add(rootView);
49 TextLabel sampleLabel = new TextLabel("Widget Viewer ");
50 sampleLabel.FontFamily = "SamsungOneUI 500";
51 sampleLabel.PointSize = 8;
52 sampleLabel.TextColor = Color.Black;
53 sampleLabel.SizeWidth = 300;
54 sampleLabel.PivotPoint = PivotPoint.Center;
55 rootView.Add(sampleLabel);
57 Bundle bundle = new Bundle();
58 bundle.AddItem("COUNT", "1");
59 String encodedBundle = bundle.Encode();
63 mWidgetView = WidgetViewManager.Instance.AddWidget("class1@Tizen.NUI.WidgetTest", encodedBundle, widgetWidth, widgetHeight, 0.0f);
64 mWidgetView.Position = new Position(100,100);
65 window.GetDefaultLayer().Add(mWidgetView);
67 //mWidgetView.WidgetContentUpdated += OnWidgetContentUpdatedCB;
69 mWidgetView2 = WidgetViewManager.Instance.AddWidget("class2@Tizen.NUI.WidgetTest", encodedBundle, widgetWidth, widgetHeight, 0.0f);
70 mWidgetView2.Position = new Position(100, widgetHeight + 110);
71 window.GetDefaultLayer().Add(mWidgetView2);
73 // Send message using port
74 _msgPort = new MessagePort(rcvPort, false);
75 Tizen.Log.Info("NUI", "MessagePort Create: " + _msgPort.PortName + "Trusted: " + _msgPort.Trusted);
78 public void OnKeyEvent(object sender, Window.KeyEventArgs e)
80 if (e.Key.State == Key.StateType.Down )
82 Tizen.Log.Info("NUI", "OnKeyEvent(View-Window) : " + e.Key.KeyPressedName + "\n");
83 if (e.Key.KeyPressedName == "1")
87 if(widgetWidth > 1000 || widgetHeight > 1000)
92 mWidgetView.Size2D = new Size2D(widgetWidth, widgetHeight);
94 // Send the WidgetView's width to Widget
95 var msg = new Bundle();
96 msg.AddItem("message", "WidgetView's message >> width:" + widgetWidth);
97 _msgPort.Send(msg, widgetAppId, rcvPort);
102 private void OnTouchEvent(object source, Window.TouchEventArgs e)
107 private void OnWidgetContentUpdatedCB(object sender, WidgetView.WidgetViewEventArgs e)
109 String encodedBundle = e.WidgetView.ContentInfo;
110 Tizen.Log.Info("NUI", "tscholb : OnWidgetContentUpdatedCB : " + encodedBundle + "\n");
111 Bundle bundle = Bundle.Decode(encodedBundle);
113 if (bundle.TryGetItem("COUNT", out outString))
115 Tizen.Log.Info("NUI", "OnWidgetContentUpdatedCB(2) : " + outString + "\n");
121 static void Main(string[] args)
123 var app = new Program();
127 private static MessagePort _msgPort;
128 private View rootView;
129 WidgetView mWidgetView;
130 WidgetView mWidgetView2;