Click here to close now.

Welcome!

Java IoT Authors: Liz McMillan, Pat Romanski, Elizabeth White, Roger Strukhoff, Carmen Gonzalez

Related Topics: Java IoT, Mobile IoT, Wearables

Java IoT: Article

Living on the Edge of Mobile Development

Overview and experience with Sencha Touch, YUI Test and PhoneGap

Which mobile device should I target for my application? That's one of the first questions you need to answer as a mobile developer. You might select the device based on personal preference or what looks cool today. The problem is that mobile technology choices are diverse and evolving quickly. The tools and languages used to develop native applications vary wildly and you probably cannot afford to learn them all. Chances are you want to find a way to replicate your application across multiple devices while minimizing your investment.  How can that be done?

Hybrid Is More than a Green Decision
We are all familiar with the idea of hybrid cars and trucks. These vehicles typically combine petroleum and electric technologies to improve efficiency, reducing your carbon footprint.  You can take a hybrid approach for your mobile application by combining multiple technologies to improve your development efficiency, reducing your expenses.  The hybrid approach combines minimal device-specific native code with your application developed with HTML5, CSS3 and JavaScript.  Development of native code is painless through the use of several libraries and tools.  HTML5 provides the underlying capability for storage, drag and drop, timed media playback, and others.  CSS3 dramatically improves the presentation of web technologies enabling a native look-and-feel for mobile applications. JavaScript allows you to use your existing web skills to implement the application.  All of these technologies run within a compatible desktop browser allowing you to develop and test your application without deploying to a device.

The combination of familiar web technologies with minimal native code enables you to develop your application once and deploy to a variety of mobile devices.  Now you might be thinking 'Are these web standards finalized?' and the answer would be no.  However, the HTML rendering engines used in most mobile devices have been implementing the features as the standards are published.  Javascript libraries are wrapping these features and compensating for device differences and standards evolution so your application does not need to.  There are several libraries under development but I elected to use Sencha Touch.

Figure 1 - This diagram depicts the major differences between mulitple native and hybrid application development

Sencha Touch Is My Cup of Tea
The Sencha company logo is a green leaf, presumably because sencha is a Japanese whole leaf green tea.  I am an ardent coffee drinker but I really like this tea.  Sencha is perhaps best known for their Ext JS and Ext GWT libraries.  Sencha Touch is their latest library released late in 2010.  There are several similar libraries in various stages of development, but Sencha was one of the first to market and I am working on commercial products that depend on released libraries.  The first release includes support for Android and Apple iOS devices.  Reading the tea leaves promises future support for Blackberry 6 and Blackberry Torch.  The library is open source and supports a dual license approach making it appropriate for commercial use.  The library includes:

  • Robust data integration including access to AJAX, JSONP, or YQL and local storage
  • Large library of user interface elements many of which automatically bind to the data objects
  • Advanced native look-and-feel styling, animation and branding capabilities
  • Model, View, Controller (MVC) support to put it all together

Figure 2 - Example Sencha Touch application running on Apple iPhones

My First Sips of Sencha
I started using Sench Touch in the Summer of 2010 while it was in beta.  I had the typical beta experience of incomplete documentation, a few bugs and changing API.  Over the frequent updates, the documentation improved and examples were updated to align with the latest API.  Throughout the beta and after the production release, I worked on my application.  My application successfully used local storage, tree and carousal navigation, animated transitions, custom search features and selective user updates to content.  The plan is to deploy on Apple iOS devices first with the need for possibly many different branding themes.

I found it quite easy to define enities and storage objects with the data integration features.  The storage objects were extensible enough to add custom search features.  The user interface elements often took some experimentation and reverse engineering to fill in the gaps of light documentation.  I had to become familiar with the inspection and debugging features of Chrome and Safari to ultimately answer many questions.  There are still a few inconsistencies in how user interface element templates are used but overall, the library is quite complete.  One of the most powerful user interface features is the branding support.

The branding support in Sencha uses Syntactically Awesome Stylesheets (SASS). SASS is a scripting language that describes how to generate cascading stylesheets.  Need to change your corporate color across all user interface elements?  Change it in one place and regenerate your native look-and-feel stylesheet.  Sencha Touch ships with a full library of SASS scripts that you can easily extend to meet your branding needs.  This approach also encodes images into the stylesheet to reduce the number of files to deploy.  I was able to extend the SASS to specify branding color selections, omit unused user interface elements and specify the needed icons.

Sencha provides best practice advice for project organization and the use of the MVC support.  Part of the project organization is for unit testing. It is your choice how to test your JavaScript, but the best practice within our organization for other technologies is to use one of the xUnit libraries and include regression testing as part of continuous integration.  I did an informal survey within our development group and found that Javascript is an exception.  Since the bulk of a hybrid application is JavaScript, I found it necessary to evaluate and select a suitable unit testing approach.

Figure 3 - You can also write applications for the Apple iPad

This is Only a Test
A robust JavaScript unit testing library should include support for:

  • Continuous integration
  • Multiple browser testing
  • Event testing
  • Mock objects
  • Organization of tests (e.g. suites)
  • Code coverage reports

I looked at two dozen different options and selected the YUI Test Standalone Library.  This is a project to separate the Test module from the popular Yahoo! UI framework.  It is currently released as a beta and appears to be slated for a first quarter 2011 release.  Running unit tests requires the use of a desktop browser.  Javascript is used to set up the test environment including the suites and tests.  I found the suites and tests to be very similar to JUnit tests.  Several examples are included and enabled me to create a regression suite with a nice summary report like this:

Figure 4 - A unit testing console for displaying progress and results

Manually reviewing unit test results should not be included in a continuous integration development environment. The YUI Test Standalone library includes integration with Selenium Remote Control (RC) to automate the regression test.  Selenium RC is a test server that controls browser sessions for testing your JavaScript. The YUI Test Selenium driver enables a build script to:

  1. Start the Selenium RC server
  2. Specify the regression test HTML files
  3. Specify the browsers to run the regression
  4. Run the tests
  5. Collect and report the success or failure of the tests
  6. Optionally create coverage reports
  7. Shutdown the Selenium RC server

All of these tasks are done via the Java-based driver included in YUI Test Standalone and can be included as part of a build such as Ant. The coverage report is conditional on a earlier instrumentation step (not shown).  The YUI Test Standalone library includes a Java-based instrumentation utility that creates instrumented Javascript proxies of the files targeted for coverage measurement.  The coverage report step above depends on the instrumented proxies to creat LCOV-based coverage reports. These coverage reports include a very nice report of line and function coverage including a line by line color coding of the coverage of the source.

Going Native
Up to this point, all development and testing has been done on a desktop running Chrome or Safari.  This has enabled a fast turn around in development and the possible use of browser-based web interface testing automation by a quality assurance group.  This is not to say that all testing can be done on the desktop.  Ultimately, device testing is needed and should be done early and often.  How can we get our HTML, CSS and Javascript to run natively on a mobile device?  The hybrid approach we introduced above would have us write a small program in the target technology that wraps and invokes the application.  Luckily, there are libraries and tools that make this painless.  PhoneGap is the option selected for this project.

PhoneGap fills the technology gap between JavaScript and the native mobile device. It provides JavaScript APIs to underlying native function such as:

  • Accelerometer
  • Camera
  • Compass
  • Contacts
  • Geolocation
  • Media
  • Storage
  • Others

PhoneGap also provides console integration with desktop debuggers, support for six platforms and integrated development environment (IDE) project templates. You must have your target platform SDK installed to use PhoneGap. Since my project is targeting Apple iOS, that means a Mac running the Xcode IDE and the iOS SDK. After downloading and installing the IDE, SDK and PhoneGap, a new project template was available. I created a new PhoneGap project and the template created all the native programs, build targets and default properties and images for me. I copied the application build results into the Xcode project, pressed Build and Run and the application was running in the phone simulator.  It was that simple. No Objective-C to learn or write with less than a day from install to running.

Gaps with PhoneGap
Despite the trivial effort to get the application running on the simulator, there were three minor gaps to address:

  • The default target is iPhones.  This means the application would start up and run on an iPad with the dimensions of a phone (with the 2x option).  Sencha Touch reported the platform as a phone even when running on the actual iPad device.  Ideally, the default would be what Apple calls a Universal App that runs on all devices and adjusts itself when running.  After some research, I found that the solution was few mouse clicks away within Xcode.
  • Orientation changes did not work.  A Sencha Touch application can change the way it looks based on the orientation of the device.  PhoneGap always reported the device orientation as portrait (0 degrees) even though Sencha Touch correctly reported the current orientation.  The solution was a minor hack to monitor for the window resize event and inform Sencha Touch to do the right thing.
  • Certain text was rendered as a link.  Clicking on the link offered to add or update a contact.  What was that all about?  It turns out the default web view component in the iOS SDK attempts to find phone number and e-mail addresses and automatically makes them links to the appropriate app like contacts.  Pretty cool if you want that behavior but does 001-999.9 look like a phone number?  The solution was to add one line of Objective-C code in the PhoneGap generated code to turn this behavior off.

