Wearables: building cross-platform wearable apps with Visual Studio and C# (Part 2)

Please see: Creating beautiful cross-platform apps for iOS, Android and Windows with Visual Studio. Part I. User Interface

(this is a multi-part series on mobile cross-platform technologies available with Visual Studio)

Microsoft Bing predicts wearables to be the hottest trend in 2015. You can check Bing Predictions technology trends right here: http://www.bing.com/trends/us/predictions/technology. According to these predictions, wearables in 2015 are even more important than personal digital assistants, home automation, 3D printing and virtual reality gaming.  This post continues the series on wonders you can do with cross-platform C# and Visual Studio tools on all kinds of devices: Android, iOS, Windows and now getting to even smaller form factors.

image16

So what are the wearables today: at least devices that are available to developers with existing or upcoming SDKs and APIs? Wearables are definitely in the IoT category: smartwatches, bands, things that we wear on our body to take body-specific measurements. The evolution of watches started a very long time ago, literally centuries ago, with the watch becoming more of a fashion item. Later, fitness bands created a new category of smart wearable devices.

image_thumb4

Let’s compare some wearable devices available today. If we attempt to classify them, they differ in sensors, functionality, price and purpose. In 2015 we will get an idea of market share each of them have, but the most interesting point: devices you see below can be accessed or programmed with C# and Visual Studio!

image_thumb7

Wearables APIs: What’s in common

