public Size Size;
}
- private const int TransitionTime = 2_000;
+ private CancellationTokenSource source;
+ private bool isInitialized = false;
+ private const int TransitionTime = 1_000;
private (Coordinates Preview, Coordinates Camera) playing;
private (Coordinates Preview, Coordinates Camera) pause =
(
Size = new Size(392, 220),
}
);
- private bool isInitialized = false;
public static readonly BindableProperty IsPlayingProperty =
BindableProperty.Create(
{
InitializeComponent();
- PlayingView.Relayout += OnPlayingViewRelayout;
+ PlayingView.PreviewStub.Relayout += OnPlayingViewRelayout;
}
public static void OnIsPlayingChanged(BindableObject bindable, object oldValue, object newValue)
private async Task TriggerStates(bool isPlaying)
{
- bool shouldAnimate = PlayingView?.CameraPosition != null;
- if (isPlaying)
+ if (isInitialized)
{
- if (shouldAnimate)
+ source?.Cancel();
+ source?.Dispose();
+ source = new CancellationTokenSource();
+
+ if (isPlaying)
{
await Task.WhenAll(
- Animate(Preview, pause.Preview, playing.Preview),
- Animate(Camera, pause.Camera, playing.Camera));
- }
-
- PauseView.Hide();
- PlayingView.Show();
- }
- else
- {
- PlayingView.Hide();
- PauseView.Show();
+ Animate(Preview, pause.Preview, playing.Preview, source.Token),
+ Animate(Camera, pause.Camera, playing.Camera, source.Token));
- if (shouldAnimate)
+ PauseView.Hide();
+ PlayingView.Show();
+ }
+ else
{
+ PlayingView.Hide();
+ PauseView.Show();
+
await Task.WhenAll(
- Animate(Preview, playing.Preview, pause.Preview),
- Animate(Camera, playing.Camera, pause.Camera));
+ Animate(Preview, playing.Preview, pause.Preview, source.Token),
+ Animate(Camera, playing.Camera, pause.Camera, source.Token));
}
+
+ SetPositionAndSize(isPlaying);
}
}
private void OnPlayingViewRelayout(object sender, System.EventArgs e)
{
UpdatePositionAndSize();
+ isInitialized = true;
+ }
+
+ private void UpdatePositionAndSize()
+ {
playing.Camera = new Coordinates()
{
- Position = Camera.Position,
- Size = Camera.Size,
+ Position = GetPosition(PlayingView.CameraStub),
+ Size = PlayingView.CameraStub.Size,
};
playing.Preview = new Coordinates()
{
- Position = Preview.Position,
- Size = Preview.Size,
+ Position = GetPosition(PlayingView.PreviewStub),
+ Size = PlayingView.PreviewStub.Size,
};
- //Tizen.Log.Debug("demo", $"camera:");
- //show(playing.Camera);
- //show(pause.Camera);
- //Tizen.Log.Debug("demo", $"");
- if (isInitialized == false)
- {
- isInitialized = true;
- TriggerStates((bool)GetValue(IsPlayingProperty));
- }
+ SetPositionAndSize((bool)GetValue(IsPlayingProperty));
}
- //void show(Coordinates c)
- //{
- // Tizen.Log.Debug("demo", $"pos: {c.Position.X} {c.Position.Y}");
- // Tizen.Log.Debug("demo", $"size: {c.Size.Width} {c.Size.Height}");
- //}
-
- private void UpdatePositionAndSize()
+ private void SetPositionAndSize(bool isPlaying)
{
- if (PlayingView.CameraPosition != null)
+ Camera.Size = playing.Camera.Size;
+ Preview.Size = playing.Preview.Size;
+
+ if (isPlaying)
+ {
+ Camera.Position = playing.Camera.Position;
+ Camera.ScaleX = 1;
+ Camera.ScaleY = 1;
+ Preview.Position = playing.Preview.Position;
+ Preview.ScaleX = 1;
+ Preview.ScaleY = 1;
+
+ PauseView.Hide();
+ PlayingView.Show();
+ }
+ else
{
- Camera.Position = PlayingView.CameraPosition;
- Camera.Size = PlayingView.CameraSize;
+ var cameraScale = pause.Camera.Size.Width / playing.Camera.Size.Width;
+ Camera.Position = pause.Camera.Position;
+ Camera.PivotPoint = new Position(0, 0);
+ Camera.ScaleX = cameraScale;
+ Camera.ScaleY = cameraScale;
+
+ var previewScale = pause.Preview.Size.Width / playing.Preview.Size.Width;
+ Preview.Position = pause.Preview.Position;
+ Preview.PivotPoint = new Position(0, 0);
+ Preview.ScaleX = previewScale;
+ Preview.ScaleY = previewScale;
- Preview.Position = PlayingView.PreviewPosition;
- Preview.Size = PlayingView.PreviewSize;
+ PlayingView.Hide();
+ PauseView.Show();
}
}
- private static Task Animate(View view, Coordinates from, Coordinates to)
+ private static Task Animate(View view, Coordinates from, Coordinates to, CancellationToken token)
{
Task Scale()
{
var animation = new Animation(TransitionTime);
animation.AnimateTo(view, "ScaleX", scale, new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear));
animation.AnimateTo(view, "ScaleY", scale, new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear));
- return animation.PlayAndDispose(CancellationToken.None);
+ return animation.PlayAndDispose(token);
}
Task Move()
{
- var path = new Path();
- path.AddPoint(from.Position);
- path.AddPoint(to.Position);
- path.GenerateControlPoints(0f);
+ var frames = new KeyFrames();
+ frames.Add(0.0f, from.Position);
+ frames.Add(1.0f, to.Position);
var animation = new Animation(TransitionTime);
- animation.AnimatePath(view, path, Vector3.Zero, new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear));
- return animation.PlayAndDispose(CancellationToken.None);
+ animation.AnimateBetween(view, nameof(from.Position), frames);
+ return animation.PlayAndDispose(token);
}
return Task.WhenAll(Scale(), Move());
}
+
+ private static Position GetPosition(View view)
+ {
+ Position position = view.Position;
+ if (view.GetParent() is View parent)
+ {
+ position += GetPosition(parent);
+ }
+
+ return position;
+ }
}
}
-using Tizen.NUI;
-using Tizen.NUI.BaseComponents;
-
-namespace Fitness.Views
+namespace Fitness.Views
{
public partial class PlayingView
{
- public Position PreviewPosition { get; private set; }
-
- public Position CameraPosition { get; private set; }
-
- public Size PreviewSize { get; private set; }
-
- public Size CameraSize { get; private set; }
-
public PlayingView()
{
InitializeComponent();
- PreviewStub.Relayout += (s, e) => UpdatePositionAndSize();
- }
-
- private void OnCameraStubRelayout(object sender, System.EventArgs e)
- {
- var pos = GetPosition(CameraStub);
- CameraPosition = new Position(pos.X, pos.Y);
- CameraSize = CameraStub.Size;
- }
-
- private void OnPreviewStubRelayout(object sender, System.EventArgs e)
- {
- var pos = GetPosition(PreviewStub);
- PreviewPosition = new Position(pos.X, pos.Y);
- PreviewSize = PreviewStub.Size;
- }
-
- private void UpdatePositionAndSize()
- {
- var pos = GetPosition(PreviewStub);
- PreviewPosition = new Position(pos.X, pos.Y);
- PreviewSize = PreviewStub.Size;
-
- pos = GetPosition(CameraStub);
- CameraPosition = new Position(pos.X, pos.Y);
- CameraSize = CameraStub.Size;
- }
-
- private static (int X, int Y) GetPosition(View view)
- {
- (int X, int Y) parentPosition = (0, 0);
- if (view.GetParent() is View parent)
- {
- parentPosition = GetPosition(parent);
- }
-
- return ((int)view.Position.X + parentPosition.X, (int)view.Position.Y + parentPosition.Y);
}
}
}