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

Download free Android, iOS or Windows Phone apps used in this article and GET FIT!

See also this article on my MSDN Blog

Cross platform apps: dream becomes reality

With recent additions to Visual Studio 2015, it becomes possible to develop apps for all 3 major platforms: iOS, Android, Windows, and also target desktop Windows and OSX. Clearly, the world is changing and I’d like to share my experience in developing rich cross-platform apps that look great and work on iPhone, Android and Windows. Yes, you heard it right, it is now possible to create rich code that compiles to native bits on each platform, with only one code base (or one developer team, with 80-90% code reuse!), all with Visual Studio, C# and .NET. This is very powerful, and clearly developers benefit from this approach by Microsoft: it greatly increases productivity even for small app development teams and allows developers to create native apps that work across all major platforms.

I’ll share more of my experience developing Active Fitness app (http://activefitness.co) for Android, iOS and Windows. You can download the app and see for yourself by clicking the links above and downloading the app for the device of your choice. I want to share the experience of developing these apps, because I feel that it’s a revolution or rather a natural evolutionary step in app development that changes our perception of 3 operating systems incompatibility, and instead focuses on making developers productive.

What’s especially important, Microsoft provides Azure Mobile Services cross-platform libraries for Android, iOS, Windows Phone, Windows and Xamarin, so that developers of cross-platform apps can use cloud resources efficiently.

Designing cross-platform user interface

Mobile user interfaces have changed dramatically since the first iPhone. Windows has Modern Design and Google has Material Design, while Apple made significant changes to its user interface in iOS 8. What is common? Designers call it dropping skeuomorphism, or using material world objects in user interface graphics, and using clean functional design paradigms instead. I like calling a cross-platform combination of Modern Design, Material Design and Apple Design guidelines a pragmatic design, but I don’t pretend that I own the name.

image
From the very beginning I decided to create a common interface design that would satisfy design guidelines of Apple, Google and Microsoft. With Xamarin Forms, a recent addition to Xamarin cross platform suite, available now directly from Visual Studio, it becomes possible, with code re-use close to 80-90%, including user interface! This is a stunning achievement, given that most shops that make apps these days have very experienced developers that know iOS very well, then they need to hire developers that know Android and Windows. The cross-platform native approach taken by Xamarin Forms and other cross-platform tools changes the way developers make apps!

The three screenshots here are from (left to right) Android, iOS and Windows Phone Active Fitness app. They are developed with the same code base, with 100% C# and XAML and naturally fit Apple, Google and Windows ecosystems. The main approach was: keep it simple: keep it beautiful! Modern lines in this design naturally blend with Google Material Design, Windows Modern Design and Apple design, because this design is clean and functional.

Xamarin Forms introduced a set of controls: Pages, Views, Layouts and Cells that blend naturally with all three platforms: Android, iOS and Windows and provide a natural user experience. What’s even more important: one developer or a very small team of developers can now develop for all 3 major platforms (plus OSX and Windows Desktop), with one code, and one language! You can look at Xamarin Forms Gallery to get a feel of what cross-platform controls are available.

Pages

Pages are very natural part of Web sites, as well as native apps in iOS, Android and Windows. Xamarin Forms offer a wide selection of Pages.

Active Fitness app takes advantage of MasterDetailPage which is very popular with Android and iPhone apps. The action bar is also very similar in Android and iPhone apps. In Windows Phone we’re more used to bottom application bar. The “sandwich” icon is becoming very popular to present a “drawer” navigation pattern.  In Xamarin Forms you can use Master Detail page to take advantage of this design. If you look at some of the latest designs for Windows Phone: Facebook app, or OneDrive app implement drawer design pattern, which is also very common in Android and iOS.

 

clip_image008

Layouts

Layouts are ways to align and position controls on your user interface. Most common layouts are grids, stacks, relative or absolute layouts. It’s interesting that while Xamarin Forms use XAML as a metadata language, most layouts and controls are actually very similar to Android AXML objects. Android developers building cross-platform apps find themselves right at home by using Xamarin Forms!

 

Views

Views are often called UserControls in Windows apps. With the cross-platform nature of Xamarin Forms, there’re many views: for labels, entry controls, buttons, date and time pickers, progress controls, and they all look native on the platform you compile the app for:

Cells

Xamarin Forms also provide cells. Cells are specialized elements used for items in tables.

Summary

The cross-platform apps in this example are developed in XAML and C# with .NET that natively runs in iOS, Android and of course Windows. .NET has a long history of open source development, and it now becomes official with Microsoft integrating cross-platform tools with Visual Studio, open sourcing .NET. Many popular 3D games also run on multiple platforms backed by .NET and C#, with Unity. Game designs are very different from other apps, so we’ll focus on Xamarin Froms as technology suitable for cross-platform apps. Interested in this post?

Please, let me know by sending a cheerful COMMENT or twit (@kashleytwit) and I’ll keep this series to tell you more about making beautiful cross-platform apps for Windows, Android and iOS. In the following posts I’ll show you how to make cross-platform apps work with speech, voice, storage, GPS, sensors and more!

Download free Android, iOS or Windows Phone apps used in this article and get fit!

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

Using Hyper-V and Visual Studio with Android x86 KitKat v4.4

Androidx86 is a project hosted on http://www.android-x86.org/. The purpose of the project is porting Android open source project to x86 platform, formerly known as “patch hosting for android x86 support“. The original plan is to host different patches for android x86 support from open source community.

Developers can actually use Hyper-V hosted Android x86 for testing and app development. Hyper-V is built into Windows 8.x and works much faster than Android emulators. In this walkthrough which requires about 10-15 minutes we’ll set up Android x86 in Hyper-V and deploy a Visual Studio Xamarin app to the virtual machine.

Overview

1. Deploy Android x86 in Hyper-V (3 minutes)
2. Deploy your APK from ADB or Visual Studio

Setting up Android x86 on HyperV

Installing Android x86 on Hyper-V is very easy: you create a VM, download Android x86 ISO from http://www.android-x86.org/download and install Android in your VM, like a regular Linux distribution. I used the latest KitKat version: android-x86-4.4-r1-iso Below are step-by-step instructions.

clip_image002

1. Start Hyper-V manager (in Windows 8.x Window-Q Hyper V), then create a new VM in Hyper-V Manager (New / Virtual Machine…)
clip_image004

2. Download Android x86 ISO from http://www.android-x86.org/download

3. Attach ISO to your VM (Media/DVD Drive/Insert Disk…) and select Android x86 ISO

4. Set up Android as you would a Linux distribution: it’ll prompt you to create and format a partition, install GRUB boot loader etc.

clip_image006

clip_image008

clip_image010

clip_image012

5. After the installation, Android x86 runs in your VM. You can now eject the ISO and let the Android boot.

Developing apps using Android x86 in Hyper-V

Android x86 running in Hyper-V is no different from any other Android device or emulator for ADB or Visual Studio. First we need to unlock Android x86 instance for development, then connect our Windows PC to it.

1. In Android x86 press Alt-F1 for command prompt, then type netcfg, which will give you an IP, e.g. 192.168.1.10, press Alt-F7 to go back to graphics shell

2. In Windows PC start ADB command prompt (provided with Android SDK) and type:

adb connect 192.168.1.10

3. If you use Visual Studio for development, for example for Xamarin apps, you can now select Android x86 virtual machine running in Hyper-V

clip_image013

4. Now you can deploy your APK from any file with adb install… or from Visual Studio directly to Android x86 emulator in Hyper-V.

Push Notifications for Xamarin.iOS

Configuring Notification Hubs for Xamarin.iOS apps

Some user devices are iOS-based, some Android, some Windows Phone, and the list goes on. Each of the native platforms has its own push notification framework and backend service. Azure Mobile Services allows the developer to configure a single Notification Hub (based on Microsoft Azure Service Bus Notification Hubs) through which notifications may be sent. The notification goes to each user via the correct push service according to her device’s requirements. Broadcast to millions in consumer scenarios, to tagged groups, to individuals with the same ease.

To use notifications hub from Azure Mobile Services with your iOS apps, you need to generate a certificate, register your iOS app for push notifications, save your certificate to a file and upload to Azure Mobile Services Management Portal, into your Notifications Hub. The whole process of generating a certificate, and configuring Azure Notification Hubs for use with iOS apps here, which is fairly extensive and has some screenshots.

Code snippet: Xamarin.iOS app using Push Notification Hubs

We use Xamarin Forms for best cross-platform portability: we can re-use the same UI and most of the middle tier in our Android project as well.

1. In Xamarin Studio on your Mac, or Visual Studio on your PC, create a new Xamarin Forms project. We will need to use WindowsAzure.Messaging from GitHub. Compile WindowsAzure.Messaging.dll and reference it in your project. This assembly provides iOS bindings for Notification Hub:

clip_image002

2. For Xamarin.iOS project, we need to make some changes in the AppDelegate.cs file. First, start by adding:
SBNotificationHub _hub;

public const string _azureConnection = “<Azure connection string>”;

public const string _notificationHubPath = “<Azure hub path>”;

3. Next in FinishedLaunching method add this to register for remote notifications in your app (providing several types of notifications):

UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(

UIRemoteNotificationType.Alert |

UIRemoteNotificationType.Badge);

4. Add the following methods to handle registration and notification processing.

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)

