为什么要学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,一切都是那么熟悉。
下面,是看帮助文档。好东西全在这里面呢。
- #ifndef_HELLOWORLD_H_
- #define_HELLOWORLD_H_
- #include<FApp.h>
- #include<FBase.h>
- #include<FSystem.h>
- #include<FUi.h>
- /**
- *[Helloworld]applicationmustinheritfromApplicationclass
- *whichprovidesbasicfeaturesnecessarytodefineanapplication.
- */
- classHelloworld:
- publicOsp::App::Application,
- publicOsp::System::IScreenEventListener
- {
- public:
- /**
- *[Helloworld]applicationmusthaveafactorymethodthatcreatesaninstanceofitself.
- */
- staticOsp::App::Application*CreateInstance(void);
- public:
- Helloworld();
- ~Helloworld();
- public:
- //Calledwhentheapplicationisinitializing.
- boolOnAppInitializing(Osp::App::AppRegistry&appRegistry);
- //Calledwhentheapplicationisterminating.
- boolOnAppTerminating(Osp::App::AppRegistry&appRegistry,boolforcedTermination=false);
- //Calledwhentheapplication'sframemovestothetopofthescreen.
- voidOnForeground(void);
- //Calledwhenthisapplication'sframeismovedfromtopofthescreentothebackground.
- voidOnBackground(void);
- //Calledwhenthesystemmemoryisnotsufficienttoruntheapplicationanyfurther.
- voidOnLowMemory(void);
- //Calledwhenthebatterylevelchanges.
- voidOnBatteryLevelChanged(Osp::System::BatteryLevelbatteryLevel);
- //Calledwhenthescreenturnson.
- voidOnScreenOn(void);
- //Calledwhenthescreenturnsoff.
- voidOnScreenOff(void);
- };
- #endif
- /**
- *Name:Helloworld
- *Version:
- *Vendor:linc
- *Description:
- */
- #include"Helloworld.h"
- #include"HelloworldForm.h"
- usingnamespaceOsp::App;
- usingnamespaceOsp::Base;
- usingnamespaceOsp::System;
- usingnamespaceOsp::Ui;
- usingnamespaceOsp::Ui::Controls;
- Helloworld::Helloworld()
- {
- }
- Helloworld::~Helloworld()
- {
- }
- Application*
- Helloworld::CreateInstance(void)
- {
- //Createtheinstancethroughtheconstructor.
- returnnewHelloworld();
- }
- bool
- Helloworld::OnAppInitializing(AppRegistry&appRegistry)
- {
- //TODO:
- //InitializeUIresourcesandapplicationspecificdata.
- //Theapplication'spermanentdataandcontextcanbeobtainedfromtheappRegistry.
- //
- //Ifthismethodissuccessful,returntrue;otherwise,returnfalse.
- //Ifthismethodreturnsfalse,theapplicationwillbeterminated.
- //Uncommentthefollowingstatementtolistentothescreenon/offevents.
- //PowerManager::SetScreenEventListener(*this);
- //Createaform
- HelloworldForm*pHelloworldForm=newHelloworldForm();
- pHelloworldForm->Initialize();
- //Addtheformtotheframe
- Frame*pFrame=GetAppFrame()->GetFrame();
- pFrame->AddControl(*pHelloworldForm);
- //Setthecurrentform
- pFrame->SetCurrentForm(*pHelloworldForm);
- //DrawandShowtheform
- pHelloworldForm->Draw();
- pHelloworldForm->Show();
- returntrue;
- }
- bool
- Helloworld::OnAppTerminating(AppRegistry&appRegistry,boolforcedTermination)
- {
- //TODO:
- //Deallocateresourcesallocatedbythisapplicationfortermination.
- //Theapplication'spermanentdataandcontextcanbesavedviaappRegistry.
- returntrue;
- }
- void
- Helloworld::OnForeground(void)
- {
- //TODO:
- //Startorresumedrawingwhentheapplicationismovedtotheforeground.
- }
- void
- Helloworld::OnBackground(void)
- {
- //TODO:
- //Stopdrawingwhentheapplicationismovedtothebackground.
- }
- void
- Helloworld::OnLowMemory(void)
- {
- //TODO:
- //Freeunusedresourcesorclosetheapplication.
- }
- void
- Helloworld::OnBatteryLevelChanged(BatteryLevelbatteryLevel)
- {
- //TODO:
- //Handleanychangesinbatterylevelhere.
- //Stopusingmultimediafeatures(camera,mp3etc.)ifthebatterylevelisCRITICAL.
- }
- void
- Helloworld::OnScreenOn(void)
- {
- //TODO:
- //GetthereleasedresourcesorresumetheoperationsthatwerepausedorstoppedinOnScreenOff().
- }
- void
- Helloworld::OnScreenOff(void)
- {
- //TODO:
- //Unlessthereisastrongreasontodootherwise,releaseresources(suchas3D,media,andsensors)toallowthedevicetoenterthesleepmodetosavethebattery.
- //Invokingalengthyasynchronousmethodwithinthislistenermethodcanberisky,becauseitisnotguaranteedtoinvokeacallbackbeforethedeviceentersthesleepmode.
- //Similarly,donotperformlengthyoperationsinthislistenermethod.Anyoperationmustbeaquickone.
- }
- /**
- *Thisfilecontainsthebadaapplicationentrypoint.
- */
- #include"Helloworld.h"
- usingnamespaceOsp::Base;
- usingnamespaceOsp::Base::Collection;
- #ifdef__cplusplus
- extern"C"
- {
- #endif//__cplusplus
- _EXPORT_intOspMain(intargc,char*pArgv[]);
- /**
- *Theentryfunctionofbadaapplicationcalledbytheoperatingsystem.
- */
- int
- OspMain(intargc,char*pArgv[])
- {
- resultr=E_SUCCESS;
- AppLog("Applicationstarted.");
- ArrayList*pArgs=newArrayList();
- pArgs->Construct();
- for(inti=0;i<argc;i++)
- pArgs->Add(*(newString(pArgv[i])));
- r=Osp::App::Application::Execute(Helloworld::CreateInstance,pArgs);
- if(IsFailed(r))
- {
- AppLogException("Applicationexecutionfailed-[%s].",GetErrorMessage(r));
- r&=0x0000FFFF;
- }
- pArgs->RemoveAll(true);
- deletepArgs;
- AppLog("Applicationfinished.");
- returnstatic_cast<int>(r);
- }
- #ifdef__cplusplus
- }
- #endif//__cplusplus
- #ifndef_HELLOWORLDFORM_H_
- #define_HELLOWORLDFORM_H_
- #include<FBase.h>
- #include<FUi.h>
- classHelloworldForm:
- publicOsp::Ui::Controls::Form,
- publicOsp::Ui::IActionEventListener,
- publicOsp::Ui::ITouchEventListener
- {
- //Construction
- public:
- HelloworldForm(void);
- virtual~HelloworldForm(void);
- boolInitialize(void);
- //Implementation
- protected:
- staticconstintID_BUTTON_OK=101;
- Osp::Ui::Controls::Button*__pButtonOk;
- Osp::Ui::Controls::Label*__pLabel;
- public:
- virtualresultOnInitializing(void);
- virtualresultOnTerminating(void);
- virtualvoidOnActionPerformed(constOsp::Ui::Control&source,intactionId);
- virtualvoidOnTouchDoublePressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
- virtualvoidOnTouchFocusIn(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
- virtualvoidOnTouchFocusOut(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
- virtualvoidOnTouchLongPressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
- virtualvoidOnTouchMoved(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
- virtualvoidOnTouchPressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
- virtualvoidOnTouchReleased(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo);
- };
- #endif//_HELLOWORLDFORM_H_
- #include"HelloworldForm.h"
- usingnamespaceOsp::Base;
- usingnamespaceOsp::Ui;
- usingnamespaceOsp::Ui::Controls;
- HelloworldForm::HelloworldForm(void)
- {
- }
- HelloworldForm::~HelloworldForm(void)
- {
- }
- bool
- HelloworldForm::Initialize()
- {
- //ConstructanXMLform
- Construct(L"IDF_HELLOWORLDFORM");
- returntrue;
- }
- result
- HelloworldForm::OnInitializing(void)
- {
- resultr=E_SUCCESS;
- //TODO:Addyourinitializationcodehere
- //GetabuttonviaresourceID
- __pButtonOk=static_cast<Button*>(GetControl(L"IDC_BUTTON_OK"));
- if(__pButtonOk!=null)
- {
- __pButtonOk->AddTouchEventListener(*this);
- __pButtonOk->SetActionId(ID_BUTTON_OK);
- __pButtonOk->AddActionEventListener(*this);
- }
- //Getalabel
- __pLabel=static_cast<Label*>(GetControl(L"IDC_LABEL1"));
- returnr;
- }
- result
- HelloworldForm::OnTerminating(void)
- {
- resultr=E_SUCCESS;
- //TODO:Addyourterminationcodehere
- returnr;
- }
- void
- HelloworldForm::OnActionPerformed(constOsp::Ui::Control&source,intactionId)
- {
- switch(actionId)
- {
- caseID_BUTTON_OK:
- {
- AppLog("OKButtonisclicked!\n");
- __pLabel->SetText(L"HelloBada!");
- __pLabel->Draw();
- MessageBoxmessageBox;
- messageBox.Construct(L"LINC",L"HelloBada.",
- MSGBOX_STYLE_NONE,3000);
- //CallShowAndWait-draw,showitselfandprocessevents
- intmodalResult=0;
- messageBox.ShowAndWait(modalResult);
- switch(modalResult)
- {
- caseMSGBOX_RESULT_OK:
- //Todo:
- break;
- default:
- break;
- }
- }
- break;
- default:
- break;
- }
- }
- void
- HelloworldForm::OnTouchDoublePressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
- {
- //TODO:Addyourimplementationcodeshere
- }
- void
- HelloworldForm::OnTouchFocusIn(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
- {
- //TODO:Addyourimplementationcodeshere
- }
- void
- HelloworldForm::OnTouchFocusOut(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
- {
- //TODO:Addyourimplementationcodeshere
- }
- void
- HelloworldForm::OnTouchLongPressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
- {
- //TODO:Addyourimplementationcodeshere
- }
- void
- HelloworldForm::OnTouchMoved(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
- {
- //TODO:Addyourimplementationcodeshere
- }
- void
- HelloworldForm::OnTouchPressed(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
- {
- //TODO:Addyourimplementationcodeshere
- AppLog("OKButtonisOnTouchPressed!\n");
- __pLabel->SetText("HelloBada!");
- }
- void
- HelloworldForm::OnTouchReleased(constOsp::Ui::Control&source,constOsp::Graphics::Point¤tPosition,constOsp::Ui::TouchEventInfo&touchInfo)
- {
- //TODO:Addyourimplementationcodeshere
- }