AutoBundle


Source link: https://github.com/ajalt/AutoBundle

AutoBundle

Automated packing and unpacking of Android Bundles.

Overview

Android's Bundle system works, but packing and unpacking the argument for Bundles is tedious and repetitive. This library takes care of the boilerplate, removing the need to manage putExtra, getExtra, and key values yourself.

Installation

AutoBundle uses jitpack to host its builds. Add the following to your gradle file to use AutoBundle:

repositories {

  maven {
 url "https://jitpack.io" 
}
 
}
  dependencies {

 compile 'com.github.ajalt:AutoBundle:1.1' 
}

Usage

AutoBundle is set up by annotating the fields of a class with the BundleArgument annotation. You can also annotate a class with BundleArguments to pack all fields in the class. Using it is this easy:

// Annotate the fields of a class of any type with @BundleArgument @BundleArguments class Arguments {

  public String stringArg;
  public int intArg;

// Constructors, etc... 
}

Set the extras of an intent by passing the intent and an instance of the arguments class to AutoBundle.packIntent:

// Create an instance of the class, and pass it to one of the AutoBundle pack methods public static Intent createIntent(Context context, Arguments args) {

  Intent intent = new Intent(context, SomeActivity.class);

  AutoBundle.packIntent(args, intent);

  return intent; 
}

Then in the onCreate of the called Activity, unpack the intent with AutoBundle.unpackIntent:

protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  Arguments args = new Arguments();

  AutoBundle.unpackIntent(getIntent(), args);
  // do something with `args`... 
}

That's it. The annotated fields in the Arguments instance will be populated with the values sent in the Intent.

Bundles outside of intents.

You can also use AutoBundle for Bundles that are not associated with an Intent by calling AutoBundle.packBundle and AutoBundle.unpackBundle. For example, with the saveInstanceState methods:

public class MyActivity extends Activity {

  @BundleArgument
  private String savedField;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

if (savedInstanceState != null) {

 AutoBundle.unpackBundle(savedInstanceState, this);

}

  
}

protected void onSaveInstanceState(Bundle outState) {

super.onSaveInstanceState(outState);

AutoBundle.packBundle(this, outState);

  
}
 
}

Manually specifying keys

By default, the keys for Bundle arguments are generated automatically. This works well if you have control of both packing and unpacking a Bundle. If you want to send or receive a Bundle from other sources, you can can specify a key parameter to BundleArgument to use specific key. Here's a translation of the standard email Intent using AutoBundle:

@BundleArgument(key=Intent.EXTRA_EMAIL) private String[] addresses;  @BundleArgument(key=Intent.EXTRA_SUBJECT) private String subject;  @BundleArgument(key=Intent.EXTRA_SUBJECT) private Uri attachment;  public void composeEmail() {

  Intent intent = new Intent(Intent.ACTION_SEND);

  intent.setType("*/*");

  AutoBundle.packIntent(this, intent);

  startActivity(intent);
 
}

Javadoc

The full javadocs can be found here.

License

Copyright (c) 2015 AJ Alt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

An Input box with different validators and ripple transition for android. It lets you to define custom animation for error text entrance and also comes up with seven ready validators.

Clean Architecture with Dagger2 + Retrofit2 + Picasso.

This application is an RSS Reader example of Clean Architecture with kotlin.

SugarLoader is a small library that adds sugar to Android Loader API.

Even when you rotate screen, tap home button, or anything, there is no risk to crash it or miss the callback, data will be loaded only once, then rendered to the restored activity/fragment, because there is Android Loader API under the hood.

A simple progress indicator (or chart widget) for Android.

Simple, Tiny, Extendable Android MVP library. No complex Base Activity, Base Fragment or Base View. Just base Presenters and View interface for you to extend from.

Extension of Android standard ImageView that lets the user scale the represented image and drag it around a pivot point defined as a fraction or a percentage.

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