Technè

Tecnologia & Experiência do Usuário no C.E.S.A.R

bada timer

Posted by Eduardo On abril - 5 - 2011

Today we will see how to use Osp::Base::Runtime::Timer

This class can activate the timer and notify the listeners.
This timer class is not a periodic timer, only a one-shot timer. If you want to carry out periodic tasks, you must start it again after it has fired.

It’s easy to use Timers in your app… lets see:

You must extend and construct your Timer

Extend (.h):

public Osp::Base::Runtime::ITimerEventListener

Construct(.cpp):

    __pTimer = new Timer();
    r = __pTimer->Construct(*this);
    r = __pTimer->Start(1000);

Implement OnTimerExpired (to start again your Timer), as shown below:

void
MyApp::OnTimerExpired(Timer& timer)
{

    ...

    timer.Start(1000);
}

Every time your timer ends, OnTimerExpired is called (so you can start your timer again).

Full example:

class MyApp
    : public ITimerEventListener
{
   ...
public:
    result InitTimer();
public:
    void OnTimerExpired(Timer& timer);
};

void
MyApp::OnTimerExpired(Timer& timer)
{

    ...

    timer.Start(1000);
}

result
MyApp::InitTimer()
{
    result r = E_SUCCESS;

    __pTimer = new Timer;

    r = __pTimer->Construct(*this);
    if (IsFailed(r))
    {
        goto CATCH;
    }

    __pTimer->Start(1000);
    if (IsFailed(r))
    {
        goto CATCH;
    }

    return r;
CATCH:
    return r;
}

A real example – implementing a bada Chronometer:
Construct:

    keepRunning = true;
    //get actual time and set as initial time when form is loaded.
    SystemTime::GetTicks(initialTime);
    __pTimer = new Timer();
    r = __pTimer->Construct(*this);
    r = __pTimer->Start(1000);

void
MyApp::Cronometer(){
 completeTime = "00:00:00";
 int diff, hour, minutes, seconds;
    String hourTxt, minutesTxt, secondsTxt;
 if(keepRunning){
  SystemTime::GetTicks(currentTime);
                //get actual time to make diff with initial time
  diff = (currentTime - initialTime);

  hour = Math::Floor((diff/1000)/60/60);
  minutes = Math::Floor((diff/1000)/60);
  seconds = Math::Floor((diff/1000)%60);
  if (seconds <= 9){
   secondsTxt = "0" + LongLong::ToString(seconds%60);
  }else if(seconds == 60){
   secondsTxt = "00";
   minutes++;
  }else{
   secondsTxt = LongLong::ToString(seconds%60);
  }

  if (minutes <= 9){
   minutesTxt = "0" + LongLong::ToString(minutes%60);
  }else if(minutes == 60){
   minutesTxt = "00";
   hour++;
  }else{
   minutesTxt = LongLong::ToString(minutes%60);
  }

  if (hour <= 9){
   hourTxt = "0" + LongLong::ToString(hour);
  }else if(hour == 24){
   hourTxt = "00";
  }else{
   hourTxt = LongLong::ToString(hour%24);
  }

  completeTime = hourTxt + ":"+ minutesTxt + ":"+ secondsTxt;

  Label *lblChrono = static_cast

Thanks for your visit! :)

Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo

bada i18n

Posted by Eduardo On abril - 4 - 2011

Today we’ll learn how to internationalize our bada apps.

i18n = internationalization – means of adapting computer software to different languages, regional differences and technical requirements of a target market. Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. The terms are frequently abbreviated to the numeronyms i18n (where 18 stands for the number of letters between the first i and last n in internationalization, a usage coined at DEC in the 1970s or 80s).

8 steps to internationalize our bada apps:

Figure 1. Resource view: Double click in String table (as shown)

Figure 2. String view will be opened

Figure 3. Right click and choose Language Setting. Here you’ll select the languages that your app will give support.

Figure 4. Add the languages that your app will give support

Figure 5. String table view will be updated with selected languages

Figure 6. Right click and choose “insert” to fill the table with internationalized content. I suggest you to use IDs with some pattern name. Example: IDS_CLASSNAME_VARIABLENAME

Figure 7. String table with a content example

Figure 8. You can just associate the contents, created in String tables, with any control (labels, buttons, …)

If you need to internationalize any text that will not be constructed directly in any Form or Popup, you must insert the ID and content in String table and you can associate the created content to any control through code, as shown below:

...
//get controls
Label *lblContent = static_cast

You can change emulator language and test your bada i18n…

Thanks for your visit! :)
Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo

form manager – how to change screens in bada apps (part 2)

Posted by Eduardo On fevereiro - 4 - 2011

As we’ve learned, FormMgr is another Form in the application responsible for Forms management. The FormMgr just change screens in bada. FormMgr don’t present labels, images, etc…

Steps:
1. create your Forms (Forms that app needs);


In this post I will just send an information from one Form to another (easiest way).
Note that in Forms properties you must set Form name, Labels name, Editfields names, …

2. update application class to start with FormMgr (and not with FormMain)

bool
FormManagerSample::OnAppInitializing(AppRegistry& appRegistry)
{
 result r = E_SUCCESS;
 FormMgr *pFormMgr = new FormMgr();
 if(pFormMgr->Initialize())
 {
  r = Application::GetInstance()->GetAppFrame()
                    ->GetFrame()->AddControl(*pFormMgr);
  TryCatch(r == E_SUCCESS, , GetErrorMessage(r));
  pFormMgr->SetStarterForm(FormMgr::REQUEST_MAINFORM,
                                         null);
 }

 return true;

 CATCH:
  SetLastResult(r);//we'll see this soon, in next posts
  return false;
}

3. create FormMgr.cpp and FormMgr.h
Now, let’s see FormMgr code…
FormMgr.h>>

#ifndef _FORMMGR_H_
#define _FORMMGR_H_

#include
#include
#include
#include
#include
#include 

class FormMgr :
 public Osp::Ui::Controls::Form //derived from Form;
{
public:
 FormMgr(void);
 virtual ~FormMgr(void);

public:
 bool Initialize(void);
 bool SetStarterForm(RequestId requestId,
 Osp::Base::Collection::IList* pArgs);
 static const RequestId REQUEST_MAINFORM = 100; //Form 1
 static const RequestId REQUEST_RESULTFORM = 101; //Form 2

protected:
 void SwitchToForm(RequestId requestId,
 Osp::Base::Collection::IList* pArgs);
 Osp::Ui::Controls::Form *__pPreviousForm;
 FormMain* __pMainForm; //Main Form - will send the data
 FormResult* __pResultForm; //Result Form - will receive the data

public:
 virtual void OnUserEventReceivedN(RequestId requestId,
Osp::Base::Collection::IList* pArgs);
};

#endif

FormMgr.cpp>>

#include "FormMgr.h"
#include "FormMain.h"
#include
#include "FormResult.h"

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

FormMgr::FormMgr(void)
{
 __pPreviousForm = null;
 __pMainForm = null;
 __pResultForm = null;
}

FormMgr::~FormMgr(void)
{
}

bool
FormMgr::Initialize(void)
{
 result r = E_SUCCESS;
 //FormMgr must be constructed...
 r = Form::Construct(FORM_STYLE_NORMAL);
 if (r != E_SUCCESS)
 {
  SetLastResult(r);
 }else{
  //and you must set a name!
  SetName(L"FormMgr");
 }
 return r == E_SUCCESS;
}

bool FormMgr::SetStarterForm(RequestId requestId,
Osp::Base::Collection::IList* pArgs)
{
 Form *pCurrentForm = Application::GetInstance()->GetAppFrame()
                      ->GetFrame()->GetCurrentForm();

 if (pCurrentForm == this)
  SwitchToForm(requestId, pArgs);
 else
  return false;

 return true;
}

void FormMgr::OnUserEventReceivedN(RequestId requestId,
Osp::Base::Collection::IList* pArgs)
{
 SwitchToForm(requestId, pArgs);
}

