Git Product home page Git Product logo

tinybus's Introduction

tinybus

Flattr this git repo

TinyBus is

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

TinyBus is for those who want

  • to remove unneccessary interfaces and direct component dependencies
  • to simplify communication between Activities, Fragments and Services
  • to simplify events exchange between background and Main Thread
  • to simplify consumption of standard system events (like Battery Level, Connection State etc.)

For those who want to simplify their apps and increase development productivity, here is TinyBus in detail.

Performance comparison tests

tinybus

Executed on Galaxy Nexus device with Android 4.3 (Dalvik) with switched off screen.

TinyBus quick start

// 1. Create event
public class LoadingEvent {
   // some fields if needed
}
   
// 2. Prepare event subscriber (Activity, Fragment or any other component)
@Subscribe
public void onEvent(LoadingEvent event) {
    // event handler logic
}
bus.register(this);
   
// 3. post event
bus.post(new LoadingEvent());

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

TinyBus

TinyBus implements interfaces defined in Otto project by applying them to Android's single thread model. There are two simple rules to follow, when using TinyBus:

  • Create TinyBus instance in Main Thread.
  • Call register() and unregister() methods in Main Thread.

To simplify communication with background threads TinyBus offers the following:

  • Method post() dispatches events in Main Thread even when called form a background thread.
  • Bus calls subscribers annotated with @Subscribe(Mode.Background) in a background thread.

TinyBus extensions

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 Bus mBus;
        
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // get bus instance and wire device shake event
        mBus = TinyBus.from(this).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 example can be found in example application.

Build with Ant

  1. git clone [email protected]:beworker/tinybus.git
  2. cd /tinybus
  3. ant release

Build with Gradle

  1. git clone [email protected]:beworker/tinybus.git
  2. cd /tinybus
  3. gradle build

Execute JUnit tests

  1. cd /tinybus-tests
  2. ant test

Gradle dependencies

For pure event bus implementation

dependencies {
    compile 'de.halfbit:tinybus:2.0.+'
}

For event bus with extensions

dependencies {
    compile 'de.halfbit:tinybus:2.0.+'
    compile 'de.halfbit:tinybus-extensions:2.0.+'
}

Proguard configuration

-keepclassmembers class ** {
    @com.halfbit.tinybus.Subscribe public *;
    @com.halfbit.tinybus.Produce public *;
}

-keepclassmembers enum com.halfbit.tinybus.Subscribe$Mode {
	public *;
}

Used in

Settings Extended

License

Copyright (c) 2014 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.

tinybus's People

Contributors

intrications avatar

Watchers

 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.