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. #include<FApp.h>
  4. #include<FBase.h>
  5. #include<FSystem.h>
  6. #include<FUi.h>
  7. /**
  8. *[Helloworld]applicationmustinheritfromApplicationclass
  9. *whichprovidesbasicfeaturesnecessarytodefineanapplication.
  10. */
  11. classHelloworld:
  12. publicOsp::App::Application,
  13. publicOsp::System::IScreenEventListener
  14. {
  15. public:
  16. /**
  17. *[Helloworld]applicationmusthaveafactorymethodthatcreatesaninstanceofitself.
  18. */
  19. staticOsp::App::Application*CreateInstance(void);
  20. public:
  21. Helloworld();
  22. ~Helloworld();
  23. public:
  24. //Calledwhentheapplicationisinitializing.
  25. boolOnAppInitializing(Osp::App::AppRegistry&appRegistry);
  26. //Calledwhentheapplicationisterminating.
  27. boolOnAppTerminating(Osp::App::AppRegistry&appRegistry,boolforcedTermination=false);
  28. //Calledwhentheapplication'sframemovestothetopofthescreen.
  29. voidOnForeground(void);
  30. //Calledwhenthisapplication'sframeismovedfromtopofthescreentothebackground.
  31. voidOnBackground(void);
  32. //Calledwhenthesystemmemoryisnotsufficienttoruntheapplicationanyfurther.
  33. voidOnLowMemory(void);
  34. //Calledwhenthebatterylevelchanges.
  35. voidOnBatteryLevelChanged(Osp::System::BatteryLevelbatteryLevel);
  36. //Calledwhenthescreenturnson.
  37. voidOnScreenOn(void);
  38. //Calledwhenthescreenturnsoff.
  39. voidOnScreenOff(void);
  40. };
  41. #endif
Helloworld.cpp
  1. /**
  2. *Name:Helloworld
  3. *Version:
  4. *Vendor:linc
  5. *Description:
  6. */
  7. #include"Helloworld.h"
  8. #include"HelloworldForm.h"
  9. usingnamespaceOsp::App;
  10. usingnamespaceOsp::Base;
  11. usingnamespaceOsp::System;
  12. usingnamespaceOsp::Ui;
  13. usingnamespaceOsp::Ui::Controls;
  14. Helloworld::Helloworld()
  15. {
  16. }
  17. Helloworld::~Helloworld()
  18. {
  19. }
  20. Application*
  21. Helloworld::CreateInstance(void)
  22. {
  23. //Createtheinstancethroughtheconstructor.
  24. returnnewHelloworld();
  25. }
  26. bool
  27. Helloworld::OnAppInitializing(AppRegistry&appRegistry)
  28. {
  29. //TODO:
  30. //InitializeUIresourcesandapplicationspecificdata.
  31. //Theapplication'spermanentdataandcontextcanbeobtainedfromtheappRegistry.
  32. //
  33. //Ifthismethodissuccessful,returntrue;otherwise,returnfalse.
  34. //Ifthismethodreturnsfalse,theapplicationwillbeterminated.
  35. //Uncommentthefollowingstatementtolistentothescreenon/offevents.
  36. //PowerManager::SetScreenEventListener(*this);
  37. //Createaform
  38. HelloworldForm*pHelloworldForm=newHelloworldForm();
  39. pHelloworldForm->Initialize();
  40. //Addtheformtotheframe
  41. Frame*pFrame=GetAppFrame()->GetFrame();
  42. pFrame->AddControl(*pHelloworldForm);
  43. //Setthecurrentform
  44. pFrame->SetCurrentForm(*pHelloworldForm);
  45. //DrawandShowtheform
  46. pHelloworldForm->Draw();
  47. pHelloworldForm->Show();
  48. returntrue;
  49. }
  50. bool
  51. Helloworld::OnAppTerminating(AppRegistry&appRegistry,boolforcedTermination)
  52. {
  53. //TODO:
  54. //Deallocateresourcesallocatedbythisapplicationfortermination.
  55. //Theapplication'spermanentdataandcontextcanbesavedviaappRegistry.
  56. returntrue;
  57. }
  58. void
  59. Helloworld::OnForeground(void)
  60. {
  61. //TODO:
  62. //Startorresumedrawingwhentheapplicationismovedtotheforeground.
  63. }
  64. void
  65. Helloworld::OnBackground(void)
  66. {
  67. //TODO:
  68. //Stopdrawingwhentheapplicationismovedtothebackground.
  69. }
  70. void
  71. Helloworld::OnLowMemory(void)
  72. {
  73. //TODO:
  74. //Freeunusedresourcesorclosetheapplication.
  75. }
  76. void
  77. Helloworld::OnBatteryLevelChanged(BatteryLevelbatteryLevel)
  78. {
  79. //TODO:
  80. //Handleanychangesinbatterylevelhere.
  81. //Stopusingmultimediafeatures(camera,mp3etc.)ifthebatterylevelisCRITICAL.
  82. }
  83. void
  84. Helloworld::OnScreenOn(void)
  85. {
  86. //TODO:
  87. //GetthereleasedresourcesorresumetheoperationsthatwerepausedorstoppedinOnScreenOff().
  88. }
  89. void
  90. Helloworld::OnScreenOff(void)
  91. {
  92. //TODO:
  93. //Unlessthereisastrongreasontodootherwise,releaseresources(suchas3D,media,andsensors)toallowthedevicetoenterthesleepmodetosavethebattery.
  94. //Invokingalengthyasynchronousmethodwithinthislistenermethodcanberisky,becauseitisnotguaranteedtoinvokeacallbackbeforethedeviceentersthesleepmode.
  95. //Similarly,donotperformlengthyoperationsinthislistenermethod.Anyoperationmustbeaquickone.
  96. }
