Fix candidate window blinks when changing input language 32/287732/1
authorInHong Han <inhong1.han@samsung.com>
Fri, 3 Feb 2023 07:44:41 +0000 (16:44 +0900)
committerInHong Han <inhong1.han@samsung.com>
Fri, 3 Feb 2023 07:44:41 +0000 (16:44 +0900)
Change-Id: I4deba99a328fe2ae347d62c30be25b6546d6deae

ISEDefaultNUI/CandidateView.cs
ISEDefaultNUI/Common/ResourceManager.cs
ISEDefaultNUI/ISEDefaultNUI.cs
ISEDefaultNUI/ISEDefaultNUI.csproj
ISEDefaultNUI/SCLNUI.cs
ISEDefaultNUI/VisibleChangedEventArgs.cs [new file with mode: 0644]

index 37c0975030e3ca41ca287a6c661778923a14766a..03ff39d7ea42ed176aaa6ef3392ce7fadfa56be4 100644 (file)
@@ -11,6 +11,7 @@ namespace ISEDefaultNUI
 {\r
     public class CandidateView\r
     {\r
+        private event EventHandler<VisibleChangedEventArgs> visibleEventHandler;\r
         private static CandidateView instance;\r
         private Timer timer;\r
         private View parentView;\r
@@ -85,12 +86,26 @@ namespace ISEDefaultNUI
             get => viewHeight;\r
         }\r
 \r
+        public bool IsTimerRunning\r
+        {\r
+            get => timer.IsRunning();\r
+        }\r
+\r
         private bool TimerTick(object source, Timer.TickEventArgs e)\r
         {\r
             Log.Info("NUIIME", "Hide candidate view");\r
-            parentView.Remove(candidateView);\r
             visible = false;\r
             candidateExpanded = false;\r
+\r
+            if (visibleEventHandler != null)\r
+            {\r
+                VisibleChangedEventArgs eventArgs;\r
+                eventArgs = new VisibleChangedEventArgs(candidateExpanded);\r
+                visibleEventHandler?.Invoke(null, eventArgs);\r
+            }\r
+\r
+            parentView.Remove(candidateView);\r
+\r
             return false;\r
         }\r
 \r
@@ -275,6 +290,11 @@ namespace ISEDefaultNUI
 \r
         public void Show(View parent)\r
         {\r
+            if (timer.IsRunning())\r
+            {\r
+                timer.Stop();\r
+            }\r
+\r
             if (!visible)\r
             {\r
                 Log.Info("NUIIME", "Show candidate view");\r
@@ -286,12 +306,10 @@ namespace ISEDefaultNUI
 \r
         public void Hide()\r
         {\r
-            if (timer.IsRunning())\r
+            if (timer.IsRunning() == false)\r
             {\r
-                timer.Stop();\r
+                timer.Start();\r
             }\r
-\r
-            timer.Start();\r
         }\r
 \r
         public void SetPosition(Size imeSize)\r
@@ -300,5 +318,10 @@ namespace ISEDefaultNUI
             candidateView.Size = new Size(imeSize.Width, viewHeight);\r
             candidateView.Position = new Position(0, 0);\r
         }\r
+\r
+        public void SetVisibleEventHandler(EventHandler<VisibleChangedEventArgs> handler)\r
+        {\r
+            visibleEventHandler += handler;\r
+        }\r
     }\r
 }\r
index ecfec06dce477e208f56e5b5f9c40a3a0863b22b..f0f8719218070e154f2ed17ac4a9406807b7a96b 100644 (file)
         public const int LayoutNumberOnlyVariationMax = 4;
         public const uint MagnifierShowDuration = 300;
         public const uint CandidateHideTimerInterval = 100;
-
-        /* FIXME : If an API is provided to get the screen size, use the API */
-        public const int screenWidth = 1920;
-        public const int screenHeight = 1080;
-
         public const string IseSettingAppId = "org.tizen.cssetting-keyboard";
         public const string DefaultKeyboardUuid = "org.tizen.ise-engine-default";
     }
index cd7dd405e3e52c8bb3ff5458f19826f15d361054..b38828b889c70d9087eaf49814a8ba6330d9d5b2 100644 (file)
@@ -150,6 +150,11 @@ namespace ISEDefaultNUI
 
         private static void Show(InputMethodEditor.ContextId a, Tizen.Uix.InputMethod.InputMethodContext b)
         {
+            if (SclNui == null)
+            {
+                SclNui = new SCLNUI(navigator);
+            }
+
             int inputContext = a.Equals(0) ? 0 : KeyboardState.Instance.FocusedContext;
             bool returnKeyState = b.ReturnKeyState;
             bool predictionAllow = b.PredictionMode;
@@ -202,17 +207,12 @@ namespace ISEDefaultNUI
 
             IMEHide();
             navigator.Pop();
+            SclNui.Dispose();
         }
 
         private static void IMEHide()
         {
-            SclNui.ClearClickCount();
-            SclNui.SetUpdatePending(true);
-            SclNui.DisableInputEvent(true);
-            SclNui.Hide();
-
             KeyboardState.Instance.VisibleState = false;
-            ResetShiftState();
             KeyboardState.Instance.ResetMultitapState(true);
         }
 
