Beispiel #1
0
/**
 * Fill the items in the receipt dialog with values.
 */
void MainScreen::fillReceiptDialog(MAUtil::String appID, MAUtil::String productID,
		int transactionDate, MAUtil::String transactionId,
		MAUtil::String versionExternalId, MAUtil::String BID)
{
	// If the field is unavailable, print a line character instead.
	if ( appID.length() == 0 )
		appID = "-";
	if ( productID.length() == 0 )
		productID = "-";
	if ( transactionDate == 0 )
		mReceiptTransactionDate->setText("-");
	else
	{
		tm transaction;
		split_time(transactionDate, &transaction);
		mReceiptTransactionDate->setText(
				MAUtil::integerToString(transaction.tm_mday) + "." +
				MAUtil::integerToString(transaction.tm_mon +1) + "." +
				MAUtil::integerToString(transaction.tm_year +1900) + " / " +
				MAUtil::integerToString(transaction.tm_hour +1) + ":" +
				MAUtil::integerToString(transaction.tm_min +1) + ":" +
				MAUtil::integerToString(transaction.tm_sec +1) );
	}
	mReceiptProductId->setText(productID);
	mReceiptAppId->setText(appID);
	if ( getPlatform() == IOS )
	{
		mReceiptTransactionId->setText(transactionId);
		mReceiptVersionExternalId->setText(versionExternalId);
		mReceiptBid->setText(BID);
	}

	mReceiptDialog->show();
}
Beispiel #2
0
/**
 * Helper function that unescapes a string.
 */
static MAUtil::String UnescapeHelper(const MAUtil::String& str)
{
	// The decoded string.
	MAUtil::String result = "";

	for (int i = 0; i < str.length(); ++i)
	{
		// If the current character is the '%' escape char...
		if ('%' == (char) str[i])
		{
			// Get the char value of the two digit hex value.
			MAUtil::String hex = str.substr(i + 1, 2);
			long charValue = strtol(
				hex.c_str(),
				NULL,
				16);
			// Append to result.
			result += (char) charValue;

			// Skip over the hex chars.
			i += 2;
		}
		else
		{
			// Not encoded, just copy the character.
			result += str[i];
		}
	}

	return result;
}
Beispiel #3
0
/**
 * Helper function that escapes a string.
 */
static MAUtil::String EscapeHelper(const MAUtil::String& str)
{
	// The encoded string.
	MAUtil::String result = "";
    char buf[8];

    for (int i = 0; i < str.length(); ++i)
    {
    	char c = str[i];
        if ((48 <= c && c <= 57) ||  // 0-9
            (65 <= c && c <= 90) ||  // a..z
            (97 <= c && c <= 122))   // A..Z
        {
        	result.append(&str[i], 1);
        }
        else
        {
        	result += "%";
            sprintf(buf, "%02X", str[i]);
            result += buf;
        }
    }

    return result;
}
Beispiel #4
0
	/**
	 * This method is called when the Submit button is clicked, or edit box
	 * return button was hit.
	 */
	void MainScreen::submitEditBoxContent()
	{
		// Get the text from the password box.
		MAUtil::String password = mPasswordBox->getText();

		// Check if the text doesn't fit the buffer( the default size is 256).
		if ( mPasswordBox->getLastError().errorCode ==
				MAW_RES_INVALID_STRING_BUFFER_SIZE )
		{
			// If the password is too long we use the instructions label
			// to inform the user. Note that C automatically concatenates
			// strings split over multiple lines.
			mInstructions->setText("Password too long. "
				"Please enter a shorter password:"******"Password too short. "
				"Please enter a password of at least 6 characters:");
		}
		else
		{
			// The password is at least 6 characters long,
			// we congratulate user.
			mInstructions->setText("Password OK");
		}
	}
