Android Recipes A Problem-Solution Approach Dave Smith instant download
Android Recipes A Problem-Solution Approach Dave Smith instant download
Smith download
https://textbookfull.com/product/android-recipes-a-problem-
solution-approach-dave-smith/
https://textbookfull.com/product/raku-recipes-a-problem-solution-
approach-j-j-merelo/
https://textbookfull.com/product/c-recipes-a-problem-solution-
approach-1st-edition-shirish-chavan/
https://textbookfull.com/product/javascript-recipes-a-problem-
solution-approach-1st-edition-russ-ferguson/
https://textbookfull.com/product/wxpython-recipes-a-problem-
solution-approach-1st-edition-mike-driscoll/
MATLAB Recipes: a problem-solution approach 2nd Edition
Michael Paluszek
https://textbookfull.com/product/matlab-recipes-a-problem-
solution-approach-2nd-edition-michael-paluszek/
https://textbookfull.com/product/java-9-recipes-a-problem-
solution-approach-3rd-edition-josh-juneau/
https://textbookfull.com/product/spring-5-recipes-a-problem-
solution-approach-4th-edition-marten-deinum/
https://textbookfull.com/product/prestashop-recipes-a-problem-
solution-approach-1st-edition-arnaldo-perez-castano-auth/
https://textbookfull.com/product/matlab-machine-learning-recipes-
a-problem-solution-approach-2nd-edition-michael-paluszek/
Android
Recipes
A Problem-Solution Approach
—
Useful code snippets and recipes using
Android 7.0 and more
—
Fifth Edition
—
Dave Smith
Erik Hellman
Android Recipes
A Problem-Solution Approach
Fifth Edition
Dave Smith
Erik Hellman
Android Recipes: A Problem-Solution Approach
Dave Smith Erik Hellman
Littleton, Colorado, USA Sundbyberg, Sweden
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified
as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
The images of the Android Robot (01/Android Robot) are reproduced from work created and shared by Google and
used according to terms described in the Creative Commons 3.0 Attribution License. Android and all Android and
Google-based marks are trademarks or registered trademarks of Google Inc. in the United States and other countries.
Apress Media LLC is not affiliated with Google Inc., and this book was written without endorsement from Google Inc.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither
the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be
made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com,
or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer
Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook
Licensing web page at www.apress.com/bulk-sales.
Any source code or other supplementary materials referenced by the author in this text are available to readers
at www.apress.com/9781484222584. For detailed information about how to locate your book’s source code,
go to www.apress.com/source-code/. Readers can also access source code at SpringerLink in the Supplementary
Material section for each chapter.
Printed on acid-free paper
Contents at a Glance
■
■Chapter 1: Layouts and Views������������������������������������������������������������������������������� 1
■
■Chapter 2: User Interaction Recipes�������������������������������������������������������������������� 85
■
■Chapter 3: Communications and Networking���������������������������������������������������� 189
■
■Chapter 4: Interacting with Device Hardware and Media���������������������������������� 259
■
■Chapter 5: Persisting Data��������������������������������������������������������������������������������� 367
■
■Chapter 6: Interacting with the System������������������������������������������������������������� 443
■
■Chapter 7: Graphics and Drawing���������������������������������������������������������������������� 585
■
■Chapter 8: Working with Android NDK and RenderScript���������������������������������� 655
Index��������������������������������������������������������������������������������������������������������������������� 699
iii
Contents
■
■Chapter 1: Layouts and Views������������������������������������������������������������������������������� 1
1-1. Styling Common Components����������������������������������������������������������������������������������� 1
Problem�������������������������������������������������������������������������������������������������������������������������������������������������� 1
Solution�������������������������������������������������������������������������������������������������������������������������������������������������� 1
How It Works������������������������������������������������������������������������������������������������������������������������������������������� 1
v
■ Contents
vi
■ Contents
Summary������������������������������������������������������������������������������������������������������������������������ 84
■
■Chapter 2: User Interaction Recipes�������������������������������������������������������������������� 85
2-1. Leveraging the Action Bar��������������������������������������������������������������������������������������� 85
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 85
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 85
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 86
vii
■ Contents
viii
■ Contents
ix
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 188
■
■Chapter 3: Communications and Networking���������������������������������������������������� 189
3-1. Displaying Web Information���������������������������������������������������������������������������������� 189
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 189
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 189
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 189
x
■ Contents
xi
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 258
■
■Chapter 4: Interacting with Device Hardware and Media���������������������������������� 259
4-1. Integrating Device Location ��������������������������������������������������������������������������������� 259
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 259
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 259
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 260
xii
■ Contents
xiii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 366
■
■Chapter 5: Persisting Data��������������������������������������������������������������������������������� 367
5-1. Making a Preference Screen�������������������������������������������������������������������������������� 367
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 367
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 367
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 367
xiv
■ Contents
xv
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 442
■
■Chapter 6: Interacting with the System������������������������������������������������������������� 443
6-1. Notifying from the Background����������������������������������������������������������������������������� 443
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 443
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 443
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 443
xvi
■ Contents
xvii
■ Contents
xviii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 584
■
■Chapter 7: Graphics and Drawing���������������������������������������������������������������������� 585
7-1. Creating Drawables as Backgrounds�������������������������������������������������������������������� 585
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 585
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 585
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 586
xix
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 653
■
■Chapter 8: Working with Android NDK and RenderScript���������������������������������� 655
Android NDK����������������������������������������������������������������������������������������������������������������� 655
8-1. Adding Native Bits with JNI���������������������������������������������������������������������������������� 658
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 658
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 658
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 659
RenderScript���������������������������������������������������������������������������������������������������������������� 674
Using the RenderScript Support Package������������������������������������������������������������������������������������������ 675
xx
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 697
Index��������������������������������������������������������������������������������������������������������������������� 699
xxi
About the Authors
Erik Hellman is a professional software engineer who has worked on everything from small embedded
systems to large backend systems for telecom and banking. He is currently focused on everything around
the Android platform, and has been doing so since 2009. During this time he has been a frequent speaker
at conferences and meetup events, teaching new developers how to work with the platform, has been
developing a wide variety of apps, and worked for OEMs on integrating Android to new hardware devices.
Erik regularly communicates via his development blog (http://www.hellsoft.se) and Twitter stream
@ErikHellman.
xxiii
About the Technical Reviewer
xxv
Acknowledgments
First and foremost, I would like to thank my wife, Lorie, for her eternal patience and support during the long
hours I spent compiling and constructing the materials for this book. Second, I send a huge thank you to the
editorial team that Apress brought together to work with me and make the book the best it could possibly
be; you guys are the ones who make me look good. Without your time and effort, this project would not even
exist.
—Dave Smith
I want to start with thanking my wife. Without the patience and support from her, my contributions to this
book would never have happened. I’d also like to thank Apress and Dave for giving me the opportunity to
work on the fifth edition of Android Recipes. Finally, a big thank you to all the people who keep inspiring me
to keep writing.
—Erik Hellman
xxvii
Introduction
xxix
■ Introduction
xxx
CHAPTER 1
The Android platform is designed to operate on a variety of device types, screen sizes, and screen
resolutions. To assist developers in meeting this challenge, Android provides a rich toolkit of user interface
(UI) components to utilize and customize to the needs of their specific applications. Android also relies
heavily on an extensible XML framework and set resource qualifiers to create liquid layouts that can adapt to
these environmental changes. In this chapter, we take a look at some practical ways to shape this framework
to fit your specific development needs.
Solution
(API Level 1)
You can abstract common attributes that define the look and feel of your application views into XML styles.
Styles are collections of view attribute customizations, such as text size or background color, that should be
applied to multiple views throughout the application. Abstracting these attributes into a style allows the
common elements to be defined in a single location, making the code easier to update and maintain.
Android also supports grouping multiple styles together in a global element called a theme. Themes
apply to an entire context (such as an activity or application), and define styles that should apply to all the
views within that context. Every activity launch in your application has a theme applied to it, even if you
don’t define one. In such cases, the default system theme is applied instead.
How It Works
To explore the styles concept, let’s create an activity layout that looks like Figure 1-1.
As you can see, this view has some elements that we want to customize to look different than they
normally do with the styling from the default system theme applied. One option would be to define all the
attributes for all the views directly in our activity layout. If we were to do so, it would look like Listing 1-1.
■■Note Although it is possible to apply a style to a standard component to look completely different, one
should avoid changing the appearance too much as it could confuse users. Refer to the Material Design
specification at http://material.google.com for details on the recommendations for different UI components.
2
Chapter 1 ■ Layouts and Views
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="@dimen/buttonHeight"
android:button="@null"
android:background="@drawable/background_radio"
android:gravity="center"
android:text="One"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="@dimen/buttonHeight"
android:button="@null"
android:background="@drawable/background_radio"
android:gravity="center"
android:text="Two"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="@dimen/buttonHeight"
android:button="@null"
android:background="@drawable/background_radio"
android:gravity="center"
android:text="Three"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textStyle="bold"
android:text="Select All"/>
<TableRow>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="@dimen/buttonHeight"
android:minWidth="@dimen/checkboxWidth"
android:button="@null"
android:gravity="center"
android:textStyle="italic"
android:textColor="@color/text_checkbox"
android:text="One"/>
3
Random documents with unrelated
content Scribd suggests to you:
The sight re-nerved my courser's feet,
A moment staggering, feebly fleet,
A moment, with a faint low neigh,690
He answer'd, and then fell;
With gasps and glazing eyes he lay,
And reeking limbs immoveable;
His first and last career is done!
On came the troop—they saw him stoop,695
They saw me strangely bound along
His back with many a bloody thong:
They stop—they start—they snuff the air,
Gallop a moment here and there,
Approach, retire, wheel round and round,700
Then plunging back with sudden bound,
Headed by one black mighty steed
Who seem'd the patriarch of his breed,
Without a single speck or hair
Of white upon his shaggy hide.705
They snort—they foam—neigh—swerve aside,
And backward to the forest fly,
By instinct, from a human eye.—
They left me there to my despair,
Link'd to the dead and stiffening wretch,710
Whose lifeless limbs beneath me stretch,
Relieved from that unwonted weight,
From whence I could not extricate
Nor him nor me—and there we lay
The dying on the dead!715
I little deem'd another day
Would see my houseless, helpless head.
XVIII
"The sun was sinking—still I lay
Chain'd to the chill and stiffening steed;
I thought to mingle there our clay;765
And my dim eyes of death had need,
No hope arose of being freed.
I cast my last looks up the sky,
And there between me and the sun
I saw the expecting raven fly,770
Who scarce would wait till both should die
Ere his repast begun.
He flew, and perch'd, then flew once more,
And each time nearer than before;
I saw his wing through twilight flit,775
And once so near me he alit
I could have smote, but lack'd the strength;
But the slight motion of my hand,
And feeble scratching of the sand,
The exerted throat's faint struggling noise,780
Which scarcely could be call'd a voice,
Together scared him off at length.—
I know no more—my latest dream
Is something of a lovely star
Which fix'd my dull eyes from afar,785
And went and came with wandering beam,
And of the cold, dull, swimming, dense
Sensation of recurring sense,
And then subsiding back to death,
And then again a little breath,790
A little thrill, a short suspense,
An icy sickness curdling o'er
My heart, and sparks that cross'd my brain—
A gasp, a throb, a start of pain,
A sigh, and nothing more.795
XIX
"I woke—Where was I?—Do I see
A human face look down on me?
And doth a roof above me close?
Do these limbs on a couch repose?
Is this a chamber where I lie?800
And is it mortal, yon bright eye
That watches me with gentle glance?
I closed my own again once more,
As doubtful that the former trance
Could not as yet be o'er.805
A slender girl, long-hair'd, and tall,
Sate watching by the cottage wall:
The sparkle of her eye I caught,
Even with my first return of thought;
For ever and anon she threw810
A prying, pitying glance on me
With her black eyes so wild and free.
I gazed, and gazed, until I knew
No vision it could be,—
But that I lived, and was released815
From adding to the vulture's feast.
And when the Cossack maid beheld
My heavy eyes at length unseal'd,
She smiled—and I essay'd to speak,
But fail'd—and she approach'd, and made820
With lip and finger signs that said,
I must not strive as yet to break
The silence, till my strength should be
Enough to leave my accents free;
And then her hand on mine she laid,825
And smooth'd the pillow for my head,
And stole along on tiptoe tread,
And gently oped the door, and spake
In whispers—ne'er was voice so sweet!
Even music follow'd her light feet;—830
But those she call'd were not awake,
And she went forth; but, ere she pass'd,
Another look on me she cast,
Another sign she made, to say,
That I had nought to fear, that all835
Were near at my command or call,
And she would not delay
Her due return:—while she was gone,
Methought I felt too much alone.
XX
"She came with mother and with sire—840
What need of more?—I will not tire
With long recital of the rest,
Since I became the Cossack's guest.
They found me senseless on the plain—
They bore me to the nearest hut—845
They brought me into life again—
Me—one day o'er their realm to reign!
Thus the vain fool who strove to glut
His rage, refining on my pain,
Sent me forth to the wilderness,850
Bound, naked, bleeding, and alone,
To pass the desert to a throne,—
What mortal his own doom may guess?—
Let none despond, let none despair!
To-morrow the Borysthenes855
May see our coursers graze at ease
Upon his Turkish bank,—and never
Had I such welcome for a river
As I shall yield when safely there.
Comrades, good night!"—The Hetman threw860
His length beneath the oak-tree shade,
With leafy couch already made,
A bed nor comfortless nor new
To him who took his rest whene'er
The hour arrived, no matter where:865
His eyes the hastening slumbers steep.
And if ye marvel Charles forgot
To thank his tale he wonder'd not,—
The king had been an hour asleep.
And there lay the steed with his nostril all wide,
But through it there rolled not the breath of his pride;
And the foam of his gasping lay white on the turf,15
And cold as the spray of the rock-beating surf.
I
St. Agnes' Eve—Ah, bitter chill it was!
The owl, for all his feathers, was a-cold;
The hare limp'd trembling through the frozen grass,
And silent was the flock in woolly fold:
Numb were the Beadsman's[143] fingers, while he told5
His rosary, and while his frosted breath,
Like pious incense from a censer old,
Seem'd taking flight for heaven, without a death,
Past the sweet Virgin's picture, while his prayer he saith.
II
His prayer he saith, this patient, holy man;10
Then takes his lamp, and riseth from his knees
And back returneth, meagre, barefoot, wan,
Along the chapel aisle by slow degrees:
The sculptured dead, on each side, seem to freeze,
Emprison'd in black, purgatorial rails:15
Knights, ladies, praying in dumb orat'ries,
He passeth by; and his weak spirit fails
To think how they may ache in icy hoods and mails.
III
Northward he turneth through a little door,
And scarce three steps, ere Music's golden tongue20
Flatter'd to tears this aged man and poor;
But no—already had his death-bell rung;
The joys of all his life were said and sung:
His was harsh penance on St. Agnes' Eve;
Another way he went, and soon among25
Rough ashes sat he for his soul's reprieve,
And all night kept awake, for sinners' sake to grieve.
IV
That ancient Beadsman heard the prelude soft;
And so it chanced, for many a door was wide,
From hurry to and fro. Soon, up aloft,30
The silver, snarling[144] trumpets 'gan to chide:
The level chambers, ready with their pride,
Were glowing to receive a thousand guests:
The carved angels, ever eager-eyed,
Stared, where upon their heads the cornice rests,35
With hair blown back, and wings put crosswise on their breasts.
V
At length burst in the argent revelry,
With plume, tiara, and all rich array,
Numerous as shadows haunting fairily
The brain, new-stuff'd, [145]in youth, with triumphs gay40
Of old romance. These let us wish away,
And turn, sole-thoughted, to one Lady there,
Whose heart had brooded, all that wintry day,
On love, and wing'd St. Agnes' saintly care,
As she had heard old dames full many times declare.45
VI
They told her how, upon St. Agnes' Eve,[146]
Young virgins might have visions of delight,
And soft adorings from their loves receive
Upon the honey'd middle of the night,
If ceremonies due they did aright;50
As, supperless to bed they must retire,
And couch supine their beauties, lily white;
Nor look behind, nor sideways, but require
Of Heaven with upward eyes for all that they desire.
VII
Full of this whim was thoughtful Madeline:55
The music, yearning like a God in pain,
She scarcely heard: her maiden eyes divine,
Fix'd on the floor, saw many a sweeping train
Pass by—she heeded not at all: in vain
Came many a tiptoe, amorous cavalier,60
And back retired; not cool'd by high disdain,
But she saw not: her heart was otherwhere;
She sigh'd for Agnes' dreams, the sweetest of the year.
VIII
She danced along with vague, regardless eyes,
Anxious her lips, her breathing quick and short:65
The hallow'd hour was near at hand: she sighs
Amid the timbrels, and the throng'd resort
Of whisperers in anger, or in sport;
'Mid looks of love, defiance, hate, and scorn,
Hoodwink'd with faery fancy; all amort,[147]70
Save to St. Agnes and her lambs[148] unshorn,
And all the bliss to be before to-morrow morn.
IX
So, purposing each moment to retire,
She lingered still. Meantime, across the moors,
Had come young Porphyro,[149] with heart on fire75
For Madeline. Beside the portal doors,
Buttress'd[150] from moonlight, stands he, and implores
All saints to give him sight of Madeline,
But for one moment in the tedious hours,
That he might gaze and worship all unseen;80
Perchance speak, kneel, touch, kiss—in sooth[151] such
things have been.
X
He ventures in: let no buzz'd whisper tell:
All eyes be muffled, or a hundred swords
Will storm his heart, Love's fev'rous citadel:
For him, those chambers held barbarian hordes,85
Hyena[152] foemen, and hot-blooded lords,
Whose very dogs would execrations howl
Against his lineage: not one breast affords
Him any mercy, in that mansion foul,
Save one old beldame,[153] weak in body and in soul.90
XI
Ah, happy chance! the aged creature came,
Shuffling along with ivory-headed wand,
To where he stood, hid from the torch's flame,
Behind a broad hall-pillar, far beyond
The sound of merriment and chorus bland:95
He startled her; but soon she knew his face,
And grasp'd his fingers in her palsied hand,
Saying, "Mercy, Porphyro! hie thee from this place;
They are all here to-night, the whole bloodthirsty race!
XII
"Get hence! get hence! there's dwarfish Hildebrand;100
He had a fever late, and in the fit
He cursed thee and thine, both house and land:
Then there's that old Lord Maurice, not a whit
More tame for his gray hairs—Alas me! flit!
Flit like a ghost away."—Ah, Gossip[154] dear,105
We're safe enough; here in this armchair sit,
And tell me how"—"Good Saints! not here, not here;
Follow me, child, or else these stones will be thy bier."
XIII
He follow'd through a lowly arched way,
Brushing the cobwebs with his lofty plume;110
And as she mutter'd "Well-a—well-a-day!"
He found him in a little moonlight room,
Pale, latticed, chill, and silent as a tomb.
"Now tell me where is Madeline," said he,
"O tell me, Angela, by the holy loom[155]115
Which none but secret sisterhood may see,
When they St. Agnes' wool are weaving piously."
XIV
"St. Agnes! Ah! it is St. Agnes' Eve—
Yet men will murder upon holy days:
Thou must hold water in a witch's sieve,[156]120
And be liege-lord of all the Elves and Fays,
To venture so: it fills me with amaze
To see thee, Porphyro!—St. Agnes' Eve!
God's help! my lady fair the conjuror plays
This very night: good angels her deceive!125
But let me laugh awhile, I've mickle[157] time to grieve."
XV
Feebly she laugheth in the languid moon,
While Porphyro upon her face doth look,
Like puzzled urchin on an aged crone
Who keepeth closed a wond'rous riddlebook,130
As spectacled she sits in chimney nook.
But soon his eyes grew brilliant, when she told
His lady's purpose; and he scarce could brook
Tears, at the thought of those enchantments cold,
And Madeline asleep in lap[158] of legends old.135
XVI
Sudden a thought came like a full-blown rose,
Flushing his brow, and in his pained heart
Made purple riot[159]: then doth he propose
A stratagem, that makes the beldame start:
"A cruel man and impious thou art:140
Sweet lady, let her pray, and sleep, and dream
Alone with her good angels, far apart
From wicked men like thee. Go, go! I deem
Thou canst not surely be the same that thou didst seem."
XVII
"I will not harm her, by all saints I swear,"145
Quoth Porphyro: "O may I ne'er find grace
When my weak voice shall whisper its last prayer,
If one of her soft ringlets I displace,
Or look with ruffian passion in her face:
Good Angela, believe me by these tears;150
Or I will, even in a moment's space,
Awake, with horrid shout, my foemen's ears,
And beard them, though they be more fang'd than wolves and
bears."
XVIII
"Ah! why wilt thou affright a feeble soul?
A poor, weak, palsy-stricken, church-yard thing,155
Whose passing-bell may ere the midnight toll;
Whose prayers for thee, each morn and evening,
Were never miss'd." Thus plaining, doth she bring
A gentler speech from burning Porphyro;
So woful, and of such deep sorrowing,160
That Angela gives promise she will do
Whatever he shall wish, betide her weal or woe.
XIX
Which was, to lead him, in close secrecy,
Even to Madeline's chamber, and there hide
Him in a closet, of such privacy165
That he might see her beauty unespied,
And win perhaps that night a peerless bride,
While legion'd fairies paced the coverlet,
And pale enchantment held her sleepy-eyed.
Never on such a night have lovers met,170
Since Merlin[160] paid his Demon all the monstrous debt.
XX
"It shall be as thou wishest," said the Dame:
"All cates[161] and dainties shall be stored there
Quickly on this feast-night: by the tambour frame[162]
Her own lute thou wilt see: no time to spare,175
For I am slow and feeble, and scarce dare
On such a catering trust my dizzy head.
Wait here, my child, with patience; kneel in prayer
The while: Ah! thou must needs the lady wed,
Or may I never leave my grave among the dead."180
XXI
So saying she hobbled off with busy fear.
The lover's endless minutes slowly pass'd;
The Dame return'd, and whisper'd in his ear
To follow her; with aged eyes aghast
From fright of dim espial. Safe at last,185
Through many a dusky gallery, they gain
The maiden's chamber, silken, hush'd and chaste;
Where Porphyro took covert, pleased amain.
His poor guide hurried back with agues in her brain.
XXII
Her falt'ring hand upon the balustrade,190
Old Angela was feeling for the stair,
When Madeline, St. Agnes' charmed maid,
Rose, like a mission'd spirit, unaware:
With silver taper's light, and pious care,
She turn'd, and down the aged gossip led195
To a safe level matting. Now prepare,
Young Porphyro, for gazing on that bed;
She comes, she comes again, like ring-dove fray'd and fled.
XXIII
Out went the taper as she hurried in;
Its little smoke, in pallid moonshine, died:200
She closed the door, she panted, all akin
To spirits of the air, and visions wide:
No uttered syllable, or, woe betide!
But to her heart, her heart was voluble,
Paining with eloquence her balmy side;205
As though a tongueless nightingale should swell
Her throat in vain, and die, heart-stifled in her dell.
XXIV
A casement high[163] and triple arch'd there was,
All garlanded with carven imag'ries
Of fruits, and flowers, and bunches of knot-grass,210
And diamonded with panes of quaint device,
Innumerable of stains and splendid dyes,
As are the tiger-moth's deep-damask'd wings;
And in the midst, 'mong thousand heraldries,[164]
And twilight saints, and dim emblazonings,[165]215
A shielded scutcheon blush'd with blood of queens and kings.
XXV
Full on this casement shone the wintry moon,
And threw warm gules[166] on Madeline's fair breast,
As down she knelt for heaven's grace and boon;
Rose-bloom fell on her hands, together prest,220
And on her silver cross soft amethyst,
And on her hair a glory, like a saint:
She seem'd a splendid angel, newly drest,
Save wings, for heaven:—Porphyro grew faint;
She knelt, so pure a thing, so free from mortal taint.225
XXVI
Anon his heart revives: her vespers done,
Of all its wreathed pearls her hair she frees;
Unclasps her warmed jewels one by one;
Loosens her fragrant bodice; by degrees
Her rich attire creeps rustling to her knees:230
Half-hidden, like a mermaid in sea-weed,
Pensive awhile she dreams awake, and sees,
In fancy, fair St. Agnes in her bed,
But dares not look behind, or all the charm is fled.
XXVII
Soon, trembling in her soft and chilly nest,235
In sort of wakeful swoon, perplex'd she lay,
Until the poppied warmth of sleep oppress'd
Her soothed limbs, and soul fatigued away;
Flown, like a thought, until the morrow-day;
Blissfully haven'd both from joy and pain;240
Clasp'd like a missal[167] where swart Paynims pray;
Blinded alike from sunshine and from rain,
As though a rose should shut, and be a bud again.
XXVIII
Stol'n to this paradise, and so entranced,
Porphyro gazed upon her empty dress,245
And listen'd to her breathing, if it chanced
To wake into a slumberous tenderness;
Which when he heard, that minute did he bless,
And breathed himself: then from the closet crept,
Noiseless as fear in a wide wilderness,250
And over the hush'd carpet, silent, stept,
And 'tween the curtains peep'd, where, lo!—how fast she slept.
XXIX
Then by the bed-side, where the faded moon
Made a dim, silver twilight, soft he set
A table, and, half anguish'd, threw thereon255
A cloth of woven crimson, gold, and jet:—
O for some drowsy Morphean[168] amulet!
The boisterous, midnight, festive clarion,
The kettle-drum, and far-heard clarionet,
Affray his ears, though but in dying tone:—260
The hall-door shuts again, and all the noise is gone.
XXX
And still she slept an azure-lidded sleep,[169]
In blanched linen, smooth, and lavender'd,
While he from forth the closet brought a heap
Of candied apple, quince, and plum, and gourd;265
With jellies soother[170] than the creamy curd,
And lucent[171] syrops, tinct with cinnamon;
Manna and dates, in argosy transferr'd
From Fez; and spiced dainties, every one,
From silken Samarcand to cedar'd Lebanon.270
XXXI
These delicates he heap'd with glowing hand
On golden dishes and in baskets bright
Of wreathed silver: sumptuous they stand
In the retired quiet of the night,
Filling the chilly room with perfume light.—275
"And now, my love, my seraph fair, awake!
Thou art my heaven, and I thine eremite[172]:
Open thine eyes, for meek St. Agnes' sake,
Or I shall drowse beside thee, so my soul doth ache."
XXXII
Thus whispering, his warm, unnerved arm280
Sank in her pillow. Shaded was her dream
By the dusk curtains:—'twas a midnight charm
Impossible to melt as iced stream:
The lustrous salvers in the moonlight gleam;
Broad golden fringe upon the carpet lies:285
It seem'd he never, never could redeem
From such a steadfast spell his lady's eyes;
So mused awhile, entoil'd in woofed phantasies.
XXXIII
Awakening up, he took her hollow lute,—
Tumultuous,—and, in chords that tenderest be.290
He play'd an ancient ditty, long since mute,
In Provence call'd "La belle dame sans mercy:[173]"
Close to her ear touching the melody;—
Wherewith disturb'd, she utter'd a soft moan:
He ceased—she panted quick—and suddenly295
Her blue affrayed eyes wide open shone:
Upon his knees he sank, pale as smooth-sculptured stone.
XXXIV
Her eyes were open, but she still beheld,
Now wide awake, the vision of her sleep:
There was a painful change, that nigh expell'd300
The blisses of her dream so pure and deep
At which fair Madeline began to weep,
And moan forth witless words with many a sigh;
While still her gaze on Porphyro would keep;
Who knelt, with joined hands and piteous eye,305
Fearing to move or speak, she look'd so dreamingly.
XXXV
"Ah, Porphyro!" said she, "but even now
Thy voice was at sweet tremble in mine ear,
Made tuneable with every sweetest vow;
And those sad eyes were spiritual and clear:310
How changed thou art! how pallid, chill, and drear!
Give me that voice again, my Porphyro,
Those looks immortal, those complainings dear!
Oh leave me not in this eternal woe,
For if thou diest, my Love, I know not where to go."315
XXXVI
Beyond a mortal man impassion'd far
At these voluptuous accents, he arose,
Ethereal, flush'd, and like a throbbing star
Seen 'mid the sapphire heaven's deep repose;
Into her dream he melted, as the rose320
Blendeth its odour with the violet,—
Solution sweet: meantime the frost-wind blows
Like Love's alarum pattering the sharp sleet
Against the window-panes; St. Agnes' moon hath set.
XXXVII
'Tis dark: quick pattereth the flaw-blown sleet:325
"This is no dream, my bride, my Madeline!"
'Tis dark: the iced gusts still rave and beat:
"No dream, alas! alas! and woe is mine!
Porphyro will leave me here to fade and pine.—
Cruel! what traitor could thee hither bring?330
I curse not, for my heart is lost in thine,
Though thou forsakest a deceived thing;—
A dove forlorn and lost with sick unpruned wing."
XXXVIII
"My Madeline! sweet dreamer! lovely bride!
Say, may I be for aye thy vassal blest?335
Thy beauty's shield, heart-shaped and vermeil dyed?
Ah, silver shrine, here will I take my rest
After so many hours of toil and quest,
A famish'd pilgrim,—saved by miracle.
Though I have found, I will not rob thy nest340
Saving of thy sweet self; if thou think'st well
To trust, fair Madeline, to no rude infidel.
XXXIX
"Hark! 'tis an elfin storm from faery land,
Of haggard seeming, but a boon indeed:
Arise—arise! the morning is at hand:—345
The bloated wassailers[174] will never heed:—
Let us away, my love, with happy speed;
There are no ears to hear, or eyes to see,—
Drown'd all in Rhenish and the sleepy mead:
Awake! arise! my love, and fearless be,350
For o'er the southern moors I have a home for thee."
XL
She hurried at his words, beset with fears,
For there were sleeping dragons all around,
At glaring watch, perhaps, with ready spears—
Down the wide stairs a darkling way they found.—355
In all the house was heard no human sound.
A chain-droop'd lamp was flickering by each door;
The arras, rich with horseman, hawk, and hound,
Flutter'd in the besieging wind's uproar;
And the long carpets rose along the gusty floor.360
XLI
They glide, like phantoms, into the wide hall;
Like phantoms to the iron porch they glide,
Where lay the Porter, in uneasy sprawl,
With a huge empty flagon by his side:
The wakeful bloodhound rose, and shook his hide,365
But his sagacious eye an inmate owns:
By one, and one, the bolts full easy slide:—
The chains lie silent on the footworn stones;—
The key turns, and the door upon its hinges groans;
XLII
And they are gone: aye, ages long ago370
These lovers fled away into the storm.
That night the Baron dreamt of many a woe,
And all his warrior-guests, with shade and form
Of witch, and demon, and large coffin-worm,
Were long be-nightmared. Angela[175] the old375
Died palsy-twitch'd, with meagre face deform;
The Beadsman, after thousand aves told,
For aye unsought-for slept among his ashes cold.
ALFRED TENNYSON
DORA
With farmer Allan at the farm abode
William and Dora. William was his son,
And she his niece. He often looked at them,
And often thought, "I'll make them man and wife."
Now Dora felt her uncle's will in all,5
And yearn'd towards William; but the youth, because
He had been always with her in the house,
Thought not of Dora.
Then there came a day
When Allan call'd his son, and said, "My son:
I married late, but I would wish to see10
My grandchild on my knees before I die:
And I have set my heart upon a match.
Now therefore look to Dora; she is well
To look to; thrifty too beyond her age.
She is my brother's daughter: he and I15
Had once hard words, and parted, and he died
In foreign lands; but for his sake I bred
His daughter Dora: take her for your wife;
For I have wish'd this marriage, night and day,
For many years." But William answer'd short:20
"I cannot marry Dora; by my life,
I will not marry Dora." Then the old man
Was wroth, and doubled up his hands, and said:
"You will not, boy! you dare to answer thus!
But in my time a father's word was law,25
And so it shall be now for me. Look to it;
Consider, William: take a month to think,
And let me have an answer to my wish;
Or, by the Lord that made me, you shall pack,
And never more darken my doors again."30
But William answer'd madly; bit his lips,
And broke away. The more he look'd at her
The less he liked her; and his ways were harsh;
But Dora bore them meekly. Then before
The month was out he left his father's house,35
And hired himself to work within the fields;
And half in love, half spite, he woo'd and wed
A laborer's daughter, Mary Morrison.
Then, when the bells were ringing, Allan call'd
His niece and said: "My girl, I love you well;40
But if you speak with him that was my son,
Or change a word with her he calls his wife,
My home is none of yours. My will is law."
And Dora promised, being meek. She thought,
"It cannot be: my uncle's mind will change!"45
And days went on, and there was born a boy
To William; then distresses came on him;
And day by day he pass'd his father's gate,
Heart-broken, and his father help'd him not.
But Dora stored what little she could save,50
And sent it them by stealth, nor did they know
Who sent it; till at last a fever seized
On William, and in harvest time he died.
Then Dora went to Mary. Mary sat
And look'd with tears upon her boy, and thought55
Hard things of Dora. Dora came and said:
"I have obey'd my uncle until now,
And I have sinn'd, for it was all thro' me
This evil came on William at the first.
But, Mary, for the sake of him that's gone,60
And for your sake, the woman that he chose,
And for this orphan, I am come to you:
You know there has not been for these five years
So full a harvest: let me take the boy,
And I will set him in my uncle's eye65
Among the wheat; that when his heart is glad
Of the full harvest, he may see the boy,
And bless him for the sake of him that's gone."
And Dora took the child, and went her way
Across the wheat, and sat upon a mound70
That was unsown, where many poppies grew.
Far off the farmer came into the field
And spied her not; for none of all his men
Dare tell him Dora waited with the child;
And Dora would have risen and gone to him,75
But her heart fail'd her; and the reapers reap'd,
And the sun fell, and all the land was dark.
But when the morrow came, she rose and took
The child once more, and sat upon the mound;
And made a little wreath of all the flowers80
That grew about, and tied it round his hat
To make him pleasing in her uncle's eye.
Then when the farmer pass'd into the field
He spied her, and he left his men at work,
And came and said: "Where were you yesterday?85
Whose child is that? What are you doing here?"
So Dora cast her eyes upon the ground,
And answer'd softly, "This is William's child!"
"And did I not," said Allan, "did I not
Forbid you, Dora?" Dora said again:90
"Do with me as you will, but take the child,
And bless him for the sake of him that's gone!"
And Allan said, "I see it is a trick
Got up betwixt you and the woman there.
I must be taught my duty, and by you!95
You knew my word was law, and yet you dared
To slight it. Well—for I will take the boy;
But go you hence, and never see me more."
So saying, he took the boy, that cried aloud
And struggled hard. The wreath of flowers fell100
At Dora's feet. She bow'd upon her hands,
And the boy's cry came to her from the field,
More and more distant. She bow'd down her head,
Remembering the day when first she came,
And all the things that had been. She bow'd down105
And wept in secret; and the reapers reap'd,
And the sun fell, and all the land was dark.
Then Dora went to Mary's house, and stood
Upon the threshold. Mary saw the boy
Was not with Dora. She broke out in praise110
To God, that help'd her in her widowhood.
And Dora said, "My uncle took the boy;
But, Mary, let me live and work with you:
He says that he will never see me more."
Then answer'd Mary, "This shall never be,115
That thou shouldst take my trouble on thyself:
And, now I think, he shall not have the boy,
For he will teach him hardness, and to slight
His mother; therefore thou and I will go,
And I will have my boy, and bring him home;120
And I will beg of him to take thee back:
But if he will not take thee back again,
Then thou and I will live within one house,
And work for William's child, until he grows
Of age to help us."
So the women kiss'd125
Each other, and set out, and reach'd the farm.
The door was off the latch: they peep'd, and saw
The boy set up betwixt his grandsire's knees,
Who thrust him in the hollows of his arm,
And clapt him on the hands and on the cheeks,130
Like one that loved him: and the lad stretch'd out
And babbled for the golden seal, that hung
From Allan's watch, and sparkled by the fire.
Then they came in: but when the boy beheld
His mother, he cried out to come to her:135
And Allan set him down, and Mary said:
"O Father!—if you let me call you so—
I never came a-begging for myself,
Or William, or this child; but now I come
For Dora: take her back; she loves you well.140
O Sir, when William died, he died at peace
With all men; for I ask'd him, and he said,
He could not ever rue his marrying me—
I had been a patient wife: but, Sir, he said
That he was wrong to cross his father thus:145
'God bless him!' he said, 'and may he never know
The troubles I have gone thro'!' Then he turn'd
His face and pass'd—unhappy that I am!
But now, Sir, let me have my boy, for you
Will make him hard, and he will learn to slight150
His father's memory; and take Dora back,
And let all this be as it was before."
So Mary said, and Dora hid her face
By Mary. There was silence in the room;
And all at once the old man burst in sobs:—155
"I have been to blame—to blame. I have kill'd my son.
I have kill'd him—but I loved him—my dear son.
May God forgive me!—I have been to blame.
Kiss me, my children."
Then they clung about
The old man's neck, and kiss'd him many times160
And all the man was broken with remorse;
And all his love came back a hundredfold;
And for three hours he sobb'd o'er William's child,
Thinking of William.
So those four abode
Within one house together; and as years165
Went forward, Mary took another mate;
But Dora lived unmarried till her death.
ŒNONE—1832
There lies a vale in Ida,[176] lovelier
Than all the valleys of Ionian[177] hills.
The swimming vapour slopes athwart the glen,
Puts forth an arm, and creeps from pine to pine,
And loiters, slowly drawn. On either hand5
The lawns and meadow-ledges midway down
Hang rich in flowers, and far below them roars
The long brook falling thro' the clov'n ravine
In cataract after cataract to the sea.
Behind the valley topmost Gargarus[178]10
Stands up and takes the morning: but in front
The gorges, opening wide apart, reveal
Troas[179] and Ilion's[180] column'd citadel,
The crown of Troas.
Hither came at noon
Mournful Œnone, wandering forlorn15
Of Paris,[181] once her playmate on the hills.
Her cheek had lost the rose, and round her neck
Floated her hair or seem'd to float in rest.
She, leaning on a fragment twined with vine,
Sang to the stillness, till the mountain-shade20
Sloped downward to her seat from the upper cliff.
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.
textbookfull.com