Example #1
0
result UserForm::InitScene() {
	result r = E_SUCCESS;

	Panel * pImagePlaceholder = dynamic_cast<Panel *>(GetControl(IDC_PANEL_USER_AVATAR, true));

	String avatarPath;
	r = JsonParseUtils::GetString(*_pUserJson, L"photo_200", avatarPath);

	if (r != E_SUCCESS) {
		r = JsonParseUtils::GetString(*_pUserJson, L"photo_100", avatarPath);
	}

	int hasMobile;
	JsonParseUtils::GetInteger(*_pUserJson, L"has_mobile", hasMobile);

	WebImageView * pAvatar = new WebImageView();
	pAvatar->Construct(Rectangle(0, 0, 300, 300), avatarPath);
	pImagePlaceholder->AddControl(pAvatar);

	Button * pWriteButton = dynamic_cast<Button *>(GetControl(IDC_BUTTON_USER_WRITETO, true));
	pWriteButton->SetActionId(ACTION_ID_WRITE);
	pWriteButton->AddActionEventListener(*this);

	Button * pCallButton = dynamic_cast<Button *>(GetControl(IDC_BUTTON_USER_CALLTO, true));
	pCallButton->SetShowState(hasMobile == 1);

	pCallButton->AddActionEventListener(*this);

	String name, nextName;
	JsonParseUtils::GetString(*_pUserJson, L"first_name", name);
	name += L" ";
	JsonParseUtils::GetString(*_pUserJson, L"last_name", nextName);
	name += nextName;

	GetHeader()->SetTitleText(name);
	GetFooter()->SetItemEnabled(0, false);
	GetFooter()->AddActionEventListener(*this);
	GetFooter()->SetShowState(false);
	GetFooter()->Invalidate(true);

	if (hasMobile == 1) {
		String phone;
		JsonParseUtils::GetString(*_pUserJson, L"mobile_phone", phone);
		if (phone.GetLength() == 0) {
			pCallButton->SetShowState(false);
		} else {
			pCallButton->SetText(L"Call " + phone);
			pCallButton->SetActionId(ACTION_ID_CALL);
		}
	}

	pCallButton->Invalidate(true);

	CheckIsFriends();

	return r;
}
void Button::SetCheck(bool checked, bool sendEvent)
{
	if(IsRadio())
	{
		SetComponentFlags(ComponentFlag_WantFocus,checked);
		if(checked)
		{
			// Make sure all other radio buttons in the group are not checked.
			Button *aRadio = GetEndRadio(false);				
			while(aRadio!=NULL)
			{
				if(aRadio!=this)
				{
					aRadio->SetComponentFlags(ComponentFlag_WantFocus,false);
					if(aRadio->IsChecked())
					{
						aRadio->SetButtonFlags(ButtonFlag_Checked, false);
						aRadio->Invalidate();
					}
				}
				
				aRadio = aRadio->GetNextRadio(true);
			}

			RequestFocus();
		}
	}

	if(sendEvent)
		FireEvent(ComponentEvent_ButtonPressed); // button pressed event
	
	if(IsChecked()==checked)
		return;

	SetButtonFlags(ButtonFlag_Checked, checked);
	Invalidate();
}