Click here to close now.




















Welcome!

Java IoT Authors: Pat Romanski, Gary Kaiser, Dana Gardner, Liz McMillan, Elizabeth White

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
SYS-CON Events announced today that HPM Networks will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. For 20 years, HPM Networks has been integrating technology solutions that solve complex business challenges. HPM Networks has designed solutions for both SMB and enterprise customers throughout the San Francisco Bay Area.
For IoT to grow as quickly as analyst firms’ project, a lot is going to fall on developers to quickly bring applications to market. But the lack of a standard development platform threatens to slow growth and make application development more time consuming and costly, much like we’ve seen in the mobile space. In his session at @ThingsExpo, Mike Weiner, Product Manager of the Omega DevCloud with KORE Telematics Inc., discussed the evolving requirements for developers as IoT matures and conducted a live demonstration of how quickly application development can happen when the need to comply wit...
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 his session at @ThingsExpo, James Kirkland, Red Hat's Chief Architect for the Internet of Things and Intelligent Systems, described how to revolutionize your archit...
It is one thing to build single industrial IoT applications, but what will it take to build the Smart Cities and truly society-changing applications of the future? The technology won’t be the problem, it will be the number of parties that need to work together and be aligned in their motivation to succeed. In his session at @ThingsExpo, Jason Mondanaro, Director, Product Management at Metanga, discussed how you can plan to cooperate, partner, and form lasting all-star teams to change the world and it starts with business models and monetization strategies.
The Internet of Everything (IoE) brings together people, process, data and things to make networked connections more relevant and valuable than ever before – transforming information into knowledge and knowledge into wisdom. IoE creates new capabilities, richer experiences, and unprecedented opportunities to improve business and government operations, decision making and mission support capabilities.
The Internet of Things is not only adding billions of sensors and billions of terabytes to the Internet. It is also forcing a fundamental change in the way we envision Information Technology. For the first time, more data is being created by devices at the edge of the Internet rather than from centralized systems. What does this mean for today's IT professional? In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists addressed this very serious issue of profound change in the industry.
Discussions about cloud computing are evolving into discussions about enterprise IT in general. As enterprises increasingly migrate toward their own unique clouds, new issues such as the use of containers and microservices emerge to keep things interesting. In this Power Panel at 16th Cloud Expo, moderated by Conference Chair Roger Strukhoff, panelists addressed the state of cloud computing today, and what enterprise IT professionals need to know about how the latest topics and trends affect their organization.
Converging digital disruptions is creating a major sea change - Cisco calls this the Internet of Everything (IoE). IoE is the network connection of People, Process, Data and Things, fueled by Cloud, Mobile, Social, Analytics and Security, and it represents a $19Trillion value-at-stake over the next 10 years. In her keynote at @ThingsExpo, Manjula Talreja, VP of Cisco Consulting Services, discussed IoE and the enormous opportunities it provides to public and private firms alike. She will share what businesses must do to thrive in the IoE economy, citing examples from several industry sectors.
Growth hacking is common for startups to make unheard-of progress in building their business. Career Hacks can help Geek Girls and those who support them (yes, that's you too, Dad!) to excel in this typically male-dominated world. Get ready to learn the facts: Is there a bias against women in the tech / developer communities? Why are women 50% of the workforce, but hold only 24% of the STEM or IT positions? Some beginnings of what to do about it! In her Opening Keynote at 16th Cloud Expo, Sandy Carter, IBM General Manager Cloud Ecosystem and Developers, and a Social Business Evangelist, d...
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.
Akana has released Envision, an enhanced API analytics platform that helps enterprises mine critical insights across their digital eco-systems, understand their customers and partners and offer value-added personalized services. “In today’s digital economy, data-driven insights are proving to be a key differentiator for businesses. Understanding the data that is being tunneled through their APIs and how it can be used to optimize their business and operations is of paramount importance,” said Alistair Farquharson, CTO of Akana.
Business as usual for IT is evolving into a "Make or Buy" decision on a service-by-service conversation with input from the LOBs. How does your organization move forward with cloud? In his general session at 16th Cloud Expo, Paul Maravei, Regional Sales Manager, Hybrid Cloud and Managed Services at Cisco, discusses how Cisco and its partners offer a market-leading portfolio and ecosystem of cloud infrastructure and application services that allow you to uniquely and securely combine cloud business applications and services across multiple cloud delivery models.
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, analyzed 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 Payment...
In his keynote at 16th Cloud Expo, Rodney Rogers, CEO of Virtustream, discussed the evolution of the company from inception to its recent acquisition by EMC – including personal insights, lessons learned (and some WTF moments) along the way. Learn how Virtustream’s unique approach of combining the economics and elasticity of the consumer cloud model with proper performance, application automation and security into a platform became a breakout success with enterprise customers and a natural fit for the EMC Federation.
"Optimal Design is a technology integration and product development firm that specializes in connecting devices to the cloud," stated Joe Wascow, Co-Founder & CMO of Optimal Design, in this SYS-CON.tv interview at @ThingsExpo, held June 9-11, 2015, at the Javits Center in New York City.
SYS-CON Events announced today that CommVault has been named “Bronze Sponsor” of SYS-CON's 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. A singular vision – a belief in a better way to address current and future data management needs – guides CommVault in the development of Singular Information Management® solutions for high-performance data protection, universal availability and simplified management of data on complex storage networks. CommVault's exclusive single-platform architecture gives companies unp...
Electric Cloud and Arynga have announced a product integration partnership that will bring Continuous Delivery solutions to the automotive Internet-of-Things (IoT) market. The joint solution will help automotive manufacturers, OEMs and system integrators adopt DevOps automation and Continuous Delivery practices that reduce software build and release cycle times within the complex and specific parameters of embedded and IoT software systems.
"ciqada is a combined platform of hardware modules and server products that lets people take their existing devices or new devices and lets them be accessible over the Internet for their users," noted Geoff Engelstein of ciqada, a division of Mars International, in this SYS-CON.tv interview at @ThingsExpo, held June 9-11, 2015, at the Javits Center in New York City.
Internet of Things is moving from being a hype to a reality. Experts estimate that internet connected cars will grow to 152 million, while over 100 million internet connected wireless light bulbs and lamps will be operational by 2020. These and many other intriguing statistics highlight the importance of Internet powered devices and how market penetration is going to multiply many times over in the next few years.
SYS-CON Events announced today that Dyn, the worldwide leader in Internet Performance, will exhibit at SYS-CON's 17th International Cloud Expo®, which will take place on November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Dyn is a cloud-based Internet Performance company. Dyn helps companies monitor, control, and optimize online infrastructure for an exceptional end-user experience. Through a world-class network and unrivaled, objective intelligence into Internet conditions, Dyn ensures traffic gets delivered faster, safer, and more reliably than ever.