Code Monkey home page Code Monkey logo

intentbuilder's Introduction

IntentBuilder

Type safe intent building for services and activities.

IntentBuilder is a type safe way of creating intents and populating them with extras. Intents were created to be very dynamic but often times the dynamic nature of intents is not needed and just gets in the way of writing safe code.

Installation

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

apply plugin: 'com.neenbedankt.android-apt'

dependencies {
    compile 'se.emilsjolander:intentbuilder-api:0.14.0'
    apt 'se.emilsjolander:intentbuilder-compiler:0.14.0'
}

Usage

Annotate your activities and services with an @IntentBuilder annotation so that they are picked up by the library. For every class with an @IntentBuilder annotation a class named MyActivityIntentBuilder will be generated (Replace 'MyActivity' in the class name whith whatever the name of your Activity or Service class is). If your activity or service takes in parameters via extras in the intent you can now mark field with the @Extra annotation and they can be injected with the static inject method on the generated intent builder class. Extras can be marked as optional with the @Nullable annotation.

Sample activity using IntentBuilder:

@IntentBuilder
class DetailActivity extends Activity {
	
	@Extra
	String id;

	@Extra @Nullable
	String title;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		DetailActivityIntentBuilder.inject(getIntent(), this);
		// TODO use id and title
	}

startActivity(new DetailActivityIntentBuilder("12345")
	.title("MyTitle")
	.build(context))
}

Sample service using IntentBuilder:

@IntentBuilder
class DownloadService extends IntentService {

    @Extra
    String downloadUrl;
	
	@Override
    protected void onHandleIntent(Intent intent) {
        MyServiceIntentBuilder.inject(intent, this);
    }

}

startService(new DownloadServiceIntentBuilder("http://google.com").build(context))

Contributing

Contributions are very welcome! Both bug fixes and additional features if they make sense. Open a pull request to discuss any changes :)

intentbuilder's People

Contributors

emilsjolander avatar bryant1410 avatar vtsaplin avatar lsjwzh avatar

Watchers

 avatar  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.