From: Andrzej Popowski Date: Thu, 28 Jan 2016 10:22:30 +0000 (+0100) Subject: [Application] - Improving examples X-Git-Tag: tizen_3.0/TD_SYNC/20161201~178^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8451358e0191386e58184e676658255600383154;p=sdk%2Fonline-doc.git [Application] - Improving examples Change-Id: I3b1e4f7f11d4efef8b74f890f2b9be9c77293149 Signed-off-by: Andrzej Popowski --- diff --git a/org.tizen.web.apireference/html/device_api/mobile/tizen/application.html b/org.tizen.web.apireference/html/device_api/mobile/tizen/application.html index dd2308b..e742a01 100644 --- a/org.tizen.web.apireference/html/device_api/mobile/tizen/application.html +++ b/org.tizen.web.apireference/html/device_api/mobile/tizen/application.html @@ -1268,15 +1268,15 @@ applications on a device.

Code example:

 var appEventCallback = {
-    oninstalled: function(appInfo) {
-       console.log('The application ' + appInfo.name + ' is installed');
-    },
-    onupdated: function(appInfo) {
-       console.log('The application ' + appInfo.name + ' is updated');
-    },
-    onuninstalled: function(appid) {
-       console.log('The application ' + appid + ' is uninstalled');
-    }
+   oninstalled: function(appInfo) {
+     console.log('The application ' + appInfo.name + ' is installed');
+   },
+   onupdated: function(appInfo) {
+     console.log('The application ' + appInfo.name + ' is updated');
+   },
+   onuninstalled: function(appid) {
+     console.log('The application ' + appid + ' is uninstalled');
+   }
  };
  var watchId = tizen.application.addAppInfoEventListener(appEventCallback);
  tizen.application.removeAppInfoEventListener(watchId);
@@ -1465,11 +1465,11 @@ System events do not require an application identifier to be specified. Therefor
 

Parameters:

  • -event: +event: Event which will invoke the callback
  • -callback: +callback: Callback function to be invoked when the event occurs
@@ -1493,12 +1493,25 @@ System events do not require an application identifier to be specified. Therefor

Code example:

 var app = tizen.application.getCurrentApplication();
 
- // for user events: sender's application ID and event name must be provided by using a dictionary
- // Let's assume that there is another application installed with id "a234567890.TestWidget"
- var watchId = app.addEventListener({"appId": "a234567890.TestWidget", "name": "custom_user_event"}, function(event, data) {
-   console.log("Data: " + JSON.stringify(data));
-   // do something
- });
+ // for user events: sender's application ID  and event name must be provided by using a dictionary
+ // Let's assume that at least two applications are installed
+ function onListInstalledApps(appsInfo) {
+   var appId = null;
+
+   if (appsInfo.length > 0 && app.appInfo.id != appsInfo[0].id) {
+     appId = appsInfo[0].id;
+   } else if (appsInfo.length > 1) {
+     appId = appsInfo[1].id;
+   }
+
+   if (appId) {
+     var watchId = app.addEventListener({"appId": appId, "name": "custom_user_event"}, function(event, data) {
+       console.log("Data: " + JSON.stringify(data));
+       // do something
+     });
+   }
+ }
+ tizen.application.getAppsInfo(onListInstalledApps);
  
@@ -1519,7 +1532,7 @@ System events do not require an application identifier to be specified. Therefor

Parameters:

  • -watchId: +watchId: Listener identifier
@@ -1532,16 +1545,30 @@ System events do not require an application identifier to be specified. Therefor
-

Code example:

 var watchId, app = tizen.application.getCurrentApplication();
+

Code example:

 var app = tizen.application.getCurrentApplication();
 
