Hello,Bada!

为什么要学bada:

现在的移动市场,纷争四起,各大厂商齐发力。目前笑的最从容的当属iPhone和Android。

在移动开发领域混了几年,感觉开发者是最苦的。要学的东西太多了,这么多手机系统,要全掌握并精通,

那简直是不可能的。聪明些的,就会做出选择,也就是所谓的抱大腿,只要你抱对了,日子过得会有滋有味;抱错了,

面临了继续重新做选择。举个现在大家都知道的例子,07年iPhone一出,好多人去学,结果那第一批人成功了;紧接着,

android也在酝酿着,好多人去学,09年android大爆发,这批人也牛了;symbian的无力,现在好多symbian开发者面临

着选择,投入到android还是iPhone,这是个问题。

其实,学习bada有几点好处:

1、这是个抱大腿的机会,如果bada修成正果,这宝也就压对了。

2、学习人家的架构,对自己还是有益的。

3、多交朋友。每个领域都有朋友,积累人脉,日后用得着。

bada简介:

sumsang的智能手机系统,开放而不开源的,用C++作开发语言,IDE是基于Eclipse的。

第一个bada程序,hello bada

开发程序,首先要搭建环境。

去sumsang官网下载吧,http://developer.bada.com/devtools/sdk

8月25日,也就是周五那一天,bada2.0放出来了。我是昨晚知道的,当然是要下载来看看了。

比之前的下载,这次有所不同。之前的版本都是下载安装包,本地安装,而这次是下载个exe,

在线安装。这可苦了我,晚上安装了近7个小时,中途出现各种断网问题,郁闷之极啊。

安装完毕后,一切就齐活了。这让我想起3年前搭symbian程序,那时才叫痛苦呢。

打开ide,如果你熟悉eclipse,一切都是那么熟悉。

下面,是看帮助文档。好东西全在这里面呢。

Helloworld.h
  1. #ifndef _HELLOWORLD_H_  
  2. #define _HELLOWORLD_H_  
  3.   
  4. #include <FApp.h>  
  5. #include <FBase.h>  
  6. #include <FSystem.h>  
  7. #include <FUi.h>  
  8.   
  9. /** 
  10.  * [Helloworld] application must inherit from Application class 
  11.  * which provides basic features necessary to define an application. 
  12.  */  
  13. class Helloworld :  
  14.     public Osp::App::Application,  
  15.     public Osp::System::IScreenEventListener  
  16. {  
  17. public:  
  18.   
  19.     /** 
  20.      * [Helloworld] application must have a factory method that creates an instance of itself. 
  21.      */  
  22.     static Osp::App::Application* CreateInstance(void);  
  23.   
  24.   
  25. public:  
  26.     Helloworld();  
  27.     ~Helloworld();  
  28.   
  29.   
  30. public:  
  31.   
  32.   
  33.     // Called when the application is initializing.  
  34.     bool OnAppInitializing(Osp::App::AppRegistry& appRegistry);  
  35.   
  36.     // Called when the application is terminating.  
  37.     bool OnAppTerminating(Osp::App::AppRegistry& appRegistry, bool forcedTermination = false);  
  38.   
  39.   
  40.     // Called when the application's frame moves to the top of the screen.  
  41.     void OnForeground(void);  
  42.   
  43.   
  44.     // Called when this application's frame is moved from top of the screen to the background.  
  45.     void OnBackground(void);  
  46.   
  47.     // Called when the system memory is not sufficient to run the application any further.  
  48.     void OnLowMemory(void);  
  49.   
  50.     // Called when the battery level changes.  
  51.     void OnBatteryLevelChanged(Osp::System::BatteryLevel batteryLevel);  
  52.   
  53.     // Called when the screen turns on.  
  54.     void OnScreenOn (void);  
  55.   
  56.     // Called when the screen turns off.  
  57.     void OnScreenOff (void);  
  58. };  
  59.   
  60. #endif  
