A TV Web application is basically a Web site stored on a TV. You can create it using Web-native languages, such as HTML5, CSS, and JavaScript.

Study the following instructions to help familiarize yourself with the Tizen Web application development process as well as using the Tizen Studio and installing the created application on the emulator or target device. With the instructions, you can create and run a basic TV Web application, which displays some text on the screen and changes the text when the user clicks it:

Before you get started with developing Tizen applications, download and install the Tizen Studio.

This step shows how you can create the application UI and make small alterations to it to improve the usability of your application.

When you are developing a more complex application, you can take advantage of the Web tools included in the Tizen Studio to ease the tasks of creating functionality and designing the application UI.

Creating a Project

The following example shows you how to create and configure a basic TV Web application project in the Tizen Studio. An application project contains all the files that make up an application.

The following figure illustrates the application to be created:

The top figure shows the application screen when the application starts. The screen displays the Basic text.

The bottom figure shows the application screen after you click the text. The screen now displays the Sample text. Clicking the text area switches between the 2 texts.

Figure: TV Web Basic application

To create the application project:

Launch the Tizen Studio.

Make sure the Web perspective is selected in the upper-right corner of the Tizen Studio window.

If not, select it. If the perspective is not visible, in the Tizen Studio menu, select Window > Perspective > Open Perspective > Other > Web, and click OK.

In the Tizen Studio menu, select File > New > Tizen Project.

The Project Wizard opens.

In the Project Wizard, define the project details.

The Project Wizard is used to create the basic application skeleton with the required folder structure and mandatory files. You can easily create different applications by selecting an applicable template or sample for the Project Wizard to use.

Select the Template project type and click Next.

Select the profile (TV) and version from a drop-down list and click Next.

The version depends on the platform version you have installed and with which you are developing the application.

Select the Web Application application type and click Next.

Select the Basic UI template and click Next.

Define the project properties and click Finish.

You can enter the project name (3-50 characters) and the unique package ID. You can also select the location and working sets by clicking More properties.

The Project Wizard sets up the project, creates the application files using the default content from the template, and closes. For more information on the Project Wizard and the available templates, see Creating Tizen Projects with Tizen Project Wizard.

You can see the created project in the Project Explorer view. The most important files and folders include:

css: Folder for CSS files used by the application to style its content

js: Folder for JavaScript files used by the application to implement its functional logic

config.xml: Application configuration file used by the platform to install and launch the application

icon.png: Application icon file used by the platform to represent the application

Building Your Application

After you have created the application project, you can implement the required features. In this example, only the default features from the project template are used, and no code changes are required.

When your application code is ready, you must build the application. The building process performs a validation check and compiles your JavaScript and CSS files.

You can build the application in the following ways:

Automatically

The automatic build means that the Tizen Studio automatically rebuilds the application whenever you change a source or resource file and save the application project.

To use the automatic build:

Select the project in the Project Explorer view.

In the Tizen Studio menu, select Project > Build Automatically.

A check mark appears next to the menu option.

You can toggle the automatic build on and off by reselecting Project > Build Automatically.

Manually

The manual build means that you determine yourself when the application is built.

To manually build the application, right-click the project in the Project Explorer view and select Build Project.

Figure: Manually building the application

Alternatively, you can also select the project in the Project Explorer view and do one of the following:

In the Project Explorer view, right-click the project and select Run As > Tizen Web Application.

Alternatively, you can also select the project in the Project Explorer view and do one of the following:

Press the Ctrl + F11 key.

Click the run icon in the toolbar.

If you have created multiple emulator instances, select the instance you want from the combo box in the toolbar before selecting to run the application. If you select an offline emulator, it is automatically launched when you select to run the application.

Confirm that the application launches on the emulator.

While the application is running, the Log view in the Tizen Studio shows the log, debug, and exception messages from the methods defined in the log macros. To see the view, in the Tizen Studio menu, go to Window > Show View > Log.

In Project Explorer view, right-click the project and select Run As > Tizen Web Application.

Alternatively, you can also select the project in the Project Explorer view and do one of the following:

Press the Ctrl + F11 key.

Click the run icon in the toolbar.

If you have both a connected device and existing emulator instances, select the device from the combo box in the toolbar before selecting to run the application.

Confirm that the application launches on the target device.

Note The application is launched using the default debug run configuration. To create and use another configuration:

In the Project Explorer view, right-click the project and select Run As > Run Configurations.

In the Run Configurations window, click the New Launch Configuration icon (), define the configuration details, and launch the application by clicking Run.

Designing a Simple UI

The TV application created with the Basic UI template has a simple user interface with a text component showing the Basic text in the middle of the screen.

The UI is created using W3C/HTML. The W3C specifications provide HTML and CSS features for creating a user interface. With HTML, you can define the structure of the application screens, while CSS allows you to define the look and feel of the screens.

Figure: User interface in the Basic UI template

Creating the Basic UI

The UI in the Basic UI template uses the HTML DOM, which is a structured model to control Web elements. It is an official W3C standard to express the document regardless of platforms or languages, and the foundation of the HTML5 APIs. The template contains the following components:

The <html> element is the top-level element of the HTML DOM tree that wraps the entire document, and it has the <head> and <body> elements as child nodes:

The <head> element contains the information that the browser refers to when rendering the body element to interpret information, such as the title of the HTML document, and the location of the related CSS and JavaScript files:

<title>: Defines the title of the document.

<meta>: Defines information, such as encoding, creator, and keywords of the document.

Modifying Existing Components with CSS

CSS (Cascading Style Sheets) specifies the layout and styling of the Web application.

There are various ways to connect CSS with HTML:

style attribute in an HTML element

<link> element in the <head> element

@import attribute in the CSS area

<style> element in the <head> element

Applying the style of an HTML element directly with the style attribute has the highest priority. On the other hand, creating a separate CSS file and managing it separately is convenient when it comes to applying changes in the future.

In the Basic UI template, the CSS file is connected to the HTML file using a <link> element in the <head> element:

The following lines in the CSS code describe the styling of the text in an element with the content_text class:

.content_text {
font-weight:bold;
font-size:5em;
color:#fff;
}

The text is set to show up as bolded, and colored white (#fff). To change the color of the text, change the CSS code by modifying the color attribute (in this case, it is changed to #2e9afe to make the text blue):