Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
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
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
bada API overview
1. bada namespaces2. Privilege levels and groups
3
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
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
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 …
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
Controls in bada
22
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
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
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
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
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
UI Builder tool basics
27
ResourceExplorer
Design Area
Properties
Controls
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
Application life cycle
28
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
Overall application life cycle
OnAppInitializing()
Terminated
SuccessRunning
Failure OnForeground()
OnAppTerminating()
OnBackground()
Launch
29
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
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){}
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()
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()
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
Summary
34
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
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
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
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.http://www.goprodiver.comDive into