processing+on+android

developing apps for android is dead easy using processing. just press play in processing and the app gets launched on the tablet. once it is installed properly at least. and that can be a bit of a pain.

so here is a few notes that can help...

1. look at this page http://blog.blprnt.com/blog/blprnt/processing-android-mobile-app-development-made-very-easy NB: you do not need to install all packages, you can go for only SDK ver 10 / 2.3

2. important: the newest version of processing (2.1) does NOT work with android support. so go to their website and grab version 2.0.3 in stead. this works. https://processing.org/download/

=ketai library= tablets and touch screens are different than computers. there is no mouseClicked etc., you need to deal with taps, swipes etc. and there is a lot funky sensors too. the ketai library covers all this beautifully: https://code.google.com/p/ketai/

=sound on android= can be a real headache. processing libraries like minim does not work on android devices. the android media player does, but it is a bit complex to use.

here is a processing example which plays a simple mp3: code format="java" // playing sound on android devices with processing and android media player // this sketch uses the ketai library for tap detection https://code.google.com/p/ketai/

import android.view.MotionEvent; import ketai.ui.*;

import android.media.*; import android.content.res.*;

KetaiGesture gesture; PImage img; MediaPlayer snd;

float imgX = 100, imgY = 100;

void setup {

orientation(LANDSCAPE); gesture = new KetaiGesture(this); size(displayWidth,displayHeight); img = loadImage("toci.jpg");

try { snd = new MediaPlayer; AssetManager assets = this.getAssets; AssetFileDescriptor fd = assets.openFd("Jump7.mp3"); snd.setDataSource(fd.getFileDescriptor, fd.getStartOffset, fd.getLength); snd.prepare; snd.start; } catch (IllegalArgumentException e) { e.printStackTrace; } catch (IllegalStateException e) { e.printStackTrace; } catch (IOException e) { e.printStackTrace; } }

void draw { background(100); imageMode(CENTER); image(img,imgX,imgY); }

void onTap(float x, float y) { imgX = x; imgY = y;

try { snd.reset; AssetManager assets = this.getAssets; AssetFileDescriptor fd = assets.openFd("Jump7.mp3"); snd.setDataSource(fd.getFileDescriptor, fd.getStartOffset, fd.getLength); snd.prepare; snd.start;

} catch (IOException e) { println("prepare failed"); } snd.start; }

public boolean surfaceTouchEvent(MotionEvent event) {

//call to keep mouseX, mouseY, etc updated super.surfaceTouchEvent(event);

//forward event to class for processing return gesture.surfaceTouchEvent(event); } code