Processing for Android


Home screens

When your device have several home screens, two functions in Processing tell you how to adjust the graphics in the sketch depending on which is the current screen: wallpaperHomeCount() and wallpaperOffset(). wallpaperHomeCount() holds the number of home screens (it can change while the wallpaper is running as the users adds or removes home screens). wallpaperOffset() is a float number between 0 and 1 that that measures the horizontal displacement along the screens: 0 at the leftmost location, and 1 when we are located at the rightmost homescreen. This post on stackoverflow explains in more detail how the x offset works.

PImage img;
float ratio;

void setup() {
  img = loadImage("landscape.jpg");
  ratio = float(img.width)/float(img.height);

void draw() {
  float w = wallpaperHomeCount() * width;
  float h = w/ratio;
  float x = map(wallpaperOffset(), 0, 1, 0, -(wallpaperHomeCount()-1) * width);
  image(img, x, 0, w, h);