/** * 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; }
/** * 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 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 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 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; }
/** * 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 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; }
/** * 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; }
/** * 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; }
/** * Notify the screen about wiki engine status * when finished, next screen can be displayed. */ void HomeScreen::engineFinished() { // Unregister from key listener. MAUtil::Environment::getEnvironment().removeKeyListener(this); // Set the progress bar to it's max value. setWidgetProperty( mProgressBar,MAW_PROGRESS_BAR_PROGRESS, PROGRESS_BAR_MAX_VALUE); // Show next screen: the one with all the available titles and // check boxes for each one. // And refresh the list view that contains those values. mTitlesScreen->showScreen(true); }
/** * 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]); } }
/** * Engine notifies this screen that a new chunk of data is received. * At each step, the progress value is incremented. */ void HomeScreen::engineChunkReceived() { int incrementBy = PROGRESS_BAR_MAX_VALUE/mSteps; setWidgetProperty( mProgressBar, MAW_PROGRESS_BAR_INCREMENT_PROGRESS, incrementBy); }
/** * 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); } }
/** * 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; }
/** * 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 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; }