这里你会初步了解bada程序的生命周期,想必你已经和Android的生命周期作对比了吧?
我提醒一下哦,android的onStop之后就处于不可见对应于bada的OnBackground,剩下的对比就看出来了。
bada也是两阶段构造的,symbian的童鞋,你们熟悉不?
HelloworldEntry.cpp
  1. /**
  2. *Thisfilecontainsthebadaapplicationentrypoint.
  3. */
  4. #include"Helloworld.h"
  5. usingnamespaceOsp::Base;
  6. usingnamespaceOsp::Base::Collection;
  7. #ifdef__cplusplus
  8. extern"C"
  9. {
  10. #endif//__cplusplus
  11. _EXPORT_intOspMain(intargc,char*pArgv[]);
  12. /**
  13. *Theentryfunctionofbadaapplicationcalledbytheoperatingsystem.
  14. */
  15. int
  16. OspMain(intargc,char*pArgv[])
  17. {
  18. resultr=E_SUCCESS;
  19. AppLog("Applicationstarted.");
  20. ArrayList*pArgs=newArrayList();
  21. pArgs->Construct();
  22. for(inti=0;i<argc;i++)
  23. pArgs->Add(*(newString(pArgv[i])));
  24. r=Osp::App::Application::Execute(Helloworld::CreateInstance,pArgs);
  25. if(IsFailed(r))
  26. {
  27. AppLogException("Applicationexecutionfailed-[%s].",GetErrorMessage(r));
  28. r&=0x0000FFFF;
  29. }
  30. pArgs->RemoveAll(true);
  31. deletepArgs;
  32. AppLog("Applicationfinished.");
  33. returnstatic_cast<int>(r);
  34. }
  35. #ifdef__cplusplus
  36. }
  37. #endif//__cplusplus