Live Long and Provision
In order to get your application running on an actual device you must go through a complex process Apple calls provisioning.  There is a nice step by step procedure to get you through it all available on the Apple developer site.  Now that I have my Sencha Touch application running on an iPad I see that performance work is needed.  Now that automated build and test process is going to pay off.  It is clear to me that a robust development cycle with this technology is possible and practical.

There are bound to be changes in the available libraries and supported devices in the coming months.  Sencha Touch and PhoneGap is a powerful and easy to use combination that is ready now.

Disclaimers

  • Opinions expressed in this article are those solely of the author and do not reflect those of my employer.
  • iPhone image Courtesy of Apple
  • Sencha Touch application images used with permission
  • The Android logo is reproduced from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

References

More Stories By Mike Jacobs

Mike Jacobs is technology architect and Technology Fellow focused on using technology to improve health care.

@ThingsExpo Stories
The Industrial Internet revolution is now underway, enabled by connected machines and billions of devices that communicate and collaborate. The massive amounts of Big Data requiring real-time analysis is flooding legacy IT systems and giving way to cloud environments that can handle the unpredictable workloads. Yet many barriers remain until we can fully realize the opportunities and benefits from the convergence of machines and devices with Big Data and the cloud, including interoperability, data security and privacy.
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In this session, James Kirkland, Red Hat's Chief Architect for the Internet of Things and Intelligent Systems, will describe how to revolutionize your architecture and...
The Internet of Things is tied together with a thin strand that is known as time. Coincidentally, at the core of nearly all data analytics is a timestamp. When working with time series data there are a few core principles that everyone should consider, especially across datasets where time is the common boundary. In his session at Internet of @ThingsExpo, Jim Scott, Director of Enterprise Strategy & Architecture at MapR Technologies, discussed single-value, geo-spatial, and log time series data. By focusing on enterprise applications and the data center, he will use OpenTSDB as an example t...
We’re entering a new era of computing technology that many are calling the Internet of Things (IoT). Machine to machine, machine to infrastructure, machine to environment, the Internet of Everything, the Internet of Intelligent Things, intelligent systems – call it what you want, but it’s happening, and its potential is huge. IoT is comprised of smart machines interacting and communicating with other machines, objects, environments and infrastructures. As a result, huge volumes of data are being generated, and that data is being processed into useful actions that can “command and control” thi...
All major researchers estimate there will be tens of billions devices - computers, smartphones, tablets, and sensors - connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades. With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo, June 9-11, 2015, at the Javits Center in New York City. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be
We are reaching the end of the beginning with WebRTC, and real systems using this technology have begun to appear. One challenge that faces every WebRTC deployment (in some form or another) is identity management. For example, if you have an existing service – possibly built on a variety of different PaaS/SaaS offerings – and you want to add real-time communications you are faced with a challenge relating to user management, authentication, authorization, and validation. Service providers will want to use their existing identities, but these will have credentials already that are (hopefully) i...
SYS-CON Events announced today that MetraTech, now part of Ericsson, has been named “Silver Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9–11, 2015, at the Javits Center in New York, NY. Ericsson is the driving force behind the Networked Society- a world leader in communications infrastructure, software and services. Some 40% of the world’s mobile traffic runs through networks Ericsson has supplied, serving more than 2.5 billion subscribers.
Scott Jenson leads a project called The Physical Web within the Chrome team at Google. Project members are working to take the scalability and openness of the web and use it to talk to the exponentially exploding range of smart devices. Nearly every company today working on the IoT comes up with the same basic solution: use my server and you'll be fine. But if we really believe there will be trillions of these devices, that just can't scale. We need a system that is open a scalable and by using the URL as a basic building block, we open this up and get the same resilience that the web enjoys.
Thanks to widespread Internet adoption and more than 10 billion connected devices around the world, companies became more excited than ever about the Internet of Things in 2014. Add in the hype around Google Glass and the Nest Thermostat, and nearly every business, including those from traditionally low-tech industries, wanted in. But despite the buzz, some very real business questions emerged – mainly, not if a device can be connected, or even when, but why? Why does connecting to the cloud create greater value for the user? Why do connected features improve the overall experience? And why do...
SYS-CON Events announced today that O'Reilly Media has been named “Media Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9–11, 2015, at the Javits Center in New York City, NY. O'Reilly Media spreads the knowledge of innovators through its books, online services, magazines, and conferences. Since 1978, O'Reilly Media has been a chronicler and catalyst of cutting-edge development, homing in on the technology trends that really matter and spurring their adoption by amplifying "faint signals" from the alpha geeks who are creating the future. An active participa...
SYS-CON Events announced today that BMC will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. BMC delivers software solutions that help IT transform digital enterprises for the ultimate competitive business advantage. BMC has worked with thousands of leading companies to create and deliver powerful IT management services. From mainframe to cloud to mobile, BMC pairs high-speed digital innovation with robust IT industrialization – allowing customers to provide amazing user experiences with optimized IT per...
Imagine a world where targeting, attribution, and analytics are just as intrinsic to the physical world as they currently are to display advertising. Advances in technologies and changes in consumer behavior have opened the door to a whole new category of personalized marketing experience based on direct interactions with products. The products themselves now have a voice. What will they say? Who will control it? And what does it take for brands to win in this new world? In his session at @ThingsExpo, Zack Bennett, Vice President of Customer Success at EVRYTHNG, will answer these questions a...
The 4th International Internet of @ThingsExpo, co-located with the 17th International Cloud Expo - to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA - announces that its Call for Papers is open. The Internet of Things (IoT) is the biggest idea since the creation of the Worldwide Web more than 20 years ago.
The Internet of Things is a misnomer. That implies that everything is on the Internet, and that simply should not be - especially for things that are blurring the line between medical devices that stimulate like a pacemaker and quantified self-sensors like a pedometer or pulse tracker. The mesh of things that we manage must be segmented into zones of trust for sensing data, transmitting data, receiving command and control administrative changes, and peer-to-peer mesh messaging. In his session at @ThingsExpo, Ryan Bagnulo, Solution Architect / Software Engineer at SOA Software, focused on desi...
An entirely new security model is needed for the Internet of Things, or is it? Can we save some old and tested controls for this new and different environment? In his session at @ThingsExpo, New York's at the Javits Center, Davi Ottenheimer, EMC Senior Director of Trust, reviewed hands-on lessons with IoT devices and reveal a new risk balance you might not expect. Davi Ottenheimer, EMC Senior Director of Trust, has more than nineteen years' experience managing global security operations and assessments, including a decade of leading incident response and digital forensics. He is co-author of t...
The multi-trillion economic opportunity around the "Internet of Things" (IoT) is emerging as the hottest topic for investors in 2015. As we connect the physical world with information technology, data from actions, processes and the environment can increase sales, improve efficiencies, automate daily activities and minimize risk. In his session at @ThingsExpo, Ed Maguire, Senior Analyst at CLSA Americas, will describe what is new and different about IoT, explore financial, technological and real-world impact across consumer and business use cases. Why now? Significant corporate and venture...
Today’s enterprise is being driven by disruptive competitive and human capital requirements to provide enterprise application access through not only desktops, but also mobile devices. To retrofit existing programs across all these devices using traditional programming methods is very costly and time consuming – often prohibitively so. In his session at @ThingsExpo, Jesse Shiah, CEO, President, and Co-Founder of AgilePoint Inc., discussed how you can create applications that run on all mobile devices as well as laptops and desktops using a visual drag-and-drop application – and eForms-buildi...
While great strides have been made relative to the video aspects of remote collaboration, audio technology has basically stagnated. Typically all audio is mixed to a single monaural stream and emanates from a single point, such as a speakerphone or a speaker associated with a video monitor. This leads to confusion and lack of understanding among participants especially regarding who is actually speaking. Spatial teleconferencing introduces the concept of acoustic spatial separation between conference participants in three dimensional space. This has been shown to significantly improve comprehe...
There will be 150 billion connected devices by 2020. New digital businesses have already disrupted value chains across every industry. APIs are at the center of the digital business. You need to understand what assets you have that can be exposed digitally, what their digital value chain is, and how to create an effective business model around that value chain to compete in this economy. No enterprise can be complacent and not engage in the digital economy. Learn how to be the disruptor and not the disruptee.
The enterprise market will drive IoT device adoption over the next five years. In his session at @ThingsExpo, John Greenough, an analyst at BI Intelligence, division of Business Insider, will analyze how companies will adopt IoT products and the associated cost of adopting those products. John Greenough is the lead analyst covering the Internet of Things for BI Intelligence- Business Insider’s paid research service. Numerous IoT companies have cited his analysis of the IoT. Prior to joining BI Intelligence, he worked analyzing bank technology for Corporate Insight and The Clearing House Pay...