Add project files.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace SafeBagDE70.Services
|
||||
{
|
||||
public static class SoundManager
|
||||
{
|
||||
private static MediaPlayer _mediaPlayer = new MediaPlayer();
|
||||
private static Uri _audioFileUri;
|
||||
private static bool _isWarningActive = false;
|
||||
|
||||
private static MediaPlayer _pressPlayer = new MediaPlayer();
|
||||
private static Uri _audioPressFileUri;
|
||||
|
||||
|
||||
static SoundManager()
|
||||
{
|
||||
var audioFilePath = "assets/audio/alarm.mp3";
|
||||
_audioFileUri = new Uri(audioFilePath, UriKind.RelativeOrAbsolute);
|
||||
_mediaPlayer.MediaEnded += MediaPlayer_MediaEnded;
|
||||
|
||||
var audioPressPath = "assets/audio/buttonpress.mp3";
|
||||
_audioPressFileUri = new Uri(audioPressPath, UriKind.RelativeOrAbsolute);
|
||||
//_pressPlayer.MediaEnded += _pressPlayer_MediaEnded; ;
|
||||
}
|
||||
|
||||
private static void _pressPlayer_MediaEnded(object? sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
public static void StartButtonPressSound()
|
||||
{
|
||||
_pressPlayer.Open(_audioPressFileUri);
|
||||
_pressPlayer.Play();
|
||||
}
|
||||
|
||||
// Starts the continuous playback
|
||||
public static void StartWarningSound()
|
||||
{
|
||||
if (!_isWarningActive)
|
||||
{
|
||||
_isWarningActive = true;
|
||||
_mediaPlayer.Open(_audioFileUri);
|
||||
_mediaPlayer.Play();
|
||||
}
|
||||
}
|
||||
|
||||
// Stops the playback
|
||||
public static void StopWarningSound()
|
||||
{
|
||||
_mediaPlayer.Stop();
|
||||
_isWarningActive= false;
|
||||
}
|
||||
|
||||
// Handles the MediaEnded event to replay the audio
|
||||
private static void MediaPlayer_MediaEnded(object sender, EventArgs e)
|
||||
{
|
||||
if (_isWarningActive)
|
||||
{
|
||||
_mediaPlayer.Position = TimeSpan.Zero;
|
||||
_mediaPlayer.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using VirtualKeyboard.Wpf.Controls;
|
||||
using VirtualKeyboard.Wpf.ViewModels;
|
||||
using VirtualKeyboard.Wpf.Views;
|
||||
|
||||
namespace VirtualKeyboard.Wpf
|
||||
{
|
||||
public static class VKeyboard
|
||||
{
|
||||
private const string _keyboardValueName = "KeyboardValueContent";
|
||||
private const string _keyboardName = "KeyboardContent";
|
||||
|
||||
private static Type _hostType = typeof(DefaultKeyboardHost);
|
||||
|
||||
private static TaskCompletionSource<string> _tcs;
|
||||
private static Window _windowHost;
|
||||
|
||||
public static void Config(Type hostType)
|
||||
{
|
||||
if (hostType.IsSubclassOf(typeof(Window))) _hostType = hostType;
|
||||
else throw new ArgumentException();
|
||||
}
|
||||
|
||||
public static void Listen<T>(Expression<Func<T, string>> property) where T: UIElement
|
||||
{
|
||||
EventManager.RegisterClassHandler(typeof(T), UIElement.PreviewMouseLeftButtonDownEvent, (RoutedEventHandler)(async (s, e) =>
|
||||
{
|
||||
if (s is AdvancedTextBox) return;
|
||||
var memberSelectorExpression = property.Body as MemberExpression;
|
||||
if (memberSelectorExpression == null) return;
|
||||
var prop = memberSelectorExpression.Member as PropertyInfo;
|
||||
if (prop == null) return;
|
||||
var initValue = (string)prop.GetValue(s);
|
||||
var value = await OpenAsync(initValue);
|
||||
prop.SetValue(s, value, null);
|
||||
}));
|
||||
}
|
||||
|
||||
public static Task<string> OpenAsync(string initialValue = "")
|
||||
{
|
||||
if (_windowHost != null) throw new InvalidOperationException();
|
||||
|
||||
_tcs = new TaskCompletionSource<string>();
|
||||
_windowHost = (Window)Activator.CreateInstance(_hostType);
|
||||
_windowHost.DataContext = new VirtualKeyboardViewModel(initialValue);
|
||||
((ContentControl)_windowHost.FindName(_keyboardValueName)).Content = new KeyboardValueView();
|
||||
((ContentControl)_windowHost.FindName(_keyboardName)).Content = new VirtualKeyboardView();
|
||||
void handler(object s, CancelEventArgs a)
|
||||
{
|
||||
var result = GetResult();
|
||||
((Window)s).Closing -= handler;
|
||||
_windowHost = null;
|
||||
_tcs?.SetResult(result);
|
||||
_tcs = null;
|
||||
}
|
||||
|
||||
_windowHost.Closing += handler;
|
||||
|
||||
_windowHost.Owner = Application.Current.MainWindow;
|
||||
_windowHost.Show();
|
||||
return _tcs.Task;
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
if (_windowHost == null) throw new InvalidOperationException();
|
||||
|
||||
_windowHost.Close();
|
||||
}
|
||||
|
||||
private static string GetResult()
|
||||
{
|
||||
var viewModel = (VirtualKeyboardViewModel)_windowHost.DataContext;
|
||||
return viewModel.KeyboardText;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#pragma checksum "..\..\..\..\Views\VirtualKeyboardView.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "33137C6642651EA1C5BE552706AFA8ECFD505EF5"
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Controls.Ribbon;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Media.Effects;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Media.Media3D;
|
||||
using System.Windows.Media.TextFormatting;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Shell;
|
||||
using VirtualKeyboard.Wpf;
|
||||
|
||||
|
||||
namespace VirtualKeyboard.Wpf.Views {
|
||||
|
||||
|
||||
internal partial class VirtualKeyboardView : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector {
|
||||
|
||||
private bool _contentLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// InitializeComponent
|
||||
/// </summary>
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "8.0.7.0")]
|
||||
public void InitializeComponent() {
|
||||
if (_contentLoaded) {
|
||||
return;
|
||||
}
|
||||
_contentLoaded = true;
|
||||
System.Uri resourceLocater = new System.Uri("/VirtualKeyboard;component/views/virtualkeyboardview.xaml", System.UriKind.Relative);
|
||||
|
||||
#line 1 "..\..\..\..\Views\VirtualKeyboardView.xaml"
|
||||
System.Windows.Application.LoadComponent(this, resourceLocater);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
}
|
||||
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "8.0.7.0")]
|
||||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
||||
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
|
||||
this._contentLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user