Application Development Guide for Internet@TV Year 2010 Version 1.00 Internet@TV 1
1. Introduction... 6 1.1. What is Internet@TV?... 6 2. Samsung Internet@TV... 7 2.1. Operating principle... 7 2.2. Operating environment... 7 3. Applications... 8 3.1. What are applications?... 8 3.2. Structure of an application... 8 3.3. Display type of applications... 9 3.4. Running an application... 10 3.5. Application Manager... 10 3.6. Features of Samsung applications... 11 4. Creating an application... 12 4.1. What you need to create an application... 12 4.2. How to make an application... 12 4.2.1. Writing config.xml... 13 4.2.2. Writing index.html... 14 4.2.3. Writing JavaScript... 14 4.2.4. Writing a CSS... 15 4.2.5. Use of the remote control... 16 4.2.6. Complete your work & Sample code... 18 4.3. config.xml... 21 4.3.1. Tag information... 21 4.3.2.... 23 4.4. Single-Sign-On... 25 4.4.1. What is Single-Sign-On... 25 4.4.2. How Single-Sign-On works... 25 4.4.3. Necessary Features Developers Should Realize... 25 4.4.4. Guide for Config.xml... 25 4.4.5. Guide for Module Realization... 26 4.4.6. Return Value When Calling CallbackFunc... 26 4.5. Reset... 27 4.5.1. What is Reset?... 27 4.5.2. How Reset Works?... 27 4.5.3. Necessary Features Developers Should Realize... 27 2
4.5.4. Guide for Config.xml Realization... 27 4.5.5. Guide for Module Realization... 27 4.6. for XHR communication... 29 5. Common modules... 32 5.1. Application Manager s common modules... 32 5.2. How to use common modules... 32 5.3. TVKeyValue... 32 5.4. Widget... 35 5.4.1. sendreadyevent()... 35 5.4.2. sendexitevent()... 36 5.4.3. sendreturnevent()... 36 5.4.4. blocknavigation()... 36 5.4.5. putinnerhtml()... 37 5.5. Plugin... 38 5.5.1. setonwatchdog()... 39 5.5.2. setoffwatchdog()... 39 5.5.3. setonosdstate()... 40 5.5.4. setoffosdstate()... 40 5.5.5. registkey()... 41 5.5.6. unregistkey()... 41 5.5.7. registimekey()... 41 5.5.8. unregistimekey()... 42 5.5.9. registallkey... 42 5.5.10. unregistallkey()... 42 5.5.11. registfullwidgetkey()... 43 5.5.12. registpartwidgetkey()... 43 5.5.13. SetBannerState()... 44 5.5.14. ShowTools()... 44 6. Tips for application developers... 46 6.1. Function necessary to be called when you open an application... 46 6.2. Access point... 46 6.3. Handling remote control key events... 46 6.4. Remote control keys for applications... 47 6.5. Closing an application... 48 6.6. Prevention of closing the TV screen by the Return or Exit key... 48 6.7. Additional information available when applications are implemented... 48 3
6.8. What CSS need to contain... 49 6.9. Loading images in advance... 49 6.10. Character of the <input> tag... 50 6.11. Scroll bar... 50 6.12. Making dynamic web pages... 50 6.13. Setting for letter-spacing... 50 6.14. Memory management... 51 6.14.1. Using XMLHttpRequest... 51 6.14.2. Freeing up the memory... 51 6.15. Watch Dog... 51 6.16. Prevention for OSD distortion... 52 6.17. Support CSS text-overflow... 52 6.18. Directions for creating video application... 52 6.19. Using IME... 52 7. Maple browser... 53 7.1. Maple?... 53 7.2. Supported standard specifications... 53 8. File API... 54 8.1. File API?... 54 8.2. API... 54 8.2.1. FileSystem()... 54 8.2.2. opencommonfile()... 55 8.2.3. closecommonfile()... 55 8.2.4. deletecommonfile()... 56 8.2.5. createcommondir()... 56 8.2.6. deletecommondir()... 57 8.2.7. isvalidcommonpath()... 57 8.2.8. readline()... 57 8.2.9. writeline()... 58 8.2.10. readall()... 58 8.2.11. writeall()... 59 9. Appendix... 60 9.1. Country Code... 60 9.2. Language Code... 61 9.3. Region Code... 62 4
Preface Purpose of Document This document is written to help application developers who enjoy the Internet@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 Readers This 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. 5
1. Introduction This section describes what Internet@TV is, how it is configured and how it works. 1.1. What is Internet@TV? SAMSUNG Internet@TV is a web-based application running on an application engine installed in digital TVs connected to the Internet. The Internet@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 Internet@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. PAVV HubSite 6
2. Samsung Internet@TV This section describes the operating principle and environment of Samsung Internet@TV. 2.1. Operating principle With Samsung Internet@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 Internet@TV installed TVs. 2.2. Operating environment Browser Maple 5.1 TV screen resolution 960 Ⅹ 540 pixel We will look at Maple, the browser dedicated to internet TVs manufactured by Samsung, in Chapter 7. Maple. 7
3. Applications This 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 Maple. 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 application An application is a web page consisting of HTML, CSS and JavaScript, and for Samsung TVs it is run on Maple. 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
3.3. Display type of applications Display 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. 9
3.4. Running an application In 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>Internet@TV to open the application Select an application Press 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 Manager The 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 they ve developed and run them on the TV. The Application Manager is also an application that is continuously updated via the Internet. 뚯Entry Screen Samsung Apps 10
Settings 3.6. Features of Samsung applications Applications for Samsung Internet@TV allow you to enjoy functions that only TVs have, unlike general web pages. 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. 11
4. Creating an application This section guides you to create a simple application. 4.1. What you need to create an application Our 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 you ve 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 application An 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 of the application. CSS files. The look of the application is determined by these files. Image files, which are used by your application. Let s 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. 12
4.2.1. Writing config.xml The config.xml file is called first among all the files the application has in it. <ver> tag value decides whether to update the application and images designated in <ThumbIcon> tag are shown in thumbnail. For information about other tags, turn to Ch. 4.3. config.xml. <?xml version="1.0" encoding="utf-8"?> <widget> <ThumbIcon>Resource/image/icon/picasa_106.png</ThumbIcon> <BigThumbIcon>Resource/image/icon/picasa_115.png</BigThumbIcon> <ListIcon>Resource/image/icon/picasa_85.png</BigThumbIcon> <BigListIcon>Resource/image/icon/picasa_95.png</BigThumbIcon> </widget> <category>lifestyle</category> <autoupdate>y</autoupdate> <cpname>junyoung</cpname> <cpauthjs></cpauthjs> <login>y</login> <ver>0.930</ver> <mgrver>1.000</mgrver> <fullwidget>n</fullwidget> <srcctl>n</srcctl> <ticker>n</ticker> <childlock>n</childlock> <audiomute>n</audiomute> <videomute>n</videomute> <dcont>y</dcont> <widgetname>helloworld</widgetname> <description>welcome!</description> <width>960</width> <height>540</height> <author> <name>samsung Electronics Co. Ltd.</name> <email></email> <link>http://www.sec.co.kr/</link> <organization>samsung Electronics Co. Ltd.</organization> </author> 13
4.2.2. Writing index.html What 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. <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>hello World!!</title> <script type="text/javascript" language="javascript" src="javascript/main.js"></script> </head> <body onload="main.onload();"> <div>welcome to Samsung application world!</div> </body> </html> 4.2.3. Writing JavaScript If 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 <body> tag. Make a Main object and add the onload function. var Main = { // Main object Main.onLoad = function () { alert("main.onload()"); /** * JavaScript code Here! */ // called by <body>'s onload event 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 <head> of index.html. 14
<script type="text/javascript" language="javascript" src="$manager_widget/common/api/widget.js"></script> 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(); Main.onLoad = function () { alert("main.onload()"); widgetapi.sendreadyevent(); /** * JavaScript code Here! */ // Create Common module // called by <body>'s onload event // Send ready message to Application Manager Ok, now run the application you ve 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 don t 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 CSS Add the following string in <head> in the index.html file. <link rel='stylesheet' type='text/css' href = 'CSS/Main.css'/> Assign an ID to <div> in the index.html file. <div id='welcome'>welcome to Samsung application world!</div> 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; 15
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 control Now, we ll 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 having focus is required to receive the event to the index.html file. Add <a> element and Register a function that will be executed when that event occurs in the onkeydown property. Place focus on <a> and press the remote control key, the function registered previously is executed. Add <a> which executes Main.keyDown() method when a keydown event occurs. <body onload="main.onload();"> <div id='welcome'>welcome to Samsung application world!</div> <a href='javascript:void(0);' id='anchor' onkeydown='main.keydown();'></a> </body> Write a keydown() method bringing key code value when pressing the remote control key Main.keyDown = function(){ // Key handler var 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. 16
Add the below code to <head> in the index.html file to use a common module TVKeyValue. <script type="text/javascript" language="javascript" src="$manager_widget/common/api/tvkeyvalue.js"></script> 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 = { var widgetapi = new Common.API.Widget(); var tvkey = new Common.API.TVKeyValue(); Main.onLoad = function(){ alert("main.onload()"); widgetapi.sendreadyevent(); document.getelementbyid("anchor").focus(); /** * JavaScript code Here! */ Main.keyDown = function(){ var keycode = event.keycode; alert("main Key code : " + keycode); // Main object // Create Common module // called by <body>'s onload event // Send ready message to Application Manager // Focus to Anchor for handling key inputs // from remote controller // Key handler switch (keycode) { case tvkey.key_left: alert("left"); document.getelementbyid("welcome").innerhtml = "Nice to meet you."; /** * Code for Left key event! */ 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"); 17
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 code With Samsung Internet@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 we ve written until now. 4.2.6.1. config.xml <?xml version="1.0" encoding="utf-8"?> <widget> <previewjs>previewhelloworld</previewjs> <cpname>junyoung</cpname> <cplogo>resource/image/settings_logo.png</cplogo> <cpauthjs></cpauthjs> <ver>0.930</ver> <mgrver>1.000</mgrver> <fullwidget>n</fullwidget> <srcctl>n</srcctl> <ticker>n</ticker> <childlock>n</childlock> <audiomute>n</audiomute> <videomute>n</videomute> <dcont>y</dcont> <widgetname>helloworld</widgetname> <description>welcome!</description> <width>960</width> <height>540</height> <author> <name>samsung SDS</name> <email></email> <link>http://acme-widget.example.com</link> <organization>acme s, Inc.</organization> </author> </widget> 18
4.2.6.2. index.html <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>hello World!!</title> <script type="text/javascript" language="javascript" src="$manager_widget/common/api/widget.js"></script> <script type="text/javascript" language="javascript" src="$manager_widget/common/api/tvkeyvalue.js"></script> <script type="text/javascript" language="javascript" src="javascript/main.js"></script> <link rel='stylesheet' type='text/css' href = 'CSS/Main.css'/> </head> <body onload="main.onload();"> <div id='welcome'>welcome to Samsung widget world!</div> <a href='javascript:void(0);' id='anchor' onkeydown='main.keydown();'></a> </body> </html> 4.2.6.3. Main.js var Main = { var widgetapi = new Common.API.Widget(); var tvkey = new Common.API.TVKeyValue(); Main.onLoad = function(){ alert("main.onload()"); widgetapi.sendreadyevent(); document.getelementbyid("anchor").focus(); /** * JavaScript code Here! */ Main.keyDown = function(){ var keycode = event.keycode; alert("main Key code : " + keycode); // Main object // Create Common module // called by <body>'s onload event // Send ready message to Application Manager // Focus to Anchor for handling key inputs // from remote controller // Key handler switch (keycode) { case tvkey.key_left: alert("left"); document.getelementbyid("welcome").innerhtml = "Nice to meet you."; /** * Code for Left key event! */ 19
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.css body { 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; 20
4.3. config.xml The config.xml file contains information about the application s 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 information Element Description Value <widget> Indicates that the information is relevant to the application. - <ThumbIcon> <BigThumbIcon> <ListIcon> <BigListIcon> <category> <autoupdate> <apptype> <contents> An icon image displayed in the Application Manager. File path It is used in case of no focus and its size is 106 x 87 pixel. 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 File path 115 x 95 pixel. An icon image displayed in the Application Manager. File path The size is 85 x 70 pixel. An icon image displayed in the Application Manager. File path The size is 95 x 78 pixel. The category to distinguish applications, available items are video, String sports, game, lifestyle, information, others. Decides whether to synchronize with hub site. The y n application which doesn t need synchronization chooses n. Shows information on contents type.(11:javascript, 12: flash, 13: Number game, ) File route at the initial execution of contents (Limited to non- File Path Javascript based applications) <channeltype> Channel Bound Service Type(optional) root child Confirms the relations with root-child clarifying root application ID. <channelroot> Application (Optional, Only when the channel bound service type is child.) ID When connected to more than one root, roots are distinguished by ::. <channelname> Channel information to be executed channel bound service (Distinguish each channel using :: Ex AAA::BBB::CCC) (Optional, only if channel bound service type is root.) String 21
<channeldisplay> It decides whether the installed channelbound service is displayed on the first main screen or not. y n (If you want to hide the service in the first main screen, select n.) <cpname> Enter the application provider in this tag. String <cpauthjs> 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 Decides a service is available to signin or not. If you select y, you <login> <ver> <mgrver> <fullwidget> <srcctl> <childlock> <audiomute> <videomute> <dcont> can enter ID and password in Integrated Sign-in site of Application Manager for sign-in. Validity verification should be preceded in y n JavaScript file corresponding to <cpauthjs> tag value. Indicates the application version. Depending on that version information, the server computer updates the corresponding x.xxx application. Indicates the Application Manager s 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 it s y n run. 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 y n channel or external input to the internal media player, and back again when the application is finished. 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 not outputted when entering the application. Set y if the application occupies full screen and set n if the application occupies parts of y n 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 y n brighten TV screen by darkening the dark screen and lightening the light screen. The screen might get lighter or darker when application 22
is on with Dynamic contrast. y turns off the Dynamic contrast, and N turns on the Dynamic contrast. If the application is occupied on full screen, select y to remove sparkling. If the application is partially occupied, select n. <movie> 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 y n 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. <widgetname> Enter a name of application. String <description> Enter a brief description of the application. String Enter the screen area that the application will be occupying. <width> Generally, it is recommended to enter 960 * 540 pixels, digital TV <height> specification. Number <author> Enter a description of the author. string 4.3.2. <?xml version="1.0" encoding="utf-8"?> <widget> <ThumbIcon>Resource/image/icon/picasa_106.png</ThumbIcon> <BigThumbIcon>Resource/image/icon/picasa_115.png</BigThumbIcon> <ListIcon>Resource/image/icon/picasa_85.png</ListIcon> <BigListIcon>Resource/image/icon/picasa_95.png</BigListIcon> <category>lifestyle</category> <autoupdate>y</autoupdate> <cpname>picasa</cpname> <cpauthjs>auth11101000000</cpauthjs> <login>y</login> <ver>2.000</ver> <mgrver>1.035</mgrver> <fullwidget>y</fullwidget> <srcctl>n</srcctl> <ticker>n</ticker> <childlock>n</childlock> <audiomute>y</audiomute> 23
<videomute>y</videomute> <dcont>y</dcont> <movie>y</movie> <widgetname>picasa Web Albums</widgetname> <description>view photo albums online</description> <width>960</width> <height>540</height> <author> <name>samsung Electronics Co. Ltd.</name> <email></email> <link>http://www.sec.co.kr/</link> <organization>samsung Electronics Co. Ltd.</organization> </author> </widget> 24
4.4. Single-Sign-On This section describes what the application needing to sign-in realizes. 4.4.1. What is Single-Sign-On Single-Sign-On(hereinafter referred to as SSO ) is the function to save ID/Password through one time ID/Password authorization process in the unit and enhance user convenience if sign-in application has been installed in ContentsHome. 4.4.2. How Single-Sign-On works 1. Once SSO starts to operate, ContentsHome brings information on config.xml of the all of installed applications. 2. ContentsHome decides the application is available to sign-in with certain information form Config.xml. 3. If the application is available to sign-in, it brings descriptions on authorization module of the application. 4. The module is executed according to the rules and ContentsHome received the result of authorization. 5. When the authorization has been completed as it should be, save the ID and Password used in the authorization in the TV unit. 6. Later, when operating the application, enter the saved ID and Password in the application 4.4.3. Necessary Features Developers Should Realize 1. Peculiar information in Config.xml(Refer to Chapter 4) 2. Module able to authorize ID and Password (Refer to Chapter 4) 4.4.4. Guide for Config.xml (ex) <login>y</login> <cpname>youtube</cpname> <cpauthjs>youtube</cpauthjs> Element Form Description <login> y or n A tag to distinguish whether to be available to sign-in, y should be 25
selected to sign up for ID/Password in SSO. <cpname> English Word Abbreviation for Contents Provider Name, the peculiar tag recognized in SSO should be unique and if there is an identical name, the last authorized module is mapped to the tag. <cpauthjs> English Word If JavaScript file name and Class name is XXXX.js, the JavaScript class name should be XXXX. 4.4.5. Guide for Module Realization 1. File name and Class name should be identical. 2. Factor consists of ID, Password, and callback function. 3. Callback function should be called to close the module, unless, the result will not be the expected one. (ex) var Youtube = { Youtube.checkAccount = function(id, pw, callbackfunc) {...... callbackfunc("true"); 4.4.6. Return Value When Calling CallbackFunc CallbackFunc is able to be executed with the return value stated below. Return value TRUE FALSE ERROR Others Description Authorization Completed. Saves ID and Password in SSO. Wrong ID and Password. Let the user enter them again. Decided as Network errors in SSO. Later, let the user try again. The same as ERROR 26
4.5. Reset Reset 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 Realize 1. Peculiar Information on config.xml(refer to Chapter 4) 2. Initialization Module (Refer to Chapter 5) 4.5.4. Guide for Config.xml Realization Add xml Element as shown below. <deletejs>myreset</deletejs> * Without deletejs Element, the application does not operate the initialization module. 4.5.5. Guide for Module Realization 1. The file name should be the same as class name. 2. No factor. 3. The name of function is reset. var MyReset= { 27
MyReset.reset = function() {...... alert("reset Complete!"); 28
4.6. for XHR communication In this section, we ll look at an example for XHR communication, which is a key factor comprising AJAX technology. The below example is HTML code that includes XHR.js, and executes the XHR.onload() function when the load event occurs. <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>xhr </title> <script type="text/javascript" language="javascript" src="$manager_widget/common/api/tvkeyvalue.js"></script> <script type="text/javascript" language="javascript" src="$manager_widget/common/api/widget.js"></script> <script type="text/javascript" language="javascript" src="xhr.js"></script> </head> <body onload="xhr.onload()"> <div id='intro'>xhr.</div> </body> </html> The below is JavaScript code. XHR is has been declared as an object and has the variable of XHRObj in it. If XHRObj already exists, XHR 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 XHR = { XHRObj : null var tvkey = new Common.API.TVKeyValue(); var widgetapi = new Common.API.Widget(); XHR.onload = function () { widgetapi.sendreadyevent(); var URL = ""; // Test URL here 29
if (this.xhrobj!= null) this.xhrobj.destroy(); this.xhrobj = new XMLHttpRequest(); if (this.xhrobj) { this.xhrobj.onreadystatechange = function () { if (XHR.XHRObj.readyState == 4) { XHR.recieveData(); ; this.xhrobj.open("get", URL, true); this.xhrobj.send(null); XHR.recieveData = function () { alert(this.xhrobj.responsetext); The above example has two remarkable points. One is that the variable of XHRObj is in the XHR 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 Maple provides to allow you to use the limited memory efficiently. XHRObjet.destroy Free up the XHR object you created from the memory. Syntax Parameter Return Value XHRObject.destroy() 30
Remarks This function, which is executed to optimize the memory usage, is only provided by Maple for Samsung TV users. 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. 31
5. Common modules In this section, we will look at a library shared by all your applications. 5.1. Application Manager s common modules The 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. <script type="text/javascript" language="javascript" src="$manager_widget/common/api/tvkeyvalue.js"></script> Create an object. var tvkey = new Common.API.TVKeyValue(); Use known member variable and method. alert(tvkey.key_left); 5.3. TVKeyValue TVKeyValue An object that defines TV key code. Library path $MANAGER_WIDGET/Common/API/TVKeyValue.js 32
Syntax Parameter Return Value Remarks Members new Common.API.TVKeyValue() TVKeyValue object 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. 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; 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 KEY_STOP 33
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 34
5.4. Widget This 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 Syntax Parameter Return Value Remarks Members Methods $MANAGER_WIDGET/Common/API/Widget.js new Common.API.Widget() Widget object var widgetapi = new Common.API.Widget(); widgetapi. sendreadyevent(); sendreadyevent sendexitevent sendreturnevent blocknavigation putinnerhtml 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 Return Value Remarks var widgetapi = new Common.API.Widget(); widgetapi.sendreadyevent(); 35
Enumeration 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 Return Value Remarks var widgetapi = new Common.API.Widget(); widgetapi.sendexitevent (); Enumeration 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 Return Value Remarks var widgetapi = new Common.API.Widget(); widgetapi.sendreturnevent (); Enumeration 5.4.4. blocknavigation() blocknavigation Key event cannot be forced to return. Syntax blocknavigation(keyevent) 36
Parameter Return Value Remarks Enumeration keyevent: Key event KEY_RETURN and KEY_EXIT events forcibly close the operating application. The func prevents forced closure and keep being executing. function keydown () { switch(event.keycode) { case this.tvkey.key_left: // Do something break; case this.tvkey.key_right: // Do something break; case this.tvkey.key_return: widgetapi.blocknavigation(event); // Not terminated break; case this.tvkey.key_exit: // Terminated by force break; default: break; 5.4.5. putinnerhtml() putinnerhtml innerhtml method to fix memory issues. Syntax Parameter Return Value Remarks Enumeration putinnerhtml(div, contents) div: Div Element to use innerhtml contents: Things to insert in innerhtml Required to use this method because repetitive use of innerhtml can occur memory issues. var widgetapi = new Common.API.Widget(); var divelement = document.getelementbyid("divid"); var contents = "Text to change"; widgetapi.putinnerhtml(divelement, contents); 37
5.5. Plugin The 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 Library path Syntax Parameter Return Value Remarks Members Methods $MANAGER_WIDGET/Common/API/Plugin.js new Common.API.Plugin() Plugin object var pluginapi = new Common.API.Plugin(); pluginapi.setonwatchdog(); None Object ID : pluginobjecttvmw setonwatchdog setoffwatchdog registkey unregistkey registimekey unregistimekey registallkey unregistallkey registfullwidgetkey registpartwidgetkey Object ID : pluginobjectvideo setonosdstate setoffosdstate Object ID : pluginobjectvideo setonosdstate setoffosdstate 38
Object list Object ID : pluginobjectnnavi SetBannerState ShowTools pluginobjecttvmw <OBJECT id='pluginobjecttvmw' border=0 classid='clsid:samsung-infolink-tvmw' style='opacity:0.0;background-color:#000000;width:0px;height:0px;'></object> pluginobjectvideo <OBJECT id='pluginobjectvideo' border=0 classid='clsid:samsung-infolink-video' style='opacity:0.0;background-color:#000000;'></object> pluginobjectnnavi <OBJECT id='pluginobjectnnavi' classid='clsid:samsung-infolink-nnavi' style='opacity:0.0;background-color:#000000;width:0px;height:0px;'></object> 5.5.1. setonwatchdog() setonwatchdog Turns on the Watch dog function. Syntax Parameter Return Value Remarks Enumeration setonwatchdog() var pluginapi = new Common.API.Plugin(); pluginapi.setonwatchdog(); 5.5.2. setoffwatchdog() setoffwatchdog Turns off the Watch dog function. Syntax Parameter Return Value Remarks setoffwatchdog() 39
Enumeration var pluginapi = new Common.API.Plugin(); pluginapi.setoffwatchdog(); 5.5.3. setonosdstate() setonosdstate Sets the area where OSD is protected. Syntax Parameter Return Value Remarks Enumeration setonosdstate(left, top, width, height) left : left coordinate of the area top : top coordinate of the area width : width of the area height : height of the area var pluginapi = new Common.API.Plugin(); pluginapi.setonosdstate(0,0, 330, 540); 5.5.4. setoffosdstate() setoffosdstate Cancels the previously set OSD area. Syntax Parameter Return Value Remarks Enumeration setoffosdstate(left, top, width, height) left : left coordinate of the area top : top coordinate of the area width : width of the area height : height of the area None var pluginapi = new Common.API.Plugin(); pluginapi.setoffosdstate(0,0, 330, 540); 40
5.5.5. registkey() registkey Let the Application Manager register specific key Syntax Parameter Return Value Remarks Enumeration registkey(pnumkeycode) pnumkeycode: key code var pluginapi = new Common.API.Plugin(); pluginapi.registkey(tvkey.key_ TOOLS); 5.5.6. unregistkey() unregistkey Let the Application Manager unregister specific key Syntax Parameter Return Value Remarks Enumeration unregistkey(pnumkeycode) pnumkeycode: key code var pluginapi = new Common.API.Plugin(); pluginapi.unregistkey(tvkey.key_ TOOLS); 5.5.7. registimekey() registimekey Let the Application Manager register IME key Syntax Parameter Return Value Remarks registimekey() Register 0~9, - (hyphen), and the PRE-CH key. 41
Enumeration var pluginapi = new Common.API.Plugin(); pluginapi.registimekey(); 5.5.8. unregistimekey() unregistimekey Let the Application Manager unregister IME key Syntax Parameter Return Value Remarks Enumeration unregistimekey() Frees up the 0~9, -, PRE-CH keys that are used when entering IME. var pluginapi = new Common.API.Plugin(); pluginapi.unregistimekey(); 5.5.9. registallkey registallkey Let the Application Manager register all keys Syntax Parameter Return Value Remarks Enumeration registallkey() Register all the keys. var pluginapi = new Common.API.Plugin(); pluginapi.registallkey(); 5.5.10. unregistallkey() unregistallkey Let the Application Manager unregister all keys 42
Syntax Parameter Return Value Remarks Enumeration unregistallkey() Close all the keys. var pluginapi = new Common.API.Plugin(); pluginapi.unregistallkey(); 5.5.11. registfullwidgetkey() registfullwidgetkey Let the Application Manager register specific key group Syntax Parameter Return Value Remarks Enumeration registfullwidgetkey() Register keys for full-screen applications. var pluginapi = new Common.API.Plugin(); pluginapi.registfullwidgetkey(); 5.5.12. registpartwidgetkey() registpartwidgetkey Let the Application Manager register specific key group Syntax registpartwidgetkey () Parameter Return Value Remarks Enumeration Register keys for single-wide applications. var pluginapi = new Common.API.Plugin(); pluginapi. registpartwidgetkey (); 43
5.5.13. SetBannerState() SetBannerState A function using when you want to put volume and channel OSD with the application. Syntax Parameter Return Value Remarks SetBannerState (nstate) 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; None When you intend to bring up volume OSD on the screen, volume key value should be registered. So does channels. See an 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(); Enumeration pluginapi.unregistkey(tvkey.key_vol_up); pluginapi.unregistkey(tvkey.key_vol_down); pluginapi.setbannerstate(pl_nnavi_state_banner_vol); 5.5.14. ShowTools() ShowTools A function to bring popup windows for screen and sound adjustment. Syntax Parameter Return Value ShowTools (ntool) ntool: Defined value on a popup window you want to bring. 0 : Sound Setting popup 1 : Picture Setting popup None 44
Remarks Enumeration You can see the point when the popup window is closed by signing up for curwidget.onwidgetevent. curwidget.onwidgetevent = function(){ // a code that will be executed after closing the popup window var pluginapi = new Common.API.Plugin(); pluginapi.showtools(1); 45
6. Tips for application developers This section describes several pieces of information that are useful for application developers. 6.1. Function necessary to be called when you open an application For an application to be run, it should ask the Application Manager to display itself on the screen. Only when the Application Manager is requested to do so, it displays the corresponding application on the screen. Any request should be made through a common module. Call the sendreadyevent() method of the Widget object in the common module. var widgetapi = new Common.API.Widget(); // Create Common module widgetapi.sendreadyevent(); // Send ready message to Application Manager 6.2. Access point Whenever you open an application, the Maple browser reads the index.html document. If you implement an application by selecting an application and clicking Enter in the Application Manager, the browser starts to read the index.html document. Register a JavaScript function in the onload property so that when the <body> load event occurs, the application is started. The application must calls sendreadyevent() of the Widget object in the common module. <body onload="main.onload();"> 6.3. Handling remote control key events If any button on the remote control is pressed, the keydown event occurs. This event is passed to an element receiving focus at the point of time when the event occurs. If the element has registered a function in the onkeydown property, that function is executed. The function identifies which button is pressed using event.keycode. You should note that an element that is supposed to respond to the keydown event should be receiving focus. If there s no element receiving focus, there will be no relation on the TV screen even though you press a remote control button. All the remote control keys have been defined by member variables of the tvkeyvalue object. 46
Look at the example below. Insert an element that will have focus in index.html. <a href='javascript:void(0);' id='anchor' onkeydown='main.keydown();'></a> Create a function that will be registered in the onkeydown property. Main.keyDown = function(){ var keycode = event.keycode; alert("main Key code : " + keycode); // Key handler switch (keycode) { case tvkey.key_left: /** * Code for Left key event! */ break; case tvkey.key_right: break; case tvkey.key_up: break; case tvkey.key_down: break; case tvkey.key_enter: break; case tvkey.key_return: break; 6.4. Remote control keys for applications If you access an application, the Application Manager registers basic keys relevant to it. The Manager depends on the <fullwidget> tag in the config.xml file to determine whether the keys are for fullscreen or single-wide applications. KEY_VOL_UP KEY_VOL_DOWN KEY_MUTE KEY_TOOLS KEY_INFO KEY_EMODE KEY_DMA KEY_MENU KEY_SOURCE KEY_PRECH KEY_FAVCH KEY_CHLIST Full-screen application KEY_1 KEY_2 KEY_3 KEY_4 KEY_5 KEY_6 KEY_7 KEY_8 KEY_9 KEY_0 KEY_WHEELDOWN KEY_WHEELUP Single-wide application KEY_WHEELDOWN KEY_WHEELUP KEY_RED KEY_GREEN KEY_YELLOW KEY_BLUE KEY_RW KEY_PAUSE KEY_FF KEY_PLAY KEY_STOP KEY_ENTER 47
KEY_DMA KEY_TTX_MIX KEY_GUIDE KEY_SUBTITLE KEY_ASPECT KEY_DOLBY_SRR KEY_MTS 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_RED KEY_GREEN KEY_YELLOW KEY_BLUE KEY_RW KEY_PAUSE KEY_FF KEY_PLAY KEY_STOP KEY_ENTER KEY_RETURN KEY_EXIT KEY_RETURN KEY_EXIT Individual applications can register or delete keys they want to use by utilizing the method of the Widget object in the common module. For detailed information, refer to Ch. 5 Common module. 6.5. Closing an application There are two ways to close your application working on the screen: pressing the Return or Exit button on the remote control or sending an event to the Application Manager. For the latter way, you use the sendexitevent() and sendreturnevent() functions of the Widget which is the common module. For more information, see Ch.5 Common module. 6.6. Prevention of closing the TV screen by the Return or Exit key Using the Return or Exit key on the remote control, you can close applications. If you press the Return key, you will be taken to the Application Manager, and if you press the Exit key, you will be taken to the TV screen. In order to prevent this from happening, when either Return or Exit is pressed, the blocknavigation() function of the Widget which is the common module has to be executed. For more information, see Ch.5 Common modules. 6.7. Additional information available when applications are implemented When an application is run, the Application Manager gives you additional information. The application gets such information by referring to window.location.search. The below is an example.?country=us&language=1&modelid=valencia&server=development&remocon=2_35_259&area=usa&id=ori59 0e@exxx.com&pw=pxxxx 48
Attribute Value Description country Country code Country code that has already been assigned. Refer to Chapter 9.1. language Language code Language code that has already been assigned. Refer to Chapter 9.2. modelid Digital TV Model ID Digital TV Model ID server development operating server type: Development Server or Operating Server remocon - No use area Region Code Region code that has already been assigned. Refer to chapter9.3. Id string Id inputted in SSO. It is passed only when entering application after sign-in. pw string Pw inputted in SSO. It is passed only when entering application after sign-in. 6.8. What CSS need to contain The element created in the margin beyond the maximum TV resolution(960 x 540 pixel) can cause the display to scroll. All the element margins and paddings in the index.html document should be defaulted to 0 to prevent the matter resulted from going beyond the area. Your CSS should contain the following strings. body { margin: 0; padding: 0; background-color: transparent; 6.9. Loading images in advance The Maple browser decodes images to make them displayed normally on your screen. If the browser continues to change images that are displayed at a high speed, it may fail to display images on the screen due to unfinished decoding process. To avoid this, you can load and keep images before you actually use them. By doing this, you can save the time for image decoding. var imagepreloading = new Image(); imagepreloading.src = "Resource/image/largeNFastChange.png"; 49
By doing the above work, you can make the Maple browser decode images. For images that have been decoded once by the browser, they don t have to be decoded again later when they are used elsewhere, so that your TV can display them faster. 6.10. Character of the <input> tag On Maple, an object that is created by the <input> tag is not overlapped by other objects. Even if you use z-index, the <input> object is always over other objects. 6.11. Scroll bar Maple provides a scrolling function, but you cannot see the actual scroll bar on the screen. You can scroll up or down the content on the screen with buttons on the remote control when the content needs a larger area than that you specified before. If you want to see the actual scroll bar on your TV screen, you should use scrollheight, scrolltop and offsetheight to make an actual scrollbar appear on the screen. Put an anchor ( <a> ) in the content you want to scroll up and down, give it focus and click the up or down button on the remote control, then you can scroll up or down the content. (Picture Source: http://sevencapitalsins.wordpress.com/2007/07/04/javascript-smooth-scroll/) 6.12. Making dynamic web pages If you want to make dynamic web pages, you can use createelement and innerhtml. The createelement function is the standard method dealing with HTML DOM, but its disadvantage is lower operating speed, compared with innerhtml. It is recommended to use innerhtml because your applications are run in TVs, which provide a less optimized operating environment than personal computers. 6.13. Setting for letter-spacing The value of letter-spacing in Maple browser is defaulted -1. In case of Thai language, letters happen to be overlapped when the value is -1. Set the value 0 to prevent this from happening. 50
Include below codes to CSS. * { letter-spacing: 0px; 6.14. Memory management If you keep changing innerhtml and creating the XMLHttpRequest object on an on, your TV memory runs out and applications installed in your TV will not run normally. Of course, you have a garbage collector, but it doesn t work fine. Another problem is limited memory resources, compared to PCs. Therefore, if you want to write optimized applications that normally run, you should take additional measures. 6.14.1. Using XMLHttpRequest If you create and use XHR objects repeatedly in Samsung TVs, you will be faced with a problem of your applications working in a wrong way. The solution to this problem is set forth in Ch. 4.5 for XHR communication. 6.14.2. Freeing up the memory If the content in the tag is replaced with the innerhtml property, the corresponding node in the DOM tree is closed and a new one is created and connected. The closed node remains in the memory. If this procedure occurs repeatedly, you could face memory full. The solution to this problem is to use the putinnerhtml() method of the Widget object in the common module. For more information on this method, refer to Ch. Common modules. 6.15. Watch Dog SAMSUNG TV periodically checks that the operating applications are working properly. If the application does not react within 20 sec, it closes the application forcibly. This system is called Watch dog. Watch dog turns on and off an application, using setonwatchdog(), setoffwatchdog() method of common module, Plugin. In application, Network related operation and big data parsing(ex. Stock ) take more than 20 sec, and this will let the Watch dog be forced to close. It is recommended that you turn off Watch dog prior to these actions. After the actions have been completed, turn on the watch dog again. If you keep Watch 51
dog off, TV might stop working. 6.16. Prevention for OSD distortion Images of an application can be distorted if the movie is playing in the background makes too fast transitions. Operating setonosdstate(), setoffosdstate() method of common module Plugin prevents the trouble. For more details on using the method, see Chapter 5.5. Plugin. This trouble could appear in Single-wide application and Ticker application. (not in Full-screen application) 6.17. Support CSS text-overflow Maple browser supports CSS1, CSS2. Also, text-overflow which is one of the attributes of CSS3 is supported, this can make the browser cope with contents over the area efficiently. 6.18. Directions for creating video application Video application using Player(Plugin) should be closed after the player is stopped. If you end application without stop playing, critical problem such that TV is paused can occur. The best way to prevent the problem is to stop Player at the registered function in onunload of <body> tag. 6.19. Using IME Text input is available via remote control in application. Internet@TV provides a module for utilizing IME(Input Method Editor). This module enables users to enter languages. For more details, refer to IME Tutorial manual distributed separately. 52
7. Maple browser This section sets forth the browser for running applications provided with Samsung Internet@TV, Maple. 7.1. Maple? Stands for Markup engine Platform for Embedded Systems Browser engine for Consumer Electronics (CE) devices Controls devices using markup tags and script classes When an application is displayed and behaves on the screen, its image and text generation should be controlled and managed. For Samsung TVs with Internet@TV installed, it is Maple that performs such work. An application s behaviors and displays are made by Maple. While Internet Explorer and Firefox are PC-based browsers, Maple is Samsung TV-based browser. 7.2. Supported standard specifications Supported web standards HTML4.01, XHTML1.0, XML1.0 Markup language specifications HTTP1.0/1.1 CSS1, CSS2, CSS TV Profile 1.0 DOM1, DOM2 JavaScript 1.6 Supported image formats BMP, JPEG, PNG, GIF 53
8. File API This section introduces the file input/output operation system which the Samsung TV application engine supports. 8.1. File API? Applications can use the file input/output system supported the Samsung TV application engine. Applications can store data they get while they are still working and read them anytime they want to restore the data. All applications perform file input/output operations in a common area. For this reason, a directory where files are created and used should be created. If multiple applications need to share some data, they should do through a file path that they previously promised to use. File input/output operations are performed by creating a file system object and calling the interface of the object. 8.2. API The following is a list of interfaces that are provided by the Samsung TV application engine. You can use them in JavaScript. 8.2.1. FileSystem() FileSystem Creates a FileSystem object which applications can use. Syntax Parameter Return Value Remarks Enumeration new FileSystem() FileSystem object var filesystemobj = new FileSystem() 54
8.2.2. opencommonfile() opencommonfile Opens a file. Syntax Parameter Return Value Remarks Enumeration filesystemobj.opencommonfile(stringfilepath, stringmode) stringfilepath : path containing the name of a file that you want to open stringmode : same as the second parameter of fopen() r : Open a file for reading. The file must exist. w : Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. a : Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist. r+ : Open a file for update both reading and writing. The file must exist. w+ : Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. a+ : Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist. file object var filesystemobj = new FileSystem(); var jsfileobj = filesystemobj.opencommonfile( testfile.dat, r ); 8.2.3. closecommonfile() closecommonfile Closes a file. Syntax Parameter Return Value filesystemobj.closecommonfile(jsfileobj) fileobj: JSFile object that you opened by using opencommonfile() Boolean 55
Remarks Enumeration var filesystemobj = new FileSystem(); var jsfileobj = filesystemobj.openfile( testfile.dat, r ); var bresult = filesystemobj.closecommonfile(jsfileobj); 8.2.4. deletecommonfile() deletecommonfile Erase a file. Syntax Parameter Return Value Remarks Enumeration filesystemobj.deletecommonfile(stringfilepath) stringfilepath : path containing the file name Boolean var filesystemobj = new FileSystem(); var bresult = filesystemobj. deletecommonfile ( testfile.dat ); 8.2.5. createcommondir() createcommondir Creates a directory. Syntax Parameter Return Value Remarks Enumeration filesystemobj.createcommondir(stringdirectorypath) stringdirectorypath: path containing the directory name Boolean var filesystemobj = new FileSystem(); var bresult = filesystemobj. createcommondir ( testdirectory ); 56
8.2.6. deletecommondir() deletecommondir Deletes a directory. Syntax Parameter Return Value Remarks Enumeration filesystemobj.deletecommondir(stringdirectorypath) stringdirectorypath: name containing the directory name Boolean var filesystemobj = new FileSystem(); var bresult = filesystemobj. deletecommondir ( testdirectory ); 8.2.7. isvalidcommonpath() isvalidcommonpath Verifies if the path already exists. Syntax Parameter Return Value Remarks Enumeration filesystemobj.isvalidcommonpath(stringpath) stringpath: path int 0 : JS function failure 1 : valid 2 : invalid var filesystemobj = new FileSystem(); var bresult = filesystemobj. isvalidcommonpath ( testdirectory ); 8.2.8. readline() readline Reads a line from an open file. Syntax jsfileobj.readline() 57
Parameter Return Value Remarks Enumeration string None var jsfileobj = filesystemobj.openfile( testfile.dat, r ); var stringresult = jsfileobj. readline(); 8.2.9. writeline() writeline Writes a line in an open file. Syntax Parameter Return Value Remarks Enumeration jsfileobj.writeline(string) string: string that you will write in the file. boolean var jsfileobj = filesystemobj.openfile( testfile.dat, w ); var bresult = jsfileobj. writeline( teststring ); 8.2.10. readall() readall Reads more than one line from an open file. Syntax Parameter Return Value Remarks Enumeration jsfileobj.readall() string var jsfileobj = filesystemobj.openfile( testfile.dat, r ); var stringresult = jsfileobj. readall(); 58
8.2.11. writeall() writeall Writes more than one line in an open file. Syntax Parameter Return Value Remarks Enumeration jsfileobj.writeall() boolean var jsfileobj = filesystemobj.openfile( testfile.dat, r ); var bresult = jsfileobj. writeall(varlongstring); 59
9. Appendix 9.1. Country Code You can get this code from Application Manager. Refer ch. 6.7, for more details. Nations Code Nations Code ALBANIA AL PORTUGAL PT ANDORRA AD ROMANIA RO AUSTRIA AT SERBIA RS BELGIUM BE SLOVAKIA SK BOSNIA BA SLOVENIA SI BULGARIA BG SPAIN ES CIS RU SWEDEN SE CROATIA HR SWITZERLAND CH CYPRUS CY UK GB CZECH CZ AMERICA US DENMARK DK CANADA CA FINLAND FI MEXICO MX FRANCE FR ARGENTINA AR GERMANY DE CHILE CL GREECE GR PERU PE HUNGRARY HU THAILAND TH ICELAND IS VIETNAM VN IRELAND IE MALAYSIA MY ITALY IT INDONESIA ID LUXEMBOURG LU PHILIPPINES PH MACEDONIA MK BRAZIL BR MONTENEGRO ME ALGERIA DZ NETHERLAND NL MOROCCO MA NORWAY NO TUNISIA TN POLAND PL 60
9.2. Language Code You can get this code from Application Manager. Refer ch. 6.7, for more details. Language Code Language Code Korean 0 Spanish 24 English 1 Swedish 25 Spanish(America) 2 Turkish 26 French(America) 3 Chinese 27 Portuguese(America) 4 Hongkong 28 Bulgarian 5 Taiwan 29 Croatian 6 Japanese 30 Czech 7 Maori 31 Danish 8 CMN 32 Dutch 9 YUE 33 Finnish 10 Hindi 34 French 11 Estonian 35 German 12 Latvian 36 Modern Greek 13 Lithuanian 37 Hungarian 14 Arabic 38 Italian 15 Persian 39 Norwegian 16 QAA 40 English(GB) 17 AD 41 Polish 18 Catalan 42 Portuguese 19 VAL 43 Romany 20 Hebrew 44 Russian 21 OTHER 45 Serbian 22 Thai 46 Slovak 23 61
9.3. Region Code You can get this code from Application Manager. Refer ch. 6.7, for more details. Code KOR USA BRA PANEURO CHI HKG ARB PANNORDIG SOUTHEASTASIA ASIA_ATV ASIA_DTV TW NORTHAFRICA EA_DTV CIS PHI S_AFR_DTV Region Korea USA/Canada/Mexico Brazil, Paraguay, Uruguay, Argentine Europe China Hong Kong Arab Nordic South-East Asia (Vietnam, Thailand, India, China, Iran, Israel, Central Asia, East Asia, Africa) South-East Asia (Vietnam, Thailand, India, China, Iran, Israel, Central Asia, East Asia, Africa) Australia, New Zealand, Singapore Taiwan, Columbia TURKEY, MOROCCO, TUNISIA Indonesia, Malaysia, Republic of South Africa, Vietnam CIS Philippine South Africa DTV 62