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

Nenhum comentário:

Postar um comentário