Saturday, 21 February 2015

Apple Watch Kit round-up

It's Saturday, a good excuse for a 'fun' post. Here's a little collection of tidbits about the Apple Watch...



Apple: Watch Kit - if you're thinking of developing for the platform, might as well start at the source :)

Wareable: The best Apple Watch apps... - some great screenshots of apps already being built, including Clear, BMW, and Nike. It's interesting to see the UI design approach being taken by different developers. Check out the similar list on ibtimes.com

FastCompany: How the Apple Watch will work... - a couple of thoughts on app design, and screenshots of Todoist.

eleks labs' unofficial Tesla app - more design thoughts and prototype video (unofficial development, not affiliated with Tesla)..

Daring Fireball: On the Pricing of the Apple Watch - so yeah, "starting at $349" sounds like it's going to be the understatement of the year.

WatchKit FAQ - Awesome collection of questions and answers (and cute watch drawings too).

If that's got you interested in building apps for the Apple Watch, it's time to check out Xamarin's Watch Kit Preview and how to get started (inc video) and my first watch app.



I've also got a couple of samples, including Magic 8 Ball, Calculator, Insta, and Todo for you to try.

^ watch frame screenshots generated with Bezel thanks to the fine folks at infinitapps.

Tuesday, 20 January 2015

Apple Watch Kit programming with C# (and Xamarin)

For my "Your First Xamarin.Forms App" talk at Evolve this year I built a very simple version of the classic "Magic Eight Ball" fortune-telling app. Seemed like a perfect example to adapt for my First Apple Watch App. It's built in C# using Xamarin (of course); Xamarin's Watch Kit Preview came out today!

Here is the finished app: a simple display that answers any question you ask ;-) Force Touch on the screen to pop-up the menu to ask another question (Shake), or simply say "Thanks". Grab the code from Github.
^ watch frame screenshots generated with Bezel thanks to the fine folks at infinitapps.

Apple Watch Projects

The solution structure for watch apps consists of three projects (notice that watch apps are split in two parts):
  • an iPhone app which delivers the watch app to the user (and is also obviously a regular iPhone app),
  • an Watch Kit Extension where the code for the watch app runs (on the iPhone, but separate to the iPhone app),
  • a Watch app which is only the storyboard and image resources that go to the watch itself.

Storyboard User Interface

After creating the three projects in a new solution, the first step is to draw the user interface in Interface Builder. Right-click on the Interface.storyboard (already in the template) and open in Xcode.

I did the following:
  • gave the interface controller a Title: 8Ball
  • dragged a Label and centered it
  • Ctrl + dragged an outlet from the label into the header file called result
  • dragged a Menu onto the scene (this is triggered by Force Touch)
  • added and named the two MenuItems: Shake & Back
  • Ctrl + dragged an action from the first menu item called shake
Remember: the storyboard (and any image resources) are the the only things that get installed on the watch itself.

WatchKit C# Code

With the user interface defined in the storyboard, I just needed to wire-up the outlet and action I created in C# to make the app work. The C# code will run in the Watch Kit Extension - on the iPhone itself, not on the CPU of the watch.