@@ -384,9 +384,9 @@ namespace ISEDefaultNUI
             }
 
             UpdateSpaceKey();
+            SclNui.SetImeSize();
             SclNui.Show();
             SclNui.DisableInputEvent(false);
-            SetIMESize();
         }
 
         private static void ResetContext()
@@ -498,16 +498,6 @@ namespace ISEDefaultNUI
             }
         }
 
-        private static void ResetShiftState()
-        {
-            uint oldState, newState;
-            SclNui.GetShiftState(out oldState);
-            newState = (uint)ShiftState.Off;
-
-            if (oldState != newState)
-                SclNui.SetShiftState(newState);
-        }
-
         private static void RegisterCallback()
         {
             InputMethodEditor.FocusedIn += FocusInEvent;
@@ -639,20 +629,6 @@ namespace ISEDefaultNUI
             SclDbus.FocusIn();
         }
 
-        private static void SetIMESize()
-        {
-            IntPtr inputModePtr;
-            SclNui.GetInputMode(out inputModePtr);
-            string inputMode = Marshal.PtrToStringAnsi(inputModePtr);
-
-            int portraitWidth, portraitHeight, landscapeWidth, landscapeHeight;
-            SclNui.GetInputModeSize(inputMode, (int)WindowAttribute.DisplayMode.Portrait, out portraitWidth, out portraitHeight);
-            SclNui.GetInputModeSize(inputMode, (int)WindowAttribute.DisplayMode.Landscape, out landscapeWidth, out landscapeHeight);
-            SclNui.SetImeSize(new Size2D(portraitWidth, portraitHeight), new Size2D(landscapeWidth, landscapeHeight));
-            IntPtr nativeHandle = new Window.SafeNativeWindowHandle().DangerousGetHandle();
-            InputMethodEditor.SetSize(nativeHandle, portraitWidth, portraitHeight, landscapeWidth, landscapeHeight);
-        }
-
         private static void UpdateSpaceKey()
         {
             int languageNum = LanguageManager.Instance.GetLanguagesNum();
index cd44f67b4b415058951b41341c58fc1411615a72..6eaecc47427b28f5234a14c9b71663b08a51b321 100644 (file)
@@ -14,7 +14,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Tizen.NET" Version="11.0.0.17642">
+    <PackageReference Include="Tizen.NET" Version="11.0.0.17670">
       <ExcludeAssets>Runtime</ExcludeAssets>
     </PackageReference>
     <Folder Include="lib\" />
index 5f33fca3599281ddc6945aaf80e128fe6b86640d..1fc3633fd08c62765cf2e4ac0a82d40908cac63e 100644 (file)
@@ -52,6 +52,7 @@ namespace ISEDefaultNUI
         private EmoticonPage emoticonPage = null;
 
         private int deviceAngle = 0;
+        private Size2D screenSize;
         private Size2D imePortraitSize;
         private Size2D imeLandscapeSize;
 
@@ -105,6 +106,8 @@ namespace ISEDefaultNUI
             showEmoticonTimer = new Timer(10);
             showEmoticonTimer.Tick += showEmoticonTimerTick;
 
+            screenSize = NUIApplication.GetScreenSize();
+
             /* Draw text callback */
             _draw_text_cb = (IntPtr font_name, short font_size, bool is_italic, bool is_bold, int r, int g, int b, int a,
                              IntPtr str, int pos_x, int pos_y, int width, int height,
@@ -553,27 +556,31 @@ namespace ISEDefaultNUI
 
                 if (windowType == WindowAttribute.WindowType.Magnifier)
                 {
+                    if (imePortraitSize == null || imeLandscapeSize == null)
+                        GetDefaultSize();
+
                     if (deviceAngle == 0 || deviceAngle == 180)
-                        magnifier.SetPosition(new WindowAttribute.Position(x, ResourceManager.screenHeight - imePortraitSize.Height + y, rotationX, ResourceManager.screenWidth - imeLandscapeSize.Height + rotationY));
+                        magnifier.SetPosition(new WindowAttribute.Position(x, screenSize.Height - imePortraitSize.Height + y, rotationX, screenSize.Width - imeLandscapeSize.Height + rotationY));
                     else
-                        magnifier.SetPosition(new WindowAttribute.Position(x, ResourceManager.screenWidth - imeLandscapeSize.Height + y, rotationX, ResourceManager.screenHeight - imePortraitSize.Height + rotationY));
+                        magnifier.SetPosition(new WindowAttribute.Position(x, screenSize.Width - imeLandscapeSize.Height + y, rotationX, screenSize.Height - imePortraitSize.Height + rotationY));
                 }
             };
             SclNuiUpdateWindowPositionCb(_updateWindowPositionChangedEvent, (IntPtr)null);
 
+            candidateView.SetVisibleEventHandler(OnVisibleChanged);
+
             _onCandidateShowEvent = (IntPtr userData) =>
             {
-                if (imePortraitSize == null || imeLandscapeSize == null)
-                    GetDefaultSize();
-
-                if (candidateView.IsVisible == false)
+                if (candidateView.IsVisible == false || candidateView.IsTimerRunning)
                 {
+                    SetImeSize(CandidateRequest.Show);
+
                     if (deviceAngle == 0 || deviceAngle == 180)
                         candidateView.SetPosition(imePortraitSize);
                     else
                         candidateView.SetPosition(imeLandscapeSize);
+
                     candidateView.Show(this);
-                    SetImeSize(CandidateRequest.Show);
                 }
             };
             SclSetCandidateShowCb(_onCandidateShowEvent, (IntPtr)null);
@@ -584,7 +591,6 @@ namespace ISEDefaultNUI
                 {
                     candidateView.Hide();
                 }
-                SetImeSize(CandidateRequest.Hide);
             };
             SclSetCandidateHideCb(_onCandidateHideEvent, (IntPtr)null);
 
