From 48e6524f45ff9b54aa2bdc37a3ef6b24295a3f92 Mon Sep 17 00:00:00 2001 From: Piotr Ganicz Date: Tue, 15 Mar 2016 11:29:29 +0100 Subject: [PATCH] [WidgetService] Added guide and tutorial. Change-Id: If8bf3beae488c0a52f74302ded116cbe8a12e0e2 Signed-off-by: Piotr Ganicz --- org.tizen.guides/html/index.htm | 1 + .../html/web/tizen/application/widgetservice_w.htm | 83 + .../tizen/application/widgetservice_tutorial_w.htm | 253 +++ .../html/device_api/mobile/index.html | 3 + .../device_api/mobile/tizen/widgetservice.html | 1862 ++++++++++++++++++++ .../html/device_api/wearable/index.html | 7 + .../device_api/wearable/tizen/widgetservice.html | 1860 +++++++++++++++++++ org.tizen.web.apireference/html/index.htm | 4 +- 8 files changed, 4072 insertions(+), 1 deletion(-) create mode 100644 org.tizen.guides/html/web/tizen/application/widgetservice_w.htm create mode 100644 org.tizen.tutorials/html/web/tizen/application/widgetservice_tutorial_w.htm create mode 100644 org.tizen.web.apireference/html/device_api/mobile/tizen/widgetservice.html create mode 100644 org.tizen.web.apireference/html/device_api/wearable/tizen/widgetservice.html diff --git a/org.tizen.guides/html/index.htm b/org.tizen.guides/html/index.htm index e2e2da0..0559e0d 100644 --- a/org.tizen.guides/html/index.htm +++ b/org.tizen.guides/html/index.htm @@ -245,6 +245,7 @@
  • Notification
  • Package
  • Preference
  • +
  • WidgetService
  • Content diff --git a/org.tizen.guides/html/web/tizen/application/widgetservice_w.htm b/org.tizen.guides/html/web/tizen/application/widgetservice_w.htm new file mode 100644 index 0000000..86ac215 --- /dev/null +++ b/org.tizen.guides/html/web/tizen/application/widgetservice_w.htm @@ -0,0 +1,83 @@ + + + + + + + + + + + + + WidgetService + + + + + +
    +

    WidgetService

    +

    WidgetService management features include retrieving information about widgets, such as widget name and supported widget size types. You can get the widget instances and receive notifications if the state of the widget changes.

    + +

    The WidgetService API is mandatory for both Tizen mobile and wearable profiles, which means that it is supported in all mobile and wearable devices. All mandatory APIs are supported on the Tizen Emulators.

    + +

    The main WidgetService features are:

    +
    + +Go to top + + + + + + + diff --git a/org.tizen.tutorials/html/web/tizen/application/widgetservice_tutorial_w.htm b/org.tizen.tutorials/html/web/tizen/application/widgetservice_tutorial_w.htm new file mode 100644 index 0000000..367524a --- /dev/null +++ b/org.tizen.tutorials/html/web/tizen/application/widgetservice_tutorial_w.htm @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + WidgetService: Providing Information about Installed Widgets + + + + + + +
    + +

    WidgetService: Providing Information about Installed Widgets

    + +

    This tutorial demonstrates how you can retrieve installed widgets and additional information related to them.

    + +

    The WidgetService API is mandatory for both Tizen mobile and wearable profiles, which means that it is supported in all mobile and wearable devices. All mandatory APIs are supported on the Tizen Emulators.

    + +

    Warm-up

    +

    Become familiar with the Widget Service API basics by learning about:

    + + +

    Retrieving Widgets

    + +

    Learning how to retrieve installed widgets list is a basic Widget service skill:

    +
      +
    1. Define a success handler implementing WidgetArraySuccessCallback() interface (in mobile and wearable applications). Optionally you can specify error handler too.

      +var successCallback = function (widgets) {
      +   console.log("There are " + widgets.length + " installed widgets");
      +};
      +
      +var errorCallback = function (error) {
      +   console.log("Error " + error.message);
      +};
    2. +
    3. To get a list of all installed widgets use the getWidgets() method of the WidgetServiceManager interface (in mobile and wearable applications). If the optional parameter packageId is given, the only widgets belonging to the given package are returned.

      +var packageId = "org.tizen.contacts";
      +tizen.widgetservice.getWidgets(successCallback, errorCallback, packageId);
      +
    4. +
    5. You can also get specific widget object by using the getWidget() method of the WidgetServiceManager interface (in mobile and wearable applications).

      +var widget = tizen.widgetservice.getWidget("org.tizen.gallery.widget");
      +
    6. +
    +

    Retrieving ID And Size Information

    + +

    Learning how to retrieve primary widget id or size makes using Widget service API easy and convenient:

    +
      +
    1. To get primary widget id of given application or package id use the getPrimaryWidgetId() method of the WidgetServiceManager interface (in mobile and wearable applications).

      +var widgetId = tizen.widgetservice.getPrimaryWidgetId("org.tizen.music-player");
      +
    2. +
    3. To get size of the corresponding size type use the getSize() method of the PackageManager interface, specifying the size type.

      +var widgetSize = tizen.widgetservice.getSize("4x4");
      +
    4. +
    +

    Retrieving Widget Name

    + +

    Learning how to retrieve widget name:

    +
      +
    1. Retrieve widget that name you would like to get.

      +var widget = tizen.widgetservice.getWidget("org.tizen.gallery.widget");
      +
    2. +
    3. To get widget name use the getName() method of the Widget interface. If the locale parameter is omitted then system locale one is used.

      +var name = widget.getName("en-us");
      +
    4. +
    +

    Retrieving Widget Instances

    + +

    Learning how to retrieve information about installed widget instances makes widget service API more useful:

    +
      +
    1. Define a success handler implementing WidgetInstancesCallback() interface (in mobile and wearable applications). Optionally you can specify error handler too.

      +var successCallback = function (instances) {
      +   console.log("There are " + instances.length + " instances");
      +};
      +
      +var errorCallback = function (error) {
      +   console.log("Error " + error.message);
      +};
    2. + +
    3. To retrieve a list of all instances belonging to the widget, use the getInstances() method of the Widget interface (in mobile and wearable applications):

      +widget.getInstances(successCallback, errorCallback);
      +
    4. +
    5. To retrieve basic package information, use the getPackageInfo() method of the PackageManager interface, specifying the package ID. If no package ID is set, the method retrieves information of the application package calling the method.

      var packageInfo = tizen.package.getPackageInfo("org.tizen.calculator");
    6. +
    + + +

    Retrieving Widget Variants

    + +

    Learning how to retrieve variants representing all of the supported widget size types

    +
      +
    1. Define a success handler implementing WidgetVariantsCallback() interface (in mobile and wearable applications). Optionally you can specify error handler too.

      +var successCallback = function (variants) {
      +   console.log("There are " + variants.length + " variants of the widget");
      +};
      +
      +var errorCallback = function (error) {
      +   console.log("Error " + error.message);
      +};
    2. +
    3. Retrieve widget that variants you would like to obtain.

      +var widget = tizen.widgetservice.getWidget("org.tizen.gallery.widget");
      +
    4. +
    5. To get a list of all variants use the getVariants() method of the Widget interface (in mobile and wearable applications):

      +widget.getVariants(successCallback, errorCallback);
      +
    6. +
    7. You can also get specific variant by using the getVariant() method with one of the supported size type as a parameter.

      +var variant = widget.getVariant("4x4");
      +
    8. +
    +

    Receiving Widget Change Notifications

    + +

    Learning to receive notifications when the state of the widget has been changed. There are four states that can be noticed: CREATE, DESTROY, PAUSE and RESUME.

    +
      +
    1. Define the event handler for state notifications using the WidgetChangeCallback listener interface (in mobile and wearable applications):

      +var WidgetChangeCallback = function (instance, event) {
      +   console.log("The instance " + instance + " has state " + event);
      +};
    2. + +
    3. Retrive widget object using the getWidget method of the WidgetServiceManager interface (in mobile and wearable applications)

      +var widget = tizen.widgetservice.getWidget("org.tizen.music-player.widget");
      +
    4. + +
    5. Add the listener to use the defined event handler with the addStateChangeListener() method of the Widget interface (in mobile and wearable applications):

      +var watchId = widget.addStateChangeListener(WidgetChangeCallback);
      +
    6. +
    7. To stop receiving notifications for defined listener, use the removeStateChangeListener() method of the Widget interface with previously obtained listener id:

      widget.removeStateChangeListener(watchId);
    8. +
    +

    Changing Update Period

    + +

    Learning how to change update interval for the widget instance:

    +
      +
    1. First of all you have to retrive widget instance by getInstances() method.

      +var instance;
      +var successCallback = function (instances) {
      +   instance = instances[0];
      +};
      +
      +var widget = tizen.widgetservice.getWidget("org.tizen.gallery.widget");
      +widget.getInstances(successCallback);
      +
    2. +
    3. To change update interval use the changeUpdatePeriod() method of the WidgetInstance interface with new value in seconds.

      +
      +instance.changeUpdatePeriod(2);
      +
    4. +
    +

    Sending And Getting Content

    + +

    Learning how to change update interval for the widget instance:

    +
      +
    1. The first step is obtaining widget instance by getInstances() method.

      +var instance;
      +var successCallback = function (instances) {
      +   instance = instances[0];
      +};
      +
      +var widget = tizen.widgetservice.getWidget("org.tizen.gallery.widget");
      +widget.getInstances(successCallback);
      +
    2. +
    3. To change update interval use the changeUpdatePeriod() method of the WidgetInstance interface with new value in seconds.

      +
      +instance.changeUpdatePeriod(2);
      +
    4. +
    5. To send data use the sendContent() method of the WidgetInstance interface. The second parameter decides if the instance will be updated even if the provider is paused.

      +
      +instance.sendContent(data, true);
      +
    6. +
    7. You can also retrieve widget instance content. At the beginning define success handler implementing WidgetContentCallback() interface (in mobile and wearable applications). Optionally you can specify error handler too.

      +var successCallback = function (object) {
      +   console.log("Data successfully retrieved");
      +};
      +
      +var errorCallback = function (error) {
      +   console.log("Error " + error.message);
      +};
    8. +
    9. Afterwards use getContent() method of the WidgetInstance interface.

      +
      +instance.getContent(successCallback, errorCallback);
      +
    10. +
    + + + + + +
    + +Go to top + + + + + + + diff --git a/org.tizen.web.apireference/html/device_api/mobile/index.html b/org.tizen.web.apireference/html/device_api/mobile/index.html index 41713aa..2f11037 100644 --- a/org.tizen.web.apireference/html/device_api/mobile/index.html +++ b/org.tizen.web.apireference/html/device_api/mobile/index.html @@ -122,6 +122,9 @@ Preference This API provides the functionality to store and retrieve small pieces of data which can be for application preferences. + + WidgetService + This API provides information of installed widgets. 3.0 Mandatory Yes diff --git a/org.tizen.web.apireference/html/device_api/mobile/tizen/widgetservice.html b/org.tizen.web.apireference/html/device_api/mobile/tizen/widgetservice.html new file mode 100644 index 0000000..e324c51 --- /dev/null +++ b/org.tizen.web.apireference/html/device_api/mobile/tizen/widgetservice.html @@ -0,0 +1,1862 @@ + + + + + +WidgetService API + + +
    +
    +

    WidgetService API

    +
    + The WidgetService API provides information about installed widgets. +
    +
    +

    +For more information on the Widget service features, see the Widget Service Guide. +

    +
    +

    + Since: + 3.0 +

    +

    Table of Contents

    + +
    +

    Summary of Interfaces and Methods

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    InterfaceMethod
    WidgetServiceManagerObject
    WidgetServiceManager + +
    void getWidgets (WidgetArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional PackageId? packageId)
    +
    +WidgetId getPrimaryWidgetId ((PackageId or ApplicationId) id)
    + +
    Widget +
    DOMString getName (optional DOMString? locale)
    +
    void getInstances (WidgetInstancesCallback successCallback, optional ErrorCallback? errorCallback)
    + +
    void getVariants (WidgetVariantsCallback successCallback, optional ErrorCallback? errorCallback)
    + +
    void removeStateChangeListener (long watchId)
    +
    WidgetSize
    WidgetVariant
    WidgetInstance +
    void changeUpdatePeriod (double seconds)
    +
    void sendContent (Object data, boolean updateIfPaused)
    +
    void getContent (WidgetContentCallback successCallback, ErrorCallback errorCallback)
    +
    WidgetArraySuccessCallback
    void onsuccess (Widget[] widgets)
    WidgetInstancesCallback
    void onsuccess (WidgetInstance[] instances)
    WidgetVariantsCallback
    void onsuccess (WidgetVariant[] instances)
    WidgetContentCallback
    void onsuccess (Object data)
    WidgetChangeCallback
    void onchange (WidgetInstance instance, WidgetStateType event)
    +
    +

    1. Type Definitions

    +
    +

    1.1. WidgetId

    +
    + The unique ID of the installed widget. +
    +
      typedef DOMString WidgetId;
    +

    + Since: + 3.0 +

    +
    +
    +

    1.2. WidgetInstanceId

    +
    + The unique ID of the installed widget instance. +
    +
      typedef DOMString WidgetInstanceId;
    +

    + Since: + 3.0 +

    +
    +
    +

    1.3. WidgetSizeType

    +
    + The WidgetSizeType enumeration lists supported widget size types. +
    +
      enum WidgetSizeType {
    +    "1x1", "2x1", "2x2", "4x1", "4x2", "4x3", "4x4", "4x5", "4x6",
    +    "EASY_1x1", "EASY_3x1", "EASY_3x3",
    +    "FULL"
    +  };
    +

    + Since: + 3.0 +

    +
    +

    +The size types defines the following types (pixel size is given for a 720x1280 resolution): +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Size type +Size in pixels +Supported profile
    +1x1 +175x175 +This size type is not used. just defined for specifying a default cell size
    +2x1 +354x175 +Mobile
    +2x2 +354x354 +Mobile, Wearable
    +4x1 +712x175 +Mobile
    +4x2 +712x354 +Mobile
    +4x3 +712x533 +Mobile
    +4x4 +712x712 +Mobile
    +4x5 +712x891 +Mobile
    +4x6 +712x1070 +Mobile
    +EASY_1x1 +224x215 +Mobile
    +EASY_3x1 +680x215 +Mobile
    +EASY_3x3 +680x653 +Mobile
    +FULL +720x1280 +Mobile
    +
    +
    +
    +

    1.4. WidgetStateType

    +
    + Enumeration for types of lifetime events of a Widget. +
    +
      enum WidgetStateType {"CREATE", "DESTROY", "PAUSE", "RESUME"};
    +

    + Since: + 3.0 +

    +
    +
      +
    • +CREATE - the widget was created
    • +
    • +DESTROY - the widget was destroyed
    • +
    • +PAUSE - the widget was paused
    • +
    • +RESUME - the widget was resumed
    • +
    +

    +Widget lifetime events can be monitored with the addStateChangeListener() method +of the Widget interface. +

    +
    +
    +
    +
    +

    2. Interfaces

    +
    +

    2.1. WidgetServiceManagerObject

    +
    + This interface defines what is instantiated by the Tizen object on the Tizen Platform. +
    +
      [NoInterfaceObject] interface WidgetServiceManagerObject {
    +      readonly attribute WidgetServiceManager widget;
    +  };
    +
      Tizen implements WidgetServiceManagerObject;
    +

    + Since: + 3.0 +

    +
    +

    +The tizen.widgetservice object provides access to the Widget service API's functionality. +

    +
    +
    +
    +

    2.2. WidgetServiceManager

    +
    + The WidgetServiceManager interface provides methods for accessing information about widgets. +
    +
      [NoInterfaceObject] interface WidgetServiceManager {
    +    Widget getWidget(WidgetId widgetId) raises(WebAPIException);
    +
    +    void getWidgets(WidgetArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional PackageId? packageId) raises(WebAPIException);
    +
    +    WidgetId getPrimaryWidgetId((PackageId or ApplicationId) id) raises(WebAPIException);
    +
    +    WidgetSize getSize(WidgetSizeType sizeType) raises(WebAPIException);
    +  };
    +

    + Since: + 3.0 +

    +
    +

    Methods

    +
    +
    +getWidget +
    +
    +
    + Retrieves a Widget object with a given widgetId. +
    +
    Widget getWidget(WidgetId widgetId);
    +             
    +

    + Since: + 3.0 +

    +

    + Privilege level: + public +

    +

    + Privilege: + http://tizen.org/privilege/widget.viewer +

    +
    +

    Parameters:

    +
      +
    • +widgetId: + The ID of the Widget to retrieve +
    • +
    +
    +
    +

    Return value:

    + Widget The Widget object +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type SecurityError, if the application does not have the privilege to use this function. +

      • +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      • + with error type IOError, if a DB operation has failed. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   console.log("Widget id is " + widget.id);
    +   console.log("Widget details:");
    +   console.log("Main application id: " + widget.applicationId);
    +   console.log("Package id: " + widget.packageId);
    +   console.log("Is hidden in the list of widgets: " + widget.noDisplay);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Widget id is org.tizen.gallery.widget
    + Widget details:
    + Main application id: org.tizen.gallery
    + Package id: org.tizen.gallery
    + Is hidden in the list of widgets: false
    + 
    +
    +
    +
    +getWidgets +
    +
    +
    + Retrieves a list of all widgets. If package id is provided returned list contains widgets included in a given package only. +
    +
    void getWidgets(WidgetArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional PackageId? packageId);
    +             
    +

    + Since: + 3.0 +

    +
    +

    +The errorCallback is launched with these error types: +

    +
      +
    • +InvalidValuesError - If any of the input parameters contain an invalid value.
    • +
    • +IOError - If a DB operation has failed.
    • +
    • +AbortError - If the operation cannot be finished properly.
    • +
    +
    +

    + Privilege level: + public +

    +

    + Privilege: + http://tizen.org/privilege/widget.viewer +

    +
    +

    Parameters:

    +
      +
    • +successCallback: + A function to call when widgets are retrieved successfully +
    • +
    • +errorCallback [optional] [nullable]: + A function to call when an error occurs +
    • +
    • +packageId [optional] [nullable]: + If this parameter is given, then only widgets belonging to the given package are returned +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to use this function. +

      • +
      +
    +
    +
    +

    Code example:

     tizen.widgetservice.getWidgets(function (widgets) {
    +   console.log("There are " + widgets.length + " available widgets");
    + }, function (error) {
    +    console.log("Error: " + error.message);
    + });
    + 
    +
    +
    +

    Output example:

     There are 3 available widgets
    + 
    +
    +
    +
    +getPrimaryWidgetId +
    +
    +
    + Returns the primary widget ID of the specified package or application. +
    +
    WidgetId getPrimaryWidgetId((PackageId or ApplicationId) id);
    +             
    +

    + Since: + 3.0 +

    +

    + Privilege level: + public +

    +

    + Privilege: + http://tizen.org/privilege/widget.viewer +

    +
    +

    Parameters:

    +
      +
    • +id: + Package or Application ID +
    • +
    +
    +
    +

    Return value:

    + WidgetId The ID of the widget +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type SecurityError, if the application does not have the privilege to use this function. +

      • +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      • + with error type IOError, if a DB operation has failed. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable id should contain valid id of the application or package.
    + var id = "org.tizen.gallery";
    + try {
    +   var widgetId = tizen.widgetservice.getPrimaryWidgetId(id);
    +   console.log("Widget id is " + widgetId);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Widget id is org.tizen.gallery.widget
    + 
    +
    +
    +
    +getSize +
    +
    +
    + Returns the size coresponding to the given sizeType. +
    +
    WidgetSize getSize(WidgetSizeType sizeType);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +sizeType: + WidgetSizeType used for retrieving corresponding pixel size object. +
    • +
    +
    +
    +

    Return value:

    + WidgetSize An object which contains width and height. +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      +
    +
    +
    +

    Code example:

     //variable sizeType should contain supported size type
    + var sizeType = "4x4";
    + try {
    +   var widgetSize = tizen.widgetservice.getSize(sizeType);
    +   console.log("Widget size width: " + widgetSize.width + ", height: " + widgetSize.height);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Widget size width: 712, height: 712
    + 
    +
    +
    +
    +
    +
    +
    +

    2.3. Widget

    +
    + The Widget interface provides access to a single Widget installed on the system. +
    +
      [NoInterfaceObject] interface Widget {
    +    readonly attribute WidgetId id;
    +
    +    readonly attribute ApplicationId applicationId;
    +
    +    readonly attribute ApplicationId? setupApplicationId;
    +
    +    readonly attribute PackageId packageId;
    +
    +    readonly attribute boolean noDisplay;
    +
    +    DOMString getName(optional DOMString? locale) raises(WebAPIException);
    +    void getInstances(WidgetInstancesCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +
    +    WidgetVariant getVariant(WidgetSizeType sizeType) raises(WebAPIException);
    +
    +    void getVariants(WidgetVariantsCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +
    +    long addStateChangeListener(WidgetChangeCallback listener) raises(WebAPIException);
    +
    +    void removeStateChangeListener(long watchId) raises(WebAPIException);
    +  };
    +

    + Since: + 3.0 +

    +
    +

    Attributes

    +
      +
    • + readonly +WidgetId id
      + Widget ID. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +ApplicationId applicationId
      + Main application ID. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +ApplicationId setupApplicationId [nullable]
      + Setup application ID. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +PackageId packageId
      + The ID of the package this widget was installed with. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +boolean noDisplay
      + true if the widget should be hidden in the list of widgets. +
      +
      +

      +Precondition: Widget tag in the config.xml file includes the "nodisplay" attribute. +

      +
      +

      + Since: + 3.0 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +getName +
    +
    +
    + Returns a name of the widget in a given locale. +
    +
    DOMString getName(optional DOMString? locale);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +locale [optional] [nullable]: + Locale ("en-us", "ko-kr", ...). If null, then the default system locale is used. +
    • +
    +
    +
    +

    Return value:

    + DOMString The name of the widget. +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   var name = widget.getName("en-us");
    +   console.log("Widget name is " + name);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Widget name is Gallery
    + 
    +
    +
    +
    +getInstances +
    +
    +
    + Retrieves Widget instances (elements that have been added to the screen). Widget instance as opposed to the widget interface (which is abstarct of application), is a specified application. +
    +
    void getInstances(WidgetInstancesCallback successCallback, optional ErrorCallback? errorCallback);
    +             
    +

    + Since: + 3.0 +

    +
    +

    +The errorCallback is launched with these error types: +

    +
      +
    • +AbortError - If the operation cannot be finished properly.
    • +
    • +NotFoundError - If the Web application which is calling this method did not add any widgets to the screen.
    • +
    +
    +
    +

    Parameters:

    +
      +
    • +successCallback: + A function to call when widgets are retrieved successfully +
    • +
    • +errorCallback [optional] [nullable]: + A function to call when an error occurs +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      +
    +
    +
    +

    Code example:

     widgetSuccessCb = function(instances) {
    +   console.log("Instances array size: " + instances.length);
    + }
    +
    + widgetErrorCb = function(error) {
    +   console.log("Error occurred: " + error.name + ": " + error.message);
    + }
    +
    + //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   widget.getInstances(widgetSuccessCb, widgetErrorCb);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Instances array size: 3
    + 
    +
    +
    +
    +getVariant +
    +
    +
    + Returns object representing widget information related to a given sizeType. +
    +
    WidgetVariant getVariant(WidgetSizeType sizeType);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +sizeType: + WidgetSizeType value that information will be returned about. +
    • +
    +
    +
    +

    Return value:

    + WidgetVariant Size variant info +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   var variant = widget.getVariant("4x4");
    +   console.log("Variant preview image path is " + variant.previewImagePath);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Variant preview image path is /usr/share/icons/default/small/preview_gallery_4x4.png
    + 
    +
    +
    +
    +getVariants +
    +
    +
    + Retrieves Wiget Variants representing all of the supported widget size types. +
    +
    void getVariants(WidgetVariantsCallback successCallback, optional ErrorCallback? errorCallback);
    +             
    +

    + Since: + 3.0 +

    +
    +

    +The errorCallback is launched with these error types: +

    +
      +
    • +AbortError - If the operation cannot be finished properly.
    • +
    +
    +
    +

    Parameters:

    +
      +
    • +successCallback: + A function to call when widgets are retrieved successfully +
    • +
    • +errorCallback [optional] [nullable]: + A function to call when an error occurs +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      +
    +
    +
    +

    Code example:

     widgetSuccessCb = function(variants) {
    +   console.log("Variants array size: " + variants.length);
    + }
    +
    + widgetErrorCb = function(error) {
    +   console.log("Error occurred: " + error.name + ": " + error.message);
    + }
    +
    + //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   widget.getVariants(widgetSuccessCb, widgetErrorCb);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Variants array size: 4
    + 
    +
    +
    +
    +addStateChangeListener +
    +
    +
    + Registers a callback which will be called whenever any of this widget instances state changes. +
    +
    long addStateChangeListener(WidgetChangeCallback listener);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +listener: + The callback +
    • +
    +
    +
    +

    Return value:

    + long The watch ID used to unregister the callback +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidValuesError, if any input parameters do not contain a valid value. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     widgetChangeCb = function(instance, event) {
    +   console.log("Instance " + instance.id + " is " + event);
    + }
    +
    + //variable id should contain valid id of the installed widget
    + var id = "org.tizen.music-player.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   var watchId = widget.addStateChangeListener(widgetChangeCb);
    +   console.log("Listener with id " + watchId + " has been added");
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Listener with id 1 has been added.
    + Instance org.tizen.music-player.widget is RESUME
    + 
    +
    +
    +
    +removeStateChangeListener +
    +
    +
    + Unregisters a callback registered under the given watchId. +
    +
    void removeStateChangeListener(long watchId);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +watchId: + The ID of the registered listener +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type NotFoundError, if listener with given watchId not exists. +

      • +
      • + with error type InvalidValuesError, if any input parameters do not contain a valid value. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     widgetChangeCb = function(instance, event) {
    +   console.log("Instance " + instance.id + " is " + event);
    +   widget.removeStateChangeListener(watchId);
    +   console.log("Listener with id " + watchId + " has been removed");
    + }
    +
    + //variable id should contain valid id of the installed widget
    + var id = "org.tizen.music-player.widget";
    + var watchId;
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   watchId = widget.addStateChangeListener(widgetChangeCb);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Listener with id 1 has been removed.
    + 
    +
    +
    +
    +
    +
    +
    +

    2.4. WidgetSize

    +
    + The WidgetSize interface contains width and height of a widget area. +
    +
      [NoInterfaceObject] interface WidgetSize {
    +    readonly attribute long width;
    +    readonly attribute long height;
    +  };
    +

    + Since: + 3.0 +

    +
    +

    Attributes

    +
      +
    • + readonly +long width
      + The horizontal dimension of the area in pixels. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +long height
      + The vertical dimension of the area in pixels. +
      +

      + Since: + 3.0 +

      +
    • +
    +
    +
    +
    +

    2.5. WidgetVariant

    +
    + The WidgetVariant interface provides Widget information related to specific sizeType. +
    +
      [NoInterfaceObject] interface WidgetVariant {
    +    readonly attribute WidgetSizeType sizeType;
    +
    +    readonly attribute long width;
    +
    +    readonly attribute long height;
    +
    +    readonly attribute DOMString previewImagePath;
    +
    +    readonly attribute boolean needsMouseEvents;
    +
    +    readonly attribute boolean needsTouchEffect;
    +
    +    readonly attribute boolean needsFrame;
    +  };
    +

    + Since: + 3.0 +

    +
    +

    Attributes

    +
      +
    • + readonly +WidgetSizeType sizeType
      + The WidgetSizeType this WidgetVariant describes. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +long width
      + Pixel width. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +long height
      + Pixel height. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +DOMString previewImagePath
      + The preview image path. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +boolean needsMouseEvents
      + true if the widget was designed to receive mouse events. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +boolean needsTouchEffect
      + true if the widget expects the system to show touch effect. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +boolean needsFrame
      + true if the widget expects the system to draw a frame. +
      +

      + Since: + 3.0 +

      +
    • +
    +
    +
    +
    +

    2.6. WidgetInstance

    +
    + The WidgetInstance interface provides access to a single instance of the Widget. +
    +
      [NoInterfaceObject] interface WidgetInstance {
    +    readonly attribute Widget widget;
    +
    +    readonly attribute WidgetInstanceId id;
    +
    +    void changeUpdatePeriod(double seconds) raises(WebAPIException);
    +
    +    void sendContent(Object data, boolean updateIfPaused) raises(WebAPIException);
    +
    +    void getContent(WidgetContentCallback successCallback, ErrorCallback errorCallback) raises(WebAPIException);
    +  };
    +

    + Since: + 3.0 +

    +
    +

    +Every visual widget element added to the home screen is a single instance of some Widget. +

    +
    +
    +

    Attributes

    +
      +
    • + readonly +Widget widget
      + The Widget this instance belongs to. +
      +

      + Since: + 3.0 +

      +
    • +
    • + readonly +WidgetInstanceId id
      + The unique ID of the widget instance. +
      +

      + Since: + 3.0 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +changeUpdatePeriod +
    +
    +
    + Changes the interval between automatic update of the widget instance data. Minimum value is 1 second. +
    +
    void changeUpdatePeriod(double seconds);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +seconds: + The interval in seconds +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidValuesError, if any input parameters do not contain a valid value. Minimum value is 1 second. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable instance should contain valid WidgetInstance object obtained by getInstances() method.
    + var instance;
    + var period = 2;
    +
    + try {
    +   instance.changeUpdatePeriod(period);
    +   console.log("Update period has been set to " + period + " seconds");
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Update period has been set to 2 seconds.
    + 
    +
    +
    +
    +sendContent +
    +
    +
    + Sends a new content data to the Widget Instance. +
    +
    void sendContent(Object data, boolean updateIfPaused);
    +             
    +

    + Since: + 3.0 +

    +
    +

    +This function does not wait for a confirmation that the data was updated. +

    +
    +
    +

    Parameters:

    +
      +
    • +data: + The new content data +
    • +
    • +updateIfPaused: + true if you want to update your widget even if the provider is paused +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type IOError, if a DB operation has failed. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable instance should contain valid WidgetInstance object obtained by getInstances() method.
    + var instance;
    +
    + var data = {
    +  data1 : 'test1',
    +  data2 : 'test2'
    + };
    +
    + try {
    +   instance.sendContent(data, true);
    +   console.log("Data has been successfully sent");
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Data has been successfully sent
    + 
    +
    +
    +
    +getContent +
    +
    +
    + Retrieves content data from the Widget Instance. +
    +
    void getContent(WidgetContentCallback successCallback, ErrorCallback errorCallback);
    +             
    +

    + Since: + 3.0 +

    +
    +

    +The errorCallback is launched with these error types: +

    +
      +
    • +InvalidValuesError - If any of the input parameters contain an invalid value
    • +
    • +IOError - If a DB operation has failed
    • +
    • +AbortError - If the operation cannot be finished properly.
    • +
    +
    +
    +

    Parameters:

    +
      +
    • +successCallback: + A function to call when data is retrieved successfully +
    • +
    • +errorCallback: + A function to call when an error occurs +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      +
    +
    +
    +

    Code example:

     //variable instance should contain valid WidgetInstance object obtained by getInstances() method.
    + var instance;
    +
    + contentSuccessCb = function(data) {
    +  console.log("Data has been obtained successfully");
    +  for (var prop in data) {
    +    console.log(prop + " : " + data[prop]);
    +  }
    + }
    +
    + contentErrorCb = function(error) {
    +  console.log("Error occurred: " + error.name + ":" + error.message);
    + }
    +
    + try {
    +   instance.getContent(contentSuccessCb, contentErrorCb);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Data has been obtained successfully
    + data1 : test1
    + data2 : test2
    + 
    +
    +
    +
    +
    +
    +
    +

    2.7. WidgetArraySuccessCallback

    +
    + The WidgetArraySuccessCallback interface implements the success callback used in the asynchronous operation to get a list of widgets using the getWidgets() method. +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetArraySuccessCallback {
    +    void onsuccess(Widget[] widgets);
    +  };
    +

    + Since: + 3.0 +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the array of Widget objects is retrieved successfully. +
    +
    void onsuccess(Widget[] widgets);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +widgets: + Array of Widget objects. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.8. WidgetInstancesCallback

    +
    + The WidgetInstancesCallback interface implements the success callback used in the asynchronous operation to get a list of widget instances using the getInstances() method. +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetInstancesCallback {
    +    void onsuccess(WidgetInstance[] instances);
    +  };
    +

    + Since: + 3.0 +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the array of WidgetInstance objects is retrieved successfully. +
    +
    void onsuccess(WidgetInstance[] instances);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +instances: + Array of WidgetInstance objects. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.9. WidgetVariantsCallback

    +
    + The WidgetVariantsCallback interface implements the success callback used in the asynchronous operation to get a list of widget variant using the getVariants() method. +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetVariantsCallback {
    +    void onsuccess(WidgetVariant[] instances);
    +  };
    +

    + Since: + 3.0 +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the array of WidgetVariants objects is retrieved successfully. +
    +
    void onsuccess(WidgetVariant[] instances);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +instances: + Array of WidgetVariants objects. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.10. WidgetContentCallback

    +
    +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetContentCallback {
    +    void onsuccess(Object data);
    +  };
    +

    + Since: + 3.0 +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the content of the widget instance is retrieved successfully. +
    +
    void onsuccess(Object data);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +data: + Content of the given widget instance. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.11. WidgetChangeCallback

    +
    + The WidgetChangeCallback describes a callback for the addStateChangeListener() method. +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetChangeCallback {
    +    void onchange(WidgetInstance instance, WidgetStateType event);
    +  };
    +

    + Since: + 3.0 +

    +
    +

    Methods

    +
    +
    +onchange +
    +
    +
    + Called when the instance state was changed. +
    +
    void onchange(WidgetInstance instance, WidgetStateType event);
    +             
    +

    + Since: + 3.0 +

    +
    +

    Parameters:

    +
      +
    • +instance: + Widget instance id that change is related to. +
    • +
    • +event: + Event of widget life cycle. +
    • +
    +
    +
    +
    +
    +
    +
    +

    3. Related Feature

    +
    + You can check if this API is supported with tizen.systeminfo.getCapability() and decide enable/disable codes that need this API. +
    +

    +

    +To guarantee that the widget application runs on a system which supports Widgets, declare the following feature requirements in the config file: +

    +

    +
  • http://tizen.org/feature/shell.appwidget
  • + +

    + For more information, see Application Filtering. + +

    4. Full WebIDL

    +
    module WidgetService {
    +  typedef DOMString WidgetId;
    +
    +  typedef DOMString WidgetInstanceId;
    +
    +  enum WidgetSizeType {
    +    "1x1", "2x1", "2x2", "4x1", "4x2", "4x3", "4x4", "4x5", "4x6",
    +    "EASY_1x1", "EASY_3x1", "EASY_3x3",
    +    "FULL"
    +  };
    +
    +  enum WidgetStateType {"CREATE", "DESTROY", "PAUSE", "RESUME"};
    +
    +  [NoInterfaceObject] interface WidgetServiceManagerObject {
    +      readonly attribute WidgetServiceManager widget;
    +  };
    +  Tizen implements WidgetServiceManagerObject;
    +
    +  [NoInterfaceObject] interface WidgetServiceManager {
    +    Widget getWidget(WidgetId widgetId) raises(WebAPIException);
    +
    +    void getWidgets(WidgetArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional PackageId? packageId) raises(WebAPIException);
    +
    +    WidgetId getPrimaryWidgetId((PackageId or ApplicationId) id) raises(WebAPIException);
    +
    +    WidgetSize getSize(WidgetSizeType sizeType) raises(WebAPIException);
    +  };
    +
    +  [NoInterfaceObject] interface Widget {
    +    readonly attribute WidgetId id;
    +
    +    readonly attribute ApplicationId applicationId;
    +
    +    readonly attribute ApplicationId? setupApplicationId;
    +
    +    readonly attribute PackageId packageId;
    +
    +    readonly attribute boolean noDisplay;
    +
    +    DOMString getName(optional DOMString? locale) raises(WebAPIException);
    +    void getInstances(WidgetInstancesCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +
    +    WidgetVariant getVariant(WidgetSizeType sizeType) raises(WebAPIException);
    +
    +    void getVariants(WidgetVariantsCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +
    +    long addStateChangeListener(WidgetChangeCallback listener) raises(WebAPIException);
    +
    +    void removeStateChangeListener(long watchId) raises(WebAPIException);
    +  };
    +
    +  [NoInterfaceObject] interface WidgetSize {
    +    readonly attribute long width;
    +    readonly attribute long height;
    +  };
    +
    +  [NoInterfaceObject] interface WidgetVariant {
    +    readonly attribute WidgetSizeType sizeType;
    +
    +    readonly attribute long width;
    +
    +    readonly attribute long height;
    +
    +    readonly attribute DOMString previewImagePath;
    +
    +    readonly attribute boolean needsMouseEvents;
    +
    +    readonly attribute boolean needsTouchEffect;
    +
    +    readonly attribute boolean needsFrame;
    +  };
    +
    +  [NoInterfaceObject] interface WidgetInstance {
    +    readonly attribute Widget widget;
    +
    +    readonly attribute WidgetInstanceId id;
    +
    +    void changeUpdatePeriod(double seconds) raises(WebAPIException);
    +
    +    void sendContent(Object data, boolean updateIfPaused) raises(WebAPIException);
    +
    +    void getContent(WidgetContentCallback successCallback, ErrorCallback errorCallback) raises(WebAPIException);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetArraySuccessCallback {
    +    void onsuccess(Widget[] widgets);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetInstancesCallback {
    +    void onsuccess(WidgetInstance[] instances);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetVariantsCallback {
    +    void onsuccess(WidgetVariant[] instances);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetContentCallback {
    +    void onsuccess(Object data);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetChangeCallback {
    +    void onchange(WidgetInstance instance, WidgetStateType event);
    +  };
    +};
    + + + + diff --git a/org.tizen.web.apireference/html/device_api/wearable/index.html b/org.tizen.web.apireference/html/device_api/wearable/index.html index 491d7bd..8413381 100644 --- a/org.tizen.web.apireference/html/device_api/wearable/index.html +++ b/org.tizen.web.apireference/html/device_api/wearable/index.html @@ -112,6 +112,13 @@ 3.0 Mandatory Yes + + WidgetService + This API provides information of installed widgets. + 3.0 + + Mandatory + Yes

    Content

    APIDescriptionVersion (Since)WearableSupported on
    Wearable Emulator
    diff --git a/org.tizen.web.apireference/html/device_api/wearable/tizen/widgetservice.html b/org.tizen.web.apireference/html/device_api/wearable/tizen/widgetservice.html new file mode 100644 index 0000000..26e8a79 --- /dev/null +++ b/org.tizen.web.apireference/html/device_api/wearable/tizen/widgetservice.html @@ -0,0 +1,1860 @@ + + + + + +WidgetService API + + +
    +
    +

    WidgetService API

    +
    + The WidgetService API provides information about installed widgets. +
    +
    +

    + Since: + 2.3.2 +

    +

    Table of Contents

    + +
    +

    Summary of Interfaces and Methods

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    InterfaceMethod
    WidgetServiceManagerObject
    WidgetServiceManager + +
    void getWidgets (WidgetArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional PackageId? packageId)
    +
    +WidgetId getPrimaryWidgetId ((PackageId or ApplicationId) id)
    + +
    Widget +
    DOMString getName (optional DOMString? locale)
    +
    void getInstances (WidgetInstancesCallback successCallback, optional ErrorCallback? errorCallback)
    + +
    void getVariants (WidgetVariantsCallback successCallback, optional ErrorCallback? errorCallback)
    + +
    void removeStateChangeListener (long watchId)
    +
    WidgetSize
    WidgetVariant
    WidgetInstance +
    void changeUpdatePeriod (double seconds)
    +
    void sendContent (Object data, boolean updateIfPaused)
    +
    void getContent (WidgetContentCallback successCallback, ErrorCallback errorCallback)
    +
    WidgetArraySuccessCallback
    void onsuccess (Widget[] widgets)
    WidgetInstancesCallback
    void onsuccess (WidgetInstance[] instances)
    WidgetVariantsCallback
    void onsuccess (WidgetVariant[] instances)
    WidgetContentCallback
    void onsuccess (Object data)
    WidgetChangeCallback
    void onchange (WidgetInstance instance, WidgetStateType event)
    +
    +

    1. Type Definitions

    +
    +

    1.1. WidgetId

    +
    + The unique ID of the installed widget. +
    +
      typedef DOMString WidgetId;
    +

    + Since: + 2.3.2 +

    +
    +
    +

    1.2. WidgetInstanceId

    +
    + The unique ID of the installed widget instance. +
    +
      typedef DOMString WidgetInstanceId;
    +

    + Since: + 2.3.2 +

    +
    +
    +

    1.3. WidgetSizeType

    +
    + The WidgetSizeType enumeration lists supported widget size types. +
    +
      enum WidgetSizeType {
    +    "1x1", "2x1", "2x2", "4x1", "4x2", "4x3", "4x4", "4x5", "4x6",
    +    "EASY_1x1", "EASY_3x1", "EASY_3x3",
    +    "FULL"
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    +The size types defines the following types (pixel size is given for a 720x1280 resolution): +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Size type +Size in pixels +Supported profile
    +1x1 +175x175 +This size type is not used. just defined for specifying a default cell size
    +2x1 +354x175 +Mobile
    +2x2 +354x354 +Mobile, Wearable
    +4x1 +712x175 +Mobile
    +4x2 +712x354 +Mobile
    +4x3 +712x533 +Mobile
    +4x4 +712x712 +Mobile
    +4x5 +712x891 +Mobile
    +4x6 +712x1070 +Mobile
    +EASY_1x1 +224x215 +Mobile
    +EASY_3x1 +680x215 +Mobile
    +EASY_3x3 +680x653 +Mobile
    +FULL +720x1280 +Mobile
    +
    +
    +
    +

    1.4. WidgetStateType

    +
    + Enumeration for types of lifetime events of a Widget. +
    +
      enum WidgetStateType {"CREATE", "DESTROY", "PAUSE", "RESUME"};
    +

    + Since: + 2.3.2 +

    +
    +
      +
    • +CREATE - the widget was created
    • +
    • +DESTROY - the widget was destroyed
    • +
    • +PAUSE - the widget was paused
    • +
    • +RESUME - the widget was resumed
    • +
    +

    +Widget lifetime events can be monitored with the addStateChangeListener() method +of the Widget interface. +

    +
    +
    +
    +
    +

    2. Interfaces

    +
    +

    2.1. WidgetServiceManagerObject

    +
    + This interface defines what is instantiated by the Tizen object on the Tizen Platform. +
    +
      [NoInterfaceObject] interface WidgetServiceManagerObject {
    +      readonly attribute WidgetServiceManager widget;
    +  };
    +
      Tizen implements WidgetServiceManagerObject;
    +

    + Since: + 2.3.2 +

    +
    +

    +The tizen.widgetservice object provides access to the Widget service API's functionality. +

    +
    +
    +
    +

    2.2. WidgetServiceManager

    +
    + The WidgetServiceManager interface provides methods for accessing information about widgets. +
    +
      [NoInterfaceObject] interface WidgetServiceManager {
    +    Widget getWidget(WidgetId widgetId) raises(WebAPIException);
    +
    +    void getWidgets(WidgetArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional PackageId? packageId) raises(WebAPIException);
    +
    +    WidgetId getPrimaryWidgetId((PackageId or ApplicationId) id) raises(WebAPIException);
    +
    +    WidgetSize getSize(WidgetSizeType sizeType) raises(WebAPIException);
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    Methods

    +
    +
    +getWidget +
    +
    +
    + Retrieves a Widget object with a given widgetId. +
    +
    Widget getWidget(WidgetId widgetId);
    +             
    +

    + Since: + 2.3.2 +

    +

    + Privilege level: + public +

    +

    + Privilege: + http://tizen.org/privilege/widget.viewer +

    +
    +

    Parameters:

    +
      +
    • +widgetId: + The ID of the Widget to retrieve +
    • +
    +
    +
    +

    Return value:

    + Widget The Widget object +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type SecurityError, if the application does not have the privilege to use this function. +

      • +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      • + with error type IOError, if a DB operation has failed. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   console.log("Widget id is " + widget.id);
    +   console.log("Widget details:");
    +   console.log("Main application id: " + widget.applicationId);
    +   console.log("Package id: " + widget.packageId);
    +   console.log("Is hidden in the list of widgets: " + widget.noDisplay);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Widget id is org.tizen.gallery.widget
    + Widget details:
    + Main application id: org.tizen.gallery
    + Package id: org.tizen.gallery
    + Is hidden in the list of widgets: false
    + 
    +
    +
    +
    +getWidgets +
    +
    +
    + Retrieves a list of all widgets. If package id is provided returned list contains widgets included in a given package only. +
    +
    void getWidgets(WidgetArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional PackageId? packageId);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    +The errorCallback is launched with these error types: +

    +
      +
    • +InvalidValuesError - If any of the input parameters contain an invalid value.
    • +
    • +IOError - If a DB operation has failed.
    • +
    • +AbortError - If the operation cannot be finished properly.
    • +
    +
    +

    + Privilege level: + public +

    +

    + Privilege: + http://tizen.org/privilege/widget.viewer +

    +
    +

    Parameters:

    +
      +
    • +successCallback: + A function to call when widgets are retrieved successfully +
    • +
    • +errorCallback [optional] [nullable]: + A function to call when an error occurs +
    • +
    • +packageId [optional] [nullable]: + If this parameter is given, then only widgets belonging to the given package are returned +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to use this function. +

      • +
      +
    +
    +
    +

    Code example:

     tizen.widgetservice.getWidgets(function (widgets) {
    +   console.log("There are " + widgets.length + " available widgets");
    + }, function (error) {
    +    console.log("Error: " + error.message);
    + });
    + 
    +
    +
    +

    Output example:

     There are 3 available widgets
    + 
    +
    +
    +
    +getPrimaryWidgetId +
    +
    +
    + Returns the primary widget ID of the specified package or application. +
    +
    WidgetId getPrimaryWidgetId((PackageId or ApplicationId) id);
    +             
    +

    + Since: + 2.3.2 +

    +

    + Privilege level: + public +

    +

    + Privilege: + http://tizen.org/privilege/widget.viewer +

    +
    +

    Parameters:

    +
      +
    • +id: + Package or Application ID +
    • +
    +
    +
    +

    Return value:

    + WidgetId The ID of the widget +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type SecurityError, if the application does not have the privilege to use this function. +

      • +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      • + with error type IOError, if a DB operation has failed. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable id should contain valid id of the application or package.
    + var id = "org.tizen.gallery";
    + try {
    +   var widgetId = tizen.widgetservice.getPrimaryWidgetId(id);
    +   console.log("Widget id is " + widgetId);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Widget id is org.tizen.gallery.widget
    + 
    +
    +
    +
    +getSize +
    +
    +
    + Returns the size coresponding to the given sizeType. +
    +
    WidgetSize getSize(WidgetSizeType sizeType);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +sizeType: + WidgetSizeType used for retrieving corresponding pixel size object. +
    • +
    +
    +
    +

    Return value:

    + WidgetSize An object which contains width and height. +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      +
    +
    +
    +

    Code example:

     //variable sizeType should contain supported size type
    + var sizeType = "4x4";
    + try {
    +   var widgetSize = tizen.widgetservice.getSize(sizeType);
    +   console.log("Widget size width: " + widgetSize.width + ", height: " + widgetSize.height);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Widget size width: 712, height: 712
    + 
    +
    +
    +
    +
    +
    +
    +

    2.3. Widget

    +
    + The Widget interface provides access to a single Widget installed on the system. +
    +
      [NoInterfaceObject] interface Widget {
    +    readonly attribute WidgetId id;
    +
    +    readonly attribute ApplicationId applicationId;
    +
    +    readonly attribute ApplicationId? setupApplicationId;
    +
    +    readonly attribute PackageId packageId;
    +
    +    readonly attribute boolean noDisplay;
    +
    +    DOMString getName(optional DOMString? locale) raises(WebAPIException);
    +    void getInstances(WidgetInstancesCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +
    +    WidgetVariant getVariant(WidgetSizeType sizeType) raises(WebAPIException);
    +
    +    void getVariants(WidgetVariantsCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +
    +    long addStateChangeListener(WidgetChangeCallback listener) raises(WebAPIException);
    +
    +    void removeStateChangeListener(long watchId) raises(WebAPIException);
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    Attributes

    +
      +
    • + readonly +WidgetId id
      + Widget ID. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +ApplicationId applicationId
      + Main application ID. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +ApplicationId setupApplicationId [nullable]
      + Setup application ID. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +PackageId packageId
      + The ID of the package this widget was installed with. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +boolean noDisplay
      + true if the widget should be hidden in the list of widgets. +
      +
      +

      +Precondition: Widget tag in the config.xml file includes the "nodisplay" attribute. +

      +
      +

      + Since: + 2.3.2 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +getName +
    +
    +
    + Returns a name of the widget in a given locale. +
    +
    DOMString getName(optional DOMString? locale);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +locale [optional] [nullable]: + Locale ("en-us", "ko-kr", ...). If null, then the default system locale is used. +
    • +
    +
    +
    +

    Return value:

    + DOMString The name of the widget. +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   var name = widget.getName("en-us");
    +   console.log("Widget name is " + name);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Widget name is Gallery
    + 
    +
    +
    +
    +getInstances +
    +
    +
    + Retrieves Widget instances (elements that have been added to the screen). Widget instance as opposed to the widget interface (which is abstarct of application), is a specified application. +
    +
    void getInstances(WidgetInstancesCallback successCallback, optional ErrorCallback? errorCallback);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    +The errorCallback is launched with these error types: +

    +
      +
    • +AbortError - If the operation cannot be finished properly.
    • +
    +
    +
    +

    Parameters:

    +
      +
    • +successCallback: + A function to call when widgets are retrieved successfully +
    • +
    • +errorCallback [optional] [nullable]: + A function to call when an error occurs +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      +
    +
    +
    +

    Code example:

     widgetSuccessCb = function(instances) {
    +   console.log("Instances array size: " + instances.length);
    + }
    +
    + widgetErrorCb = function(error) {
    +   console.log("Error occurred: " + error.name + ": " + error.message);
    + }
    +
    + //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   widget.getInstances(widgetSuccessCb, widgetErrorCb);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Instances array size: 3
    + 
    +
    +
    +
    +getVariant +
    +
    +
    + Returns object representing widget information related to a given sizeType. +
    +
    WidgetVariant getVariant(WidgetSizeType sizeType);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +sizeType: + WidgetSizeType value that information will be returned about. +
    • +
    +
    +
    +

    Return value:

    + WidgetVariant Size variant info +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidValuesError, if any of the input parameters contain an invalid value. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   var variant = widget.getVariant("4x4");
    +   console.log("Variant preview image path is " + variant.previewImagePath);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Variant preview image path is /usr/share/icons/default/small/preview_gallery_4x4.png
    + 
    +
    +
    +
    +getVariants +
    +
    +
    + Retrieves Wiget Variants representing all of the supported widget size types. +
    +
    void getVariants(WidgetVariantsCallback successCallback, optional ErrorCallback? errorCallback);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    +The errorCallback is launched with these error types: +

    +
      +
    • +AbortError - If the operation cannot be finished properly.
    • +
    +
    +
    +

    Parameters:

    +
      +
    • +successCallback: + A function to call when widgets are retrieved successfully +
    • +
    • +errorCallback [optional] [nullable]: + A function to call when an error occurs +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      +
    +
    +
    +

    Code example:

     widgetSuccessCb = function(variants) {
    +   console.log("Variants array size: " + variants.length);
    + }
    +
    + widgetErrorCb = function(error) {
    +   console.log("Error occurred: " + error.name + ": " + error.message);
    + }
    +
    + //variable id should contain valid id of the installed widget
    + var id = "org.tizen.gallery.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   widget.getVariants(widgetSuccessCb, widgetErrorCb);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Variants array size: 4
    + 
    +
    +
    +
    +addStateChangeListener +
    +
    +
    + Registers a callback which will be called whenever any of this widget instances state changes. +
    +
    long addStateChangeListener(WidgetChangeCallback listener);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +listener: + The callback +
    • +
    +
    +
    +

    Return value:

    + long The watch ID used to unregister the callback +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidValuesError, if any input parameters do not contain a valid value. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     widgetChangeCb = function(instance, event) {
    +   console.log("Instance " + instance.id + " is " + event);
    + }
    +
    + //variable id should contain valid id of the installed widget
    + var id = "org.tizen.music-player.widget";
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   var watchId = widget.addStateChangeListener(widgetChangeCb);
    +   console.log("Listener with id " + watchId + " has been added");
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Listener with id 1 has been added.
    + Instance org.tizen.music-player.widget is RESUME
    + 
    +
    +
    +
    +removeStateChangeListener +
    +
    +
    + Unregisters a callback registered under the given watchId. +
    +
    void removeStateChangeListener(long watchId);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +watchId: + The ID of the registered listener +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type NotFoundError, if listener with given watchId not exists. +

      • +
      • + with error type InvalidValuesError, if any input parameters do not contain a valid value. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     widgetChangeCb = function(instance, event) {
    +   console.log("Instance " + instance.id + " is " + event);
    +   widget.removeStateChangeListener(watchId);
    +   console.log("Listener with id " + watchId + " has been removed");
    + }
    +
    + //variable id should contain valid id of the installed widget
    + var id = "org.tizen.music-player.widget";
    + var watchId;
    +
    + try {
    +   var widget = tizen.widgetservice.getWidget(id);
    +   watchId = widget.addStateChangeListener(widgetChangeCb);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Listener with id 1 has been removed.
    + 
    +
    +
    +
    +
    +
    +
    +

    2.4. WidgetSize

    +
    + The WidgetSize interface contains width and height of a widget area. +
    +
      [NoInterfaceObject] interface WidgetSize {
    +    readonly attribute long width;
    +    readonly attribute long height;
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    Attributes

    +
      +
    • + readonly +long width
      + The horizontal dimension of the area in pixels. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +long height
      + The vertical dimension of the area in pixels. +
      +

      + Since: + 2.3.2 +

      +
    • +
    +
    +
    +
    +

    2.5. WidgetVariant

    +
    + The WidgetVariant interface provides Widget information related to specific sizeType. +
    +
      [NoInterfaceObject] interface WidgetVariant {
    +    readonly attribute WidgetSizeType sizeType;
    +
    +    readonly attribute long width;
    +
    +    readonly attribute long height;
    +
    +    readonly attribute DOMString previewImagePath;
    +
    +    readonly attribute boolean needsMouseEvents;
    +
    +    readonly attribute boolean needsTouchEffect;
    +
    +    readonly attribute boolean needsFrame;
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    Attributes

    +
      +
    • + readonly +WidgetSizeType sizeType
      + The WidgetSizeType this WidgetVariant describes. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +long width
      + Pixel width. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +long height
      + Pixel height. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +DOMString previewImagePath
      + The preview image path. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +boolean needsMouseEvents
      + true if the widget was designed to receive mouse events. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +boolean needsTouchEffect
      + true if the widget expects the system to show touch effect. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +boolean needsFrame
      + true if the widget expects the system to draw a frame. +
      +

      + Since: + 2.3.2 +

      +
    • +
    +
    +
    +
    +

    2.6. WidgetInstance

    +
    + The WidgetInstance interface provides access to a single instance of the Widget. +
    +
      [NoInterfaceObject] interface WidgetInstance {
    +    readonly attribute Widget widget;
    +
    +    readonly attribute WidgetInstanceId id;
    +
    +    void changeUpdatePeriod(double seconds) raises(WebAPIException);
    +
    +    void sendContent(Object data, boolean updateIfPaused) raises(WebAPIException);
    +
    +    void getContent(WidgetContentCallback successCallback, ErrorCallback errorCallback) raises(WebAPIException);
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    +Every visual widget element added to the home screen is a single instance of some Widget. +

    +
    +
    +

    Attributes

    +
      +
    • + readonly +Widget widget
      + The Widget this instance belongs to. +
      +

      + Since: + 2.3.2 +

      +
    • +
    • + readonly +WidgetInstanceId id
      + The unique ID of the widget instance. +
      +

      + Since: + 2.3.2 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +changeUpdatePeriod +
    +
    +
    + Changes the interval between automatic update of the widget instance data. Minimum value is 1 second. +
    +
    void changeUpdatePeriod(double seconds);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +seconds: + The interval in seconds +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidValuesError, if any input parameters do not contain a valid value. Minimum value is 1 second. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable instance should contain valid WidgetInstance object obtained by getInstances() method.
    + var instance;
    + var period = 2;
    +
    + try {
    +   instance.changeUpdatePeriod(period);
    +   console.log("Update period has been set to " + period + " seconds");
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Update period has been set to 2 seconds.
    + 
    +
    +
    +
    +sendContent +
    +
    +
    + Sends a new content data to the Widget Instance. +
    +
    void sendContent(Object data, boolean updateIfPaused);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    +This function does not wait for a confirmation that the data was updated. +

    +
    +
    +

    Parameters:

    +
      +
    • +data: + The new content data +
    • +
    • +updateIfPaused: + true if you want to update your widget even if the provider is paused +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type IOError, if a DB operation has failed. +

      • +
      • + with error type AbortError, if the operation cannot be finished properly. +

      • +
      +
    +
    +
    +

    Code example:

     //variable instance should contain valid WidgetInstance object obtained by getInstances() method.
    + var instance;
    +
    + var data = {
    +  data1 : 'test1',
    +  data2 : 'test2'
    + };
    +
    + try {
    +   instance.sendContent(data, true);
    +   console.log("Data has been successfully sent");
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Data has been successfully sent
    + 
    +
    +
    +
    +getContent +
    +
    +
    + Retrieves content data from the Widget Instance. +
    +
    void getContent(WidgetContentCallback successCallback, ErrorCallback errorCallback);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    +The errorCallback is launched with these error types: +

    +
      +
    • +InvalidValuesError - If any of the input parameters contain an invalid value
    • +
    • +IOError - If a DB operation has failed
    • +
    • +AbortError - If the operation cannot be finished properly.
    • +
    +
    +
    +

    Parameters:

    +
      +
    • +successCallback: + A function to call when data is retrieved successfully +
    • +
    • +errorCallback: + A function to call when an error occurs +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter. +

      +
    +
    +
    +

    Code example:

     //variable instance should contain valid WidgetInstance object obtained by getInstances() method.
    + var instance;
    +
    + contentSuccessCb = function(data) {
    +  console.log("Data has been obtained successfully");
    +  for (var prop in data) {
    +    console.log(prop + " : " + data[prop]);
    +  }
    + }
    +
    + contentErrorCb = function(error) {
    +  console.log("Error occurred: " + error.name + ":" + error.message);
    + }
    +
    + try {
    +   instance.getContent(contentSuccessCb, contentErrorCb);
    + } catch (error) {
    +   console.log("Error: " + error.message);
    + }
    + 
    +
    +
    +

    Output example:

     Data has been obtained successfully
    + data1 : test1
    + data2 : test2
    + 
    +
    +
    +
    +
    +
    +
    +

    2.7. WidgetArraySuccessCallback

    +
    + The WidgetArraySuccessCallback interface implements the success callback used in the asynchronous operation to get a list of widgets using the getWidgets() method. +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetArraySuccessCallback {
    +    void onsuccess(Widget[] widgets);
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the array of Widget objects is retrieved successfully. +
    +
    void onsuccess(Widget[] widgets);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +widgets: + Array of Widget objects. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.8. WidgetInstancesCallback

    +
    + The WidgetInstancesCallback interface implements the success callback used in the asynchronous operation to get a list of widget instances using the getInstances() method. +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetInstancesCallback {
    +    void onsuccess(WidgetInstance[] instances);
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the array of WidgetInstance objects is retrieved successfully. +
    +
    void onsuccess(WidgetInstance[] instances);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +instances: + Array of WidgetInstance objects. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.9. WidgetVariantsCallback

    +
    + The WidgetVariantsCallback interface implements the success callback used in the asynchronous operation to get a list of widget variant using the getVariants() method. +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetVariantsCallback {
    +    void onsuccess(WidgetVariant[] instances);
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the array of WidgetVariants objects is retrieved successfully. +
    +
    void onsuccess(WidgetVariant[] instances);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +instances: + Array of WidgetVariants objects. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.10. WidgetContentCallback

    +
    +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetContentCallback {
    +    void onsuccess(Object data);
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the content of the widget instance is retrieved successfully. +
    +
    void onsuccess(Object data);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +data: + Content of the given widget instance. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.11. WidgetChangeCallback

    +
    + The WidgetChangeCallback describes a callback for the addStateChangeListener() method. +
    +
      [NoInterfaceObject, Callback=FunctionOnly] interface WidgetChangeCallback {
    +    void onchange(WidgetInstance instance, WidgetStateType event);
    +  };
    +

    + Since: + 2.3.2 +

    +
    +

    Methods

    +
    +
    +onchange +
    +
    +
    + Called when the instance state was changed. +
    +
    void onchange(WidgetInstance instance, WidgetStateType event);
    +             
    +

    + Since: + 2.3.2 +

    +
    +

    Parameters:

    +
      +
    • +instance: + Widget instance id that change is related to. +
    • +
    • +event: + Event of widget life cycle. +
    • +
    +
    +
    +
    +
    +
    +
    +

    3. Related Feature

    +
    + You can check if this API is supported with tizen.systeminfo.getCapability() and decide enable/disable codes that need this API. +
    +

    +

    +To guarantee that the widget application runs on a system which supports Widgets, declare the following feature requirements in the config file: +

    +

    +
  • http://tizen.org/feature/shell.appwidget
  • +
    +

    + For more information, see Application Filtering. +
    +

    4. Full WebIDL

    +
    module WidgetService {
    +  typedef DOMString WidgetId;
    +
    +  typedef DOMString WidgetInstanceId;
    +
    +  enum WidgetSizeType {
    +    "1x1", "2x1", "2x2", "4x1", "4x2", "4x3", "4x4", "4x5", "4x6",
    +    "EASY_1x1", "EASY_3x1", "EASY_3x3",
    +    "FULL"
    +  };
    +
    +  enum WidgetStateType {"CREATE", "DESTROY", "PAUSE", "RESUME"};
    +
    +  [NoInterfaceObject] interface WidgetServiceManagerObject {
    +      readonly attribute WidgetServiceManager widget;
    +  };
    +  Tizen implements WidgetServiceManagerObject;
    +
    +  [NoInterfaceObject] interface WidgetServiceManager {
    +    Widget getWidget(WidgetId widgetId) raises(WebAPIException);
    +
    +    void getWidgets(WidgetArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional PackageId? packageId) raises(WebAPIException);
    +
    +    WidgetId getPrimaryWidgetId((PackageId or ApplicationId) id) raises(WebAPIException);
    +
    +    WidgetSize getSize(WidgetSizeType sizeType) raises(WebAPIException);
    +  };
    +
    +  [NoInterfaceObject] interface Widget {
    +    readonly attribute WidgetId id;
    +
    +    readonly attribute ApplicationId applicationId;
    +
    +    readonly attribute ApplicationId? setupApplicationId;
    +
    +    readonly attribute PackageId packageId;
    +
    +    readonly attribute boolean noDisplay;
    +
    +    DOMString getName(optional DOMString? locale) raises(WebAPIException);
    +    void getInstances(WidgetInstancesCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +
    +    WidgetVariant getVariant(WidgetSizeType sizeType) raises(WebAPIException);
    +
    +    void getVariants(WidgetVariantsCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +
    +    long addStateChangeListener(WidgetChangeCallback listener) raises(WebAPIException);
    +
    +    void removeStateChangeListener(long watchId) raises(WebAPIException);
    +  };
    +
    +  [NoInterfaceObject] interface WidgetSize {
    +    readonly attribute long width;
    +    readonly attribute long height;
    +  };
    +
    +  [NoInterfaceObject] interface WidgetVariant {
    +    readonly attribute WidgetSizeType sizeType;
    +
    +    readonly attribute long width;
    +
    +    readonly attribute long height;
    +
    +    readonly attribute DOMString previewImagePath;
    +
    +    readonly attribute boolean needsMouseEvents;
    +
    +    readonly attribute boolean needsTouchEffect;
    +
    +    readonly attribute boolean needsFrame;
    +  };
    +
    +  [NoInterfaceObject] interface WidgetInstance {
    +    readonly attribute Widget widget;
    +
    +    readonly attribute WidgetInstanceId id;
    +
    +    void changeUpdatePeriod(double seconds) raises(WebAPIException);
    +
    +    void sendContent(Object data, boolean updateIfPaused) raises(WebAPIException);
    +
    +    void getContent(WidgetContentCallback successCallback, ErrorCallback errorCallback) raises(WebAPIException);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetArraySuccessCallback {
    +    void onsuccess(Widget[] widgets);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetInstancesCallback {
    +    void onsuccess(WidgetInstance[] instances);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetVariantsCallback {
    +    void onsuccess(WidgetVariant[] instances);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetContentCallback {
    +    void onsuccess(Object data);
    +  };
    +
    +  [NoInterfaceObject, Callback=FunctionOnly] interface WidgetChangeCallback {
    +    void onchange(WidgetInstance instance, WidgetStateType event);
    +  };
    +};
    +
    + + + diff --git a/org.tizen.web.apireference/html/index.htm b/org.tizen.web.apireference/html/index.htm index cbdee44..211a517 100644 --- a/org.tizen.web.apireference/html/index.htm +++ b/org.tizen.web.apireference/html/index.htm @@ -49,7 +49,8 @@
  • Message Port
  • Notification
  • Package
  • -
  • Preference
  • +
  • Preference
  • +
  • WidgetService
  • Network @@ -143,6 +144,7 @@
  • Message Port
  • Notification
  • Package
  • +
  • WidgetService
  • Content -- 2.7.4