You are previewing Learn Android Studio: Build Android Apps Quickly and Effectively.
O'Reilly logo
Learn Android Studio: Build Android Apps Quickly and Effectively

Book Description

Learn Android Studio covers Android Studio and its rich tools ecosystem, including Git and Gradle: this book covers how Android Studio works seamlessly with Git, for source control, and Gradle, a build and test tool. In addition, this book demonstrates how to develop/collaborate with remote Git web-hosting services such as GitHub and Bitbucket. Four complete Android projects accompany this volume and are available for download from a public Git repository.

With this book, you learn the latest and most productive tools in the Android tools ecosystem, and the best practices for Android app development. You will be able to take away the labs' code as templates or frameworks to re-use and customize for your own similar apps.

Android Studio is an intuitive, feature-rich, and extremely forgiving Integrated Development Environment (IDE). This IDE is more productive and easier to use for your Android app creations than Eclipse. With this book you will quickly master Android Studio and maximize your Android development time. Source code on the remote web-hosting service is targeted to the latest Android Studio release, version 1.2.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Authors
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Introducing Android Studio
    1. Installing the Java Development Kit on Windows
      1. Downloading the JDK on Windows
      2. Executing the JDK Wizard on Windows
      3. Configuring Environmental Variables on Windows
    2. Installing the Java Development Kit on Mac
      1. Downloading the JDK on Mac
      2. Executing the JDK Wizard on Mac
      3. Configuring the JDK Version on Mac
    3. Installing Android Studio
    4. Creating Your First Project: HelloWorld
    5. Using Android Virtual Device Manager
    6. Running HelloWorld on an AVD
    7. Running HelloWorld on an Android Device
    8. Summary
  12. Chapter 2: Navigating Android Studio
    1. The Editor
      1. Editor Tabs
      2. The Gutter
      3. The Marker Bar
      4. Tool Buttons
      5. Default Layout
    2. Navigation Tool Windows
      1. The Project Tool Window
      2. The Structure Tool Window
      3. The Favorites Tool Window
      4. The TODO Tool Window
      5. The Commander Tool Window
    3. The Main Menu Bar
    4. The Toolbar
    5. The Navigation Bar
    6. The Status Bar
    7. Common Operations
      1. Selecting Text
      2. Using Undo and Redo
      3. Finding Recent Files
      4. Traversing Recent Navigation Operations
      5. Cutting, Copying, and Pasting
    8. Context Menus
    9. Getting Help
    10. Navigating with the Keyboard
      1. Select In
      2. Class
      3. File
      4. Line
      5. Related File
      6. Last Edit Location
      7. Type Hierarchy
      8. Declaration
    11. Finding and Replacing Text
      1. Find
      2. Find in Path
      3. Replace
      4. Replace in Path
    12. Summary
  13. Chapter 3: Programming in Android Studio
    1. Using Code Folding
    2. Performing Code Completion
    3. Commenting Code
    4. Using Code Generation
      1. Constructors
      2. Getters/Setters
      3. Override Methods
      4. toString( ) Method
      5. Delegate Methods
    5. Inserting Live Templates
    6. Moving Your Code
    7. Styling Your Code
      1. Auto-Indent Lines
      2. Rearrange Code
      3. Reformat Code
      4. Surrounding With
    8. Summary
  14. Chapter 4: Refactoring Code
    1. Rename
    2. Change Signature
    3. Type Migration
    4. Move
    5. Copy
    6. Safe Delete
    7. Extract
      1. Extract Variable
      2. Extract Constant
      3. Extract Field
      4. Extract Parameter
      5. Extract Method
    8. Advanced Refactoring
      1. Push Members Down and Pull Members Up
      2. Replace Inheritance with Delegation
      3. Encapsulate Fields
      4. Wrap Method Return Value
      5. Replace Constructor with Factory Method
      6. Convert Anonymous to Inner
    9. Summary
  15. Chapter 5: Reminders Lab: Part 1
    1. Starting a New Project
    2. Initializing the Git Repository
    3. Building the User Interface
      1. Working with the Visual Designer
      2. Editing the Layout’s Raw XML
      3. Adding Visual Enhancements
      4. Adding Items to ListView
      5. Setting the Action Bar Overflow Menu
    4. Persisting Reminders
      1. Data Model
      2. SQLite API
    5. Summary
  16. Chapter 6: Reminders Lab: Part 2
    1. Adding/Removing Reminders
    2. Responding to User Interaction
      1. User Dialog Boxes
    3. Providing Multichoice Context Menus
      1. Targeting Earlier SDKs
      2. Adding Contextual Action Mode
    4. Implementing Add, Edit, and Delete
      1. Planning a Custom Dialog Box
      2. Moving from Plans to Code
      3. Creating a Custom Dialog Box
      4. Adding a Custom Icon
    5. Summary
  17. Chapter 7: Introducing Git
    1. Installing Git
    2. Ignoring Files
    3. Adding Files
    4. Cloning the Reference App: Reminders
      1. Forking and Cloning
      2. Using the Git Log
      3. Branching
    5. Developing on a Branch
      1. Git Commits and Branches
      2. Where is Revert?
      3. Merging
      4. Git Reset Changes History
      5. Git Rebase
      6. Detached Head
      7. Relative References
      8. Resolving Conflicts While Rebasing
      9. Git Remotes
    6. Summary
  18. Chapter 8: Designing Layouts
    1. Activities
    2. Views and ViewGroups
      1. Preview Pane
      2. Width and Height
      3. Designer Mode
      4. Frame Layouts
      5. Linear Layouts
      6. Relative Layouts
      7. Nested Layouts
      8. List Views
    3. Layout Design Guidelines
      1. Covering Various Display Sizes
      2. Putting It All Together
    4. Fragments
    5. Summary
  19. Chapter 9: Currencies Lab: Part 1
    1. The Currencies Specification
    2. Initializing the Git Repository
    3. Modifying Layout for MainActivity
    4. Defining Colors
    5. Applying Colors to Layout
    6. Creating and Applying Styles
    7. Creating the JSONParser Class
    8. Creating Splash Activity
    9. Fetching Active Currency Codes as JSON
    10. Launching MainActivity
    11. Summary
  20. Chapter 10: Currencies Lab: Part 2
    1. Define Members of MainActivity
    2. Unpack Currency Codes from Bundle
    3. Create the Options Menu
    4. Implement Options Menu Behavior
    5. Create the spinner_closed Layout
    6. Bind mCurrencies to Spinners
    7. Delegate Spinner Behavior to MainActivity
    8. Create Preferences Manager
    9. Find Position Given Code
    10. Extract Code from Currency
    11. Implement Shared Preferences
    12. Button Click Behavior
    13. Store the Developer Key
    14. Fetch the Developer Key
    15. CurrencyConverterTask
      1. onPreExecute( )
      2. doInBackground( )
      3. onPostExecute( )
    16. Button Selector
    17. Launcher Icon
    18. Summary
  21. Chapter 11: Testing and Analyzing
    1. Creating a New Instrumentation Test
      1. Define SetUp( ) and TearDown( ) Methods
      2. Define Callback in MainActivity
      3. Define Some Test Methods
      4. Run Instrumentation Tests
      5. Fix the Bug
    2. Using Monkey
    3. Working with Analytical Tools
      1. Inspect Code
      2. Analyze Dependencies
      3. Analyze Stacktrace
    4. Summary
  22. Chapter 12: Debugging
    1. Logging
      1. Using Logcat
      2. Writing to the Android Log
    2. Bug Hunt!
      1. Using the Interactive Debugger
      2. Evaluating the Expression
      3. Using Stack Traces
      4. Exploring the Interactive Debugger’s Tool Window
      5. Working with the Breakpoint Browser
      6. Conditional Breakpoints
    3. Summary
  23. Chapter 13: Gradle
    1. Gradle Syntax
    2. IntelliJ Core Build System
    3. Gradle Build Concepts
      1. Gradle Android Structure
      2. Project Dependencies
    4. Case Study: The Gradle Weather Project
    5. Android Library Dependencies
      1. Java Library Dependencies
      2. Third-Party Libraries
    6. Opening Older Projects
    7. Summary
  24. Chapter 14: More SDK Tools
    1. Android Device Monitor
      1. Thread Monitor
      2. Heap Monitor
      3. Allocation Tracker
      4. Network Statistics
      5. Hierarchy Viewer
    2. Android Monitor Integration
      1. Memory Monitor
      2. Method Trace Tool
      3. Allocation Tracker
      4. Screen Capture
    3. Navigation Editor
      1. Designing a User Interface
      2. First Steps with the Navigation Editor
      3. Connecting Activities
      4. Editing Menus
    4. Terminal
      1. Query for Devices
      2. Install APK
      3. Download File
      4. Upload File
      5. Port Forward
    5. Google Cloud Tools
      1. Creating the HelloCloud Front End
      2. Creating the Java Endpoints Back-End Module
      3. Connecting the Pieces
      4. Deploying to App Engine
    6. Summary
  25. Chapter 15: Android Wear Lab
    1. Setting Up Your Wearable Environment
      1. Install Device Drivers
      2. Set Up Your SDK Tools
      3. Set Up a Wear Virtual Device
      4. Set Up Your Android Wear Hardware
    2. Creating the MegaDroid Project
      1. Optimize for Screen Technologies
      2. Build the WatchFace Service
      3. Initialize Drawable Resources and Style
      4. Manage Watch Updates
      5. Draw the Face
    3. Summary
  26. Chapter 16: Customizing Android Studio
    1. Code Style
    2. Appearance, Colors, and Fonts
    3. Keymap
    4. Macros
    5. File and Code Templates
    6. Menus and Toolbars
    7. Plug-ins
    8. Summary
  27. Index