/** * Pops a screen from a screen stack, hides the current screen and shows * the previous screen. * If there is no previous screen in the screen stack, * an empty screen will be shown. */ void StackScreen::pop() { if (mStack.size() > 0) { maWidgetStackScreenPop(getWidgetHandle()); } }
/** * This method implements a custom event listener. * Widget events are sent as custom events. */ void SettingsScreen::customEvent(const MAEvent& event) { // Check if this is a widget event. if (EVENT_TYPE_WIDGET == event.type) { // Get the widget event data structure. MAWidgetEventData* eventData = (MAWidgetEventData*) event.data; // Here we handle clicked events. if (MAW_EVENT_CLICKED == eventData->eventType) { if(mFlashModeButton == eventData->widgetHandle) { if(flashModeIndex < 3) { flashModeIndex++; } else { flashModeIndex = 0; } char buffer[128]; sprintf(buffer, "Flash Mode: %s", getModeForIndex(flashModeIndex)); maWidgetSetProperty(mFlashModeButton,MAW_BUTTON_TEXT, buffer); } else if(mSwapCameraButton == eventData->widgetHandle) { if(currentCamera < numCameras-1) { currentCamera++; } else { currentCamera = 0; } if(currentCamera == 0) { maWidgetSetProperty( mSwapCameraButton, MAW_LABEL_TEXT, "Camera Selected: Back"); } else { maWidgetSetProperty( mSwapCameraButton, MAW_LABEL_TEXT, "Camera Selected: Front"); } } else if(mOKButton == eventData->widgetHandle) { isViewed= false; maWidgetStackScreenPop(mStackScreen); } } } }
/** * 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; }