From: Jakub Skowron Date: Fri, 13 May 2016 08:33:46 +0000 (+0200) Subject: Cordova tutorials and guide: Events X-Git-Tag: tizen_3.0/TD_SYNC/20161201~81^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=80d430d4a4fa95d3e02721d6aa23044ce4037ed5;p=sdk%2Fonline-doc.git Cordova tutorials and guide: Events Change-Id: I28c82e7818f01dfa03f8ee8d39272eaa4670ad6c Signed-off-by: Jakub Skowron --- diff --git a/org.tizen.guides/html/index.htm b/org.tizen.guides/html/index.htm index 69f6a1a..e21551b 100644 --- a/org.tizen.guides/html/index.htm +++ b/org.tizen.guides/html/index.htm @@ -309,6 +309,7 @@
  • Device
  • Device Motion
  • Dialogs
  • +
  • Events
  • File Transfer
  • Globalization
  • Network Information
  • diff --git a/org.tizen.guides/html/web/tizen/cordova/cordova_guide_w.htm b/org.tizen.guides/html/web/tizen/cordova/cordova_guide_w.htm index eb6429d..270bdb7 100644 --- a/org.tizen.guides/html/web/tizen/cordova/cordova_guide_w.htm +++ b/org.tizen.guides/html/web/tizen/cordova/cordova_guide_w.htm @@ -40,6 +40,7 @@
  • Device

    Information on model, platform and installed version of Cordova.

  • Device Motion

    Access to the device's accelerometer.

  • Dialogs

    Make different types of input dialog boxes and notifications to the user.

  • +
  • Events

    Information about events defined in cordova.

  • Network Information

    information about connection (cellular, WiFi, ethernet, etc.) and connection related events

  • File Transfer

    How to download and upload files using Cordova

  • Globalization

    How to obtain information and performs operations specific to the user's locale, language and timezone

  • diff --git a/org.tizen.guides/html/web/tizen/cordova/events_w.htm b/org.tizen.guides/html/web/tizen/cordova/events_w.htm new file mode 100644 index 0000000..e9d1876 --- /dev/null +++ b/org.tizen.guides/html/web/tizen/cordova/events_w.htm @@ -0,0 +1,131 @@ + + + + + + + + + + + + + Events + + + + + +
    +

    Events

    + + +

    This module defines events provided by Cordova for use in Web API applications. Applicaton can add custom listeners for these events. The listeners take no arguments. +

    Module has no objects or properties.

    + +

    Events

    +
      +
    • deviceready +

      Signals that Cordova's device APIs have loaded and are ready to access.

      +
    • +
    • pause +

      Signals that application is put into the background. Typically when screen is being locked or when user switches to a different application.

      +
    • +
    • resume +

      Signals that application is retrieved from the background.

      +
    • + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Table: Button Press Events
    EventButton name
    backbuttonBack button
    menubuttonMenu button
    searchbuttonSearch button
    startcallbuttonStart call button
    endcallbuttonEnd call button
    volumedownbuttonVolume down button
    volumeupbuttonVolume up button
    + +

    See tutorial: How to add button press event listeners.

    + +

    Adding event listeners

    +

    Applications typically should use document.addEventListener() to attach an event listener once the deviceready event fires. +This means adding event listeners for events like pause, resume, backbutton, etc. during or after deviceready event handler.

    +

    Example:

    +
    +document.addEventListener("deviceready", onDeviceReady, false);
    +
    +function onDeviceReady() {
    +    document.addEventListener("pause", onPause);
    +    document.addEventListener("volumeupbutton", onVolumeUp);
    +}
    +
    +function onPause() {
    +    console.log("Application has been put into the background");
    +}
    +
    +function onVolumeUp() {
    +    console.log("Volume up button pressed");
    +}
    +
    +
    + + + +
    + +Go to top + + + + + + + diff --git a/org.tizen.tutorials/html/index.htm b/org.tizen.tutorials/html/index.htm index cb1e70e..f72aa4c 100644 --- a/org.tizen.tutorials/html/index.htm +++ b/org.tizen.tutorials/html/index.htm @@ -323,6 +323,7 @@
  • Device
  • Device Motion
  • Dialogs
  • +
  • Events
  • Network Information
  • File Transfer
  • Globalization
  • diff --git a/org.tizen.tutorials/html/web/tizen/cordova/cordova_tutorials_w.htm b/org.tizen.tutorials/html/web/tizen/cordova/cordova_tutorials_w.htm index ff02c87..076a99f 100644 --- a/org.tizen.tutorials/html/web/tizen/cordova/cordova_tutorials_w.htm +++ b/org.tizen.tutorials/html/web/tizen/cordova/cordova_tutorials_w.htm @@ -44,6 +44,8 @@

    Demonstrates how you can get access to the device's accelerometer.

  • Dialogs: dialog boxes and notifications

    Demonstrates how how to make different types of dialog boxes: alert, confirm, and prompt. Also demonstrates how to make a beep sound.

  • +
  • Events: events provided by Cordova for use in Web API applications +

    Demonstrates how you can register and use custom listeners for events like deviceready, pause, resume, and button press events.

  • Network Information: getting information and status of network connections

    Demonstrates how you can retrieve information about connection (cellular, WiFi, ethernet, etc.) and how to use connection related events

  • File Transfer: transfering files diff --git a/org.tizen.tutorials/html/web/tizen/cordova/events_tutorial_w.htm b/org.tizen.tutorials/html/web/tizen/cordova/events_tutorial_w.htm new file mode 100644 index 0000000..0395645 --- /dev/null +++ b/org.tizen.tutorials/html/web/tizen/cordova/events_tutorial_w.htm @@ -0,0 +1,125 @@ + + + + + + + + + + + + + Events: events provided by Cordova for use in Web API applications + + + + + + +
    + +

    Events: events provided by Cordova for use in Web API applications

    + +

    This tutorial demonstrates how you can register and use custom listeners for events like deviceready, pause, resume, and button press events.

    + +

    Waiting for deviceready event

    +

    This event signals that Cordova's device APIs have loaded and are ready to access. You should wait until this event is fired, and after that you +can start using Cordova features.

    + +
      +
    1. Prepare handler for the event:

      +
      function onDeviceReady() {
      +  // Now safe to use Cordova
      +}
      +
      +
    2. +
    3. Add event listener:

      +
      document.addEventListener('deviceready', onDeviceReady);
      +
    4. +
    +

    Alternatively you can add deviceready event listener in <body> onload hadler, for example:

    +
    window.onload = function() {
    +    document.addEventListener("deviceready", onDeviceReady);
    +};
    + +

    Pause and resume events

    +

    We will add event listeners for pause and resume events.

    +

    Pause signals that application is put into the background. Typically when screen is being locked or when user switches to a different application. Resume signals tha native platform pulls the application out from the background.

    + +
      +
    1. Prepare our event handlers for pause and resume events.

      +

      +function onPause() {
      +    console.log("Application paused");
      +}
      +
      +function onResume() {
      +    console.log("Application resumed");
      +}
      +
    2. +
    3. Add event listeners in deviceready event handler (see onDeviceReady above).

      +

      document.addEventListener("pause", onPause);
      +document.addEventListener("resume", onResume);
      +
    4. +
    + +

    Button press events

    +

    We will add event listeners for menu, volume up and volume down buttons. Each event is triggered when corresponding button is pressed.

    + +
      +
    1. Prepare our event handlers for menubutton, volumeupbutton, and volumeupbutton events.

      +

      +function onVolumeChanged() {
      +    console.log("Volume changed");
      +}
      +
      +function onMenuButton() {
      +    console.log("Menu button pressed");
      +}
      +
    2. +
    3. In deviceready event handler (see onDeviceReady above) add listeners. For this example will use one listener for both volume up and down buttons.

      +

      document.addEventListener("menubutton", onMenuButton);
      +document.addEventListener("volumeupbutton", onVolumeChanged);
      +document.addEventListener("volumedownbutton", onVolumeChanged);
      +
    4. +
    +

    Now press buttons and see results in system console.

    + + + + +
    + +Go to top + + + + + + +