(Ebook) Building Android Apps with HTML, CSS, and JavaScript, 2nd Edition by Jonathan Stark, Brian Jepson ISBN 9781449316419, 1449316417 - Download the full ebook set with all chapters in PDF format
(Ebook) Building Android Apps with HTML, CSS, and JavaScript, 2nd Edition by Jonathan Stark, Brian Jepson ISBN 9781449316419, 1449316417 - Download the full ebook set with all chapters in PDF format
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
https://ebooknice.com/product/building-android-apps-with-html-css-and-
javascript-1537242
https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312
https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018
(Ebook) Cambridge IGCSE and O Level History Workbook 2C - Depth Study:
the United States, 1919-41 2nd Edition by Benjamin Harrison ISBN
9781398375147, 9781398375048, 1398375144, 1398375047
https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044
(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master the SAT
Subject Test: Math Levels 1 & 2) by Arco ISBN 9780768923049,
0768923042
https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-
arco-master-the-sat-subject-test-math-levels-1-2-2326094
(Ebook) Building iPhone Apps with HTML, CSS, and JavaScript: Making
App Store Apps Without Objective-C or Cocoa by Jonathan Stark ISBN
9780596805784, 0596805780
https://ebooknice.com/product/building-iphone-apps-with-html-css-and-
javascript-making-app-store-apps-without-objective-c-or-cocoa-1467236
(Ebook) Building iphone apps with html, css, and javascript: Making
App Store Apps Without Objective-C or Cocoa by Stark, Jonathan ISBN
9780596805784, 9781449382919, 9781449389000, 0596805780, 1449382916,
1449389007
https://ebooknice.com/product/building-iphone-apps-with-html-css-and-
javascript-making-app-store-apps-without-objective-c-or-cocoa-18480948
(Ebook) Programming Windows Store Apps with HTML, CSS, and JavaScript
by Kraig Brockschmidt
https://ebooknice.com/product/programming-windows-store-apps-with-
html-css-and-javascript-11697606
SECOND EDITION
Jonathan Stark
with Brian Jepson
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Building Android Apps with HTML, CSS, and JavaScript, the image of a maleo, and
related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-1-449-31641-9
[LSI]
1326207514
To Erica & Cooper
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
1. Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Web Apps Versus Native Apps 1
What Is a Web App? 1
What Is a Native App? 1
Pros and Cons 2
Which Approach Is Right for You? 2
Web Programming Crash Course 3
Introduction to HTML 3
Introduction to CSS 6
Introduction to JavaScript 9
2. Basic Styling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Don’t Have a Website? 13
First Steps 15
Prepare a Separate Android Stylesheet 19
Control the Page Scaling 20
Adding the Android CSS 22
Adding the Android Look and Feel 26
Adding Basic Behavior with jQuery 28
What You’ve Learned 33
3. Advanced Styling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Adding a Touch of Ajax 35
Traffic Cop 36
Setting Up Some Content to Work With 38
Routing Requests with JavaScript 39
Simple Bells and Whistles 41
Progress Indicator 41
Setting the Page Title 44
v
Handling Long Titles 46
Automatic Scroll-to-Top 47
Hijacking Local Links Only 49
Roll Your Own Back Button 49
Adding an Icon to the Home Screen 56
What You’ve Learned 57
4. Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
With a Little Help from Our Friend 59
Sliding Home 59
Adding the Dates Panel 62
Adding the Date Panel 65
Adding the New Entry Panel 68
Adding the Settings Panel 70
Putting It All Together 74
Customizing jQTouch 76
What You’ve Learned 78
vi | Table of Contents
Install the ADT Plug-In in Eclipse 123
Add Android Platforms and Other Components 124
Download the Latest Copy of PhoneGap 125
Set Up a New Android Project 125
Running Kilo as an Android App 127
Controlling the Phone with JavaScript 129
Beep, Vibrate, and Alert 129
Geolocation 133
Accelerometer 140
What You’ve Learned 143
Thanks to mobile phones, we have moved from virtually no one having access to in-
formation to virtually everyone having access to the vast resources of the Web. This is
arguably the most important achievement of our generation. Despite its overarching
importance, mobile computing is in its infancy. Technical, financial, and political forces
have created platform fragmentation like never before, and it’s going to get worse before
it gets better.
Developers who need to engage large and diverse groups of people are faced with a
seemingly impossible challenge: “How do we implement our mobile vision in a way
that is feasible, affordable, and reaches the greatest number of participants?” In many
cases, the answer is web technologies. The combination of advances in HTML5 and
mobile devices has created an environment in which even novice developers can build
mobile apps that improve people’s lives on a global scale.
Google’s Android operating system is a compelling addition to the mobile computing
space. In true Google fashion, the platform is open, free, and highly interoperable. The
development tools are full-featured and powerful, if a bit geeky, and run on a variety
of platforms.
Carriers and handset manufacturers have jumped on the Android bandwagon. The
market is beginning to flood with Android devices of all shapes and sizes. This is a
double-edged sword for developers. On one hand, more devices mean a bigger market.
On the other hand, more devices mean more fragmentation. As with the fragmentation
in the general mobile market, fragmentation on Android can often be addressed by
building apps with HTML, CSS, and JavaScript.
I’m the first to admit that not all apps are a good fit for development with web tech-
nologies. That said, I see a lot of apps written with native code that could have just as
easily been done with HTML. When speaking to developers who aren’t sure which
approach to take, I say this:
If you can build your app with HTML, CSS, and JavaScript, you probably should.
ix
Using open source, standards-based web technologies gives you the greatest flexibility,
the broadest reach, and the lowest cost. You can easily release it as a web app, then
debug and test it under load with thousands of real users. Once you are ready to rock,
you can use PhoneGap to convert your web app to a native Android app, add a few
device-specific features if you like, and submit to the Android Market—or offer it for
download from your website. Sounds good, right?
x | Preface
This icon indicates a warning or caution.
Preface | xi
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at:
http://shop.oreilly.com/product/0636920022886.do
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our website at:
http://www.oreilly.com
Acknowledgments
Writing a book is a team effort. My heartfelt thanks go out to the following people for
their generous contributions.
Tim O’Reilly, Brian Jepson, and the rest of the gang at ORM for making the experience
of writing this book so rewarding and educational.
David Kaneda for his wonderfully obsessive pursuit of beauty. Whether it’s a bit of
code or a user interface animation, he can’t sleep until it’s perfect, and I love that.
The gang at Nitobi for creating and continuing to support PhoneGap.
Brian Fling for broadening my view of mobile beyond just the latest and greatest hard-
ware. Brian knows mobile from back in the day; he’s a wonderful writer, and on top
of that, a very generous guy.
PPK, John Gruber, John Allsopp, and John Resig for their contributions to and support
of the underlying technologies that made this book possible.
Joe Bowser, Brian LeRoux, Sara Czyzewicz, and the swarm of folks who generously
posted comments and questions on the OFPS site for this book. Your feedback was
very helpful and much appreciated.
My wonderful family, friends, and clients for being understanding and supportive while
I was chained to the keyboard.
xii | Preface
And finally, Erica. You make everything possible. I love you!
Preface | xiii
CHAPTER 1
Getting Started
Before we dive in, I’d like to quickly establish the playing field. In this chapter, I’ll define
key terms, compare the pros and cons of the two most common development ap-
proaches, and give a crash course on the three core web technologies used in this book.
1
Pros and Cons
Different applications have different requirements. Some apps are a better fit with web
technologies than others. Knowing the pros and cons of each approach will help you
make a better decision about which path is appropriate for your situation.
Here are the pros of native app development:
• Millions of registered credit card owners are one click away
• You can access all the cool hardware features of the device
Here are the cons of native app development:
• You have to pay to become an Android developer
• Your app will run only on Android phones
• You have to develop using Java
• The development cycle is slow (develop, compile, deploy, repeat)
Here are the pros of web app development:
• Web developers can use their current authoring tools
• You can use your current web design and development skills
• Your app will run on any device that has a web browser
• You can fix bugs in real time
• The development cycle is fast
Here are the cons of web app development:
• You cannot access the all cool hardware features of the phone
• You have to roll your own payment system if you want to charge for the app
• It can be difficult to achieve sophisticated UI effects
Introduction to HTML
When you are browsing the web, the pages you are viewing are just text documents
sitting on someone else’s computer. The text in a typical web page is wrapped in HTML
tags, which tell your browser about the structure of the document. With this informa-
tion, the browser can decide how to display the information in a way that makes sense.
Consider the web page snippet shown in Example 1-1. On the first line, the string
Hi there! is wrapped in a pair of h1 tags. Notice that the open tag and the close tag are
slightly different: the close tag has a slash (/) as the second character, while the open
tag does not have a slash.
Wrapping text in h1 tags tells the browser that the words enclosed are a heading, which
will cause it to be displayed in large bold text on its own line. There are also h2, h3, h4,
h5, and h6 heading tags. The lower the number, the more important the header, so text
wrapped in an h6 tag will be smaller (i.e., less important-looking) than text wrapped in
an h3 tag.
After the h1 tag in Example 1-1, there are two lines wrapped in p tags. These are called
paragraph tags. Browsers will display each paragraph on its own line. If the paragraph
is long enough to exceed the width of the browser window, the text will bump down
and continue on the next line. In either case, a blank line will be inserted after the
paragraph to separate it from the next item on the page.
Example 1-1. HTML snippet
<h1>Hi there!</h1>
<p>Thanks for visiting my web page.</p>
<p>I hope you like it.</p>
You can also put HTML tags inside other HTML tags. Example 1-2 shows an unordered
list (ul) tag that contains three list items (li). In a browser, this appears as a bulleted
list with each item on its own line. When you have a tag or tags inside another tag, the
The tags covered so far are all block tags. The defining characteristic of block tags is
that they are displayed on a line of their own, with no elements to the left or right of
them. That is why the heading, paragraphs, and list items progress down the page
instead of across it. The opposite of a block tag is an inline tag, which, as the name
implies, can appear in a line. The emphasis tag (em) is an example of an inline tag, and
it looks like this:
<p>I <em>really</em> hope you like it.</p>
The granddaddy of the inline tags—and arguably the coolest feature of HTML—is the
a tag. The “a” stands for anchor, but at times I’ll also refer to it as a link or hyperlink.
Text wrapped in an anchor tag is clickable, such that clicking on it causes the browser
to load a new HTML page.
To tell the browser which new page to load, we have to add what’s called an at-
tribute to the tag. Attributes are named values that you insert into an open tag. In an
anchor tag, you use the href attribute to specify the location of the target page. Here’s
a link to Google’s home page:
<a href="http://www.google.com/">Google</a>
That might look like a bit of a jumble if you are not used to reading HTML, but you
should be able to pick out the URL for the Google home page. You’ll be seeing a lot of
a tags and href attributes throughout the book, so take a minute to get your head around
this if it doesn’t make sense at first glance.
The HTML snippet that we’ve been looking at would normally reside in the body section
of a complete HTML document. An HTML document is made up of two sections: the
head and the body. The body is where you put all the content that you want users to
see. The head contains information about the page, most of which is invisible to the
user.
Language: English
Author of
“The Boy Scouts of the Eagle Patrol,” “The Boy Scouts
on the Range,” “The Boy Scouts’ Mountain Camp,” “The
Boy Scouts for Uncle Sam,” “The Boy Scouts at the
Panama Canal,” “The Boy Scouts and the Army Airship,”
“The Boy Scouts with the Allies in France,” “The Boy
Scouts on Belgian Battlefields,” “The Boy Scouts Under
Fire in Mexico,” “The Boy Scouts at the Panama-Pacific
Exposition,” “The Boy Scouts’ Campaign for
Preparedness,” “The Boy Scouts Under Sealed Orders,”
“The Boy Scouts’ Badge of Courage,” etc.
A. L. BURT COMPANY
Publishers New York
Printed in U. S. A.
Copyright, 1918, by
Hurst & Co., Inc.
Printed in U. S. A.
CONTENTS
CHAPTER PAGE
I. A Glimpse over into Canada 5
II. Rumblings of Coming Trouble 19
III. By Aeroplane Across the Border 30
IV. An Invasion of the Camp 42
V. Comforting Tubby 54
VI. The Logging Camp 66
VII. An Unwelcome Intruder 78
VIII. Tubby Has an Adventure 91
IX. The Man Outside 104
X. Neatly Done 114
XI. Zeb Makes Good 129
XII. A Scout’s First Duty 142
XIII. A Thrilling Discovery 154
XIV. Rob Makes Up His Mind 166
XV. On Duty Bent 178
XVI. The Stone Cairn on the Border 190
XVII. Lynx Law 202
XVIII. The Trail to the Trestle 214
XIX. The Hunt for the Wire 226
XX. The Munition Train’s Approach 238
XXI. Cutting the Battery Connections 250
XXII. Like Old Times for the Scouts 260
XXIII. In Swift Pursuit 272
XXIV. Those Who Sat by the Fire 284
XXV. Bad Luck, and Good 296
XXVI. Everybody Satisfied 308
“Now, that’s just six words for me and half a dozen for
yourself, Andy Bowles. Haven’t I seen you look longingly
at every log we passed, as if you wished Rob would give
the order to sit down and recuperate? Honest to
goodness, I do own up that I’m a trifle winded. This
pack seems to keep on getting heavier and heavier.”
“If you take a look over that way, due north, fellows,”
Rob was telling the other boys, as they sat there on the
log, and pointing as he spoke, “you can see for several
miles. Notice that big clump of hemlocks on the rise
yonder, along the near horizon? Well, unless I miss my
guess, that’s Canada!”
“I’ve been told that’s the case,” Rob assured them. The 16
talk went on along the same lines until finally the scout
master, jumping up, announced:
19
CHAPTER II
RUMBLINGS OF COMING TROUBLE
“Oh! Did you see that hump on his back, Rob? What
could it have been?” gasped Tubby, gripping the sleeve
of the other’s khaki coat in his excitement.
“Why, Tubby, don’t you know that was the pirate of the
northern woods?” cried the equally aroused Andy, who
had also been stupefied while the little drama was being
enacted, and only recovered the use of his hands, and
realized that he was carrying a gun, when the leaping
buck had completely vanished from view.
“I’ve heard a lot about the Maine woods, and how all
sorts of people manage to get a fair living from them,
winter or summer,” Tubby was saying later on. “Rob,
you know something of such things, because you’ve
been up here before. How about it?”
“Well, you may mean that as a joke,” said Rob, “but rare
gems have been found around here, which brings up
another calling that some men have followed. That is
searching all the streams for mussels, because some
pretty valuable fresh-water pearls have been discovered,
they say, in Maine bivalves.”
“Oh, why can’t the nations of the Old World keep the
peace like it’s been kept for a hundred years between
Uncle Sam and his big northern neighbor?” sighed the
tender-hearted Tubby sincerely. “Here’s a boundary of
over three thousand miles, and not a single fort to mark
the dividing line; whereas over across the water, look at
the enormous fortresses France and Belgium and
Germany have maintained, though none of the Belgians’
stood the awful pounding of those enormous guns
brought up by the Kaiser’s troops.”
30
CHAPTER III
BY AEROPLANE ACROSS THE BORDER
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com