All Projects → vanniktech → Onactivityresult

vanniktech / Onactivityresult

Licence: apache-2.0
OnActivityResult annotation compiler for Android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Onactivityresult

RapidORM
Quick solutions for Android ORM
Stars: ✭ 24 (-94.89%)
Mutual labels:  annotation-processor
Doma
DAO oriented database mapping framework for Java 8+
Stars: ✭ 257 (-45.32%)
Mutual labels:  annotation-processor
Preferenceroom
🚚 Android processing library for managing SharedPreferences persistence efficiently and structurally.
Stars: ✭ 341 (-27.45%)
Mutual labels:  annotation-processor
simple-annotation-processor
Simple annotation processor example. Inspired by the idea of "How ButterKnife works?"
Stars: ✭ 54 (-88.51%)
Mutual labels:  annotation-processor
Dexter
Manage multidexing using simple annotations and gradle tasks.
Stars: ✭ 41 (-91.28%)
Mutual labels:  annotation-processor
Blade
Android library for boilerplate destruction
Stars: ✭ 278 (-40.85%)
Mutual labels:  annotation-processor
AutoBindings
Set of annotations that aims to make your Android development experience easier along with lint checks.
Stars: ✭ 15 (-96.81%)
Mutual labels:  annotation-processor
Mapstruct
An annotation processor for generating type-safe bean mappers
Stars: ✭ 4,710 (+902.13%)
Mutual labels:  annotation-processor
annotation-processor-sample
An annotation processor which implements "Builder pattern" for your java classes.
Stars: ✭ 22 (-95.32%)
Mutual labels:  annotation-processor
Pojobuilder
A Java Code Generator for Pojo Builders
Stars: ✭ 326 (-30.64%)
Mutual labels:  annotation-processor
WinAnalytics
A light-weight android library that can be quickly integrated into any app to use analytics tools.
Stars: ✭ 23 (-95.11%)
Mutual labels:  annotation-processor
therapi-runtime-javadoc
Read Javadoc comments at run time.
Stars: ✭ 50 (-89.36%)
Mutual labels:  annotation-processor
Vscode Todo Highlight
a vscode extension to highlighting todos, fixmes, and any annotations...
Stars: ✭ 305 (-35.11%)
Mutual labels:  annotation-processor
dagger2-ktx
Kotlin extension bridge library for Dagger2 (proof-of-concept)
Stars: ✭ 41 (-91.28%)
Mutual labels:  annotation-processor
Parceler
📦 Android Parcelables made easy through code generation.
Stars: ✭ 3,589 (+663.62%)
Mutual labels:  annotation-processor
smartstruct
Dart Code Generator for generating mapper classes
Stars: ✭ 20 (-95.74%)
Mutual labels:  annotation-processor
Immutables
Annotation processor to create immutable objects and builders. Feels like Guava's immutable collections but for regular value objects. JSON, Jackson, Gson, JAX-RS integrations included
Stars: ✭ 3,031 (+544.89%)
Mutual labels:  annotation-processor
Deeplinkdispatch
A simple, annotation-based library for making deep link handling better on Android
Stars: ✭ 4,108 (+774.04%)
Mutual labels:  annotation-processor
Android Api Securekeys
Store data in a simple and secure way
Stars: ✭ 372 (-20.85%)
Mutual labels:  annotation-processor
Jackdaw
Java Annotation Processor which allows to simplify development
Stars: ✭ 306 (-34.89%)
Mutual labels:  annotation-processor

OnActivityResult

  • 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

dependencies {
  compile 'com.vanniktech:onactivityresult:0.7.0'
  annotationProcessor 'com.vanniktech:onactivityresult-compiler:0.7.0'
}

Snapshots

compile 'com.vanniktech:onactivityresult:0.8.0-SNAPSHOT'
annotationProcessor 'com.vanniktech:onactivityresult-compiler:0.8.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:

Some examples can be found here.

The @Extra annotation is generic and works with every type mentioned above. In addition it also supports custom types which are implementing Parcelable or Serializable.

The disadvantage of @Extra is that it won't let you specify a default value therefore the other annotations do exist and should be used when needed.

Advantages over AfterMath

  • Gives you compile error(s) when using invalid RequestCode
  • Annotated method does not require resultCode and Intent to be present. It'll work with every combination (no params, resultCode, Intent, resultCode & Intent, Intent & resultCode). In addition also all custom parameter annotations can be used.
  • The annotations are on mavenCentral and available as a separate artifact
  • More detailed error messages
  • Inheritance support
  • @IntentData annotation with @NonNull & @Nullable support.
  • Specify resultCodes with e.g. resultCodes = { Activity.RESULT_OK }.
  • @Extra, @ExtraBoolean, @ExtraByte, @ExtraChar, @ExtraDouble, @ExtraFloat, @ExtraInt, @ExtraLong, @ExtraShort, @ExtraString annotations.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].