Home

Awesome

<img src="https://github.com/AathifMahir/MauiShakeDetector/blob/master/images/icon_with_text.png" alt="MauiIcons_logo" height=200 width=450>
Latest StableLatest Preview
AathifMahir.Maui.MauiShakeDetectorAathifMahir.Maui.MauiShakeDetector

.Net Maui Shake Detector

Maui Shake Detector is Shake Event Detector Library Which Detects Shake Event from Android, iOS and etc. with Options to Customize the Shake Gforce and Shake Intervals and Haptics and Haptics Duration and etc.

Permission

In order to use Maui Shake Detector, You need Specific permission for Android

Android

Add the assembly-based permission:

Open the Platforms/Android/MainApplication.cs file and add the following assembly attributes after using directives:

C#


[assembly: UsesPermission(Android.Manifest.Permission.Vibrate)]

Update the Android Manifest:

Open the Platforms/Android/AndroidManifest.xml file and add the following in the manifest node:


<uses-permission android:name="android.permission.VIBRATE" />

Get Started

using MauiShakeDetector;

    // Start
    private void BtnStartListening_Clicked(object sender, EventArgs e)
    {
        if (ShakeDetector.Default.IsSupported && !ShakeDetector.Default.IsMonitoring)
        {
            ShakeDetector.Default.StartListening();
            ShakeDetector.Default.ShakeDetected += Detector_ShakeDetected;
            return;
        }
    }

    // Stop
    private void BtnStopListening_Clicked(object sender, EventArgs e)
    {
        if (ShakeDetector.Default.IsMonitoring)
        {
            ShakeDetector.Default.StopListening();
            ShakeDetector.Default.ShakeDetected -= Detector_ShakeDetected;
        }
    }

    private void Detector_ShakeDetected(object sender, ShakeDetectedEventArgs e)
    {
        Debug.Writeline($"No of Shakes : {e.NoOfShakes}");
    }

Parameters

ParametersTypeDescription
IsSupportedboolIndicating Whether ShakeDetector is Supported on this Device
IsMonitoringboolIndicating Whether ShakeDetector is Already Monitoring
IsHapticsSupportedboolIndicating Whether Haptics Supported in this Device
IsHapticsEnabledboolGet or Set the Value Indicating Whether Haptics is Enabled
ShakeThresholdGravitydoubleGet or Set the Value of Shake Detection Threshold
ShakeIntervalInMillisecondsTimeSpanGet or Set the value of Minimum Delay betweem Shakes
ShakeResetIntervalInMillisecondsTimeSpanGet or Set the Value of Shake Reset Interval in Milliseconds
MinimumShakeCountintGet or Set the Value for Number of Shakes Required Before Shake is Triggered
AutoStopAfterNoShakesintGets or sets the value of Auto Stop listening to shake event after number of shakes triggered, Minimum is 1
HapticsDurationInMillisecondsTimeSpanGet or Set the Value Of Haptics Duration
ShakeDetectedCommandICommandShake Detected Command for Detecting Whether User Shooked the Device
ShakeDetectedeventShake Detected Event for Detecting Whether User Shaked the Device
ShakeStoppedCommandICommandShake Stopped Command for Detecting Whether Shake Detector is Stopped When Auto Stop is more than 0
ShakeStoppedeventShake Stopped Event for Detecting Whether Shake Detector is Stopped When Auto Stop is more than 0
StartListening()methodStart listening for Shake Event
SensorSpeedenumSet the value for Shake Detection Speed When Using Start Listning Method
StopListening()methodStop Already Monitoring Shake Event

License

Maui Shake Detector is Licensed Under MIT License.

Contribute

If you wish to contribute to this project, please don't hesitate to create an issue or request. Your input and feedback are highly appreciated. Additionally, if you're interested in supporting the project by providing resources or becoming a sponsor, your contributions would be welcomed and instrumental in its continued development and success. Thank you for your interest in contributing to this endeavor.