Building Hybrid Android Apps with Java and JavaScript

Book description

Build HTML5-based hybrid applications for Android with a mix of native Java and JavaScript components, without using third-party libraries and wrappers such as PhoneGap or Titanium. This concise, hands-on book takes you through the entire process, from setting up your development environment to deploying your product to an app store.

Learn how to create apps that have access to native APIs, such as location, vibrator, sensors, and the camera, using a JavaScript/Java bridge—and choose the language that gives you better performance for each task. If you have experience with HTML5 and JavaScript, you’ll quickly discover why hybrid app development is the wave of the future.

  • Set up a development environment with HTML, CSS, and JavaScript tools
  • Create your first hybrid Android project, using Eclipse IDE
  • Use the WebView control to host your hybrid application
  • Explore hybrid application architecture, including JavaScript/Java communication
  • Build single-page applications, using JavaScript libraries such as Backbone and Underscore
  • Get optimization tips and useful snippets for CSS, DOM, and JavaScript
  • Distribute your application to Google Play and the Amazon Appstore

Publisher resources

View/Submit Errata

Table of contents

  1. Building Hybrid Android Apps with Java and JavaScript
  2. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
    5. Acknowledgments
      1. Nizamettin Gok
      2. Nitin Khanna
      3. About the Technical Reviewer
  3. Dedication
  4. 1. What Is Android?
    1. Android Applications
    2. What Is a Hybrid Application?
    3. Categories of Applications
    4. Key Characteristics of Hybrid Apps
    5. Why Developing Hybrid Apps Makes Sense
    6. Hybrid Application Architecture
    7. How Do Hybrid Apps Work on the Android Platform?
  5. 2. Setting Up Your Android Development Environment
    1. Installing Eclipse on Mac OS X
    2. Installing Android Development Tools
    3. Creating Your First Hybrid Android Project Using Eclipse IDE
    4. Android Development Using the Command Line
      1. Setting PATH Environment Variables
    5. What Is ADB (Android Debug Bridge)?
      1. Connecting an Android Device to the Development Host
      2. Connecting to an Android Device Over WiFi
    6. Using Apache Ant to Automate Building Android Applications
    7. Understanding the Android Build Process
      1. Resource Precompilation
      2. Service Interface Precompilation
      3. Java Compilation
      4. DEX Generation
      5. Resource Packaging
      6. Creation of the APK File
      7. Alignment
    8. CSS Preprocessors
    9. Installing SASS
      1. Integrating SASS into the Android Command-Line Build System
    10. JSLint Framework and Strict Coding Conventions
    11. Process HTML Templates
    12. Minifying CSS and JavaScript Files Using YUI Compressor
    13. Using Safari and Chrome Browsers for Faster JavaScript Debugging and UI Changes
  6. 3. Android Fundamentals
    1. Android Application Architecture
    2. Key Android Components
      1. Dalvik Virtual Machine (DVM)
      2. View
      3. Activity
      4. Fragment
      5. Intent
      6. Services
      7. Content Providers
      8. Broadcast Receiver
    3. Security Model in Android
    4. Resources
      1. String Resources
      2. Layout Resources
    5. Compiled and Uncompiled Android Resources
    6. Assets
    7. Structure of an Android App
    8. Application Manifest
      1. Application Package Name
      2. Application
    9. Activity
    10. Intents
    11. Intent Resolution
    12. Intent Filter
    13. Services
    14. Broadcast Receiver
    15. Specifying Compatible Device Configuration
    16. Declaring Needed Device Features
    17. Permissions
    18. SDK Version
    19. Hands-on Coding: Hybrid Hello World! Application
  7. 4. WebView, WebKit, and WebSettings
    1. The WebView as a Web Browser
    2. So What Is WebKit?
    3. Requesting Internet Permission from Android Manifest
    4. Instantiating and Accessing the WebView Control
    5. Loading a Web Page
    6. Loading HTML into WebView
    7. WebViewClient
      1. WebChromeClient
    8. Loading Local Files into the WebView
    9. Load Flash Files into the WebView
    10. Reading Files from the res/raw Directory
    11. Triggering JavaScript Functions from the Java Layer
    12. Opening a WebView in Fullscreen Mode
    13. Enabling a Resize Event in JavaScript While Your Application Is Fullscreen
    14. Binding Java Objects to WebView Using the addJavaScriptInterface() Method
      1. @JavaScriptInterface Annotations
    15. Security Considerations for Hybrid Applications
    16. HttpOnly Cookies and the Secure Flag
    17. Domain Whitelisting
    18. Configuring WebView Settings with WebSettings
    19. Preventing Local Files from Being Loaded in the WebView
    20. Enabling JavaScript
    21. Setting Default Font Size
    22. Zoom Controls
    23. Hardware Acceleration
  8. 5. Inter-workings of the JavaScript and Java Layers
    1. Architecture of a Hybrid Application
    2. Calling Java Methods from JavaScript
    3. Synchronous APIs
    4. Asynchronous APIs
    5. Calling JavaScript Methods from Java
    6. Routing Data to the Correct JavaScript Receiver
    7. Deferred Object Pattern
    8. Register Success Callback Using deferred.done()
    9. Register Failure Callback Using deferred.fail()
    10. Register Progress Callback Using deferred.progress()
    11. Simpler Callback registration with .then()
    12. Synchronizing Multiple Asynchronous Events with $.when()
    13. Resolve a Deferred Object
    14. Reject a Deferred Object
    15. Use of Promise
    16. Use of deferred.progress()
    17. Cache Manager for Handling Multiple Deferred Objects
    18. Thread Safety
  9. 6. HTML Architecture for Hybrid Applications
    1. Architecture of a Web Application
    2. Single Page Applications (SPA)
    3. Key Design Considerations for Single Page Applications
    4. The Libraries and Frameworks for Your Hybrid Apps
    5. Backbone.js for MVC Framework
    6. Underscore.js for Utility Support
    7. iScroll.js for scrolling
    8. iScroll Caveats
    9. jQuery.js for JavaScript application
      1. Preload Images Within the CSS Files
    10. CSS Reset Avoids Browser Inconsistencies
    11. Your Home index.html
    12. Viewport Meta Tag
    13. Viewport Width
    14. Viewport Scaling with the Content Attribute
    15. Responsive Design and Media Queries
    16. EM or Percent (%) unit for scalable interface
    17. CSS3 Introduces rem Unit
    18. Opacity or RGBA: What Is the Difference?
    19. Event Pooling
  10. 7. CSS, DOM, and JavaScript: Optimization Tips and Useful Snippets
  11. 8. Publishing Apps for Android
    1. Digitally Signing Applications
    2. Protecting Your Application with ProGuard
    3. Google Play
    4. Registering as a Publisher
    5. Developer Console
    6. Uploading an Application
    7. Amazon App Store
    8. Self-Signing and the Amazon App Store
    9. Amazon App Store Sign Up Process
    10. Uploading an Application
    11. Understanding the Application Approval Process
  12. About the Authors
  13. Colophon
  14. Copyright

Product information

  • Title: Building Hybrid Android Apps with Java and JavaScript
  • Author(s): Nizamettin Gok, Nitin Khanna
  • Release date: July 2013
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449361877