{

_hub = new SBNotificationHub(_azureConnection, _notificationHubPath);

_hub.UnregisterAllAsync (deviceToken, (error) => {

if (error == null)

{

NSSet tags = null; // create tags if you want

_hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) =>

{

// handle errors here

});

}

else

{

// handle errors here

}

});

}

public override void ReceivedRemoteNotification(UIApplication application, NSDictionary options)

{

if (null != options && options.ContainsKey(new NSString(“aps”)))

{

NSDictionary aps = options.ObjectForKey(new NSString(“aps”)) as NSDictionary;

string alert = string.Empty;

if (aps.ContainsKey(new NSString(“alert”)))

alert = (aps[new NSString("alert")] as NSString).ToString();

if (!string.IsNullOrEmpty(alert))

{

UIAlertView avAlert = new UIAlertView(“Notification”, alert, null, “OK”, null);

avAlert.Show();

}

}

}

We can now register for hub notifications and receive notifications, displaying alerts in our Xamarin.iOS apps.

Reference:

Get started with Notification Hubs with Xamarin.iOS
Xamarin.iOS: Push Notifications in iOS

Native Cross Platform UI Ideas for iOS, Android, Windows Phone with Xamarin

For many developers using C# and coming from the modern UI apps on Windows, developing cross-platform UI design with the best usability for Windows, iOS and Android presents an interesting challenge. First, they feel like they are coming to a more ‘traditional’ UI: let’s face it Microsoft team has created some very advanced and neat design concepts with the modern apps: with Modern design language, minimalism, panorama, motion animations and pivot. How do you translate that into iOS and Android?

