Building a photo booth for Droidcon NYC

A month ago, my team at Square released the Reader SDK. We had the opportunity to show a demo at Droidcon NYC. How could we make payments cool?

We set up to build SquickPic, a fun Android photo booth: pay a dollar 💳, choose a filter, smile, Snap! 📸 The photo booth prints the picture and tweets it 🐦 (@SquickPic).

Android engineers Christina, Mike, Zarah and John joined me in sporting an Oreo Nose Ring

We decided to open source SquickPic (sources on GitHub). In this blog, we’ll go over the most interesting parts of the code:

Face detection

Kiosk experience

Taking payments

Printing with Google Cloud Print

Tweeting 🐦

App flow

Idle screen, waiting for a new customer

💳Ready to take a card payment!

Filter selection. Best filter is obviously LeakCanary 😅

🖨Ready to print!

Face detection

The first step was building out face detection. We used Google Mobile Vision API and checked out the FaceTracker sample app. Nothing like copy pasting and removing what you don’t need to get to working code quickly!

The most tricky part was figuring out scaling and reversing: face detection runs on the camera bitmap and provides coordinates in that referential. The camera bitmap gets scaled up to the display, so we have to scale up our filters:

Drawing the Android Pie logo on people’s eyes

Kiosk experience

The photobooth was set up in a public space, so we locked the tablet on the photobooth app with startLockTask():

We also set the relevant activities to fullscreen:

Taking payments

This was the most important part for us! Also the simplest, just a few lines of code 💪.

Yes, the note field supports emojis 🕺

Printing with Google Cloud Print

PrinterHelper makes it easy to print bitmaps by showing a system UI to select a printer, configure attributes, and then send the print job. This is great for consumer devices but not so much for a photo booth where we expect pictures to print automatically.

We bought a Selphy CP1300 and connected it to Google Cloud Print. Unfortunately, the Cloud Print Android API also shows a UI, and the HTTP API documentation left out details that we had to figure out.

Our first step was to obtain an OAuth token. We used AccountManager to request an OAuth token:

Next, we defined a Retrofit interface to list printers and send a print job:

Retrofit is backed by OkHttp, so we set up an OkHttp interceptor to add the Cloud Print OAuth token to our requests:

We converted the bitmap into a JPEG byte array and sent it as a multipart message:

Tweeting 🐦

We set up Twitter Core and used a TwitterLoginButton to authenticate via the Twitter app. Tweeting a picture requires uploading it first, and then attaching it as a media to a status update:

Twitter still call tweeting a “status updat‍e”

That’s it! We had a ton of fun building this and taking goofy selfies with Droidcon NYC attendees. Don’t hesitate to check out the sources on GitHub!