int createOpenGLScreen(int& openglView) { int screen = maWidgetCreate( "Screen" ); maWidgetSetProperty( screen, "title", "OpenGL" ); openglView = maWidgetCreate( "GLView" ); maWidgetAddChild( screen, openglView ); return screen; }
/** * Tests to insert an element at a bad index. */ void testBadInsert() { int listView = maWidgetCreate( MAW_LIST_VIEW ); TESTIFY_ASSERT( listView > 0 ); int firstChild = maWidgetCreate( MAW_LABEL ); TESTIFY_ASSERT( firstChild > 0 ); TESTIFY_ASSERT_EQUAL( maWidgetInsertChild( listView, firstChild, -515 ), MAW_RES_INVALID_INDEX ); maWidgetDestroy( listView ); }
/** * Tests to insert an element at the end of a list. */ void testInsertLast() { int listView = maWidgetCreate( MAW_LIST_VIEW ); TESTIFY_ASSERT( listView > 0 ); int firstChild = maWidgetCreate( MAW_LABEL ); TESTIFY_ASSERT( firstChild > 0 ); TESTIFY_ASSERT_EQUAL( maWidgetInsertChild( listView, firstChild, 0 ), MAW_RES_OK ); int secondChild = maWidgetCreate( MAW_LABEL ); TESTIFY_ASSERT( secondChild > 0 ); TESTIFY_ASSERT_EQUAL( maWidgetInsertChild( listView, secondChild, -1 ), MAW_RES_OK ); maWidgetDestroy( listView ); }
/** * Creates a button with centered text by default, * font size is 20, and color is DARK GREY. * @param text The button text. * @return Handle to the new button. */ MAWidgetHandle NativeScreen::createButton(const char* text, int width, int height) { // Create button. MAWidgetHandle button = maWidgetCreate(MAW_BUTTON); // Set text and text alignment. maWidgetSetProperty(button, MAW_BUTTON_TEXT, text); maWidgetSetProperty(button, MAW_BUTTON_TEXT_VERTICAL_ALIGNMENT, "center"); maWidgetSetProperty(button, MAW_BUTTON_TEXT_HORIZONTAL_ALIGNMENT, "center"); setWidgetProperty(button, MAW_WIDGET_WIDTH, width); setWidgetProperty(button, MAW_WIDGET_HEIGHT, height); // Set font color. setWidgetProperty(button, MAW_BUTTON_FONT_COLOR, BLUE, 16); // setWidgetProperty(button, MAW_WIDGET_BACKGROUND_COLOR, DARK_SEA_GREEN, 16); // maWidgetSetProperty(button,"Gradient", " "); // Set font size to small. // setWidgetProperty(button, MAW_BUTTON_FONT_SIZE, mFontRegularSize); return button; }
/** * Utility function to create a label. * The height of the label is computed automatically. * @param width Label width. * @param fontColor Text color. * @param fontSize Text size. * @param text Label text. * @return Handle to the new label. */ MAWidgetHandle NativeScreen::createLabel( int width, int fontColor, int fontSize, const char* text) { // Create the label. MAWidgetHandle label = maWidgetCreate(MAW_LABEL); // Set the label font color. setWidgetProperty(label, MAW_LABEL_FONT_COLOR, fontColor, 16); // Set the label font size. setWidgetProperty(label, MAW_LABEL_FONT_SIZE, fontSize); // Set the widget size. setWidgetProperty(label, MAW_WIDGET_WIDTH, width); setWidgetProperty(label, MAW_WIDGET_HEIGHT, MAW_CONSTANT_WRAP_CONTENT); // Set the label text. maWidgetSetProperty(label, MAW_LABEL_TEXT, text); // Set text alignment. maWidgetSetProperty(label, MAW_LABEL_TEXT_VERTICAL_ALIGNMENT, "center"); maWidgetSetProperty(label, MAW_LABEL_TEXT_HORIZONTAL_ALIGNMENT, "center"); return label; }
/** * Constructor is protected because actual widget instances * should be subclasses of this class. * @widgetType The string constant that identifies the widget type * (one of the MAW_ constants). */ Widget::Widget(const MAUtil::String& widgetType) : mWidgetManager(WidgetManager::getInstance()), mWidgetEventListener(NULL) { mWidgetHandle = maWidgetCreate(widgetType.c_str()); mWidgetManager->registerWidget(mWidgetHandle, this); }
/** * Utility function to create a label. * The height of the label is computed automatically. * @param width Label width. * @param text Label text. * @param fontColor Text color. * @param fontSize Text size. * * @return Handle to the new label. */ MAWidgetHandle createLabel(int width, const char* text, int fontColor, int fontSize) { MAWidgetHandle label = maWidgetCreate(MAW_LABEL); // Set the label font color. setWidgetProperty(label, MAW_LABEL_FONT_COLOR, fontColor, 16); // Set the label font size. setWidgetProperty(label, MAW_LABEL_FONT_SIZE, fontSize); // Set the widget size. setWidgetProperty(label, MAW_WIDGET_WIDTH, width); setWidgetProperty(label, MAW_WIDGET_HEIGHT, MAW_CONSTANT_WRAP_CONTENT); // Set the label text. maWidgetSetProperty(label, MAW_LABEL_TEXT, text); maWidgetSetProperty( label, MAW_LABEL_TEXT_VERTICAL_ALIGNMENT, MAW_ALIGNMENT_CENTER); maWidgetSetProperty( label, MAW_LABEL_TEXT_HORIZONTAL_ALIGNMENT, MAW_ALIGNMENT_CENTER); return label; }
/** * The purpose of this test is to test the creation and destruction * of a screen. */ void createWidget(const char *type) { int widgetHandle = maWidgetCreate( type ); TESTIFY_ASSERT_NOT_EQUAL( widgetHandle, MAW_RES_INVALID_TYPE_NAME ); TESTIFY_ASSERT( widgetHandle >= 0 ); int destroyStatus = maWidgetDestroy( widgetHandle ); TESTIFY_ASSERT_EQUAL( destroyStatus, MAW_RES_OK ); }
/** * Utility function to create a web view. * @param width Web view width. * @param height Web view height. * @return Handle to the new web view. */ MAWidgetHandle createWebView(int width, int height) { MAWidgetHandle webView = maWidgetCreate(MAW_WEB_VIEW); // Set the size for this widget. setWidgetProperty(webView, MAW_WIDGET_WIDTH, width); setWidgetProperty(webView, MAW_WIDGET_HEIGHT, height); return webView; }
/** * Utility function to create an edit box. * @param width Edit box width. * @param height Edit box height. * @return Handle to the new edit box. */ MAWidgetHandle createEditBox(int width, int height) { MAWidgetHandle editBox = maWidgetCreate(MAW_EDIT_BOX); // Set the size for this edit box. setWidgetProperty(editBox, MAW_WIDGET_WIDTH, width); setWidgetProperty(editBox, MAW_WIDGET_HEIGHT, height); return editBox; }
/** * Utility function to create a list view. * @param width List View width. * @param height List View height. * @return Handle to the new list view. */ MAWidgetHandle createListView(int width, int height) { MAWidgetHandle listView = maWidgetCreate(MAW_LIST_VIEW); // Set the size for this list view. setWidgetProperty(listView, MAW_WIDGET_WIDTH, width); setWidgetProperty(listView, MAW_WIDGET_HEIGHT, height); return listView; }
/** * Utility function to create a vertical empty "spacer". * @param width Spacer width. * @param height Spacer height. * @return Handle to the new spacer. */ MAWidgetHandle createSpacer(int width, int height) { MAWidgetHandle spacer = maWidgetCreate(MAW_VERTICAL_LAYOUT); // Set the size for this layout. setWidgetProperty(spacer, MAW_WIDGET_WIDTH , width); setWidgetProperty(spacer, MAW_WIDGET_HEIGHT, height); return spacer; }
/** * Utility function to create a slider control. * @return Handle to the new slider. */ MAWidgetHandle createSlider() { MAWidgetHandle slider = maWidgetCreate(MAW_SLIDER); setWidgetProperty( slider, MAW_WIDGET_WIDTH, MAW_CONSTANT_FILL_AVAILABLE_SPACE); setWidgetProperty( slider, MAW_WIDGET_HEIGHT, MAW_CONSTANT_WRAP_CONTENT); return slider; }
/** * Utility function to create a progress bar. * @return Handle to the new progress bar. */ MAWidgetHandle createProgressBar() { MAWidgetHandle progressBar = maWidgetCreate(MAW_PROGRESS_BAR); setWidgetProperty( progressBar, MAW_WIDGET_WIDTH, MAW_CONSTANT_FILL_AVAILABLE_SPACE); setWidgetProperty( progressBar, MAW_WIDGET_HEIGHT, MAW_CONSTANT_WRAP_CONTENT); return progressBar; }
void WidgetTest::testSetUp(void) { // Keep default behavior Testify::TestCase::testSetUp( ); MAWidgetHandle widgetHandle = maWidgetCreate( m_type ); TESTIFY_ASSERT( widgetHandle >= 0 ); m_testWidgetHandle = widgetHandle; }
/** * Fill the list box with data provided by the engine. */ void SummaryScreen::fillListBox() { // Clear previous data. mSnippetLabels.clear(); mSnippets.clear(); // For each snippet we need to know the article title. mSnippets = mWiki->getAllSnippetsWithTitle(); // Destroy the list view, and recreate it. if ( mListView != -1){ maWidgetDestroy(mListView); } mListView = createListView(mScreenWidth, 7*mScreenHeight/8); setWidgetProperty(mListView, MAW_WIDGET_BACKGROUND_COLOR, DARK_WHITE, 16); maWidgetAddChild(mMainLayout, mListView); // If no titles are selected, display a short message. if (mSnippets.size() == 0) { MAWidgetHandle listItem = maWidgetCreate(MAW_LIST_VIEW_ITEM); maWidgetSetProperty( listItem, MAW_LIST_VIEW_ITEM_TEXT, WARNING_NOTHING_SELECTED.c_str() ); maWidgetAddChild(mListView, listItem); } // Update the UI. for (int i=0; i < mSnippets.size(); i++) { MAWidgetHandle listItem = maWidgetCreate(MAW_LIST_VIEW_ITEM); maWidgetSetProperty( listItem, MAW_LIST_VIEW_ITEM_TEXT, mSnippets[i].c_str() ); mSnippetLabels.add(listItem); maWidgetAddChild(mListView,mSnippetLabels[i]); } }
/** * Layout the widgets (portrait mode). */ void NativeScreen::setupUI() { // Create the main screen mScreen = maWidgetCreate(MAW_SCREEN); // Create the main layout. mMainLayout = createMainLayout(); // Add the main layout to the screen maWidgetAddChild(mScreen, mMainLayout); }
/** * Check if NativeUI is supported, panic with a help text * for the user if not. */ static void checkNativeUISupport() { int widget = maWidgetCreate(MAW_WEB_VIEW); if (widget < 0) { maPanic(0, "NativeUI is only available on Android, iOS, and Windows Phone 7."); } else { maWidgetDestroy(widget); } }
/** * Utility function to create a vertical empty "spacer". * @param width Spacer width. * @param height Spacer height. * @param backgroundColor * @return Handle to the new spacer. */ MAWidgetHandle NativeScreen::createSpacer(int width, int height, int backgroundColor) { MAWidgetHandle spacer = maWidgetCreate(MAW_VERTICAL_LAYOUT); // Set the widget size. setWidgetProperty(spacer, MAW_WIDGET_WIDTH, width); setWidgetProperty(spacer, MAW_WIDGET_HEIGHT, height); setWidgetProperty(spacer, MAW_WIDGET_BACKGROUND_COLOR, backgroundColor, 16); return spacer; }
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); }
/** * Utility function to create an image widget with the given resource. * @param imageResource The image resource handle to be used for the widget. * @param width Widget width. * @param height Widget height. * @return Handle to the new image widget. */ MAWidgetHandle NativeScreen::createImageWidget( MAHandle imageResource, int width, int height) { MAWidgetHandle image = maWidgetCreate(MAW_IMAGE); // Set the image. setWidgetProperty(image,MAW_IMAGE_IMAGE, imageResource); // Set the widget sizes. setWidgetProperty(image, MAW_WIDGET_WIDTH, width); setWidgetProperty(image, MAW_WIDGET_HEIGHT, height); return image; }
/** * 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 ); } }
/** * Utility function to create a button. * Create a button with centered text. * By default, font size is 15, and color DARK GREY. * @param text The text for the button. * @param fontColor The font color. * @param fontSize The font size. * @param width The widget width. * @param height The widget height. */ MAWidgetHandle createButton(const char* text, int fontColor, int fontSize, int width, int height) { MAWidgetHandle button = maWidgetCreate(MAW_BUTTON); maWidgetSetProperty(button, MAW_BUTTON_TEXT, text); // Set the widget size. setWidgetProperty(button, MAW_WIDGET_WIDTH, width); setWidgetProperty(button, MAW_WIDGET_HEIGHT, height); maWidgetSetProperty( button, MAW_BUTTON_TEXT_VERTICAL_ALIGNMENT, MAW_ALIGNMENT_CENTER); maWidgetSetProperty( button, MAW_BUTTON_TEXT_HORIZONTAL_ALIGNMENT, MAW_ALIGNMENT_CENTER); setWidgetProperty(button,MAW_BUTTON_FONT_SIZE, fontSize); setWidgetProperty(button,MAW_BUTTON_FONT_COLOR, fontColor, 16); return button; }
MAWidgetHandle createWebView() { // Create the WebView MAWidgetHandle webView = maWidgetCreate("WebView"); // Set size of the WebView to fill the parent. maWidgetSetProperty(webView, "width", "-1"); maWidgetSetProperty(webView, "height", "-1"); // Enable zooming. maWidgetSetProperty(webView, "enableZoom", "true"); // Get the HTML for the page from a resource. MAUtil::String html = Util::createTextFromHandle(INDEX_HTML); // Set the HTML the WebView displays. maWidgetSetProperty(webView, "html", html.c_str()); return webView; }
/** * 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); }
/** * 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; }
//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. }
/** * 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; }