Sony Addon SDK public abstract class

ControlExtension

This project is no longer being supported and will not get any further updates.
extends java.lang.Object
  1. java.lang.Object
  2. com.sonyericsson.extras.liveware.extension.util.control.ControlExtension

Class Overview

The control extension handles a control on an accessory.

Summary

Fields
protected final Context mContext The context of the extension service
protected final java.lang.String mHostAppPackageName Package name of the host application
protected final BitmapFactory.Options mBitmapOptions Default bitmap factory options that will be frequently used throughout the extension to avoid any automatic scaling.
Public Constructors
ControlExtension(Context context, java.lang.String hostAppPackageName)

Create control extension.

Public Methods
final void start()

Sets the control state to started.

final void resume()

Sets the control state to resumed.

final void pause()

Sets the control state to paused.

final void stop()

Sets the control state to stopped.

final void destroy()

Sets the control state to destroyed.

void onDoAction(int requestCode, Bundle bundle)

Called when the control receives an action request.

void onDestroy()

Called to notify a control extension that it is no longer used and is being removed.

void onStart()

Called when the control extension is started by the host application.

void onStop()

Called when the control extension is stopped by the host application.

void onPause()

Called when the control extension is paused by the host application.

void onResume()

Called when the control extension is resumed by the host application.

void onError(int code)

Called when extension receives an error.

void onTap(int action, long timeStamp)

Called when a tap event has occurred.

void onKey(int action, int keyCode, long timeStamp)

Called when a key event has occurred.

void onTouch(ControlTouchEvent event)

Called when a touch event has occurred.

void onObjectClick(ControlObjectClickEvent event)

Called when an object click event has occurred.

void onSwipe(int direction)

Called when a swipe event has occurred.

void onRequestListItem(int layoutReference, int listItemPosition)

Called when the host application requests content for a specific list item.

void onListItemClick(ControlListItem listItem, int clickType, int itemLayoutReference)

Called when an item in a list has been clicked.

void onListRefreshRequest(int layoutReference)

Called when list refresh was requested.

void onListItemSelected(ControlListItem listItem)

Called when an item in a list has been selected.

void onMenuItemSelected(int menuItem)

Called when a menu item has been selected.

void onActiveLowPowerModeChange(boolean lowPowerModeOn)

Called when the accessory screen's state leaves or enters Active Low Power mode.

Protected Methods
void startRequest()

Send request to start control extension.

void stopRequest()

Send request to stop control extension.

void showImage(int resourceId)

Show an image on the accessory.

void showLayout(int layoutId, Bundle[] layoutData)

Show a layout on the accessory.

void sendImage(int layoutReference, int resourceId)

Update an image in a specific layout, on the accessory.

void sendImage(int layoutReference, Bitmap bitmap)

Update an image in a specific layout, on the accessory.

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

Update text in a specific layout, on the accessory.

void showBitmap(Bitmap bitmap)

Show bitmap on accessory.

void showBitmap(Bitmap bitmap, int x, int y)

Show bitmap on accessory.

void setScreenState(int state)

Set the accessory screens state.

void startVibrator(int onDuration, int offDuration, int repeats)

Start repeating vibrator.

void stopVibrator()

Stop vibrator.

void startLedPattern(int id, int color, int onDuration, int offDuration, int repeats)

Start a LED pattern.

void stopLedPattern(int id)

Turn led off.

void clearDisplay()

Clear accessory display.

void sendListCount(int layoutReference, int listCount)

Set the number of items in list.

void sendListCountWithContent(int layoutReference, int listCount, Bundle[] bundles)

Set the number of items in list and populate it with content.

void sendListItem(ControlListItem item)

Update a list item.

void sendListPosition(int layoutReference, int position)

Sends a request to move a list to a specified position.

void showMenu(Bundle[] menuItems)

Show a menu.

void sendToHostApp(Intent intent)

Send intent to host application.

long getHostAppId()

Get the host application id for this control.

boolean hasVibrator()

Check if this host application has a vibrator.

ControlViewGroup parseLayout(View v)

Process View and whole ViewGroup tree into ControlViewGroup used by accessory.

Fields

protected final Context mContext

The context of the extension service

protected final java.lang.String mHostAppPackageName

Package name of the host application

protected final BitmapFactory.Options mBitmapOptions

Default bitmap factory options that will be frequently used throughout the extension to avoid any automatic scaling. Keep in mind that we are not showing the images on the phone, but on the accessory.

Public Constructors

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

Create control extension.

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

Public Methods

public final void start()

Sets the control state to started. To request a control extension to start you have to use startRequest() method.

public final void resume()

Sets the control state to resumed.

public final void pause()

Sets the control state to paused.

public final void stop()

Sets the control state to stopped. To request a control extension to stop you have to use stopRequest() method.

public final void destroy()

Sets the control state to destroyed.

public void onDoAction(int requestCode, Bundle bundle)

Called when the control receives an action request.

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

public void onDestroy()

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

public void onStart()

Called when the control extension is started by the host application.

public void onStop()

Called when the control extension is stopped by the host application.

public void onPause()

Called when the control extension is paused by the host application.

public void onResume()

Called when the control extension is resumed by the host application. The extension is expected to send a new image each time it is resumed.

public void onError(int code)

Called when extension receives an error.

Parameters
code The reported error code. EXTRA_ERROR_CODE

