Widgets

Widgets are visual components that can provide run-time information such as weather or number of unread emails.

In the SmartEyeglass UI architecture, a widget is used as the entry point to your app. The SmartEyeglass SDK allows you to customize the card that represents your app in the main menu, using the WidgetExtension API.

The basics

To start designing you own entry-point card, set up a project using the HelloWidget sample as a base. See more about creating SmartEyeglass projects in the How to create your first SmartEyeglass project tutorial.

You will use the Widget API to create your widget, so the class that extends RegistrationInformation must get the version that supports this functionality:

@Override
public int getRequiredWidgetApiVersion() {
return 3;
}

The HelloWidget project does this. If you don’t use this sample as a base, make sure you do the same.

Define a widget

Extend the WidgetExtension class in order to create your own type of widget.

When a widget is shown on the SmartEyeglass display, the Extension service in the SmartExtension framework calls the onStartRefresh() method. In your class that extends WidgetExtension, override this method to update the screen content to be displayed when the widget is visible.

Your widget can show a bitmap or a custom layout. See the User interface guide for details of how to define screen displays. For example, this simple widget displays a custom layout when it is shown:

class HelloWidget extends WidgetExtension {

    // Create a widget extension.
    public HelloWidget(Context context, String hostAppPackageName) {
        super(context, hostAppPackageName);
    }

    @Override
    public void onStartRefresh() {
        // Send a UI layout when the widget is visible.
        showLayout(R.layout.layout_widget);
    }
}

When a widget is no longer visible, the framework calls the onStopRefresh() callback.

Register your widget

If you define widgets, you must register this fact with the SmartExtension framework. In your class that extends RegistrationInformation, add code to indicate that your extension supports widgets of the size required for the SmartEyeglass display:

@Override
public boolean isWidgetSizeSupported(final int width, final int height) {
    return (height == SmartEyeglassWidgetImage.getSupportedWidgetHeight(mContext) &&
            width == SmartEyeglassWidgetImage.getSupportedWidgetWidth(mContext));
}

Create your widget

The Extension service in the SmartExtensions framework calls createWidgetExtension() to get a widget to display for your entry card in the main menu. In your class that extends ExtensionService, override this method to create and return an instance of the widget you have defined:

@Override
public WidgetExtension createWidgetExtension(String hostAppPackageName) {
    return new HelloWidget(this, hostAppPackageName);
}

Learn from the code example

For the full code example showing how to create a widget that can be placed in the SmartEyeglass main menu, see the HelloWidget project in the SmartEyeglass SDK.

Comments 0

Sort by:

Showing 0 of 0 comments. Show all comments