[NUI] Merge branch 'devel/nui'
[platform/core/csapi/tizenfx.git] / NUIsamples / NUIsamples / src / examples / feedkey-test.cs
1 /*
2 * Copyright (c) 2017 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
18 using System;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.Constants;
23
24 namespace FeedKeyTest
25 {
26     class Example : NUIApplication
27     {
28         public Example() : base()
29         {
30         }
31
32         public Example(string stylesheet) : base(stylesheet)
33         {
34         }
35
36         public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
37         {
38         }
39
40         protected override void OnCreate()
41         {
42             base.OnCreate();
43             Initialize();
44         }
45
46         public void Initialize()
47         {
48             Window window = Window.Instance;
49             window.BackgroundColor = Color.White;
50
51             View view1 = new View()
52             {
53                 Position2D = new Position2D(10, 10),
54                 BackgroundColor = Color.Magenta,
55                 Size2D = new Size2D(200, 200),
56                 Focusable = true
57             };
58
59             View view2 = new View()
60             {
61                 Position2D = new Position2D(10, 240),
62                 BackgroundColor = Color.Red,
63                 Size2D = new Size2D(200, 200),
64                 Focusable = true
65             };
66
67             window.Add(view1);
68             window.Add(view2);
69
70             FocusManager.Instance.SetCurrentFocusView(view1);
71             view2.UpFocusableView = view1;
72             view1.DownFocusableView = view2;
73
74             view1.KeyEvent += (obj, e) =>
75             {
76                 if (e.Key.State != Key.StateType.Down)
77                 {
78                     return false;
79                 }
80                 Tizen.Log.Debug("NUI", "View1 KeyPressedName: " + e.Key.KeyPressedName);
81                 Window.FeedKeyEvent(e.Key);
82                 return false;
83             };
84
85             view2.KeyEvent += (obj, e) =>
86             {
87                 if (e.Key.State != Key.StateType.Down)
88                 {
89                     // Tizen.Log.Debug("NUI", "View2 key state != Down");
90                     return false;
91                 }
92
93                 // Tizen.Log.Debug("NUI", "View2 KeyPressedName: " + e.Key.KeyPressedName);
94                 View v = obj as View;
95                 if(v == view1)
96                 {
97                     Tizen.Log.Debug("NUI", "View2 received view1 feed event: " + e.Key.KeyPressedName);
98                 }
99                 if (v == view2)
100                 {
101                     Tizen.Log.Debug("NUI", "View2 received event: " + e.Key.KeyPressedName);
102                 }
103                 return false;
104             };
105         }
106
107         [STAThread]
108         static void _Main(string[] args)
109         {
110             Example example = new Example();
111             example.Run(args);
112         }
113     }
114 }