public void onTap(int action, long timeStamp)

Called when a tap event has occurred.

Parameters
action Can be any tap actions defined in the Control.TapActions interface.
timeStamp The time when the tap event occurred.

public void onKey(int action, int keyCode, long timeStamp)

Called when a key event has occurred.

Parameters
action The key action, one of
  • ACTION_LONGPRESS
  • ACTION_PRESS
  • ACTION_RELEASE
keyCode The key code.
timeStamp The time when the event occurred.

public void onTouch(ControlTouchEvent event)

Called when a touch event has occurred.

Parameters
event The touch event.

public void onObjectClick(ControlObjectClickEvent event)

Called when an object click event has occurred.

Parameters
event The object click event.

public void onSwipe(int direction)

Called when a swipe event has occurred.

Parameters
direction The swipe direction, one of
  • DIRECTION_DOWN
  • DIRECTION_LEFT
  • DIRECTION_RIGHT
  • DIRECTION_UP

public void onRequestListItem(int layoutReference, int listItemPosition)

Called when the host application requests content for a specific list item.

Parameters
layoutReference The referenced list view
listItemPosition The requested list item position

public void onListItemClick(ControlListItem listItem, int clickType, int itemLayoutReference)

Called when an item in a list has been clicked.

Parameters
listItem The list item that was clicked
clickType The type of click ( CLICK_TYPE_SHORT, CLICK_TYPE_LONG)
itemLayoutReference The object within the list item that was clicked

public void onListRefreshRequest(int layoutReference)

Called when list refresh was requested.

Parameters
layoutReference The referenced list view

public void onListItemSelected(ControlListItem listItem)

Called when an item in a list has been selected.

Parameters
listItem The list item that was selected

public void onMenuItemSelected(int menuItem)

Called when a menu item has been selected.

Parameters
menuItem The menu item that was selected

public void onActiveLowPowerModeChange(boolean lowPowerModeOn)

Called when the accessory screen's state leaves or enters Active Low Power mode.

Parameters
lowPowerModeOn true when the low power mode is started, false when the accessory screen leaves Active Low power mode

Protected Methods

protected void startRequest()

Send request to start control extension.

protected void stopRequest()

Send request to stop control extension.

protected void showImage(int resourceId)

Show an image on the accessory.

Parameters
resourceId The image resource id.

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

Show a layout on the accessory.

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

protected void sendImage(int layoutReference, int resourceId)

Update an image in a specific layout, on the accessory.

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

protected void sendImage(int layoutReference, Bitmap bitmap)

Update an image in a specific layout, on the accessory.

Parameters
layoutReference The referenced resource within the current layout.
bitmap The bitmap to show.

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

Update text in a specific layout, on the accessory.

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

protected void showBitmap(Bitmap bitmap)

Show bitmap on accessory.

Parameters
bitmap The bitmap to show.

protected void showBitmap(Bitmap bitmap, int x, int y)

Show bitmap on accessory. Used when only updating part of the screen.

Parameters
bitmap The bitmap to show.
x The x position.
y The y position.

protected void setScreenState(int state)

Set the accessory screens state.

Parameters
state The screen state.
See Also

protected void startVibrator(int onDuration, int offDuration, int repeats)

Start repeating vibrator.

Parameters
onDuration On duration in milliseconds.
offDuration Off duration in milliseconds.
repeats The number of repeats of the on/off pattern. Use REPEAT_UNTIL_STOP_INTENT to repeat until explicitly stopped.

protected void stopVibrator()

Stop vibrator.

protected void startLedPattern(int id, int color, int onDuration, int offDuration, int repeats)

Start a LED pattern.

Parameters
id Id of the LED to be controlled.
color Color you want the LED to blink with.
onDuration On duration in milliseconds.
offDuration Off duration in milliseconds.
repeats The number of repeats of the on/off pattern. Use REPEAT_UNTIL_STOP_INTENT to repeat until explicitly stopped.

protected void stopLedPattern(int id)

Turn led off.

Parameters
id Id of the LED to be controlled.

protected void clearDisplay()

Clear accessory display.

protected void sendListCount(int layoutReference, int listCount)

Set the number of items in list. Used to specify the initial size of the list and to update the size of the list.

Parameters
layoutReference The referenced list view.
listCount The requested number of items in list.

protected void sendListCountWithContent(int layoutReference, int listCount, Bundle[] bundles)

Set the number of items in list and populate it with content.

Parameters
layoutReference The referenced list view.
listCount The requested number of items in list.
bundles List content. See EXTRA_LIST_CONTENT.

protected void sendListItem(ControlListItem item)

Update a list item.

Parameters
item List item.

protected void sendListPosition(int layoutReference, int position)

Sends a request to move a list to a specified position.

Parameters
layoutReference The referenced list view.
position

protected void showMenu(Bundle[] menuItems)

Show a menu.

Parameters
menuItems Menu items. See Control.Intents.EXTRA_MENU_ITEMS.

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 long getHostAppId()

Get the host application id for this control.

Returns

The host application id.

protected boolean hasVibrator()

Check if this host application has a vibrator.

Returns

True if vibrator exists.

protected ControlViewGroup parseLayout(View v)

Process View and whole ViewGroup tree into ControlViewGroup used by accessory.

Parameters
v View to parse.
Returns

Group of processed views.