TinyBus


Source link: https://github.com/beworker/tinybus

TinyBus is the faster implementation of Otto event bus with additional features you missed.

TinyBus is

  • tiny (~ 26K jar)
  • fast (optimized for startup and event dispatching)
  • well tested (> 90 junit tests)
  • annotation based (no requirements on method names, no interfaces to implement)

TinyBus API in a nutshell

  • @Subscribe annotates event handler methods running in the main thread.
  • @Subscribe(mode=Mode.Background) annotates event handler methods running in a background thread.
  • @Subscribe(mode=Mode.Background, queue="web") annotates event handler methods running in a serialized background queue with given name. You can have as many queues as you want.
  • @Produce annotates methods returning most recent events (aka sticky events).
  • Bus.register(Object) and Bus.unregister(Object) register and unregister objects with annotated subscriber and producer methods.
  • Bus.hasRegistered(Object) checks, whether given object is already registered.
  • Bus.post(Object) posts given event object to all registered subscribers.
  • Bus.postDelayed(Object, long) and Bus.cancelDelayed(Class) schedules single event delivery for later in time and cancels it.

For a more detailed example check out Getting started step-by-step guide or example application.

Performance reference tests

Executed on Nexus 5 device (Android 5.0.1, ART, screen off).

TinyBus extensions (still in 'β')

Extensions is a unique feature of TinyBus. With it you can easily subscribe to commonly used events like battery level, connectivity change, phone shake event or even standard Android broadcast Intents. Here is a short example.

public class MainActivity extends Activity {

  private TinyBus mBus;

  @Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// get bus instance 

mBus = TinyBus.from(this)

if (savedInstanceState == null) {

 // Note: ShakeEventWire stays wired when activity is re-created

 //

 on configuration change. That's why we register is 

 //

 only once inside if-statement.

  // wire device shake event provider

 mBus.wire(new ShakeEventWire());

}

  
}

 @Override
  protected void onStart() {

super.onStart();

mBus.register(this);
  
}

 @Override
  protected void onStop() {

mBus.unregister(this);

super.onStop();

  
}

 @Subscribe
  public void onShakeEvent(ShakeEvent event) {

// device has been shaken
  
}
 
}

More detailed usage example can be found in example application.

Gradle dependencies

For pure event bus implementation

dependencies {

  compile 'de.halfbit:tinybus:3.0.2' 
}
 

For event bus with extensions

dependencies {

  compile 'de.halfbit:tinybus:3.0.2'
  compile 'de.halfbit:tinybus-extensions:3.0.2' 
}
 

ProGuard configuration

If you use Gradle build, then you don't need to configure anything, because it will use proper configuration already delivered with Android library archive. Otherwise you can use the configuration below:

-keepclassmembers, allowobfuscation class ** {

  @de.halfbit.tinybus.Subscribe public *;
  @de.halfbit.tinybus.Produce public *; 
}
 

Used by

License

Copyright (c) 2014-2015 Sergej Shafarenka, halfbit.de Copyright (C) 2012 Square, Inc. Copyright (C) 2007 The Guava Authors  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. 

Resources

A customizable circular progress bar for Android.

A fluent and flexible RSS feed manager for Android.

For more information, please see the website

A multi-purpose Groovy library containing view injection and threading for Android using annotations. It's based on both ButterKnife and AndroidAnnotations.

A simple NoSQL client for Android. Meant as a document store using key/value pairs and some rudimentary querying. Useful for avoiding the hassle of SQL code.

An Android library which provides simple Item animations to RecyclerView items.

Android Swipe Layout is the brother of AndroidViewHover.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes