Android™ How to Program, Second Edition

Book description

Android How to Program, Second Editionprovides a clear and entertaining App-driven introduction to Android 4.3 and 4.4 development for both introductory- and intermediate-level programming courses. It also serves as a great reference and tutorial to learn Android programming.

The Deitels' App-driven Approach is simply the best way to master Android programming! The Deitels teach Android programming through seven complete, working Android Apps in the print book and more online. Each chapter presents new concepts through a single App. The authors first provide an introduction to the app, an app test-drive showing one or more sample executions, and a technologies overview. Next, the authors proceed with a detailed code walkthrough of the app’s source code in which they discuss the programming concepts and demonstrate the functionality of the Android APIs used in the app. The book also has an extensive introduction to programming using the Java language, making this book appropriate for Java courses that want to add an App-programming flavor.

Teaching and Learning Experience

This program will provide a better teaching and learning experience—for you and your students.

  • Add an App Component to your Java Course: The appendices provide a condensed, friendly introduction to Java and the object-oriented programming techniques students will need to develop Android apps.

  • Motivate Students with an App-driven Approach to Android 4.3 and 4.4 Development: Concepts are presented in the context of 7 complete working Android Apps, using the latest mobile computing technologies.

  • Enhance Learning with Outstanding Pedagogical Features: The Deitels present hundreds of Android short-answer questions and app-development exercises complete with syntax coloring, code walkthroughs and sample outputs.

  • Table of contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Deitel® Series Page
      1. How To Program Series
      2. Simply Series
      3. Course Smart Web Books
      4. Deitel® Developer Series
      5. LiveLessons Video Learning Products
    5. Dedication Page
    6. Contents
    7. Preface
      1. Android How to Program, 2/e
      2. Intended Audiences
      3. App-Development Courses
      4. Android Ecosystem: Competition, Innovation, Explosive Growth and Opportunities
      5. App-Driven Approach
      6. Online Chapters and Book Updates
      7. Copyright Notice and Code License
      8. Getting up to Speed in Java and XML
      9. Key Features of Android How to Program, 2/e
      10. Working with Open-Source Apps
      11. Pedagogic Features
      12. Software Used in Android How to Program, 2/e
      13. Instructor Resources
      14. Before You Begin
      15. Acknowledgments
        1. Reviewers of the Content from Android How to Program and Android for Programmers: An App-Driven Approach Recent Editions
      16. About the Authors
      17. Deitel® Dive-Into® Series Programming Languages Training
    8. Before You Begin
      1. Font and Naming Conventions
      2. Software and Hardware System Requirements
      3. Installing the Java Development Kit (JDK)
      4. Android Integrated Development Environment (IDE) Options
      5. Installing the Android SDK/ADT Bundle
      6. Installing Android Studio
      7. Set the Java Compiler Compliance Level and Show Line Numbers
      8. Android 4.3 SDK
      9. Creating Android Virtual Devices (AVDs)
      10. (Optional) Setting Up an Android Device for Development
      11. Obtaining the Book’s Code Examples
      12. A Note Regarding the Android Development Tools
    9. 1. Introduction to Android
      1. 1.1. Introduction
        1. App-Driven Approach
      2. 1.2. Android—The World’s Leading Mobile Operating System
      3. 1.3. Android Features
        1. Openness and Open Source
        2. Java
        3. Multitouch Screen
        4. Gestures
        5. Built-in Apps
        6. Web Services
      4. 1.4. Android Operating System
        1. Android Version Naming Convention
        2. 1.4.1. Android 2.2 (Froyo)
        3. 1.4.2. Android 2.3 (Gingerbread)
        4. 1.4.3. Android 3.0 through 3.2 (Honeycomb)
        5. 1.4.4. Android 4.0 through 4.0.4 (Ice Cream Sandwich)
        6. 1.4.5. Android 4.1–4.3 (Jelly Bean)
        7. 1.4.6. Android 4.4 (KitKat)
      5. 1.5. Downloading Apps from Google Play
      6. 1.6. Packages
      7. 1.7. Android Software Development Kit (SDK)
        1. Android SDK/ADT Bundle
        2. Android Studio
        3. Android Development Tools (ADT) Plugin for Eclipse
        4. The Android Emulator
      8. 1.8. Object-Oriented Programming: A Quick Refresher
        1. 1.8.1. The Automobile as an Object
        2. 1.8.2. Methods and Classes
        3. 1.8.3. Instantiation
        4. 1.8.4. Reuse
        5. 1.8.5. Messages and Method Calls
        6. 1.8.6. Attributes and Instance Variables
        7. 1.8.7. Encapsulation
        8. 1.8.8. Inheritance
        9. 1.8.9. Object-Oriented Analysis and Design (OOAD)
      9. 1.9. Test-Driving the Doodlz App in an Android Virtual Device (AVD)
        1. Android SDK/ADT Bundle and Android Studio IDEs
        2. 1.9.1. Running the Doodlz App in the Nexus 4 Smartphone AVD
        3. 1.9.2. Running the Doodlz App in a Tablet AVD
        4. 1.9.3. Running the Doodlz App on an Android Device
      10. 1.10. Building Great Android Apps
      11. 1.11. Android Development Resources
      12. 1.12. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    10. 2. Welcome App
      1. 2.1. Introduction
      2. 2.2. Technologies Overview
        1. 2.2.1. Android Developer Tools IDE
        2. 2.2.2. TextViews and ImageViews
        3. 2.2.3. App Resources
        4. 2.2.4. Accessibility
        5. 2.2.5. Internationalization
      3. 2.3. Creating an App
        1. 2.3.1. Launching the Android Developer Tools IDE
        2. 2.3.2. Creating a New Project
        3. 2.3.3. New Android Application Dialog
        4. 2.3.4. Configure Project Step
        5. 2.3.5. Configure Launcher Icon Step
        6. 2.3.6. Create Activity Step
        7. 2.3.7. Blank Activity Step
      4. 2.4. Android Developer Tools Window
        1. 2.4.1. Package Explorer Window
        2. 2.4.2. Editor Windows
        3. 2.4.3. Outline Window
        4. 2.4.4. App Resource Files
        5. 2.4.5. Graphical Layout Editor
        6. 2.4.6. The Default GUI
      5. 2.5. Building the App’s GUI with the Graphical Layout Editor
        1. 2.5.1. Adding Images to the Project
        2. 2.5.2. Changing the FrameLayout to a RelativeLayout
        3. 2.5.3. Adding and Configuring the TextView
        4. 2.5.4. Adding ImageViews to Display the Images
      6. 2.6. Running the Welcome App
      7. 2.7. Making Your App Accessible
        1. Enabling TalkBack for the ImageViews
        2. Testing the App with TalkBack Enabled
        3. Learning More About Accessibility
      8. 2.8. Internationalizing Your App
        1. Localization
        2. Naming the Folders for Localized Resources
        3. Adding a Localization Folder to the App’s Project
        4. Copying the strings.xml File into the values-es Folder
        5. Localizing the Strings
        6. Testing the App in Spanish
        7. Returning the AVD (or Device) to English
        8. TalkBack and Localization
        9. Localization Checklist
      9. 2.9. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    11. 3. Tip Calculator App
      1. 3.1. Introduction
      2. 3.2. Test-Driving the Tip Calculator App
        1. Open and Run the App
        2. Entering a Bill Total
        3. Selecting a Custom Tip Percentage
      3. 3.3. Technologies Overview
        1. 3.3.1. Class Activity
        2. 3.3.2. Activity Lifecycle Methods
        3. 3.3.3. Arranging Views with LinearLayout and GridLayout
        4. 3.3.4. Creating and Customizing the GUI with the Graphical Layout Editor and the Outline and Properties Windows
        5. 3.3.5. Formatting Numbers as Locale-Specific Currency and Percentage Strings
        6. 3.3.6. Implementing Interface TextWatcher for Handling EditText Text Changes
        7. 3.3.7. Implementing Interface OnSeekBarChangeListener for Handling SeekBar Thumb Position Changes
        8. 3.3.8. AndroidManifest.xml
      4. 3.4. Building the App’s GUI
        1. 3.4.1. GridLayout Introduction
        2. 3.4.2. Creating the TipCalculator Project
        3. 3.4.3. Changing to a GridLayout
        4. 3.4.4. Adding the TextViews, EditText, SeekBar and LinearLayouts
        5. 3.4.5. Customizing the Views to Complete the Design
      5. 3.5. Adding Functionality to the App
        1. The package and import Statements
        2. Tip Calculator App Activity and the Activity Lifecycle
        3. Class Variables and Instance Variables
        4. Overriding Method onCreate of Class Activity
        5. onCreate’s Bundle Parameter
        6. Generated R Class Contains Resource IDs
        7. Inflating the GUI
        8. Getting References to the Widgets
        9. Displaying Initial Values in the TextViews
        10. Registering the Event Listeners
        11. Method updateStandard of Class MainActivity
        12. Method updateCustom of Class MainActivity
        13. Anonymous Inner Class That Implements Interface OnSeekBarChangeListener
        14. Overriding Method onProgressChanged of Interface OnSeekBarChangeListener
        15. Overriding Methods onStartTrackingTouch and onStopTrackingTouch of Interface OnSeekBarChangeListener
        16. Anonymous Inner Class That Implements Interface TextWatcher
        17. Overriding Method onTextChanged of Interface TextWatcher
        18. Other Methods of the amountEditTextWatcher TextWatcher
      6. 3.6. AndroidManifest.xml
        1. Configuring MainActivity for Portrait Orientation
        2. Forcing the Soft Keypad to Always Display for MainActivity
      7. 3.7. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    12. 4. Twitter® Searches App
      1. 4.1. Introduction
      2. 4.2. Test-Driving the App
        1. 4.2.1. Importing the App and Running It
        2. 4.2.2. Adding a Favorite Search
        3. 4.2.3. Viewing Twitter Search Results
        4. 4.2.4. Editing a Search
        5. 4.2.5. Sharing a Search
        6. 4.2.6. Deleting a Search
        7. 4.2.7. Scrolling Through Saved Searches
      3. 4.3. Technologies Overview
        1. 4.3.1. ListView
        2. 4.3.2. ListActivity
        3. 4.3.3. Customizing a ListActivity’s Layout
        4. 4.3.4. ImageButton
        5. 4.3.5. SharedPreferences
        6. 4.3.6. Intents for Launching Other Activities
        7. 4.3.7. AlertDialog
        8. 4.3.8. AndroidManifest.xml
      4. 4.4. Building the App’s GUI
        1. 4.4.1. Creating the Project
        2. 4.4.2. activity_main.xml Overview
        3. 4.4.3. Adding the GridLayout and Components
        4. 4.4.4. Graphical Layout Editor Toolbar
        5. 4.4.5. ListView Item’s Layout: list_item.xml
      5. 4.5. Building the MainActivity Class
        1. 4.5.1. package and import Statements
        2. 4.5.2. Extending ListActivity
        3. 4.5.3. Fields of Class MainActivity
        4. 4.5.4. Overriding Activity Method onCreate
        5. 4.5.5. Anonymous Inner Class That Implements the saveButton’s OnClickListener to Save a New or Updated Search
        6. 4.5.6. addTaggedSearch Method
        7. 4.5.7. Anonymous Inner Class That Implements the ListView’s OnItemClickListener to Display Search Results
        8. 4.5.8. Anonymous Inner Class That Implements the ListView’s OnItemLongClickListener to Share, Edit or Delete a Search
        9. 4.5.9. shareSearch Method
        10. 4.5.10. deleteSearch Method
      6. 4.6. AndroidManifest.xml
      7. 4.7. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
        4. Project Exercises
        5. Advanced Project Exercises
    13. 5. Flag Quiz App
      1. 5.1. Introduction
      2. 5.2. Test-Driving the Flag Quiz App
        1. 5.2.1. Importing the App and Running It
        2. 5.2.2. Configuring the Quiz
        3. 5.2.3. Taking the Quiz
      3. 5.3. Technologies Overview
        1. 5.3.1. Menus
        2. 5.3.2. Fragments
        3. 5.3.3. Fragment Lifecycle Methods
        4. 5.3.4. Managing Fragments
        5. 5.3.5. Preferences
        6. 5.3.6. assets Folder
        7. 5.3.7. Resource Folders
        8. 5.3.8. Supporting Different Screen Sizes and Resolutions
        9. 5.3.9. Determining the Screen Size
        10. 5.3.10. Toasts for Displaying Messages
        11. 5.3.11. Using a Handler to Execute a Runnable in the Future
        12. 5.3.12. Applying an Animation to a View
        13. 5.3.13. Logging Exception Messages
        14. 5.3.14. Using an Explicit Intent to Launch Another Activity in the Same App
        15. 5.3.15. Java Data Structures
      4. 5.4. Building the GUI and Resource Files
        1. 5.4.1. Creating the Project
        2. 5.4.2. strings.xml and Formatted String Resources
        3. 5.4.3. arrays.xml
        4. 5.4.4. colors.xml
        5. 5.4.5. dimens.xml
        6. 5.4.6. activity_settings.xml Layout
        7. 5.4.7. activity_main.xml Layout for Phone and Tablet Portrait Orientation
        8. 5.4.8. fragment_quiz.xml Layout
        9. 5.4.9. activity_main.xml Layout for Tablet Landscape Orientation
        10. 5.4.10. preferences.xml for Specifying the App’s Settings
        11. 5.4.11. Creating the Flag Shake Animation
      5. 5.5. MainActivity Class
        1. 5.5.1. package Statement, import Statements and Fields
        2. 5.5.2. Overridden Activity Method onCreate
        3. 5.5.3. Overridden Activity Method onStart
        4. 5.5.4. Overridden Activity Method onCreateOptionsMenu
        5. 5.5.5. Overridden Activity Method onOptionsItemSelected
        6. 5.5.6. Anonymous Inner Class That Implements OnSharedPreferenceChangeListener
      6. 5.6. QuizFragment Class
        1. 5.6.1. package Statement and import Statements
        2. 5.6.2. Fields
        3. 5.6.3. Overridden Fragment Method onCreateView
        4. 5.6.4. Method updateGuessRows
        5. 5.6.5. Method updateRegions
        6. 5.6.6. Method resetQuiz
        7. 5.6.7. Method loadNextFlag
        8. 5.6.8. Method getCountryName
        9. 5.6.9. Anonymous Inner Class That Implements OnClickListener
        10. 5.6.10. Method disableButtons
      7. 5.7. SettingsFragment Class
      8. 5.8. SettingsActivity Class
      9. 5.9. AndroidManifest.xml
      10. 5.10. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    14. 6. Cannon Game App
      1. 6.1. Introduction
      2. 6.2. Test-Driving the Cannon Game App
        1. Opening and Running the App
        2. Playing the Game
      3. 6.3. Technologies Overview
        1. 6.3.1. Attaching a Custom View to a Layout
        2. 6.3.2. Using the Resource Folder raw
        3. 6.3.3. Activity and Fragment Lifecycle Methods
        4. 6.3.4. Overriding View Method onTouchEvent
        5. 6.3.5. Adding Sound with SoundPool and AudioManager
        6. 6.3.6. Frame-by-Frame Animation with Threads, SurfaceView and SurfaceHolder
        7. 6.3.7. Simple Collision Detection
        8. 6.3.8. Drawing Graphics Using Paint and Canvas
      4. 6.4. Building the App’s GUI and Resource Files
        1. 6.4.1. Creating the Project
        2. 6.4.2. strings.xml
        3. 6.4.3. fragment_game.xml
        4. 6.4.4. activity_main.xml
        5. 6.4.5. Adding the Sounds to the App
      5. 6.5. Class Line Maintains a Line’s Endpoints
      6. 6.6. MainActivity Subclass of Activity
      7. 6.7. CannonGameFragment Subclass of Fragment
      8. 6.8. CannonView Subclass of View
        1. 6.8.1. package and import Statements
        2. 6.8.2. Instance Variables and Constants
        3. 6.8.3. Constructor
        4. 6.8.4. Overriding View Method onSizeChanged
        5. 6.8.5. Method newGame
        6. 6.8.6. Method updatePositions
        7. 6.8.7. Method fireCannonball
        8. 6.8.8. Method alignCannon
        9. 6.8.9. Method drawGameElements
        10. 6.8.10. Method showGameOverDialog
        11. 6.8.11. Methods stopGame and releaseResources
        12. 6.8.12. Implementing the SurfaceHolder.Callback Methods
        13. 6.8.13. Overriding View Method onTouchEvent
        14. 6.8.14. CannonThread: Using a Thread to Create a Game Loop
      9. 6.9. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    15. 7. Doodlz App
      1. 7.1. Introduction
      2. 7.2. Technologies Overview
        1. 7.2.1. Using SensorManager to Listen for Accelerometer Events
        2. 7.2.2. Custom DialogFragments
        3. 7.2.3. Drawing with Canvas and Bitmap
        4. 7.2.4. Processing Multiple Touch Events and Storing Lines in Paths
        5. 7.2.5. Android 4.4 Immersive Mode
        6. 7.2.6. GestureDetector and SimpleOnGestureListener
        7. 7.2.7. Saving the Drawing to the Device’s Gallery
        8. 7.2.8. Android 4.4 Printing and the Android Support Library’s PrintHelper Class
      3. 7.3. Building the App’s GUI and Resource Files
        1. 7.3.1. Creating the Project
        2. 7.3.2. strings.xml
        3. 7.3.3. dimens.xml
        4. 7.3.4. Menu for the DoodleFragment
        5. 7.3.5. activity_main.xml Layout for MainActivity
        6. 7.3.6. fragment_doodle.xml Layout for DoodleFragment
        7. 7.3.7. fragment_color.xml Layout for ColorDialogFragment
        8. 7.3.8. fragment_line_width.xml Layout for LineWidthDialogFragment
        9. 7.3.9. Adding Class EraseImageDialogFragment
      4. 7.4. MainActivity Class
      5. 7.5. DoodleFragment Class
        1. package Statement, import Statements and Fields
        2. Overriding Fragment Method onCreateView
        3. Methods onStart and enableAccelerometerListening
        4. Methods onPause and disableAccelerometerListening
        5. Anonymous Inner Class That Implements Interface SensorEventListener to Process Accelerometer Events
        6. Method confirmErase
        7. Overridden Fragment Methods onCreateOptionsMenu and onOptionsItemSelected
        8. Methods getDoodleView and setDialogOnScreen
      6. 7.6. DoodleView Class
        1. DooldleView package Statement and import Statements
        2. DoodleView static and Instance Variables
        3. DoodleView Constructor
        4. Overridden View Method onSizeChanged
        5. DoodleView Methods clear, setDrawingColor, getDrawingColor, setLineWidth and getLineWidth
        6. Overridden View Method onDraw
        7. DoodleView Methods hideSystemBars and showSystemBars
        8. Anonymous Inner Class that Implements Interface SimpleOnGestureListener
        9. Overridden View Method onTouchEvent
        10. touchStarted Method of Class DoodleView
        11. touchMoved Method of Class DoodleView
        12. touchEnded Method of Class DoodleView
        13. DoodleView Method saveImage
        14. DoodleView Method printImage
      7. 7.7. ColorDialogFragment Class
        1. Overridden DialogFragment Method onCreateDialog
        2. Method getDoodleFragment
        3. Overridden Fragment Lifecycle Methods onAttach and onDetach
        4. Anonymous Inner Class That Implements Interface OnSeekBarChangeListener to Respond to the Events of the Alpha, Red, Green and Blue SeekBars
      8. 7.8. LineWidthDialogFragment Class
        1. Method onCreateDialog
        2. Anonymous Inner Class That Implements Interface OnSeekBarChangeListener to Respond to the Events of the widthSeekBar
      9. 7.9. EraseImageDialogFragment Class
      10. 7.10. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    16. 8. Address Book App
      1. 8.1. Introduction
      2. 8.2. Test-Driving the Address Book App
        1. Opening and Running the App
        2. Adding a Contact
        3. Viewing a Contact
        4. Editing a Contact
        5. Deleting a Contact
      3. 8.3. Technologies Overview
        1. 8.3.1. Displaying Fragments with FragmentTransactions
        2. 8.3.2. Communicating Data Between a Fragment and a Host Activity
        3. 8.3.3. Method onSaveInstanceState
        4. 8.3.4. Defining Styles and Applying Them to GUI Components
        5. 8.3.5. Specifying a Background for a TextView
        6. 8.3.6. Extending Class ListFragment to Create a Fragment That Contains a ListView
        7. 8.3.7. Manipulating a SQLite Database
        8. 8.3.8. Performing Database Operations Outside the GUI Thread with AsyncTasks
      4. 8.4. Building the GUI and Resource Files
        1. 8.4.1. Creating the Project
        2. 8.4.2. Creating the App’s Classes
        3. 8.4.3. strings.xml
        4. 8.4.4. styles.xml
        5. 8.4.5. textview_border.xml
        6. 8.4.6. MainActivity’s Layout: activity_main.xml
        7. 8.4.7. DetailsFragment’s Layout: fragment_details.xml
        8. 8.4.8. AddEditFragment’s Layout: fragment_add_edit.xml
        9. 8.4.9. Defining the Fragments’ Menus
      5. 8.5. MainActivity Class
        1. MainActivity package Statement, import statements and Fields
        2. MainActivity Overridden onCreate Method
        3. MainActivity Overridden onResume Method
        4. MainActivity Method onContactSelected
        5. MainActivity Method displayContact
        6. MainActivity Method onAddContact
        7. MainActivity Method displayAddEditFragment
        8. MainActivity Method onContactDeleted
        9. MainActivity Method onEditContact
        10. MainActivity Method onAddEditCompleted
      6. 8.6. ContactListFragment Class
        1. ContactListFragment package Statement and import Statements
        2. ContactListFragmentListener Interface and ContactListFragment Instance Variables
        3. ContactListFragment Overridden Methods onAttach and onDetach
        4. ContactListFragment Overridden Method onViewCreated
        5. Configuring the CursorAdapter That Binds Database Data to the ListView
        6. viewContactListener That Processes ListView Item Selection Events
        7. ContactListFragment Overridden Method onResume
        8. GetContactsTask Subclass of AsyncTask
        9. ContactListFragment Overridden Method onStop
        10. ContactListFragment Overridden Methods onCreateOptionsMenu and onOptionsItemSelected
        11. ContactListFragment Method updateContactList
      7. 8.7. AddEditFragment Class
        1. AddEditFragment package Statement and import Statements
        2. AddEditFragmentListener Interface
        3. AddEditFragment Instance Variables
        4. AddEditFragment Overridden Methods onAttach and onDetach
        5. AddEditFragment Overridden Method onCreateView
        6. OnClickListener to Process Save Contact Button Events
        7. AddEditFragment Method saveContact
      8. 8.8. DetailsFragment Class
        1. DetailsFragment package Statement and import Statements
        2. DetailsFragmentListener Interface
        3. DetailsFragment Instance Variables
        4. DetailsFragment Overridden Methods onAttach and onDetach
        5. DetailsFragment Overridden Method onCreateView
        6. DetailsFragment Overridden Method onResume
        7. DetailsFragment Overridden Method onSaveInstanceState
        8. DetailsFragment Overridden Methods onCreateOptionsMenu and onOptionsItemSelected
        9. LoadContactTask Subclass of AsyncTask
        10. Method deleteContact and DialogFragment confirmDelete
      9. 8.9. DatabaseConnector Utility Class
        1. package Statement, import Statements and Fields
        2. DatabaseConnector Constructor and Methods open and close
        3. DatabaseConnector Method insertContact
        4. DatabaseConnector Method updateContact
        5. Method getAllContacts
        6. Method getOneContact
        7. Method deleteContact
        8. private Nested Class DatabaseOpenHelper That Extends SQLiteOpenHelper
      10. 8.10. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    17. 9. Google Play and App Business Issues
      1. 9.1. Introduction
      2. 9.2. Preparing Your Apps for Publication
        1. 9.2.1. Testing Your App
        2. 9.2.2. End User License Agreement
        3. 9.2.3. Icons and Labels
        4. 9.2.4. Versioning Your App
        5. 9.2.5. Licensing to Control Access to Paid Apps
        6. 9.2.6. Obfuscating Your Code
        7. 9.2.7. Getting a Private Key for Digitally Signing Your App
        8. 9.2.8. Screenshots
        9. 9.2.9. Promotional App Video
      3. 9.3. Pricing Your App: Free or Fee
        1. 9.3.1. Paid Apps
        2. 9.3.2. Free Apps
      4. 9.4. Monetizing Apps with In-App Advertising
      5. 9.5. Monetizing Apps: Using In-App Billing to Sell Virtual Goods
        1. In-App Purchase for Apps Sold Through Other App Marketplaces
      6. 9.6. Registering at Google Play
      7. 9.7. Setting Up a Google Wallet Merchant Account
      8. 9.8. Uploading Your Apps to Google Play
      9. 9.9. Launching the Play Store from Within Your App
      10. 9.10. Managing Your Apps in Google Play
      11. 9.11. Other Android App Marketplaces
      12. 9.12. Other Popular Mobile App Platforms
      13. 9.13. Marketing Your Apps
        1. Facebook
        2. Twitter
        3. Viral Video
        4. E-Mail Newsletters
        5. App Reviews
        6. Internet Public Relations
        7. Mobile Advertising Networks
      14. 9.14. Wrap-Up
        1. Staying in Contact with Deitel & Associates, Inc.
        2. Self-Review Exercises
        3. Answers to Self-Review Exercises
        4. Exercises
    18. A. Introduction to Java Applications
      1. A.1. Introduction
      2. A.2. Your First Program in Java: Printing a Line of Text
        1. Commenting Your Programs
        2. Using Blank Lines
        3. Declaring a Class
        4. Class Names and Identifiers
        5. Declaring a Method
        6. Performing Output with System.out.println
        7. Using End-of-Line Comments on Right Braces for Readability
        8. Compiling and Executing Your First Java Application
      3. A.3. Modifying Your First Java Program
        1. Displaying Multiple Lines of Text with a Single Statement
      4. A.4 Displaying Text with printf
      5. A.5 Another Application: Adding Integers
        1. Import Declarations
        2. Declaring Class Addition
        3. Declaring and Creating a Scanner to Obtain User Input from the Keyboard
        4. Declaring Variables to Store Integers
        5. Prompting the User for Input
        6. Obtaining an int as Input from the User
        7. Prompting for and Inputting a Second int
        8. Using Variables in a Calculation
        9. Displaying the Result of the Calculation
        10. Java API Documentation
      6. A.6. Memory Concepts
      7. A.7. Arithmetic
        1. Arithmetic Expressions in Straight-Line Form
        2. Parentheses for Grouping Subexpressions
        3. Rules of Operator Precedence
        4. Sample Algebraic and Java Expressions
        5. Evaluation of a Second-Degree Polynomial
      8. A.8. Decision Making: Equality and Relational Operators
      9. A.9. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    19. B. Introduction to Classes, Objects, Methods and Strings
      1. B.1. Introduction
      2. B.2. Declaring a Class with a Method and Instantiating an Object of a Class
        1. Class GradeBook
        2. Class GradeBookTest
        3. Compiling an Application with Multiple Classes
      3. B.3. Declaring a Method with a Parameter
        1. Arguments to a Method
        2. Class Declaration with a Method That Has One Parameter
        3. More on Arguments and Parameters
        4. Notes on import Declarations
      4. B.4. Instance Variables, set Methods and get Methods
        1. GradeBook Class with an Instance Variable, a set Method and a get Method
        2. Access Modifiers public and private
        3. Methods setCourseName and getCourseName
        4. Method displayMessage
        5. GradeBookTest Class That Demonstrates Class GradeBook
        6. set and get Methods
      5. B.5. Primitive Types vs. Reference Types
      6. B.6. Initializing Objects with Constructors
        1. Constructors with Multiple Parameters
      7. B.7. Floating-Point Numbers and Type double
        1. Floating-Point Number Precision and Memory Requirements
        2. Account Class with an Instance Variable of Type double
        3. AccountTest Class to Use Class Account
      8. B.8. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    20. C. Control Statements
      1. C.1. Introduction
      2. C.2. Algorithms
      3. C.3. Pseudocode
      4. C.4. Control Structures
        1. Sequence Structure in Java
        2. Selection Statements in Java
        3. Repetition Statements in Java
      5. C.5. if Single-Selection Statement
      6. C.6. if...else Double-Selection Statement
        1. Conditional Operator (?:)
        2. Nested if...else Statements
        3. Blocks
      7. C.7. while Repetition Statement
      8. C.8. Case Study: Counter-Controlled Repetition
        1. Pseudocode Algorithm with Counter-Controlled Repetition
        2. Implementing Counter-Controlled Repetition in Class GradeBook
        3. Class GradeBookTest
        4. Notes on Integer Division and Truncation
      9. C.9. Case Study: Sentinel-Controlled Repetition
        1. Implementing Sentinel-Controlled Repetition in Class GradeBook
        2. Program Logic for Sentinel-Controlled Repetition vs. Counter-Controlled Repetition
        3. Explicitly and Implicitly Converting Between Primitive Types
      10. C.10. Case Study: Nested Control Statements
      11. C.11. Compound Assignment Operators
      12. C.12. Increment and Decrement Operators
      13. C.13. Primitive Types
      14. C.14. Essentials of Counter-Controlled Repetition
      15. C.15. for Repetition Statement
        1. A Closer Look at the for Statement’s Header
        2. Scope of a for Statement’s Control Variable
        3. Expressions in a for Statement’s Header Are Optional
      16. C.16. Examples Using the for Statement
        1. Application: Compound-Interest Calculations
        2. Formatting Strings with Field Widths and Justification
        3. Performing the Interest Calculations
        4. Formatting Floating-Point Numbers
      17. C.17. do...while Repetition Statement
      18. C.18. switch Multiple-Selection Statement
        1. Method inputGrades
        2. Method incrementLetterGradeCounter
        3. GradeBookTest Class That Demonstrates Class GradeBook
        4. Notes on the Expression in Each case of a switch
        5. Using Strings in switch Statements (New in Java SE 7)
      19. C.19. break and continue Statements
        1. break Statement
        2. continue Statement
      20. C.20. Logical Operators
        1. Conditional AND (&&)Operator
        2. Conditional OR (||)Operator
        3. Short-Circuit Evaluation of Complex Conditions
        4. Boolean Logical AND (&) and Boolean Logical Inclusive OR (|) Operators
        5. Boolean Logical Exclusive OR (^)
        6. Logical Negation (!)Operator
      21. C.21. Wrap-Up
        1. Self-Review Exercises (Sections C.1–C.13)
        2. Self-Review Exercises (Sections C.14–C.20)
        3. Answers to Self-Review Exercises (Sections C.1–C.13)
        4. Answers to Self-Review Exercises (Sections C.14–C.20)
        5. Exercises (Sections C.1–C.13)
        6. Exercises (Sections C.14–C.20)
    21. D. Methods: A Deeper Look
      1. D.1. Introduction
      2. D.2. Program Modules in Java
      3. D.3. static Methods, staticFields and Class Math
        1. Math Class Constants PI and E
        2. Why Is Method main Declared static?
      4. D.4. Declaring Methods with Multiple Parameters
        1. The public and static Keywords
        2. Method maximum
        3. Implementing Method maximum by Reusing Method Math.max
        4. Assembling Strings with String Concatenation
      5. D.5. Notes on Declaring and Using Methods
      6. D.6. Method-Call Stack and Activation Records
      7. D.7. Argument Promotion and Casting
      8. D.8. Java API Packages
      9. D.9. Introduction to Random-Number Generation
        1. D.9.1. Scaling and Shifting of Random Numbers
        2. Generalizing the Random Number Calculations
        3. D.9.2. Random-Number Repeatability for Testing and Debugging
      10. D.10. Case Study: A Game of Chance; Introducing Enumerations
        1. Method rollDice
        2. Method main’s Local Variables
        3. enum Type Status
        4. Logic of the main Method
        5. Why Some Constants Are Not Defined as enum Constants
      11. D.11. Scope of Declarations
      12. D.12. Method Overloading
        1. Declaring Overloaded Methods
        2. Distinguishing Between Overloaded Methods
        3. Return Types of Overloaded Methods
      13. D.13. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    22. E. Arrays and ArrayLists
      1. E.1. Introduction
      2. E.2. Arrays
      3. E.3. Declaring and Creating Arrays
      4. E.4. Examples Using Arrays
        1. Creating and Initializing an Array
        2. Using an Array Initializer
        3. Calculating the Values to Store in an Array
        4. Using Bar Charts to Display Array Data Graphically
        5. Using the Elements of an Array as Counters
        6. Using Arrays to Analyze Survey Results
        7. The frequency Array
        8. Summarizing the Results
        9. Exception Handling: Processing the Incorrect Response
        10. The try Statement
        11. Executing the catch Block
        12. toString Method of the Exception Parameter
      5. E.5. Case Study: Card Shuffling and Dealing Simulation
        1. Class Card
        2. Class DeckOfCards
        3. DeckOfCards Constructor
        4. DeckOfCards Method shuffle
        5. DeckOfCards Method dealCard
        6. Shuffling and Dealing Cards
      6. E.6. Enhanced for Statement
      7. E.7. Passing Arrays to Methods
        1. Notes on Passing Arguments to Methods
      8. E.8. Case Study: Class GradeBook Using an Array to Store Grades
        1. Storing Student Grades in an Array in Class GradeBook
        2. Class GradeBookTest That Demonstrates Class GradeBook
      9. E.9. Multidimensional Arrays
        1. Arrays of One-Dimensional Arrays
        2. Two-Dimensional Arrays with Rows of Different Lengths
        3. Creating Two-Dimensional Arrays with Array-Creation Expressions
        4. Two-Dimensional Array Example: Displaying Element Values
        5. Common Multidimensional-Array Manipulations Performed with for Statements
      10. E.10. Case Study: Class GradeBook Using a Two-Dimensional Array
        1. Storing Student Grades in a Two-Dimensional Array in Class GradeBook
        2. Methods getMinimum and getMaximum
        3. Method outputBarChart
        4. Method outputGrades
        5. Method getAverage
        6. Class GradeBookTest That Demonstrates Class GradeBook
      11. E.11. Class Arrays
      12. E.12. Introduction to Collections and Class ArrayList
      13. E.13. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    23. F. Classes and Objects: A Deeper Look
      1. F.1. Introduction
      2. F.2. Time Class Case Study
        1. Time1 Class Declaration
        2. Default Constructor
        3. Method setTime and Throwing Exceptions
        4. Method toUniversalString
        5. Method toString
        6. Using Class Time1
        7. Calling Time1 Method setTime with Invalid Values
        8. Notes on the Time1 Class Declaration
      3. F.3. Controlling Access to Members
      4. F.4. Referring to the Current Object’s Members with the this Reference
      5. F.5. Time Class Case Study: Overloaded Constructors
        1. Class Time2 with Overloaded Constructors
        2. Class Time2’s Constructors
        3. Class Time2’s setTime Method
        4. Notes Regarding Class Time2’s set and get Methods and Constructors
        5. Using Class Time2’s Overloaded Constructors
      6. F.6. Default and No-Argument Constructors
      7. F.7. Composition
        1. Class Date
        2. Class Employee
        3. Class EmployeeTest
      8. F.8. Enumerations
      9. F.9. Garbage Collection
      10. F.10. static Class Members
        1. Tracking the Number of Employee Objects That Have Been Created
      11. F.11. final Instance Variables
      12. F.12. Packages
      13. F.13. Package Access
      14. F.14. Wrap-Up
        1. Self-Review Exercise
        2. Answers to Self-Review Exercise
        3. Exercises
    24. G. Object-Oriented Programming: Inheritance and Polymorphism
      1. G.1. Introduction to Inheritance
      2. G.2. Superclasses and Subclasses
        1. University Community Member Hierarchy
        2. Shape Hierarchy
      3. G.3. protected Members
      4. G.4. Relationship between Superclasses and Subclasses
        1. G.4.1. Creating and Using a CommissionEmployee Class
        2. G.4.2. Creating and Using a BasePlusCommissionEmployee Class
        3. G.4.3. Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
        4. G.4.4. CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Instance Variables
        5. G.4.5. CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables
      5. G.5. Class Object
      6. G.6. Introduction to Polymorphism
        1. Programming in the Specific
        2. Interfaces
      7. G.7. Polymorphism: An Example
        1. Space Objects in a Video Game
      8. G.8. Demonstrating Polymorphic Behavior
      9. G.9. Abstract Classes and Methods
        1. Purpose of Abstract Classes
        2. Declaring an Abstract Class and Abstract Methods
        3. Using Abstract Classes to Declare Variables
      10. G.10. Case Study: Payroll System Using Polymorphism
        1. G.10.1. Abstract Superclass Employee
        2. G.10.2. Concrete Subclass SalariedEmployee
        3. G.10.3. Concrete Subclass HourlyEmployee
        4. G.10.4. Concrete Subclass CommissionEmployee
        5. G.10.5. Indirect Concrete Subclass BasePlusCommissionEmployee
        6. G.10.6. Polymorphic Processing, Operator instanceof and Downcasting
        7. G.10.7. Summary of the Allowed Assignments Between Superclass and Subclass Variables
      11. G.11. final Methods and Classes
        1. Final Methods Cannot Be Overridden
        2. Final Classes Cannot Be Superclasses
      12. G.12. Case Study: Creating and Using Interfaces
        1. Standardizing Interactions
        2. Software Objects Communicate Via Interfaces
        3. Using an Interface
        4. Relating Disparate Types
        5. Interfaces vs. Abstract Classes
        6. Tagging Interfaces
        7. G.12.1. Developing a Payable Hierarchy
        8. G.12.2. Interface Payable
        9. G.12.3. Class Invoice
        10. G.12.4. Modifying Class Employee to Implement Interface Payable
        11. G.12.5. Modifying Class SalariedEmployee for Use in the Payable Hierarchy
        12. G.12.6. Using Interface Payable to Process Invoices and Employees Polymorphically
      13. G.13. Common Interfaces of the Java API
      14. G.14. Wrap-Up
        1. Self-Review Exercises (Sections G.1–G.5)
        2. Self-Review Exercises (Sections G.6–G.13)
        3. Answers to Self-Review Exercises (Sections G.1–G.5)
        4. Answers to Self-Review Exercises (Sections G.6–G.13)
        5. Exercises (Sections G.1–G.5)
        6. Exercises (Sections G.6–G.13)
    25. H. Exception Handling: A Deeper Look
      1. H.1. Introduction
      2. H.2. Example: Divide by Zero without Exception Handling
      3. H.3. Example: Handling ArithmeticExceptions and InputMismatchExceptions
        1. Enclosing Code in a try Block
        2. Catching Exceptions
        3. Termination Model of Exception Handling
        4. Using the throws Clause
      4. H.4. When to Use Exception Handling
      5. H.5. Java Exception Hierarchy
        1. Checked vs. Unchecked Exceptions
        2. Catching Subclass Exceptions
        3. Only the First Matching catch Executes
      6. H.6. finally Block
        1. Throwing Exceptions Using the throw Statement
        2. Rethrowing Exceptions
      7. H.7. Stack Unwinding and Obtaining Information from an Exception Object
        1. Stack Unwinding
        2. Obtaining Data from an Exception Object
      8. H.8. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    26. I. GUI Components and Event Handling
      1. I.1. Introduction
      2. I.2. Nimbus Look-and-Feel
      3. I.3. Text Fields and an Introduction to Event Handling with Nested Classes
        1. Specifying the Layout
        2. Creating the GUI
        3. Steps Required to Set Up Event Handling for a GUI Component
        4. Using a Nested Class to Implement an Event Handler
        5. Nested Class TextFieldHandler
        6. Registering the Event Handler for Each Text Field
        7. Details of Class TextFieldHandler’s actionPerformed Method
        8. Class TextFieldTest
      4. I.4. Common GUI Event Types and Listener Interfaces
      5. I.5. How Event Handling Works
        1. Registering Events
        2. Event-Handler Invocation
      6. I.6. JButton
        1. Accessing the this Reference in an Object of a Top-Level Class From a Nested Class
      7. I.7. JComboBox; Using an Anonymous Inner Class for Event Handling
        1. Using an Anonymous Inner Class for Event Handling
      8. I.8. Adapter Classes
      9. I.9. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Exercises
    27. J. Other Java Topics
      1. J.1. Introduction
      2. J.2. Collections Overview
      3. J.3. Type-Wrapper Classes for Primitive Types
        1. Autoboxing and Auto-Unboxing
      4. J.4. Interface Collection and Class Collections
      5. J.5. Lists
        1. J.5.1. ArrayList and Iterator
        2. J.5.2. LinkedList
        3. Method convertToUppercaseStrings
        4. Method removeItems
        5. Method printReversedList
        6. J.5.3. Views into Collections and Arrays Method asList
      6. J.6. Collections Methods
        1. J.6.1. Method sort
        2. J.6.2. Method shuffle
      7. J.7. Interface Queue
      8. J.8. Sets
        1. Sorted Sets
      9. J.9. Maps
      10. J.10. Introduction to Files and Streams
        1. Files as Streams of Bytes
        2. Byte-Based and Character-Based Streams
        3. Opening a File
        4. The java.io Package
      11. J.11. Class File
        1. Creating File Objects
      12. J.12. Introduction to Object Serialization
        1. Classes ObjectInputStream and ObjectOutputStream
        2. Interfaces ObjectOutput and ObjectInput
      13. J.13. Introduction to Multithreading
        1. Java Concurrency
        2. Concurrent Programming Uses
        3. Concurrent Programming Is Difficult
        4. Use the Prebuilt Classes of the Concurrency APIs Whenever Possible
      14. J.14. Creating and Executing Threads with the Executor Framework
        1. Creating Concurrent Tasks with the Runnable Interface
        2. Executing Runnable Objects with an Executor
        3. Using Class Executors to Obtain an ExecutorService
        4. Implementing the Runnable Interface
        5. Using the ExecutorService to Manage Threads that Execute PrintTasks
      15. J.15. Overview of Thread Synchronization
        1. Monitors
      16. J.16. Concurrent Collections Overview
      17. J.17. Multithreading with GUI
        1. Class SwingWorker
        2. Performing Tasks in a Worker Thread
        3. Class FibonacciNumbers
      18. J.18. Wrap-Up
        1. Self-Review Exercises
        2. Answers to Self-Review Exercises
        3. Execises
    28. K. Operator Precedence Chart
    29. L. Primitive Types
    30. Index

    Product information

    • Title: Android™ How to Program, Second Edition
    • Author(s): Paul Deitel, Harvey Deitel, Abbey Deitel
    • Release date: January 2014
    • Publisher(s): Pearson
    • ISBN: 9780133802092