Category: Processing

Processing + Eclipse + Android = Proclipsoid?

Right off the bat I have doubts about using Processing for Android development.  Processing only supports up to Android version 2.2 at this point.  Android is up to 4+ now.  This can’t be good.  But I’m not sure what the repercussions are.  Maybe simple apps will be forwards compatible?  Features like NFC, which only the latest Android versions support, are going to be out of the question, right?  I hope to delve into Android more to answer such questions, but for now I have a few simple steps to get a basic Android app, which leverages Processing, up and running in the Eclipse IDE.

First we need to perform steps as documented by Google to get Android up and running on its own.

1.  Install Android SDK.

Run SDK Manager and select the components from the list as follows.  My screenshot says “update” in some places because I last played with Android a year ago.

 
2.  If you haven’t already, install Eclipse for Java.

3.  Install the Eclipse ADT Plugin.

4.  Create an AVD using Android version 2.2.

5.  Create a blank Android Project again using Android version 2.2.  On the 3rd screen for Package Name, be sure to use something like “com.example.helloandroid” and not “HelloAndroidProcessing” or you’ll get strange errors.

 

 

 
6.  In Eclipse, create a new run configuration using the AVD you created earlier.

7.  Now make sure the Android app runs on its own.  Launch using your new run configuration and you should see the Android emulator pop up.  If you’ve gotten this far, you are ready to develop for Android sans Processing.

8.  If you haven’t already, install Processing (just need to download and unzip).  I’m using version 2.04a.  Stable version 1.5.1 won’t work according to the Processing Wiki.

9.  Now import android-core from your Processing installation.  I created a folder in my new Android project directory called “lib” and placed android-core.jar into it.  Then in Eclipse go to Project -> Properties -> Java Build Path -> Add JARS… and find and select android-core.jar.  (No Proclipsing happening here, though that would be my method of choice for developing Processing in Eclipse for non-Android purposes)

10.  Now make the following code replacement in your main activity class.  Notice I commented out most of what was there by default.  I grabbed a simple Processing sketch from Dan Shiffman’s Learning Processing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.example.helloandroid;
//import android.app.Activity;
//import android.os.Bundle;
import processing.core.*;
 
/*
public class HelloAndroidProcessing extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
*/
 
public class HelloAndroidProcessing extends PApplet {
    public static void main(String args[]) {
        PApplet.main(new String[] { “–present”, “something.whatever});
    }
 
    //@Override
    //public String sketchRenderer() {
    // return P2D;
    //}
 
    PFont f;
    String message =this text is spinning”;
    float theta;
 
    @Override
    public void setup() {
        size(200,200);
        f = createFont(“Arial”, 20, true);
    }
 
    @Override
    public void draw() {
        background(255);
        fill(0);
        textFont(f);
        translate(width/2,height/2);
        rotate(theta);
        textAlign(CENTER) ;
        text(message,0,0);
        theta += 0.05;
    }
}

Running your run configuration should start up the slow slow emulator.  Once I unlock, I see the following:

 
Also you will now have a file called HelloAndroidProcessing.apk in your bin folder.  Simply copy it over to your Android device and install it and you’ll see your app in action.

SoundGround

 
Graphics programming is a new realm for me and I’ve been searching for the ideal tool sets to use for practice.  Processing is a great way to get started.  Created by Ben Fry and Casey Reas in 2001, it’s a work of art for creating works of art.  It’s incredibly quick and easy to setup, and it’s very satisfying to see your creations moving around on the screen after a few lines of code.  However, the Processing IDE leaves much to be desired, lacking any sort of debugging or intellisense.  Luckily Eclipse is a great free IDE which makes using Processing an even more pleasant experience.

Processing + Eclipse = Proclipsing

Proclipsing makes using Eclipse for Processing very straightforward.  Plus, it allows you to use some powerful Java constructs in your Processing app.  It was recommended to me by my friend Mario (aka OneDayItWillMake) who has been my guide to proclipsing effectively.

 
SoundGround is a very basic app that responds to mic input.  I used a simple particle engine and modeled some 2D physics.  It’s easier than it sounds, I learned everything from Robert Hodgin’s cinder tutorials a couple years ago.  They are an excellent resource for anyone doing any interactive programming in any language.  Also made use of controlP5, a great library to create a parameter box in Processing.

Here’s the code.