-using System;
-using System.Collections.Generic;
-using System.Linq;
+using System;
using Tizen.Multimedia;
using Tizen.NUI;
using Tizen.NUI.BaseComponents;
/// <summary>
/// The view for controlling camera.
/// </summary>
- public class Camera : View
+ public class Camera : CameraView
{
private Tizen.Multimedia.Camera camera;
- private Window previewWindow;
/// <summary>
/// Initializes a new instance of the <see cref="Camera"/> class.
/// </summary>
public Camera()
+ : this(new Tizen.Multimedia.Camera(Tizen.Multimedia.CameraDevice.Front))
{
- this.Relayout += OnCameraRelayout;
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Camera"/> class.
+ /// </summary>
+ private Camera(IntPtr handle)
+ : base(handle)
+ {
+ }
- CreateCamera();
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Camera"/> class.
+ /// </summary>
+ /// <param name="camera">The multimedia camera.</param>
+ private Camera(Tizen.Multimedia.Camera camera)
+ : this(camera.Handle)
+ {
+ this.camera = camera;
+ camera.StartPreview();
}
/// <summary>
}
/// <summary>
- /// Gets all the fps supported by the camera.
+ /// Gets the state of preview.
/// </summary>
- public IEnumerable<CameraFps> SupportedPreviewFps
- {
- get => camera.Capabilities.SupportedPreviewFps;
- }
+ public CameraState PreviewState => camera.State;
/// <summary>
/// Gets or sets the preview fps.
}
/// <summary>
- /// Gets the state of preview.
- /// </summary>
- public CameraState PreviewState => camera.State;
-
- /// <summary>
- /// Starts preview.
- /// </summary>
- public void StartPreview()
- {
- if (camera.Display != null && camera.State == CameraState.Created)
- {
- camera.StartPreview();
- }
- }
-
- /// <summary>
- /// Stops preview if preivew is displaying.
- /// </summary>
- public void StopPreview()
- {
- if (camera.State == CameraState.Preview)
- {
- camera.StopPreview();
- }
- }
-
- /// <summary>
- /// Moves preview window to input position.
- /// </summary>
- /// <remarks>This API doesn't support to change size of the preview now.</remarks>
- /// <param name="position">The position to move.</param>
- public void Move(Position position)
- {
- if (position == null)
- {
- throw new ArgumentNullException("position should be set");
- }
-
- if (position.X < 0 || position.Y < 0)
- {
- throw new ArgumentOutOfRangeException("The position should be greater than 0. We don't support relative coordicate.");
- }
-
- Services.Logger.Debug($"Position={position.X}x{position.Y}");
- previewWindow.WindowPosition = position;
- }
-
- /// <summary>
- /// Hides preview window.
- /// </summary>
- public void HidePreviewWindow()
- {
- previewWindow?.Hide();
- }
-
- /// <summary>
- /// Shows preview window.
+ /// Stops capturing and drawing preview frames on the screen.
/// </summary>
- public void ShowPreviewWindow()
- {
- previewWindow?.Show();
- }
+ public void StopPreview() => camera.StopPreview();
/// <summary>
/// Dispose.
/// <param name="type">Dispose type.</param>
protected override void Dispose(DisposeTypes type)
{
- Services.Logger.Debug("Enter");
-
- // if (disposed)
- // {
- // return;
- // }
camera?.Dispose();
- previewWindow?.Dispose();
-
base.Dispose(type);
}
-
- private void OnCameraRelayout(object sender, EventArgs e)
- {
- this.Relayout -= OnCameraRelayout;
-
- Start();
- }
-
- private void Start()
- {
- SetDisplay();
- StartPreview();
- }
-
- private void CreateCamera()
- {
- try
- {
- camera = new Tizen.Multimedia.Camera(CameraDevice.Rear);
- }
- catch (Exception e)
- {
- Services.Logger.Error(e.ToString());
-
- return;
- }
- }
-
- private void SetDisplay()
- {
- // We need to add some dummy view into Window, even if we doesn't use it.
- // If not, NUI framework will not render Window at all.
- var previewResolution = GetPreviewResolution();
-
- // Create and configure the window for preview
- previewWindow = new Window(new Tizen.NUI.Rectangle(
- (int)PositionX, (int)PositionY, (int)SizeWidth, (int)SizeHeight))
- {
- BackgroundColor = Color.Transparent,
- Title = "Scanning view",
- };
- previewWindow.SetTransparency(true);
- previewWindow.Add(new View());
- previewWindow.SetParent(Window.Instance);
-
- // Set previewWindow to Camera FW and set values for display
- camera.Display = new Display(previewWindow);
- camera.Settings.PreviewResolution = previewResolution;
- camera.DisplaySettings.Flip = Flips.Horizontal;
- }
-
- private Tizen.Multimedia.Size GetPreviewResolution()
- {
- var windowSize = Window.Instance.WindowSize;
-
- var previewResolution = camera.Capabilities.SupportedPreviewResolutions
- .Where(s => (s.Width < windowSize.Width) && (s.Height < windowSize.Height))
- .OrderByDescending(s => s.Width)
- .FirstOrDefault();
- Services.Logger.Info($"Suitable resolution : {previewResolution.Width}x{previewResolution.Height}");
-
- return previewResolution;
- }
}
}
},
Camera: new Coordinates() // fixed for now
{
- Position = new Position(1200, 138),
- Size = new Size(392, 220),
+ Position = new Position(1356, 144),
+ Size = new Size(500, 292),
});
public ExercisingView()
PlayingView.PreviewStub.Relayout += OnPlayingViewRelayout;
}
- /// <summary>
- /// OnAppearing.
- /// </summary>
- protected override void OnAppearing()
- {
- switch (cameraView.PreviewState)
- {
- case Tizen.Multimedia.CameraState.Created:
- cameraView.StartPreview();
- break;
- case Tizen.Multimedia.CameraState.Preview:
- cameraView.ShowPreviewWindow();
- break;
- }
- }
-
- /// <summary>
- /// OnDisappearing.
- /// </summary>
- protected override void OnDisappearing()
- {
- if (cameraView.PreviewState == Tizen.Multimedia.CameraState.Preview)
- {
- cameraView.HidePreviewWindow();
- }
- }
-
private static void OnIsPlayingChanged(BindableObject bindable, object oldValue, object newValue)
{
if (newValue is bool isPlaying && bindable is ExercisingView view)
}
}
- private static Task Animate(View view, Coordinates from, Coordinates to, CancellationToken token)
+ private static (Task, Task) Animate(View view, Coordinates from, Coordinates to, CancellationToken token)
{
Task Scale()
{
return animation.PlayAndDispose(token);
}
- return Task.WhenAll(Scale(), Move());
+ return (Scale(), Move());
}
private static Position GetPosition(View view)
if (isPlaying)
{
- await Animate(Preview, pause.Preview, playing.Preview, source.Token);
-
- cameraView.Move(playing.Camera.Position);
+ (Task scalePreview, Task movePreview) = Animate(Preview, pause.Preview, playing.Preview, source.Token);
+ (Task scaleCamera, Task moveCamera) = Animate(cameraView, pause.Camera, playing.Camera, source.Token);
+ await Task.WhenAll(scalePreview, movePreview, scaleCamera, moveCamera);
PauseView.Hide();
PlayingView.Show();
PlayingView.Hide();
PauseView.Show();
- cameraView.Move(pause.Camera.Position);
-
- await Animate(Preview, playing.Preview, pause.Preview, source.Token);
+ (Task scalePreview, Task movePreview) = Animate(Preview, playing.Preview, pause.Preview, source.Token);
+ (Task scaleCamera, Task moveCamera) = Animate(cameraView, playing.Camera, pause.Camera, source.Token);
+ await Task.WhenAll(scalePreview, movePreview, scaleCamera, moveCamera);
}
if (source.IsCancellationRequested == false)