Top

Creating Tizen Applications using Xamarin.Forms

Creating Tizen Applications using Xamarin.Forms

Native Cross Platform Apps

Xamarin.Forms is a cross-platform UI toolkit that allows developers to easily create native user interface layouts with XAML or C# that can be shared across Android, iOS, and Windows Phone.

Develop native mobile apps, share a lot of the app code and finally deploy it to multiple platforms are the keys of the Xamarin.Forms success. Xamarin.Forms support the following platforms:

  • Android
  • iOS
  • Windows Phone
  • UWP

Between all the petitions and wishes related with Xamarin.Forms, support new platforms is one of the most demanded.

Tizen appears on the scene

Tizen is a mobile operating system based on Linux, sponsored by the Linux Foundation with the aim of supporting a wide variety of devices like tablets, mobiles, wearables, IoT devices, SmartTVs, etc.

tizen

Supported by Samsung in a variety of devices, stands out for require less powerful hardware helping to balance and have a lower consumption.

Currently available on more than 50 millon Samsung devices including SmartTVs, wearables, IoT devices y smartphones.

In the past Microsoft Connect 2016, in San Francisco, Samsung in collaboration with Microsoft announced the initial version in Preview mode of Tizen tool for Visual Studio.

tizen-net

Tizen tools for Visual Studio provide emulator, Visual Studio extensions with Intellisense support and debugging capabilities. Use Xamarin.Forms to define the user interface as we already did with iOS and Android. In this way, Xamarin.Forms include a new platform to expand the possibilities.

Tizen.NET, features and components

Tizen.NET is based on a set of components:

  1. .NET Core
  2. Forms as UI framework
  3. Tizen specific APIs

.NET Core

.NET Core is the development platform developed by Microsoft and the .NET community available on GitHub. With cross platform as one of the main features in, it supports Windows, MacOS and Linux. In addition, it can be used in devices, the cloud or in embedded scenarios or IoT.

.NET Core contains the following parts:

  • The .NET runtime, provides assembly load, garbage collector, native interoperability, and other basic services.
  • A set of libraries that provide fundamental utilities, primitive data types, etc.
  • A set of SDK tools and language compilers that allow you to complete all development needs. Available in the .NET Core SDK.

The use of native .NET offers great advantages:

  • Faster execution times.
  • Faster boot times.
  • Low cost on deployments.
  • Optimization of memory usage.

Xamarin.Forms as UI Toolkit

Xamarin.Forms is a cross-platform UI toolkit that allows developers to easily create native user interface layouts for iOS, Android y Windows. Tizen.NET supports 99% of Xamarin.Forms features. The limitations are:

  • AppLinkEntry
  • PinchGestureRecognizer
  • PanGestureRecognizer
  • OpenGLView
  • WebView
  • OnPlatform<T>
  • PlatformEffect<TContainer, TControl>

Specific Tizen APIs

Tizen.NET allow us to work with the Platform using C#, it exposes the native APIs. Currently, using C# we have support for 60% of Tizen APIs.

tizen-architecture

The supported Tizen APIs are:

  • Applications: Provides a set of APIs related to the application such as managing events related to the state of the application.
  • Content: Content download, storage, type associations.
  • Location: Geographic localization and geofencing.
  • Multimedia: Multimedia services including audio or recording.
  • Network: Control connectivity status or access network information.
  • Security: Secure storage for storing passwords or keys for sample.
  • System: System-specific services, obtain status information, system information, etc.

The installer

Access the official Tizen.NET documentation where we have access to the installer.

download-tizen

After downloading the file, we must install the Tizen.NET tools.

installing-tizen

When completing the installation, we must have everything we need.

To consider:

  • A machine with a 64-bit processor is required.
  • Intel HAXM is required to launch the emulator. Hyper-V must be disabled.

Creating a Tizen application from Visual Studio