Helloworld.cpp
  1. /** 
  2.  * Name        : Helloworld 
  3.  * Version     :  
  4.  * Vendor      : linc 
  5.  * Description :  
  6.  */  
  7.   
  8.   
  9. #include "Helloworld.h"  
  10. #include "HelloworldForm.h"  
  11.   
  12. using namespace Osp::App;  
  13. using namespace Osp::Base;  
  14. using namespace Osp::System;  
  15. using namespace Osp::Ui;  
  16. using namespace Osp::Ui::Controls;  
  17.   
  18. Helloworld::Helloworld()  
  19. {  
  20. }  
  21.   
  22. Helloworld::~Helloworld()  
  23. {  
  24. }  
  25.   
  26. Application*  
  27. Helloworld::CreateInstance(void)  
  28. {  
  29.     // Create the instance through the constructor.  
  30.     return new Helloworld();  
  31. }  
  32.   
  33. bool  
  34. Helloworld::OnAppInitializing(AppRegistry& appRegistry)  
  35. {  
  36.     // TODO:  
  37.     // Initialize UI resources and application specific data.  
  38.     // The application's permanent data and context can be obtained from the appRegistry.  
  39.     //  
  40.     // If this method is successful, return true; otherwise, return false.  
  41.     // If this method returns false, the application will be terminated.  
  42.   
  43.     // Uncomment the following statement to listen to the screen on/off events.  
  44.     //PowerManager::SetScreenEventListener(*this);  
  45.   
  46.     // Create a form  
  47.     HelloworldForm *pHelloworldForm = new HelloworldForm();  
  48.     pHelloworldForm->Initialize();  
  49.   
  50.     // Add the form to the frame  
  51.     Frame *pFrame = GetAppFrame()->GetFrame();  
  52.     pFrame->AddControl(*pHelloworldForm);  
  53.   
  54.     // Set the current form  
  55.     pFrame->SetCurrentForm(*pHelloworldForm);  
  56.   
  57.     // Draw and Show the form  
  58.     pHelloworldForm->Draw();  
  59.     pHelloworldForm->Show();  
  60.   
  61.     return true;  
  62. }  
  63.   
  64. bool  
  65. Helloworld::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)  
  66. {  
  67.     // TODO:  
  68.     // Deallocate resources allocated by this application for termination.  
  69.     // The application's permanent data and context can be saved via appRegistry.  
  70.     return true;  
  71. }  
  72.   
  73. void  
  74. Helloworld::OnForeground(void)  
  75. {  
  76.     // TODO:  
  77.     // Start or resume drawing when the application is moved to the foreground.  
  78. }  
  79.   
  80. void  
  81. Helloworld::OnBackground(void)  
  82. {  
  83.     // TODO:  
  84.     // Stop drawing when the application is moved to the background.  
  85. }  
  86.   
  87. void  
  88. Helloworld::OnLowMemory(void)  
  89. {  
  90.     // TODO:  
  91.     // Free unused resources or close the application.  
  92. }  
  93.   
  94. void  
  95. Helloworld::OnBatteryLevelChanged(BatteryLevel batteryLevel)  
  96. {  
  97.     // TODO:  
  98.     // Handle any changes in battery level here.  
  99.     // Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.  
  100. }  
  101.   
  102. void  
  103. Helloworld::OnScreenOn (void)  
  104. {  
  105.     // TODO:  
  106.     // Get the released resources or resume the operations that were paused or stopped in OnScreenOff().  
  107. }  
  108.   
  109. void  
  110. Helloworld::OnScreenOff (void)  
  111. {  
  112.     // TODO:  
  113.     //  Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device to enter the sleep mode to save the battery.  
  114.     // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a callback before the device enters the sleep mode.  
  115.     // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.  
  116. }  