From the app prospective, since wearables are so lightweight as a platform, they commonly make use of several API tiers that are more specific to small devices:

  • Actionable Notifications: wearables make an extensive use of notifications, including actionable notifications, i.e. those that call back into the host device app, like a phone. You can think of a actionable notification as a message with multiple attached actions-buttons. Android Wear SDK gives a good example of these.
  • Glance, Watchface, Tiles etc – ways to present readable information on the screen. Android SDK has CanvasWatchFaceService for example, which allows developers drawing the face. Microsoft’s concept of tiles is perfect for wearables developers.
  • Apps (optional) – some wearables may or may not have deployable apps (depending on the device and platform) . With apps come specialized controls that can present information on the small screens.
  • History (cloud APIs) – typically wearables synchronize with the phone device and that device in tern synchronizes with the cloud
  • Form factors: Microsoft Band is of band shape, with natural sequence of tiles. Android wear is round and square. Apple watch has a rectangular shape.

    Visual Studio and C# story with Wearables

    With Visual Studio and C# you can develop cross platform wearable apps that run on Android Wear, Apple WatchKit, and we hope to see Band SDK coming out soon. This makes Visual Studio a unique Wearable development platform for all devices. C# is a fantastic language, perfectly suitable for mobile and wearable development. In many ways it is easier to make apps with C# than with the native languages in each platform.

    You can start with these guides:

    Android Wear Developer Preview Now Available

    Introducing the Xamarin WatchKit Preview

    Practical examples of cross-platform apps built with C#

    Here’s a few apps I built with Visual Studio that run on wearables or are capable of interacting with wearable devices.

    Active Fitness

    Active Fitness is a cross-platform (Windows, Android, iOS) fitness, health and sport GPS tracking app and social network of more than a million users. Great for running, walking, cycling, hiking, mountain biking, skiing, snowboarding, urban sports, such as skateboarding, scooter and hundreds of other activities. Active Fitness motivates you by providing ways for sharing your activities with your buddies and friends. Active Fitness has leaderboards for any sports and activities and includes professionally designed training plans. Enjoy and stay fit!

     

    activefitness-watch4

    Winter Sports

    Winter Sports is a cross-platform (Windows, Android, iOS) app, the official app of Professional Ski Instructors of America and American Association of Snowboard Instructors (PSIA-AASI). Beautiful GPS tracking, ski run analytics, snow reports for thousands of resorts, zoomable resort maps, activity tracking, customizable goals, a social network, leaderboards and ski lessons by snow pros. The app includes many innovations, including voice guidance.

     

    ski-snowboard-watch4

  • Winter Sports a showcase cross-platform .NET app available for iPhone users

    Winter Sports, a comprehensive app for skiers and snowboarders is released for iPhone, powered by Microsoft cloud.

    https://itunes.apple.com/us/app/winter-sports-tracker/id927727475?ls=1&mt=8

    Winter Sports is an official app of more than 32,000 Professional Ski Instructors of America and American Association of Snowboard Instructors (PSIA-AASI), an educational organization teaching seven million ski days per season in the US alone. This cross-platform sophisticated app includes ski and snowboard-specific GPS tracker, snow reports and resorts maps from 2000+ ski resorts worldwide, as well as training, workouts and content for skiers, snowboarders, mountaineering enthusiasts and snow junkies.

    FEATURES

    GPS Tracker
    Snow Reports and Resort Maps
    Step Counter
    Friends and Social
    Training and Workouts
    Action Photos
    Ski and Snowboard Analytics
    Worldwide leaderboards
    Powered by Professional Ski and Snowboard Instructors of America

    More about the app…

    Cross-platform apps are becoming very popular with the users, who want to keep their data in sync on iPhone, Android and Windows. Also in line with Microsoft open source . NET Winter Sports became very popular on Windows Phone, grew to millions of users, and now reaches iPhone and Android markets. This app can easily be a showcase of Microsoft’s recent announcement for open-source .NET: a sophisticated native app entirely built with .NET and Xamarin.

    Ultimately, with cross-platform apps, such as Winter Sports, Microsoft wins because the app is using Microsoft’s massive cloud technology called Azure, users win because they can use their favorite mobile device with the app, and developers win because the app works on all major markets: iPhone, Android and Windows. Developers also win, because they only develop one source code, with close to 95% code reuse for Windows, iOS and Android, according to Winter Sports developers.

    Web Site: http://winter-sports.co

    Azure Mobile Services and DateTimeOffset

    Important update: Please, see a comprehensive post by Carlos Figueira that recommends two additional workarounds for this issue.

    I ended up implementing a combination of my approach below and Carlos’ custom JsonConverter.

    I use DateTimeOffset very extensively, my corresponding SQL Azure table in mobile services uses datetimeoffset(3) column. The issue that I had was somewhere during JSON.NET serialization, the DateTimeOffset lost the offset and got converted to UTC. I couldn’t find any solution, until I experimentally started playing with the Mobile Services Client SerializationSettings, exposed in the latest SDK. Changing DateTimeZoneHandling  didn’t seem to help much until I discovered this post by Carlos. I changed it a little bit, keeping the idea, and voila: my DateTimeOffset now saves in Azure Mobile Services, no problem. If you know a better way, please let me know:

     

                    MobileService.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.RoundtripKind;
                    // remove date time converter
                    var conv = MobileService.SerializerSettings.Converters.Where(c => c is MobileServiceIsoDateTimeConverter).FirstOrDefault();
                    if (conv != null)
                    {
                        MobileService.SerializerSettings.Converters.Remove(conv);
                    }
     
     

    Retrieving more data from Azure Mobile Services using paging and LoadAllAsync extension

    Azure Mobile Services allow you to take 50 records at a time by default, or 1000 records at maximum. What if you have more records and want to retrieve the entire table? I just created this beautiful extension method to help you get any amount of data you want, given any page size you want. This simple call to LoadAllAsync will asynchronously load ALL data from a WAMS table in pages of 1000 (or whatever number you specify) records (may also be good for bandwidth reasons):

    var updatedReports = await azureTable.Where(r => r.complete == true).LoadAllAsync();

    And this is an extension method, which elegantly does exactly what it says: loads all data. Enjoy:

            public async static Task<List<T>> LoadAllAsync<T>(this MobileServiceTableQuery<T> table, int bufferSize = 1000)
            {
                var query = table.IncludeTotalCount();
                var results = await query.ToEnumerableAsync();
                long count = ((ITotalCountProvider)results).TotalCount;
                if (results != null && count > 0)
                {
                    var updates = new List<T>();
                    while (updates.Count < count)
                    {
    
                        var next = await query.Skip(updates.Count).Take(bufferSize).ToListAsync();
                        updates.AddRange(next);
                    }
                    return updates;
                }
    
                return null;
            }
    

    Ready to make some money, Windows 8 is coming!


    This weekend I invite you to my session at Silicon Valley Code Camp 2012:

    We’ll discuss Windows 8 Store, monetization and… a bit of a surprise: for the first time I’ll be announcing my book Professional Windows 8 Programming: Application Development with C# and XAML
    , written with a great team of authors: Nick Lecrenski, Doug Holland, Allen Sanders, Kevin Ashley. At this session we’ll focus on practical aspects of monetizing Windows 8 apps. I’ll share some code examples, including: in-app purchase, trial unlocking, placing ads in the apps and using trial model to support monetization. We’ll also touch on more advanced topics, and as an author of several apps in Windows Store, I’ll be happy to answer your questions.

    Windows 7 sold over 500 million copies in just three years, if Windows 8 does that well this is going to be one of the biggest opportunities our industry has ever seen. Come learn how to get your app into the Windows Store and how to make money. After all, you want to be the first app in the marketplace and have the early mover advantage, don’t you?

    SESSION CODE EXAMPLES INCLUDE: Trial, in-app purchases, store simulation.

    1:45 on Saturday

    Foothill College
    12345 El Monte Road
    Los Altos Hills, CA 94022

    http://binged.it/WmQYKH

    Async CTP – Task based asynchronous programming for Windows Phone

    6 code samples for this post

    [my apps for Windows Phone that use Async CTP Smile]

    Intro

    Asynchronous programming is super-interesting especially today, with responsiveness required by all modern devices. In the context of Windows Phone 7, Async CTP Version 3 was released last year, and it’s compatible with SDK 7.1, Silverlight 5 and Roslyn CTP. Our takeaways today is using async in the context of Windows Phone 7, understanding TAP (task based asynchronous programming). I’ll show you how deep the rabbit hole goes: we’ll go beyond basics to exceptions, cancellations, progress, switching threads, combinators and even re-entrancy.

    Historical Background

    And let me just say: it’s worth learning NOW, because this model is quickly becoming mainstream, especially with Windows 8 not that far on the horizon. In terms of the where we are with Async CTP Version 3: you don’t need to wait for C# 5.0 to start using it. It has been a long time since 1960s when Steve Russel was one of the first to add continuations to LISP on IBM 704. I like this definition of continuations:

    Say you’re in the kitchen in front of the refrigerator, thinking about a sandwich. You take a continuation right there and stick it in your pocket. Then you get some turkey and bread out of the refrigerator and make yourself a sandwich, which is now sitting on the counter. You invoke the continuation in your pocket, and you find yourself standing in front of the refrigerator again, thinking about a sandwich. But fortunately, there’s a sandwich on the counter, and all the materials used to make it are gone. So you eat it. :-)

    Scheme formally introduced call/cc operations.

    Continue reading “Async CTP – Task based asynchronous programming for Windows Phone”

    5 Windows Phone games great for holiday travel

    In my previous post we discussed using Expression Blend to create a flipping card animation. Since the Holiday season just started, I’d like to share these games I built, that use this technique. Happy Holidays, have a great holiday season, and for those skiers: Let It Snow!

    Continue reading “5 Windows Phone games great for holiday travel”

    Flipping Card animation for Windows Phone 7 using Expression Blend

    Download Source

    In this post I’ll show you how to create a card flipping animation for Windows Phone 7, using Expression Blend. The source code is available for download in the attachment. First, I create a Windows Phone 7 project from scratch, using Expression Blend, you can also create a project in Visual Studio, right click on any page and select “Open with Expression Blend…” context menu option. I actually used this technique in real Windows Phone games I built:

    ApplicationIconUno
    DUO
    *****
    ApplicationIconCrazyEights
    Crazy
    Eights
    ApplicationIcon101
    101 Card
    Game
    ApplicationIconMauMau
    Mau
    Mau
    ApplicationIconSwitch
    Switch
    *****

    Continue reading “Flipping Card animation for Windows Phone 7 using Expression Blend”