Ejemplo n.º 1
0
/**
 * pushes the settings screen to the device screen
 */
void SettingsScreen::pushSettingsScreen()
{
	isViewed = true;
	maWidgetStackScreenPush(mStackScreen, mScreen);
}
Ejemplo n.º 2
0
 /*
  * Push a screen inside the stack.
  * @param screen The new screen.
  */
 void StackScreen::push(Screen* screen)
 {
     maWidgetStackScreenPush(getWidgetHandle(), screen->getWidgetHandle());
     mStack.add(screen);
 }
Ejemplo n.º 3
0
	/**
	 * Implementation of standard API exposed to JavaScript
	 * This function is used to detect different messages from JavaScript
	 * and call the respective function in MoSync.
	 *
	 * @return true if stream was handled, false if not.
	 */
	bool NativeUIMessageHandler::handleMessage(Wormhole::MessageStream& stream)
	{
		char buffer[1024];
		printf("Getting the next action \n");
		char * action = (char*)stream.getNext();
		printf("action: %s\n", action);
		// Widget Handling Calls
		if(0 == strcmp("maWidgetCreate", action))
		{
			char* widgetType = (char*)stream.getNext();
			char* widgetID = (char*)stream.getNext();
			char* callbackID = (char*)stream.getNext();
			printf("maWidgetCreate: %s, %s, %s\n", widgetType, widgetID, callbackID);
			int numParams = stringToInteger(stream.getNext());

			MAWidgetHandle widget = maWidgetCreate(widgetType);
			if(widget <= 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, widget);
				sendNativeUIError(buffer);
			}
			else
			{
				if(numParams > 0)
				{
					for(int i = 0; i < numParams/2; i++)
					{
						char* property = (char*)stream.getNext();
						char* value = (char*)stream.getNext();
						printf("maWidgetSetProperty %s, %s\n", property, value);
						int res = maWidgetSetProperty(widget, property, value);
						if(res < 0)
						{
							printf("could not set property\n");
						}
						else
						{
							printf("set property done\n");
						}
					}
				}
				//We use a special callback for widget creation
				printf("calling CallBack \n");
				sprintf(
					buffer,
					"mosync.nativeui.createCallback('%s', '%s', %d)",
					callbackID,
					widgetID,
					widget);
				printf("Done creatign the script %s\n", buffer);
				mWebView->callJS(buffer);
				printf("done Calling Callback");
			}

		}
		else if(0 == strcmp("maWidgetDestroy", action))
		{
			MAWidgetHandle widget = stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();

			int res = maWidgetDestroy(widget);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetAddChild", action) )
		{
			MAWidgetHandle parent = stringToInteger(stream.getNext());
			MAWidgetHandle child = stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetAddChild(parent, child);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetInsertChild", action))
		{
			MAWidgetHandle parent = stringToInteger((char*)stream.getNext());
			MAWidgetHandle child = stringToInteger((char*)stream.getNext());
			int index = stringToInteger((char*)stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetInsertChild(parent, child, index);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetRemoveChild", action))
		{
			MAWidgetHandle child = stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();

			int res = maWidgetRemoveChild(child);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetModalDialogShow", action))
		{
			MAWidgetHandle dialogHandle =
				stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetModalDialogShow(dialogHandle);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetModalDialogHide", action))
		{
			MAWidgetHandle dialogHandle =
					stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetModalDialogHide(dialogHandle);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetScreenShow", action))
		{
			MAWidgetHandle screenHandle =
					stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetScreenShow(screenHandle);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetStackScreenPush", action))
		{
			MAWidgetHandle stackScreen =
					stringToInteger(stream.getNext());
			MAWidgetHandle newScreen =
					stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetStackScreenPush(stackScreen, newScreen);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetStackScreenPop", action))
		{
			MAWidgetHandle stackScreen =
					stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetStackScreenPop(stackScreen);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetSetProperty", action))
		{
			MAWidgetHandle widget =
					stringToInteger(stream.getNext());
			char *property = (char*)stream.getNext();
			char *value = (char*)stream.getNext();
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetSetProperty(widget, property, value);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetGetProperty", action))
		{
			char value[1024];
			MAWidgetHandle widget =
					stringToInteger(stream.getNext());
			char* property = (char*)stream.getNext();
			char* callbackID = (char*)stream.getNext();

			int res = maWidgetGetProperty(widget, property, value, 1024);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', '%s', '%s'", callbackID, property, value);
				sendNativeUISuccess(buffer);
			}
		}

		// Tell the WebView that we have processed the stream, so that
		// it can send the next one.

		char replyScript[1024];
		char * mosyncCallBackId = (char*)stream.getNext();
		if(mosyncCallBackId != NULL)
		{
			sprintf(
					replyScript,
					"mosync.bridge.reply(%s)",
					mosyncCallBackId);
			printf("calling general callback %s\n", replyScript);
			mWebView->callJS(replyScript);
		}

		return true;
	}