replace lottie to rive animation 30/284530/1
authorulgal-park <ulgal.park@samsung.com>
Tue, 18 Oct 2022 06:59:08 +0000 (15:59 +0900)
committerdyamy-lee <dyamy.lee@samsung.com>
Fri, 18 Nov 2022 09:09:29 +0000 (18:09 +0900)
Change-Id: I026c302089703bcbeaa62e41d760ed5b2172c968

packaging/org.tizen.voice-touch-1.0.0.tpk
voice-touch/RiveAnimationLayer.cs [new file with mode: 0644]
voice-touch/VoiceTouch.cs
voice-touch/VoiceTouchEventManager.cs
voice-touch/VoiceTouchState.cs [new file with mode: 0644]
voice-touch/VoiceTouchViewManager.cs
voice-touch/res/mini_a.riv [new file with mode: 0644]

index a6d8939c90c995a27a1c6ad25b6cef4147a142bb..33a8dd9b94272e52f5446cc066fe0e39434e0282 100644 (file)
Binary files a/packaging/org.tizen.voice-touch-1.0.0.tpk and b/packaging/org.tizen.voice-touch-1.0.0.tpk differ
diff --git a/voice-touch/RiveAnimationLayer.cs b/voice-touch/RiveAnimationLayer.cs
new file mode 100644 (file)
index 0000000..15b331f
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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.Collections.Generic;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+
+namespace VoiceTouch
+{
+    public class RiveAnimationLayer
+    {
+        Tizen.NUI.Extension.RiveAnimationView mRive = null;
+
+        internal static string riveURL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "rive.json";
+
+        internal static int riveSize = 124;
+        internal static int riveRightPad = 82;
+        internal static int riveAbovePad = 71;
+
+        Animation inAnimation;
+        Animation outAnimation;
+        Animation resetOkAnimation;
+        Animation resetThinkingAnimation;
+        Animation resetListenAnimation;
+
+        protected VoiceTouchState currentVoiceTouchState;
+
+        public RiveAnimationLayer()
+        {
+            inAnimation = new Animation(1100);
+            inAnimation.Finished += inAnimationFinished;
+            outAnimation = new Animation(900);
+            outAnimation.Finished += outAnimationFinished;
+        }
+
+        public void CreateRive()
+        {
+            if (mRive != null)
+            {
+                return;
+            }
+            mRive = new Tizen.NUI.Extension.RiveAnimationView(
+                Tizen.Applications.Application.Current.DirectoryInfo.Resource + "mini_a.riv")
+            {
+                Size = new Size(riveSize, riveSize),
+                Position = new Position(Window.Instance.Size.Width - riveSize - riveRightPad, riveAbovePad),
+            };
+            mRive.DrawMode = DrawModeType.Overlay2D;
+            mRive.EnableAnimation("in", true);
+            mRive.Play();
+            inAnimation.Play();
+            Window.Instance.Add(mRive);
+        }
+
+        public bool ClearRive()
+        {
+            if (mRive != null)
+            {
+                mRive.Unparent();
+                mRive.Dispose();
+                mRive = null;
+            }
+            return false;
+        }
+
+        public void Clear()
+        {
+            mRive.EnableAnimation("in", false);
+            mRive.EnableAnimation("out", true);
+            outAnimation.Play();
+        }
+
+        public void ApplyThinkingAnimation()
+        {
+            currentVoiceTouchState = VoiceTouchState.Waiting;
+            mRive.SetAnimationElapsedTime("reset", -1.0f);
+            mRive.SetAnimationElapsedTime("eye 360", -1.0f);
+            //Enable thinking animation only
+            mRive.SetAnimationElapsedTime("ok", 0.0f);
+            mRive.SetAnimationElapsedTime("listen", 0.0f);
+
+            if (resetThinkingAnimation)
+            {
+                resetThinkingAnimation.Reset();
+            }
+            else
+            {
+                resetThinkingAnimation = new Animation(3000);
+                resetThinkingAnimation.Finished += resetThinkingFinished;
+            }
+            resetThinkingAnimation.Play();
+
+            mRive.EnableAnimation("thinking", true);
+            mRive.EnableAnimation("idle", false);
+            mRive.EnableAnimation("listen", false);
+            mRive.EnableAnimation("ok", false);
+        }
+
+        public void ApplyIdleAnimation()
+        {
+            currentVoiceTouchState = VoiceTouchState.Idle;
+            mRive.SetAnimationElapsedTime("reset", -1.0f);
+            mRive.SetAnimationElapsedTime("eye 360", -1.0f);
+            //Enable idle animation only
+            mRive.SetAnimationElapsedTime("ok", 0.0f);
+            mRive.SetAnimationElapsedTime("listen", 0.0f);
+            mRive.SetAnimationElapsedTime("thinking", 0.0f);
+
+            mRive.EnableAnimation("thinking", false);
+            mRive.EnableAnimation("idle", true);
+            mRive.EnableAnimation("listen", false);
+            mRive.EnableAnimation("ok", false);
+        }
+
+        public void ApplyListenAnimation()
+        {
+            currentVoiceTouchState = VoiceTouchState.Recording;
+            mRive.SetAnimationElapsedTime("reset", -1.0f);
+            mRive.SetAnimationElapsedTime("eye 360", -1.0f);
+            //Enable listen animation only
+            mRive.SetAnimationElapsedTime("ok", 0.0f);
+            mRive.SetAnimationElapsedTime("thinking", 0.0f);
+
+            if (resetListenAnimation)
+            {
+                resetListenAnimation.Reset();
+            }
+            else
+            {
+                resetListenAnimation = new Animation(3000);
+                resetListenAnimation.Finished += resetListenFinished;
+            }
+            resetListenAnimation.Play();
+
+            mRive.EnableAnimation("thinking", false);
+            mRive.EnableAnimation("idle", false);
+            mRive.EnableAnimation("listen", true);
+            mRive.EnableAnimation("ok", false);
+        }
+
+        public void ApplyOkAnimation()
+        {
+            currentVoiceTouchState = VoiceTouchState.Done;
+            mRive.SetAnimationElapsedTime("reset", -1.0f);
+            mRive.SetAnimationElapsedTime("eye 360", -1.0f);
+            //Enable ok animation only
+            mRive.SetAnimationElapsedTime("thinking", 0.0f);
+            mRive.SetAnimationElapsedTime("listen", 0.0f);
+
+            if (resetOkAnimation)
+            {
+                resetOkAnimation.Reset();
+            }
+            else
+            {
+                resetOkAnimation = new Animation(1000);
+                resetOkAnimation.Finished += resetOkFinished;
+            }
+            resetOkAnimation.Play();
+
+            mRive.EnableAnimation("thinking", false);
+            mRive.EnableAnimation("idle", false);
+            mRive.EnableAnimation("listen", false);
+            mRive.EnableAnimation("ok", true);
+        }
+
+        void resetThinkingFinished(object sender, EventArgs e)
+        {
+            if (currentVoiceTouchState == VoiceTouchState.Waiting)
+            {
+                ApplyThinkingAnimation();
+            }
+        }
+
+        void resetListenFinished(object sender, EventArgs e)
+        {
+            if (currentVoiceTouchState == VoiceTouchState.Recording)
+            {
+                ApplyListenAnimation();
+            }
+        }
+
+        void resetOkFinished(object sender, EventArgs e)
+        {
+            if (currentVoiceTouchState == VoiceTouchState.Done)
+            {
+                currentVoiceTouchState = VoiceTouchState.Waiting;
+                ApplyThinkingAnimation();
+            }
+        }
+
+        void inAnimationFinished(object sender, EventArgs e)
+        {
+            mRive.EnableAnimation("in", false);
+            ApplyThinkingAnimation();
+        }
+
+        void outAnimationFinished(object sender, EventArgs e)
+        {
+            mRive.SetAnimationElapsedTime("reset", 0.0f);
+            mRive.SetAnimationElapsedTime("eye 360", -1.0f);
+            mRive.SetAnimationElapsedTime("out", -1.0f);
+            mRive.EnableAnimation("out", false);
+            mRive.EnableAnimation("idle", false);
+            mRive.Stop();
+            ClearRive();
+        }
+    }
+}
\ No newline at end of file
index 2f2d68777a03dbe272d3a886d90a41ffe2db8588..ef64c1f63dfbe4c25fe9e909f514dc2cb278d9f5 100644 (file)
@@ -76,7 +76,7 @@ namespace VoiceTouch
 
             int state = mVoiceTouchMmiManager.VoiceTouchActivate((int)InputEventTypeEnum.MMI_INPUT_EVENT_TYPE_VOICE_TOUCH);
 
