Showing posts with label fitcat. Show all posts
Showing posts with label fitcat. Show all posts

Thursday, November 5, 2015

Google Games: Leaderboard + Achievements

I have a weakness in cute things. I often play cute games, telling myself that I do it to "learn about game mechanics". This time, I actually integrated Google Play Games Services due to inspiration from playing!

Alphabear

My latest addiction is Alphabear. You earn bears while playing a word game, which gives you extra powers. They show you the list of bears you have collected:

I want that for Fit Cat! A catalog, if you will, showing all the cats that you have seen. Initially I was going to do the UI and tracking myself, but then I came across Google Games Achievements. Perfect!

Leaderboard

When I started looking into Google Games, I learned about Leaderboards as well, which seems a simpler concept to launch with. I just need to submit the number of steps to Google Games, and everything else is handled for me. Great!

One problem though: Fit Cat is a watch face, and the watch does not have direct internet access. To upload the steps, I transfer the data to the phone using the Wearable Data Layer API and send it to Google Games in a WearableListenerService.

To test that, I needed to pace around the house, because the Data Layer API only syncs when the data changes. If I sit on my chair in front of my computer, the number of steps stays the same, and so I will not get a callback. It was pretty hilarious, me pacing around and rushing back to the computer to check the logs and see if the phone received data.

Placeholder achievements

I was going to publish my game with the leaderboard, but got blocked because Google Games requires at least 5 achievements. This was right before Big Android BBQ, and I did not have a lot of time before flying to Texas. So I added 5 placeholder achievements and made them hidden, and launched.

Actual Achievements

After I launched leaderboard, I wanted to go back to repurpose the hidden achievements to show cats. I want them to be public so that you are motivated to reach a goal level to see a certain cat.

Alas, I cannot switch an achievement from hidden to public once I published them. So I created new achievements for the cats.

While "May appear at 10000 steps" gives people a goal to walk more, "Secret" is just really mean if it is not attainable. I was holding off the launch until I came up with 5 achievements to backfill the placeholders. That took a few days, but I now have some fun ones for people to discover!

Play Games app

The nice thing about integrating with Google Play Games Services is that your game will show up in the Play Games app. Friends can compare achievements with each other, which is really fun.

However, Fit Cat was not showing up, and I was not sure why. Turns out you need to categorize your app as "Game" rather than "Application" on Google Play, so now Fit Cat is a "Sports Game".

Usually you play sports games by tapping your fingers on screen and pretending to be playing sports, but this one you actually play with your feet in real life!

Easy gaming

Google Play Games Services has a lot of built-in UI, making it super easy to add gaming to your app, even for a non-game like Fit Cat. There was a few non-obvious requirements (ahem, minimum 5 achievements), so I'd recommend going through the checklist during planning, not before launch like me.

Overall it's a great enhancement to my app, for very little effort. I hope you like it too!

Sunday, July 12, 2015

How to test a watch face?

Fit Cat is an Android Wear watch face that shows the time with a different cat depending on how many steps you walked that day. How do you test something like that? Walk a lot while looking at your watch all the time?

I wrote Fit Cat with a modular structure that allows both unit testing and instrumentation testing.

All Android Wear apps have two modules, mobile and wear. I made them both depend on a ui module, which has the implementation for rendering the bitmap for the watch face. This in turn depends on a lib module, which is a pure Java library.

Unit testing

The lib module contains the pure Java class ActionStore, which has the logic to determine which image to show depending on the time, steps and randomizer value:

  • The number of steps decides the action level, each mapping to multiple actions.
  • Within that level, an action is picked randomly.
  • Within that action, the time determines the image for the animation frame.

The watch face calls actionStore.getImage(time, steps, randomizerValue) to get the image file name. In the junit tests, various values of time, steps and randomizerValue are passed to that function, and the resulting image file names are verified.

Instrumentation testing

Besides verifying the logic, I also want to visually inspect the rendered bitmaps. The ui module has a Renderer class with a function drawWatchFace(canvas, steps, action, time, batteryPercent). I test this function by adding an InstrumentationTestCase to the mobile module, which enumerates all possible actions and write the animation frames to sdcard. I then combine them into animated gifs for visual inspection.

Since the wear module also uses this Renderer class from the ui module, I am confident that the layout for all the different animation frames are good. Plus, I get to see all the cute actions Fit Cat does!

Monday, June 1, 2015

Fit Cat at Google I/O

One of the most exciting things at Google I/O this year for me was to meet Virginia Poltrack in person.

Online introduction

I wanted to make an Android Wear watch face with a cat that does different things depending on how many steps you took that day. The first order of business is to find an illustrator to draw the cute cats. I posted on Google Plus to ask for recommendations, and my friend Macy introduced me to Virginia. At that point I didn't say anything about a watch face, so I was really surprised when I saw this on Virginia's profile:

Yup, not only that she is an amazing illustrator, she has made watch faces before!

Rapid iterations

Once I explained my idea to Virginia, we both got really excited and started working right away.

Our goal was to launch before I/O, and we did it! Twice, in fact: first with just the cat, and then with pedometer integration.

Women Techmakers interview

At this point we have only worked together online, so we were really looking forward to seeing each other at I/O. Then Natalie Villalobos from Women Techmakers gave us a wonderful surprise: she interviewed both of us about Fit Cat!

Fit Cat everywhere!

Google I/O was a perfect place to test Fit Cat since I tend to walk a lot during conferences. I snapped photos of it throughout the day.

My friends started doing the same, and it was so heartwarming to see Fit Cat everywhere!

Only the beginning

It has been such a pleasure working with Virginia. We are already plotting our next projects together, so stay tuned!