--- /dev/null
+/*
+ * 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
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);
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)
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();
{
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;
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();
currentResponseBubbleTimerState = TimerState.Inactive;
currentHighlightTooltipTimerState = TimerState.Inactive;
currentHighlightGridTimerState = TimerState.Inactive;
- currentVoiceTouchState = VoiceTouchState.Idle;
}
public static VoiceTouchViewManager Instance
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;
}
}
{
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"));
}
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"));
}