Beispiel #5
0
void XML::CreateRoot(MAUtil::String filename)
{
	MAUtil::String root("<root filename=\"");
	
	root.append(filename.c_str(), filename.length());
	root.append("\">", 2);

	maFileWrite(file, root.c_str(), root.size());
}
void SettingsScreen::saveSettings() {
	//return;
	// Construct the filename.
	this->mScreen->initalizeHelper(mAppCodeBox->getText(), mAppUniqBox->getText(), Cloudbase::MD5(mAppPwdBox->getText()).hexdigest());
	return;

	MAUtil::String filename = getLocalPath() + SETTINGS_FILE_NAME;

	// Open the file handle.
	printf("Open '%s'\n", filename.c_str());
	MAHandle file = maFileOpen(filename.c_str(), MA_ACCESS_READ_WRITE);
	if(file < 0) {
		printf("Error opening file %i\n", file);
		return;
	}

	// If the file exists...
	int res = maFileExists(file);
	MAASSERT(res >= 0);
	if(res) {
		// Truncate it, deleting any old data.
		printf("Truncating file...\n");
		res = maFileTruncate(file, 0);
		MAASSERT(res == 0);
	} else {
		// Otherwise, create it.
		printf("Creating file...\n");
		res = maFileCreate(file);
		MAASSERT(res >= 0);
	}
	// In either case, we now have an empty file at our disposal.

	// Write some data.
	MAUtil::String settingsData = "";
	settingsData += mAppCodeBox->getText();
	settingsData += ",";
	settingsData += mAppUniqBox->getText();
	settingsData += ",";
	settingsData += Cloudbase::MD5(mAppPwdBox->getText()).hexdigest();

	//static const char data[] = strdup(settingsData.c_str());

	res = maFileWrite(file, settingsData.c_str(), settingsData.length());
	MAASSERT(res == 0);

	// Close the file.
	printf("Closing...\n");
	res = maFileClose(file);
	MAASSERT(res == 0);

	printf("Done.\n");
	this->loadSettings();
	//return true;
}
Beispiel #7
0
void UriNdefRecord::setUri(byte prefixCode, MAUtil::String& remainingUri) {
	int length = remainingUri.length();
	setTnf(MA_NFC_NDEF_TNF_WELL_KNOWN);
	byte type[] = { (byte) 0x55 }; // URI
	maNFCSetNDEFType(fHandle, type, 1);
	Vector<byte> payload(length * sizeof(char) + 1);
	payload.add(prefixCode);
	const char* szRemainingUri = remainingUri.c_str();
	for (int i = 0; i < length; i++) {
		payload.insert(1 + sizeof(char) * i, szRemainingUri[i]);
	}
	setPayload(payload);
}
Beispiel #8
0
/**
 * Checks if the given string can be converted to a color.
 * @return True if the string is in the format 0xRRGGBB.
 */
bool CreateNotificationScreen::canStringBeConvertedToColor(const MAUtil::String& string)
{
	if ( string.length() == 8)
	{
		if ( 0 == MAUtil::lowerString(string).find("0x",0) )
		{
			return true;
		}
		else
			return false;
	}
	return false;
}
Beispiel #9
0
	/**
	 * Add data from database into list view.
	 */
	void CountriesListScreen::addDataToListView()
	{
		// Clear data from map.
		mCountryMap.clear();

		// Create first section.
		NativeUI::ListViewSection* section = NULL;
		MAUtil::String sectionTitle("A");

		// For each country read create and add an ListViewItem widget.
		int countCountries = mDatabase.countCountries();
		for (int index = 0; index < countCountries; index++)
		{
			// If index is invalid skip this country.
			Country* country = mDatabase.getCountryByIndex(index);
			if (!country)
			{
				continue;
			}

			// If country's name is an empty string skip this country.
			MAUtil::String countryName = country->getName();
			if (countryName.length() == 0)
			{
				continue;
			}

			// Check if current country can go into current section.
			if (!section || countryName[0] != sectionTitle[0])
			{
				// Create new section.
				sectionTitle[0] = countryName[0];
				section = new NativeUI::ListViewSection(
					NativeUI::LIST_VIEW_SECTION_TYPE_ALPHABETICAL);
				section->setTitle(sectionTitle);
				section->setHeaderText(sectionTitle);
				mListView->addChild(section);
			}

			// Create and add list item for this country.
			NativeUI::ListViewItem* item = new NativeUI::ListViewItem();
			item->setText(countryName);
			item->setFontColor(COLOR_WHITE);
			item->setSelectionStyle(NativeUI::LIST_VIEW_ITEM_SELECTION_STYLE_GRAY);
			item->setIcon(country->getFlagID());
			section->addItem(item);

			mCountryMap.insert(item->getWidgetHandle(), country->getID());
		}
	}
