App Development Guide for Samsung Smart TV[V1.20]

download App Development Guide for Samsung Smart TV[V1.20]

of 100

Transcript of App Development Guide for Samsung Smart TV[V1.20]

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    1/100

    Application Development Guide

    for Samsung Smart TV

    Version 1.20

    Samsung Smart TV

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    2/100

    Application Development Guide for Samsung Smart TV

    2

    APPLICATION DEVELOPMENT GUIDE FOR SAMSUNG SMART TV .......................................................... 1PREFACE............................................................................................................................................................................ 71. INTRODUCTION .................................................................................................................................................... 8

    1.1. WHAT IS SAMSUNG SMART TV? ............................................................................................. ............................. 82. SAMSUNG SMART TV ........................................................ .............................................................. ..................... 9

    2.1. OPERATING PRINCIPLE ......................................................................................................................................... 92.2. OPERATING ENVIRONMENT .................................................................................................................................. 9

    3. APPLICATIONS .................................................................................................................................................... 103.1. WHAT ARE APPLICATIONS? ........................................................... .............................................................. ........ 103.2. STRUCTURE OF AN APPLICATION ........................................................................................................................ 103.3. DISPLAY TYPE OF APPLICATIONS ........................................................................................................................ 113.4. RUNNING AN APPLICATION................................................................................................................................. 123.5. APPLICATION MANAGER.................................................................................................................................... 123.6. FEATURES OF SAMSUNG APPLICATIONS............................................................................................................. 13

    4. CREATING AN APPLICATION .............................................................. ............................................................ 144.1. WHAT YOU NEED TO CREATE AN APPLICATION.................................................................................................... 144.2. HOW TO MAKE AN APPLICATION ........................................................................................................................ 14

    4.2.1. Writing config.xml ............................................................... .............................................................. ........ 154.2.2. Writing index.html ............................................................... .............................................................. ........ 164.2.3. Writing JavaScript .................................................................................................................................... 164.2.4. Writing a CSS ........................................................... ................................................................. ................ 174.2.5. Use of the remote control .............................................................. ............................................................ 184.2.6. Complete your work & Sample code ........................................................ ................................................. 20

    4.2.6.1. config.xml ...............................................................................................................................................................204.2.6.2. index.html ...............................................................................................................................................................214.2.6.3. Main.js ....................................................................................................................................................................214.2.6.4. Main.css ..................................................................................................................................................................22

    4.3. CONFIG.XML....................................................................................................................................................... 234.3.1. Tag information ........................................................ .............................................................. ................... 234.3.2. Example .................................................................................................................................................... 26

    4.4. SINGLE-SIGN-ON............................................................................................................................................... 274.4.1. What is Single-Sign-On ................................................................. ............................................................ 274.4.2.

    Registration of Account Information on Service Sites............................................................................... 28

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    3/100

    Application Development Guide for Samsung Smart TV

    3

    4.4.3. How to download account information on service sites in applications ................................................... 304.5. RESET ................................................................................................................................................................ 32

    4.5.1.

    What is Reset? .......................................................... ................................................................. ................ 32

    4.5.2. How Reset Works? ............................. ................................................................. ...................................... 324.5.3. Necessary Features Developers Should Realize ............................................................ ........................... 324.5.4. Guide for Config.xml Realization ....................................................................... ...................................... 324.5.5. Guide for Module Realization ....................................................... ............................................................ 32

    4.6. EXAMPLE FOR XHR COMMUNICATION .............................................................................................................. 345. COMMON MODULES ......................................................... .............................................................. ................... 37

    5.1. APPLICATION MANAGERS COMMON MODULES ................................................................................................. 375.2. HOW TO USE COMMON MODULES....................................................................................................................... 375.3. TVKEYVALUE ................................................................................................................................................... 375.4. WIDGET............................................................................................................................................................. 40

    5.4.1. sendReadyEvent() ..................................................................................................................................... 405.4.2. sendExitEvent() ........................................................ .............................................................. ................... 415.4.3. sendReturnEvent() .................................................................................................................................... 415.4.4. blockNavigation() ..................................................................................................................................... 415.4.5. putInnerHTML() ....................................................................................................................................... 425.4.6. getChannelWidgetListPath() .......................................................................................... ........................... 435.4.7. getSearchWidgetListPath() ........................... ................................................................. ........................... 435.4.8. runSearchWidget() .............................................................. .............................................................. ........ 445.4.9. checkSapTicket () .......................................................................... ............................................................ 445.4.10. requestSapTicket () .............................................................. .............................................................. ........ 45

    5.5. PLUGIN .............................................................................................................................................................. 455.5.1. setOnWatchDog() ................................................................................................................... ................... 475.5.2. setOffWatchDog() ................................................................ .............................................................. ........ 475.5.3. setOnOSDState() ................................................................ ............................................................... ........ 485.5.4. setOffOSDState() ................................................................ ............................................................... ........ 485.5.5. registKey()................................................................................................................................................. 495.5.6. unregistKey() ............................................................ ................................................................. ................ 495.5.7. registIMEKey() ......................................................................................................................................... 495.5.8. unregistIMEKey()...................................................................................................................................... 505.5.9. registAllKey............................................................................................................................................... 505.5.10. unregistAllKey() ................................................................. ............................................................... ........ 515.5.11. registFullWidgetKey() ............................................................................................................ ................... 515.5.12. registPartWidgetKey() ........................................................ .............................................................. ........ 52

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    4/100

    Application Development Guide for Samsung Smart TV

    4

    5.5.13. SetBannerState() .................................................................................................................... ................... 525.5.14. ShowTools()............................................................................................................................................... 535.5.15.

    setOnIdleEvent() .................................................................................................................... ................... 54

    5.5.16. setOffIdleEvent() ................................................................ ............................................................... ........ 545.5.17. setOnScreenSaver() ............................................................. .............................................................. ........ 545.5.18. setOffScreenSaver()................................................................................................................................... 555.5.19. isViewerKey() ........................................................... ................................................................. ................ 555.5.20. setOnFullScreen () ................................................................................................................. ................... 565.5.21. setOffFullScreen() ............................................................... .............................................................. ........ 56

    5.6. CIMAGEVIEWER ................................................................................................................................................ 575.6.1. CImageViewer? ........................................................ .............................................................. ................... 575.6.2. Specifications ........................................................... ................................................................. ................ 575.6.3. Basic Instructions ..................................................................................................................................... 575.6.4. Transition Effect ................................................................. ............................................................... ........ 58

    5.6.4.1. Action Principles of Slideshow ...............................................................................................................................595.6.4.2. How to Realize Transition Effect ............................................................................................................................605.6.4.3. Slideshow Mode and Restrictions ...........................................................................................................................61

    5.6.5. Events ............................................................ ................................................................. ........................... 625.6.6. Play local files .......................................................................................................................................... 62

    5.6.6.1. Play Images in an Application ................................................................................................................................625.6.6.2. Play images in USB ................................................................................................................................................63

    5.6.7. Reference................................................................................................................................................... 645.6.7.1. CImageViewer ........................................................................................................................................................645.6.7.2. Effect ......................................................................................................................................................................655.6.7.3. clearScreen() ...........................................................................................................................................................665.6.7.4. destroy() ..................................................................................................................................................................665.6.7.5. endSlideshow() .......................................................................................................................................................675.6.7.6. getStopFlag() ..........................................................................................................................................................675.6.7.7. hide() .......................................................................................................................................................................685.6.7.8. isEffectAvailable() ..................................................................................................................................................685.6.7.9. play() .......................................................................................................................................................................685.6.7.10. prepareNext() .....................................................................................................................................................695.6.7.11. setFrameArea() ...................................................................................................................................................705.6.7.12. setOnBufferingComplete() .................................................................................................................................715.6.7.13. setOnBufferingStart() .........................................................................................................................................715.6.7.14.

    setOnNetworkError() ..........................................................................................................................................72

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    5/100

    Application Development Guide for Samsung Smart TV

    5

    5.6.7.15. setOnRenderError() ............................................................................................................................................725.6.7.16. setOnRenderingComplete () ...............................................................................................................................735.6.7.17.

    show() .................................................................................................................................................................73

    5.6.7.18. showNow () ........................................................................................................................................................735.6.7.19. startSlideshow () .................................................................................................................................................745.6.7.20. stop () .................................................................................................................................................................75

    6. TIPS FOR APPLICATION DEVELOPERS ........................................................................................................ 766.1. FUNCTION NECESSARY TO BE CALLED WHEN YOU OPEN AN APPLICATION .......................................................... 766.2. ACCESS POINT ................................................................................................................................................... 766.3. HANDLING REMOTE CONTROL KEY EVENTS ....................................................................................................... 766.4. REMOTE CONTROL KEYS FOR APPLICATIONS...................................................................................................... 776.5. CLOSING AN APPLICATION.................................................................................................................................. 796.6. PREVENTION OF CLOSING THE TV SCREEN BY THE RETURN OR EXIT KEY.......................................................... 796.7. ADDITIONAL INFORMATION ............................................................................................................................... 796.8. WHAT CSS NEED TO CONTAIN ........................................................................................................................... 806.9. LOADING IMAGES IN ADVANCE .......................................................................................................................... 806.10. CHARACTER OF THE TAG ................................................................................................................. 816.11. SCROLL BAR ...................................................................................................................................................... 816.12. MAKING DYNAMIC WEB PAGES ...................................................................................................................... 816.13. SETTING FOR LETTER-SPACING ...................................................................................................................... 826.14. MEMORY MANAGEMENT................................................................................................................................ 82

    6.14.1. Using XMLHttpRequest ............................................................................................................................ 826.14.2. Freeing up the memory ............................................................................ ................................................. 82

    6.15. WATCH DOG .................................................................................................................................................. 826.16. PREVENTION FOR OSD DISTORTION............................................................................................................... 836.17. SUPPORT CSS TEXT-OVERFLOW..................................................................................................................... 836.18. DIRECTIONS FOR CREATING VIDEO APPLICATION............................................................................................ 836.19. USING IME ........................................................ ................................................................. ........................... 836.20. MINIMIZING INITIAL ENTRY SPEED OF AN APPLICATION.................................................................................. 83

    6.20.1. Load Javascript On-Demand ........................................................ ............................................................ 836.20.2. Load CSS Background Image On-Demand ......................................................... ...................................... 846.20.3. Separation of Main.onLoad functions ................................................................ ....................................... 84

    6.21. DIRECTIONS FOR DYNAMIC LOADING OF CSS ....................................................................................... ........ 857. APP ENGINE .............................................................. ................................................................. ........................... 87

    7.1. APP ENGINE? ......................................................... ................................................................. ........................... 87

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    6/100

    Application Development Guide for Samsung Smart TV

    6

    7.2. STANDARD SPECIFICATIONS............................................................................................................................... 878. FILE API ................................................................................................................................................................. 88

    8.1. FILE API? .......................................................................................................................................................... 888.2. API ............................................................. ................................................................. ...................................... 88

    8.2.1. FileSystem() .............................................................................................................................................. 888.2.2. openCommonFile() ............................................................. .............................................................. ........ 898.2.3. closeCommonFile() ............................................................. .............................................................. ........ 908.2.4. deleteCommonFile() ................................................................................................................................. 908.2.5. createCommonDir() ............................................................................................ ...................................... 918.2.6. deleteCommonDir() .................................................................................................................................. 918.2.7. isValidCommonPath() ......................................................................................... ...................................... 928.2.8. readLine() ................................................................................................................................................. 928.2.9. writeLine() ................................................................................................................................................ 938.2.10. readlAll() ....................................................... ................................................................. ........................... 938.2.11. writeAll() ....................................................... ................................................................. ........................... 948.2.12. readDir() ....................................................... ................................................................. ........................... 948.2.13. openFile() ................................................................................................................................................. 95

    9. APPENDIX ....................................................... ................................................................. ...................................... 969.1. COUNTRY CODE................................................................................................................................................. 969.2. LANGAUAGE CODE............................................................................................................................................ 979.3. REGION CODE.................................................................................................................................................... 999.4. PRODUCT CATEGORY ....................................................................................................................................... 1009.5. CAUTION INFORMATION................................................................................................................................... 100

    9.5.1. Character sensitive target device ............................................................. ............................................... 100

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    7/100

    Application Development Guide for Samsung Smart TV

    7

    Preface

    Purpose of Document

    This document is written to help application developers who enjoy the Samsung Smart TV service by

    providing an overview of the service and basic knowledge required to be obtained by application

    developers. Using this document, developers can develop and manage applications for digital TVs.

    Target ReadersThis document is aimed at programmers who have used web development languages such as HTML, CSS

    and JavaScript. This document will be even more helpful for those who have web development experience.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    8/100

    Application Development Guide for Samsung Smart TV

    8

    1. IntroductionThis section describes what Samsung Smart TV is, how it is configured and how it works.

    1.1.What is Samsung Smart TV?Samsung Smart TV is a web-based application running on an application engine installed in digital TVs

    connected to the Internet. The Samsung Smart TV service makes it possible to extend the functions of the

    TV by applying a variety of web functions to it, so that users can obtain useful information and interesting

    content on their TV screens. Users can check internet services such as news, weather, stock, UCC with

    simple operation.

    With Samsung Smart TV, digital TV users can not only download applications from HubSite and install them

    in their TVs but also personally develop applications tailored to their needs and install them in their TVs.

    HubSite

    Samsung Smart TV

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    9/100

    Application Development Guide for Samsung Smart TV

    9

    2. Samsung Smart TVThis section describes the operating principle and environment of Samsung Smart TV.

    2.1.Operating principleWith Samsung Smart TV installed in the TV, users can run Internet-based applications on the TV screen. An

    application is a special type of web page that is implemented on a web browser and runs on the TV screen.

    Viewing an application is very much like viewing web pages using a web browser on an ordinary PC.

    Differences between applications and web pages are made by screen resolution, hardware specifications

    and remote controller, the user interface for Samsung Smart TV installed TVs.

    2.2.Operating environmentBrowser App Engine 6.0

    TV screen resolution 1280x720 pixel, 960 540 pixel

    We will look at App Engine, the browser dedicated to internet TVs manufactured by Samsung, in Chapter 7.

    App Engine.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    10/100

    Application Development Guide for Samsung Smart TV

    10

    3. ApplicationsThis section looks at applications that we will develop for Samsung TVs.

    3.1.What are applications?Applications are web-based small

    applications that are run in digital TVs

    connected to the internet. They are installed

    in TVs via the Internet and are run on App

    Engine. It is safe to say that they are web

    pages displayed on the TV screen having the

    remote control as the only user interface.

    The Application Manager (N.Navi.) controls

    installing and removing applications, and performing other works for them.

    You can exploit the Software development kit (SDK) to develop new applications designed to be run on

    your TV screen.

    3.2.Structure of an applicationAn application is a web page consisting of HTML, CSS and JavaScript, and for Samsung TVs it is run on App

    Engine. The HTML page shows the structure of the application, the CSS file does the style, and the

    JavaScript file controls the behavior of the application. If you want to run an application on the TV screen,

    you have to create a config.xml file containing information on the operating environment and the version

    of the application. If you want to get more information about config.xml, see Ch. 4.3 config.xml.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    11/100

    Application Development Guide for Samsung Smart TV

    11

    3.3.Display type of applicationsDisplay type Description Screen layout

    Full-screen

    application

    Fills the entire screen with an

    application.

    Single-wide

    application

    Makes an application displayed

    only on part of the screen.

    Ticker

    Keeps an application on the

    screen while you do other

    things with your TV.

    * The application will be launched in Europe must be Full-screen application.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    12/100

    Application Development Guide for Samsung Smart TV

    12

    3.4. Running an applicationIn order to start an application, you are required to follow the steps below:

    Step Instruction description

    Get the Application

    Manager started

    Press the INTERNET(INFO.L) button on the remote control or go through Menu>

    Application>Samsung Smart TV to open the application

    Select an applicationPress arrow button located in the center of the remote control to select an

    application.

    Implement an

    application

    Press the Enter button to implement an application. The Application Manager

    reads the information from the config.xml file of the currently running

    application to set an operating environment, and reads index.html to implement

    the application.

    3.5.Application ManagerThe Application Manager serves as a manager that has the authority to authenticate, install, delete,

    update, open and finish applications. With the Application Manager, users can install or delete

    applications, and also register applications theyve developed and run them on the TV. The Application

    Manager is also an application that is continuously updated via the Internet.

    Smart Hub

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    13/100

    Application Development Guide for Samsung Smart TV

    13

    Samsung Apps Settings

    Edit Mode Sort by

    3.6.Features of Samsung applicationsApplications for Samsung Smart TV allow you to enjoy functions that only TVs have, unlike general webpages. For example, using plugins, you can volume up or down the application and play video other than

    broadcasting on the TV screen. In addition, you can use a file storage system. If you want to get detailed

    information on plug-ins and file storage system, refer to Ch. 7 and 8 File API.

    The Application Manager provides several JavaScript modules used in applications. This enhances

    convenience of application development. If you want to get detailed information on use of a common

    module, see Ch. 5 Common modules.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    14/100

    Application Development Guide for Samsung Smart TV

    14

    4. Creating an applicationThis section guides you to create a simple application.

    4.1.What you need to create an applicationOur final goal is to create applications and run them on the TV screen. To this end, you need a Samsung

    TV connected to the Internet and an SDK or a text editor with which you can write HTML, JavaScript and

    CSS files. The SDK is equipped with a simulator with which you can run an application youve created

    before actually installing it in your TV. So, if you use an SDK, you can make an application in a more

    convenient way.

    4.2.How to make an applicationAn application should contain at least the following elements:

    An index.html file. The file serves as the access point of the application. An application configuration file. This is an XML file in the root of the application structure that holds

    information about setting an application.

    JavaScript files. These are used for a preview of the application and for controlling the behavior ofthe application.

    CSS files. The look of the application is determined by these files. Image files, which are used by your application.

    Lets make an application that displays text written in CSS and responds to remote control buttons events.

    The structure and look of an application we will make now are shown as below.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    15/100

    Application Development Guide for Samsung Smart TV

    15

    4.2.1.Writing config.xmlThe config.xml file is called first among all the files the application has in it. tag value decides

    whether to update the application and images designated in tag are shown in thumbnail. For

    information about other tags, turn to Ch. 4.3.config.xml.

    Resource/image/icon/picasa_106.pngResource/image/icon/picasa_115.pngResource/image/icon/picasa_85.png

    Resource/image/icon/picasa_95.png

    lifestyley

    MyCPy

    0.9301.000

    n

    nnnnnyyn

    HelloWorldWelcome!

    960540

    Samsung Electronics Co. Ltd.http://www.sec.co.kr/Samsung Electronics Co. Ltd.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    16/100

    Application Development Guide for Samsung Smart TV

    16

    4.2.2.Writing index.htmlWhat you have to do next is writing index.html which will be the access point of the application. The

    following example is about HTML code that includes the Main.js file under the JavaScript folder and calls

    the Main.onLoad() function when the document is loaded.

    Hello World!!

    Welcome to Samsung application world!

    4.2.3.Writing JavaScriptIf the HTML document is loaded, the onLoad() function of the Main object is called, because you

    registered the Main.onLoad() function in the onload property in the tag. Make a Main object and

    add the onload function.

    var Main ={ // Main object

    }

    Main.onLoad =function(){ // called by 's onload eventalert("Main.onLoad()");/***JavaScriptcodeHere!

    */}

    If you have done all the work, you will get a debug message of Main.onLoad(). But the Welcome to

    Samsung application world! that you entered will not appear on the TV screen. If the application is

    successfully loaded, it has to ask the Application Manager to display itself on the screen using the common

    module provided by the Application Manager. The common module is a library containing essential

    functions provided by the Application Manager. For more information, refer to Ch. 5 Common Modules. Add

    the following code to ofindex.html.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    17/100

    Application Development Guide for Samsung Smart TV

    17

    If the above code is added, a common module is available to use by JavaScript. Declare the common

    module as a global variable for Main.js you were working on and call the sendReadyEvent() function. By

    doing this, you can make the Application Manager display an application on the screen.

    var Main ={ // Main object

    }

    var widgetAPI =new Common.API.Widget(); // Create Common module

    Main.onLoad =function(){ // called by 's onload eventalert("Main.onLoad()");widgetAPI.sendReadyEvent(); // Send ready message to Application Manager/***JavaScriptcodeHere!*/

    }

    Ok, now run the application youve just made. You will see the words Welcome to Samsung application

    world! that you entered in the index.html file appearing on the screen. Maybe you dont like the look of

    the application because its font size is too small and font color is just simple black. You may want to make

    your application more stylish. Then, you can give the application a style using CSS.

    4.2.4.Writing a CSSAdd the following string in in the index.html file.

    Assign an ID to in the index.html file.

    Welcome to Samsung application world!

    Create a file in the CSS folder and enter text as you see in the below box to specify the style of the

    welcome element.

    body{margin:0;padding:0;

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    18/100

    Application Development Guide for Samsung Smart TV

    18

    background-color:transparent;}

    #welcome{position:absolute;left:50px;top:50px;width:500px;height:50px;

    background-color:#AFAFAF;color:#99FFFF;font-size:30px;text-align:center;

    }

    4.2.5.Use of the remote controlNow, well make your application respond to the remote control. By pressing any of the five buttons

    located in the center of the remote control, you can change the words your application displays on the

    screen.

    If a button on the remote control is pressed, a keydown event occurs. An element hav ing focus is

    required to receive the event to the index.html file. Add element and Register a function that will beexecuted when that event occurs in the onkeydown property. Place focus on and press the remote

    control key, the function registered previously is executed.

    Add which executes Main.keyDown() method when a keydown event occurs.

    Welcome to Samsung application world!

    Write a keyDown() method bringing key code value when pressing the remote control key

    Main.keyDown =function(){ // Key handlervar keyCode = event.keyCode;alert("Main Key code : "+ keyCode);

    }

    In a function processed by keys such as keydown(), each key has its own key code value.

    The Application Manager provides a common module containing key code values to distinguish keys. Add

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    19/100

    Application Development Guide for Samsung Smart TV

    19

    the below code to in the index.html file to use a common module TVKeyValue.

    Modify Main.js in order to change the contents of welcome Div. This creates common module objects,

    classify keys in keydown() method, and define actions for each key. For detailed information on common

    modules and key code list, see Chapter 5. Common Modules.

    var Main ={ // Main object}

    var widgetAPI =new Common.API.Widget(); // Create Common modulevar tvKey =new Common.API.TVKeyValue();

    Main.onLoad =function(){ // called by 's onload eventalert("Main.onLoad()");widgetAPI.sendReadyEvent(); // Send ready message to Application Managerdocument.getElementById("anchor").focus(); // Focus to Anchor for handling key inputs

    // from remote controller/***JavaScriptcodeHere!*/

    }

    Main.keyDown =function(){ // Key handlervar keyCode = event.keyCode;alert("Main Key code : "+ keyCode);

    switch(keyCode){case tvKey.KEY_LEFT:

    alert("left");document.getElementById("welcome").innerHTML ="Nice to meet you.";/***CodeforLeftkeyevent!*/

    break;case tvKey.KEY_RIGHT:

    alert("right");document.getElementById("welcome").innerHTML ="I'm so happy.";break;

    case tvKey.KEY_UP:alert("up");document.getElementById("welcome").innerHTML ="I Love you.";break;

    case tvKey.KEY_DOWN:alert("down");document.getElementById("welcome").innerHTML ="Good job.";break;

    case tvKey.KEY_ENTER:

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    20/100

    Application Development Guide for Samsung Smart TV

    20

    alert("enter");break;

    case tvKey.KEY_RETURN:break;

    }}

    You will see the value of the welcome Div tag change as you press the up, down, left or right button.

    4.2.6.Complete your work & Sample codeWith Samsung Smart TV, you can do almost everything you do on a web page. You can create TV-

    oriented applications with extended functions using many plugins.

    The below are the codes weve written until now.

    4.2.6.1. config.xml

    Resource/image/icon/picasa_106.pngResource/image/icon/picasa_115.pngResource/image/icon/picasa_85.png

    Resource/image/icon/picasa_95.png

    PreviewHelloWorldSamsungResource/image/settings_logo.png

    0.9301.000

    nnnnnnyyn

    HelloWorldWelcome!

    960540

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    21/100

    Application Development Guide for Samsung Smart TV

    21

    Samsunghttp://acme-widget.example.comAcme Examples, Inc.

    4.2.6.2. index.html

    Hello World!!

    Welcome to Samsung widget world!

    4.2.6.3. Main.jsvar Main ={ // Main object}

    var widgetAPI =new Common.API.Widget(); // Create Common modulevar tvKey =new Common.API.TVKeyValue();

    Main.onLoad =function(){ // called by 's onload eventalert("Main.onLoad()");widgetAPI.sendReadyEvent(); // Send ready message to Application Managerdocument.getElementById("anchor").focus(); // Focus to Anchor for handling key inputs

    // from remote controller/***JavaScriptcodeHere!*/

    }

    Main.keyDown =function(){ // Key handler

    var keyCode = event.keyCode;

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    22/100

    Application Development Guide for Samsung Smart TV

    22

    alert("Main Key code : "+ keyCode);

    switch(keyCode){case tvKey.KEY_LEFT:

    alert("left");document.getElementById("welcome").innerHTML ="Nice to meet you.";/***CodeforLeftkeyevent!*/

    break;case tvKey.KEY_RIGHT:

    alert("right");document.getElementById("welcome").innerHTML ="I'm so happy.";break;

    case tvKey.KEY_UP:alert("up");

    document.getElementById("welcome").innerHTML ="I Love you.";break;

    case tvKey.KEY_DOWN:alert("down");document.getElementById("welcome").innerHTML ="Good job.";break;

    case tvKey.KEY_ENTER:alert("enter");break;

    case tvKey.KEY_RETURN:break;

    }

    }

    4.2.6.4. Main.cssbody{

    margin:0;padding:0;background-color:transparent;

    }

    #welcome{

    position:absolute;left:50px;top:50px;width:500px;height:50px;

    background-color:#AFAFAF;color:#99FFFF;font-size:30px;text-align:center;

    }

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    23/100

    Application Development Guide for Samsung Smart TV

    23

    4.3.config.xmlThe config.xml file contains information about the applications execution, update, operating environment

    setting and other related issues. Depending on that information, the Application Manager controls the

    version of your application, sets an environment in which your application is run, and creates and manages

    user accounts. The config.xml file should be located in the directory in which the application is installed,

    and contain the following elements.

    4.3.1.Tag informationElement Description Value

    Indicates that the information is relevant to the application. -

    An icon image displayed in the Application Manager.

    It is used in case of no focus and its size is 106 x 86pixel.File path

    An icon image displayed in the Application Manager.

    It is used in case that the focus is placed on an image and its size is 115

    x 95 pixel.

    File path

    An icon image displayed in the Application Manager.

    The size is 85 x 70 pixel.File path

    An icon image displayed in the Application Manager.

    The size is 95 x 78 pixel. File path

    The category to distinguish applications, available items are video,

    sports, game, lifestyle, information, others.String

    Decides whether to synchronize with hub site. The

    application which doesnt need synchronization chooses n.y | n

    Shows information on contents type

    - 11: HTML + java-script + Flash Player Object- 12: Adobe SWF ( Ver. Flash Lite 3.1 )- 13: Adobe SWF ( Ver. Flash 10.1 )- 14 : Lua Script

    Number

    File path and name at the initial execution of contents

    Only the following apptype needs contents tag.

    - 12: Adobe SWF ( Ver. Flash Lite 3.1 )- 13: Adobe SWF ( Ver. Flash 10.1 )- 14 : Lua Script

    File Path

    Channel Bound Service Type(optional) root | child

    Confirms the relations with root-child clarifying root application ID. Application

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    24/100

    Application Development Guide for Samsung Smart TV

    24

    (Optional, Only when the channel bound service type is child.)

    When connected to more than one root, roots are distinguished by ::.

    ID

    Channel information to be executed channel boundservice (Distinguish each channel using :: Ex

    AAA::BBB::CCC)

    (Optional, only if channel bound service type is root.)

    String

    It decides whether the installed channelbound service is displayed on

    the first main screen or not.

    (If you want to hide the service in the first main screen, select n.)

    y | n

    deleted String

    Enter the application provider in this tag. String

    The name of the JavaScript file that allows you to confirm account

    information of application providers. This file has to be written in a

    defined format.

    String

    deleted File path

    deleted File path

    Decides a service is available to signin or not. If you select y, you can

    enter ID and password in Integrated Sign-in site of Application Manager

    for sign-in. Validity verification should be preceded in JavaScript file

    corresponding to tag value.

    y | n

    Indicates the application version. Depending on that version

    information, the server computer updates the corresponding

    application.

    x.xxx

    Indicates the Application Managers version that is required to run an

    application having the config.xml file.x.xxx

    Indicates whether the application is a full-screen or a single-wide one.

    Display type affects the audio policy of the application when its run.

    Refer to Chapter. 6.4. Using Keys on Remote Control for details.

    y | n

    If source conversion is needed, set this tag to y. (ex. YouTube

    application).

    If you select y, the TV source automatically switched from current TV

    channel or external input to the internal media player, and back again

    when the application is finished.

    y | n

    Determines whether to use the childLock function. This function enables

    the user to lock an application.y | n

    Turns on and off the audio. If you select y, TV broadcasting sound is y | n

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    25/100

    Application Development Guide for Samsung Smart TV

    25

    not outputted when entering the application. Set y if the application

    occupies full screen and set n if the application occupies parts of the

    screen.

    Turns on and off the video. If you select y, TV broadcasting is not on

    the screen when entering the application.y | n

    Sets the Disable dynamic contrast function.

    Dynamic contrast is the function to adjust TV contrast ratio and brighten

    TV screen by darkening the dark screen and lightening the light screen.

    The screen might get lighter or darker when application is on with

    Dynamic contrast.

    y turns off the Dynamic contrast, and N turns on the Dyna mic

    contrast. If the application is occupied on full screen, select y to

    remove sparkling. If the application is partially occupied, select n.

    y | n

    Application playing video files can bring problems as stated below.

    1. If a video file is played in a device connected to HDMI port such as

    DVD Player when executing an application (ex. YouTube) converting

    sources, sounds can be mixed.

    2. Sparkling at the entry for appliction due to the difference of Frame

    rate between the TV image and playing video file.

    If you select y, you can prevent it from the problem above by ending

    operating the connected HDMI device when executing the application

    and fixing the Frame rate.

    y | n

    Enter a name of application. String

    Enter a brief description of the application. String

    Enter the screen area that the application will be occupying. Generally,

    it is recommended to enter 960 * 540 pixels, digital TV specification.Number

    Enter a description of the author. string

    This tage is used when needed to check network while operating an

    application. If the tage value is y and the network test result is fail,

    entry for the application can be blocked with a message indicating the

    failure.

    Without any set value, default is y.

    y | n

    This tage is used when needed to check whether the hubsite has been

    authorized or not while operating an application. If the tage value is y,

    and the hubsite has not been authorized, entry for the application can

    be blocked with a message indicating the failure.

    y | n

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    26/100

    Application Development Guide for Samsung Smart TV

    26

    Without any set value, default is n.

    Indicates whether the application provides Push Notification Service.

    Without any set value, default is n.

    y | n

    This tag is reserved for former Push Notification Service.

    Without any set value, default is n.y | n

    Indicates whether Push Notification Service is provided for specific user.

    Without any set value, default is n.y | n

    This tag should be enabled for application that use embedded flash

    player object, or stand-alone flash player.y | n

    4.3.2.Example

    Resource/image/icon/picasa_106.pngResource/image/icon/picasa_115.pngResource/image/icon/picasa_85.pngResource/image/icon/picasa_95.png

    lifestyley

    Picasa

    Auth11101000000y2.0001.035ynnnyyyyy

    nPicasa Web AlbumsView photo albums online960540

    Samsung Electronics Co. Ltd.http://www.sec.co.kr/Samsung Electronics Co. Ltd.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    27/100

    Application Development Guide for Samsung Smart TV

    27

    4.4.Single-Sign-OnThis section describes SSO functions supported by the application manager, how to register account

    information and get the information from the application.

    4.4.1.What is Single-Sign-OnInput of account information via TV remote control is so inconvenient that users could be stressed out if

    they should enter account information whenever they use the application. To improve this inconvenience,

    Single-Sign-On (hereinafter referred to as SSO) is provided by application manager. Application manager

    saves the account information that users have entered and sends it to the application. These enable users

    not to enter account information repetitively. The account information is encrypted and saved in safe area.

    SSO operates as stated below.

    Generate a TV Account

    It is necessary to create a TV account to use SSO. TV account is an account generated in the Application

    manager and has four-digit PIN number as a password. You can make the account in Settings->Samsung

    Smart TV-ID.

    Register Service Sites

    Registers account information of service sites (ex: YouTube, Picasa) in the generated TV account. Only

    when the entered account information is determined valid, the information is registered in the account.

    Registration can be made in Settings -> Samsung Smart TV ID.

    Sign-in to TV account

    You can sign in to the TV account created in pressing Red key on the initial screen. In general, account

    information on several service sites can be registered in a TV account. Sign-in make you enable to get

    account information on a service site you want to get in several applications.

    Execution of an Application

    At this stage, the application manager decides whether the application SSO is available to sign in or not. If

    available, the account information is given. Account information should be inputted through the process in

    .

    Use account information on service sites

    In an application, account information coexists with various circumstances information provided by the

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    28/100

    Application Development Guide for Samsung Smart TV

    28

    application manager. Thus, it is required to use account information after parsing.

    Following chapter describes modules necessary to be realized in an application to register service sites,how to parse and use the account information received by the application manager.

    4.4.2.Registration of Account Information on Service SitesRegistration of account information on service sites can be done through Settings -> Samsung Smart TV ID.

    If you wish to display the names of the service sites you want to show, configure config.xml as suggested

    below.

    YourCompany

    y

    Then, you can find YourCompany item in the list of service sites. If you cant, restart TV. Application

    manager could need to be reloaded.

    Now, the account information on service site, YourCompany can be entered. However, if there i s no

    module which confirms validity of the entered account information, the registration cannot be completed.

    You should generate the module in person.

    Validity Confirmation is to make sure that the entered account information is consistent with the ID and

    Password which are available to sign-in on the real service site. If sign-in can be made by API in each

    service site, the information is turned out to be valid.

    In Google, there is ClientLogin to judge validity. If sign-in is successfully done and auth token is granted,

    the account information is regarded valid. Refer to the URL states below regarding Client Login.

    (http://code.google.com/intl/ko/apis/accounts/docs/AuthForInstalledApps.html)

    The module to confirm validity of account information is drawn up as shown below.

    Enter the name of js file whose config.xml has a module.

    Put the name of js file which has a module to confirm account information validity in item. If

    the file name is Auth11101000000.js, put Auth11101000000. The application manager executes the module

    including the file. File names should be unique for each application. Check the variables such as

    curWidget.id and write the name distinctively.

    http://code.google.com/intl/ko/apis/accounts/docs/AuthForInstalledApps.htmlhttp://code.google.com/intl/ko/apis/accounts/docs/AuthForInstalledApps.htmlhttp://code.google.com/intl/ko/apis/accounts/docs/AuthForInstalledApps.htmlhttp://code.google.com/intl/ko/apis/accounts/docs/AuthForInstalledApps.html
  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    29/100

    Application Development Guide for Samsung Smart TV

    29

    Auth11101000000

    Create a fileCreate a js file corresponding to the entered file name in the process of . A module will be written in

    this file. This file is embedded in the top level directory where index.html exists.

    Draw up a module which confirms validity of account information.

    This module is generated in the file made in , the format should be in observance of regulations.

    Declare the object whose name is the entered value in . Add a method checkAccount to the object. checkAccount method confirms validity of the account information on the service site, and it should

    deliver the results to the callback function transferred to the factor.

    Example

    // Object Generated

    var Auth11101000000 ={

    }

    // checkAccount Method Added

    Auth11101000000.checkAccount =function(id, pw, fnCallback){

    /**

    *The id and pw inputted from the application manager are transferred to the factor.

    *Check validity of id andpw, and then operatecallbackfunction.

    */

    // ...

    // Confirmation on Validity

    // ...

    // Deliver the results

    if(isValidAccount){

    fnCallback ('TRUE');

    }

    else{

    fnCallback ('FALSE');

    }

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    30/100

    Application Development Guide for Samsung Smart TV

    30

    }

    The value transferring to the Callback function and the effect are like below.

    Return value Description

    'TRUE' If the transferred ID and Password are valid, return TRUE.

    Application manager registers ID and Password in the TV account.

    'FALSE' If the account information is invalid, return FALSE.

    The application Manager let the user reenter the account information.

    'ERROR' Errors occur while confirming validity, return ERROR. The application manager

    regards it as an error, after a while, it leads the user to try reusing accountinformation.

    Others Values other than three values above are processed identically with ERROR.

    4.4.3.How to download account information on service sites in applicationsApplications are able to get account information on service sites. Proceed like the order stated below.

    Configure config.xml like below.

    This enables the application manager to understand that this application is available to sign-in and

    necessary service site is YourCompany.

    YourCompany

    y

    Sign-in to the TV account

    The account information registered in the account can be available when sign-in process to the TV account

    is completed.

    Execution for an application

    Execute the application. Account information on CP(YourCompany) needs to be registered in the

    designated TV account in . Generally, several service sites are registered in a TV account, on the other

    hand, an application can get one service site relevant to the designated CP in .

    How to parse ID and Password

    All the conditions are satisfied, ID and Password are transferred to Browser global variable

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    31/100

    Application Development Guide for Samsung Smart TV

    31

    window.location.search. This variable includes circumstances information, and it should be parsed. Refer

    to 6.7 for further information on window.location.search.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    32/100

    Application Development Guide for Samsung Smart TV

    32

    4.5.ResetReset describes functions to initialize the application.

    4.5.1.What is Reset?The function to execute initial modules realized by applications when deleting or initializing applications

    in Application Manager.

    4.5.2.How Reset Works?1. Application Manager brings information in config.xml of the installed application when

    deleting/initializing.

    2. Check if the application needs a module which initializes through the information in config.xml.

    3. If the application has the module that initializes, bring information on the module.

    4. Execute the module in accordance with rules and try initializing.

    * Application Manager does not obtain any return value but operate the module to initialize.

    4.5.3.Necessary Features Developers Should Realize1. Peculiar Information on config.xml(Refer to Chapter 4)

    2. Initialization Module (Refer to Chapter 5)

    4.5.4.Guide for Config.xml RealizationAdd xml Element as shown below.

    MyReset

    * Without deleteJS Element, the application does not operate the initialization module.

    4.5.5.Guide for Module Realization1. The file name should be the same as class name.

    2. No factor.

    3. The name of function is reset.

    var MyReset={

    }

    MyReset.reset =function(){

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    33/100

    Application Development Guide for Samsung Smart TV

    33

    ...

    ...

    alert("Reset Complete!");}

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    34/100

    Application Development Guide for Samsung Smart TV

    34

    4.6.Example for XHR communicationIn this section, well look at an example for XHR communication, which is a key factor comprising AJAX

    technology.

    The below example is HTML code that includes XHRExample.js, and executes the XHRExample.onload()

    function when the load event occurs.

    XHR Example

    XHR Example.

    The below is JavaScript code. XHRExample is has been declared as an object and has the variable of

    XHRObj in it. If XHRObj already exists, XHRExample calls the destroy() method. We will look at this more

    specifically later in this chapter. If an XHR object has been successfully created, set it and request data. If

    the state of XHR changes to 4, which means data reception is completed, recieveData() that you

    registered in onreadystatechange is executed.

    var XHRExample ={

    XHRObj :null

    }

    var tvKey =new Common.API.TVKeyValue();

    var widgetAPI =new Common.API.Widget();

    XHRExample.onload =function(){

    widgetAPI.sendReadyEvent();

    var URL =""; // Test URL here

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    35/100

    Application Development Guide for Samsung Smart TV

    35

    if(this.XHRObj !=null)

    this.XHRObj.destroy();

    this.XHRObj =new XMLHttpRequest();

    if(this.XHRObj){

    this.XHRObj.onreadystatechange =function(){

    if(XHRExample.XHRObj.readyState ==4){

    XHRExample.recieveData();

    }

    };

    this.XHRObj.open("GET", URL,true);

    this.XHRObj.send(null);

    }

    }

    XHRExample.recieveData =function(){

    alert(this.XHRObj.responseText);

    }

    The above example has two remarkable points. One is that the variable of XHRObj is in the XHRExample

    object. The other is that the destroy() method is called before an object is assigned to XHRObj.

    With Samsung TVs, if you run out of the memory by continuing to create and use the XHR object,

    applications in your TV do not work anymore at a certain time. In order to avoid this kind of situation, you

    should delete objects you used in the past and assign new ones when you use XHR. To free up objects that

    had been used, the object pointer should be maintained. For this, developers should memorize and

    manage the variable dealing with XHR objects.

    If you want to remove an XHR object from the memory, use the destroy() method of it, and this is the

    method that App Engine provides to allow you to use the limited memory efficiently.

    XHRObjet.destroy

    Free up the XHR object you created from the memory.

    Syntax XHRObject.destroy()

    Parameter None

    Return Value None

    Remarks This function, which is executed to optimize the memory usage, is only provided by

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    36/100

    Application Development Guide for Samsung Smart TV

    36

    App Engine for Samsung TV users.

    Example

    if(this.XHRObj !=null)

    this.XHRObj.destroy();

    this.XHRObj =new XMLHttpRequest();

    In the above example, two common modules provided by the Application Manager are included. For more

    information, turn to Ch. 5 Common modules.

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    37/100

    Application Development Guide for Samsung Smart TV

    37

    5. Common modulesIn this section, we will look at a library shared by all your applications.

    5.1.Application Managers common modulesThe Application Manager provides object modules that all your applications can use. Those common

    modules enable your applications to do basic work to be normally running on the screen. Also, using

    common modules, individual applications can recognize and identify remote control button events, use

    plugins, and communicate with the Application Manager in more convenient and simpler ways.

    5.2.How to use common modules Include common modules you want to use in the index.html file. In order to prevent occurrence of any

    parsing order error, it is recommended that you include them at the top of the document.

    $MANAGER_WIDGET allows your applications to access common modules provided by the Application

    Manager.

    * In SDK, $MANAGER_WIDGET points the commonlib folder that SDK installed in.

    Create an object.

    var tvKey =new Common.API.TVKeyValue();

    Use known member variable and method.

    alert(tvKey.KEY_LEFT);

    5.3.TVKeyValueTVKeyValue

    An object that defines TV key code.

    Library path $MANAGER_WIDGET/Common/API/TVKeyValue.js

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    38/100

    Application Development Guide for Samsung Smart TV

    38

    Syntax new Common.API.TVKeyValue()

    Parameter None

    Return Value TVKeyValue object

    Remarks

    This is an object having key code used by the TV as a member variable, and identifies

    remote control keys pressed by the user by referring to member variables.

    (Since Samsung Smart TV version 2.265)

    Example

    var tvKey =new Common.API.TVKeyValue();

    switch(KEY_CODE){

    case tvKey.KEY_LEFT:

    // Do something

    break;

    case tvKey.KEY_RIGHT:

    // Do something

    break;

    default:

    break;

    }

    Members

    KEY_TOOLS

    KEY_MUTE

    KEY_RETURN

    KEY_UP

    KEY_DOWN

    KEY_LEFT

    KEY_RIGHT

    KEY_WHEELDOWN

    KEY_WHEELUP

    KEY_ENTER

    KEY_INFO

    KEY_EXIT

    KEY_RED KEY_GREEN

    KEY_YELLOW

    KEY_BLUE

    KEY_INFOLINK

    KEY_RW

    KEY_PAUSE

    KEY_FF

    KEY_PLAY

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    39/100

    Application Development Guide for Samsung Smart TV

    39

    KEY_STOP

    KEY_1

    KEY_2 KEY_3

    KEY_4

    KEY_5

    KEY_6

    KEY_7

    KEY_8

    KEY_9

    KEY_0

    KEY_EMPTY

    KEY_PRECH

    KEY_SOURCE

    KEY_CHLIST

    KEY_MENU

    KEY_WLINK

    KEY_CC

    KEY_CONTENT

    KEY_FAVCH

    KEY_REC

    KEY_EMODE

    KEY_DMA

    KEY_PANEL_CH_UP

    KEY_PANEL_CH_DOWN

    KEY_PANEL_VOL_UP

    KEY_PANEL_VOL_DOWN

    KEY_PANEL_ENTER

    KEY_PANEL_SOURCE

    KEY_PANEL_MENU

    KEY_PANEL_POWER

    Methods None

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    40/100

    Application Development Guide for Samsung Smart TV

    40

    5.4.WidgetThis is an object that has functions needed for desirable operation of an application. A method that

    notifies the Application Manager of starting of an application, a method that registers and frees up keys

    users want to use, and other methods are contained in this object.

    Widget

    Object having functions needed for desirable operation of an application

    Library path $MANAGER_WIDGET/Common/API/Widget.js

    Syntax new Common.API.Widget()

    Parameter None

    Return Value Widget object

    Remarks (Since Samsung Smart TV version 2.265)

    Examplevar widgetAPI =new Common.API.Widget();

    widgetAPI. sendReadyEvent();

    Members None

    Methods

    sendReadyEvent

    sendExitEvent

    sendReturnEvent

    blockNavigation

    putInnerHTML

    getChannelWidgetListPath

    getSearchWidgetListPath

    runSearchWidget

    5.4.1.sendReadyEvent()sendReadyEvent

    Notifies the Application Manager that the application is ready to be displayed. This event should be passed

    to display and run the application on the screen.

    Syntax sendReadyEvent()

    Parameter None

    Return Value None

    Remarks (Since Samsung Smart TV version 2.265)

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    41/100

    Application Development Guide for Samsung Smart TV

    41

    Examplevar widgetAPI =new Common.API.Widget();

    widgetAPI.sendReadyEvent();

    Enumeration None

    5.4.2.sendExitEvent()sendExitEvent

    Brings the same effect as pressing the exit key. Stops the application and goes back to the TV screen.

    Syntax sendExitEvent()

    Parameter NoneReturn Value None

    Remarks (Since Samsung Smart TV version 2.265)

    Examplevar widgetAPI =new Common.API.Widget();

    widgetAPI.sendExitEvent ();

    Enumeration None

    5.4.3.sendReturnEvent()sendReturnEvent

    Brings the same effect of pressing the Return key. Finishes the application and takes you to the Application

    Manager.

    Syntax sendReturnEvent()

    Parameter None

    Return Value None

    Remarks (Since Samsung Smart TV version 2.265)

    Examplevar widgetAPI =new Common.API.Widget();

    widgetAPI.sendReturnEvent ();

    Enumeration None

    5.4.4.blockNavigation()blockNavigation

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    42/100

    Application Development Guide for Samsung Smart TV

    42

    Key event cannot be forced to return.

    Syntax blockNavigation(keyEvent)

    Parameter keyEvent: Key event

    Return Value None

    Remarks

    KEY_RETURN and KEY_EXIT events forcibly close the operating application. The func

    prevents forced closure and keep being executing.

    (Since Samsung Smart TV version 2.265)

    Example

    function keyDown (){switch(event.keyCode){

    casethis.tvKey.KEY_LEFT:// Do something

    break;casethis.tvKey.KEY_RIGHT:// Do somethingbreak;

    casethis.tvKey.KEY_RETURN:widgetAPI.blockNavigation(event);// Not terminatedbreak;

    casethis.tvKey.KEY_EXIT:// Terminated by forcebreak;

    default:break;

    }}

    Enumeration None

    5.4.5.putInnerHTML()putInnerHTML

    innerHTML method to fix memory issues.

    Syntax putInnerHTML(div, contents)

    Parameterdiv: Div Element to use innerHTML

    contents: Things to insert in innerHTML

    Return Value None

    Remarks

    Required to use this method because repetitive use of innerHTML can occur memory

    issues.

    (Since Samsung Smart TV version 2.265)

    Example

    var widgetAPI =new Common.API.Widget();

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    43/100

    Application Development Guide for Samsung Smart TV

    43

    var divElement = document.getElementById("divID");var contents ="Text to change";

    widgetAPI.putInnerHTML(divElement, contents);

    Enumeration None

    5.4.6.getChannelWidgetListPath()getChannelWidgetListPath

    Method that brings the path of xml file having the child application list of the current channel bound

    application

    Syntax getChannelWidgetListPath()

    Parameter None

    Return Value string : xml file path

    Remarks

    This method is used when the channel bound application needs information on the

    currently installed child application.

    (Since Samsung Smart TV version 2.265)

    Examplevar widgetAPI =new Common.API.Widget();var xmlPath = widgetAPI.getChannelWidgetListPath();

    Enumeration None

    5.4.7.getSearchWidgetListPath()getSearchWidgetListPath

    Method that brings the path of xml file having the list of applications related

    Syntax getSearchWidgetListPath()

    Parameter None

    Return Value string : xml file path

    Remarks

    This method is used when a search tag in config.xml requires information on an

    application whose search tag is set as y.

    (Since Samsung Smart TV version 2.265)

    Examplevar widgetAPI =new Common.API.Widget();var xmlPath = widgetAPI.getSearchWidgetListPath();

    Enumeration None

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    44/100

    Application Development Guide for Samsung Smart TV

    44

    5.4.8.runSearchWidget()

    runSearchWidget

    Method called when executing another application in an application

    Syntax runSearchWidget ()

    ParameterappID : The application ID you intend to operate

    extraInfo : The string that transferred to the executing application

    Return Value None

    Remarks

    This method is used when the channel bound application requires information on the

    installed child application at present.(Since Samsung Smart TV version 2.265)

    Examplevar widgetAPI =new Common.API.Widget();widgetAPI.runSearchWidget(111011000001,key1=value1&key2=value2);

    Enumeration None

    5.4.9.checkSapTicket ()checkSapTicket

    Method called when checking to have the valid ticket for current logged-in user.

    Syntax checkSapTicket ()

    Parameter None

    Return Value None

    Remarks

    You should register event handler for passing the return value.

    If you have valid ticket, the return value is stat=ok&ticket=686a8281-e952-4dcc-

    a67b-57e8f92e5530

    Otherwise, it is stat=fail&ticket=null.(Since Samsung Smart TV version 3.037)

    Example

    // Register Event HandlercurWidget.onWidgetEvent = AAAA;

    var widgetAPI =new Common.API.Widget();widgetAPI.checkSapTicket();

    function AAAA(event){if( event.type == Common.API.EVENT_ENUM.PNS_CHECK_TICKET){

    // The return value is event.data.// TODO

    }

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    45/100

    Application Development Guide for Samsung Smart TV

    45

    }

    Enumeration None

    5.4.10. requestSapTicket ()requestSapTicket

    Method called when requesting new Sap Ticket for Application Server.

    Syntax requestSapTicket ()

    Parameter None

    Return Value None

    Remarks

    You should register event handler for passing the return value.

    If new ticket is generated normally, the return value is stat=ok&ticket=686a8281-

    e952-4dcc-a67b-57e8f92e5530

    Otherwise, it is stat=fail&ticket=null.

    (Since Samsung Smart TV version 3.037)

    Example

    // Register Event HandlercurWidget.onWidgetEvent = AAAA;

    var widgetAPI =new Common.API.Widget();

    widgetAPI.requestSapTicket();

    function AAAA(event){if( event.type == Common.API.EVENT_ENUM.PNS_REQUEST_TICKET){

    // The return value is event.data.// TODO

    }}

    Enumeration None

    5.5.PluginThe Application Manager provides a wrapper class that allows you to use some plugin functions in more

    convenient ways. If you want to take advantage of this class, just insert objects needed for use of plugins

    in the index.html document. Then, the Application Manager will give you an appropriate class method.

    Plugin

    Object that is wrapped for convenient use of plugins

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    46/100

    Application Development Guide for Samsung Smart TV

    46

    Library path $MANAGER_WIDGET/Common/API/Plugin.js

    Syntax new Common.API.Plugin()

    Parameter None

    Return Value Plugin object

    Remarks (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.setOnWatchDog();

    Members None

    Methods

    Object ID : pluginObjectTVMW

    setOnWatchDog

    setOffWatchDog

    registKey

    unregistKey

    registIMEKey

    unregistIMEKey

    registAllKey

    unregistAllKey

    registFullWidgetKey

    registPartWidgetKey

    Object ID : pluginObjectVideo

    setOnOSDState

    setOffOSDState

    Object ID : pluginObjectVideo

    setOnOSDState

    setOffOSDState

    Object ID : pluginObjectNNavi

    SetBannerState

    ShowTools

    setOnIdleEvent

    setOffIdleEvent

    setOnScreenSaver

    setOffScreenSaver

    Object ID : pluginObjectAppCommon

    isViewerKey

    Object list pluginObjectTVMW

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    47/100

    Application Development Guide for Samsung Smart TV

    47

    style='opacity:0.0;background-color:#000000;width:0px;height:0px;'>

    pluginObjectVideo

    pluginObjectNNavi

    pluginObjectAppCommon

    5.5.1.setOnWatchDog()

    setOnWatchDog

    Turns on the Watch dog function.

    Syntax setOnWatchDog()

    Parameter None

    Return Value None

    Remarks (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.setOnWatchDog();

    Enumeration None

    5.5.2.setOffWatchDog()setOffWatchDog

    Turns off the Watch dog function.

    Syntax setOffWatchDog()

    Parameter None

    Return Value None

    Remarks (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.setOffWatchDog();

    Enumeration None

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    48/100

    Application Development Guide for Samsung Smart TV

    48

    5.5.3.setOnOSDState()setOnOSDState

    Sets the area where OSD is protected.

    Syntax setOnOSDState(left, top, width, height)

    Parameter

    left : left coordinate of the area

    top : top coordinate of the area

    width : width of the area

    height : height of the area

    Return Value None

    Remarks (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.setOnOSDState(0,0, 330, 540);

    Enumeration None

    5.5.4.setOffOSDState()setOffOSDState

    Cancels the previously set OSD area.

    Syntax setOffOSDState(left, top, width, height)

    Parameter

    left : left coordinate of the area

    top : top coordinate of the area

    width : width of the area

    height : height of the area

    Return Value None

    Remarks (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.setOffOSDState(0,0, 330, 540);

    Enumeration None

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    49/100

    Application Development Guide for Samsung Smart TV

    49

    5.5.5.registKey()

    registKey

    Lets the Application Manager register specific key

    Syntax registKey(pNumKeyCode)

    Parameter pNumKeyCode: key code

    Return Value None

    Remarks

    Registration/Unregistration of keys should be done after window.onshow event. Refer

    to Chap. 6.4 How to use keys on remote control for more details.

    (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.registKey(tvKey.KEY_ TOOLS);

    Enumeration None

    5.5.6.unregistKey()unregistKey

    Lets the Application Manager unregister specific key

    Syntax unregistKey(pNumKeyCode)

    Parameter pNumKeyCode: key code

    Return Value None

    Remarks

    Registration/Unregistration of keys should be done after window.onshow event. Refer

    to Chap. 6.4 How to use keys on remote control for more details.

    (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.unregistKey(tvKey.KEY_ TOOLS);

    Enumeration None

    5.5.7.registIMEKey()registIMEKey

    Lets the Application Manager register IME key

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    50/100

    Application Development Guide for Samsung Smart TV

    50

    Syntax registIMEKey()

    Parameter None

    Return Value None

    Remarks

    Registers number keys from 0 to 9, -(hyphen), and previous channel key used in

    entering IME.

    Registration/Unregistration of keys should be done after window.onshow event. Refer

    to Chap. 6.4 How to use keys on remote control for more details.

    (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.registIMEKey();

    Enumeration None

    5.5.8.unregistIMEKey()unregistIMEKey

    Lets the Application Manager unregister IME key

    Syntax unregistIMEKey()

    Parameter NoneReturn Value None

    Remarks

    Unregisters number keys from 0 to 9, -(hyphen), previous channel key used in

    entering IME.

    Registration/Unregistration of keys should be done after window.onshow event. Refer

    to Chap. 6.4 How to use keys on remote control for more details.

    (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.unregistIMEKey();

    Enumeration None

    5.5.9.registAllKeyregistAllKey

    Lets the Application Manager register all keys

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    51/100

    Application Development Guide for Samsung Smart TV

    51

    Syntax registAllKey()

    Parameter None

    Return Value None

    Remarks

    Registers all keys

    Registration/Unregistration of keys should be done after window onshow event. Refer

    to Chap. 6.4 How to use keys on remote control for more details.

    (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.registAllKey();

    Enumeration None

    5.5.10. unregistAllKey()unregistAllKey

    Lets the Application Manager unregister all keys

    Syntax unregistAllKey()

    Parameter NoneReturn Value None

    Remarks

    Unregisters all keys

    Registration/Unregistration of keys should be done after window onshow event. Refer

    to Chap. 6.4 How to use keys on remote control for more details.

    (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.unregistAllKey();

    Enumeration None

    5.5.11. registFullWidgetKey()registFullWidgetKey

    Lets the Application Manager register specific key group

    Syntax registFullWidgetKey()

    Parameter None

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    52/100

    Application Development Guide for Samsung Smart TV

    52

    Return Value None

    Remarks

    Registers keys for fullwidget

    Registration/Unregistration of keys should be done after window onshow event. Referto Chap. 6.4 How to use keys on remote control for more details.

    (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI.registFullWidgetKey();

    Enumeration None

    5.5.12. registPartWidgetKey()registPartWidgetKey

    Lets the Application Manager register specific key group

    Syntax registPartWidgetKey ()

    Parameter None

    Return Value None

    Remarks

    Registers keys for part widget

    Registration/Unregistration of keys should be done after window onshow event. Referto Chap. 6.4 How to use keys on remote control for more details.

    (Since Samsung Smart TV version 2.265)

    Examplevar pluginAPI =new Common.API.Plugin();

    pluginAPI. registPartWidgetKey ();

    Enumeration None

    5.5.13. SetBannerState()SetBannerState

    A function using when you want to put volume and channel OSD with the application.

    Syntax SetBannerState (nState)

    Parameter

    nState : Defined value on OSD you want to bring with the application.

    PL_NNAVI_STATE_BANNER_NONE = 0;

    PL_NNAVI_STATE_BANNER_VOL = 1;

    PL_NNAVI_STATE_BANNER_VOL_CH = 2;

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    53/100

    Application Development Guide for Samsung Smart TV

    53

    Return Value None

    Remarks

    When you intend to bring up volume OSD on the screen, volume key value should be

    registered. So does channels. See an example.(Since Samsung Smart TV version 2.265)

    Example

    var PL_NNAVI_STATE_BANNER_NONE =0;

    var PL_NNAVI_STATE_BANNER_VOL =1;

    var PL_NNAVI_STATE_BANNER_VOL_CH =2;

    var pluginAPI =new Common.API.Plugin();

    var tvKey =new Common.API.TVKeyValue();

    pluginAPI.unregistKey(tvKey.KEY_VOL_UP);

    pluginAPI.unregistKey(tvKey.KEY_VOL_DOWN);

    pluginAPI.SetBannerState(PL_NNAVI_STATE_BANNER_VOL);

    Enumeration None

    5.5.14. ShowTools()

    ShowTools

    A function to bring popup windows for screen and sound adjustment.

    Syntax ShowTools (nTool)

    Parameter

    nTool: Defined value on a popup window you want to bring.

    0 : Sound Setting popup

    1 : Picture Setting popup

    Return Value None

    Remarks

    You can see the point when the popup window is closed by signing up for

    curWidget.onWidgetEvent.

    (Since Samsung Smart TV version 2.265)

    Example

    curWidget.onWidgetEvent =function(){

    // a code that will be executed after closing the popup window

    }

    var pluginAPI =new Common.API.Plugin();

    pluginAPI.ShowTools(1);

    Enumeration None

  • 8/2/2019 App Development Guide for Samsung Smart TV[V1.20]

    54/100

    Application Development Guide for Samsung Smart TV

    54

    5.5.15. setOnIdleEvent()

    setOnIdleEvent

    The function to set idle on to close the application in case that there is no input for a certain time

    Syntax setOnIdleEvent()

    Parameter None

    Retur