Android device shake detection.

Last update: Aug 3, 2022

Seismic

Android device shake detection.

Download

Download the latest .jar or depend via Maven:

<dependency>
  <groupId>com.squareup</groupId>
  <artifactId>seismic</artifactId>
  <version>1.0.2</version>
</dependency>

or Gradle:

implementation 'com.squareup:seismic:1.0.2'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2012 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

GitHub

https://github.com/square/seismic
Comments
  • 1. Making sensor delay configurable

    As a new requirement in Android 12 and fixing https://github.com/square/seismic/issues/24.

    The change is just expose a new start method that exposes an int parameter to configure the sensor delay.

    Please, don't hesitate to ask me for changes if needed :)

    Reviewed by gmerinojimenez at 2021-07-27 13:28
  • 2. memory leak

    In my application I have a feature like Google Maps' shake to feedback so I initialized the seismic inside my BaseActivity and extend every Activity from that. This causes leaks, is there another way to have shake detection in every activity I have?

    Reviewed by egek92 at 2018-01-27 17:38
  • 3. Call hearShake() only once for each shake.

    Until now, shaking continuously for a long time (say, a second and a half) could cause hearShake() to be called several times. This change ensures that there is a period of immobility after the hearShake() call before the next shake can be recognized.

    Reviewed by arnt at 2015-01-26 17:11
  • 4. Avoid Math.sqrt() in ShakeDetector

    Given both magnitude and ACCELERATION_THRESHOLD are positive, the following are equivalent:

    magnitude > ACCELERATION_THRESHOLD
    
    magnitude * magnitude > ACCELERATION_THRESHOLD * ACCELERATION_THRESHOLD
    

    The second one is more efficient.

    Reviewed by mkonicek at 2014-12-11 16:06
  • 5. Permission HIGH_SAMPLING_RATE_SENSORS required when targeting Android 12

    On android 12 a new permission has been added when the sampling rate is set to 0 microseconds. Would be possible to have this value configurable? Are we able to detect the shake gesture with a sampling rate lower than 200 Hz?

    The issue that I'm getting right now when initializing the ShakeDetector is this one:

    java.lang.SecurityException: To use the sampling rate of 0 microseconds, app needs to declare the normal permission HIGH_SAMPLING_RATE_SENSORS.
            at android.hardware.SystemSensorManager$BaseEventQueue.enableSensor(SystemSensorManager.java:790)
            at android.hardware.SystemSensorManager$BaseEventQueue.addSensor(SystemSensorManager.java:710)
            at android.hardware.SystemSensorManager.registerListenerImpl(SystemSensorManager.java:209)
            at android.hardware.SensorManager.registerListener(SensorManager.java:823)
            at android.hardware.SensorManager.registerListener(SensorManager.java:730)
            at com.squareup.seismic.ShakeDetector.start(ShakeDetector.java:66)
            ...
    
    Reviewed by alejandrorosas at 2021-03-30 09:54
  • 6. Incorrect package in class "Demo"

    In class "Demo" had next line:

    package com.squareup.seismic.sample; 
    

    This is a mistake, the correct value:

    package main.java.com.squareup.seismic.sample;
    
    Reviewed by johnkil at 2012-09-06 10:24
  • 7. Seismic

    I'm trying to do an app that send you notifications every time a certain seismic wave happens,and send you a notification to your phone if you have the app downloaded.

    Reviewed by drde03 at 2022-04-23 15:02
  • 8. Set motion sensitivity

    I've added this library to my android project, but I'm noticing that I've to shake it very hard to trigger the hearShake method, is there a way to set sensitivity? If not, could such methods be publicly exposed?

    Reviewed by zevektor at 2015-04-15 13:24
  • 9. Bump junit from 4.10 to 4.13.1

    Bumps junit from 4.10 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    JUnit 4.12

    Please refer to the release notes for details.

    JUnit 4.12 Beta 3

    Please refer to the release notes for details.

    JUnit 4.12 Beta 2

    No release notes provided.

    JUnit 4.12 Beta 1

    No release notes provided.

    JUnit 4.11

    No release notes provided.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    Reviewed by dependabot[bot] at 2020-12-15 17:07
  • 10. Clears sample queue on stop()

    Due to the workaround of keeping at least MIN_QUEUE_SIZE in the sample queue stale SensorEvents will be kept even after MAX_WINDOW_SIZE. It is therefore possible that a isShaking() event will be emitted to the listener immediately after restarting (start() -> stop() -> wait x seconds -> start()) because they don't get purged correctly. This is a very common use case when one uses it to start in onResume() and stops it in onPause().

    Here is a minimal example on how to reproduce it:

    https://gist.github.com/patrickfav/e6d6eb63fc0bea30f87b94d3e7b29c9c

    When the user shakes in the MainActivity, the HearShakeActivity gets startet. After waiting arbitrary amount of seconds pressing back in the HearShakeActivity immediatly restarts HearShakeActivity. (I can reproduce it on my Nexus 6p; maybe slower devices cannot reproduce this bug)

    By clearing the queue on stop(), start() will start with a clear sample queue without stale events from seconds/minutes ago. This should not break any contract, since it would be very unintuitive to expect the sample queue stretching over the stopped phase.

    Regarding testing: unfortunately I did not find a way to manually create SensorEvents to test the detector's stop behavior. Making this testable would require some refactoring, which would make the whole project really verbose.

    Disclaimer: I signed Individual Contributor License Agreement

    Reviewed by patrickfav at 2017-01-30 21:26
  • 11. Can i increase the number of shakes per second?

    The results show that the shaking occurs about seven times in two seconds. However, I want to increase the number of shaking measures. Can I increase the number of detections per second with the code in the library?

    Reviewed by sucrow at 2019-02-16 07:17
  • 12. Can't get the ShakeDetector to stop

    I put sd.stop(); in onPause(), onDestroy(), and onBackPressed() but when I leave the application and shake the device on my homescreen for example it still performs the specified action.

    Reviewed by timbremer at 2016-06-11 21:56
  • 13. Not compatible with Galaxy S5?

    Samsung overrides motion gestures like shake and it seems like this library is not compatible with their modified Android system. If there is a secret device setting to make it work, please document it.

    Reviewed by ber4444 at 2016-02-01 19:41
  • 14. Purge results in less then MIN_QUEUE_SIZE items

    The test:

    @Test public void testPurge() {
      ShakeDetector.SampleQueue q = new ShakeDetector.SampleQueue();
      q.add(1, true);
      q.add(2, true);
      q.add(3, true);
      q.add(4, true);
      q.add(5, true);
      q.add(6, true);
      q.add(7, true);
      q.add(8, true);
      q.add(9, true);
      assertThat(q.asList()).hasSize(9);
      q.purge(3);
      assertThat(q.asList()).hasSize(7);
      q.purge(8);
      assertThat(q.asList()).hasSize(4); // MIN_QUEUE_SIZE
    }
    

    The last assert fails, the size is 3.

    Reviewed by Pitel at 2015-08-10 07:58
  • 15. Add method to change window size

    I need to have way more sensitivity.

    Half a second, and more than 75 % of samples is not acceptable for my use case. I can pick the phone from table and put it back withou triggering hearShake. And I've senstivity set to 10.

    I need to detect the phone flipping over from synchronization cradle.

    Reviewed by Pitel at 2015-08-07 12:08
