66e9067b2cd86995ea82aa9b1b866918723cb891
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.WidgetViewTest / 0.Template / Tizen.NUI.WidgetViewTest / SimpleWidgetViewApp.cs
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using Tizen.NUI;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.Applications;
21 namespace WidgetApplicationTemplate
22 {
23     class Program : NUIApplication
24     {
25         protected override void OnCreate()
26         {
27             base.OnCreate();
28             Initialize();
29         }
30         void Initialize()
31         {
32             Window window = GetDefaultWindow();
33
34             window.KeyEvent += OnKeyEvent;
35             window.TouchEvent += OnTouchEvent;
36             
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);
42
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);
50
51             Bundle bundle = new Bundle();
52             bundle.AddItem("COUNT", "1");
53             String encodedBundle = bundle.Encode();
54
55             widgetWidth = 500;
56             widgetHeight = 500;
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);
60
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);
64
65
66         }
67         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
68         {
69             if (e.Key.State == Key.StateType.Down )
70             {
71                 Tizen.Log.Info("NUI", "OnKeyEvent(View-Window) : " + e.Key.KeyPressedName + "\n");
72                 if (e.Key.KeyPressedName == "1")
73                 {
74                     widgetWidth += 200;
75                     widgetHeight += 200;
76                     if(widgetWidth > 1000 || widgetHeight > 1000)
77                     {
78                         widgetWidth = 200;
79                         widgetHeight = 200;
80                     }
81                     mWidgetView.Size2D = new Size2D(widgetWidth, widgetHeight);
82                 }
83
84             }
85         }
86         private void OnTouchEvent(object source, Window.TouchEventArgs e)
87         {
88         }
89         private void OnWidgetContentUpdatedCB(object sender, WidgetView.WidgetViewEventArgs e)
90         {
91             String encodedBundle = e.WidgetView.ContentInfo;
92             Bundle bundle = Bundle.Decode(encodedBundle);
93             string outString;
94             if (bundle.TryGetItem("WidgetKey", out outString))
95             {
96                 Tizen.Log.Info("NUI", "OnWidgetContentUpdatedCB : " + outString + "\n");
97             }
98
99         }
100
101         static void Main(string[] args)
102         {
103             var app = new Program();
104             app.Run(args);
105         }
106
107         private View rootView;
108         WidgetView mWidgetView;
109         WidgetView mWidgetView2;
110         int widgetWidth;
111         int widgetHeight;
112     }
113 }
114
115