-            mVoiceTouchViewManager.ShowVoiceTouchLottie(); // show when mmi manager connected/activated?
+            mVoiceTouchViewManager.ShowVoiceTouchRive(); // show when mmi manager connected/activated?
         }
         override protected void OnPause()
         {
index 101886c9b49ce9690e4923a081a3ff26c3d6d6a9..e484c3e3fb7c3e673be8a27677d7ccfa3c12f3b5 100644 (file)
@@ -45,6 +45,8 @@ namespace VoiceTouch
         protected VoiceTouchViewManager mVoiceTouchViewManager = VoiceTouchViewManager.Instance;
         protected VoiceTouchMmiManager mVoiceTouchMmiManager = VoiceTouchMmiManager.Instance;
 
+        protected VoiceTouchState currentVoiceTouchState = VoiceTouchState.None;
+        
         public void VoiceTouchResult(object sender, SetResultEventArgs e)
         {
             Tizen.Log.Debug(LogTag, "VoiceTouchResult | type : " + e.InputEventType + ", stirng : " + e.ResultOut);
@@ -66,6 +68,8 @@ namespace VoiceTouch
                             mVoiceTouchViewManager.ShowTooltip(voiceTouchResult.uiClickableObject.infoOfClickableObjects, voiceTouchResult.uiClickableObject.tooltipType);
                             previousTooltipType = voiceTouchResult.uiClickableObject.tooltipType;
                         }
+                        currentVoiceTouchState = VoiceTouchState.Idle;
+                        mVoiceTouchViewManager.VoiceTouchStateChange(currentVoiceTouchState);
                         return;
                     case UI_CLICKED_OBJECT:
                         if (voiceTouchResult.uiClickedObject.uiObjectResultType == UI_OBJECT_RESULT_BY_GRID)
@@ -79,21 +83,31 @@ namespace VoiceTouch
                         return;
                     case ASR_PARTIAL_RESULT:
                         mVoiceTouchViewManager.ShowAsrPartialResult(voiceTouchResult.asrPartialResult.result);
+                        if (currentVoiceTouchState != VoiceTouchState.Recording) {
+                            currentVoiceTouchState = VoiceTouchState.Recording;
+                            mVoiceTouchViewManager.VoiceTouchStateChange(currentVoiceTouchState);
+                        }
                         return;
                     case ASR_FINAL_RESULT:
                         mVoiceTouchViewManager.ShowAsrFinalResult(voiceTouchResult.asrFinalResult.result);
+                        currentVoiceTouchState = VoiceTouchState.Done;
+                        mVoiceTouchViewManager.VoiceTouchStateChange(currentVoiceTouchState);
                         return;
                     case REJECT:
                         if (voiceTouchResult.reject.reason == MMI_REASON_NO_MATCHED_COMMANDS)
                         {
                             mVoiceTouchViewManager.ShowResponse("적당한 것을 선택하지 못했어요. 다시 말씀해주세요.");
                         }
+                        currentVoiceTouchState = VoiceTouchState.Idle;
+                        mVoiceTouchViewManager.VoiceTouchStateChange(currentVoiceTouchState);
                         return;
                     case ERROR:
                         if (voiceTouchResult.error.reason == MMI_REASON_NO_CLICKABLE_OBJECTS) {
                             mVoiceTouchViewManager.ShowAsrFinalResult("화면에 선택할 수 있는 것이 없어요");
                             mVoiceTouchViewManager.ClearCurrentResults();
                         }
+                        currentVoiceTouchState = VoiceTouchState.Idle;
+                        mVoiceTouchViewManager.VoiceTouchStateChange(currentVoiceTouchState);
                         return;
                     case TURN_OFF_REQUEST:
                         NUIApplication.Current.Exit();
diff --git a/voice-touch/VoiceTouchState.cs b/voice-touch/VoiceTouchState.cs
new file mode 100644 (file)
index 0000000..c8983e8
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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.Collections.Generic;
+using System.Text;
+using VoiceTouch.VoiceTouchMmi;
+using Tizen.NUI;
+
+namespace VoiceTouch
+{
+    public enum VoiceTouchState
+    {
+        None = 0,
+        Waiting = 1,
+        Idle = 2,
+        Recording = 3,
+        Done = 4,
+    }
+}
\ No newline at end of file
index 6d12aecfa164b0894aa21e07ed4f68b192f5bcd8..66c5fe357e959d28fc7595b695e0a72aa2791eb1 100644 (file)
@@ -25,10 +25,12 @@ namespace VoiceTouch
 {
     public class VoiceTouchViewManager
     {
+        internal static string LogTag = "Tizen.Mmi.ViewManager";
         private static VoiceTouchViewManager instance = null;
 
         protected TooltipLayer mTooltipLayer = null;
         protected LottieAnimationLayer mLottieAnimationLayer = null;
+        protected RiveAnimationLayer mRiveAnimationLayer = null;
         protected TextBubbleLayer mTextBubbleLayer = null;
         protected GridLayer mGridLayer = null;
 
@@ -50,17 +52,10 @@ namespace VoiceTouch
             Active = 1
         }
 
-        // need to move another place
-        protected VoiceTouchState currentVoiceTouchState;
-        public enum VoiceTouchState
-        {
-            Idle = 0,
-            Active = 1
-        }
-
         private VoiceTouchViewManager()
         {
             mLottieAnimationLayer = new LottieAnimationLayer();
+            mRiveAnimationLayer = new RiveAnimationLayer();
             mTextBubbleLayer = new TextBubbleLayer();
             mTooltipLayer = new TooltipLayer();
             mGridLayer = new GridLayer();
@@ -68,7 +63,6 @@ namespace VoiceTouch
             currentResponseBubbleTimerState = TimerState.Inactive;
             currentHighlightTooltipTimerState = TimerState.Inactive;
             currentHighlightGridTimerState = TimerState.Inactive;
-            currentVoiceTouchState = VoiceTouchState.Idle;
         }
 
         public static VoiceTouchViewManager Instance
@@ -106,21 +100,48 @@ namespace VoiceTouch
             mLottieAnimationLayer.Clear();
         }
 
+        /// <summary>
+        /// Show voice touch lottie animation
+        /// Call when mmi manager connected
+        /// </summary>
+        public void ShowVoiceTouchRive()
+        {
+            mRiveAnimationLayer.CreateRive();
+        }
+
+        /// <summary>
+        /// Clear voice touch lottie animation
+        /// </summary>
+        public void ClearVoiceTouchRive()
+        {
+            mRiveAnimationLayer.Clear();
+        }
+
 
         /// <summary>
         /// Callback for voice touch state change
         /// </summary>
         /// <param name="previousState"></param>
-        /// <param name="currentVoiceTouchState"></param>
-        public void VoiceTouchStateChange(VoiceTouchState previousState, VoiceTouchState currentVoiceTouchState)
+        /// <param name="voiceTouchState"></param>
+        public void VoiceTouchStateChange(VoiceTouchState voiceTouchState)
         {
-            if (previousState == VoiceTouchState.Idle && currentVoiceTouchState == VoiceTouchState.Active)
+            switch (voiceTouchState)
             {
-                mLottieAnimationLayer.ApplyScaleAnimation(1.2f, 1.2f, 1.2f, 500, Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOut);
-            }
-            else if (previousState == VoiceTouchState.Active && currentVoiceTouchState == VoiceTouchState.Idle)
-            {
-                mLottieAnimationLayer.ApplyScaleAnimation(1.0f, 1.0f, 1.0f, 500, Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn);
+                case VoiceTouchState.Waiting:
+                    mRiveAnimationLayer.ApplyThinkingAnimation();
+                break;
+                case VoiceTouchState.Idle:
+                    mRiveAnimationLayer.ApplyIdleAnimation();
+                break;
+                case VoiceTouchState.Recording:
+                    mRiveAnimationLayer.ApplyListenAnimation();
+                break;
+                case VoiceTouchState.Done:
+                    mRiveAnimationLayer.ApplyOkAnimation();
+                break;
+                default:
+                    Tizen.Log.Error(LogTag, "State " + voiceTouchState + "not supported");
+                break;
             }
         }
 
@@ -135,13 +156,6 @@ namespace VoiceTouch
             {
                 return;
             }
-
-            if (currentVoiceTouchState == VoiceTouchState.Idle)
-            {
-                currentVoiceTouchState = VoiceTouchState.Active;
-                mLottieAnimationLayer.ApplyScaleAnimation(1.2f, 1.2f, 1.2f, 500, Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOut);
-            }
-
             mTextBubbleLayer.CreateTextBubble(asrPartialResult, new Color("#17234D"));
         }
 
@@ -158,13 +172,6 @@ namespace VoiceTouch
                 mGridLayer.ClearHighlightedGrid();
                 mTooltipLayer.ClearHighlightedTooltip();
             }
-
-            if (currentVoiceTouchState == VoiceTouchState.Active)
-            {
-                currentVoiceTouchState = VoiceTouchState.Idle;
-                mLottieAnimationLayer.ApplyScaleAnimation(1.0f, 1.0f, 1.0f, 500, Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn);
-            }
-
             mTextBubbleLayer.CreateTextBubble(asrFinalResult, new Color("#17234D"));
         }
 
diff --git a/voice-touch/res/mini_a.riv b/voice-touch/res/mini_a.riv
new file mode 100644 (file)
index 0000000..54eba1d
Binary files /dev/null and b/voice-touch/res/mini_a.riv differ