From cd60bd93881eb680ac2372d7d3dfb51c2f89ca97 Mon Sep 17 00:00:00 2001 From: "xb.teng" Date: Mon, 31 Jul 2017 16:52:35 +0800 Subject: [PATCH] Add FeedKeyEvent api in window of nui Change-Id: Ia4606572080ddd370de12bac60f87596813a0a7e --- .../NUISamples.TizenTV/examples/feedkey-test.cs | 114 +++++++++++++++++++++ Tizen.NUI/src/internal/ManualPINVOKE.cs | 3 + Tizen.NUI/src/public/Window.cs | 5 + 3 files changed, 122 insertions(+) create mode 100755 NUISamples/NUISamples/NUISamples.TizenTV/examples/feedkey-test.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 index 0000000..0138376 --- /dev/null +++ b/NUISamples/NUISamples/NUISamples.TizenTV/examples/feedkey-test.cs @@ -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); + } + } +} diff --git a/Tizen.NUI/src/internal/ManualPINVOKE.cs b/Tizen.NUI/src/internal/ManualPINVOKE.cs index 8bf59d8..173719e 100755 --- a/Tizen.NUI/src/internal/ManualPINVOKE.cs +++ b/Tizen.NUI/src/internal/ManualPINVOKE.cs @@ -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); } } diff --git a/Tizen.NUI/src/public/Window.cs b/Tizen.NUI/src/public/Window.cs index f8a0767..53a1dca 100755 --- a/Tizen.NUI/src/public/Window.cs +++ b/Tizen.NUI/src/public/Window.cs @@ -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(); + } } } -- 2.7.4