Development Techniques for Native/Hybrid Tizen Apps Presented by - - PowerPoint PPT Presentation

development techniques for native hybrid tizen apps
SMART_READER_LITE
LIVE PREVIEW

Development Techniques for Native/Hybrid Tizen Apps Presented by - - PowerPoint PPT Presentation

Development Techniques for Native/Hybrid Tizen Apps Presented by Kirill Kruchinkin Agenda Introduction and Definitions Practices Case Studies 2 Introduction & Definitions 2 App Types Browser Apps Installable Apps


slide-1
SLIDE 1

Development Techniques for Native/Hybrid Tizen Apps

Presented by Kirill Kruchinkin

slide-2
SLIDE 2

2

Agenda

  • Introduction and Definitions
  • Practices
  • Case Studies
slide-3
SLIDE 3

Introduction & Definitions

slide-4
SLIDE 4

4

2 App Types

Browser Apps Installable Apps

  • Native
  • WebApps
  • Hybrid
slide-5
SLIDE 5

5

Browser Apps

One platform for many devices

  • HTML5 is everywhere
  • HTML5 is mobile
  • HTML5 is skillful
  • HTML5 is open
slide-6
SLIDE 6

6

Tizen Application Level

Native Framework Web Framework

Web Applications Native Applications

Social / Content

Core App Framework Graphics / UI Multimedia Location Messaging Web Security System Base Connectivity Telephony PIM

Linux Kernel and Device Drivers

Locations Uix Media Web / Xml Net / Telephony / Messaging Graphics / UI Base / Io / Text / Locales App / Security / System Services Web Runtime

Device APIs W3C / HTML5

Video CSS3 Worker Touch WebGL °°° BT NFC Call MSG °°°

slide-7
SLIDE 7

7

Advantages of Browser Apps with HTML5

  • Full offline support
  • Device APIs
  • Native UI

Web Apps

Browser

Websites Tizen Web Application

W3C Standard JS API Webkit W3C Standard JS API Webkit Tizen Device API Plugins Native Platform

Web Runtime

slide-8
SLIDE 8

8

Native Apps

  • Broader access to device hardware
  • Better integration with system features
  • Faster, smoother and better UI
slide-9
SLIDE 9

9

Hybrid Apps

  • Web UI and Native Services
  • Rapid development of UI
  • Data processing in background
  • Share native services between applications
  • Native open-source libraries
slide-10
SLIDE 10

10

Always a Challenging Decision

Native Web Hybrid Rapid UI development

  • +

+ Open standards based

  • +

+ Performance in heavy calculation +

  • +

Works offline + + + Background support +

  • +

Deep HW/platform integration +

  • +

Low complexity

  • +
slide-11
SLIDE 11

Practices

slide-12
SLIDE 12

12

Steps to a Hybrid App

  • Create a web application project
  • Create a native service project
  • Define the reference in the project’s properties
  • Define a “bridge” between the web and service applications
  • Build the application
  • Install the application
slide-13
SLIDE 13

13

Bridging Native and JS

  • Messaging layer between web and native
  • Message Port
  • Websocket
  • JavaScriptBridge plugin
slide-14
SLIDE 14

14

App Communication through Message Ports

  • Implements a communication between two applications
  • Platform built-in
slide-15
SLIDE 15

15

function onReceive(data, remoteMsgPort) { console.log('Received data to \'' + remoteMsgPort.name + '\''); // Search value with the "response“ key for(var i in data) { if(data[i].key == "response") { response = data[i].value; break; } } } try { localMessagePort = tizen.messageport.requestLocalMessagePort(localMessagePortName); localMessagePortWatchId = localMessagePort.addMessagePortListener(function(data, remote) {

  • nReceive(data, remote); } );

} catch (e) { console.log("Request local message port Error"); }

  • Define message handler and create a local message port

Message Porting: Web Step 1

slide-16
SLIDE 16

16

function onSuccess() { console.log("Service App launched successfully!"); } function onError(err) { console.log("Service Applaunch failed ="+ err); } try { tizen.application.launch(appId, onSuccess, onError); } catch (e) { // handle error }

  • Launch service application

Message Porting: Web Step 2

slide-17
SLIDE 17

17

try { remoteMessagePort = tizen.messageport.requestRemoteMessagePort(appId, servicePortName); } catch (e) { console.log("Request remote message port Error "); }

  • Open remote port

Message Porting: Web Step 3

slide-18
SLIDE 18

18

Message Porting: Native Step 1

  • Define local port listener

void ServiceChannel::OnMessageReceivedN(RemoteMessagePort* pRemoteMessagePort, IMap* pMessage) { String *pData = static_cast<String *>(pMessage->GetValue(String(L"command"))); if (pData != null) { IJsonValue* pJson = getJsonObj(pData); if(null != pJson) { // Extract command from pJson in to the pCommand pointer ... if(null != pCommand) { if (pCommand->Equals(DO_COMMAND_1, true)) { // extract additional parameters from pJson and perform requested operation – it is would be better to schedule this operation and // execute it asynchronously (for example, send event to application, set timer, run thread etc,..) } } // Relase pJsonObject ... } // Prepare answer in str variable ... //Send response in case of bi-direction communication HashMap *pMap = new HashMap(SingleObjectDeleter); pMap->Construct(); pMap->Add(new String(L"response"), new String(str)); pRemoteMessagePort->SendMessage(mLocalMessagePort, pMap); // deallocate resources ... }

slide-19
SLIDE 19

19

Message Porting: Native Step 2

  • Create local port

mLocalMessagePort = MessagePortManager::RequestLocalMessagePort(mLocalPortName); mLocalMessagePort->AddMessagePortListener( messagePortListenerImplementation );

slide-20
SLIDE 20

20

Message Porting: Native Step 3

  • Create remote port

mRemoteMessagePort = MessagePortManager::RequestRemoteMessagePort(mRemoteAppID, mRemotePortName);

slide-21
SLIDE 21

21

Websocket Approach

  • Works in other platforms
  • Works asynchronously
  • Doesn’t have a payload limit
  • Handshake implementation RFC 6455
slide-22
SLIDE 22

22

Javascriptbridge Plugin

  • Include the JavaScriptBridge plugin in a Web page
  • Implement a JS method to be called from native
  • Implement Tizen::Web::Controls::IJavaScriptBridge on native

sode

slide-23
SLIDE 23

23

Debugging

slide-24
SLIDE 24

24

Debugging Video

slide-25
SLIDE 25

25

3rd Party lib Static Linking

slide-26
SLIDE 26

26

3rd Party lib Dynamic Linking

//get a lib Path wchar_t const * const LIB_NAME = L"lib/libHybridServiceLib.so"; Tizen::App::App *pxApp = Tizen::App::App::GetInstance(); String libPath = pxApp-> GetAppRootPath(); libPath.Append(LIB_NAME); //get initialized instance of Library Tizen::Base::Runtime::Library library; result r = library.Construct(libPath); //get a function pointer void *pMethod = library.GetProcAddress(L"CalculateMd5"); pCalculateHash = reinterpret_cast<char* (*)(byte const *, int)>(pMethod); //use the function pCalculateHash(pByteArray, byteArrayLength);

slide-27
SLIDE 27

27

JSON

  • JavaScript Object Notation (JSON) is a text-based open standard

designed for human-readable data interchange

  • Parsers are available for JavaScript (native JS, jQuery and other

frameworks) and a native API

  • Human-readable format that is easy for debug
  • Web services provide data in JSON format
  • Key-value data format is enough to present any data that is

required in JavaScript

slide-28
SLIDE 28

28

JSON Usage

  • Web
  • Native
  • Tizen::Web::Json::JsonParser for parsing
  • Tizen::Web::Json::JsonWriter for composing

// parse var jsonData = JSON.parse(strJSON); // compose var strJSON = JSON.stringify(jsonData)

slide-29
SLIDE 29

29

3rd Party frameworks

  • Cordova
  • Appcelerator Titanium
  • Cocos2d-html5
slide-30
SLIDE 30

30

Tips & Tricks

  • Use Message Ports as a bridge
  • Implement re-try logic to open Message Ports
  • Use JSON to transfer data
  • Widely use Resource Acquisition Is Initialization (RAII) idiom
  • Share assets and layouts between multiple apps in your

package

  • Specify all privileges needed for the app in the manifest of the

main project

slide-31
SLIDE 31

Case Studies

slide-32
SLIDE 32

32

TuneIn

  • TuneIn offers the user the ability to

listen to streaming audio from thousands of radio stations

  • It is a Hybrid App to support more audio

formats and resolve stream handling

  • Web App
  • UI part
  • TuneIn server communication
  • Native Service
  • audio playing
  • playlist downloading
slide-33
SLIDE 33

33

TuneIn Video

slide-34
SLIDE 34

34

Peeking Protector: native experience

  • A face recognition application that restricts

access to a whole device or selected applications unless the owner’s face is recognized.

  • The application is fully native because the app

should:

  • intercept launching other protecting apps
  • have the top-most visibility
  • hook hard keys like Home and Power
  • utilize native built-in face recognition API
  • use multi-threading to be responsive while the face recognition

piece is in progress

slide-35
SLIDE 35

35

Peeking Protector Video

slide-36
SLIDE 36