Beispiel #10
0
/**
 * Handle the getLocalPath message.
 */
void MessageHandler::handleFileGetLocalPath(
    WebViewMessage& message)
{
    FileUtil fileUtil;
    MAUtil::String path = fileUtil.getLocalPath();
    if (0 == path.length())
    {
        replyNull(message);
    }
    else
    {
        replyString(message, path);
    }
}
Beispiel #11
0
/**
 * Checks if a given string can be converted to integer.
 * @return True if string contains only characters between [0-9], false
 * otherwise.
 */
bool CreateNotificationScreen::canStringBeConvertedToInteger(
	const MAUtil::String& string)
{
	for (int i = 0;i < string.length(); i++)
	{
		char character = string[i] - '0';
		if (ZERO > character || NINE < character)
		{
			return false;
		}
	}

	return true;
}
Beispiel #12
0
	void string() {
		MAUtil::String str = "test";
		assert("String::==", str == "test");
		assert("String::!=", str != "fest");
		assert("String::<", !(str < "fest") && (MAUtil::String("fest") < str));
		assert("String::>", !(MAUtil::String("fest") > str) && (str > "fest"));
		assert("String::<=", str <= "test" && str <= "west");
		assert("String::>=", str >= "test" && str >= "fest");
		assert("String::+", (str + "ing") == "testing");
		str+="ing";
		assert("String::+=", str == "testing");
		assert("String::find()", str.find("ing") == 4 && str.find("1") == MAUtil::String::npos);
		str+=" string";
		assert("String::findLastOf()", str.findLastOf('g') == 13 && str.findLastOf('1') == MAUtil::String::npos);
		assert("String::findFirstOf()", str.findFirstOf('g') == 6 && str.findFirstOf('1') == MAUtil::String::npos);
		assert("String::findFirstNotOf()", str.findFirstNotOf('t') == 1 && str.findFirstNotOf('1') == 0);
		str.insert(7, " MAUtil::");
		assert("String::insert(string)", str == "testing MAUtil:: string");

		str.remove(16, 2);
		assert("String::remove()", str == "testing MAUtil::tring");

		str.insert(16, 'S');
		assert("String::insert(char)", str == "testing MAUtil::String");

		assert("String::substr()", str.substr(8, 6) == "MAUtil");

		assert("String::length()", str.length() == 22);

		str.reserve(32);
		assert("String::reserve()", str == "testing MAUtil::String" && str.length() == 22);
		assert("String::capacity()", str.capacity() == 32);

		str.clear();
		assert("String::clear()", str.length() == 0 && str == "");
	}
Beispiel #13
0
	/**
	 * Write a text string to a file.
	 * @return true on success, false on error.
	 */
	bool FileUtil::writeTextToFile(
		const MAUtil::String& filePath,
		const MAUtil::String& outText)
	{
		MAHandle file = openFileForWriting(filePath);
		if (file < 0)
		{
			return false;
		}

		int result = maFileWrite(file, outText.c_str(), outText.length());

		maFileClose(file);

		return result == 0;
	}
