Making Use of PhoneGap’s Native Functions

0 BY sfeaster

Now that your project is set up and your application has been included, it’s important to understand the relationship between Enyo and PhoneGap.

When your application is first launched, PhoneGap will send a “deviceready” event to the document body. This event tells us that the application has been launched and PhoneGap has been loaded. It is at this point, where we can use Enyo to render our application.

Fortunately, Enyo 2 has added native support for listening to this event.
If you are using the latest Enyo 2 build in github ( https://github.com/enyojs/enyo ), you already have the needed file for this ability (enyo/source/dom/phonegap.js).

If you are using the recent public release (Enyo 2.0 beta 4), you will need to download the support package, found in the enyojs/extra repo ( https://github.com/enyojs/extra ). Then you will need to be sure to include that package in your application:

<script src="lib/extra/phonegap/package.js" type="text/javascript"></script>

Enyo 2 uses its “enyo.Signals” kind, in order to listen for when Cordova is ready to render our application. To do this, we need to add an Enyo listener to our document body.

<body>
    <script type="text/javascript">
        // tell enyo to listen for deviceready event
        enyo.dispatcher.listen(document, "deviceready");

        new App().renderInto(document.body);
    </script>
</body>

* Note that we must use App().renderInto(document.body) instead of App.write().
In order to respond to the event we have a listener for, we must add a “enyo.Signals” kind to our application.

enyo.kind({
  name: "App",
  components: [
    {kind: "Signals", ondeviceready: "deviceReady"},
    {content: "Hello world!"}
  ]
});

The full code for our example application is contained within index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>

    <title>Enyo Cordova WP7 Application</title>

   <!-- Cordova -->
    <script src="cordova-1.7.0.js" type="text/javascript" charset="utf-8"></script>

   <!-- Enyo -->
    <script src="enyo/enyo.js" type="text/javascript"></script>

    <!-- Include if using Enyo 2.0 beta 4 -->
    <script src="lib/extra/phonegap/package.js" type="text/javascript"></script>

  </head>

  <body>
    <script>

    // tell enyo to listen for deviceready event
    enyo.dispatcher.listen(document, "deviceready");

    // Application kind
    enyo.kind({
      name: "App",
      components: [
        {kind: "Signals", ondeviceready: "deviceReady"},
        {content: "Hello world!"}
      ]
    });

    new App().renderInto(document.body);

    </script>
  </body>
</html>
Topics  Uncategorized

PhoneGap webOS Updates

1 BY markus

With Version 1.6.0, PhoneGap for webOS now supports the compass sensor found in the HP TouchPad. The initial work to enable the functionality in Phonegap was done by Markus Leutwyler, a webOS Developer Relations team member, and HP officially contributed to the project.

PhoneGap is an HTML5 app platform that allows you to author native applications with web technologies and get access to APIs and app stores. PhoneGap on webOS allows cross-platform developers to code for one API for device functions such as accelerometer, compass and geolocation while PhoneGap takes care of calling the webOS specific implementations.

Here is how you can receive a current compass heading with PhoneGap:

function onSuccess(heading) {
  alert('Heading: ' + heading.magneticHeading);
};

function onError(error) {
  alert('CompassError: ' + error.code);
};

navigator.compass.getCurrentHeading(onSuccess, onError);

Check out the source code of compass.js to see how we enabled the functionality.

We also updated the API documentation to not only include the new compass functionality but also specify which other device specific APIs can be used on webOS. The current version of the documentation is on github and will be incorporated into the next release of PhoneGap.

 

Meet the team: Enda McGrath

5 BY enda

Enda McGrath


Hi fellow community members, I’m Enda McGrath.

I’m excited to be leading our developer relations effort and I want to thank you for being the best developer community in the world, bar none. It has been a privilege working with you over the past several years and I look forward to the next chapter. Time and time again I am amazed at your loyalty, the awesome apps you publish to the catalog, the new widgets being submitted to the Enyo gallery, and the contributions from the open source community (among your many other attributes).

For those of you that I haven’t worked with in a support capacity, I look forward to meeting you and getting as much feedback as my inbox can handle.

I first joined Palm at the end of 2000 when they acquired a startup I was working at, ThinAir Apps. At the time I was an application developer creating 3rd party apps for PalmOS, the most successful of which was for weightwatchers.com. Since then, I’ve filled a few different roles as the company has evolved, and I’ve enjoyed every one of them.

About 6 years ago I found my home in Developer Relations as a Developer Technical Support engineer and eventually rose to become head of DTS. Initially I worked on the Folio project and then the conception and birth of webOS. Here in Developer Relations, the people on the team are amazing; many of the engineers come from the community and are passionate about webOS (as are the marketing folks who do equally great work).

We have started hiring again, too, so check out our current openings if you’re interested in joining the team!

As you can see, I’m excited, the team is excited, and we plan to build on our vibrant and passionate community. Together we will achieve something special… here is to the future and the promise it holds!

New App Reporting Available

3 BY Roy Sutton

We are pleased to announce two new additions to the Developer Center. The first is an upgraded reporting system for app downloads that provides better visibility and analytics. The second is a new option for those developers who wish to set a privacy policy for their apps.

The new reporting system provides the ability to compare downloads to updates as well as show developers the number of active devices with their apps installed.

Developers can filter by installed version number and date range. Reports can be grouped by day, week or month. At release, there will be about two weeks worth of data in the new system. These improved reports should make it easier for developers to keep track of their app downloads.

With the new privacy policy option developers whose apps collect personal data can now include a URL that points to their privacy policy. The URL is entered in the Tax/Legal section of the app submission process. Additionally, developers can specify a company privacy policy by editing their account details and including a link to the policy in the Company section. Developers should review the applicable laws to see if a privacy policy is required.

We’re always striving to improve the developer experience on webOS. If you have suggestions you would like to share with us, please visit our forums.

Topics  Announcements