First I copied the Magic Eight Ball responses from my Xamarin.Forms app (it's a simple string array, called options) and then I started to implement methods in the InterfaceController.

The Awake method is called when the scene is created, so this is where the code selects its first random response to show the user. I store it in a local variable lastResult and also in NSUserDefaults (for the Glance, explained later).

public override void Awake (NSObject context)
{
 base.Awake (context);
 var rnd = new System.Random();
 lastResult = options[rnd.Next(0, options.Length - 1)]; 
 NSUserDefaults.StandardUserDefaults.SetString 
  (lastResult, "lastResult");
}

Then in WillActivate I set the label's text to the random value:

public override void WillActivate ()
{
 result.SetText (lastResult);
}
Finally, the menu's Shake button should choose a new random response, so the action is implemented to generate new new answer, set the local lastResult variable, the NSUserDefault, and also the label's text.

partial void shake () {
 var rnd = new System.Random();
 lastResult = options[rnd.Next(0, options.Length - 1)]; 
 result.SetText (lastResult);
 NSUserDefaults.StandardUserDefaults.SetString 
  (lastResult, "lastResult");
}

That's all the code required to get the app running! I did a couple more things, however, to demonstrate how to programmatically modify the Menu...

In the Awake method I add another menu item called Thanks:

AddMenuItem (WKMenuItemIcon.Accept, "Thanks", new ObjCRuntime.Selector ("tapped"));
The Selector is implemented as shown - notice the [Export] is required:
[Export("tapped")]
void MenuItemTapped () {
 result.SetText ("You're welcome!");
}

Glance Mode

I also implemented Glance mode, which simply displays the last response generated by the app.

The watch app template already includes a GlanceInterfaceController so I just had to drag a couple of Labels onto it, and Ctrl + drag an outlet for one, so I could change the text programmatically.



Because I always store a generated result in NSUserDefaults the GlanceInterfaceController, the code for the glance is really simple:
var r = NSUserDefaults.StandardUserDefaults.StringForKey("lastResult");
lastResult.SetText (r);


Currently you cannot test Glances from within Xamarin Studio, but it's easy to trigger it using Terminal and the following command (make sure you update path to match your app):

/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --sdkroot=/Applications/Xcode-Beta.app/Contents/Developer/ --device=:v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-8-2,devicetype=com.apple.CoreSimulator.SimDeviceType.iPhone-6 --launchsimwatch=/Users/craigdunn/Projects/Watch8Ball/Watch8Ball/bin/iPhoneSimulator/Debug/Watch8Ball.app --watchlaunchmode=Glance

The finished glance display looks like this:

And that's it! Around 10 lines of C# code to build an Apple Watch app.

Download the Xamarin Watch Kit Preview, get the code from Github and try it for yourself!

Saturday, 17 January 2015

Microsoft Band: the end

I had a lot of fun with the Band initially.

Then after literally two seconds in the shower after a long run, it died. I doubt it got that wet - I literally stepped into the shower, noticed the Band was still on my wrist, then took it off and placed it out to dry.

But that was enough to kill it. The screen went all crazy and illegible. It was dead.




I had paid the $20 'extended warranty' fee, so the guys at the Microsoft Store grudgingly replaced it. I say grudgingly because one staff member really didn't seem sure about it; luckily another guy got involved and was more than happy to help me. They made it clear that if I hadn't paid for the extended warranty, they would not be replacing it at all.

Then they asked for another $20. To cover this Band with extended warranty. I was very annoyed by this. I didn't pay. But now I'm too scared to use the Band. What if, while running outdoors, it rains? The Band apparently will die at the slightest hint of water, and next time Microsoft promised they would NOT be replacing it unless I paid the additional $20.

So now I hardly wear it. It's in a drawer somewhere. So long, Microsoft Band, I hardly knew yea...

Microsoft: if you put a GPS in a fitness device, you're saying it's okay to use it outdoors. If that same device fails in the slightest mist of rain, the device itself is a failure.

Thursday, 6 November 2014

Microsoft Band (day 7: heart rate)

So far I've had the Band a week, and it's been on my wrist almost every second of that time (except charging). I'm surprised by how easily I got used to wearing it - it is still chunky, but light enough that I can cope :-)

The one remaining question people have asked is how good the heart-rate sensor is, so I did a couple of tests today both running and walking/sitting. I used the Band in conjunction with a Polar H7 chest-band paired with both the Polar and Strava apps. 


I expected the results to be pretty close (given how good the GPS performance is on the Band)... but turns out, not so much. Here's the heart-rate data from the Band - seems consistent with an average of 165 bpm (high of 177).


The Polar H7 chest strap data was slightly different though. Here is the graph from the Strava app; it recorded an average of 149 bpm (high 159).


And of course you can view the data from the Polar chest-strap in more detail on the Strava website:


So there's a bit of variation between what the Band reports and what was recorded on the chest-strap. I did another test just walking for 20 minutes; with the following result:

  • Microsoft Band reported average 107 bpm (high 147)
  • Polar H7 chest-strap reported average 81 bpm (high 93)

Only on the internet could two tests be considered a statistically valid sample, but there you go - looks like the Band's heart-rate sensor is not as accurate as a chest-strap ;-) In reality, any number of factors could contribute to the difference: maybe I didn't have the Band on tight enough, maybe face-up versus face-down on my wrist makes a difference, maybe the strap is the bad data, who knows?!


The Bottom Line

That's all the blog posts for now - my first week with the Microsoft Band is done.

Overall I still like it - I've gotten used to having it on, the sleep data is new and interesting, and it's a good run tracker (the GPS is as good if not better than my Garmin - and it definitely finds the satellites quicker). I love the notifications on the Band: text messages, email, Facebook, etc... these could be the things that keep me using it after I get bored of the other stuff :)

