Giter Club home page Giter Club logo

android-shake-detector's Introduction

android-shake-detector

Detect shaking of the device

Install

Add the dependecy

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

dependencies {
   compile 'com.github.safetysystemtechnology:android-shake-detector:v1.2'
}

Add permissions in your AndroidManifest.xml

<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />

if you will run in background, register your broadcast receiver

<receiver android:name=".ShakeReceiver">
    <intent-filter>
        <action android:name="shake.detector" />
    </intent-filter>
</receiver>

Usage

private ShakeDetector shakeDetector;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    buildView();

    ShakeOptions options = new ShakeOptions()
            .background(true)
            .interval(1000)
            .shakeCount(2)
            .sensibility(2.0f);

    this.shakeDetector = new ShakeDetector(options).start(this, new ShakeCallback() {
        @Override
        public void onShake() {
            Log.d("event", "onShake");
        }
    });

    //IF YOU WANT JUST IN BACKGROUND
    //this.shakeDetector = new ShakeDetector(options).start(this);
}

private void buildView() {
    Button btnStopService = (Button) findViewById(R.id.btnStopService);
    btnStopService.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d("destroy", "destroy service shake");
            shakeDetector.stopShakeDetector(getBaseContext());
        }
    });
}

@Override
protected void onStop() {
    super.onStop();
}

@Override
protected void onDestroy() {
    shakeDetector.destroy(getBaseContext());
    super.onDestroy();
}

if you will run in background, create your broadcast receiver

public class ShakeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (null != intent && intent.getAction().equals("shake.detector")) {
            ...
        }
    }
}

License

The MIT License (MIT)

Copyright (c) Safety System Technology

Permission is hereby granted, free of charge, to any person obtaining a 
copy of this software and associated documentation files (the "Software"), 
to deal in the Software without restriction, including without limitation 
the rights to use, copy, modify, merge, publish, distribute, sublicense, 
and/or sell copies of the Software, and to permit persons to whom the Software is 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included 
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

android-shake-detector's People

Contributors

netodevel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-shake-detector's Issues

Stop doesn't exists

this.shakeDetector.stop(getBaseContext());
error: cannot find symbol method stop(MainActivity)

Import error

I added the dependency in my Gradle file, and it ends up with
ERROR: Failed to resolve: com.github.safetysystemtechnology:android-shake-detector:v1.2 Show in Project Structure dialog Affected Modules: app
My internet connection is working fine, but it still says that. Any solutions?

BackGround Shake Reciever

in start background shake detector work perfectly but when you can shake after few minutes then it will not work and not detected the shake
is there is any solution ?
Thanks in advance

Receiver does not work

Followed ur steps as below.

  1. complied with lib
  2. added manifest permission and receiver
  3. Created receiver class but no intent received on shake in nexus 5.

Did i miss something to mention in code!?

Cannot instantiate multiple shake detectors

Hi, I love this module but I have a scenario where I'd like multiple shake detectors. For example, to detect when a single shake has occurred vs when a double shake has occurred. I tried instantiating 2 shake detectors but it seems that the second overrides the first.

Not sure if this a bug and if there's a workaround. Would appreciate your assistance.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.