• No se han encontrado resultados

Factores que influyen en la germinación

B. Las Semillas

3. Germinación de la semilla

3.1. Factores que influyen en la germinación

The Cordova framework exposes a set of events a developer can use to react to certain things that happen on the device running the Cordova application. In some cases, the exposed events deal with hardware-related activities such as changes in the battery status or a physical button press by the user. In other cases, the exposed events deal with application status changes such as the application being paused or resumed. The purpose of these events is to expose to a web application the same device status events that are available to native applications.

The complete list of supported events is provided in Table 12.1.

Table 12.1 CCoorrddoovvaa EEvveennttss

C

Coorrddoovvaa EEvveenntt DDeessccrriippttiioonn

backbutton Fired when the device’s back button is pressed by the user. batterycritical Fired when the device battery reaches critical status. What is considered critical varies across mobile device platforms. batterylow Fired when the device battery reaches low status. What is considered low varies across mobile device platforms. batterystatus Fires when the battery status changes by at least 1% (up or down). deviceready Fires when the Cordova container has finished initialization and is ready to be used. endcallbuton Fires when the user presses the phone’s end call button.

menubutton Fires when the user presses the device’s menu button. offline Fires when a device that has a network connection loses that connection. online Fires when a device goes online, when it switches from not having network connectivity to having network connectivity.

pause

Fires when the Cordova application is suspended. This typically happens when the device user switches to another application and the native OS pushes the current application to the background.

resume Fires when a paused application is brought to the foreground. searchbutton Fires when the device user presses the search button. startcallbutton Fires when the device user presses the start call button. volumedownbutton Fires when the device user presses the volume decrease button. volumeupbutton Fires when the device user presses the volume increase button.

R

Reeggaarrddiinngg BBuuttttoonnss

Older devices had physical menu buttons and physical buttons to start and end phone calls. On newer devices, those buttons have been removed and replaced with virtual buttons that appear only when needed (like the menu and search buttons) or are specific to an application (like the phone buttons).

ptg11524036 Most of the listed events are built into the Cordova container. Only battery status is implemented as a

plugin. To enable an application to monitor battery events, you must first add the battery status plugin to your project by issuing the following CLI command from the Cordova project folder:

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status.git

The devicready event was discussed at length in Chapter 5; to see examples of that event in action, refer to the HelloWorld applications highlighted in that chapter.

To monitor one of these events, you simply have to have an application register a listener for the particular event.

document.addEventListener("eventName", eventFunction);

As an example, to listen for the loss of network connectivity, you would register an offline event listener using the following code:

document.addEventListener("offline", isOffline); function isOffline() {

//Do whatever you want to do when the device goes offline }

The isOffline function is called whenever the Cordova application that has a network connection detects that it has lost the network connection.

W

Waarrnniinngg

The events might not fire exactly when you expect them to on different mobile platforms. Be sure to test your application on different physical devices to make sure your application works as expected.

H

Haarrddwwaarree AAPPIIss

Cordova exposes a few APIs that allow developers to build applications that interact with common hardware components found in most modern smartphones. These APIs help make Cordova applications feel more like native applications, as they let a Cordova application interact with the outside world in some way.

There’s no specific grouping of these APIs in the Cordova documentation; bundling them together under the banner of hardware APIs is just my way of keeping things organized. The following APIs are discussed in this section:

Accelerometer

Camera

Capture

Compass

Geolocation

ptg11524036 The Accelerator, Compass, and Geolocation APIs all work in essentially the same manner; your

application can measure the current value for the particular metric, or you can set up a watch that allows your application to monitor the particular metric as it changes over time. The Camera and Capture APIs both allow you to capture photographs using the device camera, but they operate differently, plus the Capture API allows you to record video and audio files as well.

The World Wide Web Consortium has worked on defining specifications for some of these capabilities. The Compass API is defined at http://dev.w3.org/2009/dap/system-info/compass.html, the Geolocation API specification is defined at http://dev.w3.org/geo/api/spec-source.html, and the Device Orientation specification is defined at http://dev.w3.org/geo/api/spec-source-orientation.

What you’ll find is that some of the Cordova APIs align closely with the W3C specifications and others do not. For example, the Cordova Compass API has a getCurrentHeading method, while the W3C specification uses getCurrentOrientation. I assume that the Cordova APIs will align with the standards over time; you will need to monitor progress and update your applications accordingly. In the sections that follow, I show you a little about how each of the APIs operates. Some of the APIs support a lot of options, so deep coverage is beyond the scope of this book; you can find complete examples of how to use each of these APIs in PhoneGap Essentials (www.phonegapessentials.com).

A