[Tizen]Update ImfManager and fix Resized&LanguageChanged event
authorxb.teng <xb.teng@samsung.com>
Fri, 28 Jul 2017 15:22:13 +0000 (23:22 +0800)
committerxb.teng <xb.teng@samsung.com>
Mon, 31 Jul 2017 15:45:32 +0000 (23:45 +0800)
Change-Id: Id0ee7c5afdc47f701e4b22e9017343c7d4fc827c

NUISamples/NUISamples/NUISamples.TizenTV/examples/text-test2.cs
src/Tizen.NUI/src/public/ImfManager.cs

index 0ba752c..75d43fe 100755 (executable)
-/*\r
-* Copyright (c) 2017 Samsung Electronics Co., Ltd.\r
-*\r
-* Licensed under the Apache License, Version 2.0 (the "License");\r
-* you may not use this file except in compliance with the License.\r
-* You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*\r
-*/\r
-\r
-using System;\r
-using System.Runtime.InteropServices;\r
-using Tizen.NUI;\r
-using Tizen.NUI.UIComponents;\r
-using Tizen.NUI.BaseComponents;\r
-using Tizen.NUI.Constants;\r
-\r
-namespace TextTest2\r
-{\r
-    class Example : NUIApplication\r
-    {\r
-        public Example() : base()\r
-        {\r
-        }\r
-\r
-        public Example(string stylesheet) : base(stylesheet)\r
-        {\r
-        }\r
-\r
-        public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)\r
-        {\r
-        }\r
-\r
-        protected override void OnCreate()\r
-        {\r
-            base.OnCreate();\r
-            Initialize();\r
-        }\r
-\r
-        private PushButton _button;\r
-        private PushButton button2;\r
-        private TextField _field;\r
-        private TextEditor editor;\r
-\r
-\r
-        public void Initialize()\r
-        {\r
-            Window window = Window.Instance;\r
-            window.BackgroundColor = Color.White;\r
-\r
-            _field = new TextField();\r
-            _field.Size2D = new Size2D(500, 300);\r
-            _field.Position2D = new Position2D(530, 550);\r
-            _field.BackgroundColor = Color.Cyan;\r
-            _field.PlaceholderText = "TextField input someth...";\r
-            _field.Focusable = true;\r
-            _field.EnableSelection = true;\r
-            window.Add(_field);\r
-\r
-            PropertyMap propertyMap = new PropertyMap();\r
-            propertyMap.Add("placeholderText", new PropertyValue("TextEditor Placeholder Text"));\r
-            propertyMap.Add("placeholderColor", new PropertyValue(Color.Red));\r
-            propertyMap.Add("placeholderPointSize", new PropertyValue(12.0f));\r
-\r
-            PropertyMap fontStyleMap = new PropertyMap();\r
-            fontStyleMap.Add("weight", new PropertyValue("bold"));\r
-            fontStyleMap.Add("width", new PropertyValue("condensed"));\r
-            fontStyleMap.Add("slant", new PropertyValue("italic"));\r
-            propertyMap.Add("placeholderFontStyle", new PropertyValue(fontStyleMap));\r
-\r
-\r
-            editor = new TextEditor();\r
-            editor.Size2D = new Size2D(500, 300);\r
-            editor.Position2D = new Position2D(10, 550);\r
-            editor.BackgroundColor = Color.Magenta;\r
-            editor.Focusable = true;\r
-            editor.Placeholder = propertyMap;\r
-\r
-            window.Add(editor);\r
-            editor.TextChanged += (obj, e) => {\r
-                Tizen.Log.Fatal("NUI", "editor line count: " + e.TextEditor.LineCount);\r
-            };\r
-\r
-            editor.ScrollStateChanged += (obj, e) => {\r
-                Tizen.Log.Fatal("NUI", "editor scroll state:" + e.ScrollState);\r
-            };\r
-\r
-            Tizen.Log.Debug("NUI", "editor id: " + editor.ID);\r
-\r
-            ImfManager imfManager = ImfManager.Get();\r
-            // send privatecommand event\r
-            ImfManager.ImfEventData imfevent = new ImfManager.ImfEventData(ImfManager.ImfEvent.PrivateCommand, "", 0, 0);\r
-            imfManager.ImfManagerEventReceived += ImfManager_ImfManagerEventReceived;\r
-\r
-            //imfmanager.imfManagerLanguageChanged += ImfManager_LanguageChanged;\r
-\r
-            _button = new PushButton();\r
-            _button.LabelText = "Button1";\r
-            _button.Size2D = new Size2D(400, 200);\r
-            _button.Position2D = new Position2D(10, -10);\r
-            _button.ParentOrigin = ParentOrigin.BottomLeft;\r
-            _button.PivotPoint = PivotPoint.BottomLeft;\r
-            _button.PositionUsesPivotPoint = true;\r
-            _button.Focusable = true;\r
-            window.Add(_button);\r
-\r
-            button2 = new PushButton();\r
-            button2.LabelText = "Button2";\r
-            button2.Size2D = new Size2D(400, 200);\r
-            button2.ParentOrigin = ParentOrigin.BottomLeft;\r
-            button2.PivotPoint = PivotPoint.BottomLeft;\r
-            button2.Position2D = new Position2D(420, -10);\r
-            button2.PositionUsesPivotPoint = true;\r
-            button2.Focusable = true;\r
-            window.Add(button2);\r
-\r
-            _button.UpFocusableView = editor;\r
-            FocusManager.Instance.PreFocusChange += OnPreFocusChange;\r
-        }\r
-\r
-        private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)\r
-        {\r
-            if (!e.ProposedView && !e.CurrentView)\r
-            {\r
-                e.ProposedView = _button;\r
-            }\r
-            return e.ProposedView;\r
-        }\r
-\r
-        public ImfManager.ImfCallbackData ImfManager_ImfManagerEventReceived(object sender, ImfManager.ImfManagerEventReceivedEventArgs e)\r
-        {\r
-            Tizen.Log.Fatal("NUI", "ImfManager_ImfManagerEventReceived()!");\r
-\r
-            Tizen.Log.Fatal("NUI", "e.ImfEventData.PredictiveString= " + e?.ImfEventData?.PredictiveString);\r
-            Tizen.Log.Fatal("NUI", "e.ImfEventData.PredictiveString= " + e?.ImfEventData?.CursorOffset);\r
-            Tizen.Log.Fatal("NUI", "e.ImfEventData.PredictiveString= " + e?.ImfEventData?.EventName);\r
-            Tizen.Log.Fatal("NUI", "e.ImfEventData.PredictiveString= " + e?.ImfEventData?.NumberOfChars);\r
-\r
-            //Be able to compare VD specific private command with ImfEventData.predictiveString\r
-            if (e.ImfEventData.PredictiveString == "IME_F31")\r
-            {\r
-                ImfManager.Get().Deactivate();\r
-                ImfManager.Get().HideInputPanel();\r
-                // Do Something the user wants\r
-                Tizen.Log.Fatal("NUI", "ImfManager ImfEventData.PredictiveString: IME_F31!!!");\r
-            }\r
-            ImfManager.ImfCallbackData callbackData = new ImfManager.ImfCallbackData(true, 0, e.ImfEventData.PredictiveString, false);\r
-            Tizen.Log.Fatal("NUI", "ImfManager return callbackData!!!");\r
-            return callbackData;\r
-        }\r
-\r
-        //public void ImfManager_LanguageChanged(object sender, EventArgs args)\r
-        //{\r
-        //    Tizen.Log.Fatal("NUI", "ImfManager LanguageChanged!!!");\r
-        //    return;\r
-        //}\r
-\r
-        [STAThread]\r
-        static void _Main(string[] args)\r
-        {\r
-            Example example = new Example();\r
-            example.Run(args);\r
-        }\r
-    }\r
-}\r
+/*
+* 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.UIComponents;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Constants;
+
+namespace TextTest2
+{
+    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();
+        }
+
+        private PushButton button;
+        private TextEditor editor;
+        private ImfManager imfManager;
+
+
+        public void Initialize()
+        {
+            Window window = Window.Instance;
+            window.BackgroundColor = Color.White;
+
+            PropertyMap propertyMap = new PropertyMap();
+            propertyMap.Add("placeholderText", new PropertyValue("TextEditor Placeholder Text"));
+            propertyMap.Add("placeholderColor", new PropertyValue(Color.Red));
+            propertyMap.Add("placeholderPointSize", new PropertyValue(12.0f));
+
+            PropertyMap fontStyleMap = new PropertyMap();
+            fontStyleMap.Add("weight", new PropertyValue("bold"));
+            fontStyleMap.Add("width", new PropertyValue("condensed"));
+            fontStyleMap.Add("slant", new PropertyValue("italic"));
+            propertyMap.Add("placeholderFontStyle", new PropertyValue(fontStyleMap));
+
+
+            editor = new TextEditor()
+            {
+                Size2D = new Size2D(500, 300),
+                Position2D = new Position2D(10, 550),
+                BackgroundColor = Color.Magenta,
+                Focusable = true,
+                Placeholder = propertyMap
+            };
+
+            window.Add(editor);
+
+            editor.TextChanged += (obj, e) => {
+                Tizen.Log.Fatal("NUI", "editor line count: " + e.TextEditor.LineCount);
+            };
+
+            editor.ScrollStateChanged += (obj, e) => {
+                Tizen.Log.Fatal("NUI", "editor scroll state:" + e.ScrollState);
+            };
+
+            editor.KeyEvent += OnKeyEvent;
+
+
+            Tizen.Log.Debug("NUI", "editor id: " + editor.ID);
+
+            imfManager = ImfManager.Get();
+            imfManager.AutoEnableInputPanel(false);
+            imfManager.SetInputPanelUserData("layouttype = 1 & entrylimit = 255 & action = clearall_for_voice_commit & caller = org.volt.search - all");
+
+
+            // send privatecommand event
+            ImfManager.ImfEventData imfevent = new ImfManager.ImfEventData(ImfManager.ImfEvent.PrivateCommand, "", 0, 0);
+            imfManager.EventReceived += ImfManager_ImfManagerEventReceived;
+
+            imfManager.LanguageChanged += ImfManager_LanguageChanged;
+
+            imfManager.Activated += (obj, e) => {
+                Tizen.Log.Debug("NUI", "ImfManager Activated !!!!!");
+            };
+            imfManager.StatusChanged += (obj, e) => {
+                Tizen.Log.Debug("NUI", "ImfManager StatusChanged: !!!!!" + e.StatusChanged);
+            };
+            imfManager.Resized += (obj, e) =>
+            {
+                Tizen.Log.Debug("NUI", "ImfManager Resized !!!!!");
+            };
+            imfManager.KeyboardTypeChanged += (obj, e) => {
+                Tizen.Log.Debug("NUI", "ImfManager KeyboardTypeChanged: !!!!!" + e.KeyboardType);
+            };
+
+            button = new PushButton()
+            {
+                LabelText = "Button",
+                Size2D = new Size2D(400, 200),
+                Position2D = new Position2D(10, -10),
+                ParentOrigin = ParentOrigin.BottomLeft,
+                PivotPoint = PivotPoint.BottomLeft,
+                PositionUsesPivotPoint = true,
+                Focusable = true
+            };
+
+            window.Add(button);
+
+            button.UpFocusableView = editor;
+            editor.DownFocusableView = button;
+
+            FocusManager.Instance.SetCurrentFocusView(button);
+        }
+
+        private bool OnKeyEvent(object source, View.KeyEventArgs e)
+        {
+            Tizen.Log.Debug("NUI", "KeyEvent called !!!!!");
+            if (e.Key.State != Key.StateType.Down || editor.Focusable == false)
+            {
+                Tizen.Log.Debug("NUI", "KeyEvent ignored !!!!!");
+                return false;
+            }
+            switch (e.Key.KeyPressedName)
+            {
+                case "Return":
+                    Tizen.Log.Debug("NUI", "KeyPressedName: Return !!!!!");
+                    ShowImf();
+                    return true;
+                case "Select":
+                    Tizen.Log.Debug("NUI", "KeyPressedName: Select !!!!!");
+                    HideImf();
+                    return true;
+                case "Cancel":
+                    Tizen.Log.Debug("NUI", "KeyPressedName: Cancel !!!!!");
+                    HideImf();
+                    return true;
+                case "Down":
+                    Tizen.Log.Debug("NUI", "KeyPressedName: Down !!!!!");
+                    HideImf();
+                    return MoveFocusTo(button);
+            }
+            return false;
+        }
+
+        private void ShowImf()
+        {
+            imfManager.Activate();
+            imfManager.ShowInputPanel();
+            Tizen.Log.Debug("NUI", "IME showed !!!!!");
+        }
+
+        private bool MoveFocusTo(View view)
+        {
+            if (view == null) return false;
+            return FocusManager.Instance.SetCurrentFocusView(view);
+        }
+
+        private void HideImf()
+        {
+            imfManager.Deactivate();
+            imfManager.HideInputPanel();
+            Tizen.Log.Debug("NUI", "IME hided !!!!!");
+        }
+
+        public ImfManager.ImfCallbackData ImfManager_ImfManagerEventReceived(object sender, ImfManager.EventReceivedEventArgs e)
+        {
+            Tizen.Log.Debug("NUI", "ImfManager_ImfManagerEventReceived()!");
+
+            Tizen.Log.Debug("NUI", "e.ImfEventData.PredictiveString= " + e?.ImfEventData?.PredictiveString);
+            Tizen.Log.Debug("NUI", "e.ImfEventData.CursorOffset= " + e?.ImfEventData?.CursorOffset);
+            Tizen.Log.Debug("NUI", "e.ImfEventData.EventName= " + e?.ImfEventData?.EventName);
+            Tizen.Log.Debug("NUI", "e.ImfEventData.NumberOfChars= " + e?.ImfEventData?.NumberOfChars);
+
+            //Be able to compare VD specific private command with ImfEventData.predictiveString
+            if (e.ImfEventData.PredictiveString == "IME_F31")
+            {
+                ImfManager.Get().Deactivate();
+                ImfManager.Get().HideInputPanel();
+                // Do Something the user wants
+                Tizen.Log.Debug("NUI", "ImfManager ImfEventData.PredictiveString: IME_F31!!!");
+            }
+            ImfManager.ImfCallbackData callbackData = new ImfManager.ImfCallbackData(true, 0, e.ImfEventData.PredictiveString, false);
+            Tizen.Log.Debug("NUI", "ImfManager return callbackData!!!");
+            return callbackData;
+        }
+
+        public void ImfManager_LanguageChanged(object sender, EventArgs args)
+        {
+            Tizen.Log.Debug("NUI", "ImfManager LanguageChanged!!!");
+            return;
+        }
+
+        [STAThread]
+        static void _Main(string[] args)
+        {
+            Example example = new Example();
+            example.Run(args);
+        }
+    }
+}
index 1706bab..16f5728 100755 (executable)
@@ -860,13 +860,6 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        internal static ImfManager GetImfManagerFromPtr(IntPtr cPtr)
-        {
-            ImfManager ret = new ImfManager(cPtr, false);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
-        }
-
         /// <summary>
         /// ImfManager activated event arguments.
         /// </summary>
@@ -916,7 +909,10 @@ namespace Tizen.NUI
         {
             ImfManagerActivatedEventArgs e = new ImfManagerActivatedEventArgs();
 
-            e.ImfManager = ImfManager.GetImfManagerFromPtr(data);
+            if (data != null)
+            {
+                e.ImfManager = Registry.GetManagedBaseHandleFromNativePtr(data) as ImfManager;
+            }
 
             if (_imfManagerActivatedEventHandler != null)
             {
@@ -971,7 +967,10 @@ namespace Tizen.NUI
         {
             ActivatedEventArgs e = new ActivatedEventArgs();
 
-            e.ImfManager = ImfManager.GetImfManagerFromPtr(data);
+            if (data != null)
+            {
+                e.ImfManager = Registry.GetManagedBaseHandleFromNativePtr(data) as ImfManager;
+            }
 
             if (_activatedEventHandler != null)
             {
@@ -1038,7 +1037,10 @@ namespace Tizen.NUI
         {
             ImfManagerEventReceivedEventArgs e = new ImfManagerEventReceivedEventArgs();
 
-            e.ImfManager = ImfManager.GetImfManagerFromPtr(data);
+            if (data != null)
+            {
+                e.ImfManager = Registry.GetManagedBaseHandleFromNativePtr(data) as ImfManager;
+            }
 
             if (_imfManagerEventReceivedEventHandler != null)
             {
@@ -1100,8 +1102,14 @@ namespace Tizen.NUI
 
             EventReceivedEventArgs e = new EventReceivedEventArgs();
 
-            e.ImfManager = ImfManager.GetImfManagerFromPtr(imfManager);
-            e.ImfEventData = ImfEventData.GetImfEventDataFromPtr(imfEventData);
+            if (imfManager != null)
+            {
+                e.ImfManager = Registry.GetManagedBaseHandleFromNativePtr(imfManager) as ImfManager;
+            }
+            if (imfEventData != null)
+            {
+                e.ImfEventData = ImfEventData.GetImfEventDataFromPtr(imfEventData);
+            }
 
             if (_eventReceivedEventHandler != null)
             {
@@ -1176,7 +1184,10 @@ namespace Tizen.NUI
         {
             ImfManagerStatusChangedEventArgs e = new ImfManagerStatusChangedEventArgs();
 
-            e.ImfManager = ImfManager.GetImfManagerFromPtr(data);
+            if (data != null)
+            {
+                e.ImfManager = Registry.GetManagedBaseHandleFromNativePtr(data) as ImfManager;
+            }
 
             if (_imfManagerStatusChangedEventHandler != null)
             {
@@ -1297,7 +1308,10 @@ namespace Tizen.NUI
         {
             ImfManagerResizedEventArgs e = new ImfManagerResizedEventArgs();
 
-            e.ImfManager = ImfManager.GetImfManagerFromPtr(data);
+            if (data != null)
+            {
+                e.ImfManager = Registry.GetManagedBaseHandleFromNativePtr(data) as ImfManager;
+            }
 
             if (_imfManagerResizedEventHandler != null)
             {
@@ -1349,7 +1363,7 @@ namespace Tizen.NUI
         [Obsolete("Please do not use! this will be internal")]
         public ImfVoidSignalType ResizedSignal()
         {
-            ImfVoidSignalType ret = new ImfVoidSignalType(NDalicManualPINVOKE.ImfManager_ResizedSignal(swigCPtr), true);
+            ImfVoidSignalType ret = new ImfVoidSignalType(NDalicManualPINVOKE.ImfManager_ResizedSignal(swigCPtr), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -1402,7 +1416,10 @@ namespace Tizen.NUI
         {
             ImfManagerLanguageChangedEventArgs e = new ImfManagerLanguageChangedEventArgs();
 
-            e.ImfManager = ImfManager.GetImfManagerFromPtr(data);
+            if (data != null)
+            {
+                e.ImfManager = Registry.GetManagedBaseHandleFromNativePtr(data) as ImfManager;
+            }
 
             if (_imfManagerLanguageChangedEventHandler != null)
             {
@@ -1454,7 +1471,7 @@ namespace Tizen.NUI
         [Obsolete("Please do not use! this will be internal")]
         public ImfVoidSignalType LanguageChangedSignal()
         {
-            ImfVoidSignalType ret = new ImfVoidSignalType(NDalicManualPINVOKE.ImfManager_LanguageChangedSignal(swigCPtr), true);
+            ImfVoidSignalType ret = new ImfVoidSignalType(NDalicManualPINVOKE.ImfManager_LanguageChangedSignal(swigCPtr), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }