bool TrimMemory() {
		if(_state == CACHE_ENTRY_STATE_MEMORY && _subscribers.GetCount() == 0) {
			AppLog("trim memory, delete bitmap");
			_state = CACHE_ENTRY_STATE_FILE;
			delete _bitmap;
			return true;
		} else {
			AppLog("trim memory, not needed or not possible");
			return false;
		}
	}
	virtual void OnLoadingError() {
		if(_state == CACHE_ENTRY_STATE_LOADING) {
			AppLog("bitmap loading error");
			_state = CACHE_ENTRY_STATE_NOT_FOUND;
			File::Remove(_file);
			if(_subscribers.GetCount() != 0) {
				StartDownloading();
			}
		} else {
			AppLog("WARNING: illegal state: loading error not on LOADING state");
		}
	}
	virtual void OnLoadingSuccess(Bitmap *bitmap) {
		if(_state == CACHE_ENTRY_STATE_LOADING) {
			AppLog("bitmap loaded");
			_bitmap = bitmap;
			_state = CACHE_ENTRY_STATE_MEMORY;
			if(_subscribers.GetCount() != 0) {
				SendEventsToAll();
			}
		} else {
			AppLog("WARNING: illegal state: loaded event not on LOADING state");
		}
	}
	virtual void OnDownloadSuccess() {
		if(_state == CACHE_ENTRY_STATE_DOWNLOADING && File::IsFileExist(_file)) {
			AppLog("file downloaded");
			_state = CACHE_ENTRY_STATE_FILE;
			if(_subscribers.GetCount() != 0) {
				_state = CACHE_ENTRY_STATE_LOADING;
				StartLoading();
			}
		} else {
			AppLog("WARNING: illegal state: downloaded event not on DOWNLOADING state, or file don't exists");
		}
	}
	void RemoveSubscriber(Control *control) {
		result r;
		r = _subscribers.Remove(*control);
		if(r != E_SUCCESS) {
			AppLog("BITMAPCACHE WARNING: %ls unsubscribe unsubscribed!!!!!!!!!!!!!!", _url.GetPointer());
		}

		if(_state == CACHE_ENTRY_STATE_MEMORY && _subscribers.GetCount() == 0) {
			AppLog("BITMAPCACHE: free memory %ls", _url.GetPointer());
			delete _bitmap;
			_state = CACHE_ENTRY_STATE_FILE;
		}
	}
