Permalink
Browse files

[PopupDemo] Adding a simple demo that shows how to dynamically popup …

…widgets in a C?? NativeUI app.
  • Loading branch information...
1 parent cd9c42b commit 12bab92d8e6ae86aeeb7130dd52ebc610048fe83 Mikael Kindborg committed Feb 21, 2013
Showing with 307 additions and 0 deletions.
  1. +18 −0 PopupDemo/.cproject
  2. +23 −0 PopupDemo/.mosyncproject
  3. +30 −0 PopupDemo/.project
  4. +2 −0 PopupDemo/.settings/org.eclipse.core.resources.prefs
  5. +234 −0 PopupDemo/main.cpp
View
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?>
+
+<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+ <storageModule moduleId="org.eclipse.cdt.core.settings">
+ <cconfiguration id="org.eclipse.cdt.core.default.config.1062672351">
+ <storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.1062672351" moduleId="org.eclipse.cdt.core.settings" name="Configuration">
+ <externalSettings/>
+ <extensions/>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+ </cconfiguration>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.pathentry">
+ <pathentry kind="con" path="com.mobilesorcery.mosync.includepaths"/>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+</cproject>
View
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project supports-build-configs="true" version="1.5">
+<build.cfg id="Debug" types="Debug"/>
+<build.cfg id="Release" types="Release"/>
+<criteria>
+<filter type="com.mobilesorcery.sdk.capabilities.devices.elementfactory">
+<capabilities optional="" required="NativeUI"/>
+</filter>
+</criteria>
+<properties>
+<property key="build.prefs:additional.libraries" value="MAUtil.lib,nativeui.lib"/>
+<property key="build.prefs:additional.libraries/Debug" value="MAUtilD.lib,nativeuiD.lib"/>
+<property key="build.prefs:app.permissions" value="Camera File\ Storage Internet\ Access Vibration"/>
+<property key="build.prefs:memory.data/Debug" value="4096"/>
+<property key="build.prefs:memory.data/Release" value="4096"/>
+<property key="build.prefs:memory.heap/Debug" value="3072"/>
+<property key="build.prefs:memory.heap/Release" value="3072"/>
+<property key="build.prefs:memory.stack/Debug" value="512"/>
+<property key="build.prefs:memory.stack/Release" value="512"/>
+<property key="profile.mgr.type" value="0"/>
+<property key="template.id" value="project.nativeuicpp"/>
+</properties>
+</project>
View
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>PopupDemo</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.mobilesorcery.sdk.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.mobilesorcery.sdk.core.nature</nature>
+ <nature>org.eclipse.cdt.core.cnature</nature>
+ <nature>org.eclipse.cdt.core.ccnature</nature>
+ </natures>
+ <filteredResources>
+ <filter>
+ <id>0</id>
+ <name></name>
+ <type>6</type>
+ <matcher>
+ <id>org.eclipse.ui.ide.multiFilter</id>
+ <arguments>1.0-name-matches-false-true-.*rebuild.build.cpp</arguments>
+ </matcher>
+ </filter>
+ </filteredResources>
+</projectDescription>
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
View
@@ -0,0 +1,234 @@
+#include <ma.h>
+#include <mavsprintf.h>
+#include <MAUtil/Moblet.h>
+#include <NativeUI/Widgets.h>
+#include <NativeUI/WidgetUtil.h>
+
+using namespace MAUtil;
+using namespace NativeUI;
+
+/**
+ * Class that creates to screen and main layout.
+ * The idea is that by having this as a separate
+ * class, different UI components can be added to
+ * it in a modular way.
+ */
+class MainUI
+{
+public:
+ MainUI()
+ {
+ createUI();
+ }
+
+ void createUI()
+ {
+ // Create a NativeUI screen that will hold layout and widgets.
+ mScreen = new Screen();
+
+ // Create a RelativeLayout to use as the root layout.
+ mLayout = new RelativeLayout();
+
+ // Add the layout to the screen.
+ mScreen->setMainWidget(mLayout);
+ }
+
+ Widget* getMainLayout()
+ {
+ return mLayout;
+ }
+
+ void show()
+ {
+ mScreen->show();
+ }
+
+private:
+ Screen* mScreen;
+ RelativeLayout* mLayout;
+};
+
+/**
+ * Class that contains buttons and
+ * widgets dynamically shown/hidden.
+ */
+class PopupUI : public ButtonListener
+{
+public:
+ /**
+ * The parent is the layout to add widgets to.
+ */
+ PopupUI(Widget* parent)
+ {
+ createUI(parent);
+ }
+
+ void createUI(Widget* parent)
+ {
+ mParent = parent;
+
+ mStaticButton = new Button();
+ mStaticButton->setText("Touch Me To Show Popup");
+ mStaticButton->setTopPosition(50);
+ mStaticButton->setLeftPosition(50);
+ mStaticButton->setHeight(300);
+ mStaticButton->setWidth(300);
+ mStaticButton->setAlpha(1.0);
+ mStaticButton->setBackgroundColor(0x0000FF);
+ mStaticButton->setFontColor(0xFFFFFF);
+ mStaticButton->addButtonListener(this);
+ mParent->addChild(mStaticButton);
+
+ mPopupButton = new Button();
+ mPopupButton->setText("Touch To Hide Me");
+ mPopupButton->setTopPosition(100);
+ mPopupButton->setLeftPosition(300);
+ mPopupButton->setHeight(300);
+ mPopupButton->setWidth(300);
+ mPopupButton->setAlpha(1.0);
+ mPopupButton->setBackgroundColor(0x008800);
+ mPopupButton->setFontColor(0xFFFFFF);
+ mPopupButton->addButtonListener(this);
+ }
+
+ void buttonClicked(Widget* button)
+ {
+ if (button == mStaticButton)
+ {
+ mParent->addChild(mPopupButton);
+ }
+ else
+ if (button == mPopupButton)
+ {
+ mParent->removeChild(mPopupButton);
+ }
+ }
+
+private:
+ Button* mStaticButton;
+ Button* mPopupButton;
+ Widget* mParent;
+};
+
+
+/**
+ * A slightly different Popup UI module.
+ */
+class PopupUI2 : public ButtonListener
+{
+public:
+ /**
+ * The parent is the layout to add widgets to.
+ */
+ PopupUI2(Widget* parent)
+ {
+ createUI(parent);
+ }
+
+ void createUI(Widget* parent)
+ {
+ mParent = parent;
+
+ mPopupIsVisible = false;
+
+ mStaticButton = new Button();
+ mStaticButton->setTopPosition(400);
+ mStaticButton->setLeftPosition(50);
+ mStaticButton->setHeight(300);
+ mStaticButton->setWidth(300);
+ mStaticButton->setAlpha(1.0);
+ mStaticButton->setBackgroundColor(0x0000FF);
+ mStaticButton->setFontColor(0xFFFFFF);
+ mStaticButton->addButtonListener(this);
+ mParent->addChild(mStaticButton);
+ updateStaticButtonText();
+
+ mPopupButton = new Button();
+ mPopupButton->setText("Hello World :)");
+ mPopupButton->setTopPosition(450);
+ mPopupButton->setLeftPosition(300);
+ mPopupButton->setHeight(300);
+ mPopupButton->setWidth(300);
+ mPopupButton->setAlpha(1.0);
+ mPopupButton->setBackgroundColor(0x008800);
+ mPopupButton->setFontColor(0xFFFFFF);
+ mPopupButton->addButtonListener(this);
+ }
+
+ void updateStaticButtonText()
+ {
+ if (mPopupIsVisible)
+ {
+ mStaticButton->setText("Hide Popup");
+ }
+ else
+ {
+ mStaticButton->setText("Show Popup");
+ }
+ }
+
+ void buttonClicked(Widget* button)
+ {
+ if (mPopupIsVisible)
+ {
+ mParent->removeChild(mPopupButton);
+ mPopupIsVisible = false;
+ updateStaticButtonText();
+ }
+ else
+ {
+ mParent->addChild(mPopupButton);
+ mPopupIsVisible = true;
+ updateStaticButtonText();
+ }
+ }
+
+private:
+ Button* mStaticButton;
+ Button* mPopupButton;
+ Widget* mParent;
+ bool mPopupIsVisible;
+};
+
+/**
+ * Simple test application for the popup demo.
+ */
+class PopupDemoMoblet : public Moblet
+{
+public:
+ PopupDemoMoblet()
+ {
+ createUI();
+ }
+
+ void createUI()
+ {
+ // Create and show UI components.
+ mMainUI = new MainUI();
+ mPopupUI = new PopupUI(mMainUI->getMainLayout());
+ mPopupUI2 = new PopupUI2(mMainUI->getMainLayout());
+ mMainUI->show();
+ }
+
+ void keyPressEvent(int keyCode, int nativeCode)
+ {
+ if (MAK_BACK == keyCode || MAK_0 == keyCode)
+ {
+ close();
+ }
+ }
+
+private:
+ MainUI* mMainUI;
+ PopupUI* mPopupUI;
+ PopupUI2* mPopupUI2;
+};
+
+/**
+ * Main function that is called when the program starts.
+ */
+extern "C" int MAMain()
+{
+ Moblet::run(new PopupDemoMoblet());
+ return 0;
+}

0 comments on commit 12bab92

Please sign in to comment.