Technology

Google Glass continued..

Anthony Marshall
Anthony Marshall
7 Aug 2014
blog post featured image
Google Glass photo.JPG

Normally, writing the exact same program twice would be discouraged by management, for obvious reasons. Not so at The Technology Studio, where having written an app for Google Glass using the native Android tools, I was instructed to write the same app in C#, still to be run on Glass. This was to be achieved using Xamarin, a cross-platform framework designed to let developers share a codebase between Windows, Mac, iOS, and Android apps by converting C# into the respective languages required for those platforms.

Having worked on various Android projects before this, I at least had a head start when developing for Glass natively, but I had little experience with C#. The most experience I’d had with .NET was being forced to use VB.NET at school. Trying to adapt to three new platforms (C#, Xamarin for Android on top of that, and the Glass GDK on top of those) all at once would prove to be a challenge. I started off by writing a couple of Android apps, just to get to grips with both the language and how Xamarin translated Android-specific functionality across, which proved to be largely intuitive for the most part.

Using the original Java code as reference, I then began slowly building the app from the ground up, using Xamarin’s Google Glass component. I think this might have been more difficult than just trying to write it from scratch. C# and Java aren’t exactly similar, but they have a lot in common. Moving back and forth between the two meant I never really got into the C# mindset, often spending a long time wondering why one particular piece of code wouldn’t work, when the answer was that I was trying to write Java-esque code in C#.

One interesting comparison to make is in the speed of the asynchronous calls made during the Twitter fetches. In both apps, I’m using a library (Twitter4J for the native code, LinqToTwitter for the Xamarin version), and both are being called asynchronously by necessity on Android. Despite this, the Xamarin version is much slower to fetch the results from Twitter than the native version. After some investigation, I narrowed it down to the authorisation step, but beyond that, I couldn’t see why it was such a noticeable difference.

For the most part, I was able to recreate the app properly. Xamarin's Glass component covers pretty much everything in the GDK, but the one notable element missing is the eye gesture detection. This is entirely understandable, given that the eye gesture stuff isn't even publicly acknowledged by Google, and requires a fair amount of effort to get working natively at all. With that exception, the app exists basically in two identical forms.

At its heart, the concept of Xamarin is fascinating. Because this app was so Glass-specific, I didn't really have a chance to explore the cross-platform aspect of it, more just the idea of developing for Android in C#, but I entirely get the appeal. If you’re coming from a C# background, or haven’t used either language before, I’d happily recommend starting off with Xamarin. If I'm honest, though, I'm already used to developing for Android in Java, and I'm probably more likely to continue doing so – at the very least, you don’t need a license to do so.

Google Glass photo by Danlev - Own work. Licensed under CC BY-SA 3.0 via Wikimedia Commons.

Close chatbot
Open chatbot
Open chatbot