Android Daydream with Processing.js

How to create an Android Daydream with processing.js

I've spent some time working out how to get processing.js (a nice javascript graphics library ported from Processing) to display an Android Daydream (basically a screensaver that activates when the device is docked or charging)

I previously wrote about how to display an HTML page as a Daydream which forms the basis for this post.  Please see my earlier post for full details but to summarise you can load an HTML page in a webview like this

webView.loadUrl("file:///android_asset/www/index.html");

Processing.js allows you to display Processing code as javascript in a page, so all you need to do is either embed the processing.js code or load the Processing PDE file containing the code as explained on the processing.js site

I only had a couple of issues with it which were:

1. The js code seemed to run at a much higher frame rate than my native Processing code such that my animation looked insane. In the end I just reduced the frame rate to 8

void setup() {
  frameRate(8);
}

You might need to play with the rate for your particular animation

2. screen.width and screen.height didn't seem to work correctly and displayed my animation off the bottom of the screen.  Using window.innerWidth and window.innerHeight had the desired effect

size(window.innerWidth, window.innerHeight);

You can test it in a local browser simply by loading the HTML page into Firefox/Chrome/whatever.  Once it's working, just follow the instructions from my earlier post to set it up as a Daydream and you're good to go :)


I've added this and released it with my Android app and will see what people think

As always, if you have any questions just let me know


Daydream running on my phone
Daydream installed

Comments

Popular posts from this blog

Launch a website as a mobile app using PhoneGap/Apache Cordova

Installing and using mobilize.js to transform a desktop site to a mobile site

How to manually add Cordova plugins to your app