The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Tutorial #12 - Displaying the Book

At this point, you are probably wondering when we are ever going to have our digital book reader let us read a digital book.

Now, in this tutorial, your patience will be rewarded.

This is a continuation of the work we did in the previous tutorial.

You can find the results of the previous tutorial and the results of this tutorial in the book’s GitHub repository.

Note that starting in this tutorial, it is assumed that you know how to add import statements as needed as we refer to new classes in existing code, and so the required imports are not always going to be specified.

Step #1: Adding a Book

First, we need a book. Expecting you to write a book as part of this tutorial would seem to be a bit excessive. So, instead, we will use an already-written book: The War of the Worlds, by H. G. Wells, as distributed by Project Gutenberg.

EDITOR’S NOTE: We realize that this choice of book may be seen as offensive by Martians, as it depicts them as warlike invaders with limited immune systems. Please understand that this book is a classic of Western literature and reflects the attitude of the times. If you have any concerns about this material, please contact us at martians-so-do-not-exist@commonsware.com.

Download http://misc.commonsware.com/WarOfTheWorlds.zip and unpack its contents (a book/ directory of files) into your assets/ folder of your project. Windows and Linux Android Studio users can drag this book/ directory into the project and drop it in assets/ to copy the files to the proper location. You should wind up with assets/book/ and files inside of there:

Android Studio Project Explorer, Showing assets/book/
Figure 274: Android Studio Project Explorer, Showing assets/book/

In that directory, you will find some HTML and CSS files with the prose of the book, plus a contents.json file with metadata. We will examine this metadata in greater detail in the next section.

Step #2: Creating a ModelFragment

The preview of this section was traded for a bag of magic beans.

Step #3: Defining Our Model

The preview of this section was fed to a gremlin, after midnight.

Step #4: Examining Our Model

The preview of this section is en route to Mars.

Step #5: Defining Our Event

The preview of this section apparently resembled a Pokémon.

Step #6: Loading Our Model

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

Step #7: Registering for Events

The preview of this section is presently indisposed.

Step #8: Adapting the Content

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

Step #9: Showing the Content When Loaded

The preview of this section was the victim of a MITM ('Martian in the middle') attack.

Step #10: Attaching our ModelFragment

The preview of this section is in the process of being translated from its native Klingon.

Step #11: Showing the Content After a Configuration Change

The preview of this section is presently indisposed.

Step #12: Setting Up StrictMode

The preview of this section was fed to a gremlin, after midnight.

In Our Next Episode…

The preview of this section will not appear here for a while, due to a time machine mishap.