public IndividualMinuteTestPage(UserResult userResult, TestType testType)
        {
            InitializeComponent();
            var relativeLayout = new RelativeLayout();

            var timerIsRunning = false;

            var startDate = new DateTime();

            var button = new Button
            {
                Text            = "Начать тест",
                TextColor       = Color.White,
                BackgroundColor = Color.Red
            };

            button.Clicked += (a, b) =>
            {
                if (!timerIsRunning)
                {
                    button.Text            = "Стоп";
                    button.BackgroundColor = Color.Blue;
                    startDate      = DateTime.Now;
                    timerIsRunning = true;
                }
                else
                {
                    var resultTime = DateTime.Now - startDate;
                    Navigation.PushAsync(new ResultPage(resultTime, userResult, testType));
                }
            };

            relativeLayout.Children.Add(
                button,
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Height * 0.75),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height * 0.25)
                );

            Content = relativeLayout;
        }
Example #2
0
        public MainPage()
        {
            InitializeComponent();

            var userResult  = new UserResult();
            var stackLayout = new StackLayout();
            var buttons     = TestTypes.Select(t => new Button
            {
                Text    = TestNames[(int)t],
                Command = new Command(() => Navigation.PushAsync(new TestPreviewPage(t, userResult)))
            });


            foreach (var button in buttons)
            {
                stackLayout.Children.Add(button);
            }

            stackLayout.Children.Add(
                new Button
            {
                Text    = "Сохранить результат",
                Command = new Command(() => Navigation.PushAsync(new SavePage(userResult)))
            });

            stackLayout.Children.Add(
                new Button
            {
                Text    = "Показать результаты",
                Command = new Command(() => Navigation.PushAsync(new ShowAllResultsPage()))
            });



            Content = new ScrollView
            {
                Content = stackLayout
            };
        }
Example #3
0
        public Test1Page(TestType testType, UserResult userResult)
        {
            InitializeComponent();
            var       button          = new Button();
            var       random          = new Random();
            const int countOfTests    = 5;
            var       results         = new List <TimeSpan>();
            var       countOfMistakes = 0;

            Action startEvent;
            Action cancelEvent;

            var layout = new RelativeLayout();

            layout.Children.Add(
                button,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height)
                );

            if (testType == TestType.Color)
            {
                startEvent  = () => button.BackgroundColor = Color.Red;
                cancelEvent = () => button.BackgroundColor = Color.White;
            }
            else if (testType == TestType.Sound)
            {
                player = new MediaPlayer();
                player.Reset();

                var assetFileDescriptor = Android.App.Application.Context.Assets.OpenFd("sound.mp3");
                player.SetDataSource(assetFileDescriptor);
                player.Looping = true;
                player.Prepare();

                startEvent  = () => player.Start();
                cancelEvent = () => player.Pause();
            }
            else
            {
                var redBox = new BoxView
                {
                    BackgroundColor = Color.Red
                };

                startEvent = () => layout.Children.Add(
                    redBox,
                    Constraint.RelativeToParent((parent) => random.Next(30, (int)parent.Width - 30)),
                    Constraint.RelativeToParent((parent) => random.Next(30, (int)parent.Height - 30)),
                    Constraint.Constant(30),
                    Constraint.Constant(30)
                    );

                cancelEvent = () => layout.Children.Remove(redBox);
            }

            var task = this.startEvent(startEvent, random.Next(2000, 5000));

            button.Clicked += (sender, args) =>
            {
                if (task.IsCompleted)
                {
                    cancelEvent();
                    results.Add(DateTime.Now - task.Result);
                    if (results.Count == countOfTests)
                    {
                        player?.Stop();
                        player?.Release();
                        Navigation.PushAsync(new ResultPage(results, countOfMistakes, userResult, testType));
                    }
                    else
                    {
                        task = this.startEvent(startEvent, random.Next(2000, 5000));
                    }
                }
                else
                {
                    countOfMistakes++;
                }
            };
            Content = layout;
        }
        public Test2Page(TestType testType, UserResult userResult)
        {
            InitializeComponent();

            this.userResult = userResult;

            this.testType = testType;

            var random       = new Random();
            var currentState = 0;
            var layout       = new RelativeLayout();

            var parentLayout = new RelativeLayout();

            Action testEvent;

            if (testType == TestType.ColorPoint)
            {
                var points = new[]
                {
                    new BoxView
                    {
                        BackgroundColor = Color.Red
                    },
                    new BoxView
                    {
                        BackgroundColor = Color.Blue
                    }
                };

                testEvent = () =>
                {
                    currentState = random.Next(0, 2);
                    layout.Children.Clear();
                    layout.Children.Add(
                        points[currentState],
                        Constraint.RelativeToParent((parent) => random.Next(30, (int)parent.Width - 30)),
                        Constraint.RelativeToParent((parent) => random.Next(30, (int)parent.Height - 30)),
                        Constraint.Constant(30),
                        Constraint.Constant(30)
                        );
                };
            }
            else
            {
                var label = new Label
                {
                    VerticalOptions         = LayoutOptions.Center,
                    HorizontalOptions       = LayoutOptions.Center,
                    FontSize                = 75.0,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Center
                };

                layout.Children.Add(
                    label,
                    Constraint.Constant(0),
                    Constraint.Constant(0),
                    Constraint.RelativeToParent((parent) => parent.Width),
                    Constraint.RelativeToParent((parent) => parent.Height)
                    );

                testEvent = () =>
                {
                    var number = random.Next(0, 100);
                    label.Text   = number.ToString();
                    currentState = (number + 1) % 2;
                };
            }



            var button1 = new Button
            {
                Text = "1",
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            var button2 = new Button
            {
                Text = "2",
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            var buttonStack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    button1,
                    button2
                }
            };

            parentLayout.Children.Add(
                layout,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height * 0.75)
                );


            parentLayout.Children.Add(
                buttonStack,
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Height * 0.75),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height * 0.25)
                );

            Content = parentLayout;


            delayAction(() =>
            {
                lastDate         = startEvent(testEvent);
                button1.Clicked += (k, args) => onButtonCommand(0, currentState, testEvent);
                button2.Clicked += (k, args) => onButtonCommand(1, currentState, testEvent);
            }
                        );
        }
        public ShowAllResultsPage()
        {
            InitializeComponent();

            var stackLayout = new StackLayout
            {
                Spacing = 10
            };

            loadedResults = UserResult.Load();

            loadedResults.Reverse();



            var views = loadedResults
                        .Select(r => (result: r, view: new StackLayout()))
                        .Select((rv) =>
            {
                rv.view.Orientation = StackOrientation.Horizontal;
                rv.view.Children.Add(rv.result.GetView());
                rv.view.Children.Add(new Button
                {
                    Text              = "✕",
                    VerticalOptions   = LayoutOptions.Start,
                    HorizontalOptions = LayoutOptions.Start,
                    Command           = new Command(() =>
                    {
                        stackLayout.Children.Remove(rv.view);
                        loadedResults.Remove(rv.result);
                        UserResult.Upload(loadedResults);
                    })
                });
                return(rv.view);
            });

            stackLayout = new StackLayout();

            stackLayout.Spacing = 6;

            foreach (var view in views)
            {
                stackLayout.Children.Add(view);
            }

            var parentStackLayout = new StackLayout
            {
                Children =
                {
                    new ScrollView
                    {
                        Content = stackLayout
                    },
                    new Button
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions   = LayoutOptions.End,
                        Text    = "Экспортировать в Excel",
                        Command = new Command(() =>
                        {
                            ConvertCsvToExcel(Data.ExportPath, "1", Data.ResultPath);
                            //UserResult.Upload(loadedResults, Data.ExportPath);
                        })
                    },
                    new Button
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions   = LayoutOptions.End,
                        Text    = "Очистить все",
                        Command = new Command(() =>
                        {
                            stackLayout.Children.Clear();
                            UserResult.Upload(new List <UserResult>());
                        })
                    }
                }
            };


            Content = parentStackLayout;
        }
