result AttachPhotoElement::Construct(const Tizen::Graphics::Rectangle & rect, const Tizen::Base::String &url) { result r = E_SUCCESS; r = AttachElement::Construct(rect); RelativeLayout * layout = dynamic_cast<RelativeLayout *>(GetLayoutN()); _url = String(url); int slash = -111; // r = _url.LastIndexOf(L'/', 0, slash); for (int i=0; i<_url.GetLength(); i++) { wchar_t sym; _url.GetCharAt(i, sym); if (sym == L'/') slash = i; } slash++; String fileName; _url.SubString(slash, fileName); _icon = new LocalImageView(); _icon->Construct(Rectangle(0, 0, 72, 72), "icon_photo.png"); // r = layout->SetCenterAligned(*_icon, CENTER_ALIGN_VERTICAL); Label *label = new Label(); label->Construct(Rectangle(0, 0, rect.width, 40), fileName); label->SetTextConfig(30, LABEL_TEXT_STYLE_NORMAL); _pProgress = new SaneProgressBar(); _pProgress->Construct(Rectangle(0, 0, rect.width-20, 20), 0, 100); _pProgress->SetProgress(0); r = AddControl(label); r = AddControl(_icon); r = AddControl(_pProgress); r = layout->SetCenterAligned(*_icon, CENTER_ALIGN_HORIZONTAL); r = layout->SetRelation(*_icon, this, RECT_EDGE_RELATION_TOP_TO_TOP); r = layout->SetMargin(*_icon, 0, 0, 20, 0); r = layout->SetRelation(*label, _icon, RECT_EDGE_RELATION_TOP_TO_BOTTOM); r = layout->SetCenterAligned(*label, CENTER_ALIGN_HORIZONTAL); r = layout->SetMargin(*label, 10, 10, 10, 0); r = layout->SetRelation(*_pProgress, label, RECT_EDGE_RELATION_TOP_TO_BOTTOM); r = layout->SetMargin(*_pProgress, 10, 10, 20, 0); r = layout->SetCenterAligned(*_pProgress, CENTER_ALIGN_HORIZONTAL); _loading = true; RequestRedraw(true); SetUploaded(false); StartUpload(_url); return r; }
TableViewItem* UsersPanel::CreateItem(int groupIndex, int itemIndex, int itemWidth) { result r = E_SUCCESS; TableViewItem * pItem; RelativeLayout layout; layout.Construct(); pItem = new TableViewItem(); pItem->Construct(layout, Dimension(itemWidth, GetDefaultItemHeight()), TABLE_VIEW_ANNEX_STYLE_NORMAL); JsonObject *userJson; r = _pCurrentModel->GetUserFromGroup(groupIndex, itemIndex, userJson); String name, nextName, photo100; JsonParseUtils::GetString(*userJson, L"first_name", name); name += L" "; JsonParseUtils::GetString(*userJson, L"last_name", nextName); name += nextName; JsonParseUtils::GetString(*userJson, L"photo_100", photo100); Label *pNameLabel = new Label(); pNameLabel->Construct(Rectangle(0, 0, itemWidth, 90), name); pNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT); RoundedAvatar *pAvatar = new RoundedAvatar(AVATAR_NORMAL); pAvatar->Construct(Rectangle(0, 0, 108, 108), photo100); pItem->AddControl(pAvatar); pItem->AddControl(pNameLabel); layout.SetRelation(*pAvatar, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT); layout.SetCenterAligned(*pAvatar, CENTER_ALIGN_VERTICAL); layout.SetMargin(*pAvatar, 30, 0, 0, 0); layout.SetRelation(*pNameLabel, pAvatar, RECT_EDGE_RELATION_LEFT_TO_RIGHT); layout.SetCenterAligned(*pNameLabel, CENTER_ALIGN_VERTICAL); layout.SetMargin(*pNameLabel, 10, 0, 0, 0); return pItem; }
result MessageDocElement::Construct(const Tizen::Graphics::Rectangle & rect, JsonObject * docObject, int out) { result r = E_SUCCESS; _pDocObject = docObject->CloneN(); RelativeLayout layout; layout.Construct(); AppResource* pAppResource = VKUApp::GetInstance()->GetAppResource(); String docName; JsonParseUtils::GetString(*docObject, L"title", docName); int size; JsonParseUtils::GetInteger(*docObject, L"size", size); r = Panel::Construct(layout, rect); r = SetSize(Dimension(rect.width, rect.height)); const String filename = (out == 1) ? L"doc_out.#.png" : L"doc_in.#.png"; _pBitmap = pAppResource->GetBitmapN(filename); // TryCatch(GetLastResult() == E_SUCCESS, r = GetLastResult(), "Failed pAppResource->GetBitmapN"); _pIcon = new LocalImageView(); _pIcon->Construct(Rectangle(0, 0, 72, 72), L"icon_document.png"); r = AddControl(_pIcon); Label *docLabel = new Label(); docLabel->Construct(Rectangle(0, 0, rect.width-72, 35), docName); docLabel->SetMargin(0, 0); docLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT); docLabel->SetTextConfig(30, LABEL_TEXT_STYLE_BOLD); r = AddControl(docLabel); Label *sizeLabel = new Label(); sizeLabel->Construct(Rectangle(0, 0, rect.width-72, 30), GetSizeString(size)); sizeLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT); sizeLabel->SetTextConfig(25, LABEL_TEXT_STYLE_NORMAL); sizeLabel->SetMargin(0, 0); r = AddControl(sizeLabel); layout.SetRelation(*_pIcon, this, RECT_EDGE_RELATION_LEFT_TO_LEFT); layout.SetCenterAligned(*_pIcon, CENTER_ALIGN_VERTICAL); layout.SetMargin(*_pIcon, 0, 0, 0, 0); layout.SetRelation(*docLabel, this, RECT_EDGE_RELATION_TOP_TO_TOP); layout.SetRelation(*docLabel, this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT); layout.SetRelation(*docLabel, _pIcon, RECT_EDGE_RELATION_LEFT_TO_RIGHT); layout.SetMargin(*docLabel, 0, 10, 10, 0); layout.SetHorizontalFitPolicy(*docLabel, FIT_POLICY_CONTENT); layout.SetRelation(*sizeLabel, docLabel, RECT_EDGE_RELATION_TOP_TO_BOTTOM); layout.SetRelation(*sizeLabel, _pIcon, RECT_EDGE_RELATION_LEFT_TO_RIGHT); layout.SetMargin(*sizeLabel, 0, 10, 5, 0); layout.SetHorizontalFitPolicy(*sizeLabel, FIT_POLICY_CONTENT); SetSize(Dimension(rect.width, 90)); SetPropagatedTouchEventListener(this); return r; }
TableViewItem* VKUMessagesListItemProvider::CreateItem(int index, int itemWidth) { result r; AppLog("VKUMessagesListItemProvider::CreateItem"); RoundedAvatar *pAvatar; // NOTE: used only if chat and message is out==0 MessageBubble* pMessageBubble; RelativeLayout itemLayout; Color bgColor; JsonObject *itemObject; IJsonValue *itemValue; TableViewItem* pItem; JsonNumber outNumber; ArrayList *pMessageElements; Label *pTimeStamp; String timespampText; int timestampValue; String messageText(L"no text????"); int out = 0, readState = 0; // reverse list int reversedIndex = _messagesJson->GetCount() - 1 - index; AppLog("Item %d of %d", reversedIndex, GetItemCount()); // get message string r = _messagesJson->GetAt(reversedIndex, itemValue); TryCatch(r == E_SUCCESS, , "Failed GetAt"); itemObject = static_cast<JsonObject *>(itemValue); JsonParseUtils::GetInteger(*itemObject, L"out", out); JsonParseUtils::GetInteger(*itemObject, L"date", timestampValue); JsonParseUtils::GetInteger(*itemObject, L"read_state", readState); TimeUtils::GetDialogsTime(timestampValue, timespampText); // create rich text panel AppLog("Message is %d == out", out); pMessageBubble = new MessageBubble(); r = pMessageBubble->Construct(Dimension(itemWidth, LIST_HEIGHT)); TryCatch(r == E_SUCCESS, , "Failed Construct RichTextPanel"); pMessageBubble->SetOut(out); AppLog("RTPanel created and constructed"); itemLayout.Construct(); // get available elements pMessageElements = GetMessageElementsN(itemObject, itemWidth); // message text element for (int i=0; i<pMessageElements->GetCount(); i++) { AppLog("Adding element %d to pItem", i); MessageElement *pElement = static_cast<MessageElement *>(pMessageElements->GetAt(i)); pMessageBubble->AddElement(pElement); AppLog("Added element %d to pItem with size of %dx%d", i, pElement->GetWidth(), pElement->GetHeight()); } // timestamp label pTimeStamp = new Label(); pTimeStamp->Construct(Rectangle(0, 0, 100, 28), timespampText); pTimeStamp->SetTextConfig(28, LABEL_TEXT_STYLE_NORMAL); pTimeStamp->SetTextColor(Color(TIMESTAMP_TEXT_COLOR, false)); // create table item pItem = new TableViewItem(); r = pItem->Construct(itemLayout, Dimension(itemWidth, pMessageBubble->GetHeight() + 2*BUBBLE_VERTICAL_MARGIN)); TryCatch(r == E_SUCCESS, , "Failed GetAt"); if (out == 0 && _peerId > 2000000000) { int fromId; JsonParseUtils::GetInteger(*itemObject, L"from_id", fromId); AppLog("Finding avatar for %d", fromId); pAvatar = new RoundedAvatar(AVATAR_NORMAL); String * avatarUrl = static_cast<String *>(_pUserIdAvatarMap->GetValue(Integer(fromId))); pAvatar->Construct(Rectangle(0, 0, 80, 80), *avatarUrl); r = pItem->AddControl(pAvatar); itemLayout.SetRelation(*pAvatar, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT); itemLayout.SetRelation(*pAvatar, pItem, RECT_EDGE_RELATION_TOP_TO_TOP); itemLayout.SetMargin(*pAvatar, 10, 0, 10, 0); } // add rich text panel to table item r = pItem->AddControl(pMessageBubble); TryCatch(r == E_SUCCESS, , "Failed AddControl"); r = pItem->AddControl(pTimeStamp); itemLayout.SetCenterAligned(*pMessageBubble, CENTER_ALIGN_VERTICAL); itemLayout.SetHorizontalFitPolicy(*pTimeStamp, FIT_POLICY_CONTENT); if (out == 1) { itemLayout.SetRelation(*pMessageBubble, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT); itemLayout.SetMargin(*pMessageBubble, 0, 10, 0, 0); itemLayout.SetRelation(*pTimeStamp, *pMessageBubble, RECT_EDGE_RELATION_RIGHT_TO_LEFT); itemLayout.SetRelation(*pTimeStamp, *pItem, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM); itemLayout.SetMargin(*pTimeStamp, 0, 10, 0, 30); } else { if (_peerId > 2000000000) { itemLayout.SetRelation(*pMessageBubble, pAvatar, RECT_EDGE_RELATION_LEFT_TO_RIGHT); itemLayout.SetMargin(*pMessageBubble, 10, 0, 0, 0); } else { itemLayout.SetRelation(*pMessageBubble, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT); itemLayout.SetMargin(*pMessageBubble, 10, 0, 0, 0); } itemLayout.SetRelation(*pTimeStamp, *pMessageBubble, RECT_EDGE_RELATION_LEFT_TO_RIGHT); itemLayout.SetRelation(*pTimeStamp, *pItem, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM); itemLayout.SetMargin(*pTimeStamp, 10, 0, 0, 30); } // colors if (out == 1 && readState == 0) { bgColor = Color(LIST_ITEM_UNREAD_COLOR, false); } else { bgColor = Color::GetColor(COLOR_ID_BLACK); } pItem->SetBackgroundColor(bgColor, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL); pItem->SetBackgroundColor(bgColor, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED); pItem->SetBackgroundColor(bgColor, TABLE_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED); pItem->RequestRedraw(true); AppLog("Returning item"); return pItem; CATCH: AppLogException("$${Function:CreateItem} is failed. %s", GetErrorMessage(r)); return null; }