Coder Social home page Coder Social logo

mahmoudmabrok / rumble-4-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from josephrubin/rumble-4-android

0.0 1.0 0.0 10 KB

Dead simple Android library for API independant Vibration functionality with fluent interface.

License: MIT License

Java 52.97% Kotlin 47.03%

rumble-4-android's Introduction

Rumble-4-Android

r4a abstracts away the annoying Android Vibrator API which suffers from a number of issues:

  • Different versions of android have deprecated or added different functions and you are expected to know which ones to use depending on the device version.
  • You have to make a new object for every single vibration you want to run.
  • Patterns are tedious and not intuitive.

Instead...

Setup (easy!)

  1. Download Rumble.java and place it anywhere in the source directory of your project.
  2. Add the line <uses-permission android:name="android.permission.VIBRATE" /> inside the manifest tag of your project's AndroidManifest.xml.
  3. Call Rumble.init(applicationContext) and pass it your application's Context. For example, you can place the following code in your activity:

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState)  {
    super.onCreate(savedInstanceState);
    Rumble.init(getApplicationContext());
}

Use (fluent!)

One-time device vibration java Rumble.once(500); // Vibrate for 500 milliseconds.

Patterns

Rumble.makePattern()  
    .beat(300)  
    .rest(250)  
    .beat(720)  
    .playPattern();

Repeating patterns

Rumble.makePattern()  
    .rest(200)
    .beat(30) 
    .beat(holdDuration) // Automatically adds to previous beat.
    .playPattern(4);      // Play 4 times in a row.

Save patterns for later

RumblePattern pattern = Rumble.makePattern()
    .beat(30).rest(150).beat(40).rest(40);
	
pattern.rest(80).beat(700); // Add to a pattern later.
pattern.playPattern();      // Play it whenever you like.

Lock patterns to prevent mutation

pattern.lock();
pattern.playPattern(3);     // Works just fine.
pattern.beat(500).rest(250) // Throws IllegalStateException.

rumble-4-android's People

Contributors

josephrubin avatar rspilker avatar timoschwarzer avatar

Watchers

James Cloos avatar

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.