这里你会初步了解bada程序的生命周期,想必你已经和Android的生命周期作对比了吧?
我提醒一下哦,android的onStop之后就处于不可见对应于bada的OnBackground,剩下的对比就看出来了。
bada也是两阶段构造的,symbian的童鞋,你们熟悉不?
HelloworldEntry.cpp
  1. /** 
  2.  * This file contains the bada application entry point. 
  3.  */  
  4. #include "Helloworld.h"  
  5.   
  6. using namespace Osp::Base;  
  7. using namespace Osp::Base::Collection;  
  8.   
  9. #ifdef __cplusplus  
  10. extern "C"  
  11. {  
  12. #endif // __cplusplus  
  13.   
  14. _EXPORT_ int OspMain(int argc, char *pArgv[]);  
  15.   
  16. /** 
  17.  * The entry function of bada application called by the operating system. 
  18.  */  
  19. int  
  20. OspMain(int argc, char *pArgv[])  
  21. {  
  22.     result r = E_SUCCESS;  
  23.   
  24.     AppLog("Application started.");  
  25.     ArrayList* pArgs = new ArrayList();  
  26.     pArgs->Construct();  
  27.     for (int i = 0; i < argc; i++)  
  28.         pArgs->Add(*(new String(pArgv[i])));  
  29.   
  30.     r = Osp::App::Application::Execute(Helloworld::CreateInstance, pArgs);  
  31.     if (IsFailed(r))  
  32.     {  
  33.         AppLogException("Application execution failed-[%s].", GetErrorMessage(r));  
  34.         r &= 0x0000FFFF;  
  35.     }  
  36.   
  37.     pArgs->RemoveAll(true);  
  38.     delete pArgs;  
  39.     AppLog("Application finished.");  
  40.   
  41.     return static_cast<int>(r);  
  42. }  
  43. #ifdef __cplusplus  
  44. }  
  45. #endif // __cplusplus  
紧接着就是Form相关的了,这个做windows的又会很熟悉。
HelloworldForm.h
  1. #ifndef _HELLOWORLDFORM_H_  
  2. #define _HELLOWORLDFORM_H_  
  3.   
  4. #include <FBase.h>  
  5. #include <FUi.h>  
  6.   
  7. class HelloworldForm :  
  8.     public Osp::Ui::Controls::Form,  
  9.     public Osp::Ui::IActionEventListener,  
  10.     public Osp::Ui::ITouchEventListener  
  11. {  
  12.   
  13. // Construction  
  14. public:  
  15.     HelloworldForm(void);  
  16.     virtual ~HelloworldForm(void);  
  17.     bool Initialize(void);  
  18.   
  19. // Implementation  
  20. protected:  
  21.     static const int ID_BUTTON_OK = 101;  
  22.     Osp::Ui::Controls::Button *__pButtonOk;  
  23.     Osp::Ui::Controls::Label *__pLabel;  
  24. public:  
  25.     virtual result OnInitializing(void);  
  26.     virtual result OnTerminating(void);  
  27.     virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId);  
  28.   
  29.     virtual void OnTouchDoublePressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);  
  30.     virtual void OnTouchFocusIn(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);  
  31.     virtual void OnTouchFocusOut(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);  
  32.     virtual void OnTouchLongPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);  
  33.     virtual void OnTouchMoved(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);  
  34.     virtual void OnTouchPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);  
  35.     virtual void OnTouchReleased(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);  
  36. };  
  37.   
  38. #endif  //_HELLOWORLDFORM_H_  
