Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Shake Stopped #16

Closed
Zulqurnain opened this issue Dec 15, 2016 · 3 comments
Closed

Detect Shake Stopped #16

Zulqurnain opened this issue Dec 15, 2016 · 3 comments

Comments

@Zulqurnain
Copy link

How to detect shake is stopped ?

@nisrulz
Copy link
Owner

nisrulz commented Dec 15, 2016

Can you be a bit clear in what exactly you want done ?

Just so you know its a single event that a shake is detected, and not that a shake has started and stopped. Such events can occur as multiple shakes detected but it is not detected as a stream of when a shake was started and when it was stopped. That is so because the detection works of by calculating the diff in acceleration and deceleration that happens and compares it for a threshold value.

https://github.com/nisrulz/sensey/blob/develop/sensey/src/main/java/com/github/nisrulz/sensey/ShakeDetector.java#L59-L72

@Zulqurnain
Copy link
Author

in my case i'm doing something in my app , as long as user keep shaking its phone , but when it stop's it must revert back all operation what were done while shaking , now i understand how that , i propose there should be onShakStop function too in the interface which can detect the continues shaking have been stopped ??

And i hope it is not that difficult:

@Override
  protected void onSensorEvent(SensorEvent sensorEvent) {
    // Shake detection
    float x = sensorEvent.values[0];
    float y = sensorEvent.values[1];
    float z = sensorEvent.values[2];
    float mAccelLast = mAccelCurrent;
    mAccelCurrent = (float) Math.sqrt(x * x + y * y + z * z);
    float delta = mAccelCurrent - mAccelLast;
    mAccel = mAccel * 0.9f + delta;
    // Make this higher or lower according to how much
    // motion you want to detect
    if (mAccel > threshold) {
      shakeListener.onShakeDetected();
    }else{
      // shaking is stopped do something about it ???
   }
  }

nisrulz added a commit that referenced this issue Feb 12, 2017
- allow to detect shake stopped with ability to define when to declare that shake event is stopped
@nisrulz
Copy link
Owner

nisrulz commented Feb 13, 2017

@Zulqurnain the latest release(1.6.0) the option to detect when shake gesture is stopped.

Closing as fixed.

@nisrulz nisrulz closed this as completed Feb 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants