Step-by-step description of creating a simple application for Samsung Bada
Preliminary notes
Hello. First of all, I would like to congratulate everyone on the New Year and immediately get down to business. This article will focus on the creation of simple programs for Bada, the operating system for mobile devices released by Korean Samsung. I want to say in advance that under the cut is a simple recipe for making a simple application without lengthy discussions about the optimality and harmony of the code.
There are already quite comprehensive articles on Habré that are devoted to Bada, for example this and this , but there is no step-by-step description of creating an application for beginners. Who cares - I ask for a cat.
The topic for writing arose by chance - a friend is actively engaged in establishing the boundaries of land using GPS in a geodetic company; the specifics of the work (where it came from is a good question) is that the obtained geodetic coordinates (let me clarify what is meant by latitude and longitude) must be converted to rectangular ones right after they are received. There are no laptops at the company that can withstand an 8-hour working day, and it’s not planned, but a friend recently bought a smartphone from Samsung actively promoted in Ukraine with Samsung operating system Bada, the next question was - if you can download games for your phone, is there an application that can solve a purely described engineering problem? Such an application, of course, was not found, and I received a kind offer to write this for a known fee.
Tools
To develop applications for Bada, Bada SDK 1.2.0 is used, which can be downloaded by registering on the Bada developers site . There is nothing complicated in this process, but at the stage of selecting files for downloading, I honestly “dumbed” it by downloading only the SDK, and there is no so-called language pack, hoping that, as it is written on the site, downloading it will happen after installing the SDK automatically. However, at the installation stage, something went wrong, the installation continued without loading the language pack, which subsequently led to the inability to either build (build), or, moreover, run the application.
After downloading the SDK and the language pack, they should be put in one place, and when installing the SDK or when modifying it, the installer will pick up the language pack and install it yourself.
Actually creating the application
The development environment is based on Eclipse, the C ++ programming language used. To begin with, let's move on to creating a new application with the obvious File -> New -> bada Application Project command. In the window that appears, you should define the name of the project in the Project name field, select the application type in the Project Type list - bada Form Based Application.
Next, the environment will ask you to determine the technical parameters of the device for which the application will be intended (screen resolution, GPS availability, etc.). These parameters are defined in the special manifest file Manifest.xml, which can be selected among the SDK files, created and downloaded from the Bada Developers website, or created your own. Without further ado, I used the manifest file from the folders with Samples examples that are installed along with the SDK, since my application did not require any bells and whistles, and only screen resolution was important.
Next, the environment will ask you to specify the root directory of the SDK, this should not be a problem. After selecting, the name of the device model and its API will appear in the list, which will be used in the future for programming.
The next step is to determine the default form name, which will appear immediately after the application starts. By this name * .h and * .cpp files will be generated.
Next, you need to determine whether or not to support auto-scaling and the best screen resolution, if this feature is added. I understand that this is best done, because the application will be able to work on different devices with different resolutions and will not have to be redone.
The next link in the long chain of settings is the definition of Application ID, to certify the functions of the application if it needs to read and write to protected folders. I did not need this, so I omitted this step.
Near the end is the definition of the obvious properties of the Name, Vendor, and Description application.
And now it's almost almost the end - this is the definition of the necessary configurations for development: I recommend leaving everything as default, and now the most important configuration is Simulator-Debug - this is the ability to debug code on the device simulator, Target-Release - the configuration for compiling the application before downloading it to real device.
The last step is the information summarized for all the settings in the Summary window, which you can read again and make sure that everything is selected correctly.
After the final settings, the future application appears in Project Explorer, clicking on which will open the resource files in the Resources window and the following window will appear:
After clicking on the form (and generally on any control) on the Properties tab, you can change the obvious properties of the application, such as the text in the title, background color, the presence and name of the soft keys.
I immediately transferred the ready-made button, which the environment kindly generated, lower and wrote Calculate on it. With the GUI Editor, it’s easy to get the following interface that is well suited for my task (I believe that the process of transferring controls to the form and setting their properties does not cause any difficulties); the obvious Label was used as a label for the input fields, the EditField was used as the input fields; Label was also used to show the result of the calculations, since their editing is not provided:
Now the actual coding.
The running application goes through several stages (Help is very detailed, you can find the details there), now we are primarily interested in the initialization stage of the application, for which the OnInitializing (void) method of the form class is responsible, which can be found in the <YOUR_FORM> .cpp file in the src folder project.
By default, this method looks like this:
result
Form1::OnInitializing(void)
{
result r = E_SUCCESS;
// TODO: Add your initialization code here
// Get a button via resource ID
__pButtonOk = static_cast
Here we created a button with the identifier __pButtonOk, which was generated by the environment. In the inc folder is the header file of the form, in which you should add a new field to the protected section that will correspond to the second Clear button, as well as the event ID (Id Action) of the button in the form of an integer constant, which will be used to determine which form button was pushed in the OnActionPerformed method. I also added special constants needed for calculations here.
I did it like this:
protected:
static const int ID_BUTTON_OK = 101;
// new action ID for button CLEAR
static const int ID_BUTTON_CLEAR=102;
// geodetic constants
static const int a=6378137;
static const float alfa=1/298.257223563;
Osp::Ui::Controls::Button *__pButtonOk;
// new field: button
Osp::Ui::Controls::Button *__pButtonClear;
// new fields: edits and labels
Osp::Ui::Controls::EditField *__pB_deg;
Osp::Ui::Controls::EditField *__pB_min;
Osp::Ui::Controls::EditField *__pB_sec;
Osp::Ui::Controls::EditField *__pL_deg;
Osp::Ui::Controls::EditField *__pL_min;
Osp::Ui::Controls::EditField *__pL_sec;
Osp::Ui::Controls::EditField *__pH;
Osp::Ui::Controls::Label *__pX;
Osp::Ui::Controls::Label *__pY;
Now, in the OnInitializing (void) method, you can create a Clear button and assign it an Id Action and an “Event Listener” listener. We will do the same with EditField and Label, without adding to them, however, Id Action and Event Listener since their reaction to user actions is not provided in our simple application (IDC_BUTTON1, IDC_EDITFIELD1, etc. - the value of the Name property for the button).
__pButtonOk = static_cast
At this stage, you can already launch the application and see how data is entered into the simulator, but of course there is no benefit until the button click events are processed.
To solve this problem, the OnActionPerformed form class method is used (const Osp :: Ui :: Control & source, int actionId). As you can see, the second parameter is the Action Id already mentioned above. When the application is executed, the button click events are “listened” and the Action Id assigned to it is passed to OnActionPerformed (const Osp :: Ui :: Control & source, int actionId). If processing is provided here for such an identifier, it is executed.
OnActionPerformed has a switch preset for analyzing the actionId parameter, it is convenient to use it. Next, I allow myself to provide the code for this method with detailed comments:
void
Form1::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
const int MAX_BUFF_SIZE = 512;
switch(actionId)
{
case ID_BUTTON_OK:
// реакция на нажатие кнопки Calculate
{
// получаем строковое представление градусов, минут и секунд широты и ...
String B_deg_str(__pB_deg->GetText());
String B_min_str(__pB_min->GetText());
String B_sec_str(__pB_sec->GetText());
//...долготы
String L_deg_str(__pL_deg->GetText());
String L_min_str(__pL_min->GetText());
String L_sec_str(__pL_sec->GetText());
// ... высоты
String H_str(__pH->GetText());
double B_deg,B_min,B_sec;
double L_deg,L_min,L_sec;
double H;
// преобразование строковых представлений чисел в вещественную форму для вычислений
result r1=Double::Parse(B_deg_str,B_deg);
result r2=Double::Parse(B_min_str,B_min);
result r3=Double::Parse(B_sec_str,B_sec);
result r4=Double::Parse(L_deg_str,L_deg);
result r5=Double::Parse(L_min_str,L_min);
result r6=Double::Parse(L_sec_str,L_sec);
result r7=Double::Parse(H_str,H);
// вычисления
double b_in_decimal=B_deg+B_min/60+B_sec/3600;
double l_in_decimal=L_deg+L_min/60+L_sec/3600;
double eSqr=2*alfa-(alfa*alfa);
double N=a/Math::Sqrt(1-eSqr*(Math::Sin(b_in_decimal))*(Math::Sin(b_in_decimal)));
double X=(N+H)*Math::Cos(b_in_decimal)*Math::Cos(l_in_decimal);
double Y=(N+H)*Math::Cos(b_in_decimal)*Math::Sin(l_in_decimal);
String strX;
String strY;
// преобразование числовых значений координат в строковое представление
strX.Format(MAX_BUFF_SIZE,L"%f",X);
strY.Format(MAX_BUFF_SIZE,L"%f",Y);
// вывод полученых чисел в Label
__pX->SetText(L"X="+strX);__pY->SetText(L"Y="+strY);
__pX->Draw();__pY->Draw();
__pX->Show();__pY->Show();
}
break;
case ID_BUTTON_CLEAR:
{
// реакция на нажатие кнопки Clear
// создаем диалоговое окно с кнопками OK и CANCEL и вопросом - очистить все поля?
MessageBox *pMessageBox = new MessageBox();
pMessageBox->Construct(L"MessageBox", L"Clear all fields?" , MSGBOX_STYLE_OKCANCEL ,9000);
int ModalResult;
pMessageBox->ShowAndWait(ModalResult);
// если ответ положительный,то ...
if (ModalResult==MSGBOX_RESULT_OK) {
// ... очищаем поля ввода и надписи Label
__pB_deg->Clear();
__pB_min->Clear();
__pB_sec->Clear();
__pL_deg->Clear();
__pL_min->Clear();
__pL_sec->Clear();
__pH->Clear();
__pX->SetText(L"X=");__pY->SetText(L"Y=");
}
// удаляем MessageBox
delete pMessageBox;
}
break;
default:
break;
}
}
The appearance of the simulator with the program running is as follows:
It is with MessageBox:
That seems to be all. I want to note that the application does not at all pretend to the breadth of coverage and the correctness of all formulations, for example, there is completely no “protection against the fool”, because I hope for the sanity of my friend and four of his colleagues for whom this program is intended.
More recently, another application for development for Bada has been received - it is necessary to search and display on the map the nearest objects, such as ATMs or deposit terminals. If this topic is interesting to anyone, I will gladly share my experience.
If anyone has a question about what to do next with the program, then this is covered in detail in the articles on the Bada Developer website, I won’t touch on this, since programming is still a more complicated topic.
Application sources are available here .
If I did something wrong with the hosting, please excuse me :)
UPD: Sorry, forgot to add - all added fields of the form class (__pB_deg, _pB_min, etc.) should be initialized in the form constructor as follows:
Form1::Form1(void):
__pB_deg(null),__pB_min(null),__pB_sec(null),
__pL_deg(null),__pL_min(null),__pL_sec(null),
__pH(null),
__pX(null),__pY(null)
{
}