Add FeedKeyEvent api in window of nui
authorxb.teng <xb.teng@samsung.com>
Mon, 31 Jul 2017 08:52:35 +0000 (16:52 +0800)
committerxb.teng <xb.teng@samsung.com>
Mon, 7 Aug 2017 14:11:08 +0000 (22:11 +0800)
Change-Id: Ia4606572080ddd370de12bac60f87596813a0a7e

NUISamples/NUISamples/NUISamples.TizenTV/examples/feedkey-test.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/ManualPINVOKE.cs
src/Tizen.NUI/src/public/Window.cs

diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/feedkey-test.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/feedkey-test.cs
new file mode 100755 (executable)
index 0000000..0138376
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+* Copyright (c) 2017 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Constants;
+
+namespace FeedKeyTest
+{
+    class Example : NUIApplication
+    {
+        public Example() : base()
+        {
+        }
+
+        public Example(string stylesheet) : base(stylesheet)
+        {
+        }
+
+        public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
+        {
+        }
+
+        protected override void OnCreate()
+        {
+            base.OnCreate();
+            Initialize();
+        }
+
+        public void Initialize()
+        {
+            Window window = Window.Instance;
+            window.BackgroundColor = Color.White;
+
+            View view1 = new View()
+            {
+                Position2D = new Position2D(10, 10),
+                BackgroundColor = Color.Magenta,
+                Size2D = new Size2D(200, 200),
+                Focusable = true
+            };
+
+            View view2 = new View()
+            {
+                Position2D = new Position2D(10, 240),
+                BackgroundColor = Color.Red,
+                Size2D = new Size2D(200, 200),
+                Focusable = true
+            };
+
+            window.Add(view1);
+            window.Add(view2);
+
+            FocusManager.Instance.SetCurrentFocusView(view1);
+            view2.UpFocusableView = view1;
+            view1.DownFocusableView = view2;
+
+            view1.KeyEvent += (obj, e) =>
+            {
+                if (e.Key.State != Key.StateType.Down)
+                {
+                    return false;
+                }
+                Tizen.Log.Debug("NUI", "View1 KeyPressedName: " + e.Key.KeyPressedName);
+                Window.FeedKeyEvent(e.Key);
+                return false;
+            };
+
+            view2.KeyEvent += (obj, e) =>
+            {
+                if (e.Key.State != Key.StateType.Down)
+                {
+                    // Tizen.Log.Debug("NUI", "View2 key state != Down");
+                    return false;
+                }
+
+                // Tizen.Log.Debug("NUI", "View2 KeyPressedName: " + e.Key.KeyPressedName);
+                View v = obj as View;
+                if(v == view1)
+                {
+                    Tizen.Log.Debug("NUI", "View2 received view1 feed event: " + e.Key.KeyPressedName);
+                }
+                if (v == view2)
+                {
+                    Tizen.Log.Debug("NUI", "View2 received event: " + e.Key.KeyPressedName);
+                }
+                return false;
+            };
+        }
+
+        [STAThread]
+        static void _Main(string[] args)
+        {
+            Example example = new Example();
+            example.Run(args);
+        }
+    }
+}
index 8bf59d8..173719e 100755 (executable)
@@ -785,5 +785,8 @@ namespace Tizen.NUI
 
         [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_Window_GetPosition")]
         public static extern global::System.IntPtr GetPosition(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+        [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_Adaptor_FeedKeyEvent")]
+        public static extern void Window_FeedKeyEvent(global::System.Runtime.InteropServices.HandleRef jarg1);
     }
 }
index f8a0767..53a1dca 100755 (executable)
@@ -1453,6 +1453,11 @@ namespace Tizen.NUI
             }
         }
 
+        public static void FeedKeyEvent(Key keyEvent)
+        {
+            NDalicManualPINVOKE.Window_FeedKeyEvent(Key.getCPtr(keyEvent));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
 
     }
 }