Hardware Reference
In-Depth Information
Whenever possible, use the permissions menu rather than
editing the manifest. For everything you need in this topic,
you can use the permissions menu and be safe. It's easy
to mess things up by editing it wrong—remember, XML is
not forgiving.
For more tips on the differences, see http://wiki.process-
ing.org/w/Android for the latest information.
Now here's a quick sketch to get you started. It reads
the mouse position and saves data when you pause and
resume. You'll need to set the Sketch Permissions to
enable WRITE_EXTERNAL_STORAGE .
X
Since your sketch restarts every time you change ori-
entation, you might want to use saveStrings() and load-
Strings() to save and load variables that need to persist.
Touch It
This sketch will
show you how mouseX , mouseY , and
motionPressure work on Android. It will
reorient itself, and save and reload data
when you rotate the device.
/*
Processing for Android test
Context: Processing
*/
float ballX, ballY; // position of the ball
// file to save data for pause and resume:
String datafile = "sketchFile.dat";
void setup() {
// create a font for the screen:
String[]fontList = PFont.list();
PFont androidFont = createFont(fontList[0], 24, true);
textFont(androidFont, 24);
}
void draw() {
// color theme: Sandy stone beach ocean diver by ps
// http://kuler.adobe.com:
background(#002F2F);
fill(#EFECCA);
// show the mouse X and Y and finger pressure:
text("mouseX:" + mouseX, 10, 50);
text("mouseY:" + mouseY, 10, 80);
text("motionPressure:" + motionPressure, 10, 170);
// move the ball if the person is pressing:
if (mousePressed) {
ballX = mouseX;
ballY = mouseY;
}
// draw a nice blue ball where you touch:
fill(#046380);
ellipse(ballX, ballY, 50, 50);
}
Search WWH ::




Custom Search