Developing Portable Mobile Web Applications
All you need to develop Web applications is a text editor to write JavaScript, CSS and HTML, and a browser to test the results. The job is a bit easier using a Web-oriented IDE, a JavaScript debugger and the Safari browser, along with an assortment of mobile devices for testing. Safari has a number of features that simplify development. You can select which User Agent the browser emulates (from the Developer menu), and the Web Inspector allows you to inspect and debug Web elements, including client-side databases. Safari isn't supported on Linux, but it runs just fine under VirtualBox. The code for this article was developed using the following:
Ubuntu 9.10 and the gedit editor.
Safari browser on Windows XP on VirtualBox.
Apache httpd Web server.
GIMP for icon graphics.
jQTouch and jQuery libraries.
iPhone, iTouch, iPad and Android devices.
Installation of the tools is well documented elsewhere. The Resources section for this article gives pointers to the download URLs. To install jQTouch, just put the JavaScript and CSS files in the directory tree of your Web application, and point to them from your HTML <head> element. jQTouch comes with minimized versions of the files and a minimized jQuery library.
As an example, let's look at a simple notes application that I'll call Webnotes. With it, a user could write notes, and view, edit or delete notes later. A note will consist of a title and an arbitrary-length string. The notes will be stored locally on the smartphone, using HTML5 client-side database APIs, and we'll test it running on a variety of Apple and Android devices. When we're done, we'll compare this to a similar Android sample application that ships with the Android SDK. Because we're using client-side database features that are part of HTML5, we'd expect it to work fine on the iPhone, the Droid and the iPad, and not to work on the HTC G1 (it does not support local storage).
Our app has three screens:
The opening screen will display a list of existing notes, listed by title, in order by the date they were last edited. Touching a title will select that note for edit. Touching a + button will add a new note (Figure 1).
An edit screen will allow viewing, editing or deletion of a note. (Figure 2).
An add screen will create a new note and store it in the database (Figure 3).
Listing 1 is the HTML file, index.html, primarily concerned with layout. Listing 2 is a JavaScript file, webnotes.js, that has the logic we need. Let's go through the HTML first.
Listing 1. index.html
<!DOCTYPE HTML PUBLIC>
<head>
<title>WebNotes</title>
<link type="text/css" rel="stylesheet"
media="screen" href="jqtouch/jqtouch.min.css">
<link type="text/css" rel="stylesheet"
media="screen" href="themes/jqt/theme.min.css">
<script type="text/javascript"
src="jqtouch/jquery.1.3.2.min.js"></script>
<script type="text/javascript"
src="jqtouch/jqtouch.min.js"></script>
<script type="text/javascript"
src="javascript/webnotes.js"></script>
</head>
<body>
<div id="home">
<div class="toolbar">
<h1>Web Notes</h1>
<a class="button add slideup"
href="#addNote">+</a>
</div>
<ul class="metal">
<li id="noteTemplate" class="arrow"
style="display:none">
<span class="title">Title</span>
</li>
</ul>
</div>
<div id="addNote">
<div class="toolbar">
<h1>Add Note</h1>
<a class="button cancel" href="#">Cancel</a>
</div>
<form method="post">
<ul>
<li><input type="text" class="title" /></li>
<li><textarea class="note" ></textarea></li>
<li>
<input type="submit" class="submit"
name="action" value="Save Note" /></li>
</ul>
</form>
</div>
<div id="editNote">
<div class="toolbar">
<h1>Edit Note</h1>
<a class="button cancel" href="#">Cancel</a>
<a class="button"
onclick="deleteNoteById()">Delete</a>
</div>
<form method="post">
<ul>
<li><input type="text" class="title" /></li>
<li><textarea class="note" ></textarea></li>
<li>
<input type="submit" class="submit"
name="action" value="Save Note" /></li>
</ul>
</form>
</div>
</body>
</html>
Rick Rogers has been a professional embedded developer for more than 30 years. Now specializing in mobile application software, when Rick isn't writing software for a living, he's writing books and magazine articles like this one.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
Web Development News
Developer Poll
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- New Products
- OpenOffice.org Off-the-Wall: ToCs, Indexes and Bibliographies in OOo Writer
- Dart: a New Web Programming Experience
- Mediated Reality: University of Toronto RWM Project
- Kinect with Linux
- Power Management in Linux-Based Systems
- A Topic for Discussion - Open Source Feature-Richness?
- General
34 min 31 sec ago - Kernel Problem
10 hours 37 min ago - BASH script to log IPs on public web server
15 hours 4 min ago - DynDNS
18 hours 40 min ago - Reply to comment | Linux Journal
19 hours 12 min ago - All the articles you talked
21 hours 36 min ago - All the articles you talked
21 hours 39 min ago - All the articles you talked
21 hours 40 min ago - myip
1 day 2 hours ago - Keeping track of IP address
1 day 3 hours ago











Comments
Android compatibility.
I'm getting my feet wet with mobile development and am trying to get this working. I'm developing on an HTC Droid Eris with Android 2.1. All I'm getting is a black screen. Any one have any ideas if it should work? Or where I should be looking?
"well documented elsewhere"
"Installation of the tools is well documented elsewhere. The Resources section for this article gives pointers to the download URLs."
The resources indeed gives the pointers to the download URLs.
Is there also a link available for "well documented elsewhere"?
Is there also a pointer to the installation of the tools?
Regards,
M. Moon