Giter Club home page Giter Club logo

onactivityresult's Introduction

OnActivityResult

Build Status API License

  • Generates boilerplate code for OnActivityResult callbacks and lets you focus on what matters.
  • Generated code is fully traceable and debuggable.
  • Everything is generated during compile time with appropriate errors / warnings.
  • No reflection used!

Gradle

buildscript {
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

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

dependencies {
    compile 'com.vanniktech:onactivityresult:0.1.0'
    apt 'com.vanniktech:onactivityresult-compiler:0.1.0'
}

Snapshots

compile 'com.vanniktech:onactivityresult:0.2.0-SNAPSHOT'
apt 'com.vanniktech:onactivityresult-compiler:0.2.0-SNAPSHOT'

Modules are located on Maven Central.

Example

Override onActivityResult in your Activity / Fragment and call ActivityResult.onResult

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    ActivityResult.onResult(requestCode, resultCode, data).into(this);
}

Annotate your methods and get the callback

@OnActivityResult(requestCode = 33)
void onActivityResultTestActivity() { /* Do something */ }

@OnActivityResult(requestCode = 1, resultCodes = { Activity.RESULT_OK })
void onActivityResultActivityOk() { /* Only do something when ok */ }

@OnActivityResult(requestCode = 1, resultCodes = { Activity.RESULT_CANCELED })
void onActivityResultActivityCanceled() { /* Only do something when canceled */ }

@OnActivityResult(requestCode = 2)
void onActivityResultPickImage(final int resultCode, final Intent intent) { /* Do something */ }

Various parameters are supported:

  • none
  • int
  • Intent
  • int, Intent
  • Intent, int

Where int parameters will get the resultCode and Intent parameters will get the Intent. Note: Each annotated method shall only have one int and / or Intent variable.

In addition to that other parameter annotations are supported like:

See more examples here.

Advantages over AfterMath

  • Gives you compile error(s) when using invalid RequestCode
  • Annotated method does not require resultCode & Intent to be present. It'll work with every combination (no params, resultCode, Intent, resultCode & Intent, Intent & resultCode)
  • The annotations are on mavenCentral
  • More detailed error messages
  • Almost 100% unit test coverage
  • Inheritance support
  • @IntentData annotation. Since 0.2.0
  • Specify resultCodes with e.g. resultCodes = { Activity.RESULT_OK }. Since 0.2.0

Thanks

Thanks to JakeWharton's ButterKnife

Thanks to Hannes Dorfmann's Annotation Processing 101

License

Copyright (C) 2015 Vanniktech - Niklas Baudy

Licensed under the Apache License, Version 2.0

onactivityresult's People

Contributors

vanniktech avatar

Watchers

James Cloos 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.