Pro Android Wearables: Building Apps for Smartwatches

Book description

Learn how to design and build Android Wear apps for Android wearable devices, such as Google Android smartwatches, using the new WatchFaces API. Pro Android Wearables takes you through all the cool smartwatch features, such as health-monitoring, altimeters, and compasses. It's time to take your Android 5 Wear application development skills and experience to the next level and get exposure to a whole new world of hardware.

As smartwatches continue to grab major IoT headlines, there is a growing interest in building Android apps that run on these wearables, which are now being offered by dozens of major manufacturers. This means more revenue earning opportunity for today's indie app developers. Additionally, this book provides new media design concepts which relate to using media assets, as well as how to optimize Wear applications for low-power, single-core, dual-core or quad-core CPUs, and how to use the IntelliJ Android Studio IDE, and the Android device emulators for popular new wearable devices.

Table of contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Techincal reviewer
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Introduction to Android Wearables: Concepts, Types, and Material Design
    1. Wearable Technology Defined: What Is a Wearable?
      1. Wearable Application Development: What Types of Apps?
      2. Android Wearable Fun: Augmented Reality, Edutainment, and Gamification
    2. Mainstream Wearables: Smartwatches and Smartglasses
      1. Smartwatches: Round Watch Face vs. Square Organic Light-emitting Diode
      2. Smartglasses: Glasses and Other Smartglasses Manufacturers
    3. Wearable Application Programming Interfaces
      1. Android Studio 1.0: Android Wear SDK
      2. Google Glass Development Kit: GDK for Android or Mirror
    4. True Android or Android Peripheral: Bluetooth Link
    5. Wearable Apps Design: Android 5 Material Design
      1. The Android Material Design Themes: Light and Dark
      2. Android Material Design View Widgets: Lists and Cards
      3. Android Material Design Effects: Shadows and Animation
      4. Android Material Design Graphics Processing: Drawables
    6. What You Will Learn from This Book
    7. Summary
  12. Chapter 2: Setting Up an Android 5 Wearables Application Development Workstation
    1. Work Process for Creating an Android Workstation
      1. Android Development Workstation: Hardware Foundation
      2. Android Development Workstation: Software Foundation
    2. Java 7: Installing the Foundation for Android Studio
    3. Android Studio 1.0: Download the Android 5 IDEA
      1. Installing Android Studio: IntelliJ IDEA and Android SDK
    4. Professional Digital Imaging Software: GIMP 2.8.14
    5. Professional Digital Video Editing: Lightworks 12
    6. Professional 3D Modeling and Animation: Blender
    7. Professional Digital Audio Editing: Audacity 2.0.6
      1. Professional UI Design Wireframing: Pencil Project 2.0.5
    8. Professional Business Software Suite: OpenOffice 4
    9. Other Open Source and Affordable Media Software
    10. Summary
  13. Chapter 3: A Foundation for Android Wearables: New Wearable Features in Android 5
    1. Android’s Project Volta: Power Management Tools
      1. Android 5 Process Scheduler: JobScheduler and JobInfo
      2. Android 5 Battery Optimizer: The BatteryHistorian Tool
    2. Android’s Network Connection: NFC and Bluetooth
      1. Android 5 Multiple Network Support: ConnectivityManager
      2. Android 5 Low Energy Bluetooth: The Bluetooth LE API
      3. Android 5 NFC Improvements: Near Field Communication
    3. Android 5 Media: Adding Wow-Factor to Wearables
      1. Digital Video Playback: MediaController and MediaSession
      2. Digital Audio Playback: Enhanced AudioTrack Precision
      3. Real-Time 3D Rendering: OpenGL ES and Extension Pack
      4. WebKit Media: WebView, WebAudio, WebGL, and WebRTC
      5. Android MediaBrowser Class: Browsing Third-Party Media
      6. Android Camera 2 API: UHD Image Processing Support
    4. Android 5 Notifications: LockScreen and MetaData
      1. LockScreen Notifications: Privacy Safeguard Control APIs
      2. Notification MetaData: Intelligent Notification Classification
    5. More Android 5 Operating System Enhancements
      1. The Recents Screen: Concurrent Document Support
      2. Data Storage: Directory Structure Selection Support
      3. Second Screen: Screen Capturing and Screen Sharing
    6. Summary
  14. Chapter 4: Exploring Android Studio: Getting Familiar with the IntelliJ IDEA
    1. Updating IntelliJ IDEA: Using the Update Info Dialog
    2. Exploring IntelliJ IDEA: Help, Tips, and Keymaps
    3. Configure Android Studio: Using the SDK Manager
      1. Run As Administrator: Installing Using Admin Privileges
    4. Learning the IntelliJ IDEA Basics: Projects and SDK
      1. IntelliJ Project Level: Developing Android Applications
      2. IntelliJ Features: SDK, Language Support, and Auto-Coding
    5. Creating an Android Wearable App: Using IntelliJ
    6. Summary
  15. Chapter 5: Android Virtual Devices: Setting Up Wearables Application Emulators
    1. Using the AVD Manager: Creating Wear Emulators
    2. Using Wear Emulators: Testing Your Wearable App
      1. Using IntelliJ Run: Running Wearable Apps in Round Wear
      2. Switching AVDs: Running Apps in Round Wear ARM AVD
      3. Switching AVDs: Running Apps in Square Wear ARM AVD
    3. Summary
  16. Chapter 6: Introduction to Android Watch Faces Design: Considerations and Concepts
    1. Watch Face Design: Considerations and Guidelines
      1. A Watch Faces UI: Seamless Blending of Art and Function
      2. Watch Faces Power Usage: Interactive and Ambient Modes
      3. Watch Face Power Conservation: Low-bit and Burn Protect
      4. Watch Faces UI Design Shapes: Square vs. Round
    2. Watch Faces Integration: Assimilating OS Functions
      1. Android Notifications: CardView UI Layout Messaging
      2. Android Hardware State Indicators: Hardware Mode Status
      3. Android Hotword Placement: The OK Google Phrase
      4. Android Peripheral Connection: The Wear Companion App
    3. Watch Faces Function: Functional Data Integration
      1. Data Visualization: The Data You Want a User to See
      2. Data Integration: A Fusion of Watch Face Design and Data
      3. Data Assimilation: Use a Simple, Unified Design Objective
      4. Watch Face Development: Start Basic and Add as You Go
    4. Watch Faces Graphic Design: Multimedia Concepts
      1. Vector Watch Faces: Using SVG, Shapes, and Gradients
      2. Bitmap Watch Faces: Bitmap Formats and Image Concepts
      3. Animated Watch Faces: Animation and AnimationDrawable
    5. Summary
  17. Chapter 7: Program Watch Faces for Wear: Creating the Watch Face Code Foundation
    1. Gradle Scripts: Setting Gradle Build Dependencies
    2. Android Permissions: Watch Face Uses-Permission
    3. Canvas Watch Face Service: A Watch Face Engine
      1. The CanvasWatchFaceService Class: An Overview
      2. Creating a ProWatchFaceService Subclass: extends Keyword
      3. The CanvasWatchFaceService.Engine Class: The Engine
      4. Creating a Private Engine Class: Using onCreateEngine( )
    4. Watch Face XML Assets: Create and Edit XML Files
      1. Watch Face Wallpaper: Creating a Wallpaper Object in XML
      2. Declaring a WatchFace Service: The XML <service> Tag
    5. Watch Face Image Preview: Using Drawable Assets
    6. Summary
  18. Chapter 8: A Watch Faces Timing Engine: Using TimeZone, Time, and BroadcastReceiver
    1. Your WatchFace Surface: Android SurfaceHolder
      1. Android SurfaceHolder Interface: The Watch Face Surface
      2. A SurfaceHolder Object: onCreate(SurfaceHolder surface)
    2. Setting Watch Face Style: WatchFaceStyle.Builder
      1. Android WatchFaceStyle Class: Styling Your Watch Face
      2. Android WatchFaceStyle.Builder Class: Building the Style
      3. Building Your Watch Face: Using .setWatchFaceStyle( )
    3. Setting Watch Face Time: The Time-Related Classes
      1. Java Time Utility Classes: TimeUnit and TimeZone
      2. Keep Watch Face Time: WATCH_FACE_UPDATE Constant
      3. Android Classes: Time, Handler, and BroadcastReceiver
    4. Summary
  19. Chapter 9: Implement a WatchFaces Engine: Core WatchFaces API Methods
    1. WatchFace Seconds Time Engine: Using a Handler
      1. Android’s Handler Class: Handling Time Update Messages
      2. Android’s Message Class: Create a Time Update Message
      3. Creating a Second Hand Timer: The updateTimeHandler
    2. Watch Faces Time Calculation: Using System Time
      1. Java System Class: Accessing Time in Milliseconds
      2. Watch Face Seconds: Calculating Second Hand Movement
    3. WatchFaces API: Core Methods to Implement
      1. Android WatchFaceService Class: Core Constants
      2. Adding WatchFaceService Constants: Burn-In and Low-Bit
      3. Android WatchFaceService.Engine Class: Core Methods
      4. Adding WatchFaceService.Engine Methods: Core Function
    4. Summary
  20. Chapter 10: WatchFaces Vector Design: Using Vector Graphics for WatchFaces
    1. WatchFace Painting Engine: Using the Paint Object
      1. Android’s Paint Class: Paint Vector Shapes on the Canvas
      2. WatchFaces Painting: Creating Watch Face Paint Objects
    2. WatchFace Drawing Engine: The .onDraw( ) Method
      1. The Android Canvas Class: Your Canvas Drawing Methods
      2. Drawing Your WatchFace: Using the .drawLine( ) Method
    3. Advanced Mode Support: Dynamic Paint Methods
      1. Controlling Anti-Aliasing: Creating a setAntiAlias( ) Method
      2. Controlling Burn-In: Creating a setBurnInProtect( ) Method
      3. Ensuring Mode Support: An ensureModeSupport( ) Method
    4. Invoking Mode Methods: onAmbientModeChanged( )
    5. Returning to Interactive Mode: checkTimer( ) Method
    6. Summary
  21. Chapter 11: WatchFaces Bitmap Design: Using Raster Graphics for WatchFaces
    1. Testing a WatchFaces Design: Using the Round AVD
      1. Sending the Whole Second Delay to Your Handler Object
      2. Setting a Time Object to a Current Time in the Draw Logic
    2. Testing a WatchFace Design: Using a Square AVD
      1. AVD Crashes: Can’t Connect and Not Responding Panels
      2. Special Screen Modes: Testing the Low-Bit Ambient Mode
      3. Special Screen Modes: Testing Low-Bit and Burn-In Modes
    3. Android WindowInsets Class: Polling Screen Shape
    4. Detecting WatchFace Shape: Using WindowInsets
    5. Android Bitmap Class: Using Digital Image Assets
    6. Android Resources Class: Using Your Res Folder
    7. Accessing Imagery: Using Bitmap and Resources
    8. Android Drawable Class: Creating Drawable Objects
    9. Loading the Drawable: Using the roundFlag Boolean
    10. Android’s BitmapDrawable Class: Image Drawables
    11. Using BitmapDrawable Object: Extract and Scale
      1. Scaling Bitmaps: Using the .createScaledBitmap( ) Method
    12. Testing Background Bitmaps: Round vs. Square
      1. Solving the roundFlag Problem: onCreate( ) to onDraw( )
      2. Optimizing Your onDraw( ): First Draw vs. Every Draw
    13. Summary
  22. Chapter 12: WatchFaces Digital Imaging: Developing Multiple Mode Assets
    1. Ambient Mode Bitmap: GIMP Grayscale Image Mode
    2. Low-Bit Mode Bitmaps: GIMP’s Posterize Algorithm
      1. Dithering Low-Bit Imagery: Indexed Mode Conversion
      2. Creating a Burn-In Mode Bitmap: Using an Invert Algorithm
    3. Multimodal Bitmaps: Changing Bitmaps Using Java
      1. Installing Bitmap Objects into Your Low-Bit Ambient Mode
      2. Refining Interactive Mode: Set Tick Marks Color to Black
      3. Testing Interactive and Ambient Modes in the Square AVD
    4. Android Wear Burn-In Mode: Bitmap and Java Code
      1. Creating Burn-In Mode Bitmaps: GIMP Brightness-Contrast
      2. Burn-In Protection in Java: if(enableBurnInAmbientMode)
      3. Testing the Burn-In Protect Mode Bitmap and Java Code
    5. Summary
  23. Chapter 13: Watch Face Configuration Companion Activity: Google Mobile Services
    1. Creating a ProWatchFaceCompanionConfigActivity
      1. The Mobile App: Adding Your Activity to AndroidManifest
      2. The Java Class: Creating a WatchFace Companion Activity
      3. The Wear App: Adding Companion Metadata to Manifest
    2. Google Play Services: The GoogleApiClient Class
      1. Android’s GoogleApiClient: Using Google Mobile Services
      2. Creating the Play Client: Coding Your .onCreate( ) method
      3. The WatchFaceCompanion Class: Configuration Constants
      4. The ComponentName Class: Specify a Component
      5. Setting Watch Face Identity: ComponentName and PeerId
      6. The GoogleApiClient.Builder: Building a Google API Client
      7. Building the GoogleApiClient: Using the Wearable API
      8. Starting and Stopping a Play Client: onStart( ) and onStop( )
    3. Connect a Client: Creating the onConnected Method
      1. Android Uri Class: Uniform Resource Identifier Objects
      2. Android Uri.Builder Class: Building an Android URI Object
      3. Building a Uri for a Client: Finishing the onConnected( )
      4. Android’s GMS DataApi Interface: Configuring a Data API
      5. Using the DataApi Class: Configuring the Wearable.API
      6. The Android PendingResult Class: Receiving the Result
    4. Creating a Not Connected Dialog: Using AlertDialog
      1. Android AlertDialog: Creating an Alert Dialog for Your App
      2. Android AlertDialog.Builder: Building the Alert Dialog
      3. Using AlertDialog.Builder: Coding the AlertDialog System
    5. Coding an onResult Method: DataItem and DataMap
      1. Android’s DataItem Interface: A Foundation for Wear Data
      2. Loading a DataItem Object: Using a .getDataItem( ) Method
      3. Android’s DataMapItem Class: A DataItem with a Map
      4. Using a DataMapItem Object: The .fromDataItem( ) Method
      5. Android Data Map
      6. Creating a DataMap Object: Using a .getDataMap( ) Method
    6. Creating a Listener Service: .onMessageReceived( )
      1. The Android MessageEvent Class: Processing a Message
      2. Implementing a MessageEvent Object: Extracting the Data
      3. The ConnectionResult Class: Connecting to the Network
      4. Implementing a ConnectionResult: Blocking a Connection
    7. Summary
  24. Chapter 14: Watch Face Configuration Companion Activity Utility and Wearable API
    1. The ProWatchFaceUtility Class: Managing the Data
      1. Creating a ProWatchFaceUtility Class: Defining Constants
      2. Loading DataItems into a DataMap: .putConfigDataItem( )
      3. Android PutDataMapRequest Class: Put in a Data Request
      4. Using PutDataMapRequest to Put a Configuration DataItam
    2. Android Wearable Class: Android’s Wearable APIs
      1. Using the Wearable Class: Putting a DataApi Data Request
      2. Using Android’s Node API: .fetchConfigDataMap( ) Method
      3. Using Wearable DataApi: DataItemResultCallback( ) Class
      4. Replacing Changed Data: overwriteKeysInConfigDataMap
      5. Updating a DataMap Object: onConfigDataMapFetched( )
    3. Connect the Maps: Call the Utility from the Listener
    4. Finishing the Configuration Companion: UI Design
      1. Choosing Color Using the Spinner Widget: XML UI Layout
      2. Setting the Spinner Widget: setUpColorPickerSelection( )
      3. Setting Up a Spinner Listener: setUpColorPickerListener( )
      4. Setting Up All Four Spinners: A .setUpAllPickers( ) Method
    5. Testing the WatchFaceCompanion Activity: Nexus 5
    6. Summary
  25. Chapter 15: Wearables Application Testing: Using Hardware Devices in Android Studio
    1. Interfacing a Device with a Computer: USB Drivers
    2. Installing Wear API: Linking Smartwatch with Phone
      1. Downloading and Installing Wear API: Google Play Store
      2. Setting Up the Smartwatch: Sony SmartWatch 3
    3. Using ADB: Linking a Smartphone with the AVD
      1. Android Debug Bridge:Networking Hardware and Software
      2. Using AVD Inside Android Studio: ADBPort Forwarding
    4. Bluetooth Debugging: Linking to your Smartwatch
      1. Smartwatch Set Up: Pair and Enable Bluetooth Debugging
    5. Java Singleton: ProWatchFaceUtility( ) Constructor
    6. Testing and Debugging: Creating Your .APK Files
      1. The Android Studio Build System: An Overview
      2. Configuring Gradle Builds: Creating Different APK Types
      3. Building Your Project: Using the Gradle Build Engine
    7. Summary
  26. Chapter 16: Wear API Deprecation: Updating Apps to Use New Classes or Methods
    1. Dealing with the Unexpected Update: Android 5.2
    2. Dealing with Deprecation: .getDrawable( ) and Time
      1. Android’s Resources Class: Two .getDrawable( ) Methods
      2. The Resources.Theme Nested Class: Theme Attributes
      3. The ResourcesCompat Class: Backward Compatibility
      4. Dealing with Deprecated Classes: The Time Class
    3. Upgrading Your Code: Calendar and .getDrawable( )
      1. Upgrading the Time Class Code: Using the Calendar Class
      2. Upgrading timeZoneReceiver: The .setTimeZone( ) Method
      3. Upgrading the onDraw( ) Method: Using .setTimeInMillis( )
      4. Loading Your Time Variables: Using the .get( ) Method
      5. Upgrade the onVisibilityChanged( ) Method: .setTimeZone( )
      6. Upgrading the Code: Using the .getDrawable(int, Theme)
    4. Solving IDE Problems Introduced by SDK Upgrades
      1. Upgrading Gradle Files: Adding Build Definition Sections
      2. Using Invalidate and Restart: Rebuilding Project Structure
      3. Using Import Project
      4. Re-creating a Project from Scratch: Copy Code and Assets
      5. The Moral of the Story: Android Is More than Java or XML
    5. Summary
  27. Chapter 17: The Future of Android IoT APIs: Android TV, Glass, Auto, and Wear
    1. HD and UHD Android TV: The Opposite of Wear
    2. Android Auto: Android Apps for the Car Dashboard
    3. Google Glass: Develop Apps for Smart Eyeglasses
    4. Android Wear: Interesting API Elements to Explore
      1. Detecting Location: GPS Data from Google Play Services
      2. Voice Actions: Using Speech Recognition Technology
    5. Summary
  28. Index

Product information

  • Title: Pro Android Wearables: Building Apps for Smartwatches
  • Author(s): Wallace Jackson
  • Release date: July 2016
  • Publisher(s): Apress
  • ISBN: 9781430265511