Related tags
:iphone: [Android Library] Get device information in a super easy way.
:iphone: [Android Library] Get device information in a super easy way.

EasyDeviceInfo Android library to get device information in a super easy way. The library is built for simplicity and approachability. It not only eli

Aug 5, 2022
An Android library allowing images to exhibit a parallax effect that reacts to the device's tilt
An Android library allowing images to exhibit a parallax effect that reacts to the device's tilt

Motion An Android library allowing images to exhibit a parallax effect. By replacing static pictures and backgrounds with a fluid images that reacts t

May 22, 2022
A small utility to record Android device screen to a GIF
A small utility to record Android device screen to a GIF

RoboGif A small utility to record Android device screen to an optimized GIF so you can paste it to GitHub or a similar service. Requirements Python 2.

Jul 4, 2022
Android library for checking the internet connectivity of a device.

ConnectionChecker Android library for checking the internet connectivity of a device. Used in https://play.google.com/store/apps/details?id=com.muddas

Jun 29, 2022
adds an option to the Android Sharesheet that allows you to save files to your device.
adds an option to the Android Sharesheet that allows you to save files to your device.

Save On Device adds an option to the Android Sharesheet that allows you to save files to your device. Download Get the app from the Google Play Store

Jun 29, 2022
Android tiny device flow client