Luckily, Xamarin team has done a lot of research porting and thinking through many of these ideas. Xamarin Forms are based on XAML and work on iOS, Android and Windows Phone natively. Here’s some interesting ideas to keep in mind building a cross platform app with Xamarin Forms:

Is cross-platform UI achievable and does it work fast and look native? Thanks to Xamarin team’s efforts the answer to this is yes! You can write UI code that will look and feel native with native speeds on iOS, Android and Windows Phone.

Things to remember: Forms markup uses XAML, but Xamarin team chose to use objects from iOS and Android stack. So instead of StackPanel you get StackLayout, TextBlock is Label. Attributes also resemble those of Android AXML: Visibility becomes IsVisible (we actually like that, it eliminates a converter which otherwise needs to be used on each boolean property). Background color property becomes BackgroundColor, Foreground property becomes TextColor, ForegroundColor etc depending on the context. In other words: instead of cut and paste from Windows Phone you need to really update your XAML. Which makes a lot of sense, Xamarin team chose to use Android/iOS UI elements in XAML.

Xamarin also figured out a very smart strategy wrapping native controls, while maximizing code re-use. On the screenshot below, Xamarin Forms maps control renders as a native Android, iOS and Windows Phone map on each platform.

 

Source: Xamarin: Controls Gallery

Active Fitness with SensorCore – Pedometer + GPS + Social + Action Photo + Music all in one free app

DOWNLOAD new version

Do you need to spend extra bucks on pedometer when you already have a phone? Now with SensorCore technology in latest Windows Phone 630 and other models, your phone can work as a pedometer and count your steps, whether walking or running 24×7. With apps like Active Fitness which already has millions of active users, adding step counter in addition to GPS Tracking adds a battery efficient way and yet another dimension to measuring your sport performance.

wp_ss_20140622_0003

 

Active Fitness unites millions of active users in a fun friendly social sports app and network. Now with new Lumia 630 devices and SensorCore technology, Active Fitness adds battery friendly Pedometer function. Simply take your phone with you and it’ll automatically count steps whole day long! Very little battery consumed. Active Fitness has also been redesigned to benefit from new features of Windows Phone 8.1, you’ll immediately notice many friendly improvements for an already beautiful app. Other features include: multiple activities from a comprehensive library, music, action photos, GPS tracking, goals, training module powered by professional instructors and more!

 

image

Detailed charts of your activity

Active Fitness allows you to drill from monthly to weekly to daily view and then more into every split of your run! Windows Phone brings a clean fresh consistent design and everything about this fitness app looks great.

1

 

DOWNLOAD