Beispiel #1
0
	/**
	 * This method is called when a key is pressed.
	 */
	void handleKeyPress(int keyCode)
	{
		// The MAK_BACK key code is sent on Android when
		//  the back key is pressed.
		if (MAK_BACK == keyCode)
		{
			// Is this the color screen (first tab)?
			if (COLOR_TAB == mCurrentTabIndex)
			{
				// Exit only if this is the top screen in the stack.
				// If there are more that one screen on the stack,
				// we will instead go back to the previous screen.
				// This behaviour is built into the stack screen
				// widget, and can be turned on/off with the property
				// MAW_STACK_SCREEN_BACK_BUTTON_ENABLED.
				if (mColorScreen->getStackSize() <= 1)
				{
					maExit(0);
				}
			}
			else
			{
				// Otherwise, always exit when back key is pressed.
				maExit(0);
			}
		}
	}
Beispiel #2
0
/**
 * Simple use case for the text box.
 * This program will show a text box and
 * retrieve the text entered by the user.
 */
extern "C" int MAMain() {
	// Initializations
	const wchar* title = L"My Title";
	const wchar* text = L"My Text";
	const int length = 1024;
	wchar buf[length];

	// Shows the text box
	// Returns when the text box is ready
	// to receive input
	maTextBox(title, text, buf, length, 0);

	// Event loop
	MAEvent event;
	maWait(0);
	while(maGetEvent(&event))
	{
		// Exit when the fire key is pressed
		if(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_FIRE) {
			maExit(0);
		}
		// When the TextBox closes, display the result (OK or CANCEL),
		// the text retrieved, and its length
		if( event.type == EVENT_TYPE_TEXTBOX ) {
			printf("Result (OK = 1 ; CANCEL = 2): %d\n", event.textboxResult);
			wprintf(L"The text box contained: %s\n", buf);
			printf("Length of the text: %d\n", event.textboxLength);
			printf("Press fire to exit...\n");
		}
		maWait(0);
	}
	return 0;
}
Beispiel #3
0
	//-------------------------------------------------------------------------
	bool MapDemoScreen::handleKeyPress( int keyCode )
	//-------------------------------------------------------------------------
	{
		switch( keyCode )
		{
			case MAK_2:
				nextMapSource( );
				return true;
			case MAK_BACK:
			case MAK_SOFTRIGHT:
				maExit( 0 );
#if 0
				// TODO: proper exit
				MapDemoMoblet& moblet = (MapDemoMoblet&)Environment::getEnvironment( );
				moblet.Terminate( );
				return true;
#endif
		}

		if ( AppScreen::handleKeyPress( keyCode ) )
			return true;

		// Here we tell the map widget to handle the key press.
		return mMap->handleKeyPress( keyCode );
	}
Beispiel #4
0
void SaveScreen::keyPressEvent(int keyCode, int nativeCode) {
#if DEBUG >= 1
	lprintfln("Index: %d (%d / %d)", listBox->getSelectedIndex(), keyCode, nativeCode);
#endif

	switch(keyCode) {
		case MAK_HASH:
			// Hash (#) key - ask the moblet to close the application
			maExit(0);
			break;

		case MAK_LEFT:
		case MAK_SOFTRIGHT:
			ScreenTransition::makeTransition(this, previous, -1, 400);
			break;

		case MAK_RIGHT:
		case MAK_FIRE:
			CheckBox * cb = (CheckBox *)((Label*)listBox->getChildren()[listBox->getSelectedIndex()])->getChildren()[0];
			cb->flip();
			break;

		case MAK_DOWN:
			listBox->selectNextItem();
			break;

		case MAK_UP:
			listBox->selectPreviousItem();
			break;
	}
}
Beispiel #5
0
extern "C" int MAMain() {
	int res;

	InitConsole();

	printf("CreateData\n");
	maCreateData(RES, 386);
	printf("DestroyObject\n");
	maDestroyObject(RES);

	printf("HTTP GET\n");
	//res = myHttpGetToObject(1, "http://dev.mopix.se:8080/testing/mobile.php");
	{
		MAUtil::HttpGetToObject http("http://link.astando.se/astwms/Request.aspx?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&LAYERS=TO_Vattenytor,TO_Oppen_mark,TO_Byggnadsytor,TO_Vagkonturer,Vagkanter,TO_Geografiska_texter,TO_Allm_byggnadsnamn,Gatunamn&STYLES=&FORMAT=png&BGCOLOR=0xFF0000&TRANSPARENT=TRUE&SRS=EPSG:3152&BBOX=78202.0228224145,99374.2252203757,79546.909389597,100413.827113304&WIDTH=240&HEIGHT=188&reaspect=false", RES);
		res = http.state();
		while(res == 0) {
			EVENT event;
			maWait(0);
			while(maGetEvent(&event)) {
				if(event.type == EVENT_TYPE_CLOSE ||
					(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
				{
					maExit(0);
				} else if(event.type == EVENT_TYPE_CONN) {
					printf("cE %i %i %i\n", event.conn.handle, event.conn.opType, event.conn.result);
					http.notify(event.conn);
					res = http.state();
				}
			}
		}
	}
	printf("Got %i\n", res);
	FREEZE;
}
Beispiel #6
0
/**
 * Handle keypresses.
 */
void MainScreen::handleKeyPress(int keyCode)
{
	if (this->getStackSize() <= 1)
	{
		maExit(0);
	}
}
Beispiel #7
0
void testReadOverload(const char* url) {
	Handle conn = maConnect(url);
	if(conn < 0) {
		printf("maConnect error %i\n", conn);
		return;
	}

	int result = 0;
	char buffer[1024];
	while(result >= 0) {
		EVENT event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
			{
				maExit(0);
			} else if(event.type == EVENT_TYPE_CONN) {
				printf("Op %i result %i\n", event.conn.opType, event.conn.result);
				MAASSERT(event.conn.handle == conn);
				result = event.conn.result;
				MAASSERT(result != 0);
			}
		}
		if(result == 0) {
			maWait(0);
		} else {
			maConnRead(conn, buffer, sizeof(buffer));
		}
	}
	printf("Done.\n");
}
Beispiel #8
0
int main() {
    char bigAssBuffer[BIGASSBUFFERSIZE];
    char* hello = "HTTP GET test";
    Extent screenSize, textSize;
    screenSize = maGetScrSize();

    //Draw centered text
    println("");
    textSize = maDrawText(0, 0, hello);
    maSetColor(0);
    maFillRect(0, 0, EXTENT_X(textSize), EXTENT_Y(textSize));  //erase test text
    maDrawText((EXTENT_X(screenSize) - EXTENT_X(textSize)) / 2, 0, hello);
    maUpdateScreen();

    println("Connecting...");
    int res = maHttpGet("link.astando.se"
                        "/guido/LvRouting.asmx/GenerateRouteGuido?fromX=100502&fromY=77476&toX=100591&toY=77368",
                        //"wap.mopix.se/test/test.comb",
                        bigAssBuffer, BIGASSBUFFERSIZE);

    printiln("Got %i bytes", res);
    println(bigAssBuffer);
    println("PAK to quit");

    PAKAndRelease();
    maExit(0);
}
Beispiel #9
0
	/**
	 * Method for handling key presses.
	 */
	void keyPressEvent(int keyCode, int nativeCode)
	{
		if (MAK_0 == keyCode || MAK_BACK == keyCode)
		{
			maExit(0);
		}
	}
Beispiel #10
0
void testConnectOverload(const char* url, bool acceptSuccess) {
	int connects = 0, events = 0;
	int result = 0;
	int conn;
	bool hasConn = false;
	MAUtil::Vector<Handle> conns;
	do {
		EVENT event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
			{
				maExit(0);
			} else if(event.type == EVENT_TYPE_CONN) {
				printf("Op %i conn %i result %i\n", event.conn.opType, event.conn.handle, event.conn.result);
				MAASSERT(event.conn.opType == CONNOP_CONNECT);
				conn = event.conn.handle;
				if(acceptSuccess) {
					if(event.conn.result < 0) {
						result = event.conn.result;
					}
				} else {
					result = event.conn.result;
				}
				MAASSERT(event.conn.result != 0);
				hasConn = true;
				events++;
				printf("Event %i\n", events);
				break;
			}
		}
		if(result == 0) {
			conn = maConnect(url);
			conns.add(conn);
			if(conn < 0) {
				printf("maConnect error %i\n", conn);
				result = conn;
				hasConn = false;
			} else {
				connects++;
				printf("Connect %i\n", connects);
			}
		} else if(events != connects)
			maWait(0);
	} while(events != connects);// && connects < 3);
	if(hasConn) {
		printf("Result %i on handle %i after %i connects\n", result, conn, connects);
	} else {
		printf("Result %i after %i connects\n", result, connects);
	}
	printf("Closing %i handles\n", conns.size());
	for(int i=0; i<conns.size(); i++) {
		maConnClose(conns[i]);
	}
	printf("Done.\n");
}
Beispiel #11
0
void error(int __status, int __errnum, __const char* __format, ...)
{
	va_list args;
	va_start(args, __format);
	char buffer[2048];
	vsprintf(buffer, __format, args);
	va_end(args);
	lprintfln("error(%i, %i, %s)\n", __status, __errnum, buffer);
	maExit(1);
}
Beispiel #12
0
static void checkEvents() {
	MAEvent event;
	while(maGetEvent(&event)) {
		if(event.type == EVENT_TYPE_CLOSE ||
			(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
		{
			maExit(1);
		}
	}
}
Beispiel #13
0
void STLMoblet::keyPressEvent(int keyCode)
{
	switch(keyCode)
	{
	case MAK_BACK:
		maExit(0);
		break;
	case MAK_0:
		STL_containers();
		display_menu();
		break;
	case MAK_1:
		functors_explained();
		STL_functors();
		display_menu();
		break;
	case MAK_2:
		pointer_adapters_explained();
		STL_adaptors();
		display_menu();
		break;
	case MAK_3:
		predicates_explained();
		display_menu();
		break;
	case MAK_4:
		STL_algorithms();
		display_menu();
		break;
	case MAK_5:
		STL_string();
		display_menu();
		break;
	case MAK_6:
		aux_functions();
		display_menu();
		break;
	case MAK_7:
		STL_auto_ptr();
		display_menu();
		break;
	case MAK_8:
		STL_pair();
		display_menu();
		break;
	case MAK_9:
		STL_iterators();
		display_menu();
		break;
	}

}
Beispiel #14
0
void Freeze(int val) {
	maUpdateScreen();
	for(;;) {
		MAEvent event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED &&
				(event.key == MAK_0 || event.key == MAK_BACK)))
			{
				maExit(val);
			}
		}
		maWait(0);
	}
}
Beispiel #15
0
	//TestCase
	void start() {
		printf("Don't touch anything now...\n");
		MAEvent e;
		while(maGetEvent(&e)) {	//clear event buffer
			if(e.type == EVENT_TYPE_CLOSE)
				maExit(0);
		}
		int startTime = maGetMilliSecondCount();
		maWait(TEST_TIMEOUT);
		int delta = maGetMilliSecondCount() - startTime;
		bool success = delta > TEST_TIMEOUT - TEST_TIME_EPSILON;
		printf("%s (%i ms)\n", success ? "Success" : "Failure", delta);
		assert(name, success);
		suite->runNextCase();
	}
Beispiel #16
0
void BenchDBConnector::connRecvFinished(MAUtil::Connection * conn, int result){
	if(result >= 0) {
		printf("connRecvFinished %i\n", result);
		mHttp.recv(mBuffer, CONNECTION_BUFFER_SIZE);
		return;
	}
	else if(result == CONNERR_CLOSED) {
		printf("Receive finished!\n");
	} else {
		printf("connection error %i\n", result);
	}
	mHttp.close();
	mIsConnected = false;
	mDone = true; //nothing more to do
	maExit(0);//quit here
}
Beispiel #17
0
	//-------------------------------------------------------------------------
	bool MapDemoScreen::handlePointerPress( MAPoint2d point )
	//-------------------------------------------------------------------------
	{
		if ( AppScreen::handlePointerPress( point ) )
			return true;

		mMap->getViewport( )->beginPanning( point );

		int curTime = maGetMilliSecondCount();
		int deltaTime = curTime - lastPointerPress;

		if(deltaTime < 200)
		{
			maExit(0);
		}
		else
		{
			lastPointerPress = curTime;
		}
		return true;
	}
Beispiel #18
0
int waitConn(Handle conn) {
    while(1) {
        EVENT event;
        if(maGetEvent(&event)) {
            if(event.type == EVENT_TYPE_CLOSE ||
                    (event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
            {
                maConnClose(conn);
                maExit(0);
            } else if(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_1) {
                maConnClose(conn);
            } else if(event.type == EVENT_TYPE_CONN) {
                printf("Result: %i\n", event.conn.result);
                /*if(event.conn.result <= 0) {
                	Freeze(0);
                }*/
                return event.conn.result;
            }
        }
        maWait(0);
    }
}
Beispiel #19
0
int MAMain()
{
	//MAExtent e = maGetScrSize();

	/// play R_MOSO sound
	maSoundPlay(SOUND_RESOURCE, 0, maGetDataSize(SOUND_RESOURCE));

	printf("Press 0/RSK to exit.");

	while(1) {
		maWait(0);
		MAEvent event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && 
				(event.key == MAK_0 || event.key == MAK_SOFTRIGHT || event.key == MAK_BACK)))
			{
				maExit(0);
			}
		}
	}
}
Beispiel #20
0
int AnimatedConnWait() {
	int startTime = maGetMilliSecondCount();
	int res;
#ifdef ANIMATED
	int lPos = gPos;
	int i=0;
	int screenWidth = EXTENT_X(maGetScrSize());

	maSetColor(0);
	maFillRect(0, lPos, screenWidth - 1, gTextHeight);
	printlnf("a%i",i++);
#endif	//ANIMATED
	while(1) {
		EVENT event;

#ifdef ANIMATED
		gPos = lPos;
		maSetColor(0);
		maFillRect(0, lPos, screenWidth - 1, gTextHeight);
		printlnf("b%i",i++);
#else
		maWait(0);
#endif	//ANIMATED

		if(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
			{
				maExit(0);
			} else if(event.type == EVENT_TYPE_CONN) {
				res = event.conn.result;
				break;
			}
		}
	}
	printlnf("w%i", maGetMilliSecondCount() - startTime);
	return res;
}
Beispiel #21
0
/**
 * Waits for an event and returns the event object.
 *
 * @param millisecondTimeout Maximum number of milliseconds to wait.
 * @param eventType Event type to wait for.
 * @param returnedEvent Event object [out].
 *
 * @return True if event was caught with the given time limit.
 */
bool EventBase::waitForEvent(int millisecondTimeout, int eventType, MAEvent &returnedEvent)
{
	MAEvent event;
	long startTime = maGetMilliSecondCount();

	while (maGetMilliSecondCount() - startTime < millisecondTimeout)
	{
		maWait(100);
		while(maGetEvent(&event) != 0)
		{
			if (event.type == eventType)
			{
				returnedEvent = event;
				return true;
			}
			else if (event.type == EVENT_TYPE_CLOSE)
			{
				maExit(0);
			}
		}
	}

	return false;
}
Beispiel #22
0
void MainScreen::optionsMenuItemSelected(Screen *screen, int index) {
	switch (index) {
	case OMIAddItem:
		editScreenMode = SEMNew;
		addNewEvent();
		break;
	case OMIImport:
		importFromSdcard();
		break;
	case OMIExport:
		exportToSdcard();
		break;
	case OMIOptions:
		actScreenOptions();
		break;
	case OMIExit:
		actExit();
		maExit(0);
		break;
	default:
		dbgAction();
		break;
	}
}
Beispiel #23
0
void LabelScreen::keyPressEvent(int keyCode, int nativeCode) {
	switch(keyCode) {
		case MAK_HASH:
			// Hash (#) key - ask the moblet to close the application
			maExit(0);
			break;

		case MAK_SOFTRIGHT:
		case MAK_LEFT:
#if DEBUG >= 2
			lprintfln("Showing previous screen...");
#endif
			ScreenTransition::makeTransition(this, previous, -1, 400);
			break;

		case MAK_UP:
			listBox->selectPreviousItem();
			break;

		case MAK_DOWN:
			listBox->selectNextItem();
			break;
	}
}
Beispiel #24
0
int MAMain() {
	Handle conn;
	char ping[] = "ping\n";
	char buffer[1024];
	int res;

#ifdef CONPRINT
	InitConsole();
	gConsoleLogging = 1;
#endif

	//println("Socket test");
retry:
	printlnf("Connecting...");
	conn = maConnect("socket://130.237.3.104:6666");	//test DNS resolution
	res = AnimatedConnWait();
	if(res <= 0) {
		printlnf("err %i", res);
		goto exit;
	}
	/*conn = maConnect("socket://217.25.35.146:81");	//test IP address reading
	res = AnimatedConnWait();
	if(res <= 0) {
		printlnf("err %i", res);
		goto exit;
	}*/

	println("Writing...");
	maConnWrite(conn, ping, sizeof(ping));
	res = AnimatedConnWait();
	if(res <= 0) {
		printlnf("err %i", res);
		goto exit;
	}

	println("Reading...");

	res = ConnReadAtLeast(conn, 4, sizeof(buffer), buffer);
	if(res <= 0) {
		printlnf("err %i", res);
		goto exit;
	}
	maConnClose(conn);

	printlnf("Got %i bytes", res);

	buffer[res] = 0;
	println(buffer);
	maUpdateScreen();

exit:
	println("Press a key");
	for(;;) {
		EVENT event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
			{
				maExit(0);
			} else if(event.type == EVENT_TYPE_KEY_PRESSED) {
				goto retry;
			}
		}
		maWait(0);
	}
}
Beispiel #25
0
void Login::keyPressEvent(int keyCode) {
	error = false;
	Widget *currentSoftKeys = mainLayout->getChildren()[mainLayout->getChildren().size() - 1];
	int index = kinListBox->getSelectedIndex();

	switch(keyCode) {
		case MAK_FIRE:
			if(currentSoftKeys->getChildren()[0]->isSelected()){
				keyPressEvent(MAK_SOFTLEFT);
			}else if(currentSoftKeys->getChildren()[2]->isSelected()){
				keyPressEvent(MAK_SOFTRIGHT);
			}
			break;
		case MAK_SOFTLEFT:
			if (!isBusy) {
				switch (screen) {
					case S_LOGIN:
						if (editBoxLogin->getText()!="" & editBoxPass->getText()!="") {
							isBusy = true;
							notice->setCaption("Please wait, logging in...");
							conCatenation = editBoxPass->getText().c_str();
							value = Util::base64_encode(reinterpret_cast<const unsigned char*>(conCatenation.c_str()),conCatenation.length());
							feed->setEncrypt(value.c_str());
							feed->setUsername(editBoxLogin->getText().c_str());
							feed->setUnsuccessful("true");
							mHttp = HttpConnection(this);
							int urlLength = 71 + URLSIZE;
							char *url = new char[urlLength+1];
							memset(url,'\0',urlLength+1);
							sprintf(url, "%s?userdetails=1", URL);
							lprintfln("%s", url);
							int res = mHttp.create(url, HTTP_GET);

							if(res < 0) {
								notice->setCaption("Unable to connect, try again later...");
							} else {
								mHttp.setRequestHeader("AUTH_USER", feed->getUsername().c_str());
								mHttp.setRequestHeader("AUTH_PW", feed->getEncrypt().c_str());
								feed->addHttp();
								mHttp.finish();
							}
							delete url;
							url = NULL;
							conCatenation = "";
							value = "";
						} else {
							maVibrate(1000);
							notice->setCaption("Ensure that you have entered your username and password.");
						}
						break;
					case S_REGISTER:
						notice->setCaption("");
						if ((strcmp(feed->getRegistered().c_str(), "1") == 0)) {
							notice->setCaption("Already registered for an account with this device.");
							maVibrate(1000);
						} else if (editBoxLogin->getText().length() < 6) {
							notice->setCaption("Your username needs to be at least 6 characters long");
							maVibrate(1000);
						}
						else if (editBoxPass->getText().length() < 6) {
							notice->setCaption("Your password needs to be at least 6 characters long");
							maVibrate(1000);
						}
						else if (editBoxEmail->getText().length() == 0) {
							notice->setCaption("You need to enter an email address");
							maVibrate(1000);
						}
						else if (!Util::validateEmailAddress(editBoxEmail->getText())) {
							notice->setCaption("Please enter a valid email address");
							maVibrate(1000);
						}
						else if (!Util::validateNoWhiteSpaces(editBoxLogin->getText())) {
							notice->setCaption("Please enter a username without spaces.");
							maVibrate(1000);
						}
						else if (!Util::validateNoWhiteSpaces(editBoxPass->getText())) {
							notice->setCaption("Please enter a password without spaces.");
							maVibrate(1000);
						}
						else if (!Util::validateNoWhiteSpaces(editBoxEmail->getText())) {
							notice->setCaption("Please enter a email address without spaces.");
							maVibrate(1000);
						}
						else if (!Util::validateNoWhiteSpaces(editBoxRefer->getText())) {
							notice->setCaption("Please enter a referer name.");
							maVibrate(1000);
						}
						else {
							result = "";
							isBusy = true;
							notice->setCaption("Attempting to register user...");


							conCatenation = editBoxPass->getText().c_str();
							value = Util::base64_encode(reinterpret_cast<const unsigned char*>(conCatenation.c_str()),conCatenation.length());
							feed->setEncrypt(value.c_str());
							feed->setUsername(editBoxLogin->getText().c_str());
							feed->setUnsuccessful("true");
							char *url = NULL;
							//work out how long the url will be, the 2 is for the & and = symbols
							int urlLength = 89 + URLSIZE + editBoxLogin->getText().length() + editBoxPass->getText().length() + editBoxEmail->getText().length() + editBoxRefer->getText().length();
							url = new char[urlLength+1];
							memset(url,'\0',urlLength+1);
							sprintf(url, "%s?registeruser=1&username=%s&password=%s&email=%s&referer=%s", URL, editBoxLogin->getText().c_str(),
									editBoxPass->getText().c_str(), editBoxEmail->getText().c_str(), editBoxRefer->getText().c_str());
							lprintfln("%s", url);
							mHttp = HttpConnection(this);
							int res = mHttp.create(url, HTTP_GET);
							if(res < 0) {
								notice->setCaption("Unable to connect, try again later...");
							} else {
								mHttp.setRequestHeader("AUTH_USER", feed->getUsername().c_str());
								mHttp.setRequestHeader("AUTH_PW", feed->getEncrypt().c_str());
								feed->addHttp();
								mHttp.finish();
							}
							delete url;
							url = NULL;
						}
						break;
				}
			}
			break;
		case MAK_BACK:
		case MAK_SOFTRIGHT:
			if ((strcmp(feed->getRegistered().c_str(), "1") == 0)) {
				maExit(1);
			} else {
				previous->show();
			}

			break;
		case MAK_UP:
			if(currentSelectedKey!=NULL){
				currentSelectedKey->setSelected(false);
				currentSelectedKey = NULL;
				currentKeyPosition = -1;
				kinListBox->getChildren()[kinListBox->getChildren().size()-1]->setSelected(true);
			}
			else if (index-2 > 0) {
				kinListBox->setSelectedIndex(index-2);
			}
			break;
		case MAK_DOWN:
			if (index+2 < kinListBox->getChildren().size()) {
				kinListBox->setSelectedIndex(index+2);
			} else {
				kinListBox->getChildren()[index]->setSelected(false);
				for(int i = 0; i < currentSoftKeys->getChildren().size();i++){
					if(((Button *)currentSoftKeys->getChildren()[i])->isSelectable()){
						currentKeyPosition=i;
						currentSelectedKey= currentSoftKeys->getChildren()[i];
						currentSelectedKey->setSelected(true);
						break;
					}
				}
			}
			break;
		case MAK_LEFT:
			if(currentSelectedKey!=NULL){
				if(currentKeyPosition > 0){
					currentKeyPosition = currentKeyPosition - 1;
					for(int i = currentKeyPosition; i >= 0;i--){
						if(((Button *)currentSoftKeys->getChildren()[i])->isSelectable()){
							currentSelectedKey->setSelected(false);
							currentKeyPosition=i;
							currentSelectedKey= currentSoftKeys->getChildren()[i];
							currentSelectedKey->setSelected(true);
							break;
						}
					}
				}
			}
			break;
		case MAK_RIGHT:
			if(currentSelectedKey!=NULL){
				if(currentKeyPosition+1 < currentSelectedKey->getParent()->getChildren().size()){
					currentKeyPosition = currentKeyPosition + 1;
					for(int i = currentKeyPosition; i < currentSoftKeys->getChildren().size();i++){
						if(((Button *)currentSoftKeys->getChildren()[i])->isSelectable()){
							currentSelectedKey->setSelected(false);
							currentKeyPosition=i;
							currentSelectedKey= currentSoftKeys->getChildren()[i];
							currentSelectedKey->setSelected(true);
							break;
						}
					}
				}
			}
			break;
	}
}
Beispiel #26
0
int RenderMain ( void )
{
	int 			tmrLast = 0;
	int 			currFps = 0,
					lastFps = 0;
	int 			frameIndex = 0;
	float 			frameInterp = 0;
	float			rotRadY = 0.0f,
					rotRadX = 0.0f;
	char			textBuffer[128];
	bool 			keyTable[4] = { false };
	bool focus = true;

	Matrix4fi		transMatrix( false );
	MAExtent		size = maGetScrSize( );
	MDLFixed 		model( RES_MODEL_OGRE );
	TransformPipe	pipe( EXTENT_X( size ), EXTENT_Y( size ) );


	// Center model
	model.centerModel( );

	tmrLast = maGetMilliSecondCount( );

	//
	// Rendering loop
	//
	while ( true )
	{
		//
		// Handle input
		//
		MAEvent e;
		while ( maGetEvent( &e ) )
		{
			if ( e.type == EVENT_TYPE_CLOSE ||
				 e.type == EVENT_TYPE_KEY_PRESSED ||
				 e.type == EVENT_TYPE_POINTER_PRESSED )
				maExit(0);
			else if(e.type == EVENT_TYPE_FOCUS_LOST)
				focus = false;
			else if(e.type == EVENT_TYPE_FOCUS_GAINED)
				focus = true;

			else if ( e.type == EVENT_TYPE_KEY_PRESSED )
			{
				if ( e.key == MAK_LEFT )
					keyTable[MAK_LEFT-MAK_UP] = true;
				else if ( e.key == MAK_RIGHT )
					keyTable[MAK_RIGHT-MAK_UP] = true;
				else if ( e.key == MAK_UP )
					keyTable[MAK_UP-MAK_UP] = true;
				else if ( e.key == MAK_DOWN )
					keyTable[MAK_DOWN-MAK_UP] = true;
			}
			else if ( e.type == EVENT_TYPE_KEY_RELEASED )
			{
				if ( e.key == MAK_LEFT )
					keyTable[MAK_LEFT-MAK_UP] = false;
				else if ( e.key == MAK_RIGHT )
					keyTable[MAK_RIGHT-MAK_UP] = false;
				else if ( e.key == MAK_UP )
					keyTable[MAK_UP-MAK_UP] = false;
				else if ( e.key == MAK_DOWN )
					keyTable[MAK_DOWN-MAK_UP] = false;
			}
		}

		if(focus) {
			if ( keyTable[MAK_LEFT-MAK_UP] )
				rotRadY -= (float)M_PI / 60;
			else if ( keyTable[MAK_RIGHT-MAK_UP] )
				rotRadY += (float)M_PI / 60;
			else if ( keyTable[MAK_UP-MAK_UP] )
				rotRadX -= (float)M_PI / 60;
			else if ( keyTable[MAK_DOWN-MAK_UP] )
				rotRadX += (float)M_PI / 60;

			rotRadX = (rotRadX >= 2*(float)M_PI) ? rotRadX-2*(float)M_PI : rotRadX;
			rotRadY = (rotRadY >= 2*(float)M_PI) ? rotRadY-2*(float)M_PI : rotRadY;

			//
			// Construct transformation pipe
			//
			pipe.resetPipe( );

			transMatrix.rotateX( (float)-M_PI/2 );
			pipe.addTransform( transMatrix );
			transMatrix.rotateY( (float)M_PI/4 );
			pipe.addTransform( transMatrix );

			transMatrix.rotateX( rotRadX );
			pipe.addTransform( transMatrix );
			transMatrix.rotateY( rotRadY );
			pipe.addTransform( transMatrix );
			transMatrix.translate( 0, 0, 130 );
			pipe.addTransform( transMatrix );


			// Clear screen
			maSetColor( 0 );
			maFillRect( 0, 0, EXTENT_X( size ), EXTENT_Y( size ) );

			//
			// Animate and render model
			//
			maSetColor( 0xffffff );
			model.drawFrameLerp( frameIndex, FLT2FIX( frameInterp ), pipe );
			frameInterp += 0.25f;
			if ( frameInterp >= 1.0f )
			{
				frameIndex  = (frameIndex+1) % model.getFrameCount( );
				frameInterp = 0.0f;
			}

			// Draw fps to screen
			sprintf( textBuffer, "fps: %d", lastFps );
			maDrawText( 0, 0, textBuffer );

			// Update screen and keep backlight on
			maUpdateScreen( );
			maResetBacklight( );

			// FPS counter
			currFps++;
			if ( tmrLast+1000 <= maGetMilliSecondCount( ) )
			{
				lastFps = currFps;
				currFps = 0;
				tmrLast = maGetMilliSecondCount( );
				lprintfln( "fps: %d", lastFps );
			}
		} else {	// no focus
			maWait(0);
		}
	}
}
Beispiel #27
0
void scan() {
	int nserv=0;
	MAEvent event;
#ifdef SCAN_DEVICES
scan_devices:
	int ndev=0;
	MABtDevice d;
	char namebuf[256];
	int res;

	printf("DevDisc...\n");
	int startTime = maGetMilliSecondCount();
	maBtStartDeviceDiscovery(1);
	//printf("Started\n");

	while(true) {
		d.name = namebuf;
		d.nameBufSize = sizeof(namebuf);

		do {
			strcpy(namebuf, "Hello Debugger!");
			res = maBtGetNewDevice(&d);
			if(res) {
				printf("d%i: %i %s\n", ndev++, res, d.name);
				if(res < 0) {
					break;
				}
				printf("%s\n", btaddr2string(d.address));
			} else {
				printf("res %i\n", res);
			}
		} while(res > 0);

		maWait(0);
		maGetEvent(&event);	//this oughta work, cause maWait(0) guarantees that there's at least one event.
		if(event.type == EVENT_TYPE_BT && event.state != 0)
			break;
		if(event.type == EVENT_TYPE_CLOSE ||
			(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_0 || event.key == MAK_KP0)))
		{
			maExit(0);
		}
	}
	printf("Done %i, %i ms\n", event.state, maGetMilliSecondCount() - startTime);

	printf("Press 1 or 3\n");
	while(true) {
		maWait(0);
		maGetEvent(&event);
		if(event.type == EVENT_TYPE_CLOSE ||
			(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_0 || event.key == MAK_KP0)))
		{
			maExit(0);
		}
		if(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_1 || event.key == MAK_KP1)) {
			goto scan_devices;
		}
		if(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_3 || event.key == MAK_KP3)) {
			break;
		}
	}


	const MABtAddr& address = d.address;
#else
	//const MABtAddr address = { { 0x00, 0x0f, 0xde, 0xa1, 0x4b, 0x70 } };	//K700i Jacob
	//const MABtAddr address = { { 0x00, 0x0b, 0x0d, 0x14, 0x99, 0x0f } };	//Holux
	//const MABtAddr address = { { 0x00, 0x11, 0x9f, 0xcb, 0x74, 0x10 } };	//6630 v1.0
	//const MABtAddr address = { { 0x00, 0x18, 0xc5, 0x3f, 0x74, 0x7e } };	//N73
	//const MABtAddr address = { { 0x00, 0x80, 0x98, 0x44, 0x74, 0xc8 } };	//MS-FREDRIK
	//const MABtAddr address = { { 0x00, 0x11, 0x67, 0x9c, 0xd9, 0x3c } };	//MS-FREDRIK, new dongle
	const MABtAddr address = { { 0x00, 0x23, 0x3a, 0xb3, 0xc7, 0x82 } };	//Samsung SGH-i900
#endif	//SCAN_DEVICES

	printf("ServDisc %s\n", btaddr2string(address));
	int servStartTime = maGetMilliSecondCount();
	maBtStartServiceDiscovery(&address, &L2CAP_PROTOCOL_MAUUID);

	while(true) {
		MABtService s;
		char sNameBuf[256];
		static const int MAX_UUIDS = 32;
		MAUUID uuidBuf[MAX_UUIDS];
		int res;
		s.name = sNameBuf;
		s.nameBufSize = sizeof(sNameBuf);
		s.uuids = uuidBuf;

		//printfln("state: %i\n", maBtDiscoveryState2());
		do {
			strcpy(sNameBuf, "Hello Sebugger!");
			MABtServiceSize ss;
			res = maBtGetNextServiceSize(&ss);
			if(res) {
				MAASSERT(ss.nUuids <= MAX_UUIDS);
				if(ss.nameBufSize < 0) {
					printf("%i\n", ss.nameBufSize);
				}
				res = maBtGetNewService(&s);
				if(res) {
					if(ss.nameBufSize < 0) {
						printf("s%i: %i %i No name\n", nserv++, res, s.port);
					} else {
						printf("s%i: %i %i %i \"%s\"\n", nserv++, res, s.port, ss.nameBufSize, s.name);
					}
					/*for(int j=0; j<ss.nUuids; j++) {
						int* u = s.uuids[j].i;
						printf("%08X-%08X-%08X-%08X\n", u[0], u[1], u[2], u[3]);
					}*/
					if(res < 0) {
						//printf("res1 %i\n", res);
						break;
					}
				} else {
					//printf("res2 %i\n", res);
				}
			} else {
				//printf("res3 %i\n", res);
			}
		} while(res > 0);

		maWait(0);
		maGetEvent(&event);
		if(event.type == EVENT_TYPE_BT) {
			//printf("event %i\n", event.state);
			if(event.state != 0)
				break;
		}
		if(event.type == EVENT_TYPE_CLOSE ||
			(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_0 || event.key == MAK_KP0)))
		{
			maExit(0);
		}
	}
	printf("Done %i, %i ms\n", event.state, maGetMilliSecondCount() - servStartTime);
#ifdef SCAN_DEVICES
	printf("Done, total %i ms\n", maGetMilliSecondCount() - startTime);
#endif	//SCAN_DEVICES
}
Beispiel #28
0
void MenuScreen::keyPressEvent(int keyCode) {
	int total = listBox->getChildren().size();
	int select = listBox->getSelectedIndex();
	switch(keyCode) {
		case MAK_FIRE:
		case MAK_SOFTLEFT:
			int index = listBox->getSelectedIndex();
			if(index == OP_ALBUMS) {
				if(menu!=NULL){
					delete menu;
					feed->remHttp();
				}
				menu = new AlbumLoadScreen(this, feed, AlbumLoadScreen::ST_ALBUMS);
				menu->show();
			} else if(index == OP_SHOP) {
				if(menu!=NULL){
					delete menu;
				}
				menu = new ShopCategoriesScreen(this, feed, ShopCategoriesScreen::ST_SHOP);
				menu->show();
			} else if(index == OP_PROFILE) {
				if(menu!=NULL){
					delete menu;
				}
				menu = new DetailScreen(this, feed, DetailScreen::PROFILE, NULL);
				menu->show();
			} else if(index == OP_NOTIFICATIONS) {
				if(menu!=NULL){
					delete menu;
				}
				/* Notifications */
				menu = new DetailScreen(this, feed, DetailScreen::NOTIFICATIONS, NULL);
				menu->show();
			} else if(index == OP_FRIENDS) {
				if(menu!=NULL){
					delete menu;
				}
				/* Notifications */
				menu = new DetailScreen(this, feed, DetailScreen::FRIENDS, NULL);
				menu->show();
			} else if(index == OP_INVITEFRIENDS) {
				if(menu!=NULL){
					delete menu;
				}
				/*Invite Friend */
				menu = new TradeFriendDetailScreen(this, feed, NULL);
				menu->show();
			} else if (index == OP_LOGOUT) {
#if not defined(MA_PROF_STRING_PLATFORM_IPHONEOS)
				Albums *albums = feed->getAlbum();
				Vector<String> tmp = albums->getIDs();
				for (Vector<String>::iterator itr = tmp.begin(); itr != tmp.end(); itr++) {
					String s = itr->c_str();
					s+="-lst.sav";
					Util::saveData(s.c_str(),"");
				}
				feed->setAll("");
				feed->setRegistered("1");
				Util::saveData("fd.sav",feed->getAll().c_str());
				Util::saveData("lb.sav","");

				if (feed->getHttps() > 0) {
					label = (Label*) mainLayout->getChildren()[0]->getChildren()[1];
					label->setCaption("Please wait for all connections to finish before exiting. Try again in a few seconds.");
				} else {
					if(menu!=NULL){
						//delete menu;
					}
					maExit(0);
				}
#endif
			}
			break;
		case MAK_BACK:
		case MAK_SOFTRIGHT:
#if not defined(MA_PROF_STRING_PLATFORM_IPHONEOS)
			/*if (menu!=NULL) {
					delete menu;
			}*/
			int seconds = maLocalTime();
			int secondsLength = Util::intlen(seconds);
			char *secString = new char[secondsLength+1];
			memset(secString,'\0',secondsLength+1);
			sprintf(secString, "%d", seconds);
			feed->setSeconds(secString);
			Util::saveData("fd.sav", feed->getAll().c_str());

			if (feed->getHttps() > 0) {
				label = (Label*) mainLayout->getChildren()[0]->getChildren()[1];
				label->setCaption("Please wait for all connections to finish before exiting. Try again in a few seconds.");
			} else {
				maExit(0);
			}
#endif
			break;
		case MAK_DOWN:
			if (select == total-1) {
				listBox->setSelectedIndex(0);
			} else {
				listBox->selectNextItem();
			}
			break;
		case MAK_UP:
			if (select == 0) {
				listBox->setSelectedIndex(total-1);
			} else {
				listBox->selectPreviousItem();
			}
			break;
	}
}
Beispiel #29
0
extern "C" void GCCATTRIB(noreturn) __cxa_pure_virtual() {
	maExit(-42);
}
void OptionsScreen::keyPressEvent(int keyCode) {
	int ind = listBox->getSelectedIndex();
	int max = listBox->getChildren().size();
	Widget *currentSoftKeys = mainLayout->getChildren()[mainLayout->getChildren().size() - 1];
	switch(keyCode) {
		case MAK_FIRE:
			if(currentSoftKeys->getChildren()[0]->isSelected()){
				keyPressEvent(MAK_SOFTLEFT);
				break;
			}else if(currentSoftKeys->getChildren()[2]->isSelected()){
				keyPressEvent(MAK_SOFTRIGHT);
				break;
			}
		case MAK_SOFTLEFT:
			index = listBox->getSelectedIndex();
			switch(screenType) {
				case ST_TRADE_OPTIONS:
					if(index == 0) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new AuctionCreateScreen(this, feed, card);
						next->show();
					} else if(index == 1) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new TradeFriendDetailScreen(this, feed, card);
						next->show();
					}
					break;
				case ST_AUCTION_OPTIONS:
					if(index == 0) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new ShopCategoriesScreen(this, feed, ShopCategoriesScreen::ST_AUCTIONS);
						next->show();
					}
					else if (index == 1) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new AuctionListScreen(this, feed, AuctionListScreen::ST_USER);
						next->show();
					}
					break;
				case ST_PLAY_OPTIONS:
					if(index == 0 && !connError) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new AlbumLoadScreen(this, feed, AlbumLoadScreen::ST_PLAY);
						next->show();
					}
					else if (index == 1 && !connError) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new AlbumLoadScreen(this, feed, AlbumLoadScreen::ST_GAMES, album);
						next->show();
					}
					break;
				case ST_GAME_OPTIONS:
					if(index == 0) {
						origMenu->show();
					}
					else if (index == 1) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new GameDetailsScreen(feed, GameDetailsScreen::ST_GAME_LOG);
						next->show();
					}
					break;
				case ST_NEW_GAME_OPTIONS:
					if (index == 0) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new GamePlayScreen(this, feed, true, number, "1", false, deckId);
						next->show();
					}
					else if (index == 1) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new GamePlayScreen(this, feed, true, number, "2", false, deckId);
						next->show();
					}
					else if (index == 2) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new GamePlayScreen(this, feed, true, number, "2", true, deckId);
						next->show();
					}
					else if (index == 3) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new AlbumLoadScreen(this, feed, AlbumLoadScreen::ST_LOBBY, album,false,NULL,number);
						((AlbumLoadScreen*)next)->setDeckId(deckId);
						next->show();
					}
					break;
				case ST_CARD_OPTIONS:
					if (index == 0) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new NoteScreen(this, feed, card);
						next->show();
					}
					/*else if (index == 1) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new TradeFriendDetailScreen(this, feed, card);
						next->show();
					}*/
					else if (index == 1/*2*/) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new AuctionCreateScreen(this, feed, card);
						next->show();
					}
					else if (index == 2/*3*/) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new AlbumLoadScreen(this, feed, AlbumLoadScreen::ST_COMPARE, NULL, false, card);
						next->show();
					}
					else if (index == 3/*4*/) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new DetailScreen(this, feed,
								DetailScreen::CARD, card);
						next->show();
					}
					break;
				case ST_NEW_CARD:
					if(index == 0 && !busy) {
						busy = true;
						notice->setCaption("Accepting...");
						acceptCard();
					}
					else if (index == 1 && !busy) {
						busy = true;
						notice->setCaption("Rejecting...");
						rejectCard();
					}
					break;
				case ST_NUMBER_OPTIONS:
					if(index == 0) {
						maPlatformRequest(("tel:"+number).c_str());
					}
					else if (index == 1) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new NoteScreen(this, feed,
								card, NoteScreen::ST_SMS, number);
						next->show();
					}
					break;
				case ST_LOGIN_OPTIONS:
					if(index == 0) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new Login(this, feed, Login::S_LOGIN);
						next->show();
					}
					else if(index == 1) {
						if (next != NULL) {
							delete next;
							feed->remHttp();
							next = NULL;
						}
						next = new Login(this, feed, Login::S_REGISTER);
						next->show();
					}
					break;
			}
			break;
		case MAK_BACK:
		case MAK_SOFTRIGHT:
			switch(screenType) {
				case ST_LOGIN_OPTIONS:
#if not defined(MA_PROF_STRING_PLATFORM_IPHONEOS)
					maExit(0);
#endif
					break;
				default:
					clearListBox();
					previous->show();
					break;
			}
			break;
		case MAK_DOWN:
			if (ind+1 < listBox->getChildren().size()) {
				listBox->setSelectedIndex(ind+1);
			} else if(currentSelectedKey==NULL){
				listBox->getChildren()[ind]->setSelected(false);
				for(int i = 0; i < currentSoftKeys->getChildren().size();i++){
					if(((Button *)currentSoftKeys->getChildren()[i])->isSelectable()){
						currentKeyPosition=i;
						currentSelectedKey= currentSoftKeys->getChildren()[i];
						currentSelectedKey->setSelected(true);
						break;
					}
				}
			}
			/*if (ind == max-1) {
				listBox->setSelectedIndex(0);
			} else {
				listBox->selectNextItem();
			}*/
			break;
		case MAK_UP:
			if(currentSelectedKey!=NULL){
				currentSelectedKey->setSelected(false);
				currentSelectedKey = NULL;
				currentKeyPosition = -1;
				listBox->getChildren()[listBox->getChildren().size()-1]->setSelected(true);
			}
			else if (ind > 0) {
				listBox->setSelectedIndex(ind-1);
			}/*if (ind == 0) {
				listBox->setSelectedIndex(max-1);
			} else {
				listBox->selectPreviousItem();
			}*/
			break;
		case MAK_LEFT:
			if(currentSelectedKey!=NULL){
				if(currentKeyPosition > 0){
					currentKeyPosition = currentKeyPosition - 1;
					for(int i = currentKeyPosition; i >= 0;i--){
						if(((Button *)currentSoftKeys->getChildren()[i])->isSelectable()){
							currentSelectedKey->setSelected(false);
							currentKeyPosition=i;
							currentSelectedKey= currentSoftKeys->getChildren()[i];
							currentSelectedKey->setSelected(true);
							break;
						}
					}
				}
			}
			break;
		case MAK_RIGHT:
			if(currentSelectedKey!=NULL){
				if(currentKeyPosition+1 < currentSelectedKey->getParent()->getChildren().size()){
					currentKeyPosition = currentKeyPosition + 1;
					for(int i = currentKeyPosition; i < currentSoftKeys->getChildren().size();i++){
						if(((Button *)currentSoftKeys->getChildren()[i])->isSelectable()){
							currentSelectedKey->setSelected(false);
							currentKeyPosition=i;
							currentSelectedKey= currentSoftKeys->getChildren()[i];
							currentSelectedKey->setSelected(true);
							break;
						}
					}
				}
			}
			break;
	}
}