2 * Copyright (c) 2021 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 Tizen.NUI.BaseComponents;
22 internal class DefaultFrameBroker : FrameBrokerBase
24 private Window window;
25 private ImageView providerImage;
26 private bool isAnimating;
28 public delegate void AnimationEventHandler(bool direction);
29 internal event AnimationEventHandler AnimationInitialized;
30 internal event AnimationEventHandler AnimationFinished;
32 internal View mainView;
33 private bool direction;
35 internal Animation animation;
37 internal DefaultFrameBroker(Window window) : base(window)
43 protected override void OnFrameResumed(FrameData frame)
45 base.OnFrameResumed(frame);
47 direction = frame.DirectionForward;
55 AnimationInitialized?.Invoke(frame.DirectionForward);
57 if (frame.DirectionForward)
59 PlayAnimateTo(frame, ForwardAnimation);
63 PlayAnimateTo(frame, BackwardAnimation);
69 protected override void OnFramePaused()
79 private void PlayAnimateTo(FrameData frame, TransitionAnimation transition)
81 if (transition != null)
86 providerImage = new ImageView(transition.DefaultImageStyle);
87 providerImage.ParentOrigin = transition.DefaultImageStyle.ParentOrigin;
88 providerImage.PivotPoint = transition.DefaultImageStyle.PivotPoint;
89 providerImage.PositionUsesPivotPoint = true;
90 providerImage.AddRenderer(GetRenderer(frame));
93 mainView.Add(providerImage);
94 providerImage.LowerToBottom();
98 window.Add(providerImage);
103 providerImage.ApplyStyle(transition.DefaultImageStyle.Clone());
106 providerImage.Show();
107 int propertyCount = transition.AnimationDataList.Count;
108 animation = new Animation(transition.DurationMilliSeconds+80);
110 for (int i = 0; i < propertyCount; i++)
112 animation.PropertyList.Add(transition.AnimationDataList[i].Property);
113 animation.DestValueList.Add(transition.AnimationDataList[i].DestinationValue);
114 animation.StartTimeList.Add(80 +transition.AnimationDataList[i].StartTime);
115 animation.EndTimeList.Add(80 +transition.AnimationDataList[i].EndTime);
117 animation.PlayAnimateTo(providerImage);
118 animation.Finished += Ani_Finished;
127 private TransitionAnimation forwardAnimation;
128 internal TransitionAnimation ForwardAnimation
132 return forwardAnimation;
136 forwardAnimation = value;
140 private TransitionAnimation backwardAnimation;
141 internal TransitionAnimation BackwardAnimation
145 return backwardAnimation;
149 backwardAnimation = value;
153 private void Ani_Finished(object sender, EventArgs e)
157 AnimationFinished?.Invoke(direction);
160 private void ResetImage()
162 if (providerImage != null)
164 providerImage.Hide();
165 //providerImage.Unparent();
166 //providerImage.Dispose();
167 //providerImage = null;