Android-codegenerator-plugin-eclipse

Eclipse Plugin for Android code generation.

View project on GitHub

Introduction

Android Code Generator Plugin for Eclipse 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:

Download

All available versions of plugin are in releases.

Install

You can download jar file from latest release, and copy it into:
eclipse/plugins

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

You can quickly check how to use it by watching youtube tutorial.

Creating Code from layout file

In Package Explorer click on layout file, and you will see the Generate Android Code menu:

Package Explorer Layout

After clicking on one of the options Dialog will pop up:

Activity Dialog

If user click Create File, then file will be created and Text Editor with created file will automatically pop up.

Activity Editor

Creating Code from menu file

In Package Explorer click on menu file:

Package Explorer Menu

After click on Menu option Dialog will pop up:

Menu Dialog

Changing Templates in Preferences

User go to Eclipse preferences:

Eclipse Preferences

There is a hierarchy of pages under Android Code Generator. Under each tab there is Editable template:

Preferences Hierarchy

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
  • preference page with editable templates for generated code, template for each: Activity, Fragment, Adapter, Menu

Plans for future

The plan is to create plugin for IntelliJ IDEA/Android Studio, since more and more people are using it (including the author of the plugin :).

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.