void FormMgr::SwitchToForm(RequestId requestId,
  Osp::Base::Collection::IList* pArgs)
{
 result r = E_SUCCESS;
 Frame *pFrame = Application::GetInstance()
                 ->GetAppFrame()->GetFrame();
 //BaseForm is adopted to facilitate a large number of Forms...
 BaseForm* pBaseForm = null;

 switch (requestId)
 {
 //MAIN FORM
 case REQUEST_MAINFORM:
 {
  if (null == __pMainForm)
  {
   __pMainForm = new FormMain();
   if(!__pMainForm->Initialize())
   {
       TryCatch(false, , GetErrorMessage(r));
   }
   r = pFrame->AddControl(*__pMainForm);
   TryCatch(r == E_SUCCESS, , GetErrorMessage(r));
  }
  r = pFrame->SetCurrentForm(*__pMainForm);
  TryCatch(r == E_SUCCESS, , GetErrorMessage(r));
  __pMainForm->RequestRedraw(true);
  if (__pPreviousForm != null) {
    if (__pPreviousForm != __pMainForm)
     pFrame->RemoveControl(*__pPreviousForm);
   }
   __pPreviousForm = __pMainForm;
  break;
 }
 //RESULT FORM
 case REQUEST_RESULTFORM:
 {
  FormResult* formResult = new FormResult();
  if (formResult->Initialize()) {
   //Passing parameters from FORMMAIN to FORMRESULT
   formResult->ShowResult(pArgs);
   //BaseForm is now a FormResult
   pBaseForm = formResult;
  }
  break;
 }
 default:
  break;
 }

 if (null != pBaseForm) {
  //It can be used for a large number of Forms
  r = pFrame->AddControl(*pBaseForm);
  TryCatch(r == E_SUCCESS, , GetErrorMessage(r));
  r = pFrame->SetCurrentForm(*pBaseForm);
  TryCatch(r == E_SUCCESS, , GetErrorMessage(r));
  pBaseForm->RequestRedraw(true);
 }

 if (__pPreviousForm != null) {
  if (__pPreviousForm != __pMainForm)
   pFrame->RemoveControl(*__pPreviousForm);
 }
 __pPreviousForm = pBaseForm;

 if (null != pArgs) {
  pArgs->RemoveAll(true);
  delete pArgs;
  pArgs = null;
 }

 return;
 CATCH:
 //Avoid Memory Leak
  SetLastResult(r);
  if(null != __pMainForm)
  {
   delete __pMainForm;
   __pMainForm = null;
  }
  if(null != pBaseForm)
  {
   delete pBaseForm;
   pBaseForm = null;
  }
 return;
}

4. Link FormMgr and new Forms…
Ok, we know how to update application class to call FormMgr, understood FormMgr… Now, lets see how to call FormMgr to switch the Forms and how to receive Args.

From FormMain to FormResult: sending and presenting data texts…
FormMain.cpp>>

void
FormMain::OnActionPerformed(const Osp::Ui::Control& source,
int actionId)
{
 FormMgr *pFormMgr = null;
 Frame *pFrame = null;

 switch(actionId)
 {
        //If Button OK is clicked
 case ID_BUTTON_OK:
  {

//Get editField control
EditField * editField = static_cast(GetControl(L"IDC_EDITFIELD1"));
//Get editField content
String* strData = new String(editField->GetText());
   ArrayList * list = new ArrayList;
   list->Construct(1);
   list->Add(*strData);
//Get Frame Instance
pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
   if(null != pFrame)
   {
//Get FormMgr Control
    pFormMgr = static_cast (pFrame->GetControl("FormMgr"));
   }
   if (null != pFormMgr)
//Send an user event to FormMgr: note that
//you must say the Form to be presented and the Args.
//In this example, FormMgr will consider
//REQUEST_RESULTFORM switch case.
pFormMgr->SendUserEvent(FormMgr::REQUEST_RESULTFORM, list);
  break;
  }
 default:
  break;
 }
}

After sending… this parameters will be considered in void FormMgr::SwitchToForm(RequestId requestId, Osp::Base::Collection::IList* pArgs) function.

To receive the parameters, lets see FormResult example:
FormResult>>

void
FormResult::ShowResult(Osp::Base::Collection::IList * pArgs)
{
 String * strResultFromFormMain = static_cast<String*>
                                  (pArgs->GetAt(0));
 Label * lblResultado = static_cast<Label *>
                                  (GetControl(L"IDC_LABEL1"));
 lblResultado->SetText(*strResultFromFormMain);
}

This example is available HERE!

Thanks for your visit! :)

Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo

form manager – how to change screens in bada apps (part 1)

Posted by Eduardo On fevereiro - 4 - 2011

In general, I don’t like large posts, but I’m intending to facilitate things here :)
Form Manager will be detailed in two posts :)

We’ve seen a lot of bada concepts, bada environment, bada tools, bada docs and we’ve seen a first bada app.

Now, let’s see how to switch forms in bada…

What are Forms?

