SmartEyeglass SDK public abstract class

WidgetExtension

extends java.lang.Object
  1. java.lang.Object
  2. com.sonyericsson.extras.liveware.extension.util.widget.WidgetExtension

Class Overview

The widget extension handles a widget on an accessory. Provides the information needed to register an extension widget. The information is used to populate the Registration.WidgetRegistration table

Summary

Constants
java.lang.String SCHEDULED_REFRESH_INTENT
int WIDGET_WIDTH_SMARTWATCH Widget width in pixels in the original SmartWatch.
int WIDGET_HEIGHT_SMARTWATCH Widget height in pixels in the original SmartWatch.
int NOT_SET
Fields
protected final Context mContext The extension service context.
protected final java.lang.String mHostAppPackageName The host app package name with which the widget is connected.
protected int mInstanceId Widget instance Id.
Public Constructors
WidgetExtension(Context context, java.lang.String hostAppPackageName)

Legacy constructor for widget extension.

Public Methods
final void startRefresh()

Start widget refresh.

final void stopRefresh()

Stop widget refresh.

final void destroy()

Destroy widget.

abstract void onStartRefresh()

Called when widgets starts refreshing and is visible.

abstract void onStopRefresh()

Called when widget stops refreshing and is no longer visible.

void onScheduledRefresh()

Override this method to take action on scheduled refresh.

void onDoAction(int requestCode, Bundle bundle)

When you call the ExtensionService#doActionOnAllWidgets or ExtensionService#doActionOnWidget, this method will be called.

void onDestroy()

Called when a widget is no longer used and is being removed.

void onTouch(int type, int x, int y)

Called when the widget has been touched.

void onObjectClick(int type, int layoutReference)

Called when an object click event has occurred.

Protected Methods
void scheduleRepeatingRefresh(long triggerAtTime, long interval, java.lang.String extensionKey)

Schedule a repeating refresh.

void scheduleRefresh(long triggerAtTime, java.lang.String extensionKey)

Schedule a refresh.

void cancelScheduledRefresh(java.lang.String extensionKey)

Cancel any pending scheduled refresh associated with the extension key.

void sendImageToHostApp(int resourceId)

Show image in the widget.

void sendToHostApp(Intent intent)

Send intent to host application.

void showBitmap(Bitmap bitmap)

Show bitmap in the widget.

void showLayout(int layoutId)

Show a layout in the widget.

void showLayout(int layoutId, Bundle[] layoutData)

Show a layout in the widget.

void showLayout(int layoutId, int noTouchLayoutId, Bundle[] layoutData)

Show a layout in the widget.

void showLayout(int layoutId, int noTouchLayoutId, int offLineLayoutId, Bundle[] layoutData)

Show a layout in the widget.

void sendImage(int layoutReference, int resourceId)

Update an image in a specific layout, in the widget.

void sendText(int layoutReference, java.lang.String text)

Update a TextView in a specific layout, in the widget.

Constants

public static final java.lang.String SCHEDULED_REFRESH_INTENT

Constant Value: "com.sonyericsson.extras.liveware.extension.util.widget.scheduled.refresh"

public static final int WIDGET_WIDTH_SMARTWATCH

Widget width in pixels in the original SmartWatch.

Constant Value: 128 (0x00000080)

public static final int WIDGET_HEIGHT_SMARTWATCH

Widget height in pixels in the original SmartWatch.

Constant Value: 110 (0x0000006e)

public static final int NOT_SET

Constant Value: -1 (0xffffffffffffffff)

Fields

protected final Context mContext

The extension service context.

protected final java.lang.String mHostAppPackageName

The host app package name with which the widget is connected.

protected int mInstanceId

Widget instance Id.

Public Constructors

public WidgetExtension(Context context, java.lang.String hostAppPackageName)

Legacy constructor for widget extension. does not guarantee all values for Widget API 3 are initialised

Parameters
context The context.
hostAppPackageName Package name of host application.

Public Methods

public final void startRefresh()

Start widget refresh.

public final void stopRefresh()

Stop widget refresh.

