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
#ifndef _HELLOWORLD_H_
#define _HELLOWORLD_H_

#include <FApp.h>
#include <FBase.h>
#include <FSystem.h>
#include <FUi.h>

/**
 * [Helloworld] application must inherit from Application class
 * which provides basic features necessary to define an application.
 */
class Helloworld :
	public Osp::App::Application,
	public Osp::System::IScreenEventListener
{
public:

	/**
	 * [Helloworld] application must have a factory method that creates an instance of itself.
	 */
	static Osp::App::Application* CreateInstance(void);


public:
	Helloworld();
	~Helloworld();


public:


	// Called when the application is initializing.
	bool OnAppInitializing(Osp::App::AppRegistry& appRegistry);

	// Called when the application is terminating.
	bool OnAppTerminating(Osp::App::AppRegistry& appRegistry, bool forcedTermination = false);


	// Called when the application's frame moves to the top of the screen.
	void OnForeground(void);


	// Called when this application's frame is moved from top of the screen to the background.
	void OnBackground(void);

	// Called when the system memory is not sufficient to run the application any further.
	void OnLowMemory(void);

	// Called when the battery level changes.
	void OnBatteryLevelChanged(Osp::System::BatteryLevel batteryLevel);

	// Called when the screen turns on.
	void OnScreenOn (void);

	// Called when the screen turns off.
	void OnScreenOff (void);
};

#endif
Helloworld.cpp
/**
 * Name        : Helloworld
 * Version     : 
 * Vendor      : linc
 * Description : 
 */


#include "Helloworld.h"
#include "HelloworldForm.h"

using namespace Osp::App;
using namespace Osp::Base;
using namespace Osp::System;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;

Helloworld::Helloworld()
{
}

Helloworld::~Helloworld()
{
}

Application*
Helloworld::CreateInstance(void)
{
	// Create the instance through the constructor.
	return new Helloworld();
}

bool
Helloworld::OnAppInitializing(AppRegistry& appRegistry)
{
	// TODO:
	// Initialize UI resources and application specific data.
	// The application's permanent data and context can be obtained from the appRegistry.
	//
	// If this method is successful, return true; otherwise, return false.
	// If this method returns false, the application will be terminated.

	// Uncomment the following statement to listen to the screen on/off events.
	//PowerManager::SetScreenEventListener(*this);

	// Create a form
	HelloworldForm *pHelloworldForm = new HelloworldForm();
	pHelloworldForm->Initialize();

	// Add the form to the frame
	Frame *pFrame = GetAppFrame()->GetFrame();
	pFrame->AddControl(*pHelloworldForm);

	// Set the current form
	pFrame->SetCurrentForm(*pHelloworldForm);

	// Draw and Show the form
	pHelloworldForm->Draw();
	pHelloworldForm->Show();

	return true;
}

bool
Helloworld::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
{
	// TODO:
	// Deallocate resources allocated by this application for termination.
	// The application's permanent data and context can be saved via appRegistry.
	return true;
}

void
Helloworld::OnForeground(void)
{
	// TODO:
	// Start or resume drawing when the application is moved to the foreground.
}

void
Helloworld::OnBackground(void)
{
	// TODO:
	// Stop drawing when the application is moved to the background.
}

void
Helloworld::OnLowMemory(void)
{
	// TODO:
	// Free unused resources or close the application.
}

void
Helloworld::OnBatteryLevelChanged(BatteryLevel batteryLevel)
{
	// TODO:
	// Handle any changes in battery level here.
	// Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.
}

void
Helloworld::OnScreenOn (void)
{
	// TODO:
	// Get the released resources or resume the operations that were paused or stopped in OnScreenOff().
}

void
Helloworld::OnScreenOff (void)
{
	// TODO:
	//  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.
	// 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.
	// Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
}
这里你会初步了解bada程序的生命周期,想必你已经和Android的生命周期作对比了吧?
我提醒一下哦,android的onStop之后就处于不可见对应于bada的OnBackground,剩下的对比就看出来了。
bada也是两阶段构造的,symbian的童鞋,你们熟悉不?
HelloworldEntry.cpp
/**
 * This file contains the bada application entry point.
 */
#include "Helloworld.h"

using namespace Osp::Base;
using namespace Osp::Base::Collection;

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

_EXPORT_ int OspMain(int argc, char *pArgv[]);

/**
 * The entry function of bada application called by the operating system.
 */
