O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Dynamic UIs with Android Fragments - Second Edition

Book Description

Create engaging apps with fragments to provide a rich user interface that dynamically adapts to the individual characteristics of your customers’ tablets and smartphones

About This Book

  • From an eminent author comes a book that will help you create engaging apps that dynamically adapt to individual device characteristics
  • The only book that includes the latest fragment-oriented features and their role in Material design
  • This book provides code-intensive discussions and detailed examples that help you understand better and learn faster.

Who This Book Is For

This book is for developers with a basic understanding of Android programming who would like to improve the appearance and usability of their applications by creating a more interactive user experience and dynamically adaptive UIs; providing better support for tablets and smartphones in a single app; and reducing the complexity of managing app UIs.

What You Will Learn

  • Learn the role and capabilities of fragments
  • Use Android Studio's fragment-oriented features
  • Create an app UI that works effectively on smartphones and tablets
  • Manage the creation and life cycle of fragments
  • Dynamically manage fragments using the FragmentTransaction class
  • Learn the application design for communicating between fragments
  • Leverage fragments when implementing applications that take advantage of the latest features of Material Design

In Detail

Today’s users expect mobile apps to be dynamic and highly interactive, with rich navigation features. These same apps must look fantastic whether running on a medium-resolution smartphone or high-resolution tablet. Fragments provide the toolset we need to meet these user expectations by enabling us to build our applications out of adaptable components that take advantage of the rich capabilities of each individual device and automatically adapt to their differences.

This book looks at the impact fragments have on Android UI design and their role in both simplifying many common UI challenges and in providing best practices for incorporating rich UI behaviors. We look closely at the roll of fragment transactions and how to work with the Android back stack. Leveraging this understanding, we explore several specialized fragment-related classes such as ListFragment and DialogFragment. We then go on to discuss how to implement rich navigation features such as swipe-based screen browsing, and the role of fragments when developing applications that take advantage of the latest aspects of Material Design.

You will learn everything you need to provide dynamic, multi-screen UIs within a single activity, and the rich UI features demanded by today’s mobile users.

Style and approach

A fast-paced learning guide that gives a hands-on, code-intensive approach with a focus on real-world applications.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Creating Dynamic UIs with Android Fragments Second Edition
    1. Table of Contents
    2. Creating Dynamic UIs with Android Fragments Second Edition
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Fragments and UI Modularization
      1. The need for a new approach to UI creation
        1. The broad platform support of fragments
        2. How fragments simplify common Android tasks
        3. The relationship between fragments and activities
        4. Making the shift to fragments
        5. The old thinking – activity-oriented
          1. Defining the activity appearance
          2. Displaying the activity UI
        6. The new thinking: fragment-oriented
          1. Creating the fragment layout resources
            1. Defining the layout as a reusable list
            2. Minimizing assumptions
            3. Encapsulating the display layout
          2. Creating the Fragment class
            1. Wrapping the list in a fragment
            2. Providing the description fragment
          3. Converting an activity to use fragments
      2. Summary
    9. 2. Fragments and UI Flexibility
      1. Creating UI flexibility
        1. Dynamic fragment layout selection
          1. Adding an alternate layout resource
          2. Managing fragment layout by screen size
          3. Eliminating redundant layout descriptions
            1. Layout aliasing
        2. Designing fragments for flexibility
          1. Avoiding tight coupling
          2. Abstracting fragment relationships
            1. Defining the callback interface
            2. Making the fragment self-contained
            3. Fragment notification
          3. Encapsulating fragment operations
          4. Creating a loosely connected relationship between fragments
      2. Fragments protect against the unexpected
        1. Creating the book description activity
        2. Adding functionality to the book description activity
        3. Making the MainActivity class adaptive
      3. Summary
    10. 3. Fragment Life Cycle and Specialization
      1. Understanding the fragment life cycle
        1. Understanding fragment setup and display
          1. Avoiding method name confusion
        2. Understanding fragment hide and teardown
        3. Maximizing the available resources
          1. Managing a fragment state
      2. Special-purpose fragment classes
        1. ListFragment
          1. Associating data with the list
          2. Separating data from the display
            1. Creating the ListFragment derived class with Android Studio
            2. Handling the ListFragment item selection
            3. Updating the layout resources
        2. DialogFragment
          1. Styles
          2. Layout
          3. Displaying DialogFragment
          4. Event handling in DialogFragment
          5. The Dialog identity
            1. Accessing behavior related to Dialog
            2. Wrapping an existing dialog in a fragment
      3. Summary
    11. 4. Working with Fragment Transactions
      1. Intentional screen management
      2. Dynamically managing fragments
        1. Deferred execution of transaction changes
        2. Adding and removing fragments
        3. Supporting the back button
      3. Creating an adaptive application layout
        1. Updating the layout to support dynamic fragments
        2. Adapting to device differences
        3. Dynamically loading a fragment at startup
        4. Transitioning between fragments
          1. Eliminating redundant handling
          2. Creating the fragment on the fly
          3. Managing asynchronous creation
          4. Putting it all together
      4. Summary
    12. 5. Creating Rich Navigation
      1. A brave new world
      2. Making navigation fun with swipe
        1. Implementing swipe navigation
        2. Adding swipe navigation with Android Studio
          1. Managing the swipe UI behavior
          2. Putting the swipe UI into place
      3. Providing direct navigation to screens
        1. Don't get trapped in the past
        2. Direct navigation for a small number of screens
        3. Direct navigation for four or more screens
          1. Creating a navigation drawer activity with Android Studio
          2. The activity and application screen fragment
          3. The navigation drawer fragment
            1. Navigation drawer fragment standard responsibilities
            2. The additional responsibilities of the NavigationDrawerFragment class
            3. The navigation drawer fragment responsibilities big picture
      4. Summary
    13. 6. Fragments and Material Design
      1. Creating a rich user experience
      2. Material design
        1. Principles of material design
        2. The role of motion
      3. Converting our application to use material design
        1. Dealing with different Android versions
        2. Setting up the theme
        3. Updating the fragments appearance
      4. Incorporating motion in fragment transitions
        1. Transitioning fragments on and off the screen
          1. Transitioning the book card off and on the screen
          2. Transitioning the book details on and off the screen
        2. Creating continuity with shared element transitions
          1. Maintaining continuity across multiple cards
      5. Summary
    14. Index