SwissKnife


Source link: https://github.com/Arasthel/SwissKnife

SwissKnife

A multi-purpose Groovy library containing view injection and threading for Android using annotations. It's based on both ButterKnife and AndroidAnnotations.

With SwissKnife you can:

  • Inject views dynamically on any Object as long a you have a View to find them. No more findViewById and you don't have to extend any classes.
  • Add callback methods to several actions using @OnClick, @OnItemClick, etc.
  • Execute methods in the UI Thread or a background one using @OnUIThread and @OnBackground.
  • Make your variables persistent across state changes without messing with onSaveInstanceState.
  • Make anything Parcelable with the @Parcelable annotation - which can be used with @SaveInstance to automatize data persistance. NO MORE PARCELABLES! YAY!
  • Inject resources into your classes with @Res annotations ( @StringRes, @AnontationRes, etc.).
  • Read intent extras automatically with @Extra annotation.

You can see an example here:

class MyActivity extends Activity {

 @StringRes(R.string.important_message)
String reallyImportantMessage
 @Extra("api_key")
String apiKey
 @SaveInstance
public String myString;
 @OnClick(R.id.button)
public void onButtonClicked(Button button) {

  Toast.makeText(this, "Button clicked", Toast.LENGTH_SHOT).show();

}

 @OnBackground
public void doSomeProcessing(URL url) {

  // Contents will be executed on background
  ...

}

 @Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// This must be called for injection of views and callbacks to take place

SwissKnife.inject(this);

 // This must be called for saved state restoring

SwissKnife.restoreState(this, savedInstanceState);

 // This mus be called for automatic parsing of intent extras

SwissKnife.loadExtras(this)
  
}
 
}

Collaborators

I'd really want to thank:

  • Mario García for his help on the new GH-Pages based documentation.
  • Dexafree for adding @SaveInstance annotation and helping with the testing.
  • Eugene Kamenev for adding DSL functionality to android-dsl branch.
  • Karol for injection on any object.
  • Andrew Reitz for keeping the build files up to date.
  • Pavel for his resource injection AST transforms.

You all make SwissKnife the great tool it is!

Documentation

If you want to learn more, you can check Swissknife's docs page.

It contains info about the install instructions, all the annotations, DSLs, configurations, etc.

You can find all the releases and their changes here: RELEASES

Using it

To use SwissKnife you must use Groovy on your Android project as the code generation is done using AST processing, which is a Groovy feature. You can learn how to do that using this plugin on the wiki pages.

Once your project App Module is configured to use Groovy you can add this library as a dependency cloning it with git clone or as a maven library on the build.gradle of your App Module:

dependencies {

  ...
  compile "com.arasthel:swissknife:1.4.0"
  ... 
}

If you want SwissKnife to update automatically, you could just type:

dependencies {

  ...
  compile "com.arasthel:swissknife:+"
  ... 
}

But make sure you remember to clear Gradle's cache to get the latest version.

Also, there is an IntelliJ IDEA plugin compatible with Android Studio that lets you auto-generate the annotations and compatible method declarations.

License

SwissKnife is licensed under Apache v2 License, which means that it is Open Source and free to use and modify.

Copyright 2014 Jorge Martín Espinosa (Arasthel)  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Progressbar with whorl style.

Android horizontally scrolled DatePicker.

Android library that allows you to bind a LinearLayout with a ListAdapter.

Generate selectors for background drawable.

OPFIab is a next step from OpenIAB. It's an Android library intended to make in-app billing integration easy while supporting multiple billing providers (Appstores).

A simple fake VuMeter (or equalizer) for Android.

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