bada basics fundamentals & ui

39
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. Basics: Fundamentals & UI

Upload: samsung

Post on 19-Jan-2015

4.502 views

Category:

Education


2 download

DESCRIPTION

bada basics fundamentals & ui

TRANSCRIPT

Page 1: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Basics:Fundamentals & UI

Page 2: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Contents

bada API overview– bada namespaces and privileges

Coding idioms– Exception handling– Two phase construction– Memory handling– Virtual path

bada UI basicsApplication life cycle

2*This material is based on bada SDK 1.0.0b3

Page 3: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

bada API overview

1. bada namespaces2. Privilege levels and groups

3

Page 4: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

bada namespaces

4

User interactive features Service oriented featuresBasic bada featuresOsp::App

Osp::Base

Osp::IoOsp::LocalesOsp::Net

Osp::SecurityOsp::SystemOsp::Telephony

Osp::GraphicsOsp::MediaOsp::Ui

Osp::Uix

Osp::Web

Osp::CommerceOsp::ContentOsp::Locations

Osp::Messaging

Osp::Social

Osp::Text

KernelDevice

Service

Page 5: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Namespaces – basic bada

5

User interactive features Service oriented featuresBasic bada featuresOsp::App

Osp::Base

Osp::IoOsp::LocalesOsp::Net

Osp::SecurityOsp::SystemOsp::Telephony

Osp::GraphicsOsp::MediaOsp::Ui

Osp::Uix

Osp::Web

Osp::CommerceOsp::ContentOsp::Locations

Osp::Messaging

Osp::Social

Osp::Text

KernelDevice

Service

Osp::Base

Fundamental badaclasses:

String, ArrayList, Thread,Math …

Basic bada features

Osp::AppOsp::BaseOsp::IoOsp::LocalesOsp::NetOsp::SecurityOsp::SystemOsp::TelephonyOsp::Text

Page 6: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Namespaces – User Interactive

6

User interactive features Service oriented featuresBasic bada featuresOsp::App

Osp::Base

Osp::IoOsp::LocalesOsp::Net

Osp::SecurityOsp::SystemOsp::Telephony

Osp::GraphicsOsp::MediaOsp::Ui

Osp::Uix

Osp::Web

Osp::CommerceOsp::ContentOsp::Locations

Osp::Messaging

Osp::Social

Osp::Text

KernelDevice

Service

User interactive features

Osp::GraphicsOsp::MediaOsp::UiOsp::UixOsp::Web

Osp::Uix

Extended user interaction functions:

Touch, snap, Sensors …

Page 7: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Namespaces – User Interactive

7

User interactive features Service oriented featuresBasic bada featuresOsp::App

Osp::Base

Osp::IoOsp::LocalesOsp::Net

Osp::SecurityOsp::SystemOsp::Telephony

Osp::GraphicsOsp::MediaOsp::Ui

Osp::Uix

Osp::Web

Osp::CommerceOsp::ContentOsp::Locations

Osp::Messaging

Osp::Social

Osp::Text

KernelDevice

Service

User interactive features

Osp::GraphicsOsp::MediaOsp::UiOsp::UixOsp::Web

Osp::Web

Browser control API

Page 8: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Namespaces – Service Oriented

8

User interactive features Service oriented featuresBasic bada featuresOsp::App

Osp::Base

Osp::IoOsp::LocalesOsp::Net

Osp::SecurityOsp::SystemOsp::Telephony

Osp::GraphicsOsp::MediaOsp::Ui

Osp::Uix

Osp::Web

Osp::CommerceOsp::ContentOsp::Locations

Osp::Messaging

Osp::Social

Osp::Text

KernelDevice

Service

Service oriented features

Osp::CommerceOsp::ContentOsp::LocationsOsp::MessagingOsp::Social

Osp::Content

Local and remote content

management

Page 9: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Namespaces – Service Oriented

9

User interactive features Service oriented featuresBasic bada featuresOsp::App

Osp::Base

Osp::IoOsp::LocalesOsp::Net

Osp::SecurityOsp::SystemOsp::Telephony