- function eventListenerCallback(event, data) {
-   console.log("Data: " + JSON.stringify(data));
-   // do something and then remove the listener
-   app.removeEventListener(watchId);
+ // for user events: sender's application ID  and event name must be provided by using a dictionary
+ // Let's assume that at least two applications are installed
+ function onListInstalledApps(appsInfo) {
+   var appId = null;
+   var watchId = null;
+
+   if (appsInfo.length > 0 && app.appInfo.id != appsInfo[0].id) {
+     appId = appsInfo[0].id;
+   } else if (appsInfo.length > 1) {
+     appId = appsInfo[1].id;
+   }
+
+   if (appId) {
+     watchId = app.addEventListener({"appId": appId, "name": "custom_user_event"}, function(event, data) {
+       if (watchId) {
+         app.removeEventListener(watchId);
+         watchId = null;
+       }
+     });
+   }
  }
-
- // Let's assume that there is another application installed with id "a234567890.TestWidget"
- watchId = app.addEventListener({"appId": "a234567890.TestWidget", "name": "custom_user_event"}, eventListenerCallback);
+ tizen.application.getAppsInfo(onListInstalledApps);
  
@@ -1567,11 +1594,11 @@ An application can listen to events from other applications. However, it can onl

Parameters:

@@ -1624,11 +1651,11 @@ An application can listen to events from other applications. However, it can onl

Parameters:

@@ -2027,19 +2054,6 @@ required action requested by the calling application. Since: 2.0

-
-

Code example:

 var reqAppControl = tizen.application.getCurrentApplication().getRequestedAppControl();
- if (reqAppControl) {
-     console.log("Requester AppID : " + reqAppControl.callerAppId);
-
-     var appControl = reqAppControl.appControl;
-     if (appControl.operation == "http://tizen.org/appcontrol/operation/pick") {
-         var data = new tizen.ApplicationControlData("http://tizen.org/appcontrol/data/selected", ["Image1.jpg"]);
-         reqAppControl.replyResult([data]);
-     }
- }
- 
-

Attributes

    @@ -2106,6 +2120,19 @@ It contains the information that the calling application passed to launchApp
+
+

Code example:

 var reqAppControl = tizen.application.getCurrentApplication().getRequestedAppControl();
+ if (reqAppControl) {
+     console.log("Requester AppID : " + reqAppControl.callerAppId);
+
+     var appControl = reqAppControl.appControl;
+     if (appControl.operation == "http://tizen.org/appcontrol/operation/pick") {
+         var data = new tizen.ApplicationControlData("http://tizen.org/appcontrol/data/selected", ["Image1.jpg"]);
+         reqAppControl.replyResult([data]);
+     }
+ }
+ 
+
replyFailure @@ -2133,6 +2160,18 @@ to perform the requested action. +
+

Code example:

 var reqAppControl = tizen.application.getCurrentApplication().getRequestedAppControl();
+ if (reqAppControl) {
+     console.log("Requester AppID : " + reqAppControl.callerAppId);
+
+     var appControl = reqAppControl.appControl;
+     if (appControl.operation == "http://tizen.org/appcontrol/operation/pick") {
+         reqAppControl.replyFailure();
+     }
+ }
+ 
+
@@ -2262,6 +2301,15 @@ This callback interface specifies a success method with an array of +
+

Code example:

 function onListInstalledApps(applications) {
+     for (var i = 0; i < applications.length; i++)
+         console.log("ID : " + applications[i].id);
+ }
+
+ tizen.application.getAppsInfo(onListInstalledApps);
+ 
+
@@ -2313,6 +2361,45 @@ It is used in ApplicationManager.findAppControl(). The application control that is passed to ApplicationManager.findAppControl() +
+

Code example:

 var appControl = new tizen.ApplicationControl(
+     "http://tizen.org/appcontrol/operation/pick",
+     null,
+     "image/jpeg",
+     null);
+
+ // FindAppControlSuccessCallback instance
+ function successCB(appInfos, appControl)
+ {
+     // appControl is same object with the value passed as first parameter to findAppControl()
+     var appControlReplyCallback = {
+         // callee sent a reply
+         onsuccess: function(data) {
+             for (var i = 0; i < data.length; i++) {
+                 if (data[i].key == "http://tizen.org/appcontrol/data/selected") {
+                     console.log('Selected image is ' + data[i].value[0]);
+                 }
+             }
+         },
+         // callee returned failure
+         onfailure: function() {
+             console.log('The launch application control failed');
+         }
+     }
+
+     var appId = appInfos[0].id; // select first app's id
+
+     tizen.application.launchAppControl(
+         appControl,
+         appId,
+         function() {console.log("launch application control succeed"); },
+        function(e) {console.log("launch application control failed. reason: " + e.message); },
+        appControlReplyCallback );
+ }
+
+ tizen.application.findAppControl(appControl, successCB);
+ 
+
@@ -2389,6 +2476,37 @@ This callback interface specifies two methods: onfailure() - Invoked if the callee application calls RequestedApplicationControl.replyFailure(). +
+

Code example:

 var appControl = new tizen.ApplicationControl(
+     "http://tizen.org/appcontrol/operation/pick",
+     null,
+     "image/jpeg",
+     null);
+
+ // ApplicationControlDataArrayReplyCallback instance
+ var appControlReplyCallback = {
+     // callee sent a reply
+     onsuccess: function(data) {
+         for (var i = 0; i < data.length; i++) {
+             if (data[i].key == "http://tizen.org/appcontrol/data/selected") {
+                 console.log('Selected image is ' + data[i].value[0]);
+             }
+         }
+     },
+     // callee returned failure
+     onfailure: function() {
+         console.log('The launch application control failed');
+     }
+ }
+
+ tizen.application.launchAppControl(
+     appControl,
+     null,
+     function() {console.log("launch application control succeed"); },
+     function(e) {console.log("launch application control failed. reason: " + e.message); },
+     appControlReplyCallback );
+ 
+

Methods

@@ -2455,6 +2573,21 @@ This callback interface specifies methods that are invoked when an application is installed, updated, or uninstalled.

+
+

Code example:

 var appEventCallback = {
+    oninstalled: function(appInfo) {
+       console.log('The application ' + appInfo.name + ' is installed');
+    },
+    onupdated: function(appInfo) {
+       console.log('The application ' + appInfo.name + ' is updated');
+    },
+    onuninstalled: function(appid) {
+       console.log('The application ' + appid + ' is uninstalled');
+    }
+ };
+ var watchId = tizen.application.addAppInfoEventListener(appEventCallback);
+ 
+

Methods

@@ -2581,15 +2714,41 @@ Platform modules will be able to broadcast system events in a future Tizen relea

Parameters:

  • -event: +event: Broadcasted event which invokes this callback
  • -data: +data: Broadcasted event data
+
+

Code example:

 var app = tizen.application.getCurrentApplication();
+
+ // for user events: sender's application ID  and event name must be provided by using a dictionary
+ // Let's assume that at least two applications are installed
+ function onListInstalledApps(appsInfo) {
+   var appId = null;
+
+   if (appsInfo.length > 0 && app.appInfo.id != appsInfo[0].id) {
+     appId = appsInfo[0].id;
+   } else if (appsInfo.length > 1) {
+     appId = appsInfo[1].id;
+   }
+
+   var eventCB = function(event, data) {
+     console.log("Data: " + JSON.stringify(data));
+     // do something
+   };
+
+   if (appId) {
+     var watchId = app.addEventListener({"appId": appId, "name": "custom_user_event"}, eventCB);
+   }
+ }
+ tizen.application.getAppsInfo(onListInstalledApps);
+ 
+