Skip to content

Commit

Permalink
Merge pull request #12 from AathifMahir/Command
Browse files Browse the repository at this point in the history
Command Support
AathifMahir authored Jun 3, 2023
2 parents e77ac90 + 50a0c81 commit d8dd8c4
Showing 6 changed files with 33 additions and 9 deletions.
12 changes: 11 additions & 1 deletion src/MauiShakeDetector/IShakeDetector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MauiShakeDetector;
using System.Windows.Input;

namespace MauiShakeDetector;
public interface IShakeDetector
{

@@ -67,6 +69,14 @@ public interface IShakeDetector
event EventHandler<ShakeDetectedEventArgs>? ShakeDetected;
#nullable disable

/// <summary>
/// Shake Detected Command for detecting whether user shook the device
/// </summary>
/// <remarks>
/// Shake Detected Command will return int value of number of shakes detected as CommandParameter
/// </remarks>
ICommand ShakeDetectedCommand { get; set; }

/// <summary>
/// Start listening for shake event
/// </summary>
6 changes: 3 additions & 3 deletions src/MauiShakeDetector/MauiShakeDetector.csproj
Original file line number Diff line number Diff line change
@@ -37,9 +37,9 @@
<Description>Maui Shake Detector Shake Event Detector Library with Lots of Customization like GForce Tuning, Shake Intervals and Haptics for Shake Events</Description>
<PackageIcon>icon.png</PackageIcon>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<AssemblyFileVersion>0.3.0.0</AssemblyFileVersion>
<Version>0.3.0</Version>
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<AssemblyFileVersion>0.4.0.0</AssemblyFileVersion>
<Version>0.4.0</Version>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>Maui,Shake,ShakeDetector,MauiShake,</PackageTags>
5 changes: 4 additions & 1 deletion src/MauiShakeDetector/ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
v0.3.0
v0.4.0
• Added Command Support

v0.3.0
• Added .Net 6 Support

v0.2.0
5 changes: 4 additions & 1 deletion src/MauiShakeDetector/ShakeDetector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MauiShakeDetector;
using System.Windows.Input;

namespace MauiShakeDetector;
public static class ShakeDetector
{
public static bool IsSupported => Default.IsSupported;
@@ -17,6 +19,7 @@ public static event EventHandler<ShakeDetectedEventArgs> ShakeDetected
add => Default.ShakeDetected += value;
remove => Default.ShakeDetected -= value;
}
public static ICommand ShakeDetectedCommand => Default.ShakeDetectedCommand;

public static void StartListening(SensorSpeed sensorSpeed) => Default.StartListening(sensorSpeed);

11 changes: 9 additions & 2 deletions src/MauiShakeDetector/ShakeDetectorDefault.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MauiShakeDetector;
using System.Windows.Input;

namespace MauiShakeDetector;
internal sealed class ShakeDetectorDefault : IShakeDetector
{
// Properties
@@ -25,6 +27,7 @@ internal sealed class ShakeDetectorDefault : IShakeDetector
// Event Handlers

public event EventHandler<ShakeDetectedEventArgs> ShakeDetected;
public ICommand ShakeDetectedCommand { get; set; }

public void StartListening(SensorSpeed sensorSpeed = SensorSpeed.Default)
{
@@ -73,13 +76,17 @@ private void Accelerometer_ReadingChanged(object sender, AccelerometerChangedEve
}

currentTriggeredShakesCount++;

ShakeDetected?.Invoke(this, new ShakeDetectedEventArgs(currentShakeCount));
if (ShakeDetectedCommand is not null && ShakeDetectedCommand.CanExecute(currentShakeCount))
ShakeDetectedCommand.Execute(currentShakeCount);

AutoStopAfterNoShakeEvents();
}

private void AutoStopAfterNoShakeEvents()
{
if(AutoStopAfterNoShakes != 0 && currentTriggeredShakesCount >= AutoStopAfterNoShakes)
if(AutoStopAfterNoShakes is not 0 && currentTriggeredShakesCount >= AutoStopAfterNoShakes)
{
currentTriggeredShakesCount = 0;
StopListening();
3 changes: 2 additions & 1 deletion src/MauiShakeDetector/readme.md
Original file line number Diff line number Diff line change
@@ -78,7 +78,8 @@ using MauiShakeDetector;
| **MinimumShakeCount** | `int` | Get or Set the Value for Number of Shakes Required Before Shake is Triggered |
| **AutoStopAfterNoShakes** | `int` | Gets or sets the value of Auto Stop listening to shake event after number of shakes triggered |
| **HapticsDurationInMilliseconds** | `TimeSpan` | Get or Set the Value Of Haptics Duration |
| **ShakeDetected** | `event` | Shake Detected Event for Detecting Whether User Shaked the Device |
| **ShakeDetectedCommand** | `ICommand` | Shake Detected Command for Detecting Whether User Shooked the Device |
| **ShakeDetected** | `event` | Shake Detected Event for Detecting Whether User Shooked the Device |
| **StartListening()** | `method` | Start listening for Shake Event |
| **SensorSpeed** | `enum` | Set the value for Shake Detection Speed When Using Start Listning Method |
| **StopListening()** | `method` | Stop Already Monitoring Shake Event |

0 comments on commit d8dd8c4

Please sign in to comment.