diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-04-23 16:13:41 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-04-23 16:13:41 +0300 |
| commit | ba4aec4c691476d68b3da383a70bff42341c7171 (patch) | |
| tree | cff1ec9b2b4c6bc09ceb4d2a7a64f8cf1e6a8fc0 /Software/Visual_Studio/PPC/Tango.PPC.UI | |
| parent | 2c48f9ef5ee4978f531e18d0c5945f33705bfe46 (diff) | |
| download | Tango-ba4aec4c691476d68b3da383a70bff42341c7171.tar.gz Tango-ba4aec4c691476d68b3da383a70bff42341c7171.zip | |
Implemented screen lock for PPC.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI')
9 files changed, 194 insertions, 3 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ScreenLockView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ScreenLockView.xaml new file mode 100644 index 000000000..8a90b03a0 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ScreenLockView.xaml @@ -0,0 +1,30 @@ +<UserControl x:Class="Tango.PPC.UI.Dialogs.ScreenLockView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:Tango.PPC.UI.Dialogs" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + Background="{StaticResource TangoPrimaryBackgroundBrush}" d:DesignHeight="555" d:DesignWidth="560" Width="600" Height="250" d:DataContext="{d:DesignInstance Type=local:ScreenLockViewVM, IsDesignTimeCreatable=False}"> + + <UserControl.InputBindings> + <KeyBinding Key="Return" Command="{Binding OKCommand}"></KeyBinding> + </UserControl.InputBindings> + <Grid Margin="10"> + <DockPanel> + <StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Orientation="Horizontal"> + <touch:TouchButton Command="{Binding CloseCommand}" Style="{StaticResource TangoMessageBoxButton}" DockPanel.Dock="Right" Width="120" Height="50" VerticalAlignment="Bottom">CANCEL</touch:TouchButton> + <touch:TouchButton Command="{Binding OKCommand}" Style="{StaticResource TangoMessageBoxButton}" DockPanel.Dock="Right" Width="120" Height="50" VerticalAlignment="Bottom">OK</touch:TouchButton> + </StackPanel> + <DockPanel> + <touch:TouchIcon Foreground="{StaticResource TangoErrorBrush}" Icon="Lock" VerticalAlignment="Top" Height="70"></touch:TouchIcon> + <StackPanel Margin="10 0 0 0"> + <TextBlock FontSize="{StaticResource TangoHeaderFontSize}">Screen Locked</TextBlock> + <TextBlock Margin="0 10 0 0" TextWrapping="Wrap">Please enter the password to unlock the screen.</TextBlock> + <touch:TouchTextBox x:Name="txtPassword" Margin="0 30 40 0" IsPassword="True" KeyboardAction="Go" Text="{Binding Password,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /> + </StackPanel> + </DockPanel> + </DockPanel> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ScreenLockView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ScreenLockView.xaml.cs new file mode 100644 index 000000000..4a28984e6 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ScreenLockView.xaml.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.UI.Dialogs +{ + /// <summary> + /// Interaction logic for TechnicianModeLoginView.xaml + /// </summary> + public partial class ScreenLockView : UserControl + { + public ScreenLockView() + { + InitializeComponent(); + + Loaded += ScreenLockView_Loaded; + } + + private async void ScreenLockView_Loaded(object sender, RoutedEventArgs e) + { + await Task.Delay(200); + txtPassword.Focus(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ScreenLockViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ScreenLockViewVM.cs new file mode 100644 index 000000000..e19117621 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ScreenLockViewVM.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.SharedUI; + +namespace Tango.PPC.UI.Dialogs +{ + public class ScreenLockViewVM : DialogViewVM + { + private String _password; + public String Password + { + get { return _password; } + set { _password = value; RaisePropertyChangedAuto(); } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/TechnicianModeLoginView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/TechnicianModeLoginView.xaml index ca53d6027..24a5416ba 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/TechnicianModeLoginView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/TechnicianModeLoginView.xaml @@ -7,6 +7,11 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" Background="{StaticResource TangoPrimaryBackgroundBrush}" d:DesignHeight="555" d:DesignWidth="560" Width="600" Height="250" d:DataContext="{d:DesignInstance Type=local:TechnicianModeLoginViewVM, IsDesignTimeCreatable=False}"> + + <UserControl.InputBindings> + <KeyBinding Key="Return" Command="{Binding OKCommand}"></KeyBinding> + </UserControl.InputBindings> + <Grid Margin="10"> <DockPanel> <StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Orientation="Horizontal"> @@ -18,7 +23,7 @@ <StackPanel Margin="10 0 0 0"> <TextBlock FontSize="{StaticResource TangoHeaderFontSize}">Technician Mode</TextBlock> <TextBlock Margin="0 10 0 0" TextWrapping="Wrap">Please enter the technician mode password.</TextBlock> - <touch:TouchTextBox Margin="0 30 40 0" IsPassword="True" Text="{Binding Password,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /> + <touch:TouchTextBox x:Name="txtPassword" KeyboardAction="Go" Margin="0 30 40 0" IsPassword="True" Text="{Binding Password,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /> </StackPanel> </DockPanel> </DockPanel> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/TechnicianModeLoginView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/TechnicianModeLoginView.xaml.cs index 02dfed896..3a809b6f3 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/TechnicianModeLoginView.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/TechnicianModeLoginView.xaml.cs @@ -23,6 +23,14 @@ namespace Tango.PPC.UI.Dialogs public TechnicianModeLoginView() { InitializeComponent(); + + Loaded += TechnicianModeLoginView_Loaded; + } + + private async void TechnicianModeLoginView_Loaded(object sender, RoutedEventArgs e) + { + await Task.Delay(200); + txtPassword.Focus(); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index ba1b44c8a..1550e97e1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -29,6 +29,8 @@ using Tango.BL.Enumerations; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.WatchDog; using Tango.PPC.UI.Dialogs; +using Tango.Core.Threading; +using Tango.PPC.Common.Messages; namespace Tango.PPC.UI.PPCApplication { @@ -48,6 +50,7 @@ namespace Tango.PPC.UI.PPCApplication private INotificationProvider _notificationProvider; private WatchDogServer _watchdogServer; private ObservablesContext _machineContext; + private ActionTimer _screenLockTimer; /// <summary> /// Occurs when a system restart is required. @@ -116,6 +119,16 @@ namespace Tango.PPC.UI.PPCApplication } } + private bool _isScreenLocked; + /// <summary> + /// Gets or sets a value indicating whether the screen is currently locked. + /// </summary> + public bool IsScreenLocked + { + get { return _isScreenLocked; } + set { _isScreenLocked = value; RaisePropertyChangedAuto(); } + } + /// <summary> /// Initializes a new instance of the <see cref="DefaultPPCApplicationManager"/> class. /// </summary> @@ -306,6 +319,8 @@ namespace Tango.PPC.UI.PPCApplication /// </summary> private void FinalizeModuleInitialization() { + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + LogManager.Log("Finalizing application initialization..."); LogManager.Log("Initializing Machine Provider..."); @@ -336,10 +351,30 @@ namespace Tango.PPC.UI.PPCApplication vm.OnApplicationReady(); } - if (SettingsManager.Default.GetOrCreate<PPCSettings>().EnableTechnicianModeByDefault) + if (settings.EnableTechnicianModeByDefault) { EnterTechnicianMode(false); } + + if (settings.EnableLockScreen) + { + _screenLockTimer = new ActionTimer(settings.LockScreenTimeout); + _screenLockTimer.ResetReplace(ScreenLockTimerAction); + } + + TangoMessenger.Default.Register<MachineSettingsSavedMessage>((msg) => + { + if (_screenLockTimer != null) + { + _screenLockTimer.Dispose(); + } + + if (settings.EnableLockScreen) + { + _screenLockTimer = new ActionTimer(settings.LockScreenTimeout); + _screenLockTimer.ResetReplace(ScreenLockTimerAction); + } + }); }); } @@ -460,5 +495,38 @@ namespace Tango.PPC.UI.PPCApplication _moduleLoader.AllModules.ToList().ForEach(x => x.OnTechnicianExited()); _notificationProvider.ShowInfo("Technician mode is now disabled."); } + + /// <summary> + /// Invokes a dialog for entering a password and releasing the screen lock. + /// </summary> + public async void ReleaseScreenLock() + { + if (IsScreenLocked) + { + var vm = await _notificationProvider.ShowDialog<ScreenLockViewVM>(); + + if (vm.DialogResult) + { + if (vm.Password == SettingsManager.Default.GetOrCreate<PPCSettings>().LockScreenPassword) + { + IsScreenLocked = false; + ResetScreenLockTimer(); + } + } + } + } + + public void ResetScreenLockTimer() + { + if (_screenLockTimer != null) + { + _screenLockTimer.ResetReplace(ScreenLockTimerAction); + } + } + + private void ScreenLockTimerAction() + { + IsScreenLocked = true; + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 22ecff0f6..71fa82504 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -122,9 +122,13 @@ <Compile Include="Connectivity\WiFiAuthenticationViewVM.cs" /> <Compile Include="Converters\AppBarItemConverter.cs" /> <Compile Include="Converters\ItemBaseConverter.cs" /> + <Compile Include="Dialogs\ScreenLockView.xaml.cs"> + <DependentUpon>ScreenLockView.xaml</DependentUpon> + </Compile> <Compile Include="Dialogs\TechnicianModeLoginView.xaml.cs"> <DependentUpon>TechnicianModeLoginView.xaml</DependentUpon> </Compile> + <Compile Include="Dialogs\ScreenLockViewVM.cs" /> <Compile Include="Dialogs\TechnicianModeLoginViewVM.cs" /> <Compile Include="Dialogs\UpdateFromFileView.xaml.cs"> <DependentUpon>UpdateFromFileView.xaml</DependentUpon> @@ -186,6 +190,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Dialogs\ScreenLockView.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="Dialogs\TechnicianModeLoginView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -526,7 +534,7 @@ del "$(TargetDir)firmware_package.tfp"</PostBuildEvent> </PropertyGroup> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index 768fce222..6e820ab64 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -279,7 +279,12 @@ <!--MODULES GOES HERE--> </controls:NavigationControl> </Grid> + </DockPanel> </touch:TouchSideMenu> + + <Grid PreviewMouseUp="Grid_PreviewMouseUp" IsHitTestVisible="True" Background="Transparent" Visibility="{Binding ApplicationManager.IsScreenLocked,Converter={StaticResource BooleanToVisibilityConverter}}"> + <touch:TouchIcon HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="40" Icon="Lock" Width="60" Height="60" Opacity="0.5" Foreground="{StaticResource TangoSuccessBrush}" /> + </Grid> </Grid> </UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs index 777083b67..883d3f893 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs @@ -42,6 +42,13 @@ namespace Tango.PPC.UI.Views _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromSeconds(10); _timer.Tick += _timer_Tick; + + this.PreviewMouseUp += LayoutView_PreviewMouseUp; + } + + private void LayoutView_PreviewMouseUp(object sender, MouseButtonEventArgs e) + { + _vm.ApplicationManager.ResetScreenLockTimer(); } private void _timer_Tick(object sender, EventArgs e) @@ -77,5 +84,10 @@ namespace Tango.PPC.UI.Views _timer.Stop(); } + + private void Grid_PreviewMouseUp(object sender, MouseButtonEventArgs e) + { + _vm.ApplicationManager.ReleaseScreenLock(); + } } } |