HelloworldForm.cpp
  1. #include "HelloworldForm.h"  
  2.   
  3. using namespace Osp::Base;  
  4. using namespace Osp::Ui;  
  5. using namespace Osp::Ui::Controls;  
  6.   
  7. HelloworldForm::HelloworldForm(void)  
  8. {  
  9. }  
  10.   
  11. HelloworldForm::~HelloworldForm(void)  
  12. {  
  13. }  
  14.   
  15. bool  
  16. HelloworldForm::Initialize()  
  17. {  
  18.     // Construct an XML form  
  19.     Construct(L"IDF_HELLOWORLDFORM");  
  20.   
  21.     return true;  
  22. }  
  23.   
  24. result  
  25. HelloworldForm::OnInitializing(void)  
  26. {  
  27.     result r = E_SUCCESS;  
  28.   
  29.     // TODO: Add your initialization code here  
  30.   
  31.     // Get a button via resource ID  
  32.     __pButtonOk = static_cast<Button *>(GetControl(L"IDC_BUTTON_OK"));  
  33.     if (__pButtonOk != null)  
  34.     {  
  35.         __pButtonOk->AddTouchEventListener(*this);  
  36.         __pButtonOk->SetActionId(ID_BUTTON_OK);  
  37.         __pButtonOk->AddActionEventListener(*this);  
  38.     }  
  39.     //Get a label  
  40.     __pLabel = static_cast<Label *>(GetControl(L"IDC_LABEL1"));  
  41.     return r;  
  42. }  
  43.   
  44. result  
  45. HelloworldForm::OnTerminating(void)  
  46. {  
  47.     result r = E_SUCCESS;  
  48.   
  49.     // TODO: Add your termination code here  
  50.   
  51.     return r;  
  52. }  
  53.   
  54. void  
  55. HelloworldForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)  
  56. {  
  57.     switch(actionId)  
  58.     {  
  59.     case ID_BUTTON_OK:  
  60.         {  
  61.             AppLog("OK Button is clicked! \n");  
  62.             __pLabel->SetText(L"Hello Bada!");  
  63.             __pLabel->Draw();  
  64.             MessageBox messageBox;  
  65.             messageBox.Construct(L"LINC", L"Hello Bada.",  
  66.                     MSGBOX_STYLE_NONE, 3000);  
  67.   
  68.             // Call ShowAndWait - draw, show itself and process events  
  69.             int modalResult = 0;  
  70.             messageBox.ShowAndWait(modalResult);  
  71.   
  72.             switch(modalResult)  
  73.             {  
  74.             case MSGBOX_RESULT_OK:  
  75.                 // Todo:  
  76.                 break;  
  77.   
  78.             default:  
  79.                 break;  
  80.             }  
  81.         }  
  82.         break;  
  83.     default:  
  84.         break;  
  85.     }  
  86. }  
  87.   
  88.   
  89.   
  90. void  
  91. HelloworldForm::OnTouchDoublePressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)  
  92. {  
  93.     // TODO: Add your implementation codes here  
  94.   
  95. }  
  96.   
  97. void  
  98. HelloworldForm::OnTouchFocusIn(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)  
  99. {  
  100.     // TODO: Add your implementation codes here  
  101.   
  102. }  
  103.   
  104. void  
  105. HelloworldForm::OnTouchFocusOut(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)  
  106. {  
  107.     // TODO: Add your implementation codes here  
  108.   
  109. }  
  110.   
  111. void  
  112. HelloworldForm::OnTouchLongPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)  
  113. {  
  114.     // TODO: Add your implementation codes here  
  115.   
  116. }  
  117.   
  118. void  
  119. HelloworldForm::OnTouchMoved(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)  
  120. {  
  121.     // TODO: Add your implementation codes here  
  122.   
  123. }  
  124.   
  125. void  
  126. HelloworldForm::OnTouchPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)  
  127. {  
  128.     // TODO: Add your implementation codes here  
  129.     AppLog("OK Button is OnTouchPressed! \n");  
  130.     __pLabel->SetText("Hello Bada!");  
  131. }  
  132.   
  133. void  
  134. HelloworldForm::OnTouchReleased(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)  
  135. {  
  136.     // TODO: Add your implementation codes here  
  137.   
  138. }  


下面就是编译调试运行的步骤了,模拟器会自动打开,速度还是很快的,
你点击按钮后,预期的结果就是出现。

很奇怪的是,我第一次运行后,修改一些文件,再编译,运行,提示我模拟器已经加载。
晕了,我只好关闭它然后再开启。
答案正在寻找中...
请高手告知。

评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值