• Stars
    star
    461
  • Rank 95,028 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OnActivityResult annotation compiler for Android

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

More Repositories

1

Emoji

A library to add Emoji support to your Android / iOS / JVM Application
Kotlin
1,523
star
2

gradle-dependency-graph-generator-plugin

Gradle plugin that generates dependency graphs from your project.
Kotlin
1,343
star
3

gradle-maven-publish-plugin

A Gradle plugin that publishes your Android and Kotlin libraries, including sources and javadoc, to Maven Central or any other Nexus instance.
Kotlin
1,252
star
4

RxRiddles

Riddling your way to masterย RxJava
Kotlin
455
star
5

gradle-android-junit-jacoco-plugin

Gradle plugin that generates JaCoCo reports from an Android Gradle Project
Groovy
397
star
6

lint-rules

A set of very opinionated lint rules.
Kotlin
353
star
7

gradle-code-quality-tools-plugin

Gradle plugin that generates ErrorProne, Findbugs, Checkstyle, PMD, CPD, Lint, Detekt & Ktlint Tasks for every subproject.
Kotlin
343
star
8

RxPermission

Reactive permissions for Android
Java
189
star
9

VNTNumberPickerPreference

NumberPicker Preference for Android
Java
174
star
10

gradle-android-apk-size-plugin

Gradle plugin that generates CSV files with apk size per output and variant of an apk
Groovy
84
star
11

gradle-android-javadoc-plugin

Gradle plugin that generates Java Documentation from an Android Gradle project.
Shell
80
star
12

VNTFontListPreference

ListPreference for Android which displays fonts
Java
77
star
13

kotlin-on-code-quality-tools

Demonstration of Code Quality Tools that are applicable with Kotlin
Kotlin
45
star
14

espresso-utils

Provides helper methods for asserting a few things that Espresso does not support out of the box.
Java
27
star
15

blurhash

BlurHash support for iOS, Android and JVM via Kotlin Multiplatform
Kotlin
19
star
16

TextBuilder

Provides a Class with a builder pattern for building beautiful text super easily. Internally it uses the Spannable API.
Java
17
star
17

SpeedReader

Cross-platform SpeedReader developed with Qt
C++
16
star
18

junit-rules

A set of handy junit rules.
Kotlin
15
star
19

RxBilling

Reactive wrapper around the Android Billing API
Kotlin
13
star
20

config-home

My home directory
Shell
12
star
21

multiplatform-locale

Type Safe Kotlin Multiplatform Locale implementation
Kotlin
10
star
22

SparseBuilders

Builders for SparseIntArray, SparseBooleanArray and SparseArray
Java
7
star
23

ui

Kotlin Multiplatform UI goodies
Kotlin
3
star
24

config-sublime

My Sublime 3 configuration
Python
1
star
25

playground

Empty project with basic dependencies for testing a few things out.
Ruby
1
star