Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

bada basics fundamentals & ui

5,090 views

Published on

bada basics fundamentals & ui

Published in: Education
  • Be the first to comment

bada basics fundamentals & ui

  1. 1. Basics: Fundamentals & UI Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
  2. 2. Contents bada API overview – bada namespaces and privileges Coding idioms – Exception handling – Two phase construction – Memory handling – Virtual path bada UI basics Application life cycle *This material is based on bada SDK 1.0.0b3 Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 2
  3. 3. bada API overview 1. bada namespaces 2. Privilege levels and groups Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 3
  4. 4. bada namespaces Basic bada features User interactive features Service oriented features Osp::App Osp::Graphics Osp::Commerce Osp::Base Osp::Media Osp::Content Osp::Io Osp::Ui Osp::Locations Osp::Locales Osp::Uix Osp::Messaging Osp::Net Osp::Web Osp::Social Osp::Security Osp::System Osp::Telephony Osp::Text Service Device Kernel Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 4
  5. 5. Namespaces – basic bada Basic bada features Basic bada features User interactive features Service oriented features Osp::App Osp::App Osp::Graphics Osp::Commerce Osp::Base Osp::Base Osp::Base  Osp::Media Osp::Content Osp::Io Osp::Ui Osp::Locations Osp::Io Fundamental bada Osp::Locales Osp::Uix Osp::Messaging classes: Osp::Locales Osp::Net Osp::Web Osp::Social Osp::Net Osp::Security String, ArrayList, Osp::System Thread, Osp::Security Math … Osp::Telephony Osp::System Osp::Text Osp::Telephony Service Osp::Text Device Kernel Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 5
  6. 6. Namespaces – User Interactive User interactive features Basic bada features User interactive features Service oriented features Osp::App Osp::Graphics Osp::Graphics Osp::Commerce Osp::Base Osp::Media Osp::Uix  Osp::Content Osp::Media Osp::Io Osp::Ui Osp::Locations Osp::Ui Extended user Osp::Locales Osp::Uix Osp::Messaging interaction functions: Osp::Net Osp::Uix Osp::Web Osp::Social Osp::Security Touch, snap, Osp::Web Sensors … Osp::System Osp::Telephony Osp::Text Service Device Kernel Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 6
  7. 7. Namespaces – User Interactive User interactive features Basic bada features User interactive features Service oriented features Osp::App Osp::Graphics Osp::Graphics Osp::Commerce Osp::Base Osp::Media Osp::Web  Osp::Content Osp::Media Osp::Io Osp::Ui Osp::Locations Osp::Ui Browser control API Osp::Locales Osp::Uix Osp::Messaging Osp::Net Osp::Uix Osp::Web Osp::Social Osp::Security Osp::Web Osp::System Osp::Telephony Osp::Text Service Device Kernel Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 7
  8. 8. Namespaces – Service Oriented Service oriented features Basic bada features User interactive features Service oriented features Osp::App Osp::Graphics Osp::Commerce Osp::Commerce Osp::Base Osp::Media Osp::Content Osp::Content  Osp::Content Osp::Io Osp::Ui Osp::Locations Osp::Locales Osp::Uix Osp::Locations Local and remote Osp::Messaging Osp::Net content Osp::Web Osp::Messaging Osp::Social Osp::Security management Osp::Social Osp::System Osp::Telephony Osp::Text Service Device Kernel Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 8
  9. 9. Namespaces – Service Oriented Service oriented features Basic bada features User interactive features Service oriented features Osp::App Osp::Graphics Osp::Commerce Osp::Commerce Osp::Base Osp::Media Osp::Content Osp::Locations  Osp::Content Osp::Io Osp::Ui Osp::Locations Osp::Locales Osp::Uix Osp::Locations Interaction, Osp::Messaging Osp::Net visualisation of Osp::Web Osp::Messaging Osp::Social Osp::Security locations and Osp::Social Osp::System maps Osp::Telephony Osp::Text Service Device Kernel Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 9
  10. 10. Privilege levels Privilege levels are related to your developer membership Regulate access to the platform and user-sensitive data Level Description None-privileged Does not require any privileges. Normal Usable by all bada developer. System Usable only by Samsung developer partners. Every privilege level allows access to different privilege groups (= functionalities) Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 10
  11. 11. Coding idioms 1. Exception handling 2. Two phase construction 3. Memory handling 4. Virtual path Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 11
  12. 12. Exception handling (1/3) bada does not use standard C++ exception handling All exceptions are caught by using the bada specific result type Examples for result error types: Error Type Description E_SUCCESS The method was successful E_OUT_OF_MEMORY Insufficient memory E_SYSTEM A system error occurred Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 12
  13. 13. 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 } Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 13
  14. 14. 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; } Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 14
  15. 15. Two phase construction (1/2) bada uses a two phase construction Why? – 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 Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 15
  16. 16. Two phase construction (2/2) Example: result r = E_SUCCESS; // 1. Phase: create object CallManager *pCallManager = new CallManager(); // 2. Phase: initialize object (+allocations) r = pCallManager->Construct(); if(IsFailed(r)){ delete pCallManager; } Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 16
  17. 17. 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 Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 17
  18. 18. 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() Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 18
  19. 19. Memory handling (3/3) GetContentInfoN(): ContentInfo* pInfo = null; pInfo = mgr.GetContentInfoN(contentId); delete pInfo; OnLandmarksReceivedN(): void LandmarkManager::OnLandmarksReceivedN(, Osp::Base::Collection::IList* pResults,,,) { if (r == E_SUCCESS && pResults) { pMainForm->DrawLandmarks(pResults); pResults->RemoveAll(true); delete pResults; } } Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 19
  20. 20. Virtual path Directory Usage Permission Used to store application specific data /Home E.g.: Read/Write String fileName("/Home/test.txt"); Used to read resource files, such as for UI or /Res Read-only music and video files /Home/Share Used to share data with other bada applications Read/Write Used to read data from other bada apps via their /Share/[appid] Read-only [appid] Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 20
  21. 21. bada UI basics 1. UI controls 2. Screen structure 3. Event handling 4. UI Builder Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 21
  22. 22. Controls in bada Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 22
  23. 23. UI screen structure Frame The top level window Indicator There is one per application Title Control(s) Controls are added to Form(s) forms High level container There can be multiple forms Softkey Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 23
  24. 24. Create and show a Form Step 1: Create a Form: Form1 *pForm = new Form1(); pForm->Construct(FORM_STYLE_TITLE| FORM_STYLE_SOFTKEY_0|FORM_STYLE_INDICATOR); Other FORM_STYLEs: NORMAL/ TITLE/ INDICATOR/ SOFTKEY_0/ SOFTKEY_1/ OPTIONKEY/ TEXT_TAB/ ICON_TAB Step 2: Add Form to Frame: Frame *pFrame = GetAppFrame()->GetFrame(); pFrame->AddControl(*pForm); Step 3: Show the Form: pFrame->SetCurrentForm(*pForm); pFrame->RequestRedraw(true); // true for Draw() & Show() Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 24
  25. 25. Event handling Events: – Controls: focus, drag and drop, touch, and key – Add EventListener to Control to handle events ITouchEventListener { TouchReleased OnTouchPressed() {…} OnTouchMoved() {…} OnTouchReleased() {…} TouchMoved OnTouchDoublePressed() {…} // … } TouchPressed Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 25
  26. 26. Handling of Touch events Step 1: Inherit from listener interface class TouchListener : public ITouchEventListener {…} Step 2: Implement event handler method void TouchListener::OnTouchPressed (…,const Point& currentPosition, …) {…} Step 3: Add event listener to control AddTouchEventListener(ITouchEventListener &); Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 26
  27. 27. UI Builder tool basics Design Area Controls Resource Explorer Properties Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 27
  28. 28. Application life cycle Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 28
  29. 29. Overall application life cycle Launch OnAppInitializing() Success Running Failure OnForeground() OnBackground() OnAppTerminating() Terminated Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 29
  30. 30. Launch OnAppInitializing() OnAppInitializing() OnForeground() Invoked as soon as application is launched Initialize application resources bool MyPlaces::OnAppInitializing(AppRegistry& appRegistry) { // Initialize... … return true; } Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 30
  31. 31. OnBackground() OnAppInitializing() OnForeground() 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. void MyPlaces::OnBackground(void){} Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 31
  32. 32. OnForeground() OnAppInitializing() OnForeground() OnBackground() OnForeground() is called when the base application is terminated Recommendation: – Resume normal application processes and resource consumption void MyPlaces::OnForeground(void){} Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 32
  33. 33. OnAppTerminating() OnForeground() OnBackground() 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 bool MyPlaces::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination) { // save app state into appRegistry … } Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 33
  34. 34. Summary Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 34
  35. 35. 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 Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 35
  36. 36. Find out more Tutorials: – bada Tutorial.Fundamentals.pdf – bada Tutorial.Application.pdf – bada Tutorial.UI and Graphics.pdf Samples – BasicApp – UiControls Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 36
  37. 37. 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.
  38. 38. Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.
  39. 39. Dive into http://www.goprodiver.com Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

×