Wednesday, April 6, 2011

Configure Android Development Workspace - Part 3 Workspace Mechanic

It is very common when using Eclipse that the developer may change workspaces.  To avoid having to re-configure the workspace a good tool to use is the Workspace Mechanic.


The plugin can be accessed through the update site using the Eclipse update manager.  To install new software in Eclipse, go to Help->Install New Software...


Insert the update site address as shown below:


Once the Workspace Mechanic is installed, the developer may record their workspace changes, and the workspace mechanic will notify the developer if the workspace is in need of repair.

Workspace Mechanic notification
This tool is very useful when switching between multiple workspaces.  This concludes the Android Workspace Configuration series.

Thanks for reading.  Please feel free to post your comments.



Tuesday, April 5, 2011

Configure Android Development Workspace - Part 2 Code Style

In this post we will add some guidelines to our Java code editor which will be suitable for contributing to the AOSP (Android Open Source Project) as described in the following link.

link: Android Code Style

To format your Java code, and organize your imported packages, you will need the following two files:

Android Formatting link: android-formatting.xml

Android Import Order link: android.importorder

Copy and paste the respective contents of each link into separate files. Be sure to preserve the file extension; ".xml" and ".importorder" respectively.

The code below shows a comparison between the default Java formatted code, and code formatted for Android.

/**
* A sample source file for the code formatter preview
*/

package mypackage;

import java.util.LinkedList;

public class MyIntStack {
private final LinkedList fStack;

public MyIntStack() {
fStack = new LinkedList();
}

public int pop() {
return ((Integer) fStack.removeFirst()).intValue();
}

public void push(int elem) {
fStack.addFirst(new Integer(elem));
}

public boolean isEmpty() {
return fStack.isEmpty();
}
}
Default Java format

/**
 * A sample source file for the code formatter preview
 */

package mypackage;

import java.util.LinkedList;

public class MyIntStack {
    private final LinkedList fStack;

    public MyIntStack() {
        fStack = new LinkedList();
    }

    public int pop() {
        return ((Integer) fStack.removeFirst()).intValue();
    }

    public void push(int elem) {
        fStack.addFirst(new Integer(elem));
    }

    public boolean isEmpty() {
        return fStack.isEmpty();
    }
}
Android format

To import a new format:


  1. Go to Eclipse and navigate to Window-> Preferences
  2. Next, expand the Java section, then expand the Code Style section
  3. Next, select the Formatter section, and import the android-formatting.xml file



Similarly here is a comparison between the import order for packages:

Java import order

Android import order
  1. Go to Eclipse and navigate to Window-> Preferences
  2. Next, expand the Java section, then expand the Code Style section
  3. Next, select the Organize imports section, and import the android.importorder file
Once each file is imported your Android workspace will format your code and be suitable for contribution to the AOSP.  

Monday, April 4, 2011

Configure Android Development Workspace - Part 1 SDK Installation

This post will demonstrate how to configure your Android workspace in Eclipse.

Firstly, download the SDK located at the Official Android Developers website.  Follow the instructions regarding installation and adding the ADT plugin for Eclipse.

link: Android Developers

Next, confirm that the ADT (Android Developer Tool) plugin is configured by opening Eclipse, choosing a workspace, and going to Window->Preferences->Android on the top menu bar.



Use the browse feature to point to the location of your Android SDK as seen above.