Example: dental hygienist

Android Studio Development Essentials - eBookFrenzy

Android Studio Development Essentials Android Studio Development Essentials Second Edition 2015 Neil Smyth. All Rights Reserved. This book is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights reserved. The content of this book is provided for informational purposes only. Neither the publisher nor the author offers any warranties or representation, express or implied, with regard to the accuracy of information contained in this book, nor do they accept any liability for any loss or damage arising from any errors or omissions. This book contains trademarked terms that are used solely for editorial purposes and to the benefit of the respective trademark owner. The terms used within this book are not intended as infringement of any trademarks. Rev i Table of Contents 1. 1 Downloading the Code Samples.

v 20.4 An Event Handling Example..... 144

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Android Studio Development Essentials - eBookFrenzy

1 Android Studio Development Essentials Android Studio Development Essentials Second Edition 2015 Neil Smyth. All Rights Reserved. This book is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights reserved. The content of this book is provided for informational purposes only. Neither the publisher nor the author offers any warranties or representation, express or implied, with regard to the accuracy of information contained in this book, nor do they accept any liability for any loss or damage arising from any errors or omissions. This book contains trademarked terms that are used solely for editorial purposes and to the benefit of the respective trademark owner. The terms used within this book are not intended as infringement of any trademarks. Rev i Table of Contents 1. 1 Downloading the Code Samples.

2 1 Feedback .. 1 Errata .. 1 2. Setting up an Android Studio Development Environment .. 3 System Requirements .. 3 Installing the Java Development Kit (JDK) .. 3 Windows JDK Installation .. 3 Mac OS X JDK 4 Linux JDK Installation .. 4 Downloading the Android Studio Package .. 5 Installing Android Studio .. 5 Installation on Windows .. 5 Installation on Mac OS X .. 6 Installation on Linux .. 7 The Android Studio Setup Wizard .. 7 Installing the Latest Android SDK Packages .. 8 Making the Android SDK Tools Command-line Accessible .. 10 Windows 7 .. 10 Windows .. 11 Linux .. 11 Mac OS X .. 12 Updating the Android Studio and the SDK .. 12 Summary .. 12 3. Creating an Example Android App in Android Studio .. 13 Creating a New Android Project .. 13 Defining the Project and SDK Settings .. 14 Creating an 15 Modifying the Example 16 Reviewing the Layout and Resource 20 Previewing the Layout.

3 22 Summary .. 23 4. A Tour of the Android Studio User Interface .. 25 The Welcome Screen .. 25 The Main Window .. 26 The Tool Windows .. 27 Android Studio Keyboard Shortcuts .. 30 Switcher and Recent Files 30 Changing the Android Studio Theme .. 31 Summary .. 31 5. Creating an Android Virtual Device (AVD) in Android Studio .. 33 About Android Virtual Devices .. 33 Creating a New AVD .. 34 ii Starting the Emulator .. 36 Running the Application in the AVD .. 36 Run/Debug Configurations .. 38 Stopping a Running 39 AVD Command-line Creation .. 41 Android Virtual Device Configuration Files .. 42 Moving and Renaming an Android Virtual Device .. 42 Summary .. 43 6. Testing Android Studio Apps on a Physical Android Device .. 45 An Overview of the Android Debug Bridge (ADB) .. 45 Enabling ADB on Android based Devices .. 45 Mac OS X ADB 46 Windows ADB Configuration.

4 47 Linux adb Configuration .. 49 Testing the adb Connection .. 50 Summary .. 51 7. The Basics of the Android Studio Code Editor .. 53 The Android Studio Editor .. 53 Splitting the Editor Window .. 55 Code Completion .. 56 Statement Completion .. 57 Parameter Information .. 57 Code 57 Code Folding .. 59 Quick Documentation Lookup .. 60 Code Reformatting .. 60 Summary .. 61 8. An Overview of the Android Architecture .. 63 The Android Software Stack .. 63 The Linux Kernel .. 64 Android Runtime ART .. 64 Android Libraries .. 65 C/C++ Libraries .. 65 Application Framework .. 66 Applications .. 66 Summary .. 66 9. The Anatomy of an Android Application .. 67 Android Activities .. 67 Android Intents .. 67 Broadcast Intents .. 68 Broadcast 68 Android Services .. 68 Content Providers .. 68 The Application 69 Application Resources .. 69 Application Context.

5 69 Summary .. 69 iii 10. Understanding Android Application and Activity Lifecycles .. 71 Android Applications and Resource Management .. 71 Android Process States .. 71 Foreground Process .. 72 Visible Process .. 72 Service Process .. 72 Background Process .. 72 Empty Process .. 73 Inter-Process Dependencies .. 73 The Activity Lifecycle .. 73 The Activity Stack .. 73 Activity States .. 74 Configuration Changes .. 75 Handling State 75 Summary .. 75 11. Handling Android Activity State Changes .. 77 The Activity Class .. 77 Dynamic State vs. Persistent State .. 79 The Android Activity Lifecycle Methods .. 79 Activity Lifetimes .. 81 Summary .. 81 12. Android Activity State Changes by Example .. 83 Creating the State Change Example Project .. 83 Designing the User Interface .. 84 Overriding the Activity Lifecycle Methods .. 86 Filtering the LogCat Panel.

6 88 Running the Application .. 89 Experimenting with the Activity .. 90 Summary .. 91 13. Saving and Restoring the State of an Android Activity .. 93 Saving Dynamic 93 Default Saving of User Interface State .. 93 The Bundle Class .. 94 Saving the State .. 95 Restoring the State .. 96 Testing the Application .. 96 Summary .. 97 14. Understanding Android Views, View Groups and Layouts .. 99 Designing for Different Android Devices .. 99 Views and View Groups .. 99 Android Layout Managers .. 99 The View Hierarchy .. 100 Creating User Interfaces .. 102 Summary .. 102 15. A Guide to the Android Studio Designer Tool .. 103 iv The Android Studio Designer .. 103 Design Mode .. 103 Text 105 Setting Properties .. 105 Type Morphing .. 106 Creating a Custom Device Definition .. 107 Summary .. 107 16. Designing a User Interface using the Android Studio Designer Tool.

7 109 An Android Studio Designer Tool Example .. 109 Creating a New Activity .. 109 Designing the User Interface .. 111 Editing View Properties .. 111 Running the Application .. 112 Manually Creating an XML Layout .. 112 Using the Hierarchy Viewer .. 114 Summary .. 117 17. Creating an Android User Interface in Java Code .. 119 Java Code vs. XML Layout Files .. 119 Creating Views .. 119 Properties and Layout Parameters .. 120 Creating the Example Project in Android Studio .. 120 Adding Views to an Activity .. 121 Setting View Properties .. 122 Adding Layout Parameters and Rules .. 123 Using View IDs .. 124 Converting Density Independent Pixels (dp) to Pixels (px) .. 126 Summary .. 128 18. Using the Android GridLayout Manager in Android Studio 129 Introducing the Android GridLayout and Space Classes .. 129 The GridLayout Example .. 129 Creating the GridLayout Project.

8 130 Creating the GridLayout Instance .. 130 Adding Views to GridLayout Cells .. 131 Moving and Deleting Rows and Columns .. 132 Implementing Cell Row and Column 132 Changing the Gravity of a GridLayout Child .. 133 Summary .. 136 19. Working with the Android GridLayout using XML Layout Resources .. 137 GridLayouts in XML Resource Files .. 137 Adding Child Views to the GridLayout .. 138 Declaring Cell Spanning, Gravity and Margins .. 139 Summary .. 141 20. An Overview and Example of Android Event Handling .. 143 Understanding Android Events .. 143 Using the Android :onClick Resource .. 143 Event Listeners and Callback Methods .. 144 v An Event Handling Example .. 144 Designing the User Interface .. 145 The Event Listener and Callback Method .. 146 Consuming Events .. 147 Summary .. 148 21. Android Touch and Multi-touch Event 151 Intercepting Touch Events .. 151 The MotionEvent 151 Understanding Touch 151 Handling Multiple Touches.

9 152 An Example Multi-Touch Application .. 152 Designing the Activity User Interface .. 153 Implementing the Touch Event 154 Running the Example Application .. 157 Summary .. 157 22. Detecting Common Gestures using the Android Gesture Detector Class .. 159 Implementing Common Gesture Detection .. 159 Creating an Example Gesture Detection Project .. 160 Implementing the Listener Class .. 160 Creating the GestureDetectorCompat Instance .. 162 Implementing the onTouchEvent() Method .. 163 Testing the Application .. 164 Summary .. 164 23. Implementing Custom Gesture and Pinch Recognition on Android .. 165 The Android Gesture Builder Application .. 165 The GestureOverlayView Class .. 165 Detecting Gestures .. 165 Identifying Specific Gestures .. 165 Building and Running the Gesture Builder Application .. 166 Creating a Gestures File .. 166 Extracting the Gestures File from the SD Card.

10 167 Creating the Example Project .. 168 Adding the Gestures File to the Project .. 168 Designing the User Interface .. 168 Loading the Gestures File .. 169 Registering the Event Listener .. 170 Implementing the onGesturePerformed Method .. 170 Testing the Application .. 172 Configuring the GestureOverlayView .. 172 Intercepting Gestures .. 172 Detecting Pinch Gestures .. 173 A Pinch Gesture Example Project .. 173 Summary .. 175 24. An Introduction to Android Fragments .. 177 What is a Fragment? .. 177 Creating a Fragment .. 177 Adding a Fragment to an Activity using the Layout XML File .. 178 vi Adding and Managing Fragments in Code .. 180 Handling Fragment Events .. 181 Implementing Fragment 182 Summary .. 183 25. Using Fragments in Android Studio - An 185 About the Example Fragment Application .. 185 Creating the Example Project .. 185 Creating the First Fragment Layout.


Related search queries