Download Full Building Android Apps with HTML CSS and JavaScript 2nd Edition Jonathan Stark PDF All Chapters
Download Full Building Android Apps with HTML CSS and JavaScript 2nd Edition Jonathan Stark PDF All Chapters
com
https://ebookname.com/product/building-android-apps-with-
html-css-and-javascript-2nd-edition-jonathan-stark/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/start-programming-using-html-css-and-
javascript-1st-edition-iztok-fajfar-author/
ebookname.com
https://ebookname.com/product/html-css-and-javascript-mobile-
development-for-dummies-1st-edition-william-harrel/
ebookname.com
https://ebookname.com/product/wolves-eat-dogs-arkady-renko-05-1st-
edition-martin-cruz-smith/
ebookname.com
The Women of Colonial Latin America 2nd Edition Susan
Migden Socolow
https://ebookname.com/product/the-women-of-colonial-latin-america-2nd-
edition-susan-migden-socolow/
ebookname.com
https://ebookname.com/product/skills-for-managing-rapidly-changing-it-
projects-fabrizio-fioravanti/
ebookname.com
https://ebookname.com/product/1-000-places-to-see-in-the-united-
states-canada-before-you-die-patricia-schultz/
ebookname.com
https://ebookname.com/product/the-masks-of-god-primitive-mythology-
joseph-campbell/
ebookname.com
Bleach Vol 23 Tite Kubo
https://ebookname.com/product/bleach-vol-23-tite-kubo/
ebookname.com
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
Exploring the Variety of Random
Documents with Different Content
hailstones. Instinctively dropping on my knees, I gripped an angle of
the rock, curled up like a young fern frond with my face pressed
against my breast, and in this attitude submitted as best I could to
my thundering bath. The heavier masses seemed to strike like
cobblestones, and there was a confused noise of many waters about
my ears—hissing, gurgling, clashing sounds that were not heard as
music. The situation was quickly realized. How fast one’s thoughts
burn in such times of stress! I was weighing chances of escape.
Would the column be swayed a few inches away from the wall, or
would it come yet closer? The fall was in flood and not so lightly
would its ponderous mass be swayed. My fate seemed to depend on
a breath of the “idle wind.” It was moved gently forward, the
pounding ceased, and I was once more visited by glimpses of the
moon. But fearing I might be caught at a disadvantage in making too
hasty a retreat, I moved only a few feet along the bench to where a
block of ice lay. I wedged myself between the ice and the wall, and
lay face downwards, until the steadiness of the light gave
encouragement to rise and get away. Somewhat nerve-shaken,
drenched, and benumbed, I made out to build a fire, warmed myself,
ran home, reached my cabin before daylight, got an hour or two of
sleep, and awoke sound and comfortable, better, not worse, for my
hard midnight bath.—From “The Yosemite.” Copyright by The
Century Co., New York, and used by their kind permission.
SOMBRE[7]
By William Wetmore Story
Long golden beams from the setting sun swept over the plains of
Andalusia, and fell upon the Geralda tower of the great cathedral of
Sevilla, many miles in the distance. In their path they illumined a
stretch of vast pastures enclosed by whitened stone walls, and
dotted with magnificent cattle. In a far corner of one of the
enclosures the figure of a young girl passed through an arched stone
gateway. As she paused to look upon the scattered groups of
grazing beasts, the level rays played in lights and shadows upon the
waving masses of dark chestnut hair, richly health-tinted young face,
creamy neck, and large, lustrous eyes now painfully dry, as if tears
were exhausted. She gazed from group to group, calling eagerly,
“Sombre! Sombre!”
A pair of long, gleaming horns rose abruptly amid the browsing
herd, and a magnificent bull came towards her at a brisk trot. The
sunbeams glinted upon his dark coat as it swelled and sank under
the play of powerful muscles. His neck and shoulders were leonine
in massive strength, the legs and hind-quarters as sleek and
symmetrical as those of a race-horse, but his ferociousness was
held in check by that devoted love dumb animals express for those
who love them.
In a moment the young girl’s white arms were thrown around the
animal’s dusky neck, and her cheek was lain against the silken skin.
“Oh, Sombre!” she murmured, “do you know what they are going to
do with you? Papa wants to send you to the Plaza de Toros! I have
begged him in vain to spare you. Does he think after Anita has
brought you from a tiny calf to be such a beautiful, dear toro that she
can give you to the cruel matador to be tortured, made crazy and
killed?”
She was sobbing bitterly, and the devoted beast was striving
vainly to turn his head far enough to lick the fair neck bending down
upon his. Presently the sobbing ceased, and she stroked the strong
shoulders with her small hand.
“Never fear, Sombre, if they take you to Sevilla Anita will find a
way to save you! Now, say good night.”
Sombre thrust out his huge tongue and licked the little hand and
arms. Then she bent forward and kissed him on the frowning, furry
forehead and departed.
Anita’s path homeward lay through another field where a herd of
cattle were being driven. A young herdsman, riding a strong horse at
a brisk canter, saw the young girl enter from the adjoining pasture.
With joyful exclamation in English he rode towards her calling,
“Anita, have you seen the posters?”
Waiting until he reached her side, with bated breath she asked, “Is
—is Sombre advertised?”
“Yes, on the outer gateway. But here, I have a poster in my
pocket.”
Plaza de Toros de Sevilla
May 17.
Anniversary of the King’s Birthday,
Six Bulls to be killed,
The two magnificent brother bulls
Sol and Sombre,
and others very ferocious,
against
The intrepid Matadores,
Lariato, the American, and
Amador, of Sevilla.
“It is cruel of them, cruel! (Reading) ‘Lariato, the American.’ Why,
that is yourself! You will spare him! You will spare my Sombre!”
“They do not permit me to fight Don Alonzo’s bulls, for I raise them
and they would not fight me. Amador will fight Sombre.”
“No, no! You must fight Sombre. That wicked Amador will kill him!”
“But so would I, Anita, or be killed by him!”
Anita was silent for a time; suddenly she exclaimed: “Orlando, do
you love me well enough to put faith in a promise which will seem
impossible of fulfillment?”
“God knows I do!”
“Then listen; if Sombre goes to the Plaza de Toros, you must fight
him and spare him even though they hiss and jeer at you.”
“Death is easier. Perhaps the managers will let me fight him, for
you have raised him, and I can tell them that I have scarcely seen
him. I will fight him, Anita, and for your sake I will let him kill me!”
“No, no, Orlando, for this is my promise, even in the last extremity
Sombre shall not harm you!”
“And then, Anita!”
“Then I will leave my father’s house and go with you. We will buy
Sombre and go to those plains in your country you love so to tell
about. You will become a ranch hero, and Sombre shall be the
patriarch of our herd!”
“I have tried that once and failed!”
“Ah, but you had neither Sombre nor Anita then!” And waving him
a kiss she ran off across the field.
On the 17th of May, in the Plaza de Toros, there was a murmur
from thousands of throats like the magnified hum of bees. Amador of
Sevilla had killed several bulls and now there was a short
intermission. In a stall of the lowest tier sat Anita alone. Presently a
band of music began a stately march, and under a high stone
archway a long procession advanced. First, gaudily caparisoned
picadors on blindfolded studs, two by two, separated and came to a
halt, facing the center, with long lances abreast. Then red-coated
toreadors carrying long barbs, with brilliant streamers of ribbon,
grouped themselves near the heavy closed doors of the bull-pen;
finally, the capeadors in yellow satin, carrying flaming red capes on
their arms, filed around like the mounted picadors and stood
between their studs.
The music ceased, the murmur of voices died away, and the gates
of the bull-pen were thrown open. At a quick trot, a great black bull
dashed in, receiving in his shoulders as he passed the toreador’s
two short barbs. Anita gripped her chair and gasped, “Sombre!”
Coming from a darkened pen, Sombre had trotted eagerly forward,
expecting to find himself once more in his loved pastures, but he
paused, bewildered in the glare of light. Hither and thither he turned
in nervous abruptness, his head raised high, his tail slowly lashing
his flanks. Then he lowered his grand head and sniffed the earth,
and then he smelled fresh, warm blood, the blood of his own kind.
With gathering rage he lowered his keen horns close to the ground
and gave a deep, hoarse bellow of defiance, flinging clod after clod
with his forefeet high above his back. Then there flaunted toward him
a red object at which he charged, but it swept aside, and a new sting
of pain was felt in his neck, and warm blood was trickling over his
glossy skin. Again and again he charged, but each time the red thing
vanished and there was more pain, more torturing barbs that
maddened him.
Presently a horseman advanced with lowered spear. Surely horse
and rider could not vanish. Ah, no! Sombre found that it was not
intended that they should. Rushing upon them he struck them with
such a blow that they were forced backwards twenty feet and both
gave a scream of pain. The picador was dragged away with a broken
leg, and the horse lay lifeless, for Sombre’s horn had pierced its
heart. Instantly a great cry went up from that crater of humanity,
“Bravo! Bravo, Toro! Bravo, Sombre!”
More than once he earned that grand applause, then his
tormentors disappeared and through one of the archways advanced
a young man tall and athletic. On his left arm hung a scarlet mantle,
and in his right hand he carried a long, keen sword. Passing under
the archway, the matador swept his sword in military salute, then
with lowered point he stepped into the arena and faced his
antagonist. Upon all fell an awful silence, for Lariato and Sombre
were met in a struggle to the death!
For a time the combatants stood motionless, eyeing each other
intently. Then came stealthy movements, hither and thither, then
thundering, desperate charges, and graceful, hair-breadth escapes.
At last in one great charge, Sombre’s horn tore the mantle from
Lariato’s arm and carrying it half around the ring, as a flaming
banner, the bull ground and trampled it in the dust. A slight hissing
was heard in the audience which turned to thundering applause
when Lariato contemptuously refused a new mantle! The audience
became breathless, the man alone was now the mad beast’s target!
Sombre, dripping with blood and perspiration, his flanks swelling
and falling in his great gasps for breath, his eyes half blinded by the
dust and glare of the arena, gave the matador one brief glance, then
with head low down, charged upon him. Lariato’s long keen blade
was lowered confidently to its death-dealing slant.
Just as the murderous sword-point seemed about to sink through
the bull’s shoulders, into his very heart, a despairing woman’s cry
reached the matador’s ears. Then a mighty hiss, interspersed with
hoots and jeers, went up from the exasperated spectators, for the
bull thundered on, with the sword scarcely penetrating the tough
muscles, standing upright between his shoulders, while Lariato stood
disarmed.
Coming to a standstill far beyond his antagonist, Sombre shook
his huge neck and the sword spun high into the air and fell toward
the center of the ring. Lariato took several steps toward it, but
tottered and fell upon the ground in a swoon, for he had been
severely bruised.
With an exultant roar, the bull rushed back to complete his victory;
the hissing and the hooting was hushed, and groans of horror filled
the air. Suddenly, just as the animal had gained full headway in his
murderous charge, a slight, white figure glided into the ring, and a
clear voice cried “Sombre!”
At the sound of that voice, the charging beast came strainingly to a
halt, threw up his head, and gazed eagerly about, then turned and
rushed toward the girl! Capeadors hurried forward flaunting their red
capes, but she waved them back.
“Go back! You shall torment him no more, my poor, tortured,
wounded Sombre!”
In a moment the great beast was beside her, licking her dress and
arms and hands. As she deftly extricated the barbs from his neck
and shoulders, the thousands of throats around them shrieked out a
vast pandemonium of bravos. Blood was covering her hands and
staining her dress, but Anita was blind to it. Meanwhile Lariato had
struggled to his feet and hurried towards her. “God bless you,” he
was saying, but she pushed past him with a glad smile, saying,
“Wait, I have something to say to them!”
Standing in the middle of the ring, Anita waited for silence.
Delaying until not a sound was heard, she said in a clear voice that
reached every ear:
“Jeer not at Lariato; he spared my pet, my Sombre, because he
loved me.”
No matador ever gained such applause as followed. Bouquets,
sombreros, scarfs, and full purses showered into the ring, and as
that strange group stood facing the ovation, “Bravo, Lariato, Bravo,
la Señorita de Toros, Bravo, Sombre!” rang out and reëchoed over
the distant housetops.
KAWEAH’S RUN
By Clarence King
As I walked over to see Kaweah at the corral, I glanced down the
river, and saw, perhaps a quarter of a mile below, two horsemen ride
down our bank, spur their horses into the stream, swim to the other
side, and struggle up a steep bank, disappearing among bunches of
cottonwood trees near the river.
They were Spaniards—the same who had swum King’s River the
afternoon before, and, as it flashed on me finally, the two whom I had
studied so attentively at Visalia. Then I at once saw their purpose
was to waylay me, and made up my mind to give them a lively run.
I decided to strike across, and jumping into the saddle threw
Kaweah into a sharp trot.
I glanced at my girth and then at the bright copper upon my pistol,
and settled myself firmly.
By this time I had regained the road, which lay before me traced
over the blank, objectless plain in vanishing perspective. Fifteen
miles lay between me and a station; Kaweah and pistol were my only
defense, yet at that moment I felt a thrill of pleasure, a wild moment
of inspiration, almost worth the danger to experience.
I glanced over my shoulder and found that the Spaniards were
crowding their horses to their fullest speed; their hoofs, rattling on