Example #6
0
        public ArrowPage(Arrow correctArrow, UserResult userResult, TestType testType)
        {
            InitializeComponent();
            var countOfCorrect  = 0;
            var countOfMistakes = 0;
            var layout          = new RelativeLayout();
            var grid            = new Grid();

            var gridWidth  = 8;
            var gridHeight = 8;

            var countOfArrows = gridWidth * gridHeight;



            for (int i = 0; i < gridWidth; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
            }

            for (int i = 0; i < gridHeight; i++)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }

            var random = new Random();

            var views = Enumerable.Range(0, 4)
                        .SelectMany(a => Enumerable.Range(0, countOfArrows / 4).Select(r => a))
                        .OrderBy(a => random.Next())
                        .Select(a =>
                                new Button
            {
                Text     = Arrows[a],
                FontSize = 30.0
            }
                                )
                        .Select((b, ind) => (view: b, left: ind % gridWidth, top: ind / gridHeight));

            foreach (var view in views)
            {
                view.view.Clicked += (a, b) =>
                {
                    if (view.view.Text == Arrows[(int)correctArrow])
                    {
                        countOfCorrect++;
                    }
                    else
                    {
                        if (view.view.Text != Arrows[(int)Arrow.None])
                        {
                            countOfMistakes++;
                        }
                        //else
                    }
                    view.view.Text = Arrows[(int)Arrow.None];
                };
                grid.Children.Add(view.view, view.left, view.top);
            }

            layout.Children.Add(
                grid,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height * 0.75)
                );

            var startTime = DateTime.Now;

            layout.Children.Add(
                new Button
            {
                Text    = "Закончить",
                Command = new Command(() => Navigation.PushAsync(
                                          new ResultPage(countOfCorrect, countOfMistakes, countOfArrows, DateTime.Now - startTime, userResult, testType)
                                          )
                                      )
            },
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Height * 0.75),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height * 0.25)
                );
            Content = layout;
        }