segunda-feira, 21 de março de 2011

popup

According to BadaDev, Samsung Apps is not accepting applications which uses MessageBox, for three reasons:

1. Message box closes when user touchs out side it.
2. The button’s captions are in device’s language and not in the application’s language.
3. The Home hard button does not works while the MessageBox has focus.

All three issues relatives to MessageBox itself, but Samsung App Review Team does not care about it.

So, let's see how to work with Popup!

The Popup is an implementation of Window. It can have controls such as Buttons, Labels, and so on. However, the Popup cannot attach some controls such as Frames, MessageBoxes, Forms and another instance of a Popup.

The Popup is displayed in the center of top screen. The Show() method is responsible for displaying the popup and its children.

Example :



Now, lets see how to create a Popup:
Insert a Resource


Select Popup resolution


Create your popup... (UI - controls)


Now, you must create a Popup .cpp and .h file, to get Popup reference, as shown below:

/*
* Popup.h
*
* Created on: 11/04/2011
* Author: eao
*/

#ifndef POPUP_H_
#define POPUP_H_

#include
#include
#include
#include

#define bgPopupPath L"/Res/Images/Popup/image1.png"
#define btnExitPath L"/Res/Images/Popup/image2.png"
#define btnExitPressedPath L"/Res/Images/Popup/image3.png"
#define btnRunAgainPath L"/Res/Images/Popup/image4.png"
#define btnRunAgainPressedPath L"/Res/Images/Popup/image5.png"

class Popup:
public Osp::Ui::IActionEventListener,
public Osp::Ui::Controls::Popup
{
public:
Popup();
virtual ~Popup();
bool Initialize(void);

protected:
static const int ID_BUTTON1 = 120;
static const int ID_BUTTON2 = 121;
int intArgs;
Osp::Graphics::Bitmap * __pBitmapBg;
Osp::Graphics::Bitmap * __pBitmapMainLabel;
Osp::Graphics::Bitmap * __pBitmapExit;
Osp::Graphics::Bitmap * __pBitmapExitPressed;
Osp::Graphics::Bitmap * __pBitmapRun;
Osp::Graphics::Bitmap * __pBitmapRunPressed;
Osp::Ui::Controls::Button * __pButtonExit;
Osp::Ui::Controls::Button * __pButtonRunAgain;
Osp::Ui::Controls::Label * __pLabelMainTitle;

//implementation
public:
virtual void OnActionPerformed(const Osp::Ui::Control& source,
int actionId);
};

#endif /* POPUP */



/*
* Popup.cpp
*
* Created on: 11/04/2011
* Author: eao
*/

#include "FormMgr.h"
#include "Popup.h"
#include "Utilities.h"

using namespace Osp::Base;
using namespace Osp::App;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;
using namespace Osp::Base::Collection;
using namespace Osp::Media;
using namespace Osp::Graphics;

Popup::Popup() {
__pBitmapBg = null;
__pBitmapMainLabel = null;
__pBitmapExit = null;
__pBitmapExitPressed = null;
__pBitmapRun = null;
__pBitmapRunPressed = null;
__pLabelMainTitle = null;

}

Popup::~Popup() {
delete __pBitmapBg;
__pBitmapBg = null;

delete __pBitmapMainLabel;
__pBitmapMainLabel = null;

delete __pBitmapExit;
__pBitmapExit = null;

delete __pBitmapExitPressed;
__pBitmapExitPressed = null;

delete __pBitmapRun;
__pBitmapRun = null;

delete __pBitmapRunPressed;
__pBitmapRunPressed = null;

}


