Posts Tagged ‘ android

Kivy: Cross-platform application development with Python

I recently ran across Kivy, which in a nutshell lets you…. “develop (multi-touch) applications on Windows, Mac, Linux and Android using Python”.

I have yet to use it, but to me, this sounds awesome:  While I love the Processing API and how easy it is to get a sketch onto an Android device, I love writing code in Python even more.  The though of being able to create graphical Python apps that run on both a laptop \ Android device is pretty enticing.

Android Adventures, part 8: On a Mac?

Back to part 7.5…

I started using Apple’s back in the early 80’s:  Staying up late at my friends house playing Wizardry (1) on his Apple ][+ in ’81 was a great time.  My family picked up an Apple ][c in the mid 80’s which lasted for many years.  But by the late 80’s we jumped on the PC bandwagon, and it was a steady stream of 286’s, 386’s, 486’s, Pentium’s, etc,… up until today where I’ve had a Dell laptop for the past six years.  It treated me well, but has been showing it’s age.

Time to get a new laptop.  Doing my research, I learned the majority of the tech-friends I respect all vote for Mac.  Mac?

Long story short:  Now have a nice new shiny Macbook Air.  Easily portable, solid state drives, and feels nice in your hand.  Time to get software!

Below is the process I went through getting the Android SDK on the machine, getting ‘Processing for Android’ on it, and all the confusion that went on in-between considering I’m a complete mac noob.  This is actually very similar to “Android Adventures, part 2” where I configured everything on my PC, but with some twists.

A.  Install Software to get ‘Processing for Android’ working:

  • Per the instructions on the ‘Processing for Android’ page, I installed:
  • The Java Development Kit.  Wait, no I didn’t.  The mac comes pre-loaded with that.  Of course I didn’t know that and took me an hour or so to grasp it.  It also comes pre-loaded with Python, Ruby, and many other things.  My PC didn’t come with any of that….
  • Downloaded Android SDK for mac, and installed it.  Since this wasn’t a .dmg, but a zipped dir, I had to do research on where to put it.  Ultimately I renamed the folder it came in and:
    • Stuck it here  /Users/ak_eric/Documents/android-sdk
    • Had to edit my ~/.bash_profile adding these two lines: (there was already an export line for the PATH)
      • PATH=${PATH}:/Users/ak_eric/Documents/android-sdk/tools:/Users/ak_eric/Documents/android-sdk/platform_tools
      • export ANDROID_SDK=/Users/ak_eric/Documents/android-sdk
  • Download ‘Android for Processing’ for the mac.  This is where everything really went wrong:
    • My Android phone is still on os 2.1, which runs the SDK 7 tools.  Reading the download notes, it looked like to me I needed to download ‘Processing for Android’ revision 0191, since that seemed to mesh with SDK 7.  As it turns out, no, I was wrong, I needed to download the latest version.  After that everything started working.  But it took me several days of trial and error to figure this out.  You can see the forum thread on the subject here.

B.  Try out some code:

  • I’d already brought over all my old processing sketches.  During my ‘trial and error’ period mentioned above trying to get Processing for Android working, I downloaded the adbWireless app (which I blogged about previously).  I now use that exclusively to send my Processing for Android apps over to the phone, works great.  No more zany USB configuring for me!

So while it did take me quite a few days to get the whole thing working, it was mainly due to my lack of knowledge of the mac, and failing to install the latest software.  So far the Macbook Air has been a great reintroduction to the world of Apple, I just hope it lasts as long as my Dell 😛

Back to part 7.5…


Just ran across this great tool\app for Android development:  adbWireless.  It allows to you create a wireless (WiFi) adb (Android Debug Bridge) connection between your computer and your Android phone .  I can now present Processing sketches directly to the phone USB-free.  As mentioned\found in the comments below, you need root access for the app to function.  Worked on the first try, had to pass it along.

Android Adventures, part 7: Multi-touch in Processing

Go to part 6…, part 7.5…

Screenshot from my Samsung Captivate

One of the main reasons I got the phone was do to multi-touch apps.  The Processing for Android wiki points to some work done here to make this implementation easier.  But its a straight Android\Java implementation, and I really didn’t feel like trying to hack that into Processing.  Maybe it’s easy, but not for my brain a few days after Christmas.

I thought I’d see what it would take to code this from scratch, and it was surprisingly easy, at least for my needs.  All I wanted was a way to track multiple touch-points on screen.  The below code does that, plus tracks their ID’s, and their ‘size’.

Code Update: Previously I was pulling this info from the Android MotionEvent class that is returned by the sketche’s parental Activity class dispatchTouchEvent method.  However, this disabled Processings own motionX\motionY, mouseX\mouseY variables from ever getting populated.  Looking at the ‘Android – Processing’ wiki (here) it describes how you can can override Processings own surfaceTouchEvent function, which also accepts a MotionEvent as a argument.  This works the exact same as my original code, but no longer blocks the population of Procesisng variables.  So find updates in the source below.

surfaceTouchEvent is only triggered by pressure or motion change on the screen.  So it won’t execute if you’re not touching the screen, or if your finger is touching the screen, but stopped moving.  It is however, a good start 😉

The below Processing sketch will draw a circle under each touch point, along with the id, x, & y positions, and scale the circle based on the touch pressure.

// Eric Pavey - - 2010-12-29
// Example showing simple multi-touch detection in 'Processing - Android'.
// My Samsung Captivate (Galaxy S) can track 5 touch-points.
// Updated to work with Processing's surfaceTouchEvent instead of
// Android's dispatchTouchEvent.

// Should point out that API Level 9 has MotionEvent.PointerCoords class that
// expose some cool functionality, but I'm only on Level 7.

String[] fontList;
PFont androidFont;
int circleBaseSize = 512; // change this to make the touche circles bigger\smaller.

void setup() {
  size(screenWidth, screenHeight, A2D);
  // Fix the orientation so the sketch won't reset when rotated.
  // Setup Fonts:
  fontList = PFont.list();
  androidFont = createFont(fontList[0], 16, true);

void draw() {

void infoCircle(float x, float y, float siz, int id) {
  // What is drawn on sceen when touched.
  float diameter = circleBaseSize * siz;
  ellipse(x, y, diameter, diameter);
  ellipse(x, y, 8, 8);
  text( ("ID:"+ id + " " + int(x) + ", " + int(y) ), x-128, y-64);

// Override Processing's surfaceTouchEvent, which will intercept all
// screen touch events.  This code only runs when the screen is touched.

public boolean surfaceTouchEvent(MotionEvent me) {
  // Number of places on the screen being touched:
  int numPointers = me.getPointerCount();
  for(int i=0; i < numPointers; i++) {
    int pointerId = me.getPointerId(i);
    float x = me.getX(i);
    float y = me.getY(i);
    float siz = me.getSize(i);
    infoCircle(x, y, siz, pointerId);
  // If you want the variables for motionX/motionY, mouseX/mouseY etc.
  // to work properly, you'll need to call super.surfaceTouchEvent().
  return super.surfaceTouchEvent(me);

Go to part 6…, part 7.5…

New Android App: Floater

Find more info and install instructions from it’s page.

Floater is a particle sim responding to touch that runs on Android devices.   I built this app on an Win XP box, via Processing, specifically the “Android – Processing”.  It was tested on a (rooted) Samsung Captivate (Galaxy S), running Android 2.1.

If you get it running on a different piece of hardware, I’d really like to know :)

Merry Christmas!