public final void destroy()

Destroy widget.

public abstract void onStartRefresh()

Called when widgets starts refreshing and is visible.

public abstract void onStopRefresh()

Called when widget stops refreshing and is no longer visible.

public void onScheduledRefresh()

Override this method to take action on scheduled refresh. Example of how to schedule a refresh every 10th second in onStartRefresh() and cancel it in onStopRefresh()

public void startRefresh() {
     // Update now and every 10th second
     scheduleRepeatingRefresh(System.currentTimeMillis(), 10 * 1000,
             SampleWidgetService.EXTENSION_KEY);
 }

 public void stopRefresh() {
     cancelScheduledRefresh(SampleWidgetService.EXTENSION_KEY);
 }

 public void onScheduledRefresh() {
     // Update widget...
 }

See Also

public void onDoAction(int requestCode, Bundle bundle)

When you call the ExtensionService#doActionOnAllWidgets or ExtensionService#doActionOnWidget, this method will be called.

Parameters
requestCode Code used to distinguish between different actions.
bundle Optional bundle with additional information.
See Also

public void onDestroy()

Called when a widget is no longer used and is being removed. The widget extension should clean up any resources it holds (threads, registered receivers, etc) at this point.

public void onTouch(int type, int x, int y)

Called when the widget has been touched. Override to handle touch events.

Parameters
type The type of touch event.
x The x position of the touch event.
y The y position of the touch event.
See Also

public void onObjectClick(int type, int layoutReference)

Called when an object click event has occurred.

Parameters
type The type of click event
layoutReference The referenced layout object
See Also

Protected Methods

protected void scheduleRepeatingRefresh(long triggerAtTime, long interval, java.lang.String extensionKey)

Schedule a repeating refresh.

Parameters
triggerAtTime Time the scheduled refresh should trigger first time in System time.
interval Interval between subsequent repeats of the scheduled refresh.
extensionKey The extension key
See Also

protected void scheduleRefresh(long triggerAtTime, java.lang.String extensionKey)

Schedule a refresh.

Parameters
triggerAtTime Time the scheduled refresh should trigger in System time.
extensionKey The extension key

protected void cancelScheduledRefresh(java.lang.String extensionKey)

Cancel any pending scheduled refresh associated with the extension key.

Parameters
extensionKey The extension key

protected void sendImageToHostApp(int resourceId)

Show image in the widget.

Parameters
resourceId The image resource id.

protected void sendToHostApp(Intent intent)

Send intent to host application. Adds host application package name and our package name.

Parameters
intent The intent to send.

protected void showBitmap(Bitmap bitmap)

Show bitmap in the widget.

Parameters
bitmap The bitmap to show.

protected void showLayout(int layoutId)

Show a layout in the widget.

Parameters
layoutId The layout resource id.

protected void showLayout(int layoutId, Bundle[] layoutData)

Show a layout in the widget.

Parameters
layoutId The layout resource id.
layoutData The layout data.

protected void showLayout(int layoutId, int noTouchLayoutId, Bundle[] layoutData)

Show a layout in the widget.

Parameters
layoutId The layout resource id.
noTouchLayoutId The layout resource id for a layout to display then touch is inactive but accessory is still connected to device
layoutData The layout data. Is applied to every layout provided
See Also

protected void showLayout(int layoutId, int noTouchLayoutId, int offLineLayoutId, Bundle[] layoutData)

Show a layout in the widget.

Parameters
layoutId The layout resource id.
noTouchLayoutId The layout resource id for a layout to display then touch is inactive but accessory is still connected to device
offLineLayoutId The layout resource id for a layout to display when accessory is not connected to device
layoutData The layout data. Is applied to every layout provided
See Also

protected void sendImage(int layoutReference, int resourceId)

Update an image in a specific layout, in the widget.

Parameters
layoutReference The referenced resource within the current layout.
resourceId The image resource id.

protected void sendText(int layoutReference, java.lang.String text)

Update a TextView in a specific layout, in the widget.

Parameters
layoutReference The referenced resource within the current layout.
text The text to be shown.