Tizen tools for Visual Studio include:

  • Emulator: Use an image of Tizen 3.0 (beta) with support for .NET applications. Previous versions of the emulator do not have .NET support.
  • APIs: Only added Mobile APIs (remember Preview).
  • Extensions: Two extensions add support for editing, debugging or compiling the project.

tizen-extensions

We will create a Xamarin.Forms project with Tizen support. When creating the project, we have different project templates.

tizen-templates

Under the Tizen tab we have:

  • Blank App (Tizen Xamarin.Forms Portable): Creates a solution with a portable library and a native Tizen.NET project.
  • Blank App (Tizen Xamarin.Forms Single): Only creates the Tizen project. Ideal to add to a ready-made Xamarin.Forms solution.
  • Class Library (Tizen): Library with Tizen Support.

We select the first option. After creating the Project, we will see a solution with two projects:

  • A project named <projectname> of portable type that contains all the code Xamarin.Forms.
  • Another project called <projectname>. Tizen that contains all the code needed to initialize the application with the Tizen framework.

To deploy the application to the emulator, simply press F5 or press the Play button.

tizen-compile

After a few seconds the icon of the application should appear in the emulator allowing access to it.

xamarin-forms-tizen

NOTE: The initial emulator boots responsible for unpacking the necessary image. The process may take a few minutes.

Next, we’ll create an application with some features using MVVM to display a list of monkeys.

However, before develop the application, we will review the Tizen project structure. Let’s ignore the content of the portable library to be the same we already had in a Xamarin.Forms application.

In the Tizen project we have:

  • A shared folder that will contain elements related to the application. The application icon is packaged in the shared/res directory.
  • The res folder will contain resources for the application. For example, if your application needs a file at runtime, this is your place.
  • The lib folder contains the generated code of the application.

We also have a very important file, tizen-manifiest.xml. The manifest file is a configuration file with data of the application such as name, icon, package, etc.

After analyzing the structure of the project, we continue with our application. We start creating the folder structure:

tizen-project-structure

We continue creating the data model, a class called Monkey that will define each monkey in the list:

public class Monkey
{
    public string Name { get; set; }

    public string Location { get; set; }

    public string Details { get; set; }

    public string Image { get; set; }
}

Continue defining the view model:

public class MonkeysViewModel
{
    public ObservableCollection<Monkey> Monkeys { get; set; }

    public MonkeysViewModel()
    {
        Monkeys = new ObservableCollection<Monkey>
        {
            new Monkey
            {
                Name = "Baboon",
                Location = "Africa & Asia",
                Details = "Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae.",
                Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg"
            },
                  ...
            };
      }
}

Finally, is time to define the UI. To do this we will use the main view in XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TizenMonkeys.Views.MonkeysView"
             xmlns:templates="clr-namespace:TizenMonkeys.Views.Templates;assembly=TizenMonkeys"
             Title="Monkeys Tizen.NET">
    <ListView
        ItemsSource="{Binding Monkeys}"
        RowHeight="80"
        HasUnevenRows="true">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <templates:MonkeyItemView/>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage>

If we compile and execute the project:

tizen-net-xamarin

Awesome, right? Tizen.Net opens a world of possibilities in a simple way to open the range of supported devices.

We love the idea, what do you think?.

Tizen.Net, what’s next?

The goal is to continue adding extensions that facilitate the creation of awesome applications. The points on the roadmap are:

  • Increased support for Tizen APIs.
  • Add different profiles (TV, mobile).
  • The source code will be uploaded soon (as the rest of Xamarin.Forms is available in GitHub).
  • More examples using Tizen.NET.

One more thing

To encourage developers to create applications for Tizen, Samsung has created the Tizen Mobile App Incentive Program.

tizen-incentive-program

Samsung invest $9 million over the next 9 months. Each developer can get great rewards if the application appears in the monthly Top 100 applications.

Javier Suárez Ruiz
No Comments

Post a Comment