From 42862918771a10afcd7665b003e1b7aadcc21565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Mon, 12 Apr 2021 19:59:58 +0200 Subject: [PATCH] SEBWIN-450: Added proctoring window for mobile UI. --- ...afeExamBrowser.UserInterface.Mobile.csproj | 7 + .../UserInterfaceFactory.cs | 3 +- .../Windows/ProctoringWindow.xaml | 8 ++ .../Windows/ProctoringWindow.xaml.cs | 125 ++++++++++++++++++ 4 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 SafeExamBrowser.UserInterface.Mobile/Windows/ProctoringWindow.xaml create mode 100644 SafeExamBrowser.UserInterface.Mobile/Windows/ProctoringWindow.xaml.cs diff --git a/SafeExamBrowser.UserInterface.Mobile/SafeExamBrowser.UserInterface.Mobile.csproj b/SafeExamBrowser.UserInterface.Mobile/SafeExamBrowser.UserInterface.Mobile.csproj index 44612cb6..bc75f551 100644 --- a/SafeExamBrowser.UserInterface.Mobile/SafeExamBrowser.UserInterface.Mobile.csproj +++ b/SafeExamBrowser.UserInterface.Mobile/SafeExamBrowser.UserInterface.Mobile.csproj @@ -172,6 +172,9 @@ Code + + ProctoringWindow.xaml + RuntimeWindow.xaml @@ -480,6 +483,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/SafeExamBrowser.UserInterface.Mobile/UserInterfaceFactory.cs b/SafeExamBrowser.UserInterface.Mobile/UserInterfaceFactory.cs index a35b36eb..72425f5c 100644 --- a/SafeExamBrowser.UserInterface.Mobile/UserInterfaceFactory.cs +++ b/SafeExamBrowser.UserInterface.Mobile/UserInterfaceFactory.cs @@ -165,8 +165,7 @@ namespace SafeExamBrowser.UserInterface.Mobile public IProctoringWindow CreateProctoringWindow(IProctoringControl control) { - // TODO - throw new System.NotImplementedException(); + return Application.Current.Dispatcher.Invoke(() => new ProctoringWindow(control)); } public IRuntimeWindow CreateRuntimeWindow(AppConfig appConfig) diff --git a/SafeExamBrowser.UserInterface.Mobile/Windows/ProctoringWindow.xaml b/SafeExamBrowser.UserInterface.Mobile/Windows/ProctoringWindow.xaml new file mode 100644 index 00000000..e37acd0c --- /dev/null +++ b/SafeExamBrowser.UserInterface.Mobile/Windows/ProctoringWindow.xaml @@ -0,0 +1,8 @@ + + diff --git a/SafeExamBrowser.UserInterface.Mobile/Windows/ProctoringWindow.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Windows/ProctoringWindow.xaml.cs new file mode 100644 index 00000000..cc58b86d --- /dev/null +++ b/SafeExamBrowser.UserInterface.Mobile/Windows/ProctoringWindow.xaml.cs @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2021 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using System.ComponentModel; +using System.Windows; +using SafeExamBrowser.UserInterface.Contracts.Proctoring; +using SafeExamBrowser.UserInterface.Contracts.Windows; +using SafeExamBrowser.UserInterface.Contracts.Windows.Events; +using SafeExamBrowser.UserInterface.Shared.Utilities; + +namespace SafeExamBrowser.UserInterface.Mobile.Windows +{ + public partial class ProctoringWindow : Window, IProctoringWindow + { + private WindowClosingEventHandler closing; + + event WindowClosingEventHandler IWindow.Closing + { + add { closing += value; } + remove { closing -= value; } + } + + public ProctoringWindow(IProctoringControl control) + { + InitializeComponent(); + InitializeWindow(control); + } + + public void BringToForeground() + { + Dispatcher.Invoke(() => + { + if (WindowState == WindowState.Minimized) + { + WindowState = WindowState.Normal; + } + + Activate(); + }); + } + + public new void Close() + { + Dispatcher.Invoke(() => + { + Closing -= ProctoringWindow_Closing; + closing?.Invoke(); + base.Close(); + }); + } + + public new void Hide() + { + Dispatcher.Invoke(base.Hide); + } + + public void SetTitle(string title) + { + Dispatcher.Invoke(() => Title = title ?? ""); + } + + public new void Show() + { + Dispatcher.Invoke(base.Show); + } + + public void Toggle() + { + Dispatcher.Invoke(() => + { + if (Visibility == Visibility.Visible) + { + base.Hide(); + } + else + { + base.Show(); + } + }); + } + + private void InitializeWindow(IProctoringControl control) + { + if (control is UIElement element) + { + Content = element; + control.FullScreenChanged += Control_FullScreenChanged; + } + + Closing += ProctoringWindow_Closing; + Loaded += ProctoringWindow_Loaded; + Top = SystemParameters.WorkArea.Height - Height - 15; + Left = SystemParameters.WorkArea.Width - Width - 20; + } + + private void Control_FullScreenChanged(bool fullScreen) + { + if (fullScreen) + { + WindowState = WindowState.Maximized; + WindowStyle = WindowStyle.None; + } + else + { + WindowState = WindowState.Normal; + WindowStyle = WindowStyle.ToolWindow; + } + } + + private void ProctoringWindow_Closing(object sender, CancelEventArgs e) + { + e.Cancel = true; + } + + private void ProctoringWindow_Loaded(object sender, RoutedEventArgs e) + { + this.HideCloseButton(); + } + } +}