void SettingsScreen::loadSettings() {
	MAUtil::String filename = getLocalPath() + SETTINGS_FILE_NAME;

	MAHandle file = maFileOpen(filename.c_str(), MA_ACCESS_READ);
	if(file < 0) {
		printf("Error opening file %i\n", file);
		return;
	}

	// Check if the file exists.
	int res = maFileExists(file);
	MAASSERT(res >= 0);
	if(!res) {
		printf("File does not exist.\n");
		maFileClose(file);
		return;
	}

	// Get the file size.
	int size = maFileSize(file);
	printf("Size: %i\n", size);
	MAASSERT(size >= 0);

	// Read the file data.
	static char data[200];
	MAASSERT(size < (int)sizeof(data));
	res = maFileRead(file, data, size);
	MAASSERT(res == 0);

	// Close the file.
	printf("Closing...\n");
	res = maFileClose(file);
	MAASSERT(res == 0);

	printf("Done.\n");

	MAUtil::String contents = data;

	printf("Loaded settings string %s", contents.c_str());

	if (contents.findFirstOf(',', 0) <= 0)
		return;

	int commaPosition = contents.findFirstOf(',', 0);
	MAUtil::String appCode = contents.substr(0, commaPosition);
	mAppCodeBox->setText(appCode);
	printf("app code: %s", appCode.c_str());

	int prevCommaPosition = commaPosition + 1;
	commaPosition = contents.findFirstOf(',', prevCommaPosition);
	MAUtil::String appUniq = contents.substr(prevCommaPosition, commaPosition-prevCommaPosition);
	mAppUniqBox->setText(appUniq);
	printf("app uniq: %s", appUniq.c_str());

	prevCommaPosition = commaPosition + 1;
	commaPosition = contents.findFirstOf(',', prevCommaPosition);
	MAUtil::String appPwd = contents.substr(prevCommaPosition, contents.length() - prevCommaPosition);
	//mAppPwdBox->setText(appPwd);
	printf("app pwd: %s", appPwd.c_str());

	//helper = CBHelper(appCode, appUniq);
	//helper.setPassword(appPwd);
	this->mScreen->initalizeHelper(appCode, appUniq, appPwd);
}
Beispiel #15
0
/**
 * Handle the log message.
 */
void MessageHandler::handleLog(WebViewMessage& message)
{
    MAUtil::String s = message.getParam("message");
    maWriteLog(s.c_str(), s.length());
}
Beispiel #16
0
	/**
	 * \brief This function is used for reading the settings from the settings file
	 */
	void SettingsManager::_readSettings()
	{
		char settingsFileContent[Model::BUFF_SIZE];
		MAUtil::String content;

		int fileSize = maFileSize(_settingsFile);

		maFileRead(_settingsFile, settingsFileContent, fileSize);

		content.append(settingsFileContent, strlen(settingsFileContent));

		int offset = 0;
		int position = content.find("|", offset);
		_coin = content.substr(offset, position); //read the coin

		offset = position + 1;
		position = content.find("|", offset);

		int day = MAUtil::stringToInteger(content.substr(offset, position - offset), 10); //read the reset day

		offset = position + 1;
		position = content.find("|", offset);

		MAUtil::String dateString = content.substr(offset, position - offset); //read the dateString

		offset = position + 1;
		position = content.find("|", offset);

		MAUtil::String binaryMask = content.substr(offset, position - offset); //read the binary mask
		offset = position + 1;
		_debtValue = MAUtil::stringToDouble(content.substr(offset, content.length() - offset));

		if(binaryMask ==  "100")
		{
			_showAll = true;
			_showMonthly = false;
			_showFromDate = false;
		}
		else if(binaryMask == "010")
		{
			_showAll = false;
			_showMonthly = true;
			_showFromDate = false;
		}
		else if(binaryMask == "001")
		{
			_showAll = false;
			_showMonthly = false;
			_showFromDate = true;
		}

		if(_showMonthly)
		{
			_date._day = day;

			struct tm * dateTime = new tm;
			split_time(maTime(), dateTime);

			_date._mounth = dateTime->tm_mon + 1;
			_date._year = dateTime->tm_year + 1900;

			delete dateTime;
		}
		else if(_showFromDate)
		{
			offset = 0;
			position = dateString.find("-", offset);

			_date._year = MAUtil::stringToInteger(dateString.substr(offset, position), 10);

			offset = position + 1;
			position = dateString.find("-", offset);

			_date._mounth = MAUtil::stringToInteger(dateString.substr(offset, position - offset), 10);

			offset = position + 1;
			_date._day = MAUtil::stringToInteger(dateString.substr(offset, dateString.length() - offset), 10);
		}
		else if(_showAll)
		{
			_date._day = 1;
			_date._mounth = 1;
			_date._year = 1601;
		}
	}