2 * Copyright(c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.ComponentModel;
21 using Tizen.NUI.Scene3D;
23 using static Tizen.AIAvatar.AIAvatar;
25 namespace Tizen.AIAvatar
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 internal class EyeBlinker : AnimationModule
30 private const int blinkIntervalMinimum = 800;
31 private const int blinkIntervalMaximum = 3000;
32 private Animation eyeAnimation;
34 private Timer blinkTimer;
36 private bool isPlaying = false;
37 private const int blinkDuration = 200;
39 [EditorBrowsable(EditorBrowsableState.Never)]
45 [EditorBrowsable(EditorBrowsableState.Never)]
46 public override void Init(Animation eyeAnimation)
48 this.eyeAnimation = eyeAnimation;
51 [EditorBrowsable(EditorBrowsableState.Never)]
52 public override void Play(IAnimationModuleData data)
58 [EditorBrowsable(EditorBrowsableState.Never)]
59 public override void Stop()
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 public override void Pause()
67 eyeAnimation?.Pause();
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public override void Destroy()
76 private void StartEyeBlink()
80 blinkTimer = new Timer(blinkDuration);
81 if (blinkTimer != null)
83 blinkTimer.Tick += OnBlinkTimer;
89 private void PauseEyeBlink()
95 private void StopEyeBlink()
101 private void DestroyAnimation()
104 if (eyeAnimation != null)
107 eyeAnimation.Dispose();
113 private bool OnBlinkTimer(object source, Timer.TickEventArgs e)
115 if (eyeAnimation == null)
117 Log.Error(LogTag, "eye animation is not ready");
120 eyeAnimation?.Play();
122 var random = new Random();
123 var fortimerinterval = (uint)random.Next(blinkIntervalMinimum, blinkIntervalMaximum);
124 blinkTimer.Interval = fortimerinterval;
128 private void DestroyBlinkTimer()
130 if (blinkTimer != null)
132 blinkTimer.Tick -= OnBlinkTimer;
134 blinkTimer.Dispose();