The negatives are minor, but important for some. The battery realistically only lasts a full day - the minute you use the GPS functionality you're going to have to charge again within 24 hours. People report longer times but I doubt you are really getting the full use of the watch if you're stretching the battery so long. The other hardware issue is the question-mark over the heart-rate sensor ~ I'll leave it for people with more patience than me to do an exhaustive test, but as the disclaimer says "this is not a medical device" and it's probably as good as you can expect for a device of this size.

Finally, though, even assuming the battery lasted a week and the HR was spot-on, I would still not be able to use the Band as my only fitness-tracking device, purely because the data is locked into the Microsoft Health ecosystem. While there is no way to export ALL the data (into Strava or similar systems) I'm just not willing to give up my current devices.

Wednesday, 5 November 2014

Microsoft Band (day 6: data)

Short update today, answering two questions I've heard a lot about the Band:

  • Can the data be exported?
  • Does it work for cycling?

Can data be exported?

The short answer here is "no"; at least I have not found a way to get any of the raw data out of the Band or the Microsoft Health app. There are Connected Apps partners with Microsoft, including RunKeeper, so I signed up for their service to see how much data is shared.

The first problem with Connected Apps is that (apparently) your past data is not shared. This meant that after I joined there was no way for me to upload the half-marathon data from last weekend. New activities, however, seem to appear on RunKeeper as soon as they're sync'd to Health.

The second 'problem' is that only a summary of each activity is available... here is the information available on RunKeeper after a 5 km run this evening:


No details are available in the Connected App - no kilometer splits, elevation chart, map track or heart rate data :-( I would really like to get the running data (heart rate, GPS track as GPX) from my Band activites, and/or sync them automatically with Strava... however if the only integration possible with Strava is a 'summary' such as that shown above - I wouldn't bother!

Interesting statistic shown on the RunKeeper website...
1139 RunKeeper users also use this app
I wonder just how many Bands have been sold so far...


Does it work for cycling?

There's no particular reason why the Band won't collect data (GPS track, heart rate, etc) from a cycling effort as well as a run... I tried it out and it works fine. The problem with this is categorizing that workout in your training records. The speed/average pace recorded for a bike ride will far exceed your running capacity ;) and the heart-rate will be a lot less; making the calorie calculations also useless. 

If metrics are important to you (and they probably are, if you're reading this), then "no" the Band isn't much use for cyclists compared to the myriad of other options available.

Monday, 3 November 2014

Microsoft Band (day 5: rest)

No running after the half-marathon, so I thought I would blog some random info about the Band today.

Configuring the Run tile

I mentioned that you can change which stats are displayed while running - to do so click on the Band (top-right of screen) and choose Manage Tiles. This shows the list of available tiles with a 'switch' next to each that lets you show/hide the tile on your Band.

Some tiles have additional options (indicated by an 'edit pen' icon). Touch the row to configure; in the case of the Run tile it will display a screen explaining the options and an Edit button at the bottom of the screen. The final Run Settings screen lets you click to edit which run statistics are displayed on the Band screen:

Finding your historical heart-rate data

I just assumed that the band was monitoring my heart-rate and step-count all the time, but it took me while to find the data in the app. You would expect to access it somewhere in the Activity History screen, but that only contains Runs, Workouts, and Sleeps.

Instead touch the steps count on the main screen. This will take you to the rendering for a the current day's steps (as a histogram), with heart-rate graphed in the background. Touch the graph to switch to heart-rate view; or scroll down to view past day's step summary... notice the gap in this data (middle screenshot) -- the Band was off my wrist for charging :-)


You can display data for past days by tapping one of the past-day rows. The historical data has a darker header color (almost black, not purple), and you can view the steps and heart-rate data throughout the day... this is half-marathon race day:

Flashlight!

Just kidding... kinda. There isn't a Flashlight tile... but it is amazing how much light the Band emits when showing the menu (I've chosen a lime green theme, so it's quite bright). In a darkened house I can easily navigate around using the ambient light from the Band's screen...

