コード例 #1
0
ファイル: GeoLocation.cpp プロジェクト: Ginox/MoSync
	/**
	 * Here we handle events from the web view. We turn on or off
	 * location tracking depending of the message sent from JavaScript.
	 */
	void handleWidgetEvent(MAWidgetEventData* widgetEvent)
	{
		// Handle messages from the WebView widget.
		if (MAW_EVENT_WEB_VIEW_HOOK_INVOKED == widgetEvent->eventType)
		{
			// Get message content, this is the url set in JavaScript.
			MAUtil::String message = Util::createTextFromHandle(
				widgetEvent->urlData);

			// Note: It is very important to free the data handle
			// when we are done with using it, since a new data object
			// is allocated for each message. (In the high-level library
			// this is done automatically.)
			maDestroyPlaceholder(widgetEvent->urlData);

			// Check the message string and execute the corresponding syscall.
			if (0 == message.find("StartTrackingGeoLocation"))
			{
				maLocationStart();
			}
			else
			if (0 == message.find("StopTrackingGeoLocation"))
			{
				maLocationStop();
			}
		}
	}
コード例 #2
0
ファイル: WikiEngine.cpp プロジェクト: comforx/MoSync
/**
 * Parse the received XML, and search for title& snippet attributes.
 */
void MediaWiki::processSearchResults()
{
	/* for ex, try this request for "bear" in your browser:
	 *   http://en.wikipedia.org/w/api.php?action=query&format=xml&
	 *   list=search&srwhat=text&srsearch=bear
	 * the output looks like this:
	 * ...
	 * <search>
	 * <p ns="0" title="title1" snippet="text.." size="10283"
	 * wordcount="1324" timestamp="2011-04-12T14:25:24Z" />
	 * more paragraphs
	 * </search>
	 * ...
	 */

	// Search for each p paragraph, and get the title & snippet.
	MAUtil::String input = mBuffer;
	int openTag = input.find("<p ",0);

	while( openTag != -1 )
	{
		int closeTag = input.find("/>", openTag+1);
		if (closeTag != -1 && closeTag > openTag)
		{
			MAUtil::String  record = input.substr(
				openTag+2, closeTag - openTag +1);
			// A record, ex: <p ns="0" title="title1" snippet="text.."
			// size="10283" wordcount="1324" timestamp="2011-04-12T14:25:24Z" />
			// Add the title if it doesn't exist yet.
			MAUtil::String newRecord = getTitle(record);
			bool canAdd(true);
			for (int i=0; i < mWiki->titleResults.size(); i++)
			{
				if ( mWiki->titleResults[i] == newRecord )
				{
					canAdd = false;
				}
			}
			if (canAdd)
			{
				mWiki->titleResults.add(newRecord);
				mWiki->snippetResults.add(getSnippet(record));
			}
		}
		input.remove(0,closeTag);

		// Get the next tag.
		openTag = input.find("<p ",0);
	}
}
コード例 #3
0
/*
 * PublishingListener overwrite
 * FacebookPublisher2 registers itself as a PublishingListener of the mFacebook object. This will call the
 * FacebookPublisher2::publishingResponseReceived, sending the response from server in the "newId" param. The newId is
 * the id of new created object.
 * @param newId - the id of the new object.
 * @param path - contains the id of the object on which the publish request was made and the request name.
 * 				  e.g: id/feed, id/likes
 * This function is called when a new object is created (Album, Like, Comment, StatusMessage ect).
 */
void FacebookPublisher2::publishingResponseReceived(const MAUtil::String  &data, const MAUtil::String &path)
{
	MAUtil::String id;
	int found = data.find(":",0);
	if(found != MAUtil::String::npos)
	{
		found = data.find("\"", found);
		int last = data.findLastOf('"');
		if( (found != MAUtil::String::npos) && (last != MAUtil::String::npos))
		{
			id = data.substr(found+1, last-found);
		}

	}
	mListener->publishingResponseReceived(id, path);
}
コード例 #4
0
ファイル: WikiEngine.cpp プロジェクト: comforx/MoSync
/**
 * Parse paragraph, and get the title attribute.
 * @param input The input paragraph.
 * @return The title.
 */
