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

Android Design Patterns and Best Practice

Book Description

Create reliable, robust, and efficient Android apps with industry-standard design patterns

About This Book

  • Create efficient object interaction patterns for faster and more efficient Android development
  • Get into efficient and fast app development and start making money from your android apps
  • Implement industry-standard design patterns and best practices to reduce your app development time drastically

Who This Book Is For

This book is intended for Android developers who have some basic android development experience. Basic Java programming knowledge is a must to get the most out of this book.

What You Will Learn

  • Build a simple app and run it on real and emulated devices
  • Explore the WYSIWYG and XML approaches to material design provided within Android Studio
  • Detect user activities by using touch screen listeners, gesture detection, and reading sensors
  • Apply transitions and shared elements to employ elegant animations and efficiently use the minimal screen space of mobile devices
  • Develop apps that automatically apply the best layouts for different devices by using designated directories
  • Socialize in the digital word by connecting your app to social media
  • Make your apps available to the largest possible audience with the AppCompat support library

In Detail

Are you an Android developer with some experience under your belt? Are you wondering how the experts create efficient and good-looking apps? Then your wait will end with this book! We will teach you about different Android development patterns that will enable you to write clean code and make your app stand out from the crowd.

The book starts by introducing the Android development environment and exploring the support libraries. You will gradually explore the different design and layout patterns and get to know the best practices of how to use them together. Then you’ll then develop an application that will help you grasp activities, services, and broadcasts and their roles in Android development.

Moving on, you will add user-detecting classes and APIs such as gesture detection, touch screen listeners, and sensors to your app. You will also learn to adapt your app to run on tablets and other devices and platforms, including Android Wear, auto, and TV. Finally, you will see how to connect your app to social media and explore deployment patterns as well as the best publishing and monetizing practices.

The book will start by introducing the Android development environment and exploring the support libraries. You will gradually explore the different Design and layout patterns and learn the best practices on how to use them together. You will then develop an application that will help you grasp Activities, Services and Broadcasts and their roles in Android development. Moving on, you will add user detecting classes and APIs such as at gesture detection, touch screen listeners and sensors to our app. You will also learn to adapt your app to run on tablets and other devices and platforms, including Android Wear, Auto, and TV. Finally, you will learn to connect your app to social media and explore deployment patterns and best publishing and monetizing practices.

Style and approach

This book takes a step-by-step approach. The steps are explained using real-world practical examples. Each chapter uses case studies where we show you how using design patterns will help in your development process.

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. Android Design Patterns and Best Practice
    1. Android Design Patterns and Best Practice
    2. Credits
    3. About the Author
    4. About the Reviewer
    5. www.PacktPub.com
      1. Why subscribe?
    6. Customer Feedback
    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. Design Patterns
      1. How this book works
      2. What we will build
        1. The scenario
        2. The problem
        3. The solution
      3. Targeting platform versions
      4. The support library
      5. The factory pattern
        1. UML diagrams
      6. Running and testing an app
        1. Connecting to a real device
        2. Connecting to a virtual device
        3. Monitoring devices
      7. The abstract factory pattern
        1. Working with more than one factory
      8. Summary
    9. 2. Creational Patterns
      1. Applying themes
      2. Customizing color and text
        1. Using palettes
        2. Customizing text
      3. Adding image resources
        1. Managing screen densities
        2. Using designated resources
      4. Creating a card view
        1. Understanding card view properties
        2. Applying CardView metrics
        3. Updating the factory pattern
      5. Applying a builder pattern
      6. Summary
    10. 3. Material Patterns
      1. The app-bar
        1. Image assets
        2. Applying actions
        3. App bar structure
          1. Phones
          2. Tablets
      2. The navigation drawer
        1. Drawer construction
        2. Ratio keylines
        3. Activating the drawer
        4. Adding fragments
        5. Right handed drawers
      3. The singleton pattern
      4. Summary
    11. 4. Layout Patterns
      1. Linear layouts
        1. Weight and gravity
      2. Relative layouts
        1. The percent support library
      3. Screen rotation
      4. Large screen layouts
        1. Width qualifiers
        2. Layout aliases
      5. The strategy pattern
      6. Summary
    12. 5. Structural Patterns
      1. Generating lists
      2. List item layouts
        1. Material font sizes
      3. Connecting data
      4. Translating string resources
        1. Adapters and layout managers
      5. The adapter pattern
      6. The bridge pattern
      7. The facade pattern
      8. The criteria pattern
      9. Summary
    13. 6. Activating Patterns
      1. Collapsing toolbars
      2. Applying a data factory pattern
      3. Positioning item layouts
      4. Using the factory with the RecyclerView
      5. Adding dividers
      6. Configuring the floating action button
      7. The dialog builder
        1. Custom dialogs
      8. Adding swipe and dismiss actions
      9. Constructing layout builders
      10. Summary
    14. 7. Combining Patterns
      1. Outlining specifications
      2. The prototype pattern
        1. Setting up a prototype
        2. Applying the prototype
      3. The decorator design pattern
        1. Setting up a decorator
        2. Applying the decorator
        3. Extending the decorator
      4. A sandwich builder pattern
        1. Applying the pattern
        2. Connecting to a UI
      5. Selecting patterns
      6. Adding a decorator
        1. Attaching the pattern
        2. Connecting the pattern to the UI
      7. Summary
    15. 8. Composing Patterns
      1. The composite pattern
        1. Adding a builder
      2. A Layout composer
        1. Adding components
        2. Creating composites
        3. Create composite layouts
        4. Formatting layouts at runtime
      3. Storage options
        1. Creating static files
        2. Creating and editing application files
      4. Storing user preferences
        1. The activity life cycle
        2. Applying preferences
        3. Adding a unique identifier
      5. Summary
    16. 9. Observing Patterns
      1. The Observer pattern
        1. Creating the pattern
        2. Adding a notification
        3. Utility observers and observables
      2. Notifications
        1. Setting an intent
        2. Customizing and configuring notifications
        3. Visibility and priority
      3. Services
      4. Summary
    17. 10. Behavioral Patterns
      1. The template pattern
        1. Extending templates
        2. The strategy pattern
      2. The visitor pattern
      3. The state pattern
      4. Summary
    18. 11. Wearable Patterns
      1. Android TV
        1. TV home screen
        2. TV model-view-presenter pattern
        3. TV app structure
        4. Recommendation cards
      2. Android Wear
        1. Pairing with a wearable device
        2. Managing screen shapes
        3. Wearable notifications
        4. Reading sensors
      3. Android Auto
        1. Auto safety considerations
        2. Configuring Auto apps
      4. Summary
    19. 12. Social Patterns
      1. Adding web pages
        1. Including a link
        2. Configuring WebSettings and JavaScript
        3. Writing HTML for WebViews
      2. Connecting with Facebook
        1. Adding the Facebook SDK
        2. Obtaining a Facebook App ID
        3. Adding a LikeView
      3. Content builders
      4. Integrating Twitter
        1. Sending tweets
      5. Summary
    20. 13. Distribution Patterns
      1. Extending platform scope
      2. Publishing apps
        1. Generating a signed APK
        2. Registering as a developer
        3. Publishing an app on the Google Play store
        4. Distributing by e-mail and on websites
      3. Promoting and monetizing apps
        1. Promoting an app
        2. Monetizing an app
        3. In-app billing
        4. Including an advertisement
      4. Summary