Saturday, June 27, 2015

Pimp Your Watch (a.k.a. WatchPlus update 1.04)

I finally did it - took a break from electronics and stuff, sat on my ass and did the update I promised quite a while ago.

Main features of the new update are:
- Added option to use an image from the watch Gallery as a background
- Added 12 color options (there were no color options before)
- Added option to display seconds

In my opinion seconds are totally pointless and changing the foreground color may be cool but makes visibility worse. But, people asked for these, I promised and delivered.
The idea to use Gallery images as a background was really nice one though . BIG thanks to the dude who suggested it. I only have his e-mail though, so I am not shouting it out :)

The outcome is that you can seriously pimp your watch now :)
And, if a picture is worth a thousand words, here are 15K words:

You know what's funny - I am not going to hate Samsung in this post! Maybe just a little.
I expected to face lots of troubles implementing these features, but at the end they turned up fairly straight-forward.

Well, the 1st attempt to get pictures from Gallery failed miserably. I tried reading the files in the images folder, loading the images and showing them to the user to pick from. It worked, but it was horribly slow. That was because it had to stretch many large images at runtime. I didn't know how to pre-scale an image back them (remember, I am still a noob in this web tech thing).
Fortunately, there was an alternative way - pretty much an API call, which invokes the system default's image picker. There even is a sample how to do that in their SDK.
Of course, I still had to scale the resulting image (the background the user has chosen), but I figured out how to do that anyway (more on that later).

The other "challenge" I expected was how to colorize images - some of the clock styles use bitmap images with built-in light effects in them. So, to change their color I had to process the image and colorize its pixels.
I found many examples how to do that on the web (it is just common HTML5 tech, not Samsung-specific). The pleasant surprise was that it just worked (with my experience with Samsung so far I expected something will go wrong along the way).

The process of "processing" an image looks like this:
- create an offscreen canvas
- draw the image in it (scaling is possible)                                                          (1)
- get a copy of the canvas pixels (an array of RGBA values)                                 (2)
- process the pixels in the array any way you want (colorize them in my case)
- "draw" the array of pixels back to the canvas                                                     (3)
- get an "image URL" from the canvas!                                                               (4)
- create a new image, and tell it to load from that URL (as if it loads from file)       (5?)

If you're wondering what these numbers in parenthesis are - I counted the number of (unnecessary) memory copies in the process. Basically you copy the image twice just to get access to its pixels, and then 2-3 times to convert the result back to an image!

The game programmer in me vomited a little.

I'm pretty sure there is an explanation why it must be done like this, but honestly - I don't want to know.

Still, I was surprised that it actually worked ... and not surprised at all that it was slow.
Initially, changing the color of the clock took above 2 seconds! To be honest, it wasn't that bad, just a shame.
I started thinking of performance optimizations, at some point I caught myself thinking whether it will make a difference if I skip pixels with alpha 0 (because they should be already in the CPU cache) ... then I stopped and told myself "Dude, seriously? This is not game dev, not C++ and not PC. This is javascript running god-knows-how (interpreted?) on an exotic platform. Besides, processing the pixels is not what takes the time, the 4-5 memory copies are. Or at least I would guess so without profile data to prove it."
I could profile it with debug prints, I could delay it over several frames, but it just wasn't worth it.
I ended up with some quick-and dirty optimizations which brought it to about a second. Far from ideal, but in reality - who cares!.
At least it is not Samsung to blame here - looks like the WHOLE WEB works like this.

Ultimately, coding the new update took me less than 2 days. Not so bad.

Preparing the update for submission took me another half a day!
Because I had to prepare new screenshots and the fucking Russian translation!
That Russian translation was a big mistake.
I did it, because Russians are used to see software translated in their language. Several of them asked for translation. So I thought "why not - it would probably increase the sales in Russia".
It didn't.
Instead, sales in Korea grew significantly!
I doubt that is some kind of butterfly effect - more likely Koreans liked the analog clock styles which came with the same update. Or ... my app has been promoted in Korea (I have no way of knowing that) without Samsung telling me.
Anyway, disappointed by our brother Russians, I cut some corners and used the English screenshots in the Russian version (except for the preferences). The difference is only the date anyway.
And this time I translated the texts myself (with the help of google translate, which is crap), instead of bugging my Russian speaking colleagues for help. I don't care.

Finally, all done, checked and double-checked, I go to Samsung's web site and hit the "Update" button. Guess what happened? Nothing. Tried few more times - nope, the "Update" button didn't work!
I laughed out loud.
At the end, logging out and back in to their site solved it, so I was able to submit the update.
If nothing goes wrong, it should be live in about a week.


  1. where do you buy watchplus? I couldn't find any links.

    1. It's in the Samsung Galaxy Apps store - from your phone open Samsung Gear, tap Samsung Galaxy Apps and search for "watchplus". If it is not listed, it probably isn't compatible with your watch - it won't work on Gear S2. It will work on Gear 2, Gear 2 Neo and Gear S and probably on Gear 1

    2. Thanks Michael, I'll take a look.

    3. Thanks Michael, I'll take a look.

  2. i had this app 3 hour ago i deleted i cant find in appstore.can you help me where to find this app? please. thenk you