Osp::GraphicsOsp::MediaOsp::Ui

Osp::Uix

Osp::Web

Osp::CommerceOsp::ContentOsp::Locations

Osp::Messaging

Osp::Social

Osp::Text

KernelDevice

Service

Service oriented features

Osp::CommerceOsp::ContentOsp::LocationsOsp::MessagingOsp::Social

Osp::Locations

Interaction, visualisation of

locations and maps

Page 10: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Privilege levels

Privilege levels are related to your developer membership

Regulate access to the platform and user-sensitive data

Every privilege level allows access to different privilege groups (= functionalities)

10

Level DescriptionNone-privileged Does not require any privileges.Normal Usable by all bada developer.System Usable only by Samsung developer partners.

Page 11: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Coding idioms

1. Exception handling

2. Two phase construction

3. Memory handling

4. Virtual path

11

Page 12: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Exception handling (1/3)

bada does not use standard C++ exception handling

All exceptions are caught by using the badaspecific result type

Examples for result error types:

12

Error Type DescriptionE_SUCCESS The method was successfulE_OUT_OF_MEMORY Insufficient memoryE_SYSTEM A system error occurred

Page 13: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Exception handling (2/3)

Check the result return value– Exceptions are indicated by the return value:

result r = E_SUCCESS;

r = Camera::StartPreview( null, false );

if(IsFailed(r)){

// process the error condition

}else {// continue normally

}

13

Page 14: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Exception handling (3/3)

Check the last result using GetLastResult()– If an operation returns null:

DirEnumerator* pEnum = dir.ReadN();

if(pEnum == null){

AppLog("Directory::ReadN() failed with error: %s", GetErrorMessage(GetLastResult()));

return false;}

14

Page 15: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Two phase construction (1/2)

bada uses a two phase constructionWhy?– bada does not use standard C++ exception

mechanism to increase runtime efficiency– And to prevent resource leaks in C++

How?– The resource allocation logic is performed in

an extra Construct() method– The destructor follows traditional C++

conventions

15

Page 16: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Two phase construction (2/2)

Example:result r = E_SUCCESS;

// 1. Phase: create objectCallManager *pCallManager = new CallManager();

// 2. Phase: initialize object (+allocations)r = pCallManager->Construct();

if(IsFailed(r)){delete pCallManager;

}

16

Page 17: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Memory handling (1/3)

Ownership policy:– The “owner” of an object is responsible for

deleting dynamically allocated memory

Image* pImage = new Image();

// Some code ...

delete pImage;

Must be deleted to avoid a memory leak!

17

Page 18: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Memory handling (2/3)

Rules for 'N' postfix methods:– The caller must delete the returned instance

after an ‘N’ postfix method is called– Change of “ownership”

Examples for ‘N’ postfix methods:– GetContentInfoN()– DecodeN()– GetValueListN()– SearchN()– OnLandMarkReceivedN()

18

Page 19: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Memory handling (3/3)

GetContentInfoN():

OnLandmarksReceivedN():

ContentInfo* pInfo = null;pInfo = mgr.GetContentInfoN(contentId);delete pInfo;

voidLandmarkManager::OnLandmarksReceivedN(,

Osp::Base::Collection::IList* pResults,,,){

if (r == E_SUCCESS && pResults) {pMainForm->DrawLandmarks(pResults);pResults->RemoveAll(true);delete pResults;

}}

19

Page 20: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Virtual path

Directory Usage Permission

/HomeUsed to store application specific dataE.g.:String fileName("/Home/test.txt");

Read/Write

/Res Used to read resource files, such as for UI or music and video files Read-only

/Home/Share Used to share data with other bada applications Read/Write

/Share/[appid] Used to read data from other bada apps via their [appid] Read-only

20

Page 21: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

bada UI basics

21

1. UI controls

2. Screen structure

3. Event handling

4. UI Builder

Page 22: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Controls in bada

22

Page 23: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

UI screen structure

IndicatorTitle

Softkey

FrameThe top level windowThere is one per application

Form(s)High level container There can be multiple forms

Control(s)Controls are added to

