-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from vanniktech/master_extra_annotation
Add @extra annotation
- Loading branch information
Showing
19 changed files
with
437 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
onactivityresult-annotations/src/main/java/onactivityresult/Extra.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package onactivityresult; | ||
|
||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.RetentionPolicy.CLASS; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* parameters of a {@link OnActivityResult} annotated method can be annotated to get an extra of the Intent<br> | ||
* The type of the variable will be automatically derived.<br> | ||
* <br> | ||
* Supported types are: <br> | ||
* <ul> | ||
* <li>boolean</li> | ||
* <li>byte</li> | ||
* <li>char</li> | ||
* <li>double</li> | ||
* <li>float</li> | ||
* <li>int</li> | ||
* <li>long</li> | ||
* <li>short</li> | ||
* <li>String</li> | ||
* </ul> | ||
* Example:<br> | ||
* <p> | ||
* <code> | ||
* @OnActivityResult(requestCode = 1) | ||
* void onResult(@Extra final String extra) { | ||
* // Do something | ||
* } | ||
* </code> | ||
* </p> | ||
* <br> | ||
* extra name: same as parameter <br> | ||
* NOTE: In this case it would be extra<br> | ||
* <br> | ||
* Since the type will be derived it's not possible to set a default value via the annotation. In case the Intent does not contain the extra, type default values will be provided automatically.<br> | ||
* If you want set a deafult value use one of those annotations: {@link ExtraBoolean}, {@link ExtraByte}, {@link ExtraChar}, {@link ExtraDouble}, {@link ExtraFloat}, {@link ExtraInt}, {@link ExtraLong} and {@link ExtraShort} | ||
* | ||
* @since 0.3.0 | ||
*/ | ||
@Retention(CLASS) | ||
@Target(PARAMETER) | ||
public @interface Extra {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
onactivityresult-annotations/src/test/java/onactivityresult/ExtraTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package onactivityresult; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
public class ExtraTest { | ||
@Test | ||
public void testAnnotationRetention() { | ||
final Retention retention = Extra.class.getAnnotation(Retention.class); | ||
assertEquals(RetentionPolicy.CLASS, retention.value()); | ||
} | ||
|
||
@Test | ||
public void testAnnotationTarget() { | ||
final Target retention = Extra.class.getAnnotation(Target.class); | ||
final ElementType[] elementTypes = retention.value(); | ||
assertArrayEquals(new ElementType[] { ElementType.PARAMETER }, elementTypes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.