MAUtil::String MediaWiki::getTitle(MAUtil::String inputStr)
{
	MAUtil::String title = "";
	int start = inputStr.find("title=",0);
	if ( start != -1 ){
		int end = inputStr.find(" snippet=", start+1);
		if ( end != -1)
		{
			// Get rid of the quotes also
			// ( from beginning, and end): title="text.." snippet=etc
			title = inputStr.substr(start+7, end - start - 8);
		}
	}
	// Format the title to unicode.
	formatToUnicode(title);

	// Get rid of the span tags, and keep only the content: the searchTerm.
	trimSpanTags(title);

	return title;
}
コード例 #5
0
ファイル: WikiEngine.cpp プロジェクト: comforx/MoSync
/**
 * Parse paragraph, and get the snippet attribute.
 * @param input The input paragraph.
 * @return The snippet.
 */
MAUtil::String MediaWiki::getSnippet(MAUtil::String inputStr)
{
	MAUtil::String snippet = "";
	int start = inputStr.find("snippet=",0);
	if ( start != -1 ){
		int end = inputStr.find(" size=", start+1);
		if ( end != -1){
			// Get rid of the quotes also( from beginning, and end)
			snippet = inputStr.substr(start+9, end - start - 10 );
		}
	}
	// Format the snippet to unicode.
	formatToUnicode(snippet);

	// Get rid of the span tags, and keep only the content: the searchTerm.
	trimSpanTags(snippet);

	// Get rid of the bold tags from end, that enclose dots.
	trimBoldTags(snippet);

	return snippet;
}
コード例 #6
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 == "");
	}
コード例 #7
0
ファイル: LoginScreen.cpp プロジェクト: mvasiliniuc/Reload
void LoginScreen::initializeScreen(MAUtil::String &os, int orientation)
{
	// set the os string
	mOS = os;

	maScreenSetFullscreen(1);
	MAExtent ex = maGetScrSize();
	int screenWidth = EXTENT_X(ex);
	int screenHeight = EXTENT_Y(ex);

	int centerH, buttonWidth, buttonHeight, buttonSpacing, editBoxHeight, logoWidth,
		layoutTop, labelHeight, labelWidth, labelSpacing, layoutHeight, ipBoxButtonSpacing;
	centerH = screenWidth / 2;

	bool isLandscape = false;
	if (orientation == MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT ||
		orientation == MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT)
	{
		isLandscape = true;
	}

	buttonWidth = (int)((float)screenWidth * 0.75);
	if (isLandscape)
	{
		buttonHeight = (int)((float)screenHeight * 0.15);
	}
	else
	{
		buttonHeight = (int)((float)screenWidth * 0.15);
	}
	if(screenHeight > 1000 && os.find("Android", 0) < 0)
	{
		buttonWidth = (int)((float)screenWidth * 0.4);
	}
	if(screenHeight > 1000 && os.find("Android", 0) < 0)
	{
		buttonHeight = (int)((float)screenWidth * 0.07);
	}
	buttonSpacing = (int)((float)buttonHeight * 0.3);
	if(os.find("Windows", 0) >= 0)
	{
		buttonSpacing = (int)((float)buttonHeight * 0.1);
	}
	editBoxHeight = (int)((float)screenHeight * 0.07);
	if(screenHeight > 1000  && os.find("Android", 0) < 0)
	{
		editBoxHeight = (int)((float)screenHeight * 0.02);
	}
	logoWidth = (int)((float)screenWidth * 0.75);
	layoutTop = (int)((float)screenHeight * 0.3);
	if(screenHeight > 1000  && os.find("Android", 0) < 0)
	{
		layoutTop = (int)((float)screenHeight * 0.25);
	}
	labelHeight = (int)((float)screenHeight * 0.05);
	if(screenHeight > 1000  && os.find("Android", 0) < 0)
	{
		labelHeight = (int)((float)screenHeight * 0.025);
	}
	labelWidth = screenWidth;
	if(os.find("Android", 0) >= 0)
	{
		labelWidth = buttonWidth;
	}
	labelSpacing = (int)((float)screenHeight * 0.02);
	if(screenHeight > 1000  && os.find("Android", 0) < 0)
	{
		labelSpacing = (int)((float)labelSpacing * 0.01);
	}
	layoutHeight = (buttonHeight + buttonSpacing) * 2;
	ipBoxButtonSpacing = (int)((float)screenHeight * 0.03);

	mLoginScreen = new LoginScreenWidget();
	mLoginScreen->addLoginScreenListener(this);

	//The reload Logo
	mLogo = new Image();
	mLogo->setImage(LOGO_IMAGE);
	mLogo->wrapContentHorizontally();
	mLogo->wrapContentVertically();
	mLogo->setWidth(logoWidth);
	mLogo->setScaleMode(IMAGE_SCALE_PRESERVE_ASPECT);
	mLogo->setPosition(centerH - logoWidth/2, screenHeight / 12);

	//The connect to server button
	if(os == "iPhone OS") //Android image buttons do not support text
	{
		mServerConnectButton = new ImageButton();
		((ImageButton*)mServerConnectButton)->addButtonListener(this);
		((ImageButton*)mServerConnectButton)->setBackgroundImage(CONNECT_BG);
		mServerConnectButton->setFontColor(0x000000);
	}
	else
	{
		mServerConnectButton = new Button();
		((Button*)mServerConnectButton)->addButtonListener(this);
	}

	mServerConnectButton->setText("Connect");
	mServerConnectButton->setTextHorizontalAlignment(MAW_ALIGNMENT_CENTER);
	mServerConnectButton->setTextVerticalAlignment(MAW_ALIGNMENT_CENTER);
	mServerConnectButton->setWidth(buttonWidth);
	mServerConnectButton->setHeight(buttonHeight);
	mServerConnectButton->setPosition(centerH - buttonWidth/2, layoutHeight - buttonHeight);

	//The edit box that receives the server IP
	mServerIPBox = new EditBox();
	mServerIPBox->setWidth(buttonWidth);
	//mServerIPBox->setHeight(editBoxHeight);
	mServerIPBox->addEditBoxListener(this);
	mServerIPBox->setPosition(centerH - buttonWidth/2,layoutHeight - buttonHeight - editBoxHeight - ipBoxButtonSpacing);

	//Label for the server IP edit box
	mServerIPLabel = new Label();
	mServerIPLabel->setText("Server IP:");
	mServerIPLabel->setFontColor(0xFFFFFF);
	mServerIPLabel->setTextHorizontalAlignment(MAW_ALIGNMENT_CENTER);
	mServerIPLabel->setTextVerticalAlignment(MAW_ALIGNMENT_CENTER);
	mServerIPLabel->setWidth(labelWidth);
	mServerIPLabel->setPosition(centerH - labelWidth/2, layoutHeight - buttonHeight - labelHeight - editBoxHeight - ipBoxButtonSpacing);

	/*
	 * The mConnectLayout and mDisconnectLayout are placed
	 * on top of each other inside a relative layout, and
	 * each is only shown when needed.
	 */
	mConnectLayout = new RelativeLayout();
	mConnectLayout->setWidth(screenWidth);
	mConnectLayout->setHeight(layoutHeight);
	mConnectLayout->addChild(mServerIPLabel);
	mConnectLayout->addChild(mServerIPBox);
	mConnectLayout->addChild(mServerConnectButton);
	mConnectLayout->setPosition(0, layoutTop);

	//The disconnect button
	if(os == "iPhone OS")
	{
		mServerDisconnectButton = new ImageButton();
		((ImageButton*)mServerDisconnectButton)->addButtonListener(this);
		((ImageButton*)mServerDisconnectButton)->setBackgroundImage(CONNECT_BG);
		mServerDisconnectButton->setFontColor(0x000000);
	}
	else
	{
		mServerDisconnectButton = new Button();
		((Button*)mServerDisconnectButton)->addButtonListener(this);
	}

	mServerDisconnectButton->setText("Disconnect");
	mServerDisconnectButton->setTextHorizontalAlignment(MAW_ALIGNMENT_CENTER);
	mServerDisconnectButton->setTextVerticalAlignment(MAW_ALIGNMENT_CENTER);
	mServerDisconnectButton->setWidth(buttonWidth);
	mServerDisconnectButton->setHeight(buttonHeight);
	mServerDisconnectButton->setPosition(centerH - buttonWidth/2, layoutHeight - buttonHeight);

	//Some instructions for the user
	mInstructionsLabel = new Label();
	mInstructionsLabel->setText("Use the Reload Web UI to load an app");
	mInstructionsLabel->setFontColor(0xFFFFFF);
	mInstructionsLabel->setWidth(labelWidth);
	mInstructionsLabel->setMaxNumberOfLines(2);
	mInstructionsLabel->setTextHorizontalAlignment(MAW_ALIGNMENT_CENTER);
	mInstructionsLabel->setTextVerticalAlignment(MAW_ALIGNMENT_CENTER);
	mInstructionsLabel->setPosition(centerH - labelWidth/2, layoutHeight - buttonHeight - labelHeight - ipBoxButtonSpacing);

	//Label with the Server IP
	mConnectedToLabel = new Label();
	mConnectedToLabel->setFontColor(0xFFFFFF);
	mConnectedToLabel->setWidth(labelWidth);
	mConnectedToLabel->setTextHorizontalAlignment(MAW_ALIGNMENT_CENTER);
	mConnectedToLabel->setTextVerticalAlignment(MAW_ALIGNMENT_CENTER);
	mConnectedToLabel->setPosition(centerH - labelWidth/2, layoutHeight - buttonHeight - labelHeight * 2 - labelSpacing - ipBoxButtonSpacing);

	/*
	 * The mConnectLayout and mDisconnectLayout are placed
	 * on top of each other inside a relative layout, and
	 * each is only shown when needed.
	 */
	mDisconnectLayout = new RelativeLayout();
	mDisconnectLayout->setWidth(screenWidth);
	mDisconnectLayout->setHeight(layoutHeight);
	mDisconnectLayout->addChild(mConnectedToLabel);
	mDisconnectLayout->addChild(mInstructionsLabel);
	mDisconnectLayout->addChild(mServerDisconnectButton);
	mDisconnectLayout->setPosition(0, layoutTop);

	//The layout that appears when the client is connected
	//is hidden on startup
	mDisconnectLayout->setVisible(false);

	//Button that loads the last loaded app
	if(os == "iPhone OS")
	{
		mLoadLastAppButton = new ImageButton();
		((ImageButton*)mLoadLastAppButton)->addButtonListener(this);
		((ImageButton*)mLoadLastAppButton)->setBackgroundImage(RELOAD_BG);
		mLoadLastAppButton->setFontColor(0x000000);
	}
	else
	{
		mLoadLastAppButton = new Button();
		((Button*)mLoadLastAppButton)->addButtonListener(this);
	}

	mLoadLastAppButton->setText("Reload last app");
	mLoadLastAppButton->setTextHorizontalAlignment(MAW_ALIGNMENT_CENTER);
	mLoadLastAppButton->setTextVerticalAlignment(MAW_ALIGNMENT_CENTER);
	mLoadLastAppButton->setWidth(buttonWidth);
	mLoadLastAppButton->setHeight(buttonHeight);
	mLoadLastAppButton->setPosition(centerH - buttonWidth/2, layoutTop + layoutHeight + buttonSpacing);

	//The info icon
	mInfoIcon = new ImageButton();
	mInfoIcon->addButtonListener(this);
	mInfoIcon->setBackgroundImage(INFO_ICON);
	mInfoIcon->setSize((int)(screenWidth * 0.1),(int)(screenWidth * 0.1));
	//mInfoIcon->setScaleMode(IMAGE_SCALE_PRESERVE_ASPECT);
	mInfoIcon->setPosition((int)(screenWidth * 0.85), (int)(screenHeight * 0.95) - (int)(screenWidth * 0.1) / 2);

	//A little MoSync logo at the lower right of the screen
	mMosynclogo = new Image();
	mMosynclogo->setImage(MOSYNC_IMAGE);
	mMosynclogo->setHeight((int)(screenWidth * 0.1));
	mMosynclogo->setScaleMode(IMAGE_SCALE_PRESERVE_ASPECT);
	mMosynclogo->setPosition((int)(screenWidth * 0.05),(int)(screenHeight * 0.95) - (int)(screenWidth * 0.1) / 2);

	mBackground = new Image();
	mBackground->setSize(screenWidth, screenHeight);
	mBackground->setImage(BACKGROUND);
	mBackground->setScaleMode(IMAGE_SCALE_XY);

	mMainLayout = new RelativeLayout();
	mMainLayout->setSize(screenWidth, screenHeight);
	if(os.find("Windows", 0) < 0)
	{
		mMainLayout->addChild(mBackground);
	}
	mMainLayout->addChild(mLogo);
	mMainLayout->addChild(mConnectLayout);
	mMainLayout->addChild(mDisconnectLayout);
	mMainLayout->addChild(mLoadLastAppButton);
	mMainLayout->addChild(mMosynclogo);
	mMainLayout->addChild(mInfoIcon);

	mLoginScreen->setMainWidget(mMainLayout);
}
コード例 #8
0
ファイル: LoginScreen.cpp プロジェクト: mvasiliniuc/Reload
void LoginScreen::rebuildScreenLayout(int screenHeight, int screenWidth, MAUtil::String os, int orientation)
{
	// on wp7 the layout changes look glitchy so we'll set the layout after all the
	// repositioning has been done
	mLoginScreen->setMainWidget(NULL);

	int centerH, buttonWidth, buttonHeight, buttonSpacing, editBoxHeight, logoWidth,
		layoutTop, labelHeight, labelWidth, labelSpacing, layoutHeight, ipBoxButtonSpacing;
	centerH = screenWidth / 2;

	bool isLandscape = false;
	if (orientation == MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT ||
		orientation == MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT)
	{
		isLandscape = true;
	}

	buttonWidth = (int)((float)screenWidth * 0.75);
	if (isLandscape)
	{
		buttonHeight = (int)((float)screenHeight * 0.15);
	}
	else
	{
		buttonHeight = (int)((float)screenWidth * 0.15);
	}
	if(screenHeight > 1000 && os.find("Android", 0) < 0)
	{
		buttonWidth = (int)((float)screenWidth * 0.4);
	}
	if(screenHeight > 1000 && os.find("Android", 0) < 0)
	{
		buttonHeight = (int)((float)screenWidth * 0.07);
	}
	buttonSpacing = (int)((float)buttonHeight * 0.3);
	if(os.find("Windows", 0) >= 0)
	{
		buttonSpacing = (int)((float)buttonHeight * 0.1);
	}
	editBoxHeight = (int)((float)screenHeight * 0.07);
	if(screenHeight > 1000  && os.find("Android", 0) < 0)
	{
		editBoxHeight = (int)((float)screenHeight * 0.02);
	}
	logoWidth = (int)((float)screenWidth * 0.75);
	layoutTop = (int)((float)screenHeight * 0.3);
	if(screenHeight > 1000  && os.find("Android", 0) < 0)
	{
		layoutTop = (int)((float)screenHeight * 0.25);
	}
	labelHeight = (int)((float)screenHeight * 0.05);
	if(screenHeight > 1000  && os.find("Android", 0) < 0)
	{
		labelHeight = (int)((float)screenHeight * 0.025);
	}
	labelWidth = screenWidth;
	if(os.find("Android", 0) >= 0)
	{
		labelWidth = buttonWidth;
	}
	labelSpacing = (int)((float)screenHeight * 0.02);
	if(screenHeight > 1000  && os.find("Android", 0) < 0)
	{
		labelSpacing = (int)((float)labelSpacing * 0.01);
	}
	layoutHeight = (buttonHeight + buttonSpacing) * 2;
	ipBoxButtonSpacing = (int)((float)screenHeight * 0.03);

	mLogo->setWidth(logoWidth);
	mLogo->setPosition(centerH - logoWidth/2, screenHeight / 12);

	mServerConnectButton->setWidth(buttonWidth);
	mServerConnectButton->setHeight(buttonHeight);

	mServerIPBox->setWidth(buttonWidth);
	mServerIPBox->setPosition(centerH - buttonWidth/2,layoutHeight - buttonHeight - editBoxHeight - ipBoxButtonSpacing);

	mServerIPLabel->setWidth(labelWidth);
	mServerIPLabel->setPosition(centerH - labelWidth/2, layoutHeight - buttonHeight - labelHeight - editBoxHeight - ipBoxButtonSpacing);

	mConnectLayout->setWidth(screenWidth);
	mConnectLayout->setHeight(layoutHeight);
	mConnectLayout->setPosition(0, layoutTop);

	mServerDisconnectButton->setWidth(buttonWidth);
	mServerDisconnectButton->setHeight(buttonHeight);

	mInstructionsLabel->setWidth(labelWidth);
	mInstructionsLabel->setPosition(centerH - labelWidth/2, layoutHeight - buttonHeight - labelHeight - ipBoxButtonSpacing);

	mConnectedToLabel->setWidth(labelWidth);
	mConnectedToLabel->setPosition(centerH - labelWidth/2, layoutHeight - buttonHeight - labelHeight * 2 - labelSpacing - ipBoxButtonSpacing);

	mDisconnectLayout->setWidth(screenWidth);
	mDisconnectLayout->setHeight(layoutHeight);
	mDisconnectLayout->setPosition(0, layoutTop);

	mLoadLastAppButton->setWidth(buttonWidth);
	mLoadLastAppButton->setHeight(buttonHeight);
	mLoadLastAppButton->setPosition(centerH - buttonWidth/2, layoutTop + layoutHeight + buttonSpacing);

	mInfoIcon->setPosition((int)(screenWidth * 0.85), (int)(screenHeight * 0.95) - (int)(screenWidth * 0.1) / 2);

	mMosynclogo->setPosition((int)(screenWidth * 0.05),(int)(screenHeight * 0.95) - (int)(screenWidth * 0.1) / 2);

	// we need to set new values for some widgets for the landscape mode
	if (isLandscape)
	{
		mServerConnectButton->setPosition(centerH - buttonWidth/2, layoutHeight - buttonHeight + buttonSpacing);
		mServerDisconnectButton->setPosition(centerH - buttonWidth/2, layoutHeight - buttonHeight + buttonSpacing);
		mInfoIcon->setSize((int)(screenHeight * 0.1),(int)(screenHeight * 0.1));
		mMosynclogo->setHeight((int)(screenHeight * 0.1));
	}
	else
	{
		mServerConnectButton->setPosition(centerH - buttonWidth/2, layoutHeight - buttonHeight);
		mServerDisconnectButton->setPosition(centerH - buttonWidth/2, layoutHeight - buttonHeight);
		mInfoIcon->setSize((int)(screenWidth * 0.1),(int)(screenWidth * 0.1));
		mMosynclogo->setHeight((int)(screenWidth * 0.1));
	}

	mBackground->setSize(screenWidth, screenHeight);

	mMainLayout->setSize(screenWidth, screenHeight);

	mLoginScreen->setMainWidget(mMainLayout);
}
コード例 #9
0
ファイル: SplashScreen.cpp プロジェクト: MoSync/Reload
SplashScreen::SplashScreen() : Screen()
{
	// Get Orientation, OS, Screen dimensions
	int orientation = maScreenGetCurrentOrientation();

	char buffer[64];
	maGetSystemProperty(
		"mosync.device.OS",
		buffer,
		64);
	MAUtil::String os = buffer;

	MAExtent ex = maGetScrSize();
	int screenWidth = EXTENT_X(ex);
	int screenHeight = EXTENT_Y(ex);
	int baseSize;
	if (orientation == MA_SCREEN_ORIENTATION_PORTRAIT_UP ||
			orientation == MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN)
	{
		baseSize = screenWidth;
	}
	else
	{
		baseSize = screenHeight;
	}

	mContainer = new VerticalLayout();
	mContainer->fillSpaceHorizontally();
	mContainer->fillSpaceVertically();
	mContainer->setChildHorizontalAlignment(MAW_ALIGNMENT_CENTER);
	mContainer->setChildVerticalAlignment(MAW_ALIGNMENT_CENTER);
	if(os.find("iPhone") >= 0)
	{
		mContainer->setBackgroundColor(0x000000);
	}

	mReloadImage = new Image();
	mReloadImage->setImage(LOGO_IMAGE);
	mReloadImage->setScaleMode(IMAGE_SCALE_PRESERVE_ASPECT);
	mReloadImage->setWidth((int)((float)baseSize * 0.8));

	mPoweredBy = new Label();
	mPoweredBy->setText("powered by");
	if(os.find("iPhone") >= 0)
	{
		mPoweredBy->setFontColor(0xffffff);
	}
	mPoweredBy->setTextHorizontalAlignment(MAW_ALIGNMENT_CENTER);
	mPoweredBy->fillSpaceHorizontally();

	mMosyncImage = new Image();
	mMosyncImage->setImage(MOSYNC_IMAGE);
	mMosyncImage->setScaleMode(IMAGE_SCALE_PRESERVE_ASPECT);
	mMosyncImage->setWidth((int)((float)baseSize * 0.4));

	mContainer->addChild(mReloadImage);
	mContainer->addChild(mPoweredBy);

	/**
	 * On WP the mosync logo does not align vertically in the center.
	 * Create a layout and align it inside the layout instead
	 */
	if(os.find("Windows") >= 0)
	{
		mMosync = new HorizontalLayout();
		mMosync->setWidth((int)((float)baseSize * 0.8));
		((HorizontalLayout *)mMosync)->setChildHorizontalAlignment(MAW_ALIGNMENT_CENTER);
		mMosync->addChild(mMosyncImage);
	}
	else
	{
		mMosync = (Widget*)mMosyncImage;
	}
	mContainer->addChild(mMosync);

	this->addChild(mContainer);
	this->setMainWidget(mContainer);
}
コード例 #10
0
ファイル: WebViewMessage.cpp プロジェクト: Felard/MoSync
	/**
	 * Parse the message. This finds the message name and
	 * creates a dictionary with the message parameters.
	 */
	void WebViewMessage::parse(MAHandle dataHandle)
	{
		// Set message name to empty string as default.
		mMessageName = "";

		// We must have data.
		if (NULL == dataHandle)
		{
			return;
		}

		// Get length of the data, it is not zero terminated.
		int dataSize = maGetDataSize(dataHandle);

		// Allocate buffer for string data.
		char* stringData = (char*) malloc(dataSize + 1);

		// Get the data.
		maReadData(dataHandle, stringData, 0, dataSize);

		// Zero terminate.
		stringData[dataSize] = 0;

		// Create String object with message.
		MAUtil::String messageString = stringData;

		// Find schema.
		int start = messageString.find("mosync://");
		if (0 != start)
		{
			return;
		}

		// Set start of message name.
		start = 9;

		// Find end of message name.
		int end = messageString.find("?", start);
		if (MAUtil::String::npos == end)
		{
			// No params, set message name to rest of string.
			mMessageName = messageString.substr(start);
			return;
		}

		// Set message name.
		mMessageName = messageString.substr(start, end - start);

		while (1)
		{
			// Find param name.
			start = end + 1;
			end = messageString.find("=", start);
			if (MAUtil::String::npos == end)
			{
				// No param name found, we are done.
				break;
			}

			// Set param name.
			MAUtil::String paramName = messageString.substr(start, end - start);
			MAUtil::String paramValue;

			// Find end of param value.
			start = end + 1;
			end = messageString.find("&", start);
			if (MAUtil::String::npos == end)
			{
				// Last param, set param value to rest of string.
				paramValue = messageString.substr(start);
			}
			else
			{
				paramValue = messageString.substr(start, end - start);
			}

			// Add param to table.
			mMessageParams.insert(unescape(paramName), unescape(paramValue));

			// If no more params we are done.
			if (MAUtil::String::npos == end)
			{
				break;
			}
		}

		// Free string data.
		free(stringData);
	}
コード例 #11
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;
		}
	}