If you want total darkness from your Band, enter sleep mode (if you're actually going to sleep) or else turn Watch Mode off so that the screen doesn't even show the time.

Sunday, 2 November 2014

Microsoft Band (day 4: race)

Today I wore both the Band and my Garmin Forerunner 10 in the US Half-marathon (San Francisco) to compare their usability while running and the data they collect.



TL;DR I love having the extra data from the Band after the race (eg. heartrate) but without Strava integration to view the data in more detail I can't leave my Garmin behind just yet. Sadly the secondary readouts (heart-rate and distance) on the Band seem too small to read easily while racing.

The Band

I wore the band on a different wrist to the watch and it definitely felt heavier than the Garmin, however I hardly noticed the difference once I started running. I started the GPS detection at the same time on both devices; the Band was ready to go a lot faster than the Garmin.

As I mentioned in an earlier post: I love that the Band has the heart-rate and GPS sensors built-in, so it can do all this without requiring a phone nearby!

The Race

While running both devices seemed to keep similar distance/pace time, with the km splits being pretty consistently recorded. The Garmin beeps at a km split which is fine, but sometimes I hear the beeps from other runners' watches around me and I look down for a split and it's not there. The Band vibrates so there's no false-positives... I know when I glance down that the split time will be there. The more direct feedback is a nice touch :-)

The 'run tile' display looks like this (apols for the image quality):


I've configured it via the app Band > Manage Tiles > Run to show heart-rate, distance, and duration. This means the pull-down drawer will show calories and current pace. Double-tapping the action button will cycle between the currently displayed data so that each element occupies the bottom (larger) position. This is useful, since I found it tough to read the two smaller numeric readouts while running... I almost wish the entire display could be set to show one stat really large, and the double-tap could then cycle between that view and the more crowded setup shown above...

I mainly glanced down at the Band when it vibrated to indicate a km split; it was slightly easier to read that view (I think because the numbers weren't changing). I didn't find myself looking at the heart-rate display much during the race... maybe because I wasn't sure to do with that information anyway.

I used the Garmin more frequently to gauge my progress since I found its display easier to read on-the-run.

The Results

The main reason to wear both devices was to compare the results - Microsoft Band and Health app versus Garmin Forerunner 10 and Strava - so here they are:

Summary

The Garmin slightly over-estimated the distance (but so did the Band, by slightly less) - they are both accurate enough, but I guess the Band did better. The average pace is the same for both, however the calories estimate is again way off. I've no idea how it decides the Fats and Carbs calorie numbers... nor which is more "correct".

The Microsoft Health app has the heart rate info: average, high, and low; and also the Recovery Time which I presume is some sort of indication of how long you should wait before exercising again? They really need to help us out with how interpret some of this stuff!


Pace

The pace data for the Band is shown along with the heart rate and elevation in graph form (below). The problem with looking at this information in the app is how compressed it is - you can't easily "zoom in" to see the variations in pace or elevation over time.


By contrast, the same data in Strava (minus heart rate, which my Garmin watch doesn't record) is much easier to interpret:


Until Microsoft Health has similar visualizations (or they are able to integrate with Strava), I won't be able to use the Band on its own... I like these graphs too much :)

Map

Here's the two maps side-by-side. The GPS accuracy seems fine for both devices - neither had a major error (which does sometimes happen). Microsoft Health has the neat speed-coloring, but again it's hard to see the details inside an app. The Garmin data rendered by Strava is much easier to zoom in and browse around.


Splits

Finally, just for the sake of it, here's the two sets of splits from the Band and the Garmin. Easily close enough to be considered equally accurate over the distance. The nice thing about the Strava presentation (which you can't see here) is how interactive their rendering is: hoving over a split highlights the map and helps you visualize the elevation and location on the course.

The Battery

Because I wore the Band overnight I only had a short time to re-charge it before the race, so it was showing as 80% charged when I left for the start line. To really test it, I left the display lit the entire race (although you can press the power button to show and dim it while running). At the end of the race (around 90 mins) the battery indicator looked to be around 50%... it's not very accurate but perhaps some indication of how long the battery could last while running with GPS enabled. The Band worked throughout the rest of the day - receiving notifications and step-counting - finally complaining about low-battery around 8pm... a little over 12 hours of use including the race.

Conclusion

I still really like the Band (despite this little problem) and will continue to train with it in addition to my Garmin for a while yet. Some of the non-running functions (like notifications) have been almost as much fun to play with as the running features :)