int
OspMain(int argc, char *pArgv[])
{
	result r = E_SUCCESS;

	AppLog("Application started.");
	ArrayList* pArgs = new ArrayList();
	pArgs->Construct();
	for (int i = 0; i < argc; i++)
		pArgs->Add(*(new String(pArgv[i])));

	r = Osp::App::Application::Execute(Helloworld::CreateInstance, pArgs);
	if (IsFailed(r))
	{
		AppLogException("Application execution failed-[%s].", GetErrorMessage(r));
		r &= 0x0000FFFF;
	}

	pArgs->RemoveAll(true);
	delete pArgs;
	AppLog("Application finished.");

	return static_cast<int>(r);
}
#ifdef __cplusplus
}
#endif // __cplusplus
紧接着就是Form相关的了,这个做windows的又会很熟悉。
HelloworldForm.h
#ifndef _HELLOWORLDFORM_H_
#define _HELLOWORLDFORM_H_

#include <FBase.h>
#include <FUi.h>

class HelloworldForm :
	public Osp::Ui::Controls::Form,
	public Osp::Ui::IActionEventListener,
 	public Osp::Ui::ITouchEventListener
{

// Construction
public:
	HelloworldForm(void);
	virtual ~HelloworldForm(void);
	bool Initialize(void);

// Implementation
protected:
	static const int ID_BUTTON_OK = 101;
	Osp::Ui::Controls::Button *__pButtonOk;
	Osp::Ui::Controls::Label *__pLabel;
public:
	virtual result OnInitializing(void);
	virtual result OnTerminating(void);
	virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId);

	virtual void OnTouchDoublePressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchFocusIn(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchFocusOut(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchLongPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchMoved(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchReleased(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo);
};

#endif	//_HELLOWORLDFORM_H_
HelloworldForm.cpp
#include "HelloworldForm.h"

using namespace Osp::Base;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;

HelloworldForm::HelloworldForm(void)
{
}

HelloworldForm::~HelloworldForm(void)
{
}

bool
HelloworldForm::Initialize()
{
	// Construct an XML form
	Construct(L"IDF_HELLOWORLDFORM");

	return true;
}

result
HelloworldForm::OnInitializing(void)
{
	result r = E_SUCCESS;

	// TODO: Add your initialization code here

	// Get a button via resource ID
	__pButtonOk = static_cast<Button *>(GetControl(L"IDC_BUTTON_OK"));
	if (__pButtonOk != null)
	{
		__pButtonOk->AddTouchEventListener(*this);
		__pButtonOk->SetActionId(ID_BUTTON_OK);
		__pButtonOk->AddActionEventListener(*this);
	}
	//Get a label
	__pLabel = static_cast<Label *>(GetControl(L"IDC_LABEL1"));
	return r;
}

result
HelloworldForm::OnTerminating(void)
{
	result r = E_SUCCESS;

	// TODO: Add your termination code here

	return r;
}

void
HelloworldForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
	switch(actionId)
	{
	case ID_BUTTON_OK:
		{
			AppLog("OK Button is clicked! \n");
			__pLabel->SetText(L"Hello Bada!");
			__pLabel->Draw();
			MessageBox messageBox;
			messageBox.Construct(L"LINC", L"Hello Bada.",
					MSGBOX_STYLE_NONE, 3000);

			// Call ShowAndWait - draw, show itself and process events
			int modalResult = 0;
			messageBox.ShowAndWait(modalResult);

			switch(modalResult)
			{
			case MSGBOX_RESULT_OK:
				// Todo:
				break;

			default:
				break;
			}
		}
		break;
	default:
		break;
	}
}



void
HelloworldForm::OnTouchDoublePressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)
{
	// TODO: Add your implementation codes here

}

void
HelloworldForm::OnTouchFocusIn(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)
{
	// TODO: Add your implementation codes here

}

void
HelloworldForm::OnTouchFocusOut(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)
{
	// TODO: Add your implementation codes here

}

void
HelloworldForm::OnTouchLongPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)
{
	// TODO: Add your implementation codes here

}

void
HelloworldForm::OnTouchMoved(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)
{
	// TODO: Add your implementation codes here

}

void
HelloworldForm::OnTouchPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)
{
	// TODO: Add your implementation codes here
	AppLog("OK Button is OnTouchPressed! \n");
	__pLabel->SetText("Hello Bada!");
}

void
HelloworldForm::OnTouchReleased(const Osp::Ui::Control &source, const Osp::Graphics::Point ¤tPosition, const Osp::Ui::TouchEventInfo &touchInfo)
{
	// TODO: Add your implementation codes here

}


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

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






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值