navigation.Push(new ExercisePreviewView(workoutId));
}
- public async Task NavigateToScanningView()
- {
- var result = await PrivilegeService.Instance.CheckCameraPrivilege();
-
- if (result == Tizen.Security.RequestResult.AllowForever
- && TryCreateCameraDependentView(() => new ScanningView(), out Controls.Page view))
- {
- navigation.Push(view);
- }
- }
-
public void Pop()
{
navigation.Pop();
public MainViewModel()
{
WatchPreview = new Command(() => { NavigationService.Instance.NavigateToExercisePreviewView(SelectedWorkout.Id); });
- StartWorkout = new Command(() => _ = NavigationService.Instance.NavigateToScanningView());
+ StartWorkout = new Command(() => _ = NavigationService.Instance.NavigateToExercisingView(SelectedWorkout));
Exit = new Command(() => { Tizen.NUI.NUIApplication.Current.Exit(); });
Workouts = WorkoutRepository.Instance.GetAll();
+++ /dev/null
-using System.Windows.Input;
-using Fitness.Services;
-using Tizen.Multimedia.Vision;
-using Tizen.NUI.Binding;
-
-namespace Fitness.ViewModels
-{
- /// <summary>
- /// Class handling the scanning view.
- /// </summary>
- public class ScanningViewModel : BaseViewModel
- {
- private int count;
- private int hold;
- private int score;
- private Landmark[,] poseLandmarks;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ScanningViewModel"/> class.
- /// </summary>
- public ScanningViewModel()
- {
- CloseScanningView = new Command(() =>
- {
- NavigationService.Instance.Pop();
- });
- SquatService = new SquatService()
- {
- HoldTimeThreshold = 1200,
- };
- SquatService.ExerciseStateUpdated += SquatService_ExerciseStateUpdated;
- }
-
- /// <summary>
- /// Gets the pose landmark property.
- /// </summary>
- public Landmark[,] PoseLandmarks
- {
- get => poseLandmarks;
- private set
- {
- if (value != poseLandmarks)
- {
- poseLandmarks = value;
- RaisePropertyChanged();
- }
- }
- }
-
- /// <summary>
- /// Gets or sets the property specifying the correctness of the exercise - values ranging from 0 to 100.
- /// </summary>
- public int Score
- {
- get => score;
- set
- {
- if (value != score)
- {
- score = value;
- RaisePropertyChanged();
- }
- }
- }
-
- /// <summary>
- /// Gets or sets the property specifying the number of repetitions of the exercise.
- /// </summary>
- public int Count
- {
- get => count;
- set
- {
- if (value != count)
- {
- count = value;
- RaisePropertyChanged();
- }
- }
- }
-
- /// <summary>
- /// Gets or sets the property specifying the time of the exercise performed - values ranging from 0 to 5.
- /// </summary>
- public int Hold
- {
- get => hold;
- set
- {
- if (value != hold)
- {
- hold = value;
- RaisePropertyChanged();
- }
- }
- }
-
- /// <summary>
- /// Gets title.
- /// </summary>
- public string Title { get; private set; } = "ScanningView";
-
- /// <summary>
- /// Gets the <see cref="SquatService"/> property.
- /// </summary>
- public IExerciseService SquatService { get; private set; }
-
- /// <summary>
- /// Gets EndWorkout Command.
- /// </summary>
- public ICommand CloseScanningView { get; private set; }
-
- private void SquatService_ExerciseStateUpdated(object sender, ExerciseStateUpdatedEventArgs e)
- {
- PoseLandmarks = e.PoseLandmarks;
- Score = e.Score;
- Count = e.Count;
- Hold = e.Hold;
- }
- }
-}
+++ /dev/null
-using Tizen.Multimedia;
-
-namespace Fitness.Views
-{
- /// <summary>
- /// The page to adjust body.
- /// </summary>
- public partial class ScanningView : Fitness.Controls.Page
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="ScanningView"/> class.
- /// </summary>
- public ScanningView()
- {
- InitializeComponent();
- cameraView.Preview += DetectPreview;
- }
-
- /// <summary>
- /// OnDisappearing.
- /// </summary>
- protected override void OnDisappearing()
- {
- if (cameraView?.PreviewState == Tizen.Multimedia.CameraState.Preview)
- {
- cameraView.Preview -= DetectPreview;
- cameraView.StopPreview();
- }
- }
-
- private void DetectPreview(object sender, PreviewEventArgs e)
- {
- if (BindingContext is ViewModels.ScanningViewModel viewModel)
- {
- _ = viewModel.SquatService.DetectExercise(e.Preview);
- }
- }
- }
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<ctrl:Page x:Class="Fitness.Views.ScanningView"
- xmlns="http://tizen.org/Tizen.NUI/2018/XAML"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:vm="clr-namespace:Fitness.ViewModels"
- xmlns:ctrl="clr-namespace:Fitness.Controls"
- xmlns:views="clr-namespace:Fitness.Views"
- xmlns:behaviors="clr-namespace:Fitness.Views.Behaviors"
- HeightSpecification="{Static LayoutParamPolicies.MatchParent}"
- WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
- BackgroundColor="#EEEFF1"
- ParentOrigin="Center"
- PivotPoint="Center"
- PositionUsesPivotPoint="true"
- x:Name="Root">
-
- <View.BindingContext>
- <vm:ScanningViewModel/>
- </View.BindingContext>
-
- <View Position="320, 100"
- Size="1280, 960">
-
- <ctrl:Camera x:Name="cameraView"
- WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
- HeightSpecification="{Static LayoutParamPolicies.MatchParent}"
- PreviewFps="Fps30"/>
-
- <ctrl:Overlay WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
- HeightSpecification="{Static LayoutParamPolicies.MatchParent}"
- BindingContext="{Binding Source={x:Reference Root}, Path=BindingContext}"
- PoseLandmarks="{Binding PoseLandmarks}">
- <x:Arguments>
- <Size2D>1280, 960</Size2D>
- </x:Arguments>
- </ctrl:Overlay>
-
- </View>
-
- <View WidthSpecification="{Static LayoutParamPolicies.MatchParent}">
-
- <View.Layout>
- <LinearLayout LinearOrientation="Horizontal"/>
- </View.Layout>
-
- <View WidthSpecification="{Static LayoutParamPolicies.MatchParent}">
-
- <View.Layout>
- <LinearLayout LinearOrientation="Vertical"/>
- </View.Layout>
-
- <TextLabel BindingContext="{Binding Source={x:Reference Root}, Path=BindingContext}"
- Text="{Binding Hold, StringFormat='Hold: {0}'}"
- PixelSize="40"
- TextColor="Black" />
- <TextLabel BindingContext="{Binding Source={x:Reference Root}, Path=BindingContext}"
- Text="{Binding Count, StringFormat='Count: {0}'}"
- PixelSize="40"
- TextColor="Black" />
- <TextLabel BindingContext="{Binding Source={x:Reference Root}, Path=BindingContext}"
- Text="{Binding Score, StringFormat='Score: {0}'}"
- PixelSize="40"
- TextColor="Black"/>
-
- </View>
-
- <ctrl:NinePatchButton BindingContext="{Binding Source={x:Reference Root}, Path=BindingContext}"
- WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
- Text="Close"
- Size="{views:SizeInUnits Width=80, Height=20}"
- PointSize="6"
- Command="{Binding CloseScanningView}"/>
-
- </View>
-
-</ctrl:Page>