bool
Popup::Initialize()
{
result r = E_SUCCESS;
// Construct an XML form
//THIS POPUP NAME MUST BE SET IN POPUP PROPERTIES (UI Builder)
r = Construct(L"IDP_POPUP1");
if (r != E_SUCCESS)
{
SetLastResult(r);
}

//loading bitmaps
Image img;
r = img.Construct();
TryReturn(r==E_SUCCESS ,r, GetErrorMessage(r));

__pBitmapBg = img.DecodeN(bgPopupPath,BITMAP_PIXEL_FORMAT_ARGB8888);
TryReturn(GetLastResult()==E_SUCCESS,GetLastResult(),
GetErrorMessage(GetLastResult()));

__pBitmapExit = img.DecodeN(btnExitPath, BITMAP_PIXEL_FORMAT_ARGB8888);
TryReturn(GetLastResult()==E_SUCCESS,GetLastResult(),
GetErrorMessage(GetLastResult()));
__pBitmapExitPressed = img.DecodeN(btnExitPressedPath,
BITMAP_PIXEL_FORMAT_ARGB8888);
TryReturn(GetLastResult()==E_SUCCESS,GetLastResult(),
GetErrorMessage(GetLastResult()));
__pBitmapRun = img.DecodeN(btnRunAgainPath,
BITMAP_PIXEL_FORMAT_ARGB8888);
TryReturn(GetLastResult()==E_SUCCESS,GetLastResult(),
GetErrorMessage(GetLastResult()));
__pBitmapRunPressed = img.DecodeN(btnRunAgainPressedPath,
BITMAP_PIXEL_FORMAT_ARGB8888);
TryReturn(GetLastResult()==E_SUCCESS,GetLastResult(),
GetErrorMessage(GetLastResult()));

//set a popup background
__pLabelMainTitle = static_cast<Label *>(GetControl(L"IDC_LABEL1"));
if(null!=__pLabelMainTitle){
__pBitmapMainLabel = new Bitmap();
__pBitmapMainLabel->Construct(*__pBitmapBg,
__pLabelMainTitle->GetBounds());
__pLabelMainTitle->SetBackgroundBitmap(*__pBitmapMainLabel);
}

__pButtonExit = static_cast<Button *>(GetControl(L"IDC_BUTTON2"));
if (__pButtonExit != null)
{
//set an image for button2
__pButtonExit->SetNormalBackgroundBitmap(*__pBitmapExit);
//set an image for pressed button 2
__pButtonExit->SetPressedBackgroundBitmap(*__pBitmapExitPressed);
__pButtonExit->SetActionId(ID_BUTTON2);
__pButtonExit->AddActionEventListener(*this);

} else {
r = E_FAILURE;
}

__pButtonRunAgain = static_cast<Button *>(GetControl(L"IDC_BUTTON1"));
if (__pButtonRunAgain != null)
{
//set an image for button 1
__pButtonRunAgain->SetNormalBackgroundBitmap(*__pBitmapRun);
//set an image for pressed button 1
__pButtonRunAgain->SetPressedBackgroundBitmap(*__pBitmapRunPressed);
__pButtonRunAgain ->SetActionId(ID_BUTTON1);
__pButtonRunAgain ->AddActionEventListener(*this);
} else {
r = E_FAILURE;
}

return r == E_SUCCESS;
}

//popup control (buttons)
void
Popup::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
FormMgr *pFormMgr = null;
Frame *pFrame = null;
ArrayList * runOption = new ArrayList;
runOption->Construct(1);
String freeTimeName = __REGISTRY_SECTION_FREETIME_NAME;
String obstacleTimeName = __REGISTRY_SECTION_OBSTACLETIME_NAME;
switch(actionId)
{
case ID_BUTTON1:
{
pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
if (null != pFrame) {
pFormMgr = static_cast<FormMgr *> (pFrame->GetControl("FormMgr"));
}
if (null != pFormMgr) {
runOption->Add(*(new Integer(intArgs)));
pFormMgr->SendUserEvent(FormMgr::REQUEST_SECONDFORM, runOption);
}
break;
}
case ID_BUTTON2:
{
pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
if(null != pFrame)
{
FormRace *pFormRace = dynamic_cast<FormRace *> (pFrame->
GetCurrentForm());
if(null != pFormRace){
pFormRace->ContinueChronoTime(true,false, false);
}
}
//hide popup
this->SetShowState(false);
this->RequestRedraw(true);
break;
}

default:
break;
}
}



Note that this popup example has two buttons and one label, as presented in .cpp and .h code.


To see your popup... you must create an instance and call setshowstate and show functions, as shown below:

YourClass.cpp

result r = E_SUCCESS;
__pPopup = new Popup();
if(!__pPopup->Initialize()){
r = E_FAILURE;
}

r = __pPopup->SetShowState(true);
TryCatch(r == E_SUCCESS, , GetErrorMessage(r));
r = __pPopup->Show();
TryCatch(r == E_SUCCESS, , GetErrorMessage(r));


Thanks for your visit! :)

Next post: label with background?
Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo

domingo, 20 de março de 2011

timer

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);
}



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);
}else if(seconds == 60){
secondsTxt = "00";
minutes++;
}else{
secondsTxt = LongLong::ToString(seconds%60);
}

if (minutes <= 9){
minutesTxt = "0" + LongLong::ToString(minutes);
}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! :)

Next post: Popup

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

sábado, 12 de março de 2011

bada 2.0



Samsung Bada 2.0 OS new features will include following updates:
HTML5, multitasking, FlashLite 4, Text-To-Speech, Push Notification, Near-Field Communication, Open AL and many more.

More information here.

Thanks for your visit! :)

Next post: Timer

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

sexta-feira, 11 de março de 2011

registry

Osp::Io::Registry Class Reference

This class provides a mechanism to access the registry file. Registry consists of several sections and each section can have several entries, but only to a single depth. An entry consists of a name-value pair. The entry name must be unique inside the same section. The entry value must be one of the following data types: int, double, float, String, UuId, ByteBuffer.


Registry is an easy way to persist data.

To persist your data, you must create a section and add a value, as shown below:

//Osp::Io::Registry::Registry(void)
Osp::Io::Registry* pReg = new Osp::Io::Registry();
String regPath(L"regTest.ini");
result r = pReg->Construct(regPath, true);
TryCatch(r == E_SUCCESS, , "Failed to get a valid Registry. %s",
GetErrorMessage(r));

//create a section (data types: int, double, float, String,
//UuId, ByteBuffer)
r = pReg->AddSection(section);
TryCatch(r == E_SUCCESS, , "Failed to add the record section. %s",
GetErrorMessage(r));

//add a value to created section
//result AddValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName,
//const Osp::Base::String &value)
//example: entryRecord = key, record = value
r = pReg->AddValue(section, entryRecord, record);
TryCatch(r == E_SUCCESS, , "Failed to add the record entry. %s",
GetErrorMessage(r));

//Writes the current contents of a registry in memory to
//the non-volatile storage.
r = pReg->Flush();
TryCatch(r == E_SUCCESS, , "Failed to save registry changes. %s",
GetErrorMessage(r));
}

return;

CATCH:
SetLastResult(r);
if(pReg != null){
delete pReg;
pReg = null;
}


If you need to recover registered data:

//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName,
//Osp::Base::ByteBuffer &retVal) const

//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName,
//Osp::Base::UuId &retVal) const

//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName,
//Osp::Base::String &retVal) const

//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName, float &retVal) const

//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName, double &retVal) const

//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName, int &retVal) const
r = pReg->GetValue(section, key, value);
TryCatch(r == E_SUCCESS, , "Failed to get the record from
the registry. %s", GetErrorMessage(r));

If you need to check if a section already exists:

bool
RegistryUtils::ContainsSection(Osp::Io::Registry& reg,
Osp::Base::String& section)
{
bool containsKey = false;
Osp::Base::Collection::IList* pList = reg.GetAllSectionNamesN();
Osp::Base::String* pSection = null;
for(int index = 0; index < pList->GetCount(); index++)
{
pSection = (Osp::Base::String*)pList->GetAt(index);
if(section.Equals(*(pSection), false))
{
containsKey = true;
break;
}
}


If you need more info (API, code examples, ...), try Osp::Io::Registry Class Reference.

You can see registry file in: \Model\WaveWQ_LP1\Simulator\FS\Win32FS\Osp\Applications\ or Wave_LP1 in case of 400x800 device resolution.

Thanks for your visit! :)

Next post: bada 2.0

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

bada i18n

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! :)

Next post: Registry

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