@@ -612,6 +618,14 @@ namespace ISEDefaultNUI
             SclSetCandidateStringForeachCb(_onCandidateStringForeach, (IntPtr)null);
         }
 
+        private void OnVisibleChanged(object sender, VisibleChangedEventArgs e)
+        {
+            if (e.Visible == false)
+            {
+                SetImeSize(CandidateRequest.Hide);
+            }
+        }
+
         private bool CommitTimerTick(object source, Timer.TickEventArgs e)
         {
             InputMethodEditor.HidePreEditString();
@@ -828,8 +842,7 @@ namespace ISEDefaultNUI
 
         private void SetImeSize(CandidateRequest request)
         {
-            if (imePortraitSize == null || imeLandscapeSize == null)\r
-                GetDefaultSize();
+            GetDefaultSize();
 
             switch (request)
             {
@@ -853,22 +866,22 @@ namespace ISEDefaultNUI
 
             IntPtr nativeHandle = new Window.SafeNativeWindowHandle().DangerousGetHandle();
             InputMethodEditor.SetSize(nativeHandle, imePortraitSize.Width, imePortraitSize.Height, imeLandscapeSize.Width, imeLandscapeSize.Height);
-        }\r
-\r
-        private void GetDefaultSize()\r
-        {\r
-            IntPtr inputModePtr;\r
-            GetInputMode(out inputModePtr);\r
-            string inputMode = Marshal.PtrToStringAnsi(inputModePtr);\r
-\r
-            int portraitWidth, portraitHeight, landscapeWidth, landscapeHeight;\r
-            GetInputModeSize(inputMode, (int)WindowAttribute.DisplayMode.Portrait, out portraitWidth, out portraitHeight);\r
-            GetInputModeSize(inputMode, (int)WindowAttribute.DisplayMode.Landscape, out landscapeWidth, out landscapeHeight);\r
-\r
-            imePortraitSize = new Size2D(portraitWidth, portraitHeight);\r
-            imeLandscapeSize = new Size2D(landscapeWidth, landscapeHeight);\r
-        }\r
-\r
+        }
+
+        private void GetDefaultSize()
+        {
+            IntPtr inputModePtr;
+            GetInputMode(out inputModePtr);
+            string inputMode = Marshal.PtrToStringAnsi(inputModePtr);
+
+            int portraitWidth, portraitHeight, landscapeWidth, landscapeHeight;
+            GetInputModeSize(inputMode, (int)WindowAttribute.DisplayMode.Portrait, out portraitWidth, out portraitHeight);
+            GetInputModeSize(inputMode, (int)WindowAttribute.DisplayMode.Landscape, out landscapeWidth, out landscapeHeight);
+
+            imePortraitSize = new Size2D(portraitWidth, portraitHeight);
+            imeLandscapeSize = new Size2D(landscapeWidth, landscapeHeight);
+        }
+
         public int Init(string entry_filepath)
         {
             return SclNuiInit(entry_filepath);
@@ -983,10 +996,9 @@ namespace ISEDefaultNUI
             return SclNuiSetRotation(degree);
         }
 
-        public void SetImeSize(Size2D portraitSize, Size2D landscapeSize)
+        public void SetImeSize()
         {
-            imePortraitSize = portraitSize;
-            imeLandscapeSize = landscapeSize;
+            SetImeSize(CandidateRequest.None);
         }
     }
 }
\ No newline at end of file
diff --git a/ISEDefaultNUI/VisibleChangedEventArgs.cs b/ISEDefaultNUI/VisibleChangedEventArgs.cs
new file mode 100644 (file)
index 0000000..aa551ce
--- /dev/null
@@ -0,0 +1,22 @@
+using System;\r
+\r
+namespace ISEDefaultNUI\r
+{\r
+    public class VisibleChangedEventArgs : EventArgs\r
+    {\r
+        private bool _visible;\r
+\r
+        internal VisibleChangedEventArgs(bool visible)\r
+        {\r
+            _visible = visible;\r
+        }\r
+\r
+        public bool Visible\r
+        {\r
+            get\r
+            {\r
+                return _visible;\r
+            }\r
+        }\r
+    }\r
+}\r