forms

23

Page 24: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Create and show a Form

Step 1: Create a Form:

Step 2: Add Form to Frame:

Step 3: Show the Form:

Form1 *pForm = new Form1();pForm->Construct(FORM_STYLE_TITLE|

FORM_STYLE_SOFTKEY_0|FORM_STYLE_INDICATOR);

Frame *pFrame = GetAppFrame()->GetFrame();pFrame->AddControl(*pForm);

pFrame->SetCurrentForm(*pForm);pFrame->RequestRedraw(true); // true for Draw() & Show()

Other FORM_STYLEs: NORMAL/ TITLE/ INDICATOR/ SOFTKEY_0/ SOFTKEY_1/ OPTIONKEY/ TEXT_TAB/ ICON_TAB

24

Page 25: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Event handling

Events:– Controls: focus, drag and drop, touch, and key– Add EventListener to Control to handle events

TouchPressed

TouchMoved

TouchReleased

ITouchEventListener{

OnTouchPressed() {…}OnTouchMoved() {…}OnTouchReleased() {…}

OnTouchDoublePressed() {…}// …

}

25

Page 26: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Handling of Touch events

Step 1: Inherit from listener interface

Step 2: Implement event handler method

Step 3: Add event listener to control

class TouchListener : public ITouchEventListener{…}

void TouchListener::OnTouchPressed(…,const Point& currentPosition, …)

{…}

AddTouchEventListener(ITouchEventListener &);

26

Page 27: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

UI Builder tool basics

27

ResourceExplorer

Design Area

Properties

Controls

Page 28: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Application life cycle

28

Page 29: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Overall application life cycle

OnAppInitializing()

Terminated

SuccessRunning

Failure OnForeground()

OnAppTerminating()

OnBackground()

Launch

29

Page 30: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

OnAppInitializing()

Invoked as soon as application is launched

Initialize application resources

30

boolMyPlaces::OnAppInitializing(AppRegistry& appRegistry){// Initialize... …return true;

}

OnForeground()OnAppInitializing()

Launch

Page 31: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

OnBackground()

OnBackground() is called when a base application is launched (e.g.: incoming calls or SMS messages)

Recommendation:– Release unnecessary

resources– Stop heavy operations

• Multimedia/graphics/etc.

31

OnForeground() OnBackground()

OnAppInitializing()

voidMyPlaces::OnBackground(void){}

Page 32: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

OnForeground()

OnForeground() is called when the base application is terminated

Recommendation:– Resume normal application

processes and resource consumption

32

voidMyPlaces::OnForeground(void){}

OnForeground() OnBackground()

OnAppInitializing()

Page 33: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

OnAppTerminating()

OnAppTerminating() is called when:– Another bada app is launched – End key is pressed – Low battery or memory

Recommendation:– Save state to the registry– Destroy unnecessary, allocated

resources

33

bool MyPlaces::OnAppTerminating(AppRegistry& appRegistry,bool forcedTermination)

{ // save app state into appRegistry …

}

OnAppTerminating()

OnBackground()OnForeground()

Page 34: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Summary

34

Page 35: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

What we have learned

bada API overview– Namepaces– Privileges

bada coding idioms– Exception handling through result type– Two phase construction for runtime efficiency– Memory management and ‘N’ postfix– Virtual path (/Home, /Res, etc.)

UI basics– UI screen structure, controls, UI Builder

App life cycle– 4 states

35

Page 36: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Find out more

Tutorials:– bada Tutorial.Fundamentals.pdf– bada Tutorial.Application.pdf– bada Tutorial.UI and Graphics.pdf

Samples – BasicApp– UiControls

36

Page 37: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

3D augmented reality first person shooter

Makes use of bada to its full potential

- 360° OpenGL 3D graphics- Camera- Accelerometer, compass, tilt sensors- Audio feedback- Powerful hardware- To be published in SamsungApps store

Follow us on Twitter at #ROTU

by Samsung Mobile Innovator

Page 38: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

Page 39: bada basics fundamentals & ui

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.http://www.goprodiver.comDive into