Beispiel #1
0
	/**
	 * Destructor.
	 */
	Widget::~Widget()
	{
		// If my widget handle is NOT NULL, I set it
		// to NULL in me and all my children, because
		// once the widget handle is destroyed it will
		// destroy all child widgets on the native side.
		MAWidgetHandle widgetHandle = mWidgetHandle;
		if (NULL != widgetHandle)
		{
			markWidgetHandleAsDeleted();
		}

		// Now I recursively delete all my children. They
		// will not destroy their widget handles, because
		// they are set to NULL in the above step.
		for (int i = 0; i < mChildren.size(); ++i)
		{
			delete mChildren[i];
		}

		// If I had a widget handle, it is now destroyed, which
		// also destroys all child widgets on the native side.
		if (NULL != widgetHandle)
		{
			maWidgetDestroy(widgetHandle);
		}
	}
    /**
     * 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 );
    }
Beispiel #3
0
void
WidgetTest::testTearDown(void)
{
	TESTIFY_ASSERT( m_testWidgetHandle >= 0 );
	TESTIFY_ASSERT_EQUAL( maWidgetDestroy( m_testWidgetHandle ), MAW_RES_OK );
	m_testWidgetHandle = -1;

	// Keep default behavior
	Testify::TestCase::testTearDown( );
}
Beispiel #4
0
/**
 * 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 );
}
Beispiel #5
0
	/**
	 * 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);
		}
	}
Beispiel #6
0
/**
 * The destructor deletes the main widget
 * and all of its children.
 */
NativeScreen::~NativeScreen()
{
	// Remove the listener
	MAUtil::Environment::getEnvironment().removeCustomEventListener(this);

	// Delete the main widget, also deletes child widgets.
	maWidgetDestroy(mMainLayout);

	if (mLastDisplayedImageHandle != -1)
	{
		maDestroyPlaceholder(mLastDisplayedImageHandle);
	}
}
Beispiel #7
0
/**
 * 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 );
}
Beispiel #8
0
	/**
	 * 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 );
		}
	}
Beispiel #9
0
/**
 * 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]);
	}
}
Beispiel #10
0
	void destroyUI()
	{
		maWidgetDestroy(mScreen);
	}
Beispiel #11
0
/**
 * 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);
}
Beispiel #12
0
/**
 * The destructor deletes the main widget
 * and all of its children.
 */
NativeScreen::~NativeScreen()
{
	// Delete the main widget, also deletes child widgets.
	maWidgetDestroy(mMainLayout);
}
Beispiel #13
0
	//The last method of the AppScreen class is the destructor, it is used
	//to release the memory used by the native UI widgets. In this case we
	//just need to delete the main widget: all its children will automatically
	//be deleted too.
	~AppScreen()
	{
		maWidgetDestroy(mMainLayoutWidget);
	}
Beispiel #14
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;
	}
Beispiel #15
0
/**
 * 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);
	}
}