Introduction
Android Code Generator Plugin for Android Studio/IntelliJ IDEA was created to accelerate the process of creating or developing Android applications. Every Activity needs to have XML layout, and Activity contains all the wiring up code like:
- fields for all required Views
- assigning fields to actual objects (findViewById() method)
- wiring up listeners to buttons (setOnClickListener() method) etc...
Instead of writing this code, I would be great if this code could be generated automatically. This way I come up with idea to have a plugin which does the code generation. I couldn't find such plugin so I decided to write it by myself. Luckily I was off project then, and I could spend some time on it. This way I created the first version in 2011. In 2014 I decided to basically rewrite the plugin from the beginning, add tests and split it into two projects:
- library (https://github.com/tmorcinek/android-codegenerator-library)
- main project - this one, which contains reference to library project, and all Plugin Development Environment related code.
Install from JetBrains repository
You can install plugin from repository:
Preferences/Settings->Plugins->Browse repositories...
Then type in search: Android code Generator
Download and install
All available versions of plugin are in releases. You can download zip file from latest release and install it.
How does it work
Plugin is retrieving from xml files, data about all the views that contain android:id attribute. It collects informations about view's type and id. Based on the type of object and id plugin generates fields, assignment, imports and methods. For more informations go to android-codegenerator-library project.
How to use it
Finding menu options
For all xml files that are either in layout or menu directories menu option Generate Android Code appears. You can invoke it from Project Explorer as well as from Editor.
Generating Activity
Generating Menu for Activity
Modifying code to generate
Plugin settings in Preferences
Features
There are several very useful features some of them are:
- generating Activity Class code from layout
- generating Fragment Class code from layout
- generating Adapter Class code from item layout
- generating Menu code from menu xml
- creating files from code
- preview screen with generated code that can be modified before creation of file
- detection of project package
- detection of source directories in project
- settings in Preferences with editable template for each option: Activity, Fragment, Adapter, Menu
Plans for future
Improving plugin usability.
Authors and Contributors
The author is Tomasz Morcinek @tmorcinek.
Support or Contact
If you have any problems with the plugin, or want to help, please contact me: tomasz.morcinek@gmail.com and I will try to reply as soon as I can.