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.
19 using Tizen.NUI.BaseComponents;
20 using Tizen.Applications;
21 namespace WidgetApplicationTemplate
23 class Program : NUIApplication
25 protected override void OnCreate()
32 Window window = GetDefaultWindow();
34 window.KeyEvent += OnKeyEvent;
35 window.TouchEvent += OnTouchEvent;
37 rootView = new View();
38 rootView.BackgroundColor = Color.White;
39 rootView.Size = Window.Instance.Size;
40 rootView.PivotPoint = PivotPoint.Center;
41 window.GetDefaultLayer().Add(rootView);
43 TextLabel sampleLabel = new TextLabel("Widget Viewer ");
44 sampleLabel.FontFamily = "SamsungOneUI 500";
45 sampleLabel.PointSize = 8;
46 sampleLabel.TextColor = Color.Black;
47 sampleLabel.SizeWidth = 300;
48 sampleLabel.PivotPoint = PivotPoint.Center;
49 rootView.Add(sampleLabel);
51 Bundle bundle = new Bundle();
52 bundle.AddItem("COUNT", "1");
53 String encodedBundle = bundle.Encode();
57 mWidgetView = WidgetViewManager.Instance.AddWidget("class1@Tizen.NUI.WidgetTest", encodedBundle, widgetWidth, widgetHeight, 0.0f);
58 mWidgetView.Position = new Position(100,100);
59 window.GetDefaultLayer().Add(mWidgetView);
61 mWidgetView2 = WidgetViewManager.Instance.AddWidget("class2@Tizen.NUI.WidgetTest", encodedBundle, widgetWidth, widgetHeight, 0.0f);
62 mWidgetView2.Position = new Position(100, widgetHeight + 110);
63 window.GetDefaultLayer().Add(mWidgetView2);
67 public void OnKeyEvent(object sender, Window.KeyEventArgs e)
69 if (e.Key.State == Key.StateType.Down )
71 Tizen.Log.Info("NUI", "OnKeyEvent(View-Window) : " + e.Key.KeyPressedName + "\n");
72 if (e.Key.KeyPressedName == "1")
76 if(widgetWidth > 1000 || widgetHeight > 1000)
81 mWidgetView.Size2D = new Size2D(widgetWidth, widgetHeight);
86 private void OnTouchEvent(object source, Window.TouchEventArgs e)
89 private void OnWidgetContentUpdatedCB(object sender, WidgetView.WidgetViewEventArgs e)
91 String encodedBundle = e.WidgetView.ContentInfo;
92 Bundle bundle = Bundle.Decode(encodedBundle);
94 if (bundle.TryGetItem("WidgetKey", out outString))
96 Tizen.Log.Info("NUI", "OnWidgetContentUpdatedCB : " + outString + "\n");
101 static void Main(string[] args)
103 var app = new Program();
107 private View rootView;
108 WidgetView mWidgetView;
109 WidgetView mWidgetView2;