OnActivityResult


Source link: https://github.com/vanniktech/OnActivityResult

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

buildscript {

  dependencies {

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

  compile 'com.vanniktech:onactivityresult:0.6.0'
  apt 'com.vanniktech:onactivityresult-compiler:0.6.0' 
}

Snapshots

compile 'com.vanniktech:onactivityresult:0.7.0-SNAPSHOT' apt 'com.vanniktech:onactivityresult-compiler:0.7.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

Resources

Siri like wave view for Android.

Password Utility Free Forever

Features

  • Open Source
  • Blowfish Encryption
  • Totally Offline - we don't even require an internet access permission
  • Quick access your credentials
  • Cross Platform - Working in Progress

Implementing Search Filter Animation in Kotlin for Quora Meets LinkedIn.

DroidAwesome is a library to display FontAwesome Icons in any View or a MenuItem.

This library provides a simple and customizable away to setup @ mentions on any EditText. Here's all it takes to get started.

Recycler View Library with built-in Item click listeners, drag and swipe functionality.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes