void createUI() { // Create screen that holds the WebView. mScreen = maWidgetCreate("Screen"); // Create the WebView. mWebView = createWebView(); // Compose objects. maWidgetAddChild(mScreen, mWebView); // Show the screen. maWidgetScreenShow(mScreen); }
/** * Tests to add and remove children from the layout. */ void testAddAndRemoveChildren() { MAWidgetHandle children[ 10 ]; for(int i = 0; i < NUM_CHILDREN; i++) { children[ i ] = maWidgetCreate( MAW_LABEL ); TESTIFY_ASSERT( children[ i ] >= 0 ); TESTIFY_ASSERT_EQUAL( maWidgetAddChild( getTestWidgetHandle( ), children[ i ] ), MAW_RES_OK ); } for(int i = 0; i < NUM_CHILDREN; i++) { TESTIFY_ASSERT_EQUAL( maWidgetRemoveChild( children[ i ] ), MAW_RES_OK ); TESTIFY_ASSERT_EQUAL( maWidgetDestroy( children[ i ] ), MAW_RES_OK ); } }
/** * Lay out the widgets (portrait mode). */ void WebScreen::setupUI() { // Get the handle to the main layout and the screen. mMainLayout = getMainLayout(); mScreen = getScreen(); mLabel = getTopLabel(); mBackButton = getTopButtonLeft(); mNewSearchButton = getTopButtonRight(); setButtonText(mBackButton, " BACK "); setButtonText(mNewSearchButton, "New Search"); // Add the web view that contains the article. // It will be filled when this screen is displayed, // based on the checked titles from TitlesScreen. mWebView = createWebView( MAW_CONSTANT_FILL_AVAILABLE_SPACE, MAW_CONSTANT_FILL_AVAILABLE_SPACE); maWidgetAddChild(mMainLayout, mWebView); }
/** * Lay out the widgets (portrait mode). */ void SummaryScreen::setupUI() { // Get the handle to the main layout and the screen. mMainLayout = getMainLayout(); mScreen = getScreen(); mLabel = getTopLabel(); mHomeButton = getTopButtonRight(); mBackButton = getTopButtonLeft(); // Set the text for the widget in the top layout: the label and button. setButtonText(mBackButton, " BACK "); setButtonText(mHomeButton, " New Search "); // Add the list view that will contain the snippets. // It will be filled when this screen is displayed, based on the checked // titles from TitlesScreen. // The height is ScreenHeight - the size of the top layout. mListView = createListView(mScreenWidth, 7*mScreenHeight/8); maWidgetAddChild(mMainLayout, mListView); }
/** * Creates the required view and components */ void SettingsScreen::createUI() { // Create a Native UI screen. As the screen is a member // variable (also called instance variable) we have // prefixed the variable name with "m". mScreen = maWidgetCreate(MAW_SCREEN); // Create the screen's main layout widget. mMainLayoutWidget = maWidgetCreate(MAW_VERTICAL_LAYOUT); // Make the layout fill the entire screen. For properties that // take an integer parameter we use the widgetSetPropertyInt // function, for properties that takes a string parameter // we use the maWidgetSetProperty function. widgetSetPropertyInt( mMainLayoutWidget, MAW_WIDGET_WIDTH, MAW_CONSTANT_FILL_AVAILABLE_SPACE); widgetSetPropertyInt( mMainLayoutWidget, MAW_WIDGET_HEIGHT, MAW_CONSTANT_FILL_AVAILABLE_SPACE); // Add the layout as the root of the screen's widget tree. maWidgetAddChild(mScreen, mMainLayoutWidget); mFlashModeButton = maWidgetCreate(MAW_BUTTON); widgetSetPropertyInt( mFlashModeButton, MAW_WIDGET_WIDTH, MAW_CONSTANT_FILL_AVAILABLE_SPACE); widgetSetPropertyInt( mFlashModeButton, MAW_WIDGET_HEIGHT, MAW_CONSTANT_WRAP_CONTENT); maWidgetSetProperty( mFlashModeButton, MAW_LABEL_TEXT, "Flash Mode: OFF"); maWidgetAddChild(mMainLayoutWidget, mFlashModeButton); mSwapCameraButton = maWidgetCreate(MAW_BUTTON); widgetSetPropertyInt( mSwapCameraButton, MAW_WIDGET_WIDTH, MAW_CONSTANT_FILL_AVAILABLE_SPACE); widgetSetPropertyInt( mSwapCameraButton, MAW_WIDGET_HEIGHT, MAW_CONSTANT_WRAP_CONTENT); maWidgetSetProperty( mSwapCameraButton, MAW_LABEL_TEXT, "Camera Selected: Back"); maWidgetAddChild(mMainLayoutWidget, mSwapCameraButton); //Only enable switch camera buttons if we have more than one camera if(numCameras == 1) { maWidgetSetProperty(mSwapCameraButton, MAW_WIDGET_ENABLED, "false"); } //If the phone does not support flash disable the flash button if(flashSupported == false) { maWidgetSetProperty(mFlashModeButton, MAW_WIDGET_ENABLED, "false"); } //The button that finishes the setting operation mOKButton = maWidgetCreate(MAW_BUTTON); widgetSetPropertyInt( mOKButton, MAW_WIDGET_WIDTH, MAW_CONSTANT_FILL_AVAILABLE_SPACE); widgetSetPropertyInt( mOKButton, MAW_WIDGET_HEIGHT, MAW_CONSTANT_WRAP_CONTENT); maWidgetSetProperty( mOKButton, MAW_LABEL_TEXT, "Back to Main Screen"); maWidgetAddChild(mMainLayoutWidget, mOKButton); }
/** * Lay out the widgets (portrait mode). */ void HomeScreen::setupUI() { // Get the handle to the main layout and the screen. mMainLayout = getMainLayout(); mScreen = getScreen(); mLabel = getTopLabel(); mSearchButton = getTopButtonRight(); // We do not need a Back button in this screen, // so we can dismiss it. MAWidgetHandle backBtn = getTopButtonLeft(); maWidgetDestroy(backBtn); // The creation of the main layout is already done in the base class // constructor, called at derived object creation. // So, we can use a handle for the main layout at any point. // Set the text for the button widget in the top layout. setButtonText(mSearchButton, " NEXT "); // Add a label before the Progress bar. mProgressLabel = createLabel( mScreenWidth, " Please wait...", DARK_GREY, mFontSize ); // Show it only after Search is pressed. maWidgetSetProperty(mProgressLabel,MAW_WIDGET_VISIBLE, "false"); maWidgetAddChild(mMainLayout, mProgressLabel); // Create a progress bar for the Search action. mProgressBar = createProgressBar(); // Set the range of the progress bar from 0..100 setWidgetProperty( mProgressBar, MAW_PROGRESS_BAR_MAX, PROGRESS_BAR_MAX_VALUE); // Set the progress value to 0. setWidgetProperty( mProgressBar, MAW_PROGRESS_BAR_PROGRESS, 0); // Hide the widget at first, and display it when a Search is being performed. maWidgetSetProperty( mProgressBar, MAW_WIDGET_VISIBLE, "false"); maWidgetAddChild(mMainLayout, mProgressBar); // Next, fill the remaining space with an edit box and // some check boxes for the categories. MAWidgetHandle hintLabel = createLabel( mScreenWidth, MESSAGE_EDITBOX_HINT.c_str(), BLUE, mFontSize); maWidgetSetProperty( hintLabel,MAW_LABEL_TEXT_HORIZONTAL_ALIGNMENT,MAW_ALIGNMENT_LEFT); maWidgetAddChild(mMainLayout, hintLabel); // Add only one edit box. mEditBox = createEditBox(mScreenWidth, MAW_CONSTANT_WRAP_CONTENT); maWidgetAddChild(mMainLayout, mEditBox); // Add a small spacer before the categories. maWidgetAddChild(mMainLayout, createSpacer(mScreenWidth, mPaddingSize)); // Add the layout with checkable categories. maWidgetAddChild( mMainLayout, createCategoriesLayout()); // Add a label for the slider. MAWidgetHandle sliderLabel = createLabel( mScreenWidth, " Please select the results limit. ", BLUE,mFontSize); maWidgetAddChild(mMainLayout, sliderLabel); // Create a slider control for selecting the desired number of results. mSlider = createSlider(); setWidgetProperty(mSlider, MAW_SLIDER_MAX, SLIDER_MAX_VALUE); // Set the current slider value to 10. setWidgetProperty(mSlider, MAW_SLIDER_VALUE, 10); maWidgetAddChild(mMainLayout, mSlider); // Add two labels with minimum and maximum value of the slider. MAWidgetHandle valuesLayout = maWidgetCreate(MAW_HORIZONTAL_LAYOUT); MAWidgetHandle minValue = createLabel( mScreenWidth / 2, " 0 ", DARK_GREY, mFontSize); maWidgetSetProperty(minValue, MAW_LABEL_TEXT_HORIZONTAL_ALIGNMENT, MAW_ALIGNMENT_LEFT); maWidgetAddChild(valuesLayout, minValue); MAWidgetHandle maxValue = createLabel( mScreenWidth / 2, "", DARK_GREY, mFontSize); setWidgetProperty(maxValue, MAW_LABEL_TEXT, SLIDER_MAX_VALUE); maWidgetSetProperty(maxValue, MAW_LABEL_TEXT_HORIZONTAL_ALIGNMENT, MAW_ALIGNMENT_RIGHT); maWidgetAddChild(valuesLayout, maxValue); // Add this layout to the main one. maWidgetAddChild(mMainLayout, valuesLayout); }
/** * Create the layout with checkable categories. * It is parented by the main layout. * For the moment, there are only 6 available categories. * ( These could be expanded also by new user categories.) * @return The layout that contains the categories. */ MAWidgetHandle HomeScreen::createCategoriesLayout() { // Add a layout for categories. MAWidgetHandle categoriesLayout = maWidgetCreate(MAW_VERTICAL_LAYOUT); // Set layout's size. setWidgetSize( categoriesLayout, MAW_CONSTANT_FILL_AVAILABLE_SPACE, mScreenHeight/3); //or MAW_CONSTANT_WRAP_CONTENT // Add a horizontal line. MAWidgetHandle line1 = createSpacer(mScreenWidth,BREAKLINE_HEIGHT); setWidgetProperty( line1, MAW_WIDGET_BACKGROUND_COLOR, DARK_GREY, 16); MAWidgetHandle label = createLabel( MAW_CONSTANT_FILL_AVAILABLE_SPACE, " Categories ", BLUE, mFontSize); maWidgetSetProperty( label, MAW_LABEL_TEXT_HORIZONTAL_ALIGNMENT, MAW_ALIGNMENT_LEFT); maWidgetAddChild(categoriesLayout, label); // Add another horizontal line. MAWidgetHandle line2 = createSpacer(mScreenWidth,BREAKLINE_HEIGHT); setWidgetProperty(line2, MAW_WIDGET_BACKGROUND_COLOR, DARK_GREY, 16); maWidgetAddChild(categoriesLayout, line2); // Available categories: // All ( enabled by default), Nature, Sports, Movies, News, Science. mCategoriesStrings.clear(); mCategoriesStrings.add(CATEGORY_ALL); mCategoriesStrings.add(CATEGORY_NATURE); mCategoriesStrings.add(CATEGORY_SPORTS); mCategoriesStrings.add(CATEGORY_NEWS); mCategoriesStrings.add(CATEGORY_MOVIES); mCategoriesStrings.add(CATEGORY_SCIENCE); setWidgetProperty( categoriesLayout, MAW_WIDGET_BACKGROUND_COLOR, DARK_WHITE, 16); int index(-1); // Each category has a check box and label. for (int i=0; i < mCategoriesStrings.size() / 2; i++) { // Arrange 2 categories per row. MAWidgetHandle categoryLayout = maWidgetCreate(MAW_HORIZONTAL_LAYOUT); // Set layout's size. setWidgetSize( categoryLayout,mScreenWidth, MAW_CONSTANT_FILL_AVAILABLE_SPACE); MAWidgetHandle checkBox1 = createCheckBox(); // By default, the first category (All) is checked, // so all of them are checked also. maWidgetSetProperty(checkBox1,MAW_CHECK_BOX_CHECKED,"true"); // We hold the array of check boxes, so we can construct // the request url based on the chosen categories. mCategoryBoxes.add(checkBox1); maWidgetAddChild(categoryLayout, checkBox1); index++; MAWidgetHandle label1 = createLabel( MAW_CONSTANT_FILL_AVAILABLE_SPACE, mCategoriesStrings[index].c_str(), BLUE, mFontSize ); // Arrange the text to the left. maWidgetSetProperty( label1, MAW_LABEL_TEXT_HORIZONTAL_ALIGNMENT, MAW_ALIGNMENT_LEFT); maWidgetAddChild(categoryLayout, label1); // Add another check box & label, on the same row. MAWidgetHandle checkBox2 = createCheckBox(); // By default, the first category (All) is checked, // so all of them are checked also. maWidgetSetProperty(checkBox2,MAW_CHECK_BOX_CHECKED,"true"); // We hold the array of check boxes, so we can construct // the request url based on the chosen categories. mCategoryBoxes.add(checkBox2); maWidgetAddChild(categoryLayout, checkBox2); index++; MAWidgetHandle label2 = createLabel( MAW_CONSTANT_FILL_AVAILABLE_SPACE, mCategoriesStrings[index].c_str(), BLUE, mFontSize ); // Arrange the text to the left. maWidgetSetProperty( label2, MAW_LABEL_TEXT_HORIZONTAL_ALIGNMENT, MAW_ALIGNMENT_LEFT); maWidgetAddChild(categoryLayout, label2); // Add this layout to the main vertical layout. maWidgetAddChild(categoriesLayout, categoryLayout); } // Add another horizontal line. MAWidgetHandle line3 = createSpacer(mScreenWidth,BREAKLINE_HEIGHT); setWidgetProperty(line3, MAW_WIDGET_BACKGROUND_COLOR, DARK_GREY, 16); maWidgetAddChild(categoriesLayout, line3); return categoriesLayout; }
/** * Create all the widgets in the UI. * The start button, count down label, flickering label, * weapon buttons, rival weapon, spacer, score label, * exit button. */ MAWidgetHandle NativeScreen::createMainLayout() { // Create the main layout (the main widget that holds the other widgets). MAWidgetHandle mainLayout = maWidgetCreate(MAW_VERTICAL_LAYOUT); // Set the size for this widget. setWidgetProperty(mainLayout, MAW_WIDGET_WIDTH, MAW_CONSTANT_FILL_AVAILABLE_SPACE); setWidgetProperty(mainLayout, MAW_WIDGET_HEIGHT, MAW_CONSTANT_FILL_AVAILABLE_SPACE); // All the child widgets of the mainLayout will be centered. maWidgetSetProperty( mainLayout, MAW_VERTICAL_LAYOUT_CHILD_HORIZONTAL_ALIGNMENT, MAW_ALIGNMENT_CENTER); maWidgetSetProperty( mainLayout, MAW_VERTICAL_LAYOUT_CHILD_VERTICAL_ALIGNMENT, MAW_ALIGNMENT_CENTER); // Set a background color for the main layout. setWidgetProperty(mainLayout, MAW_WIDGET_BACKGROUND_COLOR, SEA_GREEN, 16); // Add some space before the list view. maWidgetAddChild( mainLayout, createSpacer(mScreenWidth, 10, BLUE)); mLabel = maWidgetCreate(MAW_LABEL); setLabelText(mLabel, "No image selected"); maWidgetAddChild(mainLayout, mLabel); mButton = createButton("Select image", MAW_CONSTANT_WRAP_CONTENT, MAW_CONSTANT_WRAP_CONTENT); maWidgetAddChild(mainLayout, mButton); // we need to create the event return type setting ui mEventReturnTypeHorizontalLayout = maWidgetCreate(MAW_HORIZONTAL_LAYOUT); char buffer[BUF_SIZE]; sprintf(buffer, "%d", MAW_CONSTANT_FILL_AVAILABLE_SPACE); maWidgetSetProperty(mEventReturnTypeHorizontalLayout, MAW_WIDGET_WIDTH, buffer); mEventReturnTypeCheckbox = maWidgetCreate(MAW_CHECK_BOX); maWidgetSetProperty(mEventReturnTypeCheckbox, MAW_CHECK_BOX_CHECKED, "false"); mEventReturnTypeLabel = maWidgetCreate(MAW_LABEL); maWidgetSetProperty(mEventReturnTypeLabel, MAW_LABEL_TEXT, "Return image data with the event"); maWidgetAddChild(mEventReturnTypeHorizontalLayout, mEventReturnTypeCheckbox); maWidgetAddChild(mEventReturnTypeHorizontalLayout, mEventReturnTypeLabel); maWidgetAddChild(mainLayout, mEventReturnTypeHorizontalLayout); mPreview = maWidgetCreate(MAW_IMAGE); maWidgetSetProperty(mPreview, MAW_WIDGET_WIDTH, "-1"); maWidgetSetProperty(mPreview, MAW_WIDGET_HEIGHT, "-1"); // char buffer[256]; // sprintf(buffer, "%d", RES_IMAGE_START); // maWidgetSetProperty(mPreview, MAW_IMAGE_IMAGE, buffer); maWidgetSetProperty(mPreview, MAW_IMAGE_SCALE_MODE, "scalePreserveAspect"); maWidgetAddChild(mainLayout, mPreview); maWidgetAddChild( mainLayout, createSpacer(mScreenWidth, mScreenHeight/50, BLUE)); // Exit button in a horizontal layout. MAWidgetHandle bottomMenu = maWidgetCreate(MAW_HORIZONTAL_LAYOUT); setWidgetProperty(bottomMenu, MAW_WIDGET_WIDTH, mScreenWidth); setWidgetProperty(bottomMenu, MAW_WIDGET_HEIGHT, MAW_CONSTANT_FILL_AVAILABLE_SPACE); // Set the bottom button to half the available width. mExitButton = createButton(" Exit ", mScreenWidth/2, MAW_CONSTANT_WRAP_CONTENT ); maWidgetSetProperty(mExitButton, MAW_WIDGET_BACKGROUND_GRADIENT, "0xC1FFC1,0x9BCD9B"); maWidgetAddChild(bottomMenu,mExitButton); maWidgetAddChild(mainLayout,bottomMenu); return mainLayout; }
//First, the constructor, which will be called whenever we need an //instance of AppScreen. AppScreen() { //Make the AppScreen listen for events coming from widgets. MAUtil::Environment::getEnvironment().addCustomEventListener(this); //Create a Native UI screen using the IOCTL function maWidgetCreate. mScreen = maWidgetCreate(MAW_SCREEN); //Check if this is supported on the device it's running on if(mScreen == IOCTL_UNAVAILABLE) { maPanic(0,"Sorry but this program does not run currently on this platform"); } //Create the screen's main layout widget. As it is a member variable //we give its name an "m" prefix. mMainLayoutWidget = maWidgetCreate(MAW_VERTICAL_LAYOUT); maWidgetSetProperty(mMainLayoutWidget, MAW_WIDGET_WIDTH, "-1"); maWidgetSetProperty(mMainLayoutWidget, MAW_WIDGET_HEIGHT, "-1"); //Identify the main layout widget as root of the screen's widget tree. maWidgetAddChild(mScreen, mMainLayoutWidget); //Now we create four child widgets within the main layout widget. //The first widget is a label that we'll use to present instructions. //We set its width and height, and we initialize it with some text. //Finally we locate it inside the screen widget. mInstructions = maWidgetCreate(MAW_LABEL); maWidgetSetProperty(mInstructions, MAW_WIDGET_WIDTH, "-1"); maWidgetSetProperty(mInstructions, MAW_WIDGET_HEIGHT, "-2"); maWidgetSetProperty(mInstructions, MAW_LABEL_TEXT, "Enter a password:"******"-1"); maWidgetSetProperty(mPasswordBox, MAW_WIDGET_HEIGHT, "-2"); maWidgetSetProperty(mPasswordBox, "editMode", "password"); maWidgetAddChild(mMainLayoutWidget, mPasswordBox); //The third and fourth widgets are labels that we will use as buttons. //We centre the text vertically and horizontally within the buttons. mClearButton = maWidgetCreate(MAW_BUTTON); maWidgetSetProperty(mClearButton, MAW_WIDGET_WIDTH, "-1"); maWidgetSetProperty(mClearButton, MAW_WIDGET_HEIGHT, "-2"); maWidgetSetProperty(mClearButton, MAW_BUTTON_TEXT_VERTICAL_ALIGNMENT, "center"); maWidgetSetProperty(mClearButton, MAW_BUTTON_TEXT_HORIZONTAL_ALIGNMENT, "center"); maWidgetSetProperty(mClearButton, MAW_BUTTON_TEXT, "Clear"); maWidgetAddChild(mMainLayoutWidget, mClearButton); mSubmitButton = maWidgetCreate(MAW_BUTTON); maWidgetSetProperty(mSubmitButton, MAW_WIDGET_WIDTH, "-1"); maWidgetSetProperty(mSubmitButton, MAW_WIDGET_HEIGHT, "-2"); maWidgetSetProperty(mSubmitButton, MAW_BUTTON_TEXT_VERTICAL_ALIGNMENT, "center"); maWidgetSetProperty(mSubmitButton, MAW_BUTTON_TEXT_HORIZONTAL_ALIGNMENT, "center"); maWidgetSetProperty(mSubmitButton, MAW_BUTTON_TEXT, "Submit"); maWidgetAddChild(mMainLayoutWidget, mSubmitButton); //That's the constructor finished. }
/** * 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; }
/** * Fill the list box with data provided by the engine. */ void TitleScreen::fillListBox() { // Clear previous entries. mCheckBoxes.clear(); mTitleLabels.clear(); mTitles.clear(); mSnippets.clear(); mTitles = mWiki->getAllTitles(); mSnippets = mWiki->getAllSnippets(); // Destroy the list view, and recreate it. if ( mListView != -1){ maWidgetDestroy(mListView); } mListView = createListView(mScreenWidth, MAW_CONSTANT_FILL_AVAILABLE_SPACE); maWidgetAddChild(mMainLayout, mListView); // Add a Select/Deselect All button. MAWidgetHandle selectAllLayout = maWidgetCreate(MAW_HORIZONTAL_LAYOUT); // Set layout's size. setWidgetSize( selectAllLayout, mScreenWidth, MAW_CONSTANT_FILL_AVAILABLE_SPACE); mSelectAll = createCheckBox(); // All titles are deselected by default. maWidgetSetProperty(mSelectAll, MAW_CHECK_BOX_CHECKED, "false"); maWidgetAddChild(selectAllLayout, mSelectAll); MAWidgetHandle labelSelectAll = createLabel( MAW_CONSTANT_FILL_AVAILABLE_SPACE, MESSAGE_SELECT_ALL.c_str(), DARK_GREY, mFontSize ); mTitleLabels.add(labelSelectAll); maWidgetAddChild(selectAllLayout, labelSelectAll); maWidgetAddChild(mListView,selectAllLayout); // Update the UI. for (int i=0; i < mTitles.size(); i++) { // Add results in a horizontal layout. MAWidgetHandle layout = maWidgetCreate(MAW_HORIZONTAL_LAYOUT); setWidgetSize(layout, mScreenWidth, MAW_CONSTANT_FILL_AVAILABLE_SPACE); MAWidgetHandle checkbox = createCheckBox(); mCheckBoxes.add(checkbox); maWidgetAddChild(layout, mCheckBoxes[i]); MAWidgetHandle label = createLabel( MAW_CONSTANT_FILL_AVAILABLE_SPACE, mTitles[i].c_str(), BLUE, mFontSize); mTitleLabels.add(label); maWidgetAddChild(layout, label); setWidgetProperty(layout, MAW_WIDGET_BACKGROUND_COLOR, DARK_WHITE, 16); maWidgetAddChild(mListView,layout); } }
/** * In the constructor we create the user interface. */ SineRunnerMoblet() : mGLViewInitialized(false) { // Create a screen widget that will hold the OpenGL view. int screen = maWidgetCreate(MAW_SCREEN); MAExtent screenSize = maGetScrSize(); mXRes = EXTENT_X(screenSize); mYRes = EXTENT_Y(screenSize); mTime = 0; mX = mY = 0.0; mCPosStart = -100.0; mCPos = mCPosStart; //behind the front of the curve mCYPos = 0.0; mMaxPoint = 0.0; mHit = false; mHitTimes = 0; mScreenIsPressed = false; mNumTicks = 0; inAir = false; mDead = false; mFinished = false; // Check if NativeUI is supported by the runtime platform. // For example, MoRE does not support NativeUI at the time // of writing this program. if (IOCTL_UNAVAILABLE == screen) { maPanic(0, "NativeUI is not available."); } // Create a GL_VIEW widget and add it to the screen. // widgetSetPropertyInt is a helper function defined // in WidgetUtil.cpp. mGLView = maWidgetCreate(MAW_GL_VIEW); if (MAW_RES_INVALID_TYPE_NAME == mGLView) { maPanic(1, "OpenGL|ES unavailable. OpenGL|ES is only available on Android and iOS. Also, please check that the device is able to run the version of OpenGL|ES you requested."); } widgetSetPropertyInt( mGLView, MAW_WIDGET_WIDTH, MAW_CONSTANT_FILL_AVAILABLE_SPACE); widgetSetPropertyInt( mGLView, MAW_WIDGET_HEIGHT, MAW_CONSTANT_FILL_AVAILABLE_SPACE); maWidgetAddChild(screen, mGLView); // Show the screen. maWidgetScreenShow(screen); // Make the Moblet listen to custom events, so that we // know when the GLView widget is ready to be drawn. MAUtil::Environment::getEnvironment().addCustomEventListener(this); }