OAuth 2.0 Device Flow Example Setup Create an Auth0 application Enable Device Code Grants in Advanced settings Disable Client Credentials Enable Devic

May 15, 2022
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.

Secure-preferences - Deprecated Please use EncryptedSharedPreferences from androidx.security in preferenced to secure-preference. (There are no active

Aug 8, 2022
Android library which makes it easy to handle the different obstacles while calling an API (Web Service) in Android App.
Android library which makes it  easy to handle the different obstacles while calling an API (Web Service) in Android App.

API Calling Flow API Calling Flow is a Android library which can help you to simplify handling different conditions while calling an API (Web Service)

Nov 9, 2021
Gesture detector framework for multitouch handling on Android, based on Android's ScaleGestureDetector

Android Gesture Detectors Framework Introduction Since I was amazed Android has a ScaleGestureDetector since API level 8 but (still) no such thing as

Jul 28, 2022
Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

May 12, 2022
A util for setting status bar style on Android App.
A util for setting status bar style on Android App.

StatusBarUtil A util for setting status bar style on Android App. It can work above API 19(KitKat 4.4). 中文版点我 Sample Download StatusBarUtil-Demo Chang

Aug 4, 2022
A logger with a small, extensible API which provides utility on top of Android's normal Log class.
A logger with a small, extensible API which provides utility on top of Android's normal Log class.

This is a logger with a small, extensible API which provides utility on top of Android's normal Log class. I copy this class into all the little apps

Aug 17, 2022
Java implementation of a Disk-based LRU cache which specifically targets Android compatibility.

Disk LRU Cache A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key and a fixed number of values. Each key m

Aug 14, 2022
a simple cache for android and java

ASimpleCache ASimpleCache 是一个为android制定的 轻量级的 开源缓存框架。轻量到只有一个java文件(由十几个类精简而来)。 1、它可以缓存什么东西? 普通的字符串、JsonObject、JsonArray、Bitmap、Drawable、序列化的java对象,和 b

Aug 10, 2022
gRPC and protocol buffers for Android, Kotlin, and Java.

Wire “A man got to have a code!” - Omar Little See the project website for documentation and APIs. As our teams and programs grow, the variety and vol

Aug 13, 2022
✔️ Secure, simple key-value storage for Android
✔️ Secure, simple key-value storage for Android

Hawk 2.0 Secure, simple key-value storage for android Important Note This version has no backward compatibility with Hawk 1+ versions. If you still wa

Aug 14, 2022
A robust native library loader for Android.
A robust native library loader for Android.

ReLinker A robust native library loader for Android. More information can be found in our blog post Min SDK: 9 JavaDoc Overview The Android PackageMan

Aug 11, 2022
A lightning fast, transactional, file-based FIFO for Android and Java.

Tape by Square, Inc. Tape is a collection of queue-related classes for Android and Java. QueueFile is a lightning-fast, transactional, file-based FIFO

Aug 8, 2022
Joda-Time library with Android specialization

joda-time-android This library is a version of Joda-Time built with Android in mind. Why Joda-Time? Android has built-in date and time handling - why

Aug 15, 2022