Icepick


Source link: https://github.com/frankiesardo/icepick

Icepick

Icepick is an Android library that eliminates the boilerplate of saving and restoring instance state. It uses annotation processing to generate code that does bundle manipulation and key generation, so that you don't have to write it yourself.

class ExampleActivity extends Activity {

@State String username; // This will be automatically saved and restored
 @Override public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  Icepick.restoreInstanceState(this, savedInstanceState);

}

 @Override public void onSaveInstanceState(Bundle outState) {

  super.onSaveInstanceState(outState);

  Icepick.saveInstanceState(this, outState);

}

 // You can put the calls to Icepick into a BaseActivity
// All Activities extending BaseActivity automatically have state saved/restored 
}

It works for Activities, Fragments or any object that needs to serialize its state on a Bundle (e.g. mortar's ViewPresenters)

Icepick can also generate the instance state code for custom Views:

class CustomView extends View {

@State int selectedPosition; // This will be automatically saved and restored
 @Override public Parcelable onSaveInstanceState() {

  return Icepick.saveInstanceState(this, super.onSaveInstanceState());

}

 @Override public void onRestoreInstanceState(Parcelable state) {

  super.onRestoreInstanceState(Icepick.restoreInstanceState(this, state));

}

 // You can put the calls to Icepick into a BaseCustomView and inherit from it
// All Views extending this CustomView automatically have state saved/restored 
}

Custom Bundler

From version 3.2.0 you can supply a class parameter to the State annotation. This class should implement the Bundler interface and you can use it to provide custom serialisation and deserialisation for your types.

class MyFragment {

@State(MyCustomBundler.class) MyCustomType myCustomType; 
}
  class MyCustomBundler implements Bundler<MyCustomType> {

void put(String key, MyCustomType value, Bundle bundle) {

  ...

}

 MyCustomType get(String key, Bundle bundle) {

  ...

}
 
}

This is useful if you want to use icepick in conjunction with Parceler.

Proguard

If Proguard is enabled make sure you add these rules to your configuration:

-dontwarn icepick.** -keep class icepick.** {
 *; 
}
 -keep class **$$Icepick {
 *; 
}
 -keepclasseswithmembernames class * {

  @icepick.* <fields>; 
}
 -keepnames class * {
 @icepick.State *;
}
 

Download

Icepick needs two libraries: icepick and icepick-processor.

Gradle:

repositories {

maven {
url "https://clojars.org/repo/"
}
 
}
 dependencies {

compile 'frankiesardo:icepick:{
{
latest-version
}

}
'
provided 'frankiesardo:icepick-processor:{
{
latest-version
}

}
' 
}

Maven:

<repositories>
<repository>
  <id>clojars</id>
  <url>https://clojars.org/repo/</url>
  <snapshots>

 <enabled>true</enabled>
  </snapshots>
  <releases>

 <enabled>true</enabled>
  </releases>
</repository> </repositories> <dependencies>
<dependency>
  <groupId>frankiesardo</groupId>
  <artifactId>icepick</artifactId>
  <version>{
{
latest-version
}

}
</version>
</dependency>
<dependency>
  <groupId>frankiesardo</groupId>
  <artifactId>icepick-processor</artifactId>
  <version>{
{
latest-version
}

}
</version>
  <optional>true</optional>
</dependency> </dependencies>

Resources

A Tap Target implementation in Android based on Material Design Onboarding guidelines.

This library helps with sequential tasks that will be run one after another and only when each task is finished. These tasks can either be UI or background.

Space Navigation is a library allowing easily integrate fully customizable Google Spaces like navigation to your app.

Core-Adapter supports any type of items in RecyclerView with no pain.

A simple customizable indicator for ViewPagers.

This is a simple CheckBox for Android with cool animation.

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