[Bada] Creating “Hello World” for Bada

I recently had a look at writing applications for Bada. Bada is a smart phone platform from Samsung. As I was starting out, I was trying to write a “Hello World” application to start off. The documentation provided a starting point for creating a “Hello World” project (bada Developer Guide -> Application Development Process -> Creating Your First Application). The next section, Designing and Creating the Application GUI, was on constructing the user interface using the visual GUI builder. Instead of using that GUI builder, I constructed it programmatcially.

For the application, I created a project called “HelloWorld” (no spaces), which resulted in the HelloWorld.cpp and HelloWordEntry.cpp to be created in project’s src folder. The folder structure looked something like this:

File structure of the projected, automatically created by the Bada IDE.

The files generated cpp files is prefilled with some code. According to the documentation, the OnAppInitializing method is typically responsible for creating the UI and restoring the application state. To create display the “Hello World” screen, I changed this method to create and display the UI components. The code listing for this method is as follows:

bool
HelloWorld::OnAppInitializing(AppRegistry& appRegistry)
{
	Form *pForm = new Form();
    pForm->Construct(FORM_STYLE_NORMAL|
    		FORM_STYLE_TITLE|
			FORM_STYLE_INDICATOR|
			FORM_STYLE_SOFTKEY_0|
			FORM_STYLE_OPTIONKEY);
    pForm->SetName(L"Hello World");
    pForm->SetTitleText(L"Hello World");

    Frame *appFrame = GetAppFrame()->GetFrame();
    Label *pLabel = new Label();
    pLabel->Construct(Rectangle(5, 20,
    		appFrame->GetBounds().width - 10, 40),
    		L"Hello World Label");
    pLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
    pLabel->SetName(L"Hello World Label");
    pForm->AddControl(*pLabel);

    appFrame->AddControl(*pForm);
    return true;
}

A Form is a fullscreen view that hold other UI components. A “Hello World” Label is created and placed on the Form. The Form is then placed on the application’s Frame. The documentation on Form states that a Form can be placed on only one Frame, but a Frame can have multiple Forms. Furthermore, an application can have only one Frame. The application’s Frame is obtain by the call to GetAppFrame and GetFrame at line 13.

Notice that the each of the UI components are created using heap memory (i.e. with pointers and calling new). It is possible to create them on the stack (i.e. using local variables and not using new). However, the documentation titled UI: Creating the Application UI Using bada UI Controls states that they must be created using heap memory. As for releasing the memory allocated to the components, it also stated that the application framework will free the heap memory for the UI components that are attached to the Frame.

The example source files can be downloaded from here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: