2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 using System.Collections.Generic;
19 using System.ComponentModel;
21 using Tizen.NUI.BaseComponents;
25 internal class DefaultFrameBroker : FrameBrokerBase
27 private Window window;
28 private ImageView providerImage;
29 private bool isAnimating;
31 public delegate void AnimationEventHandler(bool direction);
32 internal event AnimationEventHandler AnimationInitialized;
33 internal event AnimationEventHandler AnimationFinished;
35 internal View mainView;
36 private bool direction;
38 internal Animation animation;
40 internal DefaultFrameBroker(Window window) : base(window)
46 protected override void OnFrameResumed(FrameData frame)
48 base.OnFrameResumed(frame);
50 direction = frame.DirectionForward;
58 AnimationInitialized?.Invoke(frame.DirectionForward);
60 if (frame.DirectionForward)
62 PlayAnimateTo(frame, ForwardAnimation);
66 PlayAnimateTo(frame, BackwardAnimation);
72 protected override void OnFramePaused()
82 private void PlayAnimateTo(FrameData frame, TransitionAnimation transition)
84 if (transition != null)
89 providerImage = new ImageView(transition.DefaultImageStyle);
90 providerImage.ParentOrigin = transition.DefaultImageStyle.ParentOrigin;
91 providerImage.PivotPoint = transition.DefaultImageStyle.PivotPoint;
92 providerImage.PositionUsesPivotPoint = true;
93 providerImage.AddRenderer(GetRenderer(frame));
96 mainView.Add(providerImage);
97 providerImage.LowerToBottom();
101 window.Add(providerImage);
106 providerImage.ApplyStyle(transition.DefaultImageStyle.Clone());
109 providerImage.Show();
110 int propertyCount = transition.AnimationDataList.Count;
111 animation = new Animation(transition.DurationMilliSeconds+80);
112 animation.Properties = new string[propertyCount];
113 animation.DestValue = new string[propertyCount];
114 animation.StartTime = new int[propertyCount];
115 animation.EndTime = new int[propertyCount];
117 for (int i = 0; i < propertyCount; i++)
119 animation.Properties[i] = transition.AnimationDataList[i].Property;
120 animation.DestValue[i] = transition.AnimationDataList[i].DestinationValue;
121 animation.StartTime[i] = 80+transition.AnimationDataList[i].StartTime;
122 animation.EndTime[i] = 80+transition.AnimationDataList[i].EndTime;
124 animation.PlayAnimateTo(providerImage);
125 animation.Finished += Ani_Finished;
134 private TransitionAnimation forwardAnimation;
135 internal TransitionAnimation ForwardAnimation
139 return forwardAnimation;
143 forwardAnimation = value;
147 private TransitionAnimation backwardAnimation;
148 internal TransitionAnimation BackwardAnimation
152 return backwardAnimation;
156 backwardAnimation = value;
160 private void Ani_Finished(object sender, EventArgs e)
164 AnimationFinished?.Invoke(direction);
167 private void ResetImage()
169 if (providerImage != null)
171 providerImage.Hide();
172 //providerImage.Unparent();
173 //providerImage.Dispose();
174 //providerImage = null;