Example #6
0
char*
TextSelection::GetXaml ()
{
	const char *header = "<Section xml:space=\"preserve\" HasTrailingParagraphBreakOnPaste=\"False\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">";
	const char *trailer = "</Section>";

	GString *str;
	ArrayList ancestors;
	DependencyObject *el;

	if (xaml)
		goto done;

	if (!anchor.GetParent() || !moving.GetParent()) {
		xaml = g_strdup ("");
		goto done;
	}

	if (anchor.GetParent() == moving.GetParent() && anchor.GetLocation () == moving.GetLocation()) {
		xaml = g_strdup ("");
		goto done;
	}

	str = g_string_new (header);

	// first we serialize the xaml start elements for all
	// TextElements that contain the selection start (but not the
	// most deeply nested element itself)

	el = anchor.GetParent();
	if (el && !el->Is (Type::RICHTEXTBOX)) {
		// skip anchor.GetParent() here.
		el = el->GetParent() ? el->GetParent()->GetParent() : NULL;
		while (el) {
			if (el->Is (Type::RICHTEXTBOX))
				break;
			ancestors.Add (el);
			el = el->GetParent() ? el->GetParent()->GetParent() : NULL;
			if (!el)
				break;
		}
	}

	for (int i = ancestors.GetCount() - 1; i >= 0; i --) {
		TextElement *te = (TextElement*)ancestors[i];
		IDocumentNode *node = IDocumentNode::CastToIDocumentNode (te);
		node->SerializeXamlStartElement (str);
	}




	// now we output the start element (and deal with the case where start_element == end_element)
	el = anchor.GetParent ();
	if (el->Is (Type::RUN)) {
		if (el == moving.GetParent()) {
			// if both textpointers are in the same
			// element, we need to use start+length form
			((Run*)el)->SerializeXaml (str, anchor.ResolveLocation (), moving.ResolveLocation () - anchor.ResolveLocation());
		}
		else {
			// since the moving textpointer is outside
			// this run, we just use the start form.
			((Run*)el)->SerializeXaml (str, anchor.ResolveLocation ());
		}
	}
	else {
		((TextElement*)el)->SerializeXaml (str);
	}

	if (anchor.GetParent() != moving.GetParent()) {
		// now walk the document from start element to end element, outputting everything manually along the way.
		DocumentWalker walker (anchor.GetParentNode(), DocumentWalker::Forward);
		IDocumentNode *node;
		DocumentWalker::StepType stepType;

		stepType = walker.Step (); // step out of the start element

		while (stepType != DocumentWalker::Done) {
			stepType = walker.Step (&node);

			if (node == moving.GetParentNode())
				break;
			if (stepType == DocumentWalker::Enter)
				node->SerializeXamlStartElement(str);
			else
				node->SerializeXamlEndElement(str);
		}

		// now we output the end element
		el = moving.GetParent ();
		if (el->Is (Type::RUN)) {
			((Run*)el)->SerializeXaml (str, 0, moving.ResolveLocation ());
		}
		else {
			((TextElement*)el)->SerializeXaml (str);
		}
	}

	// now serialize the xaml end elements for all TextElements
	// that contain the selection end (but not the most deeply
	// nested element itself)

	if (anchor.GetParent() == moving.GetParent ()) {
		// this case is trivial, we just output the same list
		// of end elements that we outputted the start
		// elements before
		for (int i = ancestors.GetCount() - 1; i >= 0; i --) {
			TextElement *te = (TextElement*)ancestors[i];
			IDocumentNode *node = IDocumentNode::CastToIDocumentNode (te);
			node->SerializeXamlEndElement (str);
		}
	}
	else {
		ancestors.SetCount (0);

		DependencyObject *el = moving.GetParent();
		if (el && !el->Is (Type::RICHTEXTBOX)) {
			// skip moving.GetParent() here.
			el = el->GetParent() ? el->GetParent()->GetParent() : NULL;
			while (el) {
				if (el->Is (Type::RICHTEXTBOX))
					break;
				ancestors.Add (el);
				el = el->GetParent() ? el->GetParent()->GetParent() : NULL;
				if (!el)
					break;
			}
		}

		for (int i = ancestors.GetCount() - 1; i >= 0; i --) {
			TextElement *te = (TextElement*)ancestors[i];
			IDocumentNode *node = IDocumentNode::CastToIDocumentNode (te);
			node->SerializeXamlEndElement (str);
		}
	}

	g_string_append (str, trailer);

	xaml = g_string_free (str, FALSE);

 done:
	return g_strdup (xaml);
}
void
ProjectGiraffeTab4::connectionDidFinish(HttpConnection *connection, HashMap *response)
{
	/*
	if (response) {
		String userKey("user");
		String messageKey("message");
		String errorKey("error");
		if (response->ContainsKey(userKey)) {
			HashMap *userDict = (HashMap *)response->GetValue(userKey);
			User::currentUser()->updateFromDictionary(userDict);

//			showProfile();

			String *message = (String *)response->GetValue(messageKey);
			showStatus("User Update Status", *message, false);
		} else if (response->ContainsKey(errorKey)) {
			String *errorMessage = (String *)response->GetValue(errorKey);

			// Flash error message
			showStatus("User Update Status", *errorMessage, true);

			Draw();
		}

		delete connection;
//		delete response;
	}
	*/
	AppLog("HttpConnection finished");
	if (response) {
		// TODO: check for the return value
		ArrayList *graffitiList = static_cast<ArrayList *>(response->GetValue(kHTTPParamNameGraffiti));
		if (graffitiList) {
			AppLog("Retrieved list");
			ArrayList *newItems = new ArrayList(SingleObjectDeleter);
			newItems->Construct();

			for (int i = 0; i < graffitiList->GetCount(); i++) {
				HashMap *graffitiDictionary = static_cast<HashMap *>(graffitiList->GetAt(i));
				AppLog("updating dictionary");
				if (graffitiDictionary) {
					Graffiti *newGraffiti = new Graffiti();
					newGraffiti->updateFromDictionary(graffitiDictionary);
					newGraffiti->setUser(User::currentUser());
					AppLog("Updated from dictionary");
					newItems->Add(newGraffiti);
				}
			}
			if(graffitiList->GetCount() == 0){
				AppLog("No graffiti to display");
				displayNoGraffiti();
			}
			AppLog("Setting new items");
			setItems(newItems);
		}else{
			AppLog("Failed to retrieve graffiti list");
			displayNoGraffiti();
		}
	} else {

		connectionDidFail(connection);
	}
}
Example #8
0
void
MainForm::OnParsingCompleted(ArrayList &feedData) {
	AppResource *pAppResource = Application::GetInstance()->GetAppResource();
	if (feedData.GetCount() == 0) {
		// no service this day
		String emptyText;
		pAppResource->GetString("IDS_NOSERVICE", emptyText);
		__pListFood->SetTextOfEmptyList(emptyText);
	} else {
		IEnumerator *pEnum = feedData.GetEnumeratorN();
		HashMap *pItem = null;
		int mensaIndex = -1;
		String *currentMensa = null;
		String currencySymbol;
		pAppResource->GetString("IDS_CURRENCY", currencySymbol);
		String soldOut;
		pAppResource->GetString("IDS_SOLDOUT", soldOut);

		// iterate over items (meals) in feed
		while (pEnum->MoveNext() == E_SUCCESS) {
			pItem = (HashMap *)pEnum->GetCurrent();

			// check if mensa is already in the list (we assume the feed to be ordered)
			if (!currentMensa || !(static_cast<String *>(pItem->GetValue(*(new String("author")))))->Equals(*currentMensa, false)) {
				currentMensa = static_cast<String *>(pItem->GetValue(*(new String("author"))));
				mensaIndex++;
				// Create a main item of the ExpandableList
				CustomListItem* pMainItem = new CustomListItem();
				pMainItem->Construct(100);
				pMainItem->SetItemFormat(*__pMainItemFormat);
				pMainItem->SetElement(TEXT_ID, *(new String(*currentMensa)));
				// Add the item to the ExpandableList
				__pListFood->AddItem(*pMainItem, mensaIndex);
			}

			String *title = static_cast<String *>(pItem->GetValue(*(new String("title"))));
			title->Trim();
			String priceStudents;
			String priceStaff;
			int stringLength = title->GetLength();

			// Create a sub item of the ExpandableList
			CustomListItem *pSubItem = new CustomListItem();
			pSubItem->Construct(100);
			pSubItem->SetItemFormat(*__pSubItemFormat);

			// get prices
			if (title->EndsWith(L" EUR)")) {
				// parse price
				title->SubString(stringLength - 20, 5, priceStudents);
				priceStudents.Append(currencySymbol);
				title->SubString(stringLength - 9, 5, priceStaff);
				priceStaff.Append(currencySymbol);
				title->Remove(stringLength - 22, 22);

				pSubItem->SetElement(PRICESTUDENT_ID, priceStudents);
				pSubItem->SetElement(PRICESTAFF_ID, priceStaff);
			} else if (title->EndsWith(L"(ausverkauft)")) {
				// sold out
				title->Remove(stringLength - 14, 14);
				pSubItem->SetElement(REMARK_ID, soldOut);
			}

			pSubItem->SetElement(TEXT_ID, *title);

			// Add sub item to the ExpandableList
			__pListFood->AddSubItem(mensaIndex, *pSubItem);
		}

		// clean up
		delete pEnum;
	}

	__pListFood->RequestRedraw();
	__pListFood->ScrollToTop();

	StopLoadingAnimation();
}
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;
}
	void SendEventsToAll() {
		for(int i = 0; i < _subscribers.GetCount(); i++) {
			SendEvent(static_cast<Control *>(_subscribers.GetAt(i)));
		}
	}