紧接着就是Form相关的了,这个做windows的又会很熟悉。
HelloworldForm.h
  1. #ifndef_HELLOWORLDFORM_H_
  2. #define_HELLOWORLDFORM_H_
  3. #include<FBase.h>
  4. #include<FUi.h>
  5. classHelloworldForm:
  6. publicOsp::Ui::Controls::Form,
  7. publicOsp::Ui::IActionEventListener,
  8. publicOsp::Ui::ITouchEventListener
  9. {
  10. //Construction
  11. public:
  12. HelloworldForm(void);
  13. virtual~HelloworldForm(void);
  14. boolInitialize(void);
  15. //Implementation
  16. protected:
  17. staticconstintID_BUTTON_OK=101;
  18. Osp::Ui::Controls::Button*__pButtonOk;
  19. Osp::Ui::Controls::Label*__pLabel;
  20. public:
  21. virtualresultOnInitializing(void);
  22. virtualresultOnTerminating(void);
  23. virtualvoidOnActionPerformed(constOsp::Ui::Control&source,intactionId);
  24. virtualvoidOnTouchDoublePressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
  25. virtualvoidOnTouchFocusIn(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
  26. virtualvoidOnTouchFocusOut(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
  27. virtualvoidOnTouchLongPressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
  28. virtualvoidOnTouchMoved(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
  29. virtualvoidOnTouchPressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
  30. virtualvoidOnTouchReleased(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
  31. };
  32. #endif//_HELLOWORLDFORM_H_
HelloworldForm.cpp
  1. #include"HelloworldForm.h"
  2. usingnamespaceOsp::Base;
  3. usingnamespaceOsp::Ui;
  4. usingnamespaceOsp::Ui::Controls;
  5. HelloworldForm::HelloworldForm(void)
  6. {
  7. }
  8. HelloworldForm::~HelloworldForm(void)
  9. {
  10. }
  11. bool
  12. HelloworldForm::Initialize()
  13. {
  14. //ConstructanXMLform
  15. Construct(L"IDF_HELLOWORLDFORM");
  16. returntrue;
  17. }
  18. result
  19. HelloworldForm::OnInitializing(void)
  20. {
  21. resultr=E_SUCCESS;
  22. //TODO:Addyourinitializationcodehere
  23. //GetabuttonviaresourceID
  24. __pButtonOk=static_cast<Button*>(GetControl(L"IDC_BUTTON_OK"));
  25. if(__pButtonOk!=null)
  26. {
  27. __pButtonOk->AddTouchEventListener(*this);
  28. __pButtonOk->SetActionId(ID_BUTTON_OK);
  29. __pButtonOk->AddActionEventListener(*this);
  30. }
  31. //Getalabel
  32. __pLabel=static_cast<Label*>(GetControl(L"IDC_LABEL1"));
  33. returnr;
  34. }
  35. result
  36. HelloworldForm::OnTerminating(void)
  37. {
  38. resultr=E_SUCCESS;
  39. //TODO:Addyourterminationcodehere
  40. returnr;
  41. }
  42. void
  43. HelloworldForm::OnActionPerformed(constOsp::Ui::Control&source,intactionId)
  44. {
  45. switch(actionId)
  46. {
  47. caseID_BUTTON_OK:
  48. {
  49. AppLog("OKButtonisclicked!\n");
  50. __pLabel->SetText(L"HelloBada!");
  51. __pLabel->Draw();
  52. MessageBoxmessageBox;
  53. messageBox.Construct(L"LINC",L"HelloBada.",
  54. MSGBOX_STYLE_NONE,3000);
  55. //CallShowAndWait-draw,showitselfandprocessevents
  56. intmodalResult=0;
  57. messageBox.ShowAndWait(modalResult);
  58. switch(modalResult)
  59. {
  60. caseMSGBOX_RESULT_OK:
  61. //Todo:
  62. break;
  63. default:
  64. break;
  65. }
  66. }
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. void
  73. HelloworldForm::OnTouchDoublePressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
  74. {
  75. //TODO:Addyourimplementationcodeshere
  76. }
  77. void
  78. HelloworldForm::OnTouchFocusIn(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
  79. {
  80. //TODO:Addyourimplementationcodeshere
  81. }
  82. void
  83. HelloworldForm::OnTouchFocusOut(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
  84. {
  85. //TODO:Addyourimplementationcodeshere
  86. }
  87. void
  88. HelloworldForm::OnTouchLongPressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
  89. {
  90. //TODO:Addyourimplementationcodeshere
  91. }
  92. void
  93. HelloworldForm::OnTouchMoved(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
  94. {
  95. //TODO:Addyourimplementationcodeshere
  96. }
  97. void
  98. HelloworldForm::OnTouchPressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
  99. {
  100. //TODO:Addyourimplementationcodeshere
  101. AppLog("OKButtonisOnTouchPressed!\n");
  102. __pLabel->SetText("HelloBada!");
  103. }
  104. void
  105. HelloworldForm::OnTouchReleased(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
  106. {
  107. //TODO:Addyourimplementationcodeshere
  108. }


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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值