Java Reference
In-Depth Information
This is the programming logic for the widget. First, we create a new
class, helloworld , using similar syntax to the one used for creating a
Java class. All the variables and functions must belong to this class, and
at its beginning we define a few instance fields that can be used by all
methods, as they have class scope:
const int CMD_BACK = 1;
MenuItem BACK = new MenuItem(CMD_BACK, "Back");
We will discuss them shortly. First, let's take a look at the most
important lifecyle methods for a widget class:
void startWidget() {
setMinimizedView(createView("viewMini", getStyle("bg")));
startWidget() is called after the widget is created. It's a signal that
our widget is ready to be displayed in the dashboard and we set the view
for its minimized (not open) state. Here we provide the viewMini view
defined in widget.xml , which displays a label with the widget's name.
The other important method called by the framework is openWidget() :
Shell openWidget() {
Flow view = createView("viewMaxi", getStyle("bg"));
return new Shell(view);
Here we provide a view for the widget when it's opened by the user.
Our implementation creates viewMaxi , as defined in widget.xml ,
using the bg stylesheet class defined in the <stylesheet> element in
the <resources> section. Upon viewMaxi creation, the framework
checks the contents of the XML file, looking for the elements below
'viewMaxi'. In our example, it finds the <script> element, with an ID
of hello . For each <script> below a given view, the framework calls
the createElement() method, which we implement to create the UI
elements for the maximized view of the widget:
Component createElement(String viewName,
String elementName,
Style style,
Object context) {
if (elementName.equals("hello")) {
Search WWH ::

Custom Search