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

MultiSelectListPreferenceCompat

Backport MultiSelectListPreference class to older android devices.

Originally MultiSelectListPreference was introduced to API level 11 (Honeycomb) and official support package does not include this class. This library introduces compatible class of MultiSelectListPreference.

android-verticalseekbar is a vertical SeekBar class which supports Android 2.3 - 5.0.

Pretty is a library that enables one to enhance Android layout inflation without boilerplate and knowledge about LayoutInflater internals. Pretty hooks into the Android layout inflation so you could add new attributes to existing View subtypes.

Statically typed programming language targeting the JVM and JavaScript.

100% interoperable with Java™

Spotify Web API Wrapper with Retrofit and OkClients just for Android.

This library includes authentication and account token management feature.

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