The Form provides the top level container with an indicator bar, soft key, and title bar. It is attached to a Frame. The Frame provides the main window for an application. There can be only 1 frame, however we can have a lot of forms in bada.

As your applications become more complex, it won’t be enough to have one form only.

Let’s start creating a new Form Manager Sample Code…

As we know, we must create a bada Form Based Project



And after these steps, we’ll see our project in workspace.

If you ckeck the code into the header (FormMain.h) you’ll see the declaration of the form’s class.

class FormMain :
 public Osp::Ui::Controls::Form,
 public Osp::Ui::IActionEventListener
{

Every Form are derived from Osp::Ui::Controls::Form.

The Form is created in FormMain.cpp, on Initialize() function.

bool
FormMain::Initialize()
{
 // Construct an XML form
 Construct(L"IDF_FORMMAIN");

 return true;
}

Note that the construct parameter refers to Form name, that could be updated in Form properties, as shown below.

Once you have your form’s class ready, you will need to show it somehow to the user. For such purposes we have to go to the application’s class. The FormMain.cpp, in this example, is not the main class of the project so it must be explicity initialized. When we create a bada project, the class that has the exact name of the project is the main class of the project (application class). In this example, FormManagerSample is the application class.

In FormManagerSample.cpp, you can find a callback function which is called on application’s start: OnAppInitializing()

bool
FormManagerSample::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
 FormMain *pFormMain = new FormMain();
 pFormMain->Initialize();

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

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

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

 return true;
}

And… if you need a lot of Forms (screens)?
Bada suggests FormMgr (code is available in SDK_FOLDER\workspace\UiControls\src\FormMgr.cpp). You can just add UiControls project to your workspace by accessing “bada SDK Samples” view (as shown here).

What is FormMgr?
Another Form in the application responsible for Forms management. The FormMgr just change screens in bada. FormMgr don’t present labels, images, etc…

Let’s better understand FormMgr in next post!

Thanks for your visit! :)

Next post: Form Manager – How to change screens in bada apps (part 2)

Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo

how to enable usb debugging on your bada phone

Posted by Eduardo On fevereiro - 3 - 2011

Quick steps:

1. Install device driver (example: SDK_FOLDER\Tools\Wave-Driver-V5_02_0_0\Setup.exe for Wave or
SDK_FOLDER\Tools\WaveWQ-Driver-V4_50_7_1 for others);
2. Turn on “Mass storage” on your device (just plug your USB cable and you’ll be asked);
3. Copy rootCACert into a device folder that you could find later (rootCACert location: SDK_FOLDER\Tools\sbuild\rootCACert.cer);
4. Install the certificate on mobile phone;
5. Build your Eclipse project as Target Debug (with device connected via USB);
6. Turn on “USB debugging” on your device (just plug your USB cable and you’ll be asked);
7. Run your project as “bada Target Application”;

That’s it :)

Thanks for your visit! :)

Next post: Form Manager – How to change screens in bada apps

Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo

Original Post: http://mobilecoding.blogspot.com/

creating our first bada app!

Posted by Eduardo On fevereiro - 2 - 2011

Let’s create our first bada app…

1. Open your bada SDK and create a bada project as shown in Fig. 1

Figure 1. Creating your bada project

2.Select “bada Form Based Application” and give a project name, as shown in Fig. 2

Figure 2. Give a name to your bada project

3. Device Configurations is default… you can just click next button, as presented in Fig. 3. For manifest.xml details, click here and select Generate a New Application Profile link.

Figure 3. Device Configurations

4. Select bada SDK and language package, as shown in Fig. 4

Figure 4. bada SDK

5. As you created a bada Form Based App, now you must give a name to your Form, as shown in Fig 5.

Figure 5. Give a name to your Form

6. Select your device screen size, as presented in Fig. 6. You must select the resolution based on the device that you are intended to emulate. Samsung Wave has 480×800 resolution. The form will be created based on this size.

Figure 6. Auto-scaling Settings

7. Fill the basic settings… as shown in Fig. 7

Figure 7. Basic Settings

8. Select the configurations in which you want to deploy, as presented in Fig. 8. I suggest you to select all the options. Let’s better understand each one:
Simulator-Debug: Emulate your app on windows;
Target-Debug: Allows you to debug your app in the device;
Target-Release: Compiles your code to be released in Samsung Apps (AppLog is disabled in this option).

Figure 8. Select Configurations

9. The next screen presents to you a project summary (Fig. 9)

Figure 9. Summary

10. Now, you’re ready to start developing. Your project was created, as shown in Fig. 10

Figure 10. bada project

If you want to run your default app, you must select your build option, as presented ing Fig. 11. To emulate in Windows, choose Simulator-Debug option.

Figure 11. bada build

Now, you can run your app, as shown in Fig. 12

Figure 12. Running your first bada app

In this example, we’ve selected 240×400 resolution, so we’ve got a Samsung Scotia skin while emulating (Fig. 13). Note that the FORM was created in 240×400 folder.
If you need to edit the Form you must always edit the Form in Resource view. Don’t try to edit the xml file (you can get serious problems).

Figure 13. Scotia emulation (240×400 screen size)

You can see some emulation options, such as Event Injector, right clicking over the device skin, as shown in Fig 14.

Figure 14. Emulation options

Now, a very important tip for you.
Interested in bada sample codes?
In the IDE, select the “bada SDK Samples” view (Fig. 15 and Fig. 16). You’ll see a lot of sample codes.
Double-click and the project will be available into your workspace. Enjoy the codes :)


Figure 15. Select other views…


Figure 16. Select bada SDK Samples

Today we’ve configured our first bada project!
Now, we’re ready to start seeing bada codes :)

Thanks for your visit! :)

Next post: How to enable USB debugging on your bada phone

Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo

Original post: http://mobilecoding.blogspot.com

bada: let’s get it started…

Posted by Eduardo On janeiro - 27 - 2011

The main idea here is to do something simple, just to help you to start developing for mobile technologies. I will present you concepts, tools, good practices, code solutions, etc…

Feel free to contact if you need any help :)

Why bada?
- I am working with since september (C.E.S.A.R / Samsung Internship);
- I am involved in the development of Bada apps for Samsung;
- Excellent support (docs, forum, tutorials);
- Wide acceptance in the market;
- bada Ecosystem – Samsung App Store;

What is bada?

Samsung bada is a smartphone platform released in 2010. The word “bada” means “ocean” in Korean. Samsung Wave is the first bada-powered phone.
According to Samsung, for developers, bada will bring a new blue ocean of mobile applications. For customers, they will have a wider choice of smartphones with cost-effective yet powerful bada-powered phones.

Bada still don’t support any service or daemon in background (may be in Bada 2.0).
There is no multi-tasking in Bada. Therefore, one user-developer app will be running at a time but more than one Bada system app can run simultaneously. Bada provide Application Controls (detailed post coming soon) as an alternative for apps that need services.

How Samsung see bada

The vision of bada is “Smartphone for Everyone“. bada’s main goal is not to compete with other existing smartphone platforms. Instead, bada will turn Samsung’s conventional customers into smartphone users by providing cost-effective smartphones. This means that bada will open and extend a new smartphone market, which does not exist in the current mobile market.

bada will create a new smartphone market, which will turn into a new blue ocean

Samsung bada OS presentation

Ecosystem Support

To help customers and developers, bada provides well-made ecosystem support. Samsung bada provides an application store, developer support systems with useful information, and a developer-friendly certification process.

For more information: Samsung App Store.

How do you configure your development environment?

We’ve worked with:
- bada SDK v1.2.1.
The bada SDK installation also contains the bada IDE.
Before installing the SDK, make sure that your computer fulfills the system requirements and that the required software has been installed.
* Microsoft Windows® XP, Windows® Vista or Windows® 7 operating system.
* At least 1.4 GB of RAM memory.
* At least 1.8 GB of free disk space.
* Local administrator rights.
* The bada Simulator screen size is 480 * 800. If the screen resolution of your computer monitor is under 800, the Simulator does not show normally for applications that use OpenGL®.

NOTE: For devices with 240×400 screen size (example: Samsung Wave 525), we’ve worked with SDK v1.1.0.

More details here

References

- Tutorials available in SDK\Documents\Tutorial folder.
- Developer bada Site
- BadaDev

- An Introduction to Bada: A Developer’s Guide

- Introduction to Bada (part 1)
- Introduction to Bada (part 2)
- Introduction to Bada (part 3)

- C++ Reference

Thanks for your visit! :)

Next post: Creating our first bada